From c781418118b496c503b1c5c806646be4be5c88b5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 19 Dec 2002 05:11:25 +0000 Subject: [PATCH] project-specific prefs svn path=/trunk/boinc/; revision=777 --- checkin_notes | 20 ++++ html/user/account_created.php | 30 ++++++ html/user/create_account_action.php | 17 +-- html/user/prefs.inc | 134 +++++++++++++----------- html/user/prefs.php | 6 +- html/user/prefs_edit_global_form.php | 2 +- html/user/prefs_edit_project_action.php | 1 + html/user/prefs_edit_project_form.php | 4 +- html/user/project_specific_prefs.inc | 55 ++++++++++ html/user/util.inc | 13 ++- lib/countries.C | 1 + lib/countries.h | 2 +- 12 files changed, 200 insertions(+), 85 deletions(-) create mode 100644 html/user/account_created.php create mode 100644 html/user/project_specific_prefs.inc diff --git a/checkin_notes b/checkin_notes index 1e495349b8..c6faa9107c 100755 --- a/checkin_notes +++ b/checkin_notes @@ -2707,3 +2707,23 @@ Seth Dec 18 2002 wingui_listctrl.cpp,h (new) wingui_pictrl.cpp,h (new) +David Dec 18 2002 + - Have account create action redirect to a different page + so you don't get "Repost form data" if you go back to it + - Added full support for project-specific preferences. + Logic is encapsulated in project_specific_prefs.inc. + The example lets you choose color scheme + (Tahiti Sunset, Desert Sands) + + html_user/ + account_created.php (new) + project_specific_prefs.inc (new) + create_account_action.php + prefs.inc + prefs.php + prefs_edit_global_form.php + prefs_edit_project_action.php + prefs_edit_project_form.php + util.inc + lib/ + countries.C,h diff --git a/html/user/account_created.php b/html/user/account_created.php new file mode 100644 index 0000000000..638d73d19c --- /dev/null +++ b/html/user/account_created.php @@ -0,0 +1,30 @@ +account key is being emailed to you. +

+ If you are already running the BOINC client: +

+ Select the Add Project command in the BOINC client. + Enter the project URL and your account key. +
+ If you aren't running the BOINC client: +
+ Download the BOINC client. + Install and run the client. + Enter the project URL and your account key. +
+

+ Your account initially has default preferences + (limits on CPU, disk and network usage). + View or edit these preferences. + "; + + send_auth_email($new_email_addr, $authenticator); + + page_tail(); + +?> diff --git a/html/user/create_account_action.php b/html/user/create_account_action.php index d666b4418e..b8d2feb223 100644 --- a/html/user/create_account_action.php +++ b/html/user/create_account_action.php @@ -53,19 +53,8 @@ function show_error($str) { if (!$result) { show_error("Couldn't create account"); } - page_head("Account created"); - echo "Your account has been created, - and an account key is being emailed to you. -

- If you don't already have it, - download the BOINC client. - Install and run the client, and give it your account key. -

- If you're already running the BOINC client, - select the Add Project command - and give it your account key. -

"; - send_auth_email($new_email_addr, $authenticator); + // In success case, redirect to a fixed page so that user can + // return to it without getting "Repost form data" stuff - page_tail(); + Header("Location: account_created.php"); diff --git a/html/user/prefs.inc b/html/user/prefs.inc index ee5f17226f..0a705751a9 100644 --- a/html/user/prefs.inc +++ b/html/user/prefs.inc @@ -4,11 +4,9 @@ // preferences (global and project). // Preferences are represented in two ways: // - As a PHP structure (usually called $prefs) +// This has fields dont_run_on_batteries, etc. +// The fields "project_specific" is raw XML // - As XML (usually called $prefs_xml) -// Various functions are defined below for converting between these forms, -// and also to/from HTML form elements - -// functions to parse preferences XML into a struct // // This XML has the general structure // @@ -28,6 +26,13 @@ // // +// 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; @@ -97,6 +102,9 @@ function element_end($parser, $name) { case "send_email": $parse_result->send_email = $text; break; + case "mod_time": + $parse_result->mod_time = $text; + break; case "global_preferences": break; case "project_preferences": @@ -117,7 +125,7 @@ function char_handler($parser, $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; @@ -148,7 +156,8 @@ function prefs_show_global($prefs) { echo "

