-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.php
More file actions
137 lines (128 loc) · 3.65 KB
/
utility.php
File metadata and controls
137 lines (128 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
function unix_timestamp_to_human ($timestamp = "", $format = 'd M Y - H:i:s') {
if (empty($timestamp) || ! is_numeric($timestamp)) $timestamp = time();
return ($timestamp) ? date($format, $timestamp) : date($format, $timestamp);
}
function secondMinute($seconds){
/// get minutes
$minResult = floor($seconds/60);
/// if minutes is between 0-9, add a "0" --> 00-09
if($minResult < 10){$minResult = 0 . $minResult;}
/// get sec
$secResult = ($seconds/60 - $minResult)*60;
/// if secondes is between 0-9, add a "0" --> 00-09
if($secResult < 10){$secResult = 0 . $secResult;}
/// return result
echo $minResult,":",$secResult;
}
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
function curPageNameWithParameters() {
$url = curPageURL();
$pos = strrpos($url, "/");
$dir = substr($url, $pos+1);
return $dir;
}
function curPageDir() {
$url = curPageURL();
$pos = strrpos($url, "/");
$dir = substr($url, 0, $pos+1);
return $dir;
}
//This script is developed by www.webinfopedia.com and being modified
//For more examples in php visit www.webinfopedia.com
function zipFilesAndDownload($file_names, $display_names, $decrypted_files, $archive_file_name)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
for($i=0; $i<=count($file_names)-1; $i++) {
$zip->addFile($file_names[$i], $display_names[$i]);
}
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
unlink("$archive_file_name");
for($i=0; $i<=count($file_names)-1; $i++) {
if ($decrypted_files[$i]=="true") {
unlink($file_names[$i]);
}
}
}
function formatSQLCondInFromConfigString($configString,$name)
{
$result = "";
$token = explode(";", $configString);
foreach($token as $value) {
if (strpos($value, "-")!==FALSE) {
$range = explode("-", $value);
if (count($range)==2) {
$start = intval($range[0]);
$end = intval($range[1]);
if ($start < $end) {
for ($x = $start; $x <= $end; $x++) {
if (empty($result)) {
$result = $name .= " IN (";
$result .= "'";
$result .= $x;
$result .= "'";
} else {
$result .= ", ";
$result .= "'";
$result .= $x;
$result .= "'";
}
}
}
}
} else {
if (empty($result)) {
$result = $name .= " IN (";
$result .= "'";
$result .= $value;
$result .= "'";
} else {
$result .= ", ";
$result .= "'";
$result .= $value;
$result .= "'";
}
}
}
if (!empty($result)) {
$result .= ")";
}
return $result;
}
?>