@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | // |
34 | 34 | $config = get_config(); |
35 | 35 | global $master_url; |
36 | -$master_url = parse_config($config , "<master_url>"); |
|
36 | +$master_url = parse_config($config, "<master_url>"); |
|
37 | 37 | $recaptcha_public_key = parse_config($config, "<recaptcha_public_key>"); |
38 | 38 | $recaptcha_private_key = parse_config($config, "<recaptcha_private_key>"); |
39 | 39 | |
40 | 40 | // Set parameters to defaults if not defined in config.xml |
41 | 41 | |
42 | 42 | $x = parse_config($config, "<user_country>"); |
43 | -define('USER_COUNTRY', ($x===null)?1:(int)$x); |
|
43 | +define('USER_COUNTRY', ($x === null) ? 1 : (int)$x); |
|
44 | 44 | |
45 | 45 | $x = parse_config($config, "<user_url>"); |
46 | -define('USER_URL', ($x===null)?1:(int)$x); |
|
46 | +define('USER_URL', ($x === null) ? 1 : (int)$x); |
|
47 | 47 | |
48 | 48 | // Set parameters to defaults if not defined in project.inc |
49 | 49 | |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | } |
137 | 137 | |
138 | 138 | function url_base() { |
139 | - return is_https()?secure_url_base():URL_BASE; |
|
139 | + return is_https() ?secure_url_base() : URL_BASE; |
|
140 | 140 | } |
141 | 141 | |
142 | -function send_cookie($name, $value, $permanent, $ops=false) { |
|
142 | +function send_cookie($name, $value, $permanent, $ops = false) { |
|
143 | 143 | global $master_url; |
144 | 144 | |
145 | 145 | // the following allows independent login for projects on the same server |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | $path = substr($path, 0, -1); |
151 | 151 | $path .= "_ops/"; |
152 | 152 | } |
153 | - $expire = $permanent?time()+3600*24*365:0; |
|
153 | + $expire = $permanent ?time() + 3600*24*365 : 0; |
|
154 | 154 | setcookie($name, $value, $expire, $path); |
155 | 155 | } |
156 | 156 | |
157 | -function clear_cookie($name, $ops=false) { |
|
157 | +function clear_cookie($name, $ops = false) { |
|
158 | 158 | global $master_url; |
159 | 159 | $url = parse_url($master_url); |
160 | 160 | $path = $url['path']; |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | $path = substr($path, 0, -1); |
163 | 163 | $path .= "_ops/"; |
164 | 164 | } |
165 | - setcookie($name, '', time()-3600, $path); |
|
165 | + setcookie($name, '', time() - 3600, $path); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $g_logged_in_user = null; |
169 | 169 | $got_logged_in_user = false; |
170 | 170 | |
171 | -function get_logged_in_user($must_be_logged_in=true) { |
|
171 | +function get_logged_in_user($must_be_logged_in = true) { |
|
172 | 172 | global $g_logged_in_user, $got_logged_in_user; |
173 | 173 | if ($got_logged_in_user) { |
174 | 174 | // this could have been called earlier with $must_be_logged_in false |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $next_url = $_SERVER['REQUEST_URI']; |
195 | 195 | $n = strrpos($next_url, "/"); |
196 | 196 | if ($n) { |
197 | - $next_url = substr($next_url, $n+1); |
|
197 | + $next_url = substr($next_url, $n + 1); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | $next_url = urlencode($next_url); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | return $g_logged_in_user; |
206 | 206 | } |
207 | 207 | |
208 | -function show_login_info($prefix="") { |
|
208 | +function show_login_info($prefix = "") { |
|
209 | 209 | $user = get_logged_in_user(false); |
210 | 210 | if ($user) { |
211 | 211 | $url_tokens = url_tokens($user->authenticator); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | -$cache_control_extra=""; |
|
218 | +$cache_control_extra = ""; |
|
219 | 219 | $is_login_page = false; |
220 | 220 | |
221 | 221 | // Call this to start pages. |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | // with an existing web framework can more easily do so. |
228 | 228 | // To do so, define page_head() in the project include file. |
229 | 229 | // |
230 | -if (!function_exists("page_head")){ |
|
230 | +if (!function_exists("page_head")) { |
|
231 | 231 | function page_head( |
232 | 232 | $title, |
233 | 233 | // page title. Put in <title>, used as title for browser tab. |
234 | - $body_attrs=null, |
|
234 | + $body_attrs = null, |
|
235 | 235 | // <body XXXX> |
236 | 236 | // e.g. Javascript to put focus in an input field |
237 | 237 | // (onload="document.form.foo.focus()") |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | // if set, include schedulers.txt. |
241 | 241 | // also pass to project_banner() in case you want a different |
242 | 242 | // header for your main page. |
243 | - $url_prefix="", |
|
243 | + $url_prefix = "", |
|
244 | 244 | // prepend this to links. |
245 | 245 | // Use for web pages not in the top directory |
246 | - $head_extra=null |
|
246 | + $head_extra = null |
|
247 | 247 | // extra stuff to put in <head>. E.g.: |
248 | 248 | // reCAPTCHA code (create_profile.php) |
249 | 249 | // bbcode javascript (forums) |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | header("Content-type: text/html; charset=utf-8"); |
266 | 266 | header("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); |
267 | 267 | // Date in the past |
268 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC"); |
|
268 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." UTC"); |
|
269 | 269 | // always modified |
270 | 270 | header("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0"); |
271 | 271 | // for HTTP/1.1 |
@@ -286,11 +286,11 @@ discard block |
||
286 | 286 | if ($head_extra) { |
287 | 287 | echo "\n$head_extra\n"; |
288 | 288 | } |
289 | - if ($is_main && (!defined('NO_COMPUTING')||!NO_COMPUTING)) { |
|
289 | + if ($is_main && (!defined('NO_COMPUTING') || !NO_COMPUTING)) { |
|
290 | 290 | readfile("schedulers.txt"); |
291 | 291 | } |
292 | 292 | |
293 | - $t = $title?$title:PROJECT; |
|
293 | + $t = $title ? $title : PROJECT; |
|
294 | 294 | echo "<title>$t</title>\n"; |
295 | 295 | echo ' |
296 | 296 | <meta charset="utf-8"> |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | echo '<div class="container-fluid"> |
348 | 348 | '; |
349 | 349 | |
350 | - switch($title) { //kludge |
|
350 | + switch ($title) { //kludge |
|
351 | 351 | case tra("Log in"): |
352 | 352 | case tra("Create an account"): |
353 | 353 | case tra("Server status page"): |
@@ -362,13 +362,13 @@ discard block |
||
362 | 362 | |
363 | 363 | // See the comments for page_head() |
364 | 364 | // |
365 | -if (!function_exists("page_tail")){ |
|
365 | +if (!function_exists("page_tail")) { |
|
366 | 366 | function page_tail( |
367 | - $show_date=false, |
|
367 | + $show_date = false, |
|
368 | 368 | // true for pages that are generated periodically rather than on the fly |
369 | - $url_prefix="", |
|
369 | + $url_prefix = "", |
|
370 | 370 | // use for pages not at top level |
371 | - $is_main=false |
|
371 | + $is_main = false |
|
372 | 372 | // passed to project_footer; |
373 | 373 | ) { |
374 | 374 | echo "<br>\n"; |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | -function display_cvs_versions(){ |
|
386 | +function display_cvs_versions() { |
|
387 | 387 | global $cvs_version_tracker; |
388 | 388 | echo "\n<!-- SVN VERSIONS -->\n"; |
389 | - for ($i=0;$i<sizeof($cvs_version_tracker);$i++) { |
|
389 | + for ($i = 0; $i < sizeof($cvs_version_tracker); $i++) { |
|
390 | 390 | echo "<!-- ".$cvs_version_tracker[$i]." -->\n"; |
391 | 391 | } |
392 | 392 | } |
@@ -411,24 +411,24 @@ discard block |
||
411 | 411 | // convert time interval in seconds to a string of the form |
412 | 412 | // 'D days h hours m min s sec'. |
413 | 413 | |
414 | -function time_diff($x, $res=3) { |
|
414 | +function time_diff($x, $res = 3) { |
|
415 | 415 | $x = (int)$x; |
416 | 416 | $days = (int)($x/86400); |
417 | - $hours = (int)(($x-$days*86400)/3600); |
|
418 | - $minutes = (int)(($x-$days*86400-$hours*3600)/60); |
|
419 | - $seconds = $x % 60; |
|
417 | + $hours = (int)(($x - $days*86400)/3600); |
|
418 | + $minutes = (int)(($x - $days*86400 - $hours*3600)/60); |
|
419 | + $seconds = $x%60; |
|
420 | 420 | |
421 | 421 | $s = ""; |
422 | 422 | if ($days) { |
423 | 423 | $s .= "$days ".tra("days")." "; |
424 | 424 | } |
425 | - if ($res>0 && ($hours || strlen($s))) { |
|
425 | + if ($res > 0 && ($hours || strlen($s))) { |
|
426 | 426 | $s .= "$hours ".tra("hours")." "; |
427 | 427 | } |
428 | - if ($res>1 && ($minutes || strlen($s))) { |
|
428 | + if ($res > 1 && ($minutes || strlen($s))) { |
|
429 | 429 | $s .= "$minutes ".tra("min")." "; |
430 | 430 | } |
431 | - if ($res>2) { |
|
431 | + if ($res > 2) { |
|
432 | 432 | $s .= "$seconds ".tra("sec")." "; |
433 | 433 | } |
434 | 434 | return $s; |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | |
443 | 443 | function time_str($x) { |
444 | 444 | if ($x == 0) return "---"; |
445 | - return gmdate('j M Y, G:i:s', (int)$x) . " UTC"; |
|
445 | + return gmdate('j M Y, G:i:s', (int)$x)." UTC"; |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | function local_time_str($x) { |
@@ -454,14 +454,14 @@ discard block |
||
454 | 454 | return time_str($x); |
455 | 455 | } |
456 | 456 | |
457 | -function start_table_str($class="", $style="") { |
|
458 | - $s = $style?'style="'.$style.'"':''; |
|
457 | +function start_table_str($class = "", $style = "") { |
|
458 | + $s = $style ? 'style="'.$style.'"' : ''; |
|
459 | 459 | return '<div class="table"> |
460 | 460 | <table '.$s.' width="100%" class="table table-condensed '.$class.'" > |
461 | 461 | '; |
462 | 462 | } |
463 | 463 | |
464 | -function start_table($class="", $style="") { |
|
464 | +function start_table($class = "", $style = "") { |
|
465 | 465 | echo start_table_str($class, $style); |
466 | 466 | } |
467 | 467 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | echo "</tr>\n"; |
507 | 507 | } |
508 | 508 | |
509 | -function row1($x, $ncols=2, $class="heading") { |
|
509 | +function row1($x, $ncols = 2, $class = "heading") { |
|
510 | 510 | if ($class == "heading") { |
511 | 511 | echo "<tr><th class=\"bg-primary\" colspan=\"$ncols\">$x</th></tr>\n"; |
512 | 512 | } else { |
@@ -518,10 +518,10 @@ discard block |
||
518 | 518 | define('VALUE_ATTRS', 'style="padding-left:12px"'); |
519 | 519 | define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"'); |
520 | 520 | |
521 | -function row2($x, $y, $show_error=false, $lwidth='40%') { |
|
522 | - if ($x==="") $x="<br>"; |
|
523 | - if ($y==="") $y="<br>"; |
|
524 | - $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS; |
|
521 | +function row2($x, $y, $show_error = false, $lwidth = '40%') { |
|
522 | + if ($x === "") $x = "<br>"; |
|
523 | + if ($y === "") $y = "<br>"; |
|
524 | + $attrs = $show_error ?VALUE_ATTRS_ERR:VALUE_ATTRS; |
|
525 | 525 | echo "<tr> |
526 | 526 | <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td> |
527 | 527 | <td $attrs >$y</td> |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | "; |
530 | 530 | } |
531 | 531 | |
532 | -function row2_init($x, $y, $lwidth='40%') { |
|
532 | +function row2_init($x, $y, $lwidth = '40%') { |
|
533 | 533 | echo '<tr> |
534 | 534 | <td class="text-right " width="'.$lwidth.'" style="padding-right: 20px;">'.$x.'</td> |
535 | 535 | <td '.VALUE_ATTRS.'>'.$y.' |
@@ -552,20 +552,20 @@ discard block |
||
552 | 552 | echo "</tr>\n"; |
553 | 553 | } |
554 | 554 | |
555 | -define ('ALIGN_RIGHT', 'style="text-align:right;"'); |
|
555 | +define('ALIGN_RIGHT', 'style="text-align:right;"'); |
|
556 | 556 | |
557 | -function row_heading_array($x, $attrs=null, $class='bg-primary') { |
|
557 | +function row_heading_array($x, $attrs = null, $class = 'bg-primary') { |
|
558 | 558 | echo "<tr>"; |
559 | 559 | $i = 0; |
560 | 560 | foreach ($x as $h) { |
561 | - $a = $attrs?$attrs[$i]:""; |
|
561 | + $a = $attrs ? $attrs[$i] : ""; |
|
562 | 562 | echo "<th $a class=\"$class\">$h</th>"; |
563 | 563 | $i++; |
564 | 564 | } |
565 | 565 | echo "</tr>\n"; |
566 | 566 | } |
567 | 567 | |
568 | -function row_heading($x, $class='bg-primary') { |
|
568 | +function row_heading($x, $class = 'bg-primary') { |
|
569 | 569 | echo sprintf('<tr><th class="%s" colspan=99>%s</th></tr> |
570 | 570 | ', $class, $x |
571 | 571 | ); |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | // If $ellipsis is true, then an ellipsis is added to any sentence which |
626 | 626 | // is cut short. |
627 | 627 | |
628 | -function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) { |
|
628 | +function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis = false) { |
|
629 | 629 | $words = explode($delimiter, $sentence); |
630 | 630 | $total_chars = 0; |
631 | 631 | $trunc = false; |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | |
709 | 709 | // returns null if the arg is optional and missing |
710 | 710 | // |
711 | -function get_int($name, $optional=false) { |
|
712 | - $x=null; |
|
711 | +function get_int($name, $optional = false) { |
|
712 | + $x = null; |
|
713 | 713 | if (isset($_GET[$name])) $x = $_GET[$name]; |
714 | 714 | if (!is_numeric($x)) { |
715 | 715 | if ($optional) { |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | |
729 | 729 | // returns null if the arg is optional and missing |
730 | 730 | // |
731 | -function post_num($name, $optional=false) { |
|
731 | +function post_num($name, $optional = false) { |
|
732 | 732 | $x = null; |
733 | 733 | if (isset($_POST[$name])) $x = $_POST[$name]; |
734 | 734 | if (!is_numeric($x)) { |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | |
744 | 744 | // returns null if the arg is optional and missing |
745 | 745 | // |
746 | -function post_int($name, $optional=false) { |
|
746 | +function post_int($name, $optional = false) { |
|
747 | 747 | $x = post_num($name, $optional); |
748 | 748 | if (is_null($x)) return null; |
749 | 749 | $y = (int)$x; |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | } |
762 | 762 | } |
763 | 763 | |
764 | -function get_str($name, $optional=false) { |
|
764 | +function get_str($name, $optional = false) { |
|
765 | 765 | if (isset($_GET[$name])) { |
766 | 766 | $x = $_GET[$name]; |
767 | 767 | } else { |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | return undo_magic_quotes($x); |
774 | 774 | } |
775 | 775 | |
776 | -function post_str($name, $optional=false) { |
|
776 | +function post_str($name, $optional = false) { |
|
777 | 777 | if (isset($_POST[$name])) { |
778 | 778 | $x = $_POST[$name]; |
779 | 779 | } else { |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | return undo_magic_quotes($x); |
786 | 786 | } |
787 | 787 | |
788 | -function post_arr($name, $optional=false) { |
|
788 | +function post_arr($name, $optional = false) { |
|
789 | 789 | if (isset($_POST[$name]) && is_array($_POST[$name])) { |
790 | 790 | $x = $_POST[$name]; |
791 | 791 | } else { |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | // the mb_* functions are not included by default |
802 | 802 | // return (mb_detect_encoding($passwd) -= 'ASCII'); |
803 | 803 | |
804 | - for ($i=0; $i<strlen($str); $i++) { |
|
804 | + for ($i = 0; $i < strlen($str); $i++) { |
|
805 | 805 | $c = ord(substr($str, $i)); |
806 | 806 | if ($c < 32 || $c > 127) return false; |
807 | 807 | } |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | $number = str_replace(',', '.', $number); // replace the german decimal separator |
826 | 826 | // if no value was entered and this is ok |
827 | 827 | // |
828 | - if ($number=='' && !$low) return true; |
|
828 | + if ($number == '' && !$low) return true; |
|
829 | 829 | |
830 | 830 | // the supplied value contains alphabetic characters |
831 | 831 | // |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | // Generate a "select" element from an array of values |
844 | 844 | // |
845 | -function select_from_array($name, $array, $selection=null, $width=240) { |
|
845 | +function select_from_array($name, $array, $selection = null, $width = 240) { |
|
846 | 846 | $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"'; |
847 | 847 | |
848 | 848 | foreach ($array as $key => $value) { |
@@ -867,8 +867,8 @@ discard block |
||
867 | 867 | return $str; |
868 | 868 | } |
869 | 869 | |
870 | -function strip_bbcode($string){ |
|
871 | - return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string); |
|
870 | +function strip_bbcode($string) { |
|
871 | + return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/", "", $string); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | function current_url() { |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | // @params extra Additional text in href tag |
898 | 898 | // |
899 | 899 | |
900 | -function button_text($url, $text, $desc=null, $class=null, $extra='') { |
|
900 | +function button_text($url, $text, $desc = null, $class = null, $extra = '') { |
|
901 | 901 | if (!$desc) { |
902 | 902 | $desc = $text; |
903 | 903 | } |
@@ -909,19 +909,19 @@ discard block |
||
909 | 909 | ); |
910 | 910 | } |
911 | 911 | |
912 | -function show_button($url, $text, $desc=null, $class=null, $extra=null) { |
|
912 | +function show_button($url, $text, $desc = null, $class = null, $extra = null) { |
|
913 | 913 | echo button_text($url, $text, $desc, $class, $extra); |
914 | 914 | } |
915 | 915 | |
916 | 916 | // for places with a bunch of buttons, like forum posts |
917 | 917 | // |
918 | -function show_button_small($url, $text, $desc=null) { |
|
918 | +function show_button_small($url, $text, $desc = null) { |
|
919 | 919 | echo button_text($url, $text, $desc, "btn-primary btn-xs"); |
920 | 920 | } |
921 | 921 | |
922 | 922 | // used for showing icons |
923 | 923 | // |
924 | -function show_image($src, $title, $alt, $height=null) { |
|
924 | +function show_image($src, $title, $alt, $height = null) { |
|
925 | 925 | $h = ""; |
926 | 926 | if ($height) { |
927 | 927 | $h = "height=\"$height\""; |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | // tries instead to connect to <replica_db_host> if tag exists. |
959 | 959 | // DEPRECATED - use boinc_db.inc |
960 | 960 | // |
961 | -function db_init($try_replica=false) { |
|
961 | +function db_init($try_replica = false) { |
|
962 | 962 | check_web_stopped(); |
963 | 963 | $retval = db_init_aux($try_replica); |
964 | 964 | if ($retval == 1) { |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | // Check this to avoid XSS vulnerability |
1050 | 1050 | // |
1051 | 1051 | function sanitize_sort_by($x) { |
1052 | - switch($x) { |
|
1052 | + switch ($x) { |
|
1053 | 1053 | case 'expavg_credit': |
1054 | 1054 | case 'total_credit': |
1055 | 1055 | return; |
@@ -1066,9 +1066,9 @@ discard block |
||
1066 | 1066 | return $c/(200/24); |
1067 | 1067 | } |
1068 | 1068 | |
1069 | -function do_download($path,$name="") { |
|
1070 | - if (strcmp($name,"") == 0) { |
|
1071 | - $name=basename($path); |
|
1069 | +function do_download($path, $name = "") { |
|
1070 | + if (strcmp($name, "") == 0) { |
|
1071 | + $name = basename($path); |
|
1072 | 1072 | } |
1073 | 1073 | header('Content-Description: File Transfer'); |
1074 | 1074 | header('Content-Type: application/octet-stream'); |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | header('Expires: 0'); |
1078 | 1078 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
1079 | 1079 | header('Pragma: public'); |
1080 | - header('Content-Length: ' . filesize($path)); |
|
1080 | + header('Content-Length: '.filesize($path)); |
|
1081 | 1081 | flush(); |
1082 | 1082 | readfile($path); |
1083 | 1083 | } |
@@ -1126,10 +1126,10 @@ discard block |
||
1126 | 1126 | // Otherwise return 0. |
1127 | 1127 | // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)" |
1128 | 1128 | // |
1129 | -function boinc_client_version(){ |
|
1129 | +function boinc_client_version() { |
|
1130 | 1130 | if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0; |
1131 | 1131 | $x = $_SERVER['HTTP_USER_AGENT']; |
1132 | - $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/"; |
|
1132 | + $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/"; |
|
1133 | 1133 | if (preg_match($e, $x, $matches)) { |
1134 | 1134 | return $matches[1]*10000 + $matches[2]*100 + $matches[3]; |
1135 | 1135 | } |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | $rem_name = $name."_remaining"; |
1159 | 1159 | return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\" |
1160 | 1160 | onkeyup=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\">".$text."</textarea> |
1161 | - <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen-strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining") |
|
1161 | + <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen - strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining") |
|
1162 | 1162 | ; |
1163 | 1163 | } |
1164 | 1164 | |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | // use the following around text with long lines, |
1189 | 1189 | // to limit the width and make it more readable. |
1190 | 1190 | // |
1191 | -function text_start($width=640) { |
|
1191 | +function text_start($width = 640) { |
|
1192 | 1192 | echo sprintf("<div style=\"max-width: %dpx;\">\n", $width); |
1193 | 1193 | } |
1194 | 1194 | function text_end() { |
@@ -1214,7 +1214,7 @@ discard block |
||
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | function cert_filename() { |
1217 | - return defined("CERT_FILENAME")?CERT_FILENAME:"cert1.php"; |
|
1217 | + return defined("CERT_FILENAME") ?CERT_FILENAME:"cert1.php"; |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | // if user hasn't validated their email addr, tell them to |
@@ -1231,6 +1231,6 @@ discard block |
||
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | |
1234 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
1234 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
1235 | 1235 | |
1236 | 1236 | ?> |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | display_errors(); |
19 | 19 | |
20 | -$debug=0; |
|
20 | +$debug = 0; |
|
21 | 21 | |
22 | 22 | // test a LAMMPS job |
23 | 23 | // |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | // output: success flag, CPU time per step, est. disk usage per job |
31 | 31 | // |
32 | 32 | function terminate_job($p) { |
33 | - $pstatus=proc_get_status($p); |
|
34 | - $ppid=$pstatus['pid']; |
|
35 | - $ret=`ps -o pid --no-heading --ppid $ppid`; |
|
33 | + $pstatus = proc_get_status($p); |
|
34 | + $ppid = $pstatus['pid']; |
|
35 | + $ret = `ps -o pid --no-heading --ppid $ppid`; |
|
36 | 36 | //echo "parent pid is $ppid\nterninate it\n"; |
37 | 37 | proc_terminate($p); |
38 | 38 | // echo "child process is $ret\n"; |
39 | - $pids=preg_split('/\s+/',$ret); |
|
40 | - foreach($pids as $pid){ |
|
41 | - if(is_numeric($pid)){ |
|
42 | - if($GLOBALS["debug"])echo "killing child process $pid\n"; |
|
43 | - posix_kill($pid,9); |
|
39 | + $pids = preg_split('/\s+/', $ret); |
|
40 | + foreach ($pids as $pid) { |
|
41 | + if (is_numeric($pid)) { |
|
42 | + if ($GLOBALS["debug"])echo "killing child process $pid\n"; |
|
43 | + posix_kill($pid, 9); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
@@ -51,23 +51,23 @@ discard block |
||
51 | 51 | $descs = array(); |
52 | 52 | $pipes = array(); |
53 | 53 | $options = file("cmd_variables"); |
54 | - $options[0] = chop($options[0],"\n"); |
|
54 | + $options[0] = chop($options[0], "\n"); |
|
55 | 55 | $cmd = "../lmp_linux ".$options[0]."&>output"; |
56 | 56 | if ($GLOBALS["debug"]) echo $cmd."<br>"; |
57 | 57 | system("unzip pot_files >/dev/null"); |
58 | 58 | $stime = time(); |
59 | 59 | $p = proc_open("$cmd", $descs, $pipes); |
60 | 60 | while (1) { |
61 | - $ctime=time(); |
|
62 | - if($ctime-$stime >=2 and ! file_exists("log.1")){ |
|
63 | - if($GLOBALS["debug"]) echo "time out "."<br>"; |
|
61 | + $ctime = time(); |
|
62 | + if ($ctime - $stime >= 2 and !file_exists("log.1")) { |
|
63 | + if ($GLOBALS["debug"]) echo "time out "."<br>"; |
|
64 | 64 | terminate_job($p); |
65 | 65 | break; |
66 | 66 | } |
67 | 67 | if (file_exists("log.1")) { |
68 | 68 | list($avg_cpu, $test_steps) = calc_step_cpu("log.1"); |
69 | 69 | if ($avg_cpu != 0) { |
70 | - if($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>"; |
|
70 | + if ($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>"; |
|
71 | 71 | terminate_job($p); |
72 | 72 | $test_result = 1; |
73 | 73 | break; |
@@ -86,32 +86,32 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | function get_total_steps($cmd_file) { |
89 | - $fd = fopen($cmd_file,"r"); |
|
89 | + $fd = fopen($cmd_file, "r"); |
|
90 | 90 | if (!$fd) { |
91 | 91 | echo "can not open file $cmd_file\n"; |
92 | 92 | exit(-1); |
93 | 93 | } |
94 | 94 | $this_loopno = 1; |
95 | 95 | $this_looprun = 1; |
96 | - $total_steps=1; |
|
96 | + $total_steps = 1; |
|
97 | 97 | while (!feof($fd)) { |
98 | - $line = fgets($fd,4096); |
|
98 | + $line = fgets($fd, 4096); |
|
99 | 99 | if (preg_match("/loopnumber\s+\d+/", $line, $matches) |
100 | 100 | && preg_match("/\d+/", $matches[0], $no) |
101 | 101 | ) { |
102 | - $this_loopno=$no[0]; |
|
102 | + $this_loopno = $no[0]; |
|
103 | 103 | } |
104 | 104 | if (preg_match("/looprun\s+\d+/", $line, $matches) |
105 | 105 | and preg_match("/\d+/", $matches[0], $no) |
106 | 106 | ) { |
107 | - $this_looprun=$no[0]; |
|
108 | - if($this_loopno*$this_looprun>$total_steps)$total_steps=$this_loopno*$this_looprun; |
|
107 | + $this_looprun = $no[0]; |
|
108 | + if ($this_loopno*$this_looprun > $total_steps)$total_steps = $this_loopno*$this_looprun; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | } |
112 | 112 | fclose($fd); |
113 | 113 | //$total_steps = $loopno*$looprun; |
114 | - if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
114 | + if ($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
115 | 115 | return $total_steps; |
116 | 116 | } |
117 | 117 | |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | } |
130 | 130 | $count = 0; |
131 | 131 | while (!feof($fd)) { |
132 | - $line = fgets($fd,4096); |
|
133 | - if (preg_match('/^Step\s+CPU/',$line)) { |
|
132 | + $line = fgets($fd, 4096); |
|
133 | + if (preg_match('/^Step\s+CPU/', $line)) { |
|
134 | 134 | //echo $line."\n"; |
135 | 135 | $start = 1; |
136 | 136 | continue; |
@@ -139,24 +139,24 @@ discard block |
||
139 | 139 | $arr = preg_split("/\s+/", $line); |
140 | 140 | //print_r($arr); |
141 | 141 | |
142 | - if (count($arr) <=6 || !is_numeric($arr[1])) { |
|
142 | + if (count($arr) <= 6 || !is_numeric($arr[1])) { |
|
143 | 143 | continue; |
144 | 144 | } |
145 | 145 | $step = (int)$arr[1]; |
146 | 146 | $cpu = (float)$arr[2]; |
147 | 147 | //echo "step=".$step." cpu=".$cpu."\n"; |
148 | - if ($cpu==0) { |
|
149 | - $count=0; |
|
148 | + if ($cpu == 0) { |
|
149 | + $count = 0; |
|
150 | 150 | $start_step = $step; |
151 | 151 | } else { |
152 | - $count+=1; |
|
153 | - if($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
154 | - if($count >= 10) { |
|
152 | + $count += 1; |
|
153 | + if ($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
154 | + if ($count >= 10) { |
|
155 | 155 | $end_step = $step; |
156 | - $steps = $end_step-$start_step; |
|
156 | + $steps = $end_step - $start_step; |
|
157 | 157 | $avg_cpu = $cpu/$steps; |
158 | 158 | #$avg_cpu = $cpu/$count; |
159 | - if ($GLOBALS["debug"]){ |
|
159 | + if ($GLOBALS["debug"]) { |
|
160 | 160 | echo "test steps is ".$steps."<br>"; |
161 | 161 | echo "avg_cpu is ".$avg_cpu."<br>"; |
162 | 162 | } |
@@ -165,56 +165,56 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | } |
168 | - return array($avg_cpu,$test_steps); |
|
168 | + return array($avg_cpu, $test_steps); |
|
169 | 169 | } |
170 | 170 | |
171 | -function calc_est_size($lammps_script, $structure_file, $cmd_file,$test_steps){ |
|
171 | +function calc_est_size($lammps_script, $structure_file, $cmd_file, $test_steps) { |
|
172 | 172 | $dump_types = 0; |
173 | - $fd = fopen($lammps_script,"r"); |
|
174 | - if (!$fd){ |
|
173 | + $fd = fopen($lammps_script, "r"); |
|
174 | + if (!$fd) { |
|
175 | 175 | echo "can not open file $lammps_script\n"; |
176 | 176 | exit(-1); |
177 | 177 | } |
178 | - while (!feof($fd)){ |
|
178 | + while (!feof($fd)) { |
|
179 | 179 | $line = fgets($fd, 4096); |
180 | 180 | //if (preg_match("/^\s*dump/", $line) |
181 | 181 | // and preg_match_all("/dump\S+\.\w{3}/", $line, $matches, PREG_PATTERN_ORDER)) |
182 | 182 | |
183 | - if(preg_match("/^\s*dump\s+(\d)\s+/", $line,$matches)) |
|
183 | + if (preg_match("/^\s*dump\s+(\d)\s+/", $line, $matches)) |
|
184 | 184 | { |
185 | - if($GLOBALS["debug"]){print "matches=";print_r($matches);} |
|
185 | + if ($GLOBALS["debug"]) {print "matches="; print_r($matches); } |
|
186 | 186 | |
187 | - $dump_types=(int)$matches[1]; |
|
187 | + $dump_types = (int)$matches[1]; |
|
188 | 188 | break; |
189 | 189 | } |
190 | 190 | } |
191 | 191 | fclose($fd); |
192 | - if($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>"; |
|
192 | + if ($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>"; |
|
193 | 193 | |
194 | 194 | $structure_file_size = filesize($structure_file); |
195 | - $fd = fopen($cmd_file,"r"); |
|
196 | - if (!$fd){ |
|
195 | + $fd = fopen($cmd_file, "r"); |
|
196 | + if (!$fd) { |
|
197 | 197 | echo "can not open file $cmd_file\n"; |
198 | 198 | exit(-1); |
199 | 199 | } |
200 | - if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
201 | - |
|
202 | - $loopno=1; |
|
203 | - $looprun=1; |
|
204 | - while (!feof($fd)){ |
|
205 | - $line = fgets($fd,4096); |
|
206 | - if(preg_match("/loopnumber\s+\d+/", $line, $matches)){ |
|
207 | - if(preg_match("/\d+/", $matches[0], $no)){ |
|
200 | + if ($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
201 | + |
|
202 | + $loopno = 1; |
|
203 | + $looprun = 1; |
|
204 | + while (!feof($fd)) { |
|
205 | + $line = fgets($fd, 4096); |
|
206 | + if (preg_match("/loopnumber\s+\d+/", $line, $matches)) { |
|
207 | + if (preg_match("/\d+/", $matches[0], $no)) { |
|
208 | 208 | //$loopno=$no[0]; |
209 | - if($no[0]>$loopno)$loopno=$no[0]; |
|
209 | + if ($no[0] > $loopno)$loopno = $no[0]; |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | if (preg_match("/looprun\s+\d+/", $line, $matches) and preg_match("/\d+/", $matches[0], $no)) { |
213 | - if($no[0]>$looprun)$looprun=$no[0]; |
|
213 | + if ($no[0] > $looprun)$looprun = $no[0]; |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | fclose($fd); |
217 | - if($GLOBALS["debug"]){ |
|
217 | + if ($GLOBALS["debug"]) { |
|
218 | 218 | print "max loopno(number of loops to run)=".$loopno."<br>"; |
219 | 219 | print "max looprun(steps for each loop)=".$looprun."<br>"; |
220 | 220 | } |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | $dump_files = glob("dump1*"); |
226 | 226 | $test_dump_file = $dump_files[0]; |
227 | 227 | $test_dump_size = filesize($test_dump_file); |
228 | - $dump_size1 = $test_dump_size+0.5*$test_dump_size*ceil(($looprun-$test_steps)/$test_steps); |
|
228 | + $dump_size1 = $test_dump_size + 0.5*$test_dump_size*ceil(($looprun - $test_steps)/$test_steps); |
|
229 | 229 | $dump_size = $loopno*$dump_size1*$dump_types; |
230 | 230 | $app_fixed_size = 5e7; |
231 | - $est_size = $log_size+$dump_size+$app_fixed_size; |
|
231 | + $est_size = $log_size + $dump_size + $app_fixed_size; |
|
232 | 232 | |
233 | - if($GLOBALS["debug"]){ |
|
233 | + if ($GLOBALS["debug"]) { |
|
234 | 234 | print "test_steps=".$test_steps."<br>"; |
235 | 235 | print "test_log_size=".$test_log_size."<br>"; |
236 | 236 | print "log_size1=".$log_size1."<br>"; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | if ($njobs < $nhosts) { |
322 | 322 | return $flops_per_job/$median_flops; |
323 | 323 | } else { |
324 | - $k = (int)(($njobs+$nhosts-1)/$nhosts); |
|
324 | + $k = (int)(($njobs + $nhosts - 1)/$nhosts); |
|
325 | 325 | return $k*$flops_per_job/$median_flops; |
326 | 326 | } |
327 | 327 | } |
@@ -361,27 +361,27 @@ discard block |
||
361 | 361 | if ($GLOBALS["debug"]) { |
362 | 362 | print "est_cpu_time is ".$est_cpu_time."<br>"; |
363 | 363 | } |
364 | - if ($error==0) { |
|
365 | - $err_msgs=file("output"); |
|
366 | - $err="Your test job <strong>failed</strong> |
|
364 | + if ($error == 0) { |
|
365 | + $err_msgs = file("output"); |
|
366 | + $err = "Your test job <strong>failed</strong> |
|
367 | 367 | <br>Please refer to the following Error Message:<br><p> |
368 | 368 | "; |
369 | - foreach($err_msgs as $line){ |
|
370 | - $err=$err.$line."<br>"; |
|
369 | + foreach ($err_msgs as $line) { |
|
370 | + $err = $err.$line."<br>"; |
|
371 | 371 | } |
372 | - $err=$err." <p> |
|
372 | + $err = $err." <p> |
|
373 | 373 | <a href=sandbox.php><strong> File_Sandbox </strong></a> |
374 | 374 | "; |
375 | 375 | error_page($err); |
376 | 376 | } |
377 | 377 | |
378 | 378 | system("rm *"); |
379 | - $info->rsc_fpops_est = $est_cpu_time * 1.5e9; |
|
380 | - $info->rsc_fpops_bound = $info->rsc_fpops_est * 20; |
|
379 | + $info->rsc_fpops_est = $est_cpu_time*1.5e9; |
|
380 | + $info->rsc_fpops_bound = $info->rsc_fpops_est*20; |
|
381 | 381 | |
382 | - if ($disk==0){ |
|
383 | - $info->rsc_disk_bound=1000000; |
|
384 | - } else{ |
|
382 | + if ($disk == 0) { |
|
383 | + $info->rsc_disk_bound = 1000000; |
|
384 | + } else { |
|
385 | 385 | $info->rsc_disk_bound = $disk; |
386 | 386 | } |
387 | 387 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | // |
393 | 393 | $njobs = count(file($cmdline_file_path)); |
394 | 394 | $secs_est = estimated_makespan($njobs, $info->rsc_fpops_est); |
395 | - if($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
395 | + if ($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
396 | 396 | //assume the server's flops is 1.5G and the average client's flops is 1G |
397 | 397 | $hrs_est = number_format($secs_est*1.5/60, 2); |
398 | 398 | //$hrs_est = number_format($secs_est, 2); |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | } |
417 | 417 | |
418 | 418 | function submit_job($app, $batch_id, $info, $cmdline, $i) { |
419 | - $client_disk=$info->rsc_disk_bound*2; |
|
420 | - if($client_disk<500000000) $client_disk=500000000; |
|
419 | + $client_disk = $info->rsc_disk_bound*2; |
|
420 | + if ($client_disk < 500000000) $client_disk = 500000000; |
|
421 | 421 | $cmd = "cd ../..; ./bin/create_work --appname $app->name --batch $batch_id --rsc_fpops_est $info->rsc_fpops_est --rsc_fpops_bound $info->rsc_fpops_bound --rsc_disk_bound $client_disk"; |
422 | 422 | if ($cmdline) { |
423 | 423 | $cmd .= " --command_line \"$cmdline\""; |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | $x = file_get_contents("$tmpfile"); |
442 | 442 | $info = unserialize($x); |
443 | 443 | |
444 | - $njobs=0; |
|
444 | + $njobs = 0; |
|
445 | 445 | $cmdlines = file($info->cmdline_file_path); |
446 | - foreach ($cmdlines as $cmdline){ |
|
446 | + foreach ($cmdlines as $cmdline) { |
|
447 | 447 | if (preg_match("/^\s*-var/", $cmdline)) { |
448 | 448 | $njobs++; |
449 | 449 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | |
460 | 460 | $i = 0; |
461 | 461 | foreach ($cmdlines as $cmdline) { |
462 | - if (preg_match("/^\s*-var/", $cmdline)){ |
|
462 | + if (preg_match("/^\s*-var/", $cmdline)) { |
|
463 | 463 | submit_job($app, $batch_id, $info, $cmdline, $i); |
464 | 464 | $i++; |
465 | 465 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | display_errors(); |
19 | 19 | |
20 | 20 | $app_name = "treeThreader"; |
21 | -$log = fopen("/tmp/tt_job.log","a+"); |
|
21 | +$log = fopen("/tmp/tt_job.log", "a+"); |
|
22 | 22 | |
23 | 23 | function error($s) { |
24 | 24 | echo "<error>\n<message>$s</message>\n</error>\n"; |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | function handle_submit($r, $user, $app) { |
29 | - global $app_name,$log; |
|
29 | + global $app_name, $log; |
|
30 | 30 | |
31 | - $timestamp = date("Y-m-d H:i",time()); |
|
31 | + $timestamp = date("Y-m-d H:i", time()); |
|
32 | 32 | // read the list of template filenames |
33 | 33 | // |
34 | 34 | $files = file("../../tree_threader_template_files"); |
35 | 35 | if ($files === false) { |
36 | - fwrite($log,"$timestamp\ttemplate file tree_threader_template_files\n"); |
|
36 | + fwrite($log, "$timestamp\ttemplate file tree_threader_template_files\n"); |
|
37 | 37 | error("no templates file"); |
38 | 38 | |
39 | 39 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | // |
91 | 91 | function handle_get_output($r, $batch) { |
92 | 92 | global $log; |
93 | - $timestamp = date("Y-m-d H:i",time()); |
|
93 | + $timestamp = date("Y-m-d H:i", time()); |
|
94 | 94 | $wus = BoincWorkUnit::enum("batch=$batch->id"); |
95 | 95 | $outdir = "/tmp/treeThreader_result_".$batch->id; |
96 | 96 | @mkdir($outdir); |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | error("can't zip output files"); |
130 | 130 | } |
131 | 131 | $fname = "treeThreader_result_".$batch->id.".zip"; |
132 | - $treeThreader_dir="treeThreaderResult"; |
|
133 | - if(!is_dir("../../download/$treeThreader_dir"))mkdir("../../download/$treeThreader_dir"); |
|
132 | + $treeThreader_dir = "treeThreaderResult"; |
|
133 | + if (!is_dir("../../download/$treeThreader_dir"))mkdir("../../download/$treeThreader_dir"); |
|
134 | 134 | @symlink("/tmp/$fname", "../../download/$treeThreader_dir/$fname"); |
135 | 135 | system("rm -fr $outdir"); |
136 | 136 | $config = simplexml_load_string(file_get_contents("../../config.xml")); |
137 | 137 | $download_url = trim((string)$config->config->download_url); |
138 | 138 | echo "<tt_reply>\n<url>$download_url/$treeThreader_dir/$fname</url>\n</tt_reply>\n"; |
139 | - $log_msg="$timestamp\tuser $batch->user_id downloads results for batch $batch->id : $download_url/$treeThreader_dir/$fname\n"; |
|
139 | + $log_msg = "$timestamp\tuser $batch->user_id downloads results for batch $batch->id : $download_url/$treeThreader_dir/$fname\n"; |
|
140 | 140 | fwrite($log, $log_msg); |
141 | 141 | } |
142 | 142 |