@@ -45,6 +45,9 @@ discard block |
||
45 | 45 | return "../bolt_snap/compare_snapshot_$x"; |
46 | 46 | } |
47 | 47 | |
48 | +/** |
|
49 | + * @param null|integer $dur |
|
50 | + */ |
|
48 | 51 | function write_compare_snapshot($course_id, $select_name, $xset_name, $dur) { |
49 | 52 | $now = time(); |
50 | 53 | $start = $now - $dur*86400; |
@@ -127,6 +130,9 @@ discard block |
||
127 | 130 | return "../bolt_snap/map_snapshot_".$course_id; |
128 | 131 | } |
129 | 132 | |
133 | +/** |
|
134 | + * @param null|integer $dur |
|
135 | + */ |
|
130 | 136 | function write_map_snapshot($course_id, $dur) { |
131 | 137 | $now = time(); |
132 | 138 | $start = $now - $dur*86400; |
@@ -116,7 +116,9 @@ discard block |
||
116 | 116 | function read_compare_snapshot($course_id, $select_name, $xset_name) { |
117 | 117 | $filename = compare_snapshot_filename($course_id, $select_name, $xset_name); |
118 | 118 | $f = @fopen($filename, "r"); |
119 | - if (!$f) return null; |
|
119 | + if (!$f) { |
|
120 | + return null; |
|
121 | + } |
|
120 | 122 | $x = fread($f, filesize($filename)); |
121 | 123 | fclose($f); |
122 | 124 | return unserialize($x); |
@@ -220,7 +222,9 @@ discard block |
||
220 | 222 | function read_map_snapshot($course_id) { |
221 | 223 | $filename = map_snapshot_filename($course_id); |
222 | 224 | $f = @fopen($filename, "r"); |
223 | - if (!$f) return null; |
|
225 | + if (!$f) { |
|
226 | + return null; |
|
227 | + } |
|
224 | 228 | $x = fread($f, filesize($filename)); |
225 | 229 | fclose($f); |
226 | 230 | return unserialize($x); |
@@ -23,6 +23,9 @@ discard block |
||
23 | 23 | |
24 | 24 | // get names of units of a given type |
25 | 25 | |
26 | +/** |
|
27 | + * @param string $type |
|
28 | + */ |
|
26 | 29 | function units_of_type($unit, $type) { |
27 | 30 | $names = array(); |
28 | 31 | if (get_class($unit) == $type) { |
@@ -118,6 +121,10 @@ discard block |
||
118 | 121 | |
119 | 122 | //////////// graph drawing |
120 | 123 | |
124 | +/** |
|
125 | + * @param integer $n |
|
126 | + * @param integer $width |
|
127 | + */ |
|
121 | 128 | function compare_bar($title, $n, $width, $lo, $hi) { |
122 | 129 | $x1 = $width*$lo; |
123 | 130 | $x2 = $width*($hi-$lo); |
@@ -137,6 +144,9 @@ discard block |
||
137 | 144 | "; |
138 | 145 | } |
139 | 146 | |
147 | +/** |
|
148 | + * @param integer $width |
|
149 | + */ |
|
140 | 150 | function compare_bar_insuff($title, $width) { |
141 | 151 | return " |
142 | 152 | <tr> |
@@ -150,6 +160,10 @@ discard block |
||
150 | 160 | "; |
151 | 161 | } |
152 | 162 | |
163 | +/** |
|
164 | + * @param integer[] $x |
|
165 | + * @param integer $width |
|
166 | + */ |
|
153 | 167 | function outcome_graph($x, $width) { |
154 | 168 | $n = $x[0]+$x[1]+$x[2]; |
155 | 169 | if (!$n) return empty_cell(); |
@@ -182,6 +196,9 @@ discard block |
||
182 | 196 | return $s; |
183 | 197 | } |
184 | 198 | |
199 | +/** |
|
200 | + * @param integer $w |
|
201 | + */ |
|
185 | 202 | function time_graph($t, $w) { |
186 | 203 | if ($t == 0) return "<td>---</td>"; |
187 | 204 | $x = (log10($t)+2)*$w/4; |
@@ -193,6 +210,10 @@ discard block |
||
193 | 210 | </td>"; |
194 | 211 | } |
195 | 212 | |
213 | +/** |
|
214 | + * @param integer $t |
|
215 | + * @param integer $w |
|
216 | + */ |
|
196 | 217 | function score_graph($t, $w) { |
197 | 218 | if ($t == 0) return "<td>---</td>"; |
198 | 219 | $x = $t*$w; |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $n++; |
90 | 90 | $delta = $x - $m; |
91 | 91 | $m += $delta/$n; |
92 | - $m2 += $delta*($x-$m); |
|
92 | + $m2 += $delta*($x - $m); |
|
93 | 93 | } |
94 | 94 | $mean = $m; |
95 | - $stdev = sqrt($m2/($n-1)); |
|
95 | + $stdev = sqrt($m2/($n - 1)); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // approximate the 90% confidence interval for the mean of an array |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | |
104 | 104 | // I'm too lazy to compute the t distribution |
105 | 105 | $t_90 = 1.7; |
106 | - $d = $t_90 * $stdev / sqrt($n); |
|
106 | + $d = $t_90*$stdev/sqrt($n); |
|
107 | 107 | $lo = $mean - $d; |
108 | 108 | $hi = $mean + $d; |
109 | 109 | } |
110 | 110 | |
111 | 111 | function test_stats() { |
112 | - $a = array(1,1,1,1,0,1,1,1,3, 1, 1, 1, 1); |
|
112 | + $a = array(1, 1, 1, 1, 0, 1, 1, 1, 3, 1, 1, 1, 1); |
|
113 | 113 | mean_stdev($a, $mean, $stdev); |
114 | 114 | echo "mean: $mean stdev: $stdev\n"; |
115 | 115 | conf_int_90($a, $lo, $hi); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | function compare_bar($title, $n, $width, $lo, $hi) { |
122 | 122 | $x1 = $width*$lo; |
123 | - $x2 = $width*($hi-$lo); |
|
123 | + $x2 = $width*($hi - $lo); |
|
124 | 124 | $a1 = number_format($lo*100); |
125 | 125 | $a2 = number_format($hi*100); |
126 | 126 | return " |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | function outcome_graph($x, $width) { |
154 | - $n = $x[0]+$x[1]+$x[2]; |
|
154 | + $n = $x[0] + $x[1] + $x[2]; |
|
155 | 155 | if (!$n) return empty_cell(); |
156 | 156 | $x0 = $width*$x[1]/$n; |
157 | 157 | $x1 = $width*$x[0]/$n; |
158 | 158 | $x2 = $width*$x[2]/$n; |
159 | - if ($x[1]/$n>0.05) { |
|
159 | + if ($x[1]/$n > 0.05) { |
|
160 | 160 | $t0 = number_format(100*$x[1]/$n)."%"; |
161 | 161 | } else { |
162 | 162 | $t0 = ""; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | function time_graph($t, $w) { |
186 | 186 | if ($t == 0) return "<td>---</td>"; |
187 | - $x = (log10($t)+2)*$w/4; |
|
187 | + $x = (log10($t) + 2)*$w/4; |
|
188 | 188 | $t = number_format($t, 1); |
189 | 189 | return "<td> |
190 | 190 | <table class=bolt_bar><tr> |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | function score_graph($t, $w) { |
197 | 197 | if ($t == 0) return "<td>---</td>"; |
198 | 198 | $x = $t*$w; |
199 | - $y = (1-$t)*$w; |
|
199 | + $y = (1 - $t)*$w; |
|
200 | 200 | $t = number_format($t*100); |
201 | 201 | $s = "<td> |
202 | 202 | <table class=bolt_bar><tr> |
@@ -66,11 +66,15 @@ discard block |
||
66 | 66 | // Find a unit of given name |
67 | 67 | // |
68 | 68 | function lookup_unit($top_unit, $name) { |
69 | - if ($top_unit->name == $name) return $top_unit; |
|
69 | + if ($top_unit->name == $name) { |
|
70 | + return $top_unit; |
|
71 | + } |
|
70 | 72 | if (is_subclass_of($top_unit, "BoltSet")) { |
71 | 73 | foreach ($top_unit->units as $child) { |
72 | 74 | $u = lookup_unit($child, $name); |
73 | - if ($u) return $u; |
|
75 | + if ($u) { |
|
76 | + return $u; |
|
77 | + } |
|
74 | 78 | } |
75 | 79 | } |
76 | 80 | return null; |
@@ -152,7 +156,9 @@ discard block |
||
152 | 156 | |
153 | 157 | function outcome_graph($x, $width) { |
154 | 158 | $n = $x[0]+$x[1]+$x[2]; |
155 | - if (!$n) return empty_cell(); |
|
159 | + if (!$n) { |
|
160 | + return empty_cell(); |
|
161 | + } |
|
156 | 162 | $x0 = $width*$x[1]/$n; |
157 | 163 | $x1 = $width*$x[0]/$n; |
158 | 164 | $x2 = $width*$x[2]/$n; |
@@ -183,7 +189,9 @@ discard block |
||
183 | 189 | } |
184 | 190 | |
185 | 191 | function time_graph($t, $w) { |
186 | - if ($t == 0) return "<td>---</td>"; |
|
192 | + if ($t == 0) { |
|
193 | + return "<td>---</td>"; |
|
194 | + } |
|
187 | 195 | $x = (log10($t)+2)*$w/4; |
188 | 196 | $t = number_format($t, 1); |
189 | 197 | return "<td> |
@@ -194,7 +202,9 @@ discard block |
||
194 | 202 | } |
195 | 203 | |
196 | 204 | function score_graph($t, $w) { |
197 | - if ($t == 0) return "<td>---</td>"; |
|
205 | + if ($t == 0) { |
|
206 | + return "<td>---</td>"; |
|
207 | + } |
|
198 | 208 | $x = $t*$w; |
199 | 209 | $y = (1-$t)*$w; |
200 | 210 | $t = number_format($t*100); |
@@ -22,6 +22,9 @@ discard block |
||
22 | 22 | public $weight; |
23 | 23 | public $callback; |
24 | 24 | |
25 | + /** |
|
26 | + * @param null|BoltRefresh $refresh |
|
27 | + */ |
|
25 | 28 | function __construct( |
26 | 29 | $name, $units, $number, $repeats, $refresh, $attrs, $callback, $weight |
27 | 30 | ) { |
@@ -156,10 +159,16 @@ discard block |
||
156 | 159 | define('REPEAT', 2); |
157 | 160 | define('NEXT', 4); |
158 | 161 | |
162 | +/** |
|
163 | + * @param integer $f |
|
164 | + */ |
|
159 | 165 | function repeat($s, $u, $f) { |
160 | 166 | return new BoltRepeat($s, $u, $f); |
161 | 167 | } |
162 | 168 | |
169 | +/** |
|
170 | + * @param integer[] $a |
|
171 | + */ |
|
163 | 172 | function refresh($a) { |
164 | 173 | return new BoltRefresh($a); |
165 | 174 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $nshown = $state_rec['nshown']; |
53 | 53 | $state_rec['scores'][$nshown] = $score; |
54 | 54 | $iter->state[$this->name] = $state_rec; |
55 | - $is_last = ($nshown+1 == $this->ntoshow); |
|
55 | + $is_last = ($nshown + 1 == $this->ntoshow); |
|
56 | 56 | if (!$is_last) { |
57 | 57 | return false; |
58 | 58 | } |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | // - optionally create or update bolt_refresh record |
63 | 63 | // |
64 | 64 | $total_score = 0; |
65 | - for ($i=0; $i<$nshown+1; $i++) { |
|
65 | + for ($i = 0; $i < $nshown + 1; $i++) { |
|
66 | 66 | $total_score += $state_rec['scores'][$i]; |
67 | 67 | } |
68 | - $avg_score = $total_score/($nshown+1); |
|
68 | + $avg_score = $total_score/($nshown + 1); |
|
69 | 69 | |
70 | 70 | $repeat = null; |
71 | 71 | $least = 2; |
72 | 72 | foreach ($this->repeats as $r) { |
73 | - if ($avg_score < $r->score && $r->score<$least) { |
|
73 | + if ($avg_score < $r->score && $r->score < $least) { |
|
74 | 74 | $repeat = $r; |
75 | 75 | $least = $r->score; |
76 | 76 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | -class BoltRefresh{ |
|
137 | +class BoltRefresh { |
|
138 | 138 | public $intervals; |
139 | 139 | function __construct($i) { |
140 | 140 | $this->intervals = $i; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } else if (get_class($arg) == "BoltRepeat") { |
192 | 192 | $repeats[] = $arg; |
193 | 193 | } else if (get_class($arg) == "BoltRefresh") { |
194 | - $refresh= $arg; |
|
194 | + $refresh = $arg; |
|
195 | 195 | } else { |
196 | 196 | echo "Can't include object of type ".get_class($arg)." within an exercise set."; |
197 | 197 | } |
@@ -200,7 +200,9 @@ |
||
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - if ($number == 0) $number = count($units); |
|
203 | + if ($number == 0) { |
|
204 | + $number = count($units); |
|
205 | + } |
|
204 | 206 | return new BoltExerciseSet( |
205 | 207 | $name, $units, $number, $repeats, $refresh, $attrs, $callback, $weight |
206 | 208 | ); |
@@ -38,6 +38,9 @@ |
||
38 | 38 | return $job->insert($clause); |
39 | 39 | } |
40 | 40 | |
41 | +/** |
|
42 | + * @param string $name |
|
43 | + */ |
|
41 | 44 | function bossa_batch_create($appid, $name, $calibration) { |
42 | 45 | $now = time(); |
43 | 46 | $c = $calibration?"1":"0"; |
@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | function bossa_batch_create($appid, $name, $calibration) { |
42 | 42 | $now = time(); |
43 | - $c = $calibration?"1":"0"; |
|
43 | + $c = $calibration ? "1" : "0"; |
|
44 | 44 | return BossaBatch::insert("(create_time, app_id, name, calibration) values ($now, $appid, '$name', $c)"); |
45 | 45 | } |
46 | 46 |
@@ -47,13 +47,17 @@ |
||
47 | 47 | function bossa_app_lookup($name) { |
48 | 48 | $name = BoincDb::escape_string($name); |
49 | 49 | $app = BossaApp::lookup("short_name='$name'"); |
50 | - if (!$app) return 0; |
|
50 | + if (!$app) { |
|
51 | + return 0; |
|
52 | + } |
|
51 | 53 | return $app->id; |
52 | 54 | } |
53 | 55 | |
54 | 56 | function bossa_lookup_job($instid, &$job, &$inst, &$user) { |
55 | 57 | $inst = BossaJobInst::lookup_id($instid); |
56 | - if (!$inst) return false; |
|
58 | + if (!$inst) { |
|
59 | + return false; |
|
60 | + } |
|
57 | 61 | $job = BossaJob::lookup_id($inst->job_id); |
58 | 62 | $user = BoincUser::lookup_id($inst->user_id); |
59 | 63 | BossaUser::lookup($user); |
@@ -59,6 +59,9 @@ discard block |
||
59 | 59 | return $path; |
60 | 60 | } |
61 | 61 | |
62 | +/** |
|
63 | + * @param string $dir |
|
64 | + */ |
|
62 | 65 | function disk_usage($dir) { |
63 | 66 | $usage=0; |
64 | 67 | if ($handle=@opendir($dir)) { |
@@ -76,6 +79,10 @@ discard block |
||
76 | 79 | return $usage; |
77 | 80 | } |
78 | 81 | |
82 | +/** |
|
83 | + * @param integer $max_age |
|
84 | + * @param string $dir |
|
85 | + */ |
|
79 | 86 | function clean_cache($max_age, $dir) { |
80 | 87 | $start_dir = getcwd(); |
81 | 88 | if (!chdir($dir)) { |
@@ -116,6 +123,9 @@ discard block |
||
116 | 123 | clean_cache($x, "../cache"); |
117 | 124 | } |
118 | 125 | |
126 | +/** |
|
127 | + * @param string $path |
|
128 | + */ |
|
119 | 129 | function cache_need_to_regenerate($path, $max_age){ |
120 | 130 | $regenerate = false; |
121 | 131 | $request = apache_request_headers(); |
@@ -139,6 +149,9 @@ discard block |
||
139 | 149 | } |
140 | 150 | |
141 | 151 | // Returns cached data or false if nothing was found |
152 | +/** |
|
153 | + * @param integer $max_age |
|
154 | + */ |
|
142 | 155 | function get_cached_data($max_age, $params=""){ |
143 | 156 | global $no_cache; |
144 | 157 | |
@@ -253,6 +266,10 @@ discard block |
||
253 | 266 | } |
254 | 267 | } |
255 | 268 | |
269 | +/** |
|
270 | + * @param integer $max_age |
|
271 | + * @param string $data |
|
272 | + */ |
|
256 | 273 | function set_cached_data($max_age, $data, $params=""){ |
257 | 274 | // for the benefit of hackers |
258 | 275 | if (strstr($params, "..")) { |
@@ -99,7 +99,7 @@ |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | - @closedir($handle); |
|
102 | + @closedir($handle); |
|
103 | 103 | } |
104 | 104 | chdir($start_dir); |
105 | 105 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | mkdir("../cache", 0770); |
33 | 33 | chmod("../cache", 0770); |
34 | 34 | } |
35 | - for ($i=0;$i<256;$i++) { |
|
36 | - $j=sprintf("%02x",$i); |
|
35 | + for ($i = 0; $i < 256; $i++) { |
|
36 | + $j = sprintf("%02x", $i); |
|
37 | 37 | if (!@filemtime("../cache/$j")) { |
38 | 38 | mkdir("../cache/$j", 0770); |
39 | 39 | chmod("../cache/$j", 0770); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | -function get_path($params, $phpfile=null) { |
|
44 | +function get_path($params, $phpfile = null) { |
|
45 | 45 | if (!@filemtime("../cache/00")) make_cache_dirs(); |
46 | 46 | if ($phpfile) { |
47 | 47 | $z = $phpfile; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | // add a layer of subdirectories for reducing file lookup time |
54 | - $sz = substr(md5($z."_".urlencode($params)),1,2); |
|
54 | + $sz = substr(md5($z."_".urlencode($params)), 1, 2); |
|
55 | 55 | $path = "../cache/".$sz."/".$z; |
56 | 56 | if ($params) { |
57 | 57 | $path = $path."_".urlencode($params); |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | function disk_usage($dir) { |
63 | - $usage=0; |
|
64 | - if ($handle=@opendir($dir)) { |
|
65 | - while ($file=readdir($handle)) { |
|
63 | + $usage = 0; |
|
64 | + if ($handle = @opendir($dir)) { |
|
65 | + while ($file = readdir($handle)) { |
|
66 | 66 | if (($file != ".") && ($file != "..")) { |
67 | 67 | if (@is_dir($dir."/".$file)) { |
68 | - $usage+=disk_usage($dir."/".$file); |
|
68 | + $usage += disk_usage($dir."/".$file); |
|
69 | 69 | } else { |
70 | - $usage+=@filesize($dir."/".$file); |
|
70 | + $usage += @filesize($dir."/".$file); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | if (!chdir($dir)) { |
82 | 82 | return; |
83 | 83 | } |
84 | - if ($handle=@opendir(".")) { |
|
85 | - while ($file=readdir($handle)) { |
|
84 | + if ($handle = @opendir(".")) { |
|
85 | + while ($file = readdir($handle)) { |
|
86 | 86 | if ($file == ".") continue; |
87 | 87 | if ($file == "..") continue; |
88 | 88 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (@is_dir($file)) { |
94 | 94 | clean_cache($max_age, $file); |
95 | 95 | } else { |
96 | - if ((time()-@filemtime($file))>$max_age) { |
|
96 | + if ((time() - @filemtime($file)) > $max_age) { |
|
97 | 97 | //echo "unlinking ".getcwd()."/$file\n"; |
98 | 98 | @unlink($file); |
99 | 99 | } |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | |
108 | 108 | // check cache size every once in a while, purge if too big |
109 | 109 | // |
110 | -function cache_check_diskspace(){ |
|
111 | - if ((rand() % CACHE_SIZE_CHECK_FREQ)) return; |
|
110 | +function cache_check_diskspace() { |
|
111 | + if ((rand()%CACHE_SIZE_CHECK_FREQ)) return; |
|
112 | 112 | if (disk_usage("../cache") < MAX_CACHE_USAGE) return; |
113 | 113 | $x = max(TEAM_PAGE_TTL, USER_PAGE_TTL, USER_HOST_TTL, |
114 | 114 | USER_PROFILE_TTL, TOP_PAGES_TTL, INDEX_PAGE_TTL |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | clean_cache($x, "../cache"); |
117 | 117 | } |
118 | 118 | |
119 | -function cache_need_to_regenerate($path, $max_age){ |
|
119 | +function cache_need_to_regenerate($path, $max_age) { |
|
120 | 120 | $regenerate = false; |
121 | 121 | $request = apache_request_headers(); |
122 | 122 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | // and touch the cached copy so other processes |
129 | 129 | // don't regenerate at the same time |
130 | 130 | // |
131 | - if ($lastmodified<time()-$max_age) { |
|
131 | + if ($lastmodified < time() - $max_age) { |
|
132 | 132 | $regenerate = true; |
133 | 133 | @touch($path); |
134 | 134 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // Returns cached data or false if nothing was found |
142 | -function get_cached_data($max_age, $params=""){ |
|
142 | +function get_cached_data($max_age, $params = "") { |
|
143 | 143 | global $no_cache; |
144 | 144 | |
145 | 145 | if ($no_cache) return; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | } else { |
157 | 157 | cache_check_diskspace(); |
158 | - $regenerate=cache_need_to_regenerate($path, $max_age); |
|
158 | + $regenerate = cache_need_to_regenerate($path, $max_age); |
|
159 | 159 | if (!$regenerate) { |
160 | 160 | return file_get_contents($path); |
161 | 161 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | // DEPRECATED |
168 | -function start_cache($max_age, $params=""){ |
|
168 | +function start_cache($max_age, $params = "") { |
|
169 | 169 | global $no_cache, $caching, $memcache; |
170 | 170 | |
171 | 171 | if ($no_cache) return; |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | $regenerate = cache_need_to_regenerate($path, $max_age); |
189 | 189 | } |
190 | 190 | //Is the stored version too old, do we need to regenerate it? |
191 | - if ($regenerate){ |
|
191 | + if ($regenerate) { |
|
192 | 192 | // If cached version is too old (or non-existent) |
193 | 193 | // generate the page and write to cache |
194 | 194 | // |
195 | 195 | ob_start(); |
196 | 196 | ob_implicit_flush(0); |
197 | - Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
198 | - Header("Expires: " . gmdate("D, d M Y H:i:s",time()+$max_age) . " GMT"); |
|
199 | - Header("Cache-Control: public, max-age=" . $max_age); |
|
197 | + Header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
198 | + Header("Expires: ".gmdate("D, d M Y H:i:s", time() + $max_age)." GMT"); |
|
199 | + Header("Cache-Control: public, max-age=".$max_age); |
|
200 | 200 | |
201 | 201 | // allow the calling page to see cache period |
202 | 202 | // |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | if (strstr($params, "format=xml")) { |
209 | 209 | header('Content-type: text/xml'); |
210 | 210 | } |
211 | - Header("Last-Modified: " . gmdate("D, d M Y H:i:s",$lastmodified) . " GMT"); |
|
212 | - Header("Expires: " . gmdate("D, d M Y H:i:s",$lastmodified+$max_age) . " GMT"); |
|
213 | - Header("Cache-Control: public, max-age=" . $max_age ); |
|
211 | + Header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastmodified)." GMT"); |
|
212 | + Header("Expires: ".gmdate("D, d M Y H:i:s", $lastmodified + $max_age)." GMT"); |
|
213 | + Header("Cache-Control: public, max-age=".$max_age); |
|
214 | 214 | if ($cache && $cache->content) { |
215 | 215 | echo $cache->content; |
216 | 216 | exit; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | // write output buffer both to client and to cache |
230 | 230 | // DEPRECATED |
231 | -function end_cache($max_age,$params=""){ |
|
231 | +function end_cache($max_age, $params = "") { |
|
232 | 232 | global $no_cache; |
233 | 233 | if ($no_cache) return; |
234 | 234 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | -function set_cached_data($max_age, $data, $params=""){ |
|
256 | +function set_cached_data($max_age, $data, $params = "") { |
|
257 | 257 | // for the benefit of hackers |
258 | 258 | if (strstr($params, "..")) { |
259 | 259 | return "bad params"; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | self::$instance->setOption(Memcached::OPT_PREFIX_KEY, MEMCACHE_PREFIX); |
295 | 295 | } |
296 | 296 | $servers = explode('|', MEMCACHE_SERVERS); |
297 | - foreach($servers as &$server) { |
|
297 | + foreach ($servers as &$server) { |
|
298 | 298 | list($ip, $port) = explode(':', $server); |
299 | 299 | if (!$port) { $port = 11211; } |
300 | 300 | $server = array($ip, $port); |
@@ -42,7 +42,9 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | function get_path($params, $phpfile=null) { |
45 | - if (!@filemtime("../cache/00")) make_cache_dirs(); |
|
45 | + if (!@filemtime("../cache/00")) { |
|
46 | + make_cache_dirs(); |
|
47 | + } |
|
46 | 48 | if ($phpfile) { |
47 | 49 | $z = $phpfile; |
48 | 50 | } else { |
@@ -83,8 +85,12 @@ discard block |
||
83 | 85 | } |
84 | 86 | if ($handle=@opendir(".")) { |
85 | 87 | while ($file=readdir($handle)) { |
86 | - if ($file == ".") continue; |
|
87 | - if ($file == "..") continue; |
|
88 | + if ($file == ".") { |
|
89 | + continue; |
|
90 | + } |
|
91 | + if ($file == "..") { |
|
92 | + continue; |
|
93 | + } |
|
88 | 94 | |
89 | 95 | // don't let hackers trick us into deleting other files! |
90 | 96 | if (strstr($file, "..")) { |
@@ -108,8 +114,12 @@ discard block |
||
108 | 114 | // check cache size every once in a while, purge if too big |
109 | 115 | // |
110 | 116 | function cache_check_diskspace(){ |
111 | - if ((rand() % CACHE_SIZE_CHECK_FREQ)) return; |
|
112 | - if (disk_usage("../cache") < MAX_CACHE_USAGE) return; |
|
117 | + if ((rand() % CACHE_SIZE_CHECK_FREQ)) { |
|
118 | + return; |
|
119 | + } |
|
120 | + if (disk_usage("../cache") < MAX_CACHE_USAGE) { |
|
121 | + return; |
|
122 | + } |
|
113 | 123 | $x = max(TEAM_PAGE_TTL, USER_PAGE_TTL, USER_HOST_TTL, |
114 | 124 | USER_PROFILE_TTL, TOP_PAGES_TTL, INDEX_PAGE_TTL |
115 | 125 | ); |
@@ -142,7 +152,9 @@ discard block |
||
142 | 152 | function get_cached_data($max_age, $params=""){ |
143 | 153 | global $no_cache; |
144 | 154 | |
145 | - if ($no_cache) return; |
|
155 | + if ($no_cache) { |
|
156 | + return; |
|
157 | + } |
|
146 | 158 | |
147 | 159 | $path = get_path($params); |
148 | 160 | if ($max_age) { |
@@ -168,7 +180,9 @@ discard block |
||
168 | 180 | function start_cache($max_age, $params=""){ |
169 | 181 | global $no_cache, $caching, $memcache; |
170 | 182 | |
171 | - if ($no_cache) return; |
|
183 | + if ($no_cache) { |
|
184 | + return; |
|
185 | + } |
|
172 | 186 | $caching = true; |
173 | 187 | |
174 | 188 | if ($max_age) { |
@@ -230,7 +244,9 @@ discard block |
||
230 | 244 | // DEPRECATED |
231 | 245 | function end_cache($max_age,$params=""){ |
232 | 246 | global $no_cache; |
233 | - if ($no_cache) return; |
|
247 | + if ($no_cache) { |
|
248 | + return; |
|
249 | + } |
|
234 | 250 | |
235 | 251 | // for the benefit of hackers |
236 | 252 | if (strstr($params, "..")) { |
@@ -37,6 +37,9 @@ |
||
37 | 37 | $ops = number_format($ops, 2); |
38 | 38 | } |
39 | 39 | |
40 | +/** |
|
41 | + * @param boolean $bolden |
|
42 | + */ |
|
40 | 43 | function credit_string($credit, $bolden) { |
41 | 44 | $cobbs = number_format($credit, 0); |
42 | 45 |
@@ -43,10 +43,10 @@ |
||
43 | 43 | credit_to_ops($credit, $ops, $unit); |
44 | 44 | |
45 | 45 | if ($bolden) { |
46 | - $lbold="[["; |
|
47 | - $rbold="]]"; |
|
46 | + $lbold = "[["; |
|
47 | + $rbold = "]]"; |
|
48 | 48 | } else { |
49 | - $lbold=""; $rbold=""; |
|
49 | + $lbold = ""; $rbold = ""; |
|
50 | 50 | } |
51 | 51 | return " $lbold$cobbs Cobblestones$rbold of computation ($ops $unit floating-point operations)"; |
52 | 52 | } |
@@ -69,6 +69,10 @@ discard block |
||
69 | 69 | function _mysql_fetch_row($r) { |
70 | 70 | return mysqli_fetch_row($r); |
71 | 71 | } |
72 | + |
|
73 | + /** |
|
74 | + * @param resource $r |
|
75 | + */ |
|
72 | 76 | function _mysql_fetch_assoc($r) { |
73 | 77 | return mysqli_fetch_assoc($r); |
74 | 78 | } |
@@ -132,6 +136,10 @@ discard block |
||
132 | 136 | function _mysql_fetch_row($r) { |
133 | 137 | return mysql_fetch_row($r); |
134 | 138 | } |
139 | + |
|
140 | + /** |
|
141 | + * @param resource $r |
|
142 | + */ |
|
135 | 143 | function _mysql_fetch_assoc($r) { |
136 | 144 | return mysql_fetch_assoc($r); |
137 | 145 | } |
@@ -86,14 +86,14 @@ |
||
86 | 86 | function _mysql_field_attrs($r, $i) { |
87 | 87 | $x = mysqli_fetch_field_direct($r, $i); |
88 | 88 | switch ($x->type) { |
89 | - case 1: $x->type = 'tinyint'; break; |
|
90 | - case 2: $x->type = 'smallint'; break; |
|
91 | - case 3: $x->type = 'int'; break; |
|
92 | - case 5: $x->type = 'double'; break; |
|
93 | - case 7: $x->type = 'timestamp'; break; |
|
94 | - case 252: $x->type = 'blob'; break; |
|
95 | - case 253: $x->type = 'varchar'; break; |
|
96 | - case 254: $x->type = 'char'; break; |
|
89 | + case 1: $x->type = 'tinyint'; break; |
|
90 | + case 2: $x->type = 'smallint'; break; |
|
91 | + case 3: $x->type = 'int'; break; |
|
92 | + case 5: $x->type = 'double'; break; |
|
93 | + case 7: $x->type = 'timestamp'; break; |
|
94 | + case 252: $x->type = 'blob'; break; |
|
95 | + case 253: $x->type = 'varchar'; break; |
|
96 | + case 254: $x->type = 'char'; break; |
|
97 | 97 | } |
98 | 98 | return $x; |
99 | 99 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | function _mysql_connect($host, $user, $pass, $dbname) { |
44 | 44 | global $mysqli; |
45 | 45 | $x = explode(":", $host); |
46 | - if (sizeof($x)>1) { |
|
46 | + if (sizeof($x) > 1) { |
|
47 | 47 | $host = $x[0]; |
48 | 48 | $port = $x[1]; |
49 | 49 | } else { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | -function db_init_aux($try_replica=false) { |
|
165 | +function db_init_aux($try_replica = false) { |
|
166 | 166 | $config = get_config(); |
167 | 167 | $user = parse_config($config, "<db_user>"); |
168 | 168 | $pass = parse_config($config, "<db_passwd>"); |
@@ -111,7 +111,9 @@ discard block |
||
111 | 111 | } else { |
112 | 112 | function _mysql_connect($host, $user, $pass, $db_name) { |
113 | 113 | $link = mysql_pconnect($host, $user, $pass); |
114 | - if (!$link) return null; |
|
114 | + if (!$link) { |
|
115 | + return null; |
|
116 | + } |
|
115 | 117 | if (!mysql_select_db($db_name, $link)) { |
116 | 118 | return null; |
117 | 119 | } |
@@ -173,11 +175,17 @@ discard block |
||
173 | 175 | if ($x) { |
174 | 176 | $host = $x; |
175 | 177 | $x = parse_config($config, "<replica_db_user>"); |
176 | - if ($x) $user = $x; |
|
178 | + if ($x) { |
|
179 | + $user = $x; |
|
180 | + } |
|
177 | 181 | $x = parse_config($config, "<replica_db_passwd>"); |
178 | - if ($x) $pass = $x; |
|
182 | + if ($x) { |
|
183 | + $pass = $x; |
|
184 | + } |
|
179 | 185 | $x = parse_config($config, "<replica_db_name>"); |
180 | - if ($x) $db_name = $x; |
|
186 | + if ($x) { |
|
187 | + $db_name = $x; |
|
188 | + } |
|
181 | 189 | } |
182 | 190 | } |
183 | 191 | if ($host == null) { |
@@ -26,6 +26,9 @@ discard block |
||
26 | 26 | var $db_name; |
27 | 27 | var $readonly; |
28 | 28 | |
29 | + /** |
|
30 | + * @param boolean $readonly |
|
31 | + */ |
|
29 | 32 | function init_conn($user, $passwd, $host, $name, $readonly) { |
30 | 33 | if (MYSQLI) { |
31 | 34 | $x = explode(":", $host); |
@@ -112,6 +115,10 @@ discard block |
||
112 | 115 | return $this->lookup_fields($table, $classname, "*", $clause); |
113 | 116 | } |
114 | 117 | |
118 | + /** |
|
119 | + * @param string $table |
|
120 | + * @param string $classname |
|
121 | + */ |
|
115 | 122 | function lookup_id($id, $table, $classname) { |
116 | 123 | $id = (int)$id; |
117 | 124 | return $this->lookup($table, $classname, "id=$id"); |
@@ -146,28 +153,51 @@ discard block |
||
146 | 153 | return $this->enum_general($classname,$query); |
147 | 154 | } |
148 | 155 | |
156 | + /** |
|
157 | + * @param string $table |
|
158 | + * @param string $classname |
|
159 | + */ |
|
149 | 160 | function enum($table, $classname, $where_clause=null, $order_clause=null) { |
150 | 161 | return self::enum_fields( |
151 | 162 | $table, $classname, '*', $where_clause, $order_clause |
152 | 163 | ); |
153 | 164 | } |
154 | 165 | |
166 | + /** |
|
167 | + * @param string $table |
|
168 | + */ |
|
155 | 169 | function update($obj, $table, $clause) { |
156 | 170 | $query = "update DBNAME.$table set $clause where id=$obj->id"; |
157 | 171 | return $this->do_query($query); |
158 | 172 | } |
173 | + |
|
174 | + /** |
|
175 | + * @param string $table |
|
176 | + */ |
|
159 | 177 | function update_aux($table, $clause) { |
160 | 178 | $query = "update DBNAME.$table set $clause"; |
161 | 179 | return $this->do_query($query); |
162 | 180 | } |
181 | + |
|
182 | + /** |
|
183 | + * @param string $table |
|
184 | + */ |
|
163 | 185 | function insert($table, $clause) { |
164 | 186 | $query = "insert into DBNAME.$table $clause"; |
165 | 187 | return $this->do_query($query); |
166 | 188 | } |
189 | + |
|
190 | + /** |
|
191 | + * @param string $table |
|
192 | + */ |
|
167 | 193 | function delete($obj, $table) { |
168 | 194 | $query = "delete from DBNAME.$table where id=$obj->id"; |
169 | 195 | return $this->do_query($query); |
170 | 196 | } |
197 | + |
|
198 | + /** |
|
199 | + * @param string $table |
|
200 | + */ |
|
171 | 201 | function delete_aux($table, $clause) { |
172 | 202 | $query = "delete from DBNAME.$table where $clause"; |
173 | 203 | return $this->do_query($query); |
@@ -179,6 +209,10 @@ discard block |
||
179 | 209 | return mysql_insert_id($this->db_conn); |
180 | 210 | } |
181 | 211 | } |
212 | + |
|
213 | + /** |
|
214 | + * @param string $field |
|
215 | + */ |
|
182 | 216 | function get_int($query, $field) { |
183 | 217 | $result = $this->do_query($query); |
184 | 218 | if (!$result) error_page("database error on query $query"); |
@@ -209,14 +243,26 @@ discard block |
||
209 | 243 | $query = "select count(*) as total from DBNAME.$table where $clause"; |
210 | 244 | return $this->get_int($query, 'total'); |
211 | 245 | } |
246 | + |
|
247 | + /** |
|
248 | + * @param string $table |
|
249 | + */ |
|
212 | 250 | function sum($table, $field, $clause="") { |
213 | 251 | $query = "select sum($field) as total from DBNAME.$table $clause"; |
214 | 252 | return $this->get_double($query, 'total'); |
215 | 253 | } |
254 | + |
|
255 | + /** |
|
256 | + * @param string $table |
|
257 | + */ |
|
216 | 258 | function max($table, $field, $clause="") { |
217 | 259 | $query = "select max($field) as total from DBNAME.$table $clause"; |
218 | 260 | return $this->get_double($query, 'total'); |
219 | 261 | } |
262 | + |
|
263 | + /** |
|
264 | + * @param string $table |
|
265 | + */ |
|
220 | 266 | function percentile($table, $field, $clause, $pct) { |
221 | 267 | $n = $this->count($table, $clause); |
222 | 268 | if (!$n) return false; |
@@ -224,6 +270,10 @@ discard block |
||
224 | 270 | $query = "select $field from DBNAME.$table where $clause order by $field limit $m,1"; |
225 | 271 | return $this->get_double($query, $field); |
226 | 272 | } |
273 | + |
|
274 | + /** |
|
275 | + * @param string $table |
|
276 | + */ |
|
227 | 277 | function replace($table, $clause) { |
228 | 278 | $query = "replace into DBNAME.$table set $clause"; |
229 | 279 | return $this->do_query($query); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | function init_conn($user, $passwd, $host, $name, $readonly) { |
30 | 30 | if (MYSQLI) { |
31 | 31 | $x = explode(":", $host); |
32 | - if (sizeof($x)>1) { |
|
32 | + if (sizeof($x) > 1) { |
|
33 | 33 | $host = $x[0]; |
34 | 34 | $port = $x[1]; |
35 | 35 | } else { |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | $where_clause = "where $where_clause"; |
144 | 144 | } |
145 | 145 | $query = "select $fields from DBNAME.$table $where_clause $order_clause"; |
146 | - return $this->enum_general($classname,$query); |
|
146 | + return $this->enum_general($classname, $query); |
|
147 | 147 | } |
148 | 148 | |
149 | - function enum($table, $classname, $where_clause=null, $order_clause=null) { |
|
149 | + function enum($table, $classname, $where_clause = null, $order_clause = null) { |
|
150 | 150 | return self::enum_fields( |
151 | 151 | $table, $classname, '*', $where_clause, $order_clause |
152 | 152 | ); |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | if ($x) return (double)$x->$field; |
206 | 206 | return false; |
207 | 207 | } |
208 | - function count($table, $clause="TRUE") { |
|
208 | + function count($table, $clause = "TRUE") { |
|
209 | 209 | $query = "select count(*) as total from DBNAME.$table where $clause"; |
210 | 210 | return $this->get_int($query, 'total'); |
211 | 211 | } |
212 | - function sum($table, $field, $clause="") { |
|
212 | + function sum($table, $field, $clause = "") { |
|
213 | 213 | $query = "select sum($field) as total from DBNAME.$table $clause"; |
214 | 214 | return $this->get_double($query, 'total'); |
215 | 215 | } |
216 | - function max($table, $field, $clause="") { |
|
216 | + function max($table, $field, $clause = "") { |
|
217 | 217 | $query = "select max($field) as total from DBNAME.$table $clause"; |
218 | 218 | return $this->get_double($query, 'total'); |
219 | 219 | } |
@@ -119,7 +119,9 @@ discard block |
||
119 | 119 | |
120 | 120 | function enum_general($classname, $query) { |
121 | 121 | $result = $this->do_query($query); |
122 | - if (!$result) return null; |
|
122 | + if (!$result) { |
|
123 | + return null; |
|
124 | + } |
|
123 | 125 | $x = array(); |
124 | 126 | if (MYSQLI) { |
125 | 127 | while ($obj = $result->fetch_object($classname)) { |
@@ -181,7 +183,9 @@ discard block |
||
181 | 183 | } |
182 | 184 | function get_int($query, $field) { |
183 | 185 | $result = $this->do_query($query); |
184 | - if (!$result) error_page("database error on query $query"); |
|
186 | + if (!$result) { |
|
187 | + error_page("database error on query $query"); |
|
188 | + } |
|
185 | 189 | if (MYSQLI) { |
186 | 190 | $x = $result->fetch_object("StdClass"); |
187 | 191 | $result->free(); |
@@ -189,12 +193,16 @@ discard block |
||
189 | 193 | $x = mysql_fetch_object($result); |
190 | 194 | mysql_free_result($result); |
191 | 195 | } |
192 | - if ($x) return $x->$field; |
|
196 | + if ($x) { |
|
197 | + return $x->$field; |
|
198 | + } |
|
193 | 199 | return false; |
194 | 200 | } |
195 | 201 | function get_double($query, $field) { |
196 | 202 | $result = $this->do_query($query); |
197 | - if (!$result) error_page("database error on query $query"); |
|
203 | + if (!$result) { |
|
204 | + error_page("database error on query $query"); |
|
205 | + } |
|
198 | 206 | if (MYSQLI) { |
199 | 207 | $x = $result->fetch_object("StdClass"); |
200 | 208 | $result->free(); |
@@ -202,7 +210,9 @@ discard block |
||
202 | 210 | $x = mysql_fetch_object($result); |
203 | 211 | mysql_free_result($result); |
204 | 212 | } |
205 | - if ($x) return (double)$x->$field; |
|
213 | + if ($x) { |
|
214 | + return (double)$x->$field; |
|
215 | + } |
|
206 | 216 | return false; |
207 | 217 | } |
208 | 218 | function count($table, $clause="TRUE") { |
@@ -219,7 +229,9 @@ discard block |
||
219 | 229 | } |
220 | 230 | function percentile($table, $field, $clause, $pct) { |
221 | 231 | $n = $this->count($table, $clause); |
222 | - if (!$n) return false; |
|
232 | + if (!$n) { |
|
233 | + return false; |
|
234 | + } |
|
223 | 235 | $m = (int)($n*$pct/100); |
224 | 236 | $query = "select $field from DBNAME.$table where $clause order by $field limit $m,1"; |
225 | 237 | return $this->get_double($query, $field); |
@@ -251,10 +263,14 @@ discard block |
||
251 | 263 | } |
252 | 264 | function table_exists($table_name) { |
253 | 265 | $result = $this->do_query("show tables from DBNAME like '$table_name'"); |
254 | - if (!$result) error_page("database error on query $query"); |
|
266 | + if (!$result) { |
|
267 | + error_page("database error on query $query"); |
|
268 | + } |
|
255 | 269 | $t = _mysql_fetch_array($result); |
256 | 270 | _mysql_free_result($result); |
257 | - if ($t[0] == "$table_name") return true; |
|
271 | + if ($t[0] == "$table_name") { |
|
272 | + return true; |
|
273 | + } |
|
258 | 274 | return false; |
259 | 275 | } |
260 | 276 | } |
@@ -103,6 +103,9 @@ discard block |
||
103 | 103 | |
104 | 104 | // Function prints a description of $table |
105 | 105 | // |
106 | +/** |
|
107 | + * @param integer $which |
|
108 | + */ |
|
106 | 109 | function print_describe_table_onecol($table, $which, $columns) { |
107 | 110 | $db = BoincDb::get(true); |
108 | 111 | $result = $db->do_query("SELECT * from $table LIMIT 1"); |
@@ -262,6 +265,10 @@ discard block |
||
262 | 265 | $this->urlquery .= "&clauses=$clause"; |
263 | 266 | } |
264 | 267 | } |
268 | + |
|
269 | + /** |
|
270 | + * @param string $name |
|
271 | + */ |
|
265 | 272 | function addeq($name) { |
266 | 273 | if (isset($_GET[$name])) { |
267 | 274 | $value = $_GET[$name]; |
@@ -273,6 +280,10 @@ discard block |
||
273 | 280 | $this->urlquery .= "&$name=".urlencode($value); |
274 | 281 | } |
275 | 282 | } |
283 | + |
|
284 | + /** |
|
285 | + * @param string $name |
|
286 | + */ |
|
276 | 287 | function addeq_not_CHOOSE_ALL($name) { |
277 | 288 | if (isset($_GET[$name])) { |
278 | 289 | $value = $_GET[$name]; |
@@ -287,6 +298,10 @@ discard block |
||
287 | 298 | $this->urlquery .= "&$name=".urlencode($value); |
288 | 299 | } |
289 | 300 | } |
301 | + |
|
302 | + /** |
|
303 | + * @param string $name |
|
304 | + */ |
|
290 | 305 | function addgt($name) { |
291 | 306 | if (isset($_GET[$name])) { |
292 | 307 | $value = $_GET[$name]; |
@@ -298,6 +313,11 @@ discard block |
||
298 | 313 | $this->urlquery .= "&$name=".urlencode($value); |
299 | 314 | } |
300 | 315 | } |
316 | + |
|
317 | + /** |
|
318 | + * @param string $name |
|
319 | + * @param string $order |
|
320 | + */ |
|
301 | 321 | function addsort($name, $order) { |
302 | 322 | if (isset($_GET[$name])) { |
303 | 323 | $value = $_GET[$name]; |
@@ -375,6 +395,9 @@ discard block |
||
375 | 395 | } |
376 | 396 | |
377 | 397 | |
398 | +/** |
|
399 | + * @param string $mq |
|
400 | + */ |
|
378 | 401 | function link_results($n, $mq, $query, $clauses) { |
379 | 402 | if ($n == '0') { // intentional compare by string |
380 | 403 | return "0"; |
@@ -824,6 +847,9 @@ discard block |
||
824 | 847 | return number_format($x/86400, 2)." days"; |
825 | 848 | } |
826 | 849 | |
850 | +/** |
|
851 | + * @param integer $x |
|
852 | + */ |
|
827 | 853 | function resource_name($x) { |
828 | 854 | switch ($x) { |
829 | 855 | case 2: return "CPU"; |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $value=null; |
306 | 306 | } |
307 | 307 | if (isset($_GET[$order])) { |
308 | - $order = $_GET[$order]; |
|
308 | + $order = $_GET[$order]; |
|
309 | 309 | } else { |
310 | - $order = null; |
|
310 | + $order = null; |
|
311 | 311 | } |
312 | 312 | if (strlen($value)) { |
313 | 313 | if ($order == 'asc') { |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | $res = new StdClass; |
576 | 576 | $res->server_state = $ss; |
577 | 577 | row2(result_server_state_string($res), |
578 | - link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
578 | + link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
579 | 579 | ); |
580 | 580 | } |
581 | 581 | echo "</table></td>"; |
@@ -1026,8 +1026,8 @@ discard block |
||
1026 | 1026 | |
1027 | 1027 | function validate_color($validate_state) { |
1028 | 1028 | switch ($validate_state) { |
1029 | - case 1: return '33cc33'; // valid, green |
|
1030 | - case 2: return 'ffa500'; // invalid result, orange |
|
1029 | + case 1: return '33cc33'; // valid, green |
|
1030 | + case 2: return 'ffa500'; // invalid result, orange |
|
1031 | 1031 | } |
1032 | 1032 | return ''; |
1033 | 1033 | } |
@@ -40,27 +40,27 @@ discard block |
||
40 | 40 | // @return String A user readable DateTime-String in UTC |
41 | 41 | // @param Integer $x The mysql-Timestamp to convert |
42 | 42 | function mysqltime_str($x) { |
43 | - if(strpos($x,"-")==4) { |
|
43 | + if (strpos($x, "-") == 4) { |
|
44 | 44 | // Syntax of supplied mysql-timestamp is YYYY-MM-DD HH:MM:SS |
45 | - $year = substr($x,0,4); |
|
46 | - $month = substr($x,5,2); |
|
47 | - $day = substr($x,8,2); |
|
48 | - $hour = substr($x,11,2); |
|
49 | - $minute = substr($x,14,2); |
|
50 | - $second = substr($x,17,2); |
|
45 | + $year = substr($x, 0, 4); |
|
46 | + $month = substr($x, 5, 2); |
|
47 | + $day = substr($x, 8, 2); |
|
48 | + $hour = substr($x, 11, 2); |
|
49 | + $minute = substr($x, 14, 2); |
|
50 | + $second = substr($x, 17, 2); |
|
51 | 51 | } else { |
52 | 52 | // Syntax of supplied mysql-timestamp is YYYYMMDDHHMMSS |
53 | - $year = substr($x,0,4); |
|
54 | - $month = substr($x,4,2); |
|
55 | - $day = substr($x,6,2); |
|
56 | - $hour = substr($x,8,2); |
|
57 | - $minute = substr($x,10,2); |
|
58 | - $second = substr($x,12,2); |
|
53 | + $year = substr($x, 0, 4); |
|
54 | + $month = substr($x, 4, 2); |
|
55 | + $day = substr($x, 6, 2); |
|
56 | + $hour = substr($x, 8, 2); |
|
57 | + $minute = substr($x, 10, 2); |
|
58 | + $second = substr($x, 12, 2); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 | //make a Unix-Timestamp |
62 | 62 | // echo "Time string is " . "$x"; |
63 | - $time = mktime($hour,$minute,$second,$month,$day,$year); |
|
63 | + $time = mktime($hour, $minute, $second, $month, $day, $year); |
|
64 | 64 | return time_str($time); |
65 | 65 | } |
66 | 66 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $constants = get_defined_constants(true); |
99 | 99 | foreach ($constants['mysqli'] as $c => $n) if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
100 | 100 | } |
101 | - return array_key_exists($type_id, $types)? strtolower($types[$type_id]) : "unknown"; |
|
101 | + return array_key_exists($type_id, $types) ? strtolower($types[$type_id]) : "unknown"; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Function prints a description of $table |
@@ -108,38 +108,38 @@ discard block |
||
108 | 108 | $result = $db->do_query("SELECT * from $table LIMIT 1"); |
109 | 109 | $fields = $result->field_count; |
110 | 110 | |
111 | - $avgnum=(int)($fields/$columns); |
|
112 | - if ($avgnum*$columns<$fields) { |
|
111 | + $avgnum = (int)($fields/$columns); |
|
112 | + if ($avgnum*$columns < $fields) { |
|
113 | 113 | $avgnum++; |
114 | 114 | } |
115 | 115 | |
116 | - $actualcolumns=0; |
|
117 | - while ($avgnum*$actualcolumns<$fields) { |
|
116 | + $actualcolumns = 0; |
|
117 | + while ($avgnum*$actualcolumns < $fields) { |
|
118 | 118 | $actualcolumns++; |
119 | 119 | } |
120 | 120 | |
121 | - if ($which>$actualcolumns) { |
|
121 | + if ($which > $actualcolumns) { |
|
122 | 122 | return 0; |
123 | 123 | } |
124 | 124 | |
125 | - $bot=($which-1)*$avgnum; |
|
126 | - $top=$which*$avgnum; |
|
125 | + $bot = ($which - 1)*$avgnum; |
|
126 | + $top = $which*$avgnum; |
|
127 | 127 | |
128 | - $width=100.0/$actualcolumns; |
|
128 | + $width = 100.0/$actualcolumns; |
|
129 | 129 | |
130 | 130 | // echo "<td><table border='2' width=\"$width%\">\n"; |
131 | 131 | echo "<td><table border=\"1\" width=\"100%\">\n"; |
132 | 132 | echo "<tr><th align=\"left\">NAME</th><th align=\"left\">Type</th><th align=\"left\">Bytes</th>\n"; |
133 | - for ($count=$bot; $count<$top; $count++) { |
|
134 | - if ($count<$fields) { |
|
133 | + for ($count = $bot; $count < $top; $count++) { |
|
134 | + if ($count < $fields) { |
|
135 | 135 | $x = $result->fetch_field_direct($count); |
136 | 136 | $name = $x->name; |
137 | 137 | $type = mysql_fieldtype_str($x->type); |
138 | 138 | $length = $x->length; |
139 | 139 | } else { |
140 | - $name="<br/> "; |
|
141 | - $type="<br/>"; |
|
142 | - $length="<br/>"; |
|
140 | + $name = "<br/> "; |
|
141 | + $type = "<br/>"; |
|
142 | + $length = "<br/>"; |
|
143 | 143 | } |
144 | 144 | echo "\t<tr><td><b>$name</b></td><td>$type</td><td>$length</td></tr>\n"; |
145 | 145 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // Number of columns for showing table description |
153 | 153 | echo "<h2>Description of <b>$table</b> table fields:</h2>\n"; |
154 | 154 | echo "<table border=\"0\" width=\"100%\">\n\t<tr>"; |
155 | - for ($i=1; $i<=$how_many_columns; $i++) { |
|
155 | + for ($i = 1; $i <= $how_many_columns; $i++) { |
|
156 | 156 | print_describe_table_onecol($table, $i, $how_many_columns); |
157 | 157 | } |
158 | 158 | echo "\t</tr>\n</table>\n"; |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | function print_query_field() { |
173 | - $currenttime=time(); |
|
174 | - $hourago=$currenttime-3600; |
|
175 | - $dayago=$currenttime-24*3600; |
|
176 | - $weekago=$currenttime-7*24*3600; |
|
173 | + $currenttime = time(); |
|
174 | + $hourago = $currenttime - 3600; |
|
175 | + $dayago = $currenttime - 24*3600; |
|
176 | + $weekago = $currenttime - 7*24*3600; |
|
177 | 177 | echo " |
178 | 178 | <tr> |
179 | 179 | <td align=\"right\">Additional clauses</td> |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | -function append_sql_query($original,$addition,$first) { |
|
200 | +function append_sql_query($original, $addition, $first) { |
|
201 | 201 | if ($first == 1) { |
202 | - return $original . " where " . $addition; |
|
202 | + return $original." where ".$addition; |
|
203 | 203 | } else { |
204 | - return $original . " and " . $addition; |
|
204 | + return $original." and ".$addition; |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | if (isset($_GET[$name])) { |
303 | 303 | $value = $_GET[$name]; |
304 | 304 | } else { |
305 | - $value=null; |
|
305 | + $value = null; |
|
306 | 306 | } |
307 | 307 | if (isset($_GET[$order])) { |
308 | 308 | $order = $_GET[$order]; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | function get_url($base = "db_action.php") { |
346 | - $s = $base . "?table=$this->table$this->urlquery"; |
|
346 | + $s = $base."?table=$this->table$this->urlquery"; |
|
347 | 347 | return $s; |
348 | 348 | } |
349 | 349 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | $this->addeq('app_version_id'); |
359 | 359 | $this->addeq('exit_status'); |
360 | 360 | if (isset($_GET['nsecs'])) { |
361 | - $_GET['mod_time'] = date("YmdHis",time() - $_GET['nsecs']); |
|
361 | + $_GET['mod_time'] = date("YmdHis", time() - $_GET['nsecs']); |
|
362 | 362 | } |
363 | 363 | $this->addgt('mod_time'); |
364 | 364 | $this->addeq_not_CHOOSE_ALL('server_state'); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | if ($n == '0') { // intentional compare by string |
380 | 380 | return "0"; |
381 | 381 | } else { |
382 | - if(strlen($clauses)) { |
|
382 | + if (strlen($clauses)) { |
|
383 | 383 | return "<a href=\"db_action.php?table=result&query=$mq&$query&clauses=".urlencode($clauses)."&sort_by=mod_time&detail=low\">$n</a>"; |
384 | 384 | } |
385 | 385 | else { |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | // Determines if in stderr_out is an error reported and prints as human readable String |
393 | 393 | // @return String A human readable string if error otherwise FALSE |
394 | 394 | // @param String $stderr_out the stderr_out value to parse |
395 | -function stderr_error_string($stderr_out){ |
|
395 | +function stderr_error_string($stderr_out) { |
|
396 | 396 | $y = parse_element($stderr_out, "<error_code>"); |
397 | 397 | $x = 0; |
398 | 398 | if ($y) { |
399 | 399 | $x = (int)$y; |
400 | 400 | } |
401 | - if (0<=$x && $x<=9) { |
|
401 | + if (0 <= $x && $x <= 9) { |
|
402 | 402 | return FALSE; |
403 | 403 | } else { |
404 | 404 | return "$x ".error_code_str($x); |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | |
408 | 408 | function show_result_summary() { |
409 | 409 | |
410 | - $ntotal =0; // TODO: how to count $result? |
|
411 | - $nvalid = 0; // for SUCCESS results |
|
410 | + $ntotal = 0; // TODO: how to count $result? |
|
411 | + $nvalid = 0; // for SUCCESS results |
|
412 | 412 | $ninvalid = 0; |
413 | 413 | $nfile_deleted = 0; |
414 | 414 | |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $outcome = array(); |
417 | 417 | $client_state = array(); |
418 | 418 | |
419 | - for ($ss=1; $ss<6; $ss++) { |
|
419 | + for ($ss = 1; $ss < 6; $ss++) { |
|
420 | 420 | $server_state[$ss] = 0; |
421 | 421 | } |
422 | - for ($ro=0; $ro<8; $ro++) { |
|
422 | + for ($ro = 0; $ro < 8; $ro++) { |
|
423 | 423 | $outcome[$ro] = 0; |
424 | 424 | } |
425 | - for ($cs=1; $cs<7; $cs++) { |
|
425 | + for ($cs = 1; $cs < 7; $cs++) { |
|
426 | 426 | $client_state[$cs] = 0; |
427 | 427 | } |
428 | - for ($fds=0; $fds<4; $fds++) { |
|
428 | + for ($fds = 0; $fds < 4; $fds++) { |
|
429 | 429 | $delete_state[$fds] = 0; |
430 | 430 | } |
431 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
432 | - $validate_state[$vs]=0; |
|
431 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
432 | + $validate_state[$vs] = 0; |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $_GET['table'] = 'result'; |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | // |
505 | 505 | $delay = parse_config(get_config(), "<delete_delay_hours>"); |
506 | 506 | if ($delay) { |
507 | - $start2 = $start - $delay*3600;; |
|
507 | + $start2 = $start - $delay*3600; ; |
|
508 | 508 | $main_query .= " and ((file_delete_state>1 and mod_time>FROM_UNIXTIME($start2)) or (mod_time>FROM_UNIXTIME($start)))"; |
509 | 509 | } else { |
510 | 510 | $main_query .= " and mod_time > FROM_UNIXTIME($start)"; |
@@ -563,19 +563,19 @@ discard block |
||
563 | 563 | |
564 | 564 | echo "<table>"; |
565 | 565 | echo "<tr valign=\"top\">"; |
566 | - echo "<td><h2>" . link_results("$ntotal results", $urlquery, '', '') . "</h2></td>"; |
|
567 | - echo "<td><h2>" . link_results("'Over' results", $urlquery, "server_state=5", '') . "</h2></td>"; |
|
568 | - echo "<td><h2>" . link_results("'Success' results", $urlquery, "outcome=1", '') . "</h2></td>"; |
|
569 | - echo "<td><h2>" . link_results("'Client error' results", $urlquery, "outcome=3", '') . "</h2></td>"; |
|
566 | + echo "<td><h2>".link_results("$ntotal results", $urlquery, '', '')."</h2></td>"; |
|
567 | + echo "<td><h2>".link_results("'Over' results", $urlquery, "server_state=5", '')."</h2></td>"; |
|
568 | + echo "<td><h2>".link_results("'Success' results", $urlquery, "outcome=1", '')."</h2></td>"; |
|
569 | + echo "<td><h2>".link_results("'Client error' results", $urlquery, "outcome=3", '')."</h2></td>"; |
|
570 | 570 | echo "</tr>"; |
571 | 571 | echo "<tr valign=\"top\">"; |
572 | 572 | echo "<td><table border=2 cellpadding=4>\n"; |
573 | 573 | echo "<tr><th>Server state</th><th># results</th></tr>\n"; |
574 | - for ($ss=1; $ss<6; $ss++) { |
|
574 | + for ($ss = 1; $ss < 6; $ss++) { |
|
575 | 575 | $res = new StdClass; |
576 | 576 | $res->server_state = $ss; |
577 | 577 | row2(result_server_state_string($res), |
578 | - link_results("$server_state[$ss]", $urlquery,"server_state=$ss", '') |
|
578 | + link_results("$server_state[$ss]", $urlquery, "server_state=$ss", '') |
|
579 | 579 | ); |
580 | 580 | } |
581 | 581 | echo "</table></td>"; |
@@ -583,11 +583,11 @@ discard block |
||
583 | 583 | echo "<td><table border=2 cellpadding=4>\n"; |
584 | 584 | echo "<tr><th>Outcome</th><th># results</th></tr>\n"; |
585 | 585 | |
586 | - for ($ro=0; $ro<8; $ro++) { |
|
586 | + for ($ro = 0; $ro < 8; $ro++) { |
|
587 | 587 | $res = new StdClass; |
588 | 588 | $res->outcome = $ro; |
589 | 589 | $res->exit_status = 0; |
590 | - c_row2($outcome[$ro]?outcome_color($ro):'', result_outcome_string($res), |
|
590 | + c_row2($outcome[$ro] ? outcome_color($ro) : '', result_outcome_string($res), |
|
591 | 591 | link_results("$outcome[$ro]", $urlquery, "outcome=$ro", '') |
592 | 592 | ); |
593 | 593 | } |
@@ -595,18 +595,18 @@ discard block |
||
595 | 595 | |
596 | 596 | echo "<td><table border=2 cellpadding=4>\n"; |
597 | 597 | echo "<tr><th>Validate state</th><th># results</th></tr>\n"; |
598 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
598 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
599 | 599 | $res = new StdClass; |
600 | 600 | $res->validate_state = $vs; |
601 | 601 | $res->exit_status = 0; |
602 | - c_row2($validate_state[$vs]?validate_color($vs):'', validate_state_str($res), |
|
602 | + c_row2($validate_state[$vs] ? validate_color($vs) : '', validate_state_str($res), |
|
603 | 603 | link_results("$validate_state[$vs]", $urlquery, "validate_state=$vs", "outcome=1")); |
604 | 604 | } |
605 | 605 | echo "</table>"; |
606 | 606 | echo "<table border=2 cellpadding=4>\n"; |
607 | 607 | echo "<tr><th>File Delete state</th><th># results</th></tr>\n"; |
608 | 608 | |
609 | - for ($fds=0; $fds<4; $fds++) { |
|
609 | + for ($fds = 0; $fds < 4; $fds++) { |
|
610 | 610 | row2(file_delete_state_str($fds), |
611 | 611 | link_results("$file_delete[$fds]", $urlquery, "outcome=1", "file_delete_state=$fds")); |
612 | 612 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | |
617 | 617 | echo "<td><table border=2 cellpadding=4>\n"; |
618 | 618 | echo "<tr><th>Client state</th><th># results</th></tr>\n"; |
619 | - for ($cs=1; $cs<7; $cs++) { |
|
619 | + for ($cs = 1; $cs < 7; $cs++) { |
|
620 | 620 | $res = new StdClass; |
621 | 621 | $res->client_state = $cs; |
622 | 622 | $res->exit_status = 0; |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | <select name=\"server_state\"> |
635 | 635 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
636 | 636 | "; |
637 | - for ($i=1; $i<6; $i++) { |
|
637 | + for ($i = 1; $i < 6; $i++) { |
|
638 | 638 | $res = new StdClass; |
639 | - $res->server_state=$i; |
|
639 | + $res->server_state = $i; |
|
640 | 640 | echo "<option value=\"$i\"> "."[$i] ".' '.result_server_state_string($res)."</option>\n"; |
641 | 641 | } |
642 | 642 | echo "</select>\n"; |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | <select name=\"outcome\"> |
648 | 648 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
649 | 649 | "; |
650 | - for ($i=0; $i<8; $i++) { |
|
650 | + for ($i = 0; $i < 8; $i++) { |
|
651 | 651 | $res = new StdClass; |
652 | 652 | $res->outcome = $i; |
653 | 653 | $res->exit_status = 0; |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | <select name=\"validate_state\"> |
662 | 662 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
663 | 663 | "; |
664 | - for ($vs=0; $vs<NVALIDATE_STATES; $vs++) { |
|
664 | + for ($vs = 0; $vs < NVALIDATE_STATES; $vs++) { |
|
665 | 665 | $res = new StdClass; |
666 | 666 | $res->validate_state = $vs; |
667 | 667 | $res->exit_status = 0; |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | <select name=\"client_state\"> |
676 | 676 | <option value=\"CHOOSE_ALL\" selected=\"selected\"> Any </option> |
677 | 677 | "; |
678 | - for ($i=0; $i<7; $i++) { |
|
678 | + for ($i = 0; $i < 7; $i++) { |
|
679 | 679 | $res = new StdClass; |
680 | 680 | $res->client_state = $i; |
681 | 681 | $res->exit_status = 0; |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | } |
713 | 713 | |
714 | 714 | function table_title($table) { |
715 | - switch($table) { |
|
715 | + switch ($table) { |
|
716 | 716 | case "platform": return "Platforms"; |
717 | 717 | case "app": return "Applications"; |
718 | 718 | case "app_version": return "Application Versions"; |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | row("Created", time_str($platform->create_time)); |
733 | 733 | row("Name", $platform->name); |
734 | 734 | row("User friendly name", $platform->user_friendly_name); |
735 | - row("","<a href=\"db_action.php?table=app_version&platformid=$platform->id\">App versions for this platform</a>"); |
|
735 | + row("", "<a href=\"db_action.php?table=app_version&platformid=$platform->id\">App versions for this platform</a>"); |
|
736 | 736 | end_table(); |
737 | 737 | } |
738 | 738 | |
@@ -744,8 +744,8 @@ discard block |
||
744 | 744 | row("User-friendly name", $app->user_friendly_name); |
745 | 745 | row("Deprecated", $app->deprecated); |
746 | 746 | row("Homogeneous redundancy", $app->homogeneous_redundancy); |
747 | - row("","<a href=\"db_action.php?table=app_version&appid=$app->id\">App Versions for this application</a>"); |
|
748 | - row("","<a href=\"db_action.php?table=workunit&appid=$app->id&detail=low\">Workunits for this application</a>"); |
|
747 | + row("", "<a href=\"db_action.php?table=app_version&appid=$app->id\">App Versions for this application</a>"); |
|
748 | + row("", "<a href=\"db_action.php?table=workunit&appid=$app->id&detail=low\">Workunits for this application</a>"); |
|
749 | 749 | end_table(); |
750 | 750 | } |
751 | 751 | |
@@ -753,9 +753,9 @@ discard block |
||
753 | 753 | start_table(); |
754 | 754 | row("ID", $app_version->id); |
755 | 755 | row("Created", time_str($app_version->create_time)); |
756 | - row("Application", "<a href=\"db_action.php?table=app&id=$app_version->appid\">" . app_name_by_id($app_version->appid) . "</a>"); |
|
756 | + row("Application", "<a href=\"db_action.php?table=app&id=$app_version->appid\">".app_name_by_id($app_version->appid)."</a>"); |
|
757 | 757 | row("Version num", $app_version->version_num); |
758 | - row("Platform", "<a href=\"db_action.php?table=platform&id=$app_version->platformid\">" . platform_name_by_id($app_version->platformid) . "</a>" ); |
|
758 | + row("Platform", "<a href=\"db_action.php?table=platform&id=$app_version->platformid\">".platform_name_by_id($app_version->platformid)."</a>"); |
|
759 | 759 | row("Plan Class", $app_version->plan_class); |
760 | 760 | row("XML doc", "<pre>".htmlspecialchars($app_version->xml_doc)."</pre>"); |
761 | 761 | row("min_core_version", $app_version->min_core_version); |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | row("External IP address", "$host->external_ip_addr<br>"); |
891 | 891 | row("Domain name", $host->domain_name); |
892 | 892 | $x = $host->timezone/3600; |
893 | - if ($x >= 0) $x="+$x"; |
|
893 | + if ($x >= 0) $x = "+$x"; |
|
894 | 894 | row("Local Standard Time", "UTC $x hours"); |
895 | 895 | row("Number of CPUs", $host->p_ncpus); |
896 | 896 | row("CPU", "$host->p_vendor $host->p_model"); |
@@ -938,10 +938,10 @@ discard block |
||
938 | 938 | start_table(); |
939 | 939 | row("Created", time_str($wu->create_time)); |
940 | 940 | row("Transition Time", time_str($wu->transition_time)); |
941 | - row("Last time modified",mysqltime_str($wu->mod_time)); |
|
941 | + row("Last time modified", mysqltime_str($wu->mod_time)); |
|
942 | 942 | row("Name", $wu->name); |
943 | 943 | row("XML doc", "<pre>".htmlspecialchars($wu->xml_doc)."</pre>"); |
944 | - row("Application", "<a href=\"db_action.php?table=app&id=$wu->appid\">" . app_name_by_id($wu->appid) . " [".$wu->appid."]</a>"); |
|
944 | + row("Application", "<a href=\"db_action.php?table=app&id=$wu->appid\">".app_name_by_id($wu->appid)." [".$wu->appid."]</a>"); |
|
945 | 945 | row("Batch", $wu->batch); |
946 | 946 | $x = number_format($wu->rsc_fpops_est/1e9, 2); |
947 | 947 | row("Estimated FP Operations", "$x GFLOPS"); |
@@ -953,12 +953,12 @@ discard block |
||
953 | 953 | $x = $wu->rsc_disk_bound/(1024*1024); |
954 | 954 | $y = number_format($x, 2); |
955 | 955 | row("Max Disk Usage", "$y MB"); |
956 | - row("Need validate?", ($wu->need_validate?"yes [":"no [").$wu->need_validate."]"); |
|
956 | + row("Need validate?", ($wu->need_validate ? "yes [" : "no [").$wu->need_validate."]"); |
|
957 | 957 | row("Canonical resultid", |
958 | 958 | "<a href=\"db_action.php?table=result&id=$wu->canonical_resultid\">".$wu->canonical_resultid."</a>"); |
959 | 959 | row("Canonical credit", $wu->canonical_credit); |
960 | 960 | //row("Timeout check time", time_str($wu->timeout_check_time)); |
961 | - row("Delay bound", "$wu->delay_bound" . " = " . time_diff($wu->delay_bound) ); |
|
961 | + row("Delay bound", "$wu->delay_bound"." = ".time_diff($wu->delay_bound)); |
|
962 | 962 | row("Error mask", wu_error_mask_str($wu->error_mask)); |
963 | 963 | row("File delete state", file_delete_state_str($wu->file_delete_state)." [".$wu->file_delete_state."]"); |
964 | 964 | row("Assimilation state", assimilate_state_str($wu->assimilate_state)." [".$wu->assimilate_state."]"); |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | row("max error results", $wu->max_error_results); |
969 | 969 | row("max total results", $wu->max_total_results); |
970 | 970 | row("max success results", $wu->max_success_results); |
971 | - row("result template file",$wu->result_template_file); |
|
971 | + row("result template file", $wu->result_template_file); |
|
972 | 972 | row("hr_class", $wu->hr_class); |
973 | 973 | row("opaque", $wu->opaque); |
974 | 974 | row("Priority", $wu->priority); |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $cr = "none"; |
999 | 999 | } |
1000 | 1000 | $wu_link = "<a href=\"db_action.php?table=workunit&id=".$wu->id."&detail=high\">".$wu->id."</a>"; |
1001 | - $cr = $cr. " <a href=\"db_action.php?table=result&workunitid=$wu->id&detail=low\">all</a>"; |
|
1001 | + $cr = $cr." <a href=\"db_action.php?table=result&workunitid=$wu->id&detail=low\">all</a>"; |
|
1002 | 1002 | $e = wu_error_mask_str($wu->error_mask); |
1003 | 1003 | $f = file_delete_state_str($wu->file_delete_state); |
1004 | 1004 | $a = assimilate_state_str($wu->assimilate_state); |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | function outcome_color($outcome) { |
1036 | - switch($outcome) { |
|
1036 | + switch ($outcome) { |
|
1037 | 1037 | case 0: return '9900cc'; // "Init", purple |
1038 | 1038 | case 1: return '33cc33'; // "Success", green |
1039 | 1039 | case 3: return 'ff3333'; // "Client error", red |
@@ -1060,18 +1060,18 @@ discard block |
||
1060 | 1060 | row("Sent", time_str($result->sent_time)); |
1061 | 1061 | row("Report deadline", time_str($result->report_deadline)); |
1062 | 1062 | row("Received", time_str($result->received_time)); |
1063 | - row("Last time modified",mysqltime_str($result->mod_time)); |
|
1063 | + row("Last time modified", mysqltime_str($result->mod_time)); |
|
1064 | 1064 | row("Name", $result->name); |
1065 | - row("Workunit", "<a href=\"db_action.php?table=workunit&id=$result->workunitid\">" . wu_name_by_id($result->workunitid) . "</a> [$result->workunitid]" ); |
|
1065 | + row("Workunit", "<a href=\"db_action.php?table=workunit&id=$result->workunitid\">".wu_name_by_id($result->workunitid)."</a> [$result->workunitid]"); |
|
1066 | 1066 | row("Server state", result_server_state_string($result)." [$result->server_state]"); |
1067 | 1067 | row("Outcome", result_outcome_string($result)." [$result->outcome]"); |
1068 | 1068 | row("Client state", result_client_state_string($result)." [$result->client_state]"); |
1069 | 1069 | row("Exit status", exit_status_string($result->exit_status)); |
1070 | - row("Host ID", "<a href=\"db_action.php?table=host&id=$result->hostid\">" . host_name_by_id($result->hostid) . "</a> [$result->hostid]"); |
|
1071 | - row("User ID", "<a href=\"db_action.php?table=user&id=$result->userid\">" . user_name_by_id($result->userid) . "</a> [$result->userid]"); |
|
1070 | + row("Host ID", "<a href=\"db_action.php?table=host&id=$result->hostid\">".host_name_by_id($result->hostid)."</a> [$result->hostid]"); |
|
1071 | + row("User ID", "<a href=\"db_action.php?table=user&id=$result->userid\">".user_name_by_id($result->userid)."</a> [$result->userid]"); |
|
1072 | 1072 | row("CPU time", $result->cpu_time); |
1073 | 1073 | row("Elapsed time", $result->elapsed_time); |
1074 | - if($error=stderr_error_string($result->stderr_out)) { |
|
1074 | + if ($error = stderr_error_string($result->stderr_out)) { |
|
1075 | 1075 | row("error in stderr out", $error); |
1076 | 1076 | } |
1077 | 1077 | row("Batch", $result->batch); |
@@ -1088,16 +1088,16 @@ discard block |
||
1088 | 1088 | row("App version", $x1.app_version_string($result).$x2); |
1089 | 1089 | row("App version ID", $result->app_version_id); |
1090 | 1090 | row("Estimated GFLOPS", number_format($result->flops_estimate/1e9, 2)); |
1091 | - row("Random",$result->random); |
|
1092 | - row("Opaque",$result->opaque); |
|
1093 | - row("Teamid",$result->teamid); |
|
1094 | - row("Priority",$result->priority); |
|
1091 | + row("Random", $result->random); |
|
1092 | + row("Opaque", $result->opaque); |
|
1093 | + row("Teamid", $result->teamid); |
|
1094 | + row("Priority", $result->priority); |
|
1095 | 1095 | row("XML doc in", "<pre>".htmlspecialchars($result->xml_doc_in)."</pre>"); |
1096 | 1096 | row("XML doc out", "<pre>".htmlspecialchars($result->xml_doc_out)."</pre>"); |
1097 | 1097 | row("stderr out", "<pre>" |
1098 | 1098 | .htmlspecialchars( |
1099 | 1099 | $result->stderr_out, |
1100 | - ENT_QUOTES | (defined('ENT_SUBSTITUTE')?ENT_SUBSTITUTE:0), |
|
1100 | + ENT_QUOTES|(defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), |
|
1101 | 1101 | 'utf-8' |
1102 | 1102 | ) |
1103 | 1103 | ."</pre>" |
@@ -1145,23 +1145,23 @@ discard block |
||
1145 | 1145 | } else { |
1146 | 1146 | // result has not been received yet, so show report deadline either |
1147 | 1147 | // in green if in the future or in red if in the past. |
1148 | - $timenow=time(); |
|
1149 | - if ($result->report_deadline==0) { |
|
1148 | + $timenow = time(); |
|
1149 | + if ($result->report_deadline == 0) { |
|
1150 | 1150 | // not sent -- show create time in purple |
1151 | - $received = "<font color=\"9900cc\">". time_str($result->create_time) . "</font>"; |
|
1152 | - } else if ($result->report_deadline>=$timenow) { |
|
1151 | + $received = "<font color=\"9900cc\">".time_str($result->create_time)."</font>"; |
|
1152 | + } else if ($result->report_deadline >= $timenow) { |
|
1153 | 1153 | // overdue -- show deadline in red |
1154 | - $received = "<font color=\"#33cc33\">". time_str($result->report_deadline) . "</font>"; |
|
1154 | + $received = "<font color=\"#33cc33\">".time_str($result->report_deadline)."</font>"; |
|
1155 | 1155 | } else { |
1156 | 1156 | // in progress and not overdue -- show deadline in green |
1157 | - $received = "<font color=\"#ff3333\">". time_str($result->report_deadline) . "</font>"; |
|
1157 | + $received = "<font color=\"#ff3333\">".time_str($result->report_deadline)."</font>"; |
|
1158 | 1158 | } |
1159 | 1159 | } |
1160 | 1160 | $version = app_version_string($result)." (<a href=\"db_action.php?table=app_version&id=$result->app_version_id\">$result->app_version_id</a>)"; |
1161 | 1161 | $outcome_color = outcome_color($result->outcome); |
1162 | 1162 | $validate_color = validate_color($result->validate_state); |
1163 | 1163 | $host_user = host_user_link($result->hostid); |
1164 | - $cpu_hours = sprintf("%.1f",$result->cpu_time / 3600); |
|
1164 | + $cpu_hours = sprintf("%.1f", $result->cpu_time/3600); |
|
1165 | 1165 | $granted_credit = "<a href=credit.php?resultid=$result->id>".credit_str($result->granted_credit)."</a>"; |
1166 | 1166 | $delete_state = file_delete_state_str($result->file_delete_state); |
1167 | 1167 | |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | row("ID", $user->id); |
1190 | 1190 | row("Created", time_str($user->create_time)); |
1191 | 1191 | row("Name", $user->name); |
1192 | - if(!in_rops()) { |
|
1192 | + if (!in_rops()) { |
|
1193 | 1193 | row("Authenticator", $user->authenticator); |
1194 | 1194 | } |
1195 | 1195 | row("Email address", $user->email_addr); |
@@ -1202,7 +1202,7 @@ discard block |
||
1202 | 1202 | row("Default venue", $user->venue); |
1203 | 1203 | row("Hosts", "<a href=\"db_action.php?table=host&userid=$user->id&detail=low\">click</a>"); |
1204 | 1204 | row("Cross project ID", $user->cross_project_id); |
1205 | - if(!in_rops()) { |
|
1205 | + if (!in_rops()) { |
|
1206 | 1206 | row("Password Hash", $user->passwd_hash); |
1207 | 1207 | } |
1208 | 1208 | row("Donated", $user->donated); |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | echo "</table></td>"; |
1254 | 1254 | echo "<td><table border=\"2\">\n"; |
1255 | 1255 | echo "<tr><th>User</th><th># posts</th></tr>\n"; |
1256 | - for ($p=1; $p<=10; $p++) { |
|
1256 | + for ($p = 1; $p <= 10; $p++) { |
|
1257 | 1257 | row2_plain(user_links_ops($top10poster[$p]), $top10poster[$p]->posts); |
1258 | 1258 | } |
1259 | 1259 | echo "</table></td>"; |
@@ -1292,10 +1292,10 @@ discard block |
||
1292 | 1292 | function show_team($team) { |
1293 | 1293 | start_table(); |
1294 | 1294 | row("ID", $team->id); |
1295 | - row("Team Founder", "<a href=\"db_action.php?table=user&id=$team->userid\">" . user_name_by_id($team->userid) . "</a>"); |
|
1295 | + row("Team Founder", "<a href=\"db_action.php?table=user&id=$team->userid\">".user_name_by_id($team->userid)."</a>"); |
|
1296 | 1296 | row("Name", $team->name); |
1297 | - row("Name (HTML Formatted)", "<pre>" . htmlspecialchars($team->name_html) . "</pre>" ); |
|
1298 | - row("Url", "<a href=\"http://$team->url\">" . $team->url . "</a>"); |
|
1297 | + row("Name (HTML Formatted)", "<pre>".htmlspecialchars($team->name_html)."</pre>"); |
|
1298 | + row("Url", "<a href=\"http://$team->url\">".$team->url."</a>"); |
|
1299 | 1299 | row("Type", team_type_string($team->type)); |
1300 | 1300 | row("Description", $team->description); |
1301 | 1301 | row("", "<a href=\"db_action.php?table=user&teamid=$team->id\">List All Members</a>"); |
@@ -1338,7 +1338,7 @@ discard block |
||
1338 | 1338 | if (!strlen($host->domain_name) && !strlen($host->last_ip_addr)) { |
1339 | 1339 | return "(blank)"; |
1340 | 1340 | } else { |
1341 | - return $host->domain_name . " (" . $host->last_ip_addr . ")"; |
|
1341 | + return $host->domain_name." (".$host->last_ip_addr.")"; |
|
1342 | 1342 | } |
1343 | 1343 | } |
1344 | 1344 |
@@ -96,7 +96,9 @@ discard block |
||
96 | 96 | if (!isset($types)) { |
97 | 97 | $types = array(); |
98 | 98 | $constants = get_defined_constants(true); |
99 | - foreach ($constants['mysqli'] as $c => $n) if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
|
99 | + foreach ($constants['mysqli'] as $c => $n) { |
|
100 | + if (preg_match('/^MYSQLI_TYPE_(.*)/', $c, $m)) $types[$n] = $m[1]; |
|
101 | + } |
|
100 | 102 | } |
101 | 103 | return array_key_exists($type_id, $types)? strtolower($types[$type_id]) : "unknown"; |
102 | 104 | } |
@@ -324,7 +326,9 @@ discard block |
||
324 | 326 | $count_query = "select count(*) as cnt from $this->table $this->query"; |
325 | 327 | $db = BoincDb::get(true); |
326 | 328 | $result = $db->do_query($count_query); |
327 | - if (!$result) return 0; |
|
329 | + if (!$result) { |
|
330 | + return 0; |
|
331 | + } |
|
328 | 332 | $res = $result->fetch_object(); |
329 | 333 | $result->free(); |
330 | 334 | return $res->cnt; |
@@ -366,7 +370,9 @@ discard block |
||
366 | 370 | $this->addeq_not_CHOOSE_ALL('client_state'); |
367 | 371 | $this->addeq_not_CHOOSE_ALL('validate_state'); |
368 | 372 | $clauses = get_str("clauses", true); |
369 | - if (strstr($clauses, ";")) error_page("bad clause"); |
|
373 | + if (strstr($clauses, ";")) { |
|
374 | + error_page("bad clause"); |
|
375 | + } |
|
370 | 376 | if ($clauses) { |
371 | 377 | $this->addclause($clauses); |
372 | 378 | } |
@@ -381,8 +387,7 @@ discard block |
||
381 | 387 | } else { |
382 | 388 | if(strlen($clauses)) { |
383 | 389 | return "<a href=\"db_action.php?table=result&query=$mq&$query&clauses=".urlencode($clauses)."&sort_by=mod_time&detail=low\">$n</a>"; |
384 | - } |
|
385 | - else { |
|
390 | + } else { |
|
386 | 391 | return "<a href=\"db_action.php?table=result&query=$mq&$query&sort_by=mod_time&detail=low\">$n</a>"; |
387 | 392 | } |
388 | 393 | |
@@ -839,10 +844,14 @@ discard block |
||
839 | 844 | $version_info = resource_name($avid%1000000); |
840 | 845 | } else { |
841 | 846 | $av = BoincAppVersion::lookup("id=$avid"); |
842 | - if (!$av) return "Missing app version $avid"; |
|
847 | + if (!$av) { |
|
848 | + return "Missing app version $avid"; |
|
849 | + } |
|
843 | 850 | $appid = $av->appid; |
844 | 851 | $platform = BoincPlatform::lookup_id($av->platformid); |
845 | - if (!$platform) return "Missing platform $av->platformid"; |
|
852 | + if (!$platform) { |
|
853 | + return "Missing platform $av->platformid"; |
|
854 | + } |
|
846 | 855 | $platform_name = $platform->user_friendly_name; |
847 | 856 | $version_info = "$av->version_num $av->plan_class |
848 | 857 | <br>PFC: $av->pfc_avg ($av->pfc_n) |
@@ -850,7 +859,9 @@ discard block |
||
850 | 859 | "; |
851 | 860 | } |
852 | 861 | $app = BoincApp::lookup_id($appid); |
853 | - if (!$app) return "Missing app $appid"; |
|
862 | + if (!$app) { |
|
863 | + return "Missing app $appid"; |
|
864 | + } |
|
854 | 865 | return "$app->user_friendly_name |
855 | 866 | <br>$platform_name |
856 | 867 | <br>$version_info |
@@ -890,7 +901,9 @@ discard block |
||
890 | 901 | row("External IP address", "$host->external_ip_addr<br>"); |
891 | 902 | row("Domain name", $host->domain_name); |
892 | 903 | $x = $host->timezone/3600; |
893 | - if ($x >= 0) $x="+$x"; |
|
904 | + if ($x >= 0) { |
|
905 | + $x="+$x"; |
|
906 | + } |
|
894 | 907 | row("Local Standard Time", "UTC $x hours"); |
895 | 908 | row("Number of CPUs", $host->p_ncpus); |
896 | 909 | row("CPU", "$host->p_vendor $host->p_model"); |
@@ -1014,13 +1027,19 @@ discard block |
||
1014 | 1027 | } |
1015 | 1028 | |
1016 | 1029 | function host_user_link($hostid) { |
1017 | - if (!$hostid) return '---'; |
|
1030 | + if (!$hostid) { |
|
1031 | + return '---'; |
|
1032 | + } |
|
1018 | 1033 | |
1019 | 1034 | $h = "<a href=\"db_action.php?table=host&id=$hostid\">$hostid</a>"; |
1020 | 1035 | $host = BoincHost::enum_fields("userid", "id=".$hostid, "limit 1"); |
1021 | - if (!$host) return $h; |
|
1036 | + if (!$host) { |
|
1037 | + return $h; |
|
1038 | + } |
|
1022 | 1039 | $user = BoincUser::enum_fields("id, name", "id=".$host[0]->userid, "limit 1"); |
1023 | - if (!$user) return $h; |
|
1040 | + if (!$user) { |
|
1041 | + return $h; |
|
1042 | + } |
|
1024 | 1043 | return "$h<br><small>(<a href=\"db_action.php?table=user&id=".$user[0]->id."\">".$user[0]->name."</a>)</small>"; |
1025 | 1044 | } |
1026 | 1045 | |
@@ -1304,37 +1323,49 @@ discard block |
||
1304 | 1323 | |
1305 | 1324 | function team_name_by_id($teamid) { |
1306 | 1325 | $team = BoincTeam::lookup_id($teamid); |
1307 | - if (!$team) return "No team"; |
|
1326 | + if (!$team) { |
|
1327 | + return "No team"; |
|
1328 | + } |
|
1308 | 1329 | return $team->name; |
1309 | 1330 | } |
1310 | 1331 | |
1311 | 1332 | function user_name_by_id($user_id) { |
1312 | 1333 | $user = BoincUser::lookup_id($user_id); |
1313 | - if (!$user) return "No user"; |
|
1334 | + if (!$user) { |
|
1335 | + return "No user"; |
|
1336 | + } |
|
1314 | 1337 | return $user->name; |
1315 | 1338 | } |
1316 | 1339 | |
1317 | 1340 | function app_name_by_id($appid) { |
1318 | 1341 | $app = BoincApp::lookup_id($appid); |
1319 | - if (!$app) return "No app"; |
|
1342 | + if (!$app) { |
|
1343 | + return "No app"; |
|
1344 | + } |
|
1320 | 1345 | return $app->name; |
1321 | 1346 | } |
1322 | 1347 | |
1323 | 1348 | function wu_name_by_id($workunitid) { |
1324 | 1349 | $wu = BoincWorkunit::lookup_id($workunitid); |
1325 | - if (!$wu) return "Missing workunit"; |
|
1350 | + if (!$wu) { |
|
1351 | + return "Missing workunit"; |
|
1352 | + } |
|
1326 | 1353 | return $wu->name; |
1327 | 1354 | } |
1328 | 1355 | |
1329 | 1356 | function platform_name_by_id($platformid) { |
1330 | 1357 | $plat = BoincPlatform::lookup_id($platformid); |
1331 | - if (!$plat) return "Missing platform"; |
|
1358 | + if (!$plat) { |
|
1359 | + return "Missing platform"; |
|
1360 | + } |
|
1332 | 1361 | return $plat->name; |
1333 | 1362 | } |
1334 | 1363 | |
1335 | 1364 | function host_name_by_id($hostid) { |
1336 | 1365 | $host = BoincHost::lookup_id($hostid); |
1337 | - if (!$host) return "No host"; |
|
1366 | + if (!$host) { |
|
1367 | + return "No host"; |
|
1368 | + } |
|
1338 | 1369 | if (!strlen($host->domain_name) && !strlen($host->last_ip_addr)) { |
1339 | 1370 | return "(blank)"; |
1340 | 1371 | } else { |