diff --git a/checkin_notes b/checkin_notes index c98dabdca3..d7d92d2132 100644 --- a/checkin_notes +++ b/checkin_notes @@ -10113,3 +10113,20 @@ David 28 Oct 2007 merge_by_name.php pending.php top_hosts.php + +David 28 Oct 2007 + - user web: more of the above. + Also, try to make it PHP 4 compatible + + html/ + inc/ + boinc_db.inc + db_conn.inc + host.inc + profile.inc + user/ + create_profile.php + profile_menu.php + profile_search_action.php + lib/ + prefs.C diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 365bd69cdc..502cfa91fb 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -3,7 +3,7 @@ require_once("../inc/db_conn.inc"); class BoincDb extends DbConn { - public static $instance; + static $instance; static function get() { if (!isset($instance)) { @@ -99,9 +99,9 @@ class BoincResult { $db = BoincDb::get(); return $db->enum('result', 'BoincResult', $clause); } - static function update_multi($clause) { + static function update_aux($clause) { $db = BoincDb::get(); - return $db->update_multi('result', $clause); + return $db->update_aux('result', $clause); } } @@ -112,4 +112,23 @@ class BoincPost { } } +class BoincProfile { + static function lookup($clause) { + $db = BoincDb::get(); + return $db->lookup('profile', 'BoincProfile', $clause); + } + static function update_aux($clause) { + $db = BoincDb::get(); + return $db->update_aux('profile', $clause); + } + static function insert($clause) { + $db = BoincDb::get(); + return $db->insert('profile', $clause); + } + static function enum($clause) { + $db = BoincDb::get(); + return $db->enum('profile', 'BoincProfile', $clause); + } +} + ?> diff --git a/html/inc/db_conn.inc b/html/inc/db_conn.inc index 02d0348424..7942b42a64 100644 --- a/html/inc/db_conn.inc +++ b/html/inc/db_conn.inc @@ -7,8 +7,8 @@ error_reporting(E_ALL); // Intended to be subclassed (e.g., BoincDb, BossaDb) class DbConn { - private $db_conn; - private $db_name; + var $db_conn; + var $db_name; function init_conn($user_tag, $passwd_tag, $host_tag, $name_tag) { $config = get_config(); @@ -75,7 +75,7 @@ class DbConn { $query = "update DBNAME.$table set $clause where id=$obj->id"; return $this->do_query($query); } - function update_multi($table, $clause) { + function update_aux($table, $clause) { $query = "update DBNAME.$table set $clause"; return $this->do_query($query); } diff --git a/html/inc/host.inc b/html/inc/host.inc index 66702c3c8c..f8b8f3e694 100644 --- a/html/inc/host.inc +++ b/html/inc/host.inc @@ -405,11 +405,11 @@ function merge_hosts($old_host, $new_host) { echo "
Merging host $old_host->id into host $new_host->id\n"; - // decay the average credit of both hosts - // - $now = time(); - update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); - update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); + // decay the average credit of both hosts + // + $now = time(); + update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); + update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); // update the database: // - add credit from old to new host @@ -423,7 +423,7 @@ function merge_hosts($old_host, $new_host) { if (!$result) { return "Couldn't update credit of new computer"; } - $result = BoincResult::update_multi("hostid=$new_host->id where hostid=$old_host->id"); + $result = BoincResult::update_aux("hostid=$new_host->id where hostid=$old_host->id"); if (!$result) { return "Couldn't update results"; } diff --git a/html/inc/profile.inc b/html/inc/profile.inc index 04083bdbe5..1fc5dd76c7 100644 --- a/html/inc/profile.inc +++ b/html/inc/profile.inc @@ -1,7 +1,7 @@ id); if (post_str("submit", true)) { - $config = get_config(); - $privatekey = parse_config($config, ""); - if ($privatekey) { - $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], - $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); - - if (!$resp->is_valid) { - error_page("The reCAPTCHA wasn't entered correctly. Go back and try it again.
". - "(reCAPTCHA said: " . $resp->error . ")"); - } - } + $config = get_config(); + $privatekey = parse_config($config, ""); + if ($privatekey) { + $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], + $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"] + ); + if (!$resp->is_valid) { + error_page("The reCAPTCHA wasn't entered correctly. Go back and try it again.
". + "(reCAPTCHA said: " . $resp->error . ")" + ); + } + } process_create_profile($user, $profile); exit(); @@ -125,10 +120,10 @@ function show_questions($profile) { $response1 = ""; $response2 = ""; if (isset($profile->response1)) { - $response1 = stripslashes($profile->response1); + $response1 = stripslashes($profile->response1); } if (isset($profile->response2)) { - $response2 = stripslashes($profile->response2); + $response2 = stripslashes($profile->response2); } row1(show_profile_heading1()); @@ -233,8 +228,8 @@ function show_submit() { $config = get_config(); $publickey = parse_config($config, ""); if ($publickey) { - table_row("To protect project's webpages from spam, we ask you to type in two words shown in the image:
\n". - recaptcha_get_html($publickey)); + table_row("To protect project's webpages from spam, we ask you to type in two words shown in the image:
\n". + recaptcha_get_html($publickey)); } table_row("

"); } @@ -303,31 +298,29 @@ function process_create_profile($user, $profile) { $response1 = sanitize_html($response1); $response2 = sanitize_html($response2); if ($profile) { - $query = 'UPDATE profile SET ' - ." response1 = '".boinc_real_escape_string($response1)."'," + $query = " response1 = '".boinc_real_escape_string($response1)."'," ." response2 = '".boinc_real_escape_string($response2)."'," ." language = '".boinc_real_escape_string($language)."'," ." has_picture = '$hasPicture'," ." verification = '$profile->verification'" ." WHERE userid = '$user->id'"; - $result = mysql_query($query); + $result = BoincProfile::update_aux($query); if (!$result) { - echo mysql_error(); profile_error_page("Couldn't update profile: database error"); } } else { - $query = 'INSERT INTO profile SET ' + $query = 'SET ' ." userid = '$user->id'," ." language = '".boinc_real_escape_string($language)."'," ." response1 = '".boinc_real_escape_string($response1)."'," ." response2 = '".boinc_real_escape_string($response2)."'," ." has_picture = '$hasPicture'," ." verification=0"; - $result = mysql_query($query); + $result = BoincProfile::insert($query); if (!$result) { profile_error_page("Couldn't create profile: database error"); } - mysql_query("update user set has_profile=1 where id=$user->id"); + $user->update("has_profile=1"); } show_result_page($user); diff --git a/html/user/create_profile.php b/html/user/create_profile.php index 7de0a8232c..f28d6470ef 100644 --- a/html/user/create_profile.php +++ b/html/user/create_profile.php @@ -2,8 +2,6 @@ require_once("../inc/profile.inc"); -db_init(); - $user = get_logged_in_user(true); show_profile_creation_page($user); diff --git a/html/user/profile_menu.php b/html/user/profile_menu.php index 4131314313..58ad7226a4 100644 --- a/html/user/profile_menu.php +++ b/html/user/profile_menu.php @@ -2,7 +2,7 @@ $cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit -require_once("../inc/db.inc"); +require_once("../inc/boinc_db.inc"); require_once("../inc/util.inc"); require_once("../inc/profile.inc"); require_once("../inc/uotd.inc"); @@ -84,25 +84,25 @@ function select_profile($cmd) { // Request for a random profile. // if ($cmd == "rand") { + $profiles = array(); if ($_GET['pic'] == 0) { - $result = mysql_query("SELECT userid FROM profile WHERE has_picture=0"); + $profiles = BoincProfile::enum("has_picture=0"); } else if ($_GET['pic'] == 1) { - $result = mysql_query("SELECT userid FROM profile WHERE has_picture=1"); + $profiles = BoincProfile::enum("has_picture=1"); } else if ($_GET['pic'] == -1) { - $result = mysql_query("SELECT userid FROM profile"); + $profiles = BoincProfile::enum(null); } - while ($row = mysql_fetch_row($result)) { - $userIds[] = $row[0]; - } - - if (count($userIds) == 0) { + if (count($profiles) == 0) { + page_head("No profiles"); echo "No profiles matched your query.
"; + page_tail(); exit(); } - shuffle($userIds); - header("Location: " . URL_BASE . "/view_profile.php?userid=" . $userIds[0]); + shuffle($profiles); + $userid = $profiles[0]->userid; + header("Location: ".URL_BASE."/view_profile.php?userid=$userid"); exit(); } } diff --git a/html/user/profile_search_action.php b/html/user/profile_search_action.php index c4c424fef1..51efdce60e 100644 --- a/html/user/profile_search_action.php +++ b/html/user/profile_search_action.php @@ -20,7 +20,13 @@ page_head("Profile search results"); echo "

Profiles containing '$search_string'

\n"; $q = "select * from profile where match(response1, response2) against ('$search_string') limit $offset,$count"; $result = mysql_query($q); -echo ""; +echo "
User nameJoined projectCountryTotal creditRecent credit
+ + + + + +"; $n = 0; while ($profile = mysql_fetch_object($result)) { show_profile_link($profile, $n+$offset+1); @@ -28,6 +34,7 @@ while ($profile = mysql_fetch_object($result)) { } echo "
User nameJoined projectCountryTotal creditRecent credit
"; mysql_free_result($result); + if ($offset==0 && $n==0) { echo "No profiles found containing '$search_string'"; } diff --git a/lib/prefs.C b/lib/prefs.C index 26632ab0c1..9b72299910 100644 --- a/lib/prefs.C +++ b/lib/prefs.C @@ -65,8 +65,8 @@ void GLOBAL_PREFS_MASK::set_all() { disk_max_used_pct = true; disk_min_free_gb = true; vm_max_used_frac = true; - ram_max_used_busy_frac = true; - ram_max_used_idle_frac = true; + ram_max_used_busy_frac = true; + ram_max_used_idle_frac = true; idle_time_to_run = true; max_bytes_sec_up = true; max_bytes_sec_down = true; @@ -95,8 +95,8 @@ bool GLOBAL_PREFS_MASK::are_prefs_set() { if (disk_max_used_pct) return true; if (disk_min_free_gb) return true; if (vm_max_used_frac) return true; - if (ram_max_used_busy_frac) return true; - if (ram_max_used_idle_frac) return true; + if (ram_max_used_busy_frac) return true; + if (ram_max_used_idle_frac) return true; if (idle_time_to_run) return true; if (max_bytes_sec_up) return true; if (max_bytes_sec_down) return true; @@ -121,7 +121,6 @@ bool GLOBAL_PREFS_MASK::are_simple_prefs_set() { // TIME_SPAN implementation bool TIME_SPAN::suspended(double hour) const { - if (start_hour == end_hour) return false; if (start_hour == 0 && end_hour == 24) return false; if (start_hour == 24 && end_hour == 0) return true; @@ -134,7 +133,6 @@ bool TIME_SPAN::suspended(double hour) const { TIME_SPAN::TimeMode TIME_SPAN::mode() const { - if (end_hour == start_hour || (start_hour == 0.0 && end_hour == 24.0)) { return Always; } else if (start_hour == 24.0 && end_hour == 0.0) { @@ -169,16 +167,14 @@ bool TIME_PREFS::suspended() const { // WEEK_PREFS implementation WEEK_PREFS::WEEK_PREFS() { - - for (int i = 0; i < 7; i++) { + for (int i=0; i<7; i++) { days[i] = 0; } } WEEK_PREFS::WEEK_PREFS(const WEEK_PREFS& original) { - - for (int i = 0; i < 7; i++) { + for (int i=0; i<7; i++) { TIME_SPAN* time = original.days[i]; if (time) { days[i] = new TIME_SPAN(time->start_hour, time->end_hour); @@ -190,9 +186,8 @@ WEEK_PREFS::WEEK_PREFS(const WEEK_PREFS& original) { WEEK_PREFS& WEEK_PREFS::operator=(const WEEK_PREFS& rhs) { - if (this != &rhs) { - for (int i = 0; i < 7; i++) { + for (int i=0; i<7; i++) { TIME_SPAN* time = rhs.days[i]; if (time) { if (days[i]) { @@ -211,8 +206,7 @@ WEEK_PREFS& WEEK_PREFS::operator=(const WEEK_PREFS& rhs) { // Create a deep copy. void WEEK_PREFS::copy(const WEEK_PREFS& original) { - - for (int i = 0; i < 7; i++) { + for (int i=0; i<7; i++) { TIME_SPAN* time = original.days[i]; if (time) { days[i] = new TIME_SPAN(time->start_hour, time->end_hour); @@ -229,8 +223,7 @@ WEEK_PREFS::~WEEK_PREFS() { void WEEK_PREFS::clear() { - - for (int i = 0; i < 7; i++) { + for (int i=0; i<7; i++) { if (days[i]) { delete days[i]; days[i] = 0; @@ -247,27 +240,21 @@ TIME_SPAN* WEEK_PREFS::get(int day) const { void WEEK_PREFS::set(int day, double start, double end) { - if (day < 0 || day > 6) return; - if (days[day]) delete days[day]; days[day] = new TIME_SPAN(start, end); } void WEEK_PREFS::set(int day, TIME_SPAN* time) { - if (day < 0 || day > 6) return; if (days[day] == time) return; if (days[day]) delete days[day]; - days[day] = time; } void WEEK_PREFS::unset(int day) { - if (day < 0 || day > 6) return; - if (days[day]) { delete days[day]; days[day] = 0; @@ -299,11 +286,12 @@ void GLOBAL_PREFS::defaults() { disk_max_used_pct = 50; disk_min_free_gb = 0.1; vm_max_used_frac = 0.75; - ram_max_used_busy_frac = 0.5; - ram_max_used_idle_frac = 0.9; + ram_max_used_busy_frac = 0.5; + ram_max_used_idle_frac = 0.9; max_bytes_sec_up = 0; max_bytes_sec_down = 0; cpu_usage_limit = 100; + // don't initialize source_project, source_scheduler, // mod_time, host_specific here // since they are outside of elements, @@ -537,19 +525,19 @@ int GLOBAL_PREFS::parse_override( continue; } if (xp.parse_double(tag, "vm_max_used_pct", dtemp)) { - vm_max_used_frac = dtemp/100; + vm_max_used_frac = dtemp/100; mask.vm_max_used_frac = true; continue; } if (xp.parse_double(tag, "ram_max_used_busy_pct", dtemp)) { if (!dtemp) dtemp = 100; - ram_max_used_busy_frac = dtemp/100; + ram_max_used_busy_frac = dtemp/100; mask.ram_max_used_busy_frac = true; continue; } if (xp.parse_double(tag, "ram_max_used_idle_pct", dtemp)) { if (!dtemp) dtemp = 100; - ram_max_used_idle_frac = dtemp/100; + ram_max_used_idle_frac = dtemp/100; mask.ram_max_used_idle_frac = true; continue; } @@ -653,33 +641,33 @@ int GLOBAL_PREFS::write(MIOFILE& f) { disk_max_used_pct, disk_min_free_gb, vm_max_used_frac*100, - ram_max_used_busy_frac*100, - ram_max_used_idle_frac*100, + ram_max_used_busy_frac*100, + ram_max_used_idle_frac*100, idle_time_to_run, max_bytes_sec_up, max_bytes_sec_down, cpu_usage_limit ); - for (int i = 0; i < 7; i++) { - TIME_SPAN* cpu = cpu_times.week.get(i); + for (int i=0; i<7; i++) { + TIME_SPAN* cpu = cpu_times.week.get(i); TIME_SPAN* net = net_times.week.get(i); - //write only when needed - if (net || cpu) { - - f.printf(" \n"); - f.printf(" %d\n", i); - if (cpu) { - f.printf(" %.02f\n", cpu->start_hour); - f.printf(" %.02f\n", cpu->end_hour); - } - if (net) { - f.printf(" %.02f\n", net->start_hour); - f.printf(" %.02f\n", net->end_hour); - } - f.printf(" \n"); - } - } + //write only when needed + if (net || cpu) { + + f.printf(" \n"); + f.printf(" %d\n", i); + if (cpu) { + f.printf(" %.02f\n", cpu->start_hour); + f.printf(" %.02f\n", cpu->end_hour); + } + if (net) { + f.printf(" %.02f\n", net->start_hour); + f.printf(" %.02f\n", net->end_hour); + } + f.printf(" \n"); + } + } f.printf("\n"); return 0; @@ -786,28 +774,25 @@ int GLOBAL_PREFS::write_subset(MIOFILE& f, GLOBAL_PREFS_MASK& mask) { f.printf(" %f\n", cpu_usage_limit); } - for (int i = 0; i < 7; i++) { - TIME_SPAN* cpu = cpu_times.week.get(i); + for (int i=0; i<7; i++) { + TIME_SPAN* cpu = cpu_times.week.get(i); TIME_SPAN* net = net_times.week.get(i); - //write only when needed - if (net || cpu) { - - f.printf(" \n"); - f.printf(" %d\n", i); - if (cpu) { - f.printf(" %.02f\n", cpu->start_hour); - f.printf(" %.02f\n", cpu->end_hour); - } - if (net) { - f.printf(" %.02f\n", net->start_hour); - f.printf(" %.02f\n", net->end_hour); - } - f.printf(" \n"); - } - } - + //write only when needed + if (net || cpu) { + f.printf(" \n"); + f.printf(" %d\n", i); + if (cpu) { + f.printf(" %.02f\n", cpu->start_hour); + f.printf(" %.02f\n", cpu->end_hour); + } + if (net) { + f.printf(" %.02f\n", net->start_hour); + f.printf(" %.02f\n", net->end_hour); + } + f.printf(" \n"); + } + } f.printf("\n"); - return 0; }