diff --git a/checkin_notes b/checkin_notes
index bc6b405d02..84cdc09a11 100755
--- a/checkin_notes
+++ b/checkin_notes
@@ -3622,3 +3622,28 @@ David Mar 3 2003
util.inc
test/
test_uc.php
+
+David Mar 4 2003
+ - added PHP code for creating/editing/deleting multiple pref sets
+ See "prefs.inc" for a description of the XML format.
+ Prefs are divided into two subsets (global and project).
+ For each subset there is a mandatory "primary" version
+ and optional versions for home, school, and work.
+ The prefs display/editing code has been consolidated
+ and parameterized (subset = global or project,
+ venue = none, home, school, work).
+ This actually simplifies things a little.
+
+ html_user/
+ account_setup_first_action.php
+ account_setup_nonfirst_action.php
+ add_venue_action.php (new)
+ add_venue_form.php (new)
+ prefs.inc
+ prefs.php
+ prefs_edit_action.php (new)
+ prefs_edit_form.php (new)
+ prefs_edit_global* (removed)
+ prefs_edit_project* (removed)
+ user.inc
+ util.inc
diff --git a/html/user/account_setup_first_action.php b/html/user/account_setup_first_action.php
index 78b439be59..22fe960d16 100644
--- a/html/user/account_setup_first_action.php
+++ b/html/user/account_setup_first_action.php
@@ -15,11 +15,11 @@ if ($user == NULL) {
// TODO: consolidate the three DB updates into one
-$prefs = prefs_parse($user->global_prefs);
+$prefs = prefs_parse_global($user->global_prefs);
prefs_global_parse_form($prefs);
global_prefs_update($user, $prefs);
-$prefs = prefs_parse($user->project_prefs);
+$prefs = prefs_parse_project($user->project_prefs);
prefs_email_parse_form($prefs);
project_prefs_update($user, $prefs);
diff --git a/html/user/account_setup_nonfirst_action.php b/html/user/account_setup_nonfirst_action.php
index 9866bb0bcf..87513f3342 100644
--- a/html/user/account_setup_nonfirst_action.php
+++ b/html/user/account_setup_nonfirst_action.php
@@ -13,7 +13,7 @@ if ($user == NULL) {
exit();
}
-$prefs = prefs_parse($user->prefs);
+$prefs = prefs_parse_global($user->global_prefs);
prefs_resource_parse_form($prefs);
project_prefs_update($user, $prefs);
diff --git a/html/user/add_venue_action.php b/html/user/add_venue_action.php
new file mode 100644
index 0000000000..5d5167cedb
--- /dev/null
+++ b/html/user/add_venue_action.php
@@ -0,0 +1,31 @@
+global_prefs);
+ prefs_global_parse_form($new_prefs);
+ $prefs->$venue = $new_prefs;
+ $retval = global_prefs_update($user, $prefs);
+ } else {
+ $prefs = prefs_parse_project($user->project_prefs);
+ prefs_project_parse_form($new_prefs);
+ $prefs->$venue = $new_prefs;
+ $retval = project_prefs_update($user, $prefs);
+ }
+ if (retval) {
+ Header("Location: prefs.php?subset=$subset");
+ } else {
+ db_error_page();
+ }
+?>
diff --git a/html/user/add_venue_form.php b/html/user/add_venue_form.php
new file mode 100644
index 0000000000..ee313fe73b
--- /dev/null
+++ b/html/user/add_venue_form.php
@@ -0,0 +1,35 @@
+Add $x preferences for computers at $venue";
+ echo "
\n";
+ page_tail();
+
+?>
diff --git a/html/user/prefs.inc b/html/user/prefs.inc
index 27f8956315..c1096dbef2 100644
--- a/html/user/prefs.inc
+++ b/html/user/prefs.inc
@@ -9,10 +9,15 @@
// - As XML (usually called $prefs_xml)
//
// This XML has the general structure
-//
+//
+// ...
//
// 1.3
// ...
+//
+//
+// ...
+//
//
//
// and
@@ -29,20 +34,18 @@
// 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 $top_parse_result;
global $in_project_specific;
-// the following parses either global or project prefs
-// TODO: split up into separate functions
+// functions to parse preferences XML into a struct
//
-function element_start($parser, $name, $attrs) {
+function element_start_project($parser, $name, $attrs) {
global $text;
- global $project;
global $in_project_specific;
switch($name) {
@@ -59,7 +62,23 @@ function element_start($parser, $name, $attrs) {
}
}
-function element_end($parser, $name) {
+function element_start_global($parser, $name, $attrs) {
+ global $top_parse_result;
+ global $parse_result;
+ global $text;
+
+ switch($name) {
+ case "home":
+ case "school":
+ case "work":
+ $top_parse_result = $parse_result;
+ $parse_result = null;
+ break;
+ }
+ $text = "";
+}
+
+function element_end_project($parser, $name) {
global $text;
global $parse_result;
global $in_project_specific;
@@ -69,6 +88,38 @@ function element_end($parser, $name) {
$parse_result->project_specific = $text;
$in_project_specific = false;
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 "project_preferences":
+ break;
+ default:
+ if ($in_project_specific) {
+ $text = $text."$name>\n";
+ } else {
+ echo "Unknown tag: $name\n";
+ }
+ }
+}
+
+function element_end_global($parser, $name) {
+ global $text;
+ global $parse_result;
+ global $top_parse_result;
+
+ switch($name) {
+ case "home":
+ case "school":
+ case "work":
+ $top_parse_result->$name = $parse_result;
+ $parse_result = $top_parse_result;
+ break;
case "run_on_batteries":
$parse_result->run_on_batteries = true;
break;
@@ -99,28 +150,13 @@ function element_end($parser, $name) {
case "max_bytes_sec_up":
$parse_result->max_bytes_sec_up = $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";
- }
+ echo "Unknown tag: $name\n";
}
}
@@ -131,7 +167,7 @@ function char_handler($parser, $x) {
// state of prefs for new users
//
-function default_prefs() {
+function default_prefs_global() {
$p = null;
$p->run_on_batteries = false;
$p->run_if_user_active = true;
@@ -143,37 +179,54 @@ function default_prefs() {
$p->disk_min_free_gb = 1;
$p->max_bytes_sec_down = 0;
$p->max_bytes_sec_up = 0;
+ return $p;
+}
+function default_prefs_project() {
+ $p = null;
$p->resource_share = 100;
$p->show_email = false;
$p->send_email = true;
-
$p->project_specific = project_specific_prefs_default();
return $p;
}
// state of prefs before parsing; initialize all booleans to false
//
-function initialize_prefs_before_parsing() {
- $p = default_prefs();
- $p->show_email = false;
- $p->send_email = false;
+function initialize_prefs_before_parsing_global() {
+ $p = default_prefs_global();
$p->run_on_batteries = false;
$p->run_if_user_active = false;
$p->confirm_before_connecting = false;
return $p;
}
-// parse prefs (either global or project) from XML to a struct
-//
-function prefs_parse($prefs_xml) {
- global $parse_result;
-
- $parse_result = initialize_prefs_before_parsing();
+function initialize_prefs_before_parsing_project() {
+ $p = default_prefs_project();
+ $p->show_email = false;
+ $p->send_email = false;
+ return $p;
+}
+// parse prefs from XML to a struct
+//
+function prefs_parse_project($prefs_xml) {
+ global $parse_result;
+ $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", "element_end");
+ 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;
+}
+
+function prefs_parse_global($prefs_xml) {
+ global $parse_result;
+ $parse_result = initialize_prefs_before_parsing_global();
+ $xml_parser = xml_parser_create();
+ xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_set_element_handler($xml_parser, "element_start_global", "element_end_global");
xml_set_character_data_handler($xml_parser, "char_handler");
xml_parse($xml_parser, $prefs_xml, 1);
return $parse_result;
@@ -214,24 +267,66 @@ function prefs_show_project($prefs) {
project_specific_prefs_show($prefs);
}
-function print_prefs_display($user) {
- echo "\n";
- $global_prefs = prefs_parse($user->global_prefs);
- $project_prefs = prefs_parse($user->project_prefs);
+function print_prefs_display_project($user) {
+ $project_prefs = prefs_parse_project($user->project_prefs);
$project_specific_prefs = project_specific_prefs_parse($project_prefs->project_specific);
- echo "".PROJECT." preferences |
\n";
+ start_table();
+ row1(PROJECT." preferences");
prefs_show_resource($project_prefs);
prefs_show_project($project_specific_prefs);
prefs_show_email($project_prefs);
venue_show($user);
- echo "Edit ".PROJECT." preferences |
\n";
- echo "
|
\n";
- echo "BOINC preferences
- These apply to all BOINC projects in which you participate |
\n";
+ row2("", "Edit ".PROJECT." preferences");
+ prefs_display_venue($project_prefs, "home", "project");
+ prefs_display_venue($project_prefs, "school", "project");
+ prefs_display_venue($project_prefs, "work", "project");
+ end_table();
+}
+
+function subset_name($subset) {
+ if ($subset == "global") return "BOINC";
+ return PROJECT;
+}
+
+function prefs_display_venue($prefs, $venue, $subset) {
+ $x = $prefs->$venue;
+ if ($x) {
+ row1("Separate preferences for computers at $venue");
+ if ($subset == "global") {
+ prefs_show_global($x);
+ } else {
+ prefs_show_project($x);
+ }
+ row2("
", "Edit | Remove");
+ } else {
+ $x = subset_name($subset);
+ row1("Click to add separate $x preferences for computers at $venue");
+ }
+}
+
+function print_prefs_display_global($user) {
+ $global_prefs = prefs_parse_global($user->global_prefs);
+
+ echo "BOINC preferences
These apply to all BOINC projects in which you participate
";
+
+ start_table();
+ if ($global_prefs->home || $global_prefs->work || $global_prefs->school) {
+ row1("Primary preferences");
+ }
prefs_show_global($global_prefs);
- echo "Edit BOINC preferences |
\n";
- echo "
";
+ row2("
", "Edit");
+
+ 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 "
\n";
+ print_prefs_display_global($user);
}
////////////////////////////////////////////
@@ -426,10 +521,12 @@ function prefs_project_parse_form(&$prefs) {
//
// convert prefs from structure to XML
//
-function global_prefs_make_xml($prefs) {
- $xml = "\n";
- $now = time();
- $xml = $xml."$now\n";
+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";
}
@@ -448,12 +545,25 @@ function global_prefs_make_xml($prefs) {
."$prefs->disk_min_free_gb\n"
."$prefs->max_bytes_sec_down\n"
."$prefs->max_bytes_sec_up\n";
- $xml = $xml."\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) {
- $xml = "\n";
+function project_prefs_make_xml($prefs, $primary=true) {
+ if ($primary) {
+ $xml = "\n";
+ }
if ($prefs->show_email == 1) {
$xml = $xml."\n";
}
@@ -468,7 +578,18 @@ function project_prefs_make_xml($prefs) {
$xml = $xml
."\n$prefs->project_specific\n";
}
- $xml = $xml."\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;
}
@@ -478,14 +599,16 @@ function project_prefs_make_xml($prefs) {
//
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");
+ $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);
- mysql_query("update user set project_prefs='$prefs_xml' where id=$user->id");
+ $retval = mysql_query("update user set project_prefs='$prefs_xml' where id=$user->id");
$user->project_prefs = $prefs_xml;
+ return $retval;
}
?>
diff --git a/html/user/prefs.php b/html/user/prefs.php
index 047d28b983..e55881bafa 100644
--- a/html/user/prefs.php
+++ b/html/user/prefs.php
@@ -9,8 +9,13 @@
$user = get_user_from_auth($authenticator);
require_login($user);
- page_head("Preferences");
- print_prefs_display($user);
+ $subset = $_GET["subset"];
+ page_head(subset_name($subset)." preferences");
+ if ($subset == "global") {
+ print_prefs_display_global($user);
+ } else {
+ print_prefs_display_project($user);
+ }
page_tail();
?>
diff --git a/html/user/prefs_edit_action.php b/html/user/prefs_edit_action.php
new file mode 100644
index 0000000000..e20cb5fde2
--- /dev/null
+++ b/html/user/prefs_edit_action.php
@@ -0,0 +1,38 @@
+global_prefs);
+ if ($venue) $prefs = $main_prefs->$venue;
+ else $prefs = $main_prefs;
+ prefs_global_parse_form($prefs);
+ if ($venue) $main_prefs->$venue = $prefs;
+ else $main_prefs = $prefs;
+ global_prefs_update($user, $main_prefs);
+} else {
+ $main_prefs = prefs_parse_project($user->project_prefs);
+ if ($venue) $prefs = $main_prefs->$venue;
+ else $prefs = $main_prefs;
+ prefs_global_parse_form($prefs);
+ if ($venue) $main_prefs->$venue = $prefs;
+ else $main_prefs = $prefs;
+ project_prefs_update($user, $main_prefs);
+}
+Header("Location: prefs.php?subset=$subset");
+
+?>
diff --git a/html/user/prefs_edit_global_action.php b/html/user/prefs_edit_global_action.php
deleted file mode 100644
index 38d49f44b0..0000000000
--- a/html/user/prefs_edit_global_action.php
+++ /dev/null
@@ -1,21 +0,0 @@
-prefs);
-prefs_global_parse_form($prefs);
-global_prefs_update($user, $prefs);
-Header("Location: prefs.php");
-
-?>
diff --git a/html/user/prefs_edit_global_form.php b/html/user/prefs_edit_global_form.php
deleted file mode 100644
index 756350506e..0000000000
--- a/html/user/prefs_edit_global_form.php
+++ /dev/null
@@ -1,39 +0,0 @@
-global_prefs);
-echo "Edit BOINC preferences
- These preferences apply to all the BOINC projects
- in which you participate.
-
If you participate in multiple BOINC projects,
- edit your preferences only one project's web site;
-
otherwise edits may be overwritten.
-";
-
-echo "\n
-";
-
-echo "Back to preferences\n";
-page_tail();
-
-?>
diff --git a/html/user/prefs_edit_project_action.php b/html/user/prefs_edit_project_action.php
deleted file mode 100644
index 050ccc56cc..0000000000
--- a/html/user/prefs_edit_project_action.php
+++ /dev/null
@@ -1,28 +0,0 @@
-project_prefs);
-prefs_project_parse_form($prefs);
-prefs_resource_parse_form($prefs);
-prefs_email_parse_form($prefs);
-project_prefs_update($user, $prefs);
-
-venue_parse($user);
-venue_update($user);
-
-Header("Location: prefs.php");
-
-?>
diff --git a/html/user/prefs_edit_project_form.php b/html/user/prefs_edit_project_form.php
deleted file mode 100644
index b3932d6a33..0000000000
--- a/html/user/prefs_edit_project_form.php
+++ /dev/null
@@ -1,34 +0,0 @@
-project_prefs);
-
-echo "\n
-";
-
-page_tail();
-
-?>
diff --git a/html/user/prefs_remove.php b/html/user/prefs_remove.php
new file mode 100644
index 0000000000..7cdc9d1394
--- /dev/null
+++ b/html/user/prefs_remove.php
@@ -0,0 +1,30 @@
+global_prefs);
+ $main_prefs->$venue = null;
+ global_prefs_update($user, $main_prefs);
+} else {
+ $main_prefs = prefs_parse_project($user->project_prefs);
+ $main_prefs->$venue = null;
+ project_prefs_update($user, $main_prefs);
+}
+Header("Location: prefs.php?subset=$subset");
+
+?>
diff --git a/html/user/user.inc b/html/user/user.inc
index 677b3c84b3..4e443f6ca7 100644
--- a/html/user/user.inc
+++ b/html/user/user.inc
@@ -71,7 +71,8 @@ function show_user_page_private($user) {
echo "\n";
echo "";
}
diff --git a/html/user/util.inc b/html/user/util.inc
index c5546b41f6..3e894f1476 100644
--- a/html/user/util.inc
+++ b/html/user/util.inc
@@ -88,6 +88,17 @@ function page_tail() {
echo "
Copyright (c) 2003 ".PROJECT."\n";
}
+function db_error_page() {
+ page_head("Database error");
+ echo "Database error
+ A database error occurred while handling your request.
+
Please try again later.
+
If the error persists, please submit a
+ problem report.
+ ";
+ page_tail();
+}
+
function date_str($when) {
return date("g:i A, l M j", $when);
}
@@ -98,7 +109,15 @@ function time_str($x) {
}
function start_table() {
- echo "";
+ echo "";
+}
+
+function end_table() {
+ echo "
\n";
+}
+
+function row1($x) {
+ echo "$x |
\n";
}
function row2($x, $y) {