\n";
print_prefs_display_global($user);
}
////////////////////////////////////////////
//
// Functions to display preference subsets as forms
//
function prefs_form_global($user, $prefs) {
$x = "Should ".PROJECT." run while the computer is on battery power?
(This matters only for portable computers)
";
$y = "Yes run_on_batteries?"checked":"")
."> No run_on_batteries?"":"checked")
.">
";
row2($x, $y);
$x = "Should ".PROJECT." run while you're using the computer?";
$y = "Yes run_if_user_active?"checked":"")
."> No run_if_user_active?"":"checked")
.">
";
row2($x, $y);
$x = "Should ".PROJECT." ask you before connecting to Internet?
(This matters only if you use a modem)
";
$y = "Yes confirm_before_connecting?"checked":"")
."> No confirm_before_connecting?"":"checked")
.">
";
row2($x, $y);
$x = "Should ".PROJECT." disconnect when done if it connected?
(This matters only if you use a modem)
";
$y = "Yes hangup_if_dialed?"checked":"")
."> No hangup_if_dialed?"":"checked")
.">
";
row2($x, $y);
$x = "Keep enough to work on disk to last between";
$y = "
and
days
";
row2($x, $y);
row1("Limit the disk space used by BOINC:");
row2("Use no more than",
" Gbytes"
);
row2("Leave at least",
" Gbytes free"
);
row2("Use no more than",
" % of total space"
);
row1("Limit BOINC's network use:");
$d = $prefs->max_bytes_sec_down;
$dt = $d?"$d":"";
$u = $prefs->max_bytes_sec_up;
$ut = $u?"$u":"";
row2("Maximum bytes/sec download",
""
);
row2("Maximum bytes/sec upload",
""
);
}
function prefs_form_email($prefs) {
$y = "Yes send_email?"checked":"")
."> No send_email?"":"checked")
.">
";
row2("Should ".PROJECT." send you email newsletters?", $y);
$y = "Yes show_email?"checked":"")
."> No show_email?"":"checked")
.">
";
row2("Should ".PROJECT." show your email address on its web site?", $y);
}
function prefs_form_resource($prefs) {
row2(
"Resource share: The proportion of your computer's resources
(processing time and disk space)
allocated to ".PROJECT."
relative to the other BOINC projects in which you participate.
The default is 100.
For example, if you participate in two projects and
give them resource shares of 100 and 200,
the first will get 1/3 of our resources and the second will get 2/3.
",
"venue);
}
function venue_form($user) {
if ($user->venue == "home") $h = "selected";
if ($user->venue == "work") $w = "selected";
if ($user->venue == "school") $s = "selected";
row2("Default computer location",
"
"
);
}
function venue_parse_form(&$user) {
$user->venue = $_GET['default_venue'];
}
function venue_update($user) {
mysql_query("update user set venue='$user->venue' where id=$user->id");
}
////////////////////////////////////////////
//
// Functions to parse form elements, modifying a preferences structure
//
function prefs_global_parse_form(&$prefs) {
$run_on_batteries = $_GET["run_on_batteries"];
$run_if_user_active = $_GET["run_if_user_active"];
$confirm_before_connecting = $_GET["confirm_before_connecting"];
$hangup_if_dialed = $_GET["hangup_if_dialed"];
$work_buf_min_days = $_GET["work_buf_min_days"];
$work_buf_max_days = $_GET["work_buf_max_days"];
$disk_max_used_gb = $_GET["disk_max_used_gb"];
$disk_max_used_pct = $_GET["disk_max_used_pct"];
$disk_min_free_gb = $_GET["disk_min_free_gb"];
$max_bytes_sec_down = $_GET["max_bytes_sec_down"];
$max_bytes_sec_up = $_GET["max_bytes_sec_up"];
$prefs->run_on_batteries = ($run_on_batteries == "yes");
$prefs->run_if_user_active = ($run_if_user_active == "yes");
$prefs->confirm_before_connecting = ($confirm_before_connecting == "yes");
$prefs->hangup_if_dialed = ($hangup_if_dialed == "yes");
if ($work_buf_min_days<0) $work_buf_min_days = 0;
if ($work_buf_max_days<0) $work_buf_max_days = 0;
if ($work_buf_min_days > $work_buf_max_days) $work_buf_min_days = $work_buf_max_days;
$prefs->work_buf_min_days = $work_buf_min_days;
$prefs->work_buf_max_days = $work_buf_max_days;
if ($disk_max_used_gb<0) $disk_max_used_gb = 0;
if ($disk_max_used_pct<0) $disk_max_used_pct = 0;
if ($disk_max_used_pct>100) $disk_max_used_pct = 100;
if ($disk_min_free_gb<0) $disk_min_free_gb = 0;
$prefs->disk_max_used_gb = $disk_max_used_gb;
$prefs->disk_max_used_pct = $disk_max_used_pct;
$prefs->disk_min_free_gb = $disk_min_free_gb;
$prefs->max_bytes_sec_down = $max_bytes_sec_down;
$prefs->max_bytes_sec_up = $max_bytes_sec_up;
}
function prefs_resource_parse_form(&$prefs) {
$prefs->resource_share = $_GET['resource_share'];
}
function prefs_email_parse_form(&$prefs) {
$prefs->send_email = ($_GET['send_email'] == "yes");
$prefs->show_email = ($_GET['show_email'] == "yes");
}
function prefs_project_parse_form(&$prefs) {
$prefs->project_specific = project_specific_prefs_parse_form();
}
////////////////////////////////////////////
//
// convert prefs from structure to XML
//
function global_prefs_make_xml($prefs, $primary=true) {
if ($primary) {
$xml = "\n";
$now = time();
$xml = $xml."$now\n";
}
if ($prefs->run_on_batteries) {
$xml = $xml."\n";
}
if ($prefs->run_if_user_active) {
$xml = $xml."\n";
}
if ($prefs->confirm_before_connecting) {
$xml = $xml."\n";
}
if ($prefs->hangup_if_dialed) {
$xml = $xml."\n";
}
$xml = $xml
."$prefs->work_buf_min_days\n"
."$prefs->work_buf_max_days\n";
$xml = $xml
."$prefs->disk_max_used_gb\n"
."$prefs->disk_max_used_pct\n"
."$prefs->disk_min_free_gb\n"
."$prefs->max_bytes_sec_down\n"
."$prefs->max_bytes_sec_up\n";
if ($prefs->home) {
$xml = $xml."\n".global_prefs_make_xml($prefs->home, false)."\n";
}
if ($prefs->work) {
$xml = $xml."\n".global_prefs_make_xml($prefs->work, false)."\n";
}
if ($prefs->school) {
$xml = $xml."\n".global_prefs_make_xml($prefs->school, false)."\n";
}
if ($primary) {
$xml = $xml."\n";
}
return $xml;
}
function project_prefs_make_xml($prefs, $primary=true) {
$xml = "";
if ($primary) {
$xml = "\n";
if ($prefs->show_email == 1) {
$xml = $xml."\n";
}
if ($prefs->send_email == 1) {
$xml = $xml."\n";
}
}
if ($prefs->resource_share) {
$xml = $xml
."$prefs->resource_share\n";
}
if ($prefs->project_specific) {
$x = trim($prefs->project_specific);
$xml = $xml
."\n$x\n\n";
}
if ($prefs->home) {
$xml = $xml."\n".project_prefs_make_xml($prefs->home, false)."\n";
}
if ($prefs->work) {
$xml = $xml."\n".project_prefs_make_xml($prefs->work, false)."\n";
}
if ($prefs->school) {
$xml = $xml."\n".project_prefs_make_xml($prefs->school, false)."\n";
}
if ($primary) {
$xml = $xml."\n";
}
return $xml;
}
////////////////////////////////////////////
//
// Update user's prefs in database, from a given structure
//
function global_prefs_update(&$user, $prefs) {
$prefs_xml = global_prefs_make_xml($prefs);
$retval = mysql_query("update user set global_prefs='$prefs_xml' where id=$user->id");
$user->global_prefs = $prefs_xml;
return $retval;
}
function project_prefs_update(&$user, $prefs) {
$prefs_xml = project_prefs_make_xml($prefs);
$retval = mysql_query("update user set project_prefs='$prefs_xml' where id=$user->id");
$user->project_prefs = $prefs_xml;
return $retval;
}
?>