2002-04-30 22:22:54 +00:00
|
|
|
<?php
|
|
|
|
|
2002-09-27 06:12:50 +00:00
|
|
|
// This file contains support functions for display and editing
|
|
|
|
// preferences (global and project).
|
2002-05-29 23:25:21 +00:00
|
|
|
// Preferences are represented in two ways:
|
|
|
|
// - As a PHP structure (usually called $prefs)
|
2003-02-21 01:38:16 +00:00
|
|
|
// This has fields run_on_batteries, etc.
|
2002-12-19 05:11:25 +00:00
|
|
|
// The fields "project_specific" is raw XML
|
2002-05-29 23:25:21 +00:00
|
|
|
// - As XML (usually called $prefs_xml)
|
|
|
|
//
|
|
|
|
// This XML has the general structure
|
2003-03-04 19:13:21 +00:00
|
|
|
// <global_preferences>
|
|
|
|
// <mod_time>...</mod_time>
|
2003-02-21 01:38:16 +00:00
|
|
|
// <run_if_user_active/>
|
2003-02-27 22:30:31 +00:00
|
|
|
// <work_buf_min_days>1.3</work_buf_min_days>
|
2002-05-29 23:25:21 +00:00
|
|
|
// ...
|
2003-03-04 19:13:21 +00:00
|
|
|
// <home>
|
|
|
|
// <run_if_user_active/>
|
|
|
|
// ...
|
|
|
|
// </home>
|
2002-09-27 06:12:50 +00:00
|
|
|
// </global_preferences>
|
|
|
|
//
|
|
|
|
// and
|
|
|
|
//
|
2003-03-05 06:21:24 +00:00
|
|
|
// <project_preferences>
|
2002-09-27 06:12:50 +00:00
|
|
|
// <resource_share>4</resource_share>
|
2002-09-26 05:57:10 +00:00
|
|
|
// <project-specific>
|
2002-05-29 23:25:21 +00:00
|
|
|
// ... (arbitrary project-specific XML)
|
2002-09-26 05:57:10 +00:00
|
|
|
// </project-specific>
|
2003-03-05 06:21:24 +00:00
|
|
|
// <home>
|
|
|
|
// ...
|
|
|
|
// </home>
|
2002-09-27 06:12:50 +00:00
|
|
|
// </project_preferences>
|
2003-03-20 02:05:25 +00:00
|
|
|
//
|
|
|
|
// In addition there are some fields of the user table
|
|
|
|
// (send_email and show_hosts) that are treated as project preferences
|
2002-05-29 23:25:21 +00:00
|
|
|
|
2002-12-19 05:11:25 +00:00
|
|
|
// Various functions are defined below for converting between these forms,
|
|
|
|
// and also to/from HTML form elements
|
|
|
|
|
|
|
|
|
|
|
|
include_once("project_specific_prefs.inc");
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
global $text;
|
|
|
|
global $parse_result;
|
2003-03-04 19:13:21 +00:00
|
|
|
global $top_parse_result;
|
2002-05-29 23:25:21 +00:00
|
|
|
global $in_project_specific;
|
2003-03-06 00:42:18 +00:00
|
|
|
global $venue_name;
|
2002-05-29 23:25:21 +00:00
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
// functions to parse preferences XML into a struct
|
2002-09-27 06:12:50 +00:00
|
|
|
//
|
2003-03-04 19:13:21 +00:00
|
|
|
function element_start_project($parser, $name, $attrs) {
|
2003-03-05 06:21:24 +00:00
|
|
|
global $top_parse_result;
|
|
|
|
global $parse_result;
|
2002-05-29 23:25:21 +00:00
|
|
|
global $text;
|
|
|
|
global $in_project_specific;
|
2003-03-06 00:42:18 +00:00
|
|
|
global $venue_name;
|
2002-05-29 23:25:21 +00:00
|
|
|
|
|
|
|
switch($name) {
|
2003-03-06 00:42:18 +00:00
|
|
|
case "venue":
|
|
|
|
$venue_name = $attrs["name"];
|
2003-03-04 21:33:10 +00:00
|
|
|
$top_parse_result = $parse_result;
|
|
|
|
$parse_result = null;
|
|
|
|
break;
|
2002-05-29 23:25:21 +00:00
|
|
|
case "project_specific":
|
|
|
|
$in_project_specific = 1;
|
|
|
|
$text = "";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ($in_project_specific) {
|
|
|
|
$text= $text."<$name>";
|
|
|
|
} else {
|
|
|
|
$text = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function element_start_global($parser, $name, $attrs) {
|
|
|
|
global $top_parse_result;
|
|
|
|
global $parse_result;
|
|
|
|
global $text;
|
2003-03-06 00:42:18 +00:00
|
|
|
global $venue_name;
|
2003-03-04 19:13:21 +00:00
|
|
|
|
|
|
|
switch($name) {
|
2003-03-06 00:42:18 +00:00
|
|
|
case "venue":
|
|
|
|
$venue_name = $attrs["name"];
|
2003-03-04 19:13:21 +00:00
|
|
|
$top_parse_result = $parse_result;
|
|
|
|
$parse_result = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$text = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function element_end_project($parser, $name) {
|
2002-05-29 23:25:21 +00:00
|
|
|
global $text;
|
|
|
|
global $parse_result;
|
|
|
|
global $in_project_specific;
|
2003-03-05 06:21:24 +00:00
|
|
|
global $top_parse_result;
|
2003-03-06 00:42:18 +00:00
|
|
|
global $venue_name;
|
2002-05-29 23:25:21 +00:00
|
|
|
|
|
|
|
switch($name) {
|
2003-03-06 00:42:18 +00:00
|
|
|
case "venue":
|
|
|
|
$top_parse_result->$venue_name = $parse_result;
|
2003-03-04 21:33:10 +00:00
|
|
|
$parse_result = $top_parse_result;
|
|
|
|
break;
|
2002-05-29 23:25:21 +00:00
|
|
|
case "project_specific":
|
2002-09-27 17:42:30 +00:00
|
|
|
$parse_result->project_specific = $text;
|
2002-05-29 23:25:21 +00:00
|
|
|
$in_project_specific = false;
|
|
|
|
break;
|
2003-03-04 19:13:21 +00:00
|
|
|
case "resource_share":
|
|
|
|
$parse_result->resource_share = $text;
|
|
|
|
break;
|
|
|
|
case "project_preferences":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ($in_project_specific) {
|
|
|
|
$text = $text."</$name>\n";
|
|
|
|
} else {
|
2003-03-21 22:33:20 +00:00
|
|
|
//echo "Unknown tag: $name\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function element_end_global($parser, $name) {
|
|
|
|
global $text;
|
|
|
|
global $parse_result;
|
|
|
|
global $top_parse_result;
|
2003-03-06 00:42:18 +00:00
|
|
|
global $venue_name;
|
2003-03-04 19:13:21 +00:00
|
|
|
|
|
|
|
switch($name) {
|
2003-03-06 00:42:18 +00:00
|
|
|
case "venue":
|
|
|
|
$top_parse_result->$venue_name = $parse_result;
|
2003-03-04 19:13:21 +00:00
|
|
|
$parse_result = $top_parse_result;
|
|
|
|
break;
|
2003-02-21 01:38:16 +00:00
|
|
|
case "run_on_batteries":
|
|
|
|
$parse_result->run_on_batteries = true;
|
2002-05-29 23:25:21 +00:00
|
|
|
break;
|
2003-02-21 01:38:16 +00:00
|
|
|
case "run_if_user_active":
|
|
|
|
$parse_result->run_if_user_active = true;
|
2002-05-29 23:25:21 +00:00
|
|
|
break;
|
2003-03-25 01:30:13 +00:00
|
|
|
case "start_hour":
|
|
|
|
$parse_result->start_hour = $text;
|
|
|
|
break;
|
|
|
|
case "end_hour":
|
|
|
|
$parse_result->end_hour = $text;
|
|
|
|
break;
|
2002-05-29 23:25:21 +00:00
|
|
|
case "confirm_before_connecting":
|
2003-02-24 21:25:16 +00:00
|
|
|
$parse_result->confirm_before_connecting = true;
|
2002-05-29 23:25:21 +00:00
|
|
|
break;
|
2003-03-10 23:17:16 +00:00
|
|
|
case "hangup_if_dialed":
|
|
|
|
$parse_result->hangup_if_dialed = true;
|
|
|
|
break;
|
2003-02-27 22:30:31 +00:00
|
|
|
case "work_buf_min_days":
|
|
|
|
$parse_result->work_buf_min_days = $text;
|
2002-05-29 23:25:21 +00:00
|
|
|
break;
|
2003-02-27 22:30:31 +00:00
|
|
|
case "work_buf_max_days":
|
|
|
|
$parse_result->work_buf_max_days = $text;
|
2002-05-29 23:25:21 +00:00
|
|
|
break;
|
2003-03-20 02:05:25 +00:00
|
|
|
case "max_cpus":
|
|
|
|
$parse_result->max_cpus = $text;
|
|
|
|
break;
|
|
|
|
case "disk_interval":
|
|
|
|
$parse_result->disk_interval = $text;
|
|
|
|
break;
|
2002-05-29 23:25:21 +00:00
|
|
|
case "disk_max_used_gb":
|
|
|
|
$parse_result->disk_max_used_gb = $text;
|
|
|
|
break;
|
|
|
|
case "disk_max_used_pct":
|
|
|
|
$parse_result->disk_max_used_pct = $text;
|
|
|
|
break;
|
|
|
|
case "disk_min_free_gb":
|
|
|
|
$parse_result->disk_min_free_gb = $text;
|
|
|
|
break;
|
2003-03-02 19:24:09 +00:00
|
|
|
case "max_bytes_sec_down":
|
|
|
|
$parse_result->max_bytes_sec_down = $text;
|
|
|
|
break;
|
|
|
|
case "max_bytes_sec_up":
|
|
|
|
$parse_result->max_bytes_sec_up = $text;
|
|
|
|
break;
|
2002-12-19 05:11:25 +00:00
|
|
|
case "mod_time":
|
|
|
|
$parse_result->mod_time = $text;
|
|
|
|
break;
|
2002-09-27 06:12:50 +00:00
|
|
|
case "global_preferences":
|
|
|
|
break;
|
2002-05-29 23:25:21 +00:00
|
|
|
default:
|
2003-03-21 22:33:20 +00:00
|
|
|
//echo "Unknown tag: $name\n";
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function char_handler($parser, $x) {
|
|
|
|
global $text;
|
|
|
|
$text = $text.$x;
|
|
|
|
}
|
|
|
|
|
2003-02-14 22:35:35 +00:00
|
|
|
// state of prefs for new users
|
|
|
|
//
|
2003-03-04 19:13:21 +00:00
|
|
|
function default_prefs_global() {
|
2003-02-07 09:00:35 +00:00
|
|
|
$p = null;
|
2003-02-21 01:38:16 +00:00
|
|
|
$p->run_on_batteries = false;
|
2003-02-24 21:25:16 +00:00
|
|
|
$p->run_if_user_active = true;
|
2003-03-25 01:30:13 +00:00
|
|
|
$p->start_hour = 0;
|
|
|
|
$p->end_hour = 0;
|
2003-02-24 21:25:16 +00:00
|
|
|
$p->confirm_before_connecting = false;
|
2003-03-10 23:17:16 +00:00
|
|
|
$p->hangup_if_dialed = true;
|
2003-02-27 22:30:31 +00:00
|
|
|
$p->work_buf_min_days = 1;
|
|
|
|
$p->work_buf_max_days = 3;
|
2003-03-20 02:05:25 +00:00
|
|
|
$p->max_cpus = 2;
|
|
|
|
$p->disk_interval = 60;
|
2003-02-08 02:06:35 +00:00
|
|
|
$p->disk_max_used_gb = 100;
|
2003-02-07 09:00:35 +00:00
|
|
|
$p->disk_max_used_pct = 50;
|
|
|
|
$p->disk_min_free_gb = 1;
|
2003-03-02 19:24:09 +00:00
|
|
|
$p->max_bytes_sec_down = 0;
|
|
|
|
$p->max_bytes_sec_up = 0;
|
2003-03-04 19:13:21 +00:00
|
|
|
return $p;
|
|
|
|
}
|
2003-02-07 09:00:35 +00:00
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function default_prefs_project() {
|
|
|
|
$p = null;
|
2003-02-07 09:00:35 +00:00
|
|
|
$p->resource_share = 100;
|
2003-02-24 21:25:16 +00:00
|
|
|
$p->project_specific = project_specific_prefs_default();
|
2003-02-07 09:00:35 +00:00
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
2003-02-27 22:30:31 +00:00
|
|
|
// state of prefs before parsing; initialize all booleans to false
|
2003-02-14 22:35:35 +00:00
|
|
|
//
|
2003-03-04 19:13:21 +00:00
|
|
|
function initialize_prefs_before_parsing_global() {
|
|
|
|
$p = default_prefs_global();
|
2003-02-27 22:30:31 +00:00
|
|
|
$p->run_on_batteries = false;
|
|
|
|
$p->run_if_user_active = false;
|
|
|
|
$p->confirm_before_connecting = false;
|
2003-03-10 23:17:16 +00:00
|
|
|
$p->hangup_if_dialed = false;
|
2003-02-24 21:25:16 +00:00
|
|
|
return $p;
|
2003-02-14 22:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function initialize_prefs_before_parsing_project() {
|
|
|
|
$p = default_prefs_project();
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse prefs from XML to a struct
|
2003-02-14 22:35:35 +00:00
|
|
|
//
|
2003-03-04 19:13:21 +00:00
|
|
|
function prefs_parse_project($prefs_xml) {
|
2002-05-29 23:25:21 +00:00
|
|
|
global $parse_result;
|
2003-03-04 19:13:21 +00:00
|
|
|
$parse_result = initialize_prefs_before_parsing_project();
|
|
|
|
$xml_parser = xml_parser_create();
|
|
|
|
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
|
|
|
|
xml_set_element_handler($xml_parser, "element_start_project", "element_end_project");
|
|
|
|
xml_set_character_data_handler($xml_parser, "char_handler");
|
|
|
|
xml_parse($xml_parser, $prefs_xml, 1);
|
|
|
|
return $parse_result;
|
|
|
|
}
|
2002-09-27 06:12:50 +00:00
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function prefs_parse_global($prefs_xml) {
|
|
|
|
global $parse_result;
|
|
|
|
$parse_result = initialize_prefs_before_parsing_global();
|
2002-05-29 23:25:21 +00:00
|
|
|
$xml_parser = xml_parser_create();
|
|
|
|
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
|
2003-03-04 19:13:21 +00:00
|
|
|
xml_set_element_handler($xml_parser, "element_start_global", "element_end_global");
|
2002-05-29 23:25:21 +00:00
|
|
|
xml_set_character_data_handler($xml_parser, "char_handler");
|
|
|
|
xml_parse($xml_parser, $prefs_xml, 1);
|
|
|
|
return $parse_result;
|
|
|
|
}
|
|
|
|
|
2003-03-25 01:30:13 +00:00
|
|
|
function hour_str($x) {
|
|
|
|
return "$x:00";
|
|
|
|
}
|
|
|
|
|
|
|
|
function hour_select($x, $name) {
|
|
|
|
$s = "";
|
|
|
|
$s = $s. "<select name=$name>\n";
|
|
|
|
for ($i=0; $i<24; $i++) {
|
|
|
|
$y = hour_str($i);
|
|
|
|
$sel = ($x == $i)?"selected":"";
|
|
|
|
$s = $s."<option value=$i $sel> $y";
|
|
|
|
}
|
|
|
|
$s = $s."</select>\n";
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
////////////////////////////////////////////
|
|
|
|
//
|
2003-03-02 19:24:09 +00:00
|
|
|
// display preference subsets
|
2002-05-29 23:25:21 +00:00
|
|
|
//
|
2002-09-27 06:12:50 +00:00
|
|
|
function prefs_show_global($prefs) {
|
2003-03-02 19:24:09 +00:00
|
|
|
row2("Work if computer on batteries?", $prefs->run_on_batteries?"Yes":"No");
|
|
|
|
row2("Work if computer in use?", $prefs->run_if_user_active?"Yes":"No");
|
2003-03-25 01:30:13 +00:00
|
|
|
if ($prefs->start_hour == $prefs->end_hour) {
|
|
|
|
$x = "no restriction";
|
|
|
|
} else {
|
|
|
|
$s = hour_str($prefs->start_hour);
|
|
|
|
$e = hour_str($prefs->end_hour);
|
|
|
|
$x = "$s and $e";
|
|
|
|
}
|
|
|
|
row2("Use my computer only between", $x);
|
2003-03-02 19:24:09 +00:00
|
|
|
row2("Confirm before connecting to network?", $prefs->confirm_before_connecting?"Yes":"No");
|
2003-03-10 23:17:16 +00:00
|
|
|
row2("Disconnect when connection complete?", $prefs->hangup_if_dialed?"Yes":"No");
|
2003-02-27 22:30:31 +00:00
|
|
|
row2("Amount of work to buffer:", "$prefs->work_buf_min_days to $prefs->work_buf_max_days days");
|
2003-03-25 01:30:13 +00:00
|
|
|
row2("On multiprocessors, use at most", "$prefs->max_cpus processors");
|
2003-03-20 02:05:25 +00:00
|
|
|
row2("Write to disk at most every", "$prefs->disk_interval seconds");
|
2003-02-27 22:30:31 +00:00
|
|
|
row2("Maximum disk space to use:", "$prefs->disk_max_used_gb GB");
|
|
|
|
row2("Minimum disk space to leave free:", "$prefs->disk_min_free_gb GB");
|
2003-03-25 01:30:13 +00:00
|
|
|
row2("Maximum % of disk allowed to used:", "$prefs->disk_max_used_pct%");
|
2003-03-02 19:24:09 +00:00
|
|
|
$x = $prefs->max_bytes_sec_down;
|
|
|
|
row2("Maximum bytes/sec download:", $x?"$x":"No limit");
|
|
|
|
$x = $prefs->max_bytes_sec_up;
|
|
|
|
row2("Maximum bytes/sec upload:", $x?"$x":"No limit");
|
2003-02-08 02:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function prefs_show_resource($prefs) {
|
2003-02-18 23:07:48 +00:00
|
|
|
row2(
|
2003-02-27 22:30:31 +00:00
|
|
|
"Resource share<br>
|
|
|
|
<font size=-1>If you participate in multiple BOINC projects, this is the proportion of your resources used by ".PROJECT."</font>",
|
2003-02-18 23:07:48 +00:00
|
|
|
$prefs->resource_share
|
|
|
|
);
|
2003-02-08 02:06:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-20 02:05:25 +00:00
|
|
|
function prefs_show_privacy($user) {
|
|
|
|
row2("Should ".PROJECT." send you email newsletters?", $user->send_email?"Yes":"No");
|
|
|
|
row2("Should ".PROJECT." show your computers on its web site?", $user->show_hosts?"Yes":"No");
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
function prefs_show_project($prefs) {
|
2003-03-05 06:21:24 +00:00
|
|
|
$project_specific_prefs = project_specific_prefs_parse($prefs->project_specific);
|
|
|
|
project_specific_prefs_show($project_specific_prefs);
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function subset_name($subset) {
|
2003-03-06 17:42:49 +00:00
|
|
|
if ($subset == "global") return "general";
|
2003-03-04 19:13:21 +00:00
|
|
|
return PROJECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prefs_display_venue($prefs, $venue, $subset) {
|
|
|
|
$x = $prefs->$venue;
|
|
|
|
if ($x) {
|
2003-03-06 17:42:49 +00:00
|
|
|
row1("Separate preferences for $venue");
|
2003-03-04 19:13:21 +00:00
|
|
|
if ($subset == "global") {
|
|
|
|
prefs_show_global($x);
|
|
|
|
} else {
|
2003-03-05 06:21:24 +00:00
|
|
|
prefs_show_resource($x);
|
2003-03-04 19:13:21 +00:00
|
|
|
prefs_show_project($x);
|
|
|
|
}
|
|
|
|
row2("<br>", "<a href=prefs_edit_form.php?venue=$venue&subset=$subset>Edit</a> | <a href=prefs_remove.php?venue=$venue&subset=$subset>Remove</a>");
|
|
|
|
} else {
|
|
|
|
$x = subset_name($subset);
|
2003-03-06 17:42:49 +00:00
|
|
|
row1("<a href=add_venue_form.php?venue=$venue&subset=$subset>Add separate $x preferences for $venue</a>");
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-05 06:21:24 +00:00
|
|
|
function print_prefs_display_project($user) {
|
|
|
|
$project_prefs = prefs_parse_project($user->project_prefs);
|
|
|
|
|
|
|
|
start_table();
|
|
|
|
row1(PROJECT." preferences");
|
|
|
|
prefs_show_resource($project_prefs);
|
|
|
|
prefs_show_project($project_prefs);
|
2003-03-20 02:05:25 +00:00
|
|
|
prefs_show_privacy($user);
|
2003-03-05 06:21:24 +00:00
|
|
|
venue_show($user);
|
|
|
|
row2("", "<a href=prefs_edit_form.php?subset=project>Edit ".PROJECT." preferences</a>");
|
|
|
|
prefs_display_venue($project_prefs, "home", "project");
|
|
|
|
prefs_display_venue($project_prefs, "school", "project");
|
|
|
|
prefs_display_venue($project_prefs, "work", "project");
|
|
|
|
end_table();
|
|
|
|
}
|
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function print_prefs_display_global($user) {
|
|
|
|
$global_prefs = prefs_parse_global($user->global_prefs);
|
|
|
|
|
2003-03-06 17:42:49 +00:00
|
|
|
echo "<font size=+2>General preferences</font><br><font size=-1>These apply to all BOINC projects in which you participate</font><br><br>";
|
2003-03-04 19:13:21 +00:00
|
|
|
|
|
|
|
start_table();
|
|
|
|
if ($global_prefs->home || $global_prefs->work || $global_prefs->school) {
|
|
|
|
row1("Primary preferences");
|
|
|
|
}
|
2003-02-08 02:06:35 +00:00
|
|
|
prefs_show_global($global_prefs);
|
2003-03-04 19:13:21 +00:00
|
|
|
row2("<br>", "<a href=prefs_edit_form.php?subset=global>Edit</a>");
|
|
|
|
|
|
|
|
prefs_display_venue($global_prefs, "home", "global");
|
|
|
|
prefs_display_venue($global_prefs, "school", "global");
|
|
|
|
prefs_display_venue($global_prefs, "work", "global");
|
|
|
|
end_table();
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_prefs_display($user) {
|
|
|
|
print_prefs_display_project($user);
|
|
|
|
echo "<br><br>\n";
|
|
|
|
print_prefs_display_global($user);
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Functions to display preference subsets as forms
|
|
|
|
//
|
2003-02-18 23:07:48 +00:00
|
|
|
function prefs_form_global($user, $prefs) {
|
2003-03-03 19:13:16 +00:00
|
|
|
$x = "Should ".PROJECT." run while the computer is on battery power?
|
2003-02-07 09:00:35 +00:00
|
|
|
<br><font size=-1>(This matters only for portable computers)</font>
|
|
|
|
";
|
2003-03-03 19:13:16 +00:00
|
|
|
$y = "Yes <input type=radio name=run_on_batteries value=yes "
|
|
|
|
.($prefs->run_on_batteries?"checked":"")
|
|
|
|
."> No <input type=radio name=run_on_batteries value=no "
|
|
|
|
.($prefs->run_on_batteries?"":"checked")
|
|
|
|
.">
|
2003-02-07 09:00:35 +00:00
|
|
|
";
|
2003-03-03 19:13:16 +00:00
|
|
|
row2($x, $y);
|
|
|
|
|
|
|
|
$x = "Should ".PROJECT." run while you're using the computer?";
|
|
|
|
$y = "Yes <input type=radio name=run_if_user_active value=yes "
|
|
|
|
.($prefs->run_if_user_active?"checked":"")
|
|
|
|
."> No <input type=radio name=run_if_user_active value=no "
|
|
|
|
.($prefs->run_if_user_active?"":"checked")
|
|
|
|
.">
|
|
|
|
";
|
|
|
|
row2($x, $y);
|
|
|
|
|
2003-03-25 01:30:13 +00:00
|
|
|
$x = "Use my computer only between the hours of
|
|
|
|
<br><font size=-1>(no restriction if same times)</font>";
|
|
|
|
$y = hour_select($prefs->start_hour, "start_hour")."and".hour_select($prefs->end_hour, "end_hour");
|
|
|
|
row2($x, $y);
|
|
|
|
|
2003-03-10 23:17:16 +00:00
|
|
|
$x = "Should ".PROJECT." ask you before connecting to Internet?
|
2003-02-07 09:00:35 +00:00
|
|
|
<br><font size=-1>(This matters only if you use a modem)</font>
|
|
|
|
";
|
2003-03-03 19:13:16 +00:00
|
|
|
$y = "Yes <input type=radio name=confirm_before_connecting value=yes "
|
|
|
|
.($prefs->confirm_before_connecting?"checked":"")
|
|
|
|
."> No <input type=radio name=confirm_before_connecting value=no "
|
|
|
|
.($prefs->confirm_before_connecting?"":"checked")
|
|
|
|
.">
|
|
|
|
";
|
|
|
|
row2($x, $y);
|
|
|
|
|
2003-03-10 23:17:16 +00:00
|
|
|
$x = "Should ".PROJECT." disconnect when done if it connected?
|
|
|
|
<br><font size=-1>(This matters only if you use a modem)</font>
|
|
|
|
";
|
|
|
|
$y = "Yes <input type=radio name=hangup_if_dialed value=yes "
|
|
|
|
.($prefs->hangup_if_dialed?"checked":"")
|
|
|
|
."> No <input type=radio name=hangup_if_dialed value=no "
|
|
|
|
.($prefs->hangup_if_dialed?"":"checked")
|
|
|
|
.">
|
|
|
|
";
|
|
|
|
row2($x, $y);
|
|
|
|
|
2003-03-03 19:13:16 +00:00
|
|
|
$x = "Keep enough to work on disk to last between";
|
|
|
|
$y = "<input size=5 name=work_buf_min_days value='$prefs->work_buf_min_days'>
|
2003-02-07 09:00:35 +00:00
|
|
|
and
|
2003-02-27 22:30:31 +00:00
|
|
|
<input size=5 name=work_buf_max_days value='$prefs->work_buf_max_days'> days
|
2003-03-03 19:13:16 +00:00
|
|
|
";
|
|
|
|
row2($x, $y);
|
|
|
|
|
2003-03-20 02:05:25 +00:00
|
|
|
row2("Use at most", "<input size=4 name=max_cpus value=$prefs->max_cpus> processors");
|
|
|
|
row2("Write to disk at most every", "<input size=6 name=disk_interval value=$prefs->disk_interval> seconds");
|
|
|
|
|
2003-03-06 17:42:49 +00:00
|
|
|
row1("Limit the disk space used by BOINC:");
|
2003-03-03 19:13:16 +00:00
|
|
|
|
|
|
|
row2("Use no more than",
|
|
|
|
"<input size=7 name=disk_max_used_gb value='$prefs->disk_max_used_gb'> Gbytes"
|
|
|
|
);
|
|
|
|
|
|
|
|
row2("Leave at least",
|
|
|
|
"<input size=7 name=disk_min_free_gb value='$prefs->disk_min_free_gb'> Gbytes free"
|
|
|
|
);
|
|
|
|
row2("Use no more than",
|
|
|
|
"<input size=5 name=disk_max_used_pct value='$prefs->disk_max_used_pct'> % of total space"
|
|
|
|
);
|
|
|
|
|
2003-03-06 17:42:49 +00:00
|
|
|
row1("Limit BOINC's network use:");
|
2003-03-02 19:24:09 +00:00
|
|
|
$d = $prefs->max_bytes_sec_down;
|
|
|
|
$dt = $d?"$d":"";
|
|
|
|
$u = $prefs->max_bytes_sec_up;
|
|
|
|
$ut = $u?"$u":"";
|
2003-03-03 19:13:16 +00:00
|
|
|
row2("Maximum bytes/sec download",
|
|
|
|
"<input size=7 name=max_bytes_sec_down value='$dt'>"
|
|
|
|
);
|
|
|
|
row2("Maximum bytes/sec upload",
|
|
|
|
"<input size=7 name=max_bytes_sec_up value='$ut'>"
|
|
|
|
);
|
2003-02-07 09:00:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-20 02:05:25 +00:00
|
|
|
function prefs_form_privacy($user) {
|
2003-03-03 19:13:16 +00:00
|
|
|
$y = "Yes <input type=radio name=send_email value=yes "
|
2003-03-20 02:05:25 +00:00
|
|
|
.($user->send_email?"checked":"")
|
2003-03-03 19:13:16 +00:00
|
|
|
."> No <input type=radio name=send_email value=no "
|
2003-03-20 02:05:25 +00:00
|
|
|
.($user->send_email?"":"checked")
|
2003-03-03 19:13:16 +00:00
|
|
|
.">
|
2003-02-08 02:06:35 +00:00
|
|
|
";
|
2003-03-03 19:13:16 +00:00
|
|
|
row2("Should ".PROJECT." send you email newsletters?", $y);
|
|
|
|
|
2003-03-20 02:05:25 +00:00
|
|
|
$y = "Yes <input type=radio name=show_hosts value=yes "
|
|
|
|
.($user->show_hosts?"checked":"")
|
|
|
|
."> No <input type=radio name=show_hosts value=no "
|
|
|
|
.($user->show_hosts?"":"checked")
|
2003-03-03 19:13:16 +00:00
|
|
|
.">
|
2003-02-08 02:06:35 +00:00
|
|
|
";
|
2003-03-20 02:05:25 +00:00
|
|
|
row2("Should ".PROJECT." show your computers on its web site?", $y);
|
2003-02-08 02:06:35 +00:00
|
|
|
}
|
|
|
|
|
2003-02-18 23:07:48 +00:00
|
|
|
function prefs_form_resource($prefs) {
|
2003-03-03 19:13:16 +00:00
|
|
|
row2(
|
|
|
|
"<b>Resource share:</b>
|
2003-02-18 23:07:48 +00:00
|
|
|
<font size=-1><br>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.
|
2003-03-03 19:13:16 +00:00
|
|
|
</font>",
|
|
|
|
"<input name=resource_share value='$prefs->resource_share'"
|
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2003-02-18 23:07:48 +00:00
|
|
|
function prefs_form_project($prefs_xml) {
|
2003-02-07 09:00:35 +00:00
|
|
|
$prefs = project_specific_prefs_parse($prefs_xml);
|
|
|
|
project_specific_prefs_edit($prefs);
|
2003-02-18 23:07:48 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
function venue_show($user) {
|
2003-03-06 17:42:49 +00:00
|
|
|
row2("Default computer location", $user->venue);
|
2003-02-21 01:38:16 +00:00
|
|
|
}
|
|
|
|
|
2003-02-18 23:07:48 +00:00
|
|
|
function venue_form($user) {
|
2003-02-21 01:38:16 +00:00
|
|
|
if ($user->venue == "home") $h = "selected";
|
|
|
|
if ($user->venue == "work") $w = "selected";
|
|
|
|
if ($user->venue == "school") $s = "selected";
|
2003-03-05 06:21:24 +00:00
|
|
|
row2("Default computer location",
|
|
|
|
"<select name=default_venue>
|
2003-02-21 01:38:16 +00:00
|
|
|
<option value=home $h>Home
|
|
|
|
<option value=work $w>Work
|
|
|
|
<option value=school $s>School
|
2003-02-18 23:07:48 +00:00
|
|
|
</select>
|
2003-03-03 19:13:16 +00:00
|
|
|
</td></tr>"
|
|
|
|
);
|
2003-02-18 23:07:48 +00:00
|
|
|
}
|
|
|
|
|
2003-03-05 06:21:24 +00:00
|
|
|
function venue_parse_form(&$user) {
|
|
|
|
$user->venue = $_GET['default_venue'];
|
2003-02-18 23:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function venue_update($user) {
|
|
|
|
mysql_query("update user set venue='$user->venue' where id=$user->id");
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Functions to parse form elements, modifying a preferences structure
|
|
|
|
//
|
2002-09-27 06:12:50 +00:00
|
|
|
function prefs_global_parse_form(&$prefs) {
|
2003-02-27 22:30:31 +00:00
|
|
|
$run_on_batteries = $_GET["run_on_batteries"];
|
|
|
|
$run_if_user_active = $_GET["run_if_user_active"];
|
|
|
|
$confirm_before_connecting = $_GET["confirm_before_connecting"];
|
2003-03-10 23:17:16 +00:00
|
|
|
$hangup_if_dialed = $_GET["hangup_if_dialed"];
|
2003-02-27 22:30:31 +00:00
|
|
|
$work_buf_min_days = $_GET["work_buf_min_days"];
|
|
|
|
$work_buf_max_days = $_GET["work_buf_max_days"];
|
2003-03-20 02:05:25 +00:00
|
|
|
$max_cpus = $_GET["max_cpus"];
|
|
|
|
$disk_interval = $_GET["disk_interval"];
|
2003-02-27 22:30:31 +00:00
|
|
|
$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"];
|
2003-03-02 19:24:09 +00:00
|
|
|
$max_bytes_sec_down = $_GET["max_bytes_sec_down"];
|
|
|
|
$max_bytes_sec_up = $_GET["max_bytes_sec_up"];
|
2003-02-24 21:25:16 +00:00
|
|
|
|
2003-02-21 01:38:16 +00:00
|
|
|
$prefs->run_on_batteries = ($run_on_batteries == "yes");
|
|
|
|
$prefs->run_if_user_active = ($run_if_user_active == "yes");
|
2003-03-25 01:30:13 +00:00
|
|
|
$prefs->start_hour = $_GET["start_hour"];
|
|
|
|
$prefs->end_hour = $_GET["end_hour"];
|
2003-02-24 21:25:16 +00:00
|
|
|
$prefs->confirm_before_connecting = ($confirm_before_connecting == "yes");
|
2003-03-10 23:17:16 +00:00
|
|
|
$prefs->hangup_if_dialed = ($hangup_if_dialed == "yes");
|
2003-02-24 21:25:16 +00:00
|
|
|
|
2003-02-27 22:30:31 +00:00
|
|
|
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;
|
2003-03-20 02:05:25 +00:00
|
|
|
if ($max_cpus<1) $max_cpus = 1;
|
|
|
|
if ($disk_interval<0) $disk_interval = 0;
|
2003-02-27 22:30:31 +00:00
|
|
|
$prefs->work_buf_min_days = $work_buf_min_days;
|
|
|
|
$prefs->work_buf_max_days = $work_buf_max_days;
|
2003-03-20 02:05:25 +00:00
|
|
|
$prefs->max_cpus = $max_cpus;
|
|
|
|
$prefs->disk_interval = $disk_interval;
|
2003-02-24 21:25:16 +00:00
|
|
|
|
|
|
|
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;
|
2002-05-29 23:25:21 +00:00
|
|
|
$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;
|
2003-03-02 19:24:09 +00:00
|
|
|
$prefs->max_bytes_sec_down = $max_bytes_sec_down;
|
|
|
|
$prefs->max_bytes_sec_up = $max_bytes_sec_up;
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
2003-02-07 09:00:35 +00:00
|
|
|
function prefs_resource_parse_form(&$prefs) {
|
2003-02-27 22:30:31 +00:00
|
|
|
$prefs->resource_share = $_GET['resource_share'];
|
2003-02-07 09:00:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-20 02:05:25 +00:00
|
|
|
function prefs_privacy_parse_form(&$user) {
|
|
|
|
$user->send_email = ($_GET['send_email'] == "yes")?1:0;
|
|
|
|
$user->show_hosts = ($_GET['show_hosts'] == "yes")?1:0;
|
2003-02-08 02:06:35 +00:00
|
|
|
}
|
|
|
|
|
2003-02-07 09:00:35 +00:00
|
|
|
function prefs_project_parse_form(&$prefs) {
|
2002-12-19 05:11:25 +00:00
|
|
|
$prefs->project_specific = project_specific_prefs_parse_form();
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
2003-02-07 09:00:35 +00:00
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// convert prefs from structure to XML
|
|
|
|
//
|
2003-03-04 19:13:21 +00:00
|
|
|
function global_prefs_make_xml($prefs, $primary=true) {
|
|
|
|
if ($primary) {
|
|
|
|
$xml = "<global_preferences>\n";
|
|
|
|
$now = time();
|
|
|
|
$xml = $xml."<mod_time>$now</mod_time>\n";
|
|
|
|
}
|
2003-02-21 01:38:16 +00:00
|
|
|
if ($prefs->run_on_batteries) {
|
|
|
|
$xml = $xml."<run_on_batteries/>\n";
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
2003-02-21 01:38:16 +00:00
|
|
|
if ($prefs->run_if_user_active) {
|
|
|
|
$xml = $xml."<run_if_user_active/>\n";
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
2003-03-25 01:30:13 +00:00
|
|
|
if ($prefs->start_hour != $prefs->end_hour) {
|
|
|
|
$xml = $xml."<start_hour>$prefs->start_hour</start_hour>"
|
|
|
|
."<end_hour>$prefs->end_hour</end_hour>\n";
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
if ($prefs->confirm_before_connecting) {
|
2003-02-07 09:00:35 +00:00
|
|
|
$xml = $xml."<confirm_before_connecting/>\n";
|
2003-02-04 01:17:56 +00:00
|
|
|
}
|
2003-03-10 23:17:16 +00:00
|
|
|
if ($prefs->hangup_if_dialed) {
|
|
|
|
$xml = $xml."<hangup_if_dialed/>\n";
|
|
|
|
}
|
2003-02-18 23:07:48 +00:00
|
|
|
$xml = $xml
|
2003-02-27 22:30:31 +00:00
|
|
|
."<work_buf_min_days>$prefs->work_buf_min_days</work_buf_min_days>\n"
|
2003-03-20 02:05:25 +00:00
|
|
|
."<work_buf_max_days>$prefs->work_buf_max_days</work_buf_max_days>\n"
|
|
|
|
."<max_cpus>$prefs->max_cpus</max_cpus>\n"
|
|
|
|
."<disk_interval>$prefs->disk_interval</disk_interval>\n";
|
2003-02-18 23:07:48 +00:00
|
|
|
$xml = $xml
|
|
|
|
."<disk_max_used_gb>$prefs->disk_max_used_gb</disk_max_used_gb>\n"
|
|
|
|
."<disk_max_used_pct>$prefs->disk_max_used_pct</disk_max_used_pct>\n"
|
2003-03-02 19:24:09 +00:00
|
|
|
."<disk_min_free_gb>$prefs->disk_min_free_gb</disk_min_free_gb>\n"
|
|
|
|
."<max_bytes_sec_down>$prefs->max_bytes_sec_down</max_bytes_sec_down>\n"
|
|
|
|
."<max_bytes_sec_up>$prefs->max_bytes_sec_up</max_bytes_sec_up>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
if ($prefs->home) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"home\">\n".global_prefs_make_xml($prefs->home, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($prefs->work) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"work\">\n".global_prefs_make_xml($prefs->work, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($prefs->school) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"school\">\n".global_prefs_make_xml($prefs->school, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($primary) {
|
|
|
|
$xml = $xml."</global_preferences>\n";
|
|
|
|
}
|
2002-05-29 23:25:21 +00:00
|
|
|
return $xml;
|
|
|
|
}
|
|
|
|
|
2003-03-04 19:13:21 +00:00
|
|
|
function project_prefs_make_xml($prefs, $primary=true) {
|
2003-03-05 06:21:24 +00:00
|
|
|
$xml = "";
|
2003-03-04 19:13:21 +00:00
|
|
|
if ($primary) {
|
|
|
|
$xml = "<project_preferences>\n";
|
2003-02-14 22:35:35 +00:00
|
|
|
}
|
2003-02-24 21:25:16 +00:00
|
|
|
if ($prefs->resource_share) {
|
|
|
|
$xml = $xml
|
|
|
|
."<resource_share>$prefs->resource_share</resource_share>\n";
|
|
|
|
}
|
|
|
|
if ($prefs->project_specific) {
|
2003-03-05 06:21:24 +00:00
|
|
|
$x = trim($prefs->project_specific);
|
2003-02-24 21:25:16 +00:00
|
|
|
$xml = $xml
|
2003-03-05 06:21:24 +00:00
|
|
|
."<project_specific>\n$x\n</project_specific>\n";
|
2003-02-24 21:25:16 +00:00
|
|
|
}
|
2003-03-04 19:13:21 +00:00
|
|
|
if ($prefs->home) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"home\">\n".project_prefs_make_xml($prefs->home, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($prefs->work) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"work\">\n".project_prefs_make_xml($prefs->work, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($prefs->school) {
|
2003-03-06 00:42:18 +00:00
|
|
|
$xml = $xml."<venue name=\"school\">\n".project_prefs_make_xml($prefs->school, false)."</venue>\n";
|
2003-03-04 19:13:21 +00:00
|
|
|
}
|
|
|
|
if ($primary) {
|
|
|
|
$xml = $xml."</project_preferences>\n";
|
|
|
|
}
|
2002-09-27 17:42:30 +00:00
|
|
|
return $xml;
|
2002-09-27 06:12:50 +00:00
|
|
|
}
|
|
|
|
|
2002-05-29 23:25:21 +00:00
|
|
|
////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Update user's prefs in database, from a given structure
|
|
|
|
//
|
2002-12-19 05:11:25 +00:00
|
|
|
function global_prefs_update(&$user, $prefs) {
|
2002-09-27 06:12:50 +00:00
|
|
|
$prefs_xml = global_prefs_make_xml($prefs);
|
2003-03-20 02:05:25 +00:00
|
|
|
$query = "update user set global_prefs='$prefs_xml' where id=$user->id";
|
|
|
|
$retval = mysql_query($query);
|
|
|
|
if (!$retval) {
|
|
|
|
echo "Update failed: ".htmlspecialchars($query)."\n";
|
|
|
|
echo mysql_error();
|
|
|
|
exit();
|
|
|
|
}
|
2002-09-27 17:42:30 +00:00
|
|
|
$user->global_prefs = $prefs_xml;
|
2003-03-04 19:13:21 +00:00
|
|
|
return $retval;
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-19 05:11:25 +00:00
|
|
|
function project_prefs_update(&$user, $prefs) {
|
2002-09-27 06:12:50 +00:00
|
|
|
$prefs_xml = project_prefs_make_xml($prefs);
|
2003-03-20 02:05:25 +00:00
|
|
|
$retval = mysql_query("update user set project_prefs='$prefs_xml', send_email=$user->send_email, show_hosts=$user->show_hosts where id=$user->id");
|
2002-09-27 17:42:30 +00:00
|
|
|
$user->project_prefs = $prefs_xml;
|
2003-03-04 19:13:21 +00:00
|
|
|
return $retval;
|
2002-05-29 23:25:21 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
?>
|