"; echo "\n"; - echo "".TD2.LG_FONT."Global preferences:\n"; + 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 { @@ -182,9 +191,11 @@ function prefs_show_global($prefs) { function prefs_show_project($prefs) { echo "

"; echo "

\n"; - echo "".TD2.LG_FONT."Project preferences:\n"; + echo "".TD2.LG_FONT."Project preferences +
These apply only to this project\n"; row2a("Resource Share: ", $prefs->resource_share); - row2a("Project Specific Preferences: ", htmlspecialchars($prefs->project_specific)); + $prefs = project_specific_prefs_parse($prefs); + project_specific_prefs_show($prefs); echo "\n"; echo "
Edit project preferences
"; } @@ -199,63 +210,62 @@ function print_prefs_display($user) { // Functions to display preference subsets as forms // function prefs_form_global($user, $prefs) { - echo "

\n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo "\n +
Don't run if computer is on batteries
\n + \n + \n"; printf(" \n", $prefs->dont_run_on_batteries?"checked":""); - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n + \n + \n"; printf(" \n", $prefs->dont_run_if_user_active?"checked":""); - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n + \n + \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 " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
Don't run if computer is on batteries
Don't run if user is active
Don't run if user is active
Confirm before connecting
Confirm before connecting
Minimum amount of work to buffer (days)
Maximum amount of work to buffer (days)
Maximum disk space allowed
to be used for BOINC (in GB)
Minimum disk space to leave
free (in GB)
Maximum % of disk space to
use for BOINC
\n"; - echo " \n"; - echo "
\n"; + echo " \n + \n + Minimum amount of work to buffer\n"; + printf(" days\n"); + echo " \n + \n + Maximum amount of work to buffer\n"; + printf(" days\n"); + echo " \n + \n + Maximum disk space allowed
to be used for BOINC\n + Gbytes\n + \n + \n + Minimum disk space to leave free\n + Gbytes\n + \n + \n + Maximum % of disk space to
use for BOINC\n + \n + \n + \n + \n + \n"; } function prefs_form_project($prefs) { - echo "
\n"; - echo " \n"; - echo " \n"; - - echo " \n"; - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
Resource share:
(If projects"; - echo " compete for resources,
this is the fraction of resources you
choose to"; - echo " allocate to this project.)
Project-specific preferences:

\n"; - echo "
\n"; + echo "
\n + \n + \n + \n + \n + \n"; + $prefs = project_specific_prefs_parse($prefs); + project_specific_prefs_edit($prefs); + echo " + \n +
Resource share:
+ If you participate in multiple projects, +
this is the proportion of resources +
allocated to this project. +

\n +
\n"; } //////////////////////////////////////////// @@ -277,7 +287,7 @@ function prefs_global_parse_form(&$prefs) { function prefs_project_parse_form(&$prefs) { parse_str(getenv("QUERY_STRING")); $prefs->resource_share = $resource_share; - $prefs->project_specific = $project_specific; + $prefs->project_specific = project_specific_prefs_parse_form(); } @@ -322,13 +332,13 @@ function project_prefs_make_xml($prefs) { // // Update user's prefs in database, from a given structure // -function global_prefs_update($user, $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"); $user->global_prefs = $prefs_xml; } -function project_prefs_update($user, $prefs) { +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; diff --git a/html/user/prefs.php b/html/user/prefs.php index e80f2b495b..047d28b983 100644 --- a/html/user/prefs.php +++ b/html/user/prefs.php @@ -9,8 +9,8 @@ $user = get_user_from_auth($authenticator); require_login($user); - page_head("Preferences"); - print_prefs_display($user); - page_tail(); + page_head("Preferences"); + print_prefs_display($user); + page_tail(); ?> diff --git a/html/user/prefs_edit_global_form.php b/html/user/prefs_edit_global_form.php index a5281e554b..bbd90c4a48 100644 --- a/html/user/prefs_edit_global_form.php +++ b/html/user/prefs_edit_global_form.php @@ -13,7 +13,7 @@ if ($user == NULL) { exit(); } page_head("Edit Global Preferences"); -$prefs = prefs_parse($user->prefs); +$prefs = prefs_parse($user->global_prefs); prefs_form_global($user, $prefs); echo "Back to preferences\n"; echo "

\n"; diff --git a/html/user/prefs_edit_project_action.php b/html/user/prefs_edit_project_action.php index d1d48ef17c..e42b1ff62a 100644 --- a/html/user/prefs_edit_project_action.php +++ b/html/user/prefs_edit_project_action.php @@ -13,6 +13,7 @@ if ($user == NULL) { exit(); } +no_cache(); page_head("Preferences"); $prefs = prefs_parse($user->project_prefs); prefs_project_parse_form($prefs); diff --git a/html/user/prefs_edit_project_form.php b/html/user/prefs_edit_project_form.php index f2d636b748..b4390aa36b 100644 --- a/html/user/prefs_edit_project_form.php +++ b/html/user/prefs_edit_project_form.php @@ -14,8 +14,8 @@ if ($user == NULL) { } page_head("Edit project preferences"); parse_str(getenv("QUERY_STRING")); -$prefs = prefs_parse($user->prefs); -prefs_form_project($prefs->project, "prefs_edit_project_action.php"); +$prefs = prefs_parse($user->project_prefs); +prefs_form_project($prefs); echo "

\n"; page_tail(); diff --git a/html/user/project_specific_prefs.inc b/html/user/project_specific_prefs.inc new file mode 100644 index 0000000000..daf6e8d8bd --- /dev/null +++ b/html/user/project_specific_prefs.inc @@ -0,0 +1,55 @@ +$name\n"; +} + +// given struct, show form for editing +// +function project_specific_prefs_edit($prefs) { + $x = $prefs->color_scheme; + echo "\n + Color scheme:\n + \n + \n + \n + "; +} + +// QUERY_STRING has already been parsed into variables. +// Return XML version of project-specific prefs +// +function project_specific_prefs_parse_form() { + parse_str(getenv("QUERY_STRING")); + return "$color_scheme"; +} + +// show non-editable version of prefs +// +function project_specific_prefs_show($prefs) { + echo "\n + Color scheme:\n + $prefs->color_scheme\n + \n"; +} + +// parse XML, fill in struct +// +function project_specific_prefs_parse($prefs) { + $xml = $prefs->project_specific; + $prefs->color_scheme = parse_element($xml, ""); + return $prefs; +} diff --git a/html/user/util.inc b/html/user/util.inc index 8bd837ce3a..437b880879 100644 --- a/html/user/util.inc +++ b/html/user/util.inc @@ -82,11 +82,11 @@ function page_head($title) { function page_tail() { - echo "

Return to main ".PROJECT." page
\n"; + echo "


Return to main ".PROJECT." page
\n"; // put your copyright notice etc. here - echo "
Copyright (c) 2002 Sample Project\n"; + echo "

Copyright (c) 2002 ".PROJECT."
\n"; } function date_str($when) { @@ -164,4 +164,13 @@ function parse_config($tag) { return $element; } +// Call this if for dynamic pages +// +function no_cache() { + header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past + header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified + header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header ("Pragma: no-cache"); // HTTP/1.0 +} + ?> diff --git a/lib/countries.C b/lib/countries.C index 160ca2a52b..467965c3e8 100644 --- a/lib/countries.C +++ b/lib/countries.C @@ -3,6 +3,7 @@ #include "countries.h" char *countries[NUM_COUNTRIES] = { + "None", "United States", "Afghanistan", "Albania", diff --git a/lib/countries.h b/lib/countries.h index 0ab579533a..db32eda3ca 100644 --- a/lib/countries.h +++ b/lib/countries.h @@ -1,2 +1,2 @@ -#define NUM_COUNTRIES 226 +#define NUM_COUNTRIES 227 extern char *countries[NUM_COUNTRIES];