-
Notifications
You must be signed in to change notification settings - Fork 328
/
pages_common.php
144 lines (110 loc) · 2.85 KB
/
pages_common.php
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
138
139
140
141
142
143
144
<?php
/*********************************************************************
* Name: pages_common.php
* Author: Liran tal <liran.tal@gmail.com>
*
* Provides common operations on different management pages and other
* categories
*
*********************************************************************/
/* returns a random alpha-numeric string of length $length */
function createPassword($length) {
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= ($length - 1)) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
/* convert byte to to size */
/* function contributed by ugenk (Evgeniy Kozhuhovskiy <ugenk@xdsl.by>) */
function toxbyte($size)
{
// Gigabytes
if ( $size > 1073741824 )
{
$ret = $size / 1073741824;
$ret = round($ret,2)." Gb";
return $ret;
}
// Megabytes
if ( $size > 1048576 )
{
$ret = $size / 1048576;
$ret = round($ret,2)." Mb";
return $ret;
}
// Kilobytes
if ($size > 1024 )
{
$ret = $size / 1024;
$ret = round($ret,2)." Kb";
return $ret;
}
// Bytes
if ( ($size != "") && ($size <= 1024 ) )
{
$ret = $size." B";
return $ret;
}
}
// set of functions to ease the usage of escaping " chars in echo or print functions
// thanks to php.net
function qq($text) {return str_replace('`','"',$text); }
function printq($text) { print qq($text); }
function printqn($text) { print qq($text)."\n"; }
// function taken from dialup_admin
function time2str($time) {
$str = ""; // initialize variable
$time = floor($time);
if (!$time)
return "0 seconds";
$d = $time/86400;
$d = floor($d);
if ($d){
$str .= "$d days, ";
$time = $time % 86400;
}
$h = $time/3600;
$h = floor($h);
if ($h){
$str .= "$h hours, ";
$time = $time % 3600;
}
$m = $time/60;
$m = floor($m);
if ($m){
$str .= "$m minutes, ";
$time = $time % 60;
}
if ($time)
$str .= "$time seconds, ";
$str = ereg_replace(', $','',$str);
return $str;
}
/*
* wrapper function to add a tooltip balloon
*
* @param $view array of view parameters
* @return $string returns string
*/
function addToolTipBalloon($view) {
if ($view['divId'])
$viewId = '<div id="'.$view['divId'].'">Loading...</div>';
else
$viewId = '';
$str = "<a class='tablenovisit' href='javascript:return;'
onClick=\"".$view['onClick']." javascript:__displayTooltip();\"
tooltipText='".$view['content']."
<br/><br/>
$viewId
<br/>'
>".$view['value']."</a>";
return $str;
}
?>