//
// 1.3
// ...
//
//
// and
//
//
// 4
//
// ... (arbitrary project-specific XML)
//
//
//
//
// Various functions are defined below for converting between these forms,
// and also to/from HTML form elements
// First: functions to parse preferences XML into a struct
include_once("project_specific_prefs.inc");
global $text;
global $parse_result;
global $in_project_specific;
// the following will parse either global or project prefs
// TODO: split up into separate functions
//
function element_start($parser, $name, $attrs) {
global $text;
global $project;
global $in_project_specific;
switch($name) {
case "project_specific":
$in_project_specific = 1;
$text = "";
break;
default:
if ($in_project_specific) {
$text= $text."<$name>";
} else {
$text = "";
}
}
}
function element_end($parser, $name) {
global $text;
global $parse_result;
global $in_project_specific;
switch($name) {
case "project_specific":
$parse_result->project_specific = $text;
$in_project_specific = false;
break;
case "dont_run_on_batteries":
$parse_result->dont_run_on_batteries = 1;
break;
case "dont_run_if_user_active":
$parse_result->dont_run_if_user_active = 1;
break;
case "confirm_before_connecting":
$parse_result->confirm_before_connecting = 1;
break;
case "low_water_days":
$parse_result->low_water_days = $text;
break;
case "high_water_days":
$parse_result->high_water_days = $text;
break;
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;
case "resource_share":
$parse_result->resource_share = $text;
break;
case "show_email":
$parse_result->show_email = true;
break;
case "send_email":
$parse_result->send_email = true;
break;
case "mod_time":
$parse_result->mod_time = $text;
break;
case "global_preferences":
break;
case "project_preferences":
break;
default:
if ($in_project_specific) {
$text = $text."$name>\n";
} else {
echo "Unknown tag: $name\n";
}
}
}
function char_handler($parser, $x) {
global $text;
$text = $text.$x;
}
// state of prefs for new users
//
function default_prefs() {
$p = null;
$p->dont_run_on_batteries = 1;
$p->dont_run_if_user_active = 1;
$p->confirm_before_connecting = 0;
$p->low_water_days = 1;
$p->high_water_days = 3;
$p->disk_max_used_gb = 100;
$p->disk_max_used_pct = 50;
$p->disk_min_free_gb = 1;
$p->resource_share = 100;
$p->show_email = false;
$p->send_email = true;
return $p;
}
// state of prefs before parsing
//
function initial_prefs() {
$p = default_prefs;
$p->show_email = false;
$p->send_email = false;
}
// parse prefs (either global or project) from XML to a struct
//
function prefs_parse($prefs_xml) {
global $parse_result;
$parse_result = initial_prefs();
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "element_start", "element_end");
xml_set_character_data_handler($xml_parser, "char_handler");
xml_parse($xml_parser, $prefs_xml, 1);
return $parse_result;
}
////////////////////////////////////////////
//
// display preference subsets, with Edit buttons
//
function prefs_show_global($prefs) {
echo "
".TD2.LG_FONT."Global preferences
These apply to all BOINC projects in which you participate
\n";
if ($prefs->dont_run_on_batteries) {
$batteries = "No";
} else {
$batteries = "Yes";
}
if ($prefs->dont_run_if_user_active) {
$in_use = "No";
} else {
$in_use = "Yes";
}
if ($prefs->confirm_before_connecting) {
$confirm = "Yes";
} else {
$confirm = "No";
}
row2a("Work if computer on batteries:", $batteries);
row2a("Work if computer in use:", $in_use);
row2a("Confirm before connecting to network:", $confirm);
row2a("Minimum amount of work to buffer:", "$prefs->low_water_days days");
row2a("Maximum amount of work to buffer:", "$prefs->high_water_days days");
row2a("Maximum disk space to use:", "$prefs->disk_max_used_gb GB");
row2a("Minimum disk space to leave free:", "$prefs->disk_min_free_gb GB");
row2a("Maximum % of disk allowed to used:", "$prefs->disk_max_used_pct %");
echo "Edit global preferences |
\n";
}
function prefs_show_resource($prefs) {
echo "".TD2.LG_FONT."Resource share
Control how your resources are divided among BOINC projects
\n";
row2a(PROJECT." resource share:", $prefs->resource_share);
echo "Edit resource share |
\n";
}
function prefs_show_email($prefs) {
echo "".TD2.LG_FONT."Email options
Control how ".PROJECT." uses your email address
\n";
row2a("Should ".PROJECT." send you email newsletters?", $prefs->send_email?"Yes":"No");
row2a("Should ".PROJECT." show your email address on its web site?", $prefs->show_email?"Yes":"No");
echo "Edit email options |
\n";
}
function prefs_show_project($prefs) {
echo "".TD2.LG_FONT."Graphics preferences
Customize ".PROJECT." screensaver graphics
\n";
project_specific_prefs_show($prefs);
echo "Edit graphics preferences |
\n";
}
function print_prefs_display($user) {
echo "\n";
$global_prefs = prefs_parse($user->global_prefs);
$project_prefs = prefs_parse($user->project_prefs);
$project_specific_prefs = project_specific_prefs_parse($project_prefs->project_specific);
prefs_show_resource($project_prefs);
prefs_show_project($project_specific_prefs);
prefs_show_email($project_prefs);
prefs_show_global($global_prefs);
echo "
";
}
////////////////////////////////////////////
//
// Functions to display preference subsets as forms
//
function prefs_form_global($user, $prefs, $next_url) {
echo "
";
}
function prefs_form_email($prefs, $next_url) {
echo "
";
}
function prefs_form_resource($prefs, $next_url) {
echo "
";
}
function prefs_form_project($prefs_xml, $next_url) {
$prefs = project_specific_prefs_parse($prefs_xml);
echo "
";
}
////////////////////////////////////////////
//
// Functions to parse form elements, modifying a preferences structure
//
function prefs_global_parse_form(&$prefs) {
parse_str(getenv("QUERY_STRING"));
$prefs->dont_run_on_batteries = isset($dont_run_on_batteries)?1:0;
$prefs->dont_run_if_user_active = isset($dont_run_if_user_active)?1:0;
$prefs->confirm_before_connecting = isset($confirm_before_connecting)?1:0;
$prefs->low_water_days = $low_water_days;
$prefs->high_water_days = $high_water_days;
$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;
}
function prefs_resource_parse_form(&$prefs) {
parse_str(getenv("QUERY_STRING"));
$prefs->resource_share = $resource_share;
}
function prefs_email_parse_form(&$prefs) {
parse_str(getenv("QUERY_STRING"));
$prefs->send_email = isset($send_email)?1:0;
$prefs->show_email = isset($show_email)?1:0;
}
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) {
$xml = "\n";
$now = time();
$xml = $xml."$now\n";
if ($prefs->dont_run_on_batteries) {
$xml = $xml."\n";
}
if ($prefs->dont_run_if_user_active) {
$xml = $xml."\n";
}
if ($prefs->confirm_before_connecting) {
$xml = $xml."\n";
}
$xml = $xml."$prefs->low_water_days
$prefs->high_water_days
";
$xml = $xml."$prefs->disk_max_used_gb
$prefs->disk_max_used_pct
$prefs->disk_min_free_gb
";
$xml = $xml."\n";
return $xml;
}
function project_prefs_make_xml($prefs) {
$xml = "\n";
if ($prefs->show_email) {
$xml = $xml."\n";
}
if ($prefs->send_email) {
$xml = $xml."\n";
}
$xml = $xml
."$prefs->resource_share\n"
."\n$prefs->project_specific\n";
$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);
mysql_query("update user set global_prefs='$prefs_xml' where id=$user->id");
$user->global_prefs = $prefs_xml;
}
function project_prefs_update(&$user, $prefs) {
$prefs_xml = project_prefs_make_xml($prefs);
mysql_query("update user set project_prefs='$prefs_xml' where id=$user->id");
$user->project_prefs = $prefs_xml;
}
?>