// // 1.3 // ... // // ... // 45 // ... // // ... (arbitrary project-specific XML) // // // ... (other projects) // global $text; global $parse_result; global $project; global $in_project_specific; function element_start($parser, $name, $attrs) { global $text; global $project; global $in_project_specific; switch($name) { case "project": $project = null; $text = ""; break; 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 $project; global $parse_result; global $in_project_specific; switch($name) { case "project": $n = sizeof($parse_result->projects); $parse_result->projects[$n] = $project; break; case "project_specific": $project->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 "master_url": $project->master_url = $text; break; case "email_addr": $project->email_addr = $text; break; case "authenticator": $project->authenticator = $text; break; case "resource_share": $project->resource_share = $text; break; case "show_email": $project->show_email = $text; break; case "send_email": $project->send_email = $text; break; case "preferences": break; default: if ($in_project_specific) { $text = $text."\n"; } else { echo "Unknown tag: $name\n"; } } } function char_handler($parser, $x) { global $text; $text = $text.$x; } function prefs_parse($prefs_xml) { global $parse_result; $parse_result = null; $parse_result->dont_run_on_batteries = 0; $parse_result->dont_run_if_user_active = 0; $parse_result->confirm_before_connecting = 0; $parse_result->disk_max_used_gb = 1000; $parse_result->disk_max_used_pct = 50; $parse_result->disk_min_free_gb = 1; $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; } //////////////////////////////////////////// // // Functions to display preference subsets, with Edit buttons // function prefs_show_work($prefs) { echo "

Work preferences

\n"; if ($prefs->dont_run_on_batteries) { echo "
Don't do work if running on batteries"; } else { echo "
Do work even if running on batteries"; } if ($prefs->dont_run_if_user_active) { echo "
Don't do work if computers is in use"; } else { echo "
Do work even if computer is in user"; } if ($prefs->confirm_before_connecting) { echo "
Confirm before connecting to network"; } else { echo "
Don't confirm before connecting to network"; } echo "
Buffer at least $prefs->low_water_days hours of work\n"; echo "
Buffer at most $prefs->high_water_days hours of work\n"; echo "
Edit work preferences\n"; } function prefs_show_disk($prefs) { echo "

Disk preferences

\n"; echo "
Maximum disk used: $prefs->disk_max_used_gb GB\n"; echo "
Minimum disk free: $prefs->disk_min_free_gb GB\n"; echo "
Maximum % of disk used: $prefs->disk_max_used_pct\n"; echo "
Edit disk preferences\n"; } function prefs_show_project($project) { echo "
master_url: $project->master_url"; echo "
email_addr: $project->email_addr"; echo "
authenticator: $project->authenticator"; echo "
resource_share: $project->resource_share"; echo "
project_specific: ".htmlspecialchars($project->project_specific); } function prefs_show_projects($prefs) { echo "

Project preferences

\n"; for ($i=0; $iprojects); $i++) { $project = $prefs->projects[$i]; prefs_show_project($project); echo "

\n"; } echo "
Edit project preferences\n"; } function print_prefs_display($prefs) { echo "

Preferences

\n"; prefs_show_work($prefs); prefs_show_disk($prefs); prefs_show_projects($prefs); } //////////////////////////////////////////// // // Functions to display preference subsets as forms // function prefs_form_work($user, $prefs) { echo "
\n"; echo " \n"; echo " \n"; echo " \n"; printf(" \n", $prefs->dont_run_on_batteries?"checked":""); echo " \n"; echo " \n"; echo " \n"; printf(" \n", $prefs->dont_run_if_user_active?"checked":""); echo " \n"; echo " \n"; echo " \n"; printf(" \n", $prefs->confirm_before_connecting?"checked":""); echo " \n"; echo " \n"; echo " \n"; printf(" \n"); echo " \n"; echo " \n"; echo " \n"; printf(" \n"); echo " \n"; echo " \n"; echo "
don't run if on batteries
don't run if user is active
confirm before connecting
Minimum work buffer (hours)
Maximum work buffer (hours)

\n"; echo "
\n"; } function prefs_form_disk($user, $prefs) { echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
Maximum disk space to use for BOINC
Minimum disk space to leave free
Maximum % of disk space to use for BOINC

\n"; echo "
\n"; } function prefs_form_projects($prefs) { for ($i=0; $iprojects); $i++) { $project = $prefs->projects[$i]; echo "
\n"; prefs_show_project($project); echo "
master_url>Delete this project\n"; echo "
master_url>Edit this project\n"; } echo "
Add a project\n"; echo "
"; } function prefs_form_project($project, $action) { echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
Master URL
email address
Authenticator
Resource share
Project-specific preferences

\n"; } //////////////////////////////////////////// // // Functions to parse form elements, modifying a preferences structure // function prefs_work_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; } function prefs_disk_parse_form(&$prefs) { parse_str(getenv("QUERY_STRING")); $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_project_parse_form(&$project) { parse_str(getenv("QUERY_STRING")); $project->master_url = $master_url; $project->email_addr = $email_addr; $project->authenticator = $authenticator; $project->resource_share = $resource_share; $project->project_specific = $project_specific; } //////////////////////////////////////////// // // convert prefs from structure to XML // function prefs_make_xml($prefs) { $xml = "\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"; for ($i=0; $iprojects); $i++) { $project = $prefs->projects[$i]; $xml = $xml." $project->master_url $project->email_addr $project->authenticator $project->resource_share \n$project->project_specific\n "; } $xml = $xml."\n"; return $xml; } //////////////////////////////////////////// // // Update user's prefs in database, from a given structure // function prefs_update($user, $prefs) { $prefs_xml = prefs_make_xml($prefs); $now = time(); mysql_query("update user set prefs='$prefs_xml', prefs_mod_time=$now where id=$user->id"); } //////////////////////////////////////////// // // Misc // function project_index($prefs, $master_url) { for ($i=0; $iprojects); $i++) { $project = $prefs->projects[$i]; if ($project->master_url == $master_url) { return $i; } } return -1; } ?>