Subversion Repositories ALCASAR

Rev

Rev 324 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
function time2str($time)
3
{
4
	$time = floor($time);
5
	if (!$time)
6
		return "0 seconds";
7
	$d = $time/86400;
8
	$d = floor($d);
1805 clement.si 9
	$str = '';
324 richard 10
	if ($d){
11
		$str .= "$d days, ";
12
		$time = $time % 86400;
13
	}
14
	$h = $time/3600;
15
	$h = floor($h);
16
	if ($h){
17
		$str .= "$h hours, ";
18
		$time = $time % 3600;
19
	}
20
	$m = $time/60;
21
	$m = floor($m);
22
	if ($m){
23
		$str .= "$m minutes, ";
24
		$time = $time % 60;
25
	}
26
	if ($time)
27
		$str .= "$time seconds, ";
28
 
1805 clement.si 29
	$str = preg_replace('/, $/','',$str);
30
 
324 richard 31
	return $str;
32
}
33
 
34
function time2strclock($time)
35
{
36
	$time = floor($time);
37
	if (!$time)
38
		return "00:00:00";
39
 
40
	$str["days"] = $str["hour"] = $str["min"] = $str["sec"] = "00";
41
 
42
	$d = $time/86400;
43
	$d = floor($d);
44
	if ($d){
45
		if ($d < 10)
46
			$d = "0" . $d;
47
		$str["days"] = "$d";
48
		$time = $time % 86400;
49
	}
50
	$h = $time/3600;
51
	$h = floor($h);
52
	if ($h){
53
		if ($h < 10)
54
			$h = "0" . $h;
55
		$str["hour"] = "$h";
56
		$time = $time % 3600;
57
	}
58
	$m = $time/60;
59
	$m = floor($m);
60
	if ($m){
61
		if ($m < 10)
62
			$m = "0" . $m;
63
		$str["min"] = "$m";
64
		$time = $time % 60;
65
	}
66
	if ($time){
67
		if ($time < 10)
68
			$time = "0" . $time;
69
	}
70
	else
71
		$time = "00";
72
	$str["sec"] = "$time";
73
	if ($str["days"] != "00")
74
		$ret = "$str[days]:$str[hour]:$str[min]:$str[sec]";
75
	else
76
		$ret = "$str[hour]:$str[min]:$str[sec]";
77
 
78
	return $ret;
79
}
80
 
81
function date2timediv($date,$now)
82
{
83
	list($day,$time)=explode(' ',$date);
84
	$day = explode('-',$day);
85
	$time = explode(':',$time);
86
	$timest = mktime($time[0],$time[1],$time[2],$day[1],$day[2],$day[0]);
87
	if (!$now)
88
		$now = time();
89
	return ($now - $timest);
90
}
91
 
92
function date2time($date)
93
{
94
	list($day,$time)=explode(' ',$date);
95
	$day = explode('-',$day);
96
	$time = explode(':',$time);
97
	$timest = mktime($time[0] ?"":0,$time[1],$time[2],$day[1],$day[2],$day[0]);
98
	return $timest;
99
}
100
 
101
function bytes2str($bytes)
102
{
103
	$bytes=floor($bytes);
104
	if ($bytes > 536870912)
105
		$str = sprintf("%5.2f GBs", $bytes/1073741824);
106
	else if ($bytes > 524288)
107
		$str = sprintf("%5.2f MBs", $bytes/1048576);
108
	else
109
		$str = sprintf("%5.2f KBs", $bytes/1024);
110
 
111
	return $str;
112
}
113
 
114
function nothing($ret)
115
{
116
	return $ret;
117
}
118
function check_defaults($val,$op,$def)
119
{
1805 clement.si 120
	for($i=0;$i<$def['count'];$i++){
121
		if ($val == $def[$i] && ($op == '' || $op == $def['operator'][$i]))
324 richard 122
			return 1;
123
	}
124
 
125
	return 0;
126
}
127
 
128
function check_ip($ipaddr) {
129
    if(ereg("^([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})\x2E([0-9]{1,3})$", $ipaddr,$digit)) {
130
   	  if(($digit[1] <= 255) && ($digit[2] <= 255) && ($digit[3] <= 255) && ($digit[4] <= 255)) {
131
        return(1);
132
      }
133
    }
134
    return(0);
135
  }
136
 
137
?>