- user web: more of the above.

Also, try to make it PHP 4 compatible

svn path=/trunk/boinc/; revision=13982
This commit is contained in:
David Anderson 2007-10-29 04:02:41 +00:00
parent dc4ca1e5cd
commit ee1621c566
9 changed files with 142 additions and 123 deletions

View File

@ -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

View File

@ -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);
}
}
?>

View File

@ -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);
}

View File

@ -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";
}

View File

@ -1,7 +1,7 @@
<?php
$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/sanitize_html.inc");
require_once("../inc/cache.inc");
@ -62,13 +62,7 @@ function show_combo_box($name, $filename, $selection=null) {
}
function get_profile($userid) {
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
if (!$result) {
return NULL;
}
$profile = mysql_fetch_object($result);
mysql_free_result($result);
return $profile;
return BoincProfile::lookup("userid = $userid");
}
function show_profile_creation_page($user) {
@ -81,11 +75,12 @@ function show_profile_creation_page($user) {
$privatekey = parse_config($config, "<recaptcha_private_key>");
if ($privatekey) {
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$_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.<br>".
"(reCAPTCHA said: " . $resp->error . ")");
"(reCAPTCHA said: " . $resp->error . ")"
);
}
}
@ -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);

View File

@ -2,8 +2,6 @@
require_once("../inc/profile.inc");
db_init();
$user = get_logged_in_user(true);
show_profile_creation_page($user);

View File

@ -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.<br>";
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();
}
}

View File

@ -20,7 +20,13 @@ page_head("Profile search results");
echo "<h2>Profiles containing '$search_string'</h2>\n";
$q = "select * from profile where match(response1, response2) against ('$search_string') limit $offset,$count";
$result = mysql_query($q);
echo "<table align=\"center\" cellpadding=\"1\" border=\"1\" width=\"90%\"><tr><th align=\"center\">User name</th><th align=\"center\">Joined project</th><th align=\"center\">Country</th><th align=\"center\">Total credit</th><th align=\"center\">Recent credit</th></tr>";
echo "<table align=\"center\" cellpadding=\"1\" border=\"1\" width=\"90%\">
<tr><th align=\"center\">User name</th>
<th align=\"center\">Joined project</th>
<th align=\"center\">Country</th>
<th align=\"center\">Total credit</th>
<th align=\"center\">Recent credit</th></tr>
";
$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 "</table>";
mysql_free_result($result);
if ($offset==0 && $n==0) {
echo "No profiles found containing '$search_string'";
}

View File

@ -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,7 +167,6 @@ bool TIME_PREFS::suspended() const {
// WEEK_PREFS implementation
WEEK_PREFS::WEEK_PREFS() {
for (int i=0; i<7; i++) {
days[i] = 0;
}
@ -177,7 +174,6 @@ WEEK_PREFS::WEEK_PREFS() {
WEEK_PREFS::WEEK_PREFS(const WEEK_PREFS& original) {
for (int i=0; i<7; i++) {
TIME_SPAN* time = original.days[i];
if (time) {
@ -190,7 +186,6 @@ 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++) {
TIME_SPAN* time = rhs.days[i];
@ -211,7 +206,6 @@ 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++) {
TIME_SPAN* time = original.days[i];
if (time) {
@ -229,7 +223,6 @@ WEEK_PREFS::~WEEK_PREFS() {
void WEEK_PREFS::clear() {
for (int i=0; i<7; i++) {
if (days[i]) {
delete days[i];
@ -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;
@ -304,6 +291,7 @@ void GLOBAL_PREFS::defaults() {
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 <venue> elements,
@ -791,7 +779,6 @@ int GLOBAL_PREFS::write_subset(MIOFILE& f, GLOBAL_PREFS_MASK& mask) {
TIME_SPAN* net = net_times.week.get(i);
//write only when needed
if (net || cpu) {
f.printf(" <day_prefs>\n");
f.printf(" <day_of_week>%d</day_of_week>\n", i);
if (cpu) {
@ -805,9 +792,7 @@ int GLOBAL_PREFS::write_subset(MIOFILE& f, GLOBAL_PREFS_MASK& mask) {
f.printf(" </day_prefs>\n");
}
}
f.printf("</global_preferences>\n");
return 0;
}