2004-02-02 23:34:39 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
2010-01-19 00:38:31 +00:00
// Copyright (C) 2010 University of California
2008-08-05 22:43:14 +00:00
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2004-02-02 23:34:39 +00:00
// This file contains support functions for display and editing
// preferences (global and project).
// Preferences are represented in two ways:
// - As a PHP structure (usually called $prefs)
2007-07-19 23:22:19 +00:00
// This has fields run_if_user_active, etc.
2004-02-02 23:34:39 +00:00
// The fields "project_specific" is plain XML
// - As XML (usually called $prefs_xml)
//
// This XML has the general structure
// <global_preferences>
// <mod_time>...</mod_time>
// <run_if_user_active/>
// <work_buf_min_days>1.3</work_buf_min_days>
// ...
// <venue name="home">
// <run_if_user_active/>
// ...
// </venue>
// </global_preferences>
//
// and
//
// <project_preferences>
// <resource_share>4</resource_share>
2006-10-25 21:15:08 +00:00
// [ <allow_beta_work>0|1</allow_beta_work> ]
2009-09-28 04:24:18 +00:00
// [ <no_cpu>1</no_cpu> ]
// [ <no_cuda>1</no_cuda> ]
// [ <no_ati>1</no_ati> ]
2004-02-02 23:34:39 +00:00
// <project-specific>
// ... (arbitrary project-specific XML)
// </project-specific>
// <home>
// ...
// </home>
// </project_preferences>
//
// In addition there are some fields of the user table
// (send_email and show_hosts) that are treated as project preferences
// Various functions are defined below for converting between these forms,
// and also to/from HTML form elements
2010-04-22 23:19:49 +00:00
error_reporting ( E_ALL );
ini_set ( 'display_errors' , true );
ini_set ( 'display_startup_errors' , true );
2010-04-23 18:32:30 +00:00
include_once ( " ../inc/prefs_util.inc " );
2004-02-02 23:34:39 +00:00
include_once ( " ../project/project_specific_prefs.inc " );
2009-09-28 04:24:18 +00:00
$app_types = get_app_types ();
2010-04-22 23:19:49 +00:00
$venues = array ( " home " , " school " , " work " );
$cpu_prefs = array (
new PREF_BOOL (
tra (
2010-04-26 02:34:58 +00:00
" Suspend work while computer is on battery power? %1 Matters only for portable computers %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
2010-04-26 20:28:54 +00:00
" run_on_batteries " ,
false , true
2010-04-22 23:19:49 +00:00
),
new PREF_BOOL (
tra ( " Suspend work while computer is in use? " ),
2010-04-26 20:28:54 +00:00
" run_if_user_active " ,
true , true
2010-04-22 23:19:49 +00:00
),
new PREF_BOOL (
tra (
2010-04-26 19:31:28 +00:00
" Suspend GPU work while computer is in use? %1 Enforced by version 6.6.21+ %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
2010-04-26 20:28:54 +00:00
" run_gpu_if_user_active " ,
false , true
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra ( " 'In use' means mouse/keyboard activity in last " ),
" idle_time_to_run " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " minutes " ), 1 , 9999 , 3 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra (
2010-04-26 02:34:58 +00:00
" Suspend work if no mouse/keyboard activity in last %1 Needed to enter low-power mode on some computers %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" suspend_if_no_recent_input " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " minutes " ), 0 , 9999 , 0 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra (
2011-02-09 19:10:10 +00:00
" Suspend work when non-BOINC CPU usage is above %1 0 means no restriction<br>Enforced by version 6.10.30+ %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" suspend_cpu_usage " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( " % " , 0 , 100 , 25 )
2010-04-22 23:19:49 +00:00
),
new PREF_HOUR_RANGE (
2010-04-26 02:34:58 +00:00
tra ( " Do work only between the hours of %1 No restriction if equal %2 " ,
2010-04-23 18:32:30 +00:00
" <br><span class=note> " ,
" </span> "
),
2010-04-22 23:19:49 +00:00
" start_hour " , " end_hour "
),
new PREF_BOOL (
tra (
2010-04-26 02:34:58 +00:00
" Leave tasks in memory while suspended? %1 Suspended tasks will consume swap space if 'yes' %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" leave_apps_in_memory " ,
false
),
new PREF_NUM (
tra (
2010-04-26 02:34:58 +00:00
" Switch between tasks every %1 Recommended: 60 minutes %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" cpu_scheduling_period_minutes " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " minutes " ), 1 , 9999 , 60 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra ( " On multiprocessors, use at most " ),
" max_cpus " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " processors " ), 0 , 9999 , 0 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra (
2010-04-26 02:34:58 +00:00
" On multiprocessors, use at most %1 Enforced by version 6.1+ %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" max_ncpus_pct " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of the processors " ), 0 , 100 , 100 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
tra (
2010-04-26 02:34:58 +00:00
" Use at most %1 Can be used to reduce CPU heat %2 " ,
2010-04-22 23:19:49 +00:00
" <br><span class=note> " ,
" </span> "
),
" cpu_usage_limit " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of CPU time " ), 0 , 100 , 100 )
2010-04-22 23:19:49 +00:00
),
);
2010-04-23 17:46:57 +00:00
$dp = get_disk_space_config ();
$disk_prefs = array (
new PREF_NUM (
tra ( " Disk: use at most " ),
" disk_max_used_gb " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " GB " ), 0 , 9999999 , $dp -> disk_max_used_gb )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
2010-04-26 02:34:58 +00:00
tra ( " Disk: leave free at least %1 Values smaller than %2 are ignored %3 " ,
2010-04-23 17:46:57 +00:00
" <br><span class=note> " ,
" 0.001 " ,
" </span> "
),
" disk_min_free_gb " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " GB " ), 0.001 , 9999999 , $dp -> disk_min_free_gb )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Disk: use at most " ),
" disk_max_used_pct " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of total " ), 0 , 100 , $dp -> disk_max_used_pct )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Tasks checkpoint to disk at most every " ),
" disk_interval " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " seconds " ), 0 , 9999999 , 60 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Swap space: use at most " ),
" vm_max_used_pct " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of total " ), 0 , 100 , 75 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Memory: when computer is in use, use at most " ),
" ram_max_used_busy_pct " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of total " ), 0 , 100 , 50 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Memory: when computer is not in use, use at most " ),
" ram_max_used_idle_pct " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " % of total " ), 0 , 100 , 90 )
2010-04-23 17:46:57 +00:00
),
2007-03-29 03:29:41 +00:00
);
2010-04-23 17:46:57 +00:00
$net_prefs = array (
new PREF_NUM (
tra (
2012-02-16 16:52:07 +00:00
" Maintain enough tasks to keep busy for at least%1(max 10 days).%2 " ,
2010-04-23 17:46:57 +00:00
" <br><span class=note> " ,
" </span> "
),
" work_buf_min_days " ,
2012-02-28 06:57:28 +00:00
new NUM_SPEC ( tra ( " days " ), 0 , 10 , . 1 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
2012-02-16 16:52:07 +00:00
tra ( " ... and up to an additional " ),
2010-04-23 17:46:57 +00:00
" work_buf_additional_days " ,
2012-02-28 06:57:28 +00:00
new NUM_SPEC ( tra ( " days " ), 0 , 10 , . 5 )
2010-04-23 17:46:57 +00:00
),
new PREF_BOOL (
tra (
2010-04-26 02:34:58 +00:00
" Confirm before connecting to Internet? %1 Matters only if you have a modem, ISDN or VPN connection %2 " ,
2010-04-23 17:46:57 +00:00
" <br><span class=note> " ,
" </span> "
),
" confirm_before_connecting " ,
false
),
new PREF_BOOL (
tra (
2010-04-26 02:34:58 +00:00
" Disconnect when done? %1 Matters only if you have a modem, ISDN or VPN connection %2 " ,
2010-04-23 17:46:57 +00:00
" <br><span class=note> " ,
" </span> "
),
" hangup_if_dialed " ,
false
),
new PREF_NUM (
tra ( " Maximum download rate: " ),
" max_bytes_sec_down " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " Kbytes/sec " ), 0 , 9999999 , 0 , 1000 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
tra ( " Maximum upload rate: " ),
" max_bytes_sec_up " ,
2010-04-23 20:29:02 +00:00
new NUM_SPEC ( tra ( " Kbytes/sec " ), 0 , 9999999 , 0 , 1000 )
2010-04-23 17:46:57 +00:00
),
new PREF_HOUR_RANGE (
tra ( " Use network only between the hours of " ),
" net_start_hour " , " net_end_hour "
),
2010-04-23 20:29:02 +00:00
new PREF_NUM2 (
2010-04-26 02:34:58 +00:00
tra ( " Transfer at most %1 Enforced by version 6.10.46+ %2 " ,
" <br><span class=note> " ,
" </span> "
),
2010-04-23 20:29:02 +00:00
" daily_xfer_limit_mb " ,
" daily_xfer_period_days " ,
new NUM_SPEC ( tra ( " Mbytes every " ), 0 , 9999999 , 0 ),
new NUM_SPEC ( tra ( " days " ), 0 , 9999999 , 0 )
),
2010-04-23 17:46:57 +00:00
new PREF_BOOL (
tra (
2010-04-26 02:34:58 +00:00
" Skip image file verification? %1 Check this ONLY if your Internet provider modifies image files (UMTS does this, for example). %2 Skipping verification reduces the security of BOINC. %3 " ,
2010-04-23 17:46:57 +00:00
" <br><span class=note> " ,
" " ,
" </span> "
),
" dont_verify_images " ,
false
),
2010-02-15 04:30:25 +00:00
);
2010-04-23 17:46:57 +00:00
2010-04-26 19:31:28 +00:00
$project_pref_descs = array (
new PREF_NUM (
$x = tra (
" Resource share %1 Determines the proportion of your computer's resources allocated to this project. Example: if you participate in two BOINC projects with resource shares of 100 and 200, the first will get 1/3 of your resources and the second will get 2/3. %2 " ,
" <br><span class=note> " ,
" </span> "
),
" resource_share " ,
new NUM_SPEC ( " " , 0 , 9999999 , 100 )
),
);
2010-11-09 05:10:56 +00:00
if ( isset ( $accelerate_gpu_apps_pref ) && $accelerate_gpu_apps_pref ) {
$project_pref_descs [] = new PREF_BOOL (
tra ( " Accelerate GPU tasks by dedicating a CPU to each one? " ),
" accelerate_gpu_apps " ,
false
);
}
2010-04-26 19:31:28 +00:00
if ( $app_types -> count > 1 ) {
if ( $app_types -> cpu ) {
$project_pref_descs [] = new PREF_BOOL (
tra (
" Use CPU %1 Enforced by version 6.10+ %2 " ,
" <br><span class=note> " ,
" </span> "
),
" no_cpu " ,
false ,
true
);
}
if ( $app_types -> ati ) {
$project_pref_descs [] = new PREF_BOOL (
tra (
" Use ATI GPU %1 Enforced by version 6.10+ %2 " ,
" <br><span class=note> " ,
" </span> "
),
" no_ati " ,
false ,
true
);
}
if ( $app_types -> cuda ) {
$project_pref_descs [] = new PREF_BOOL (
tra (
" Use NVIDIA GPU %1 Enforced by version 6.10+ %2 " ,
" <br><span class=note> " ,
" </span> "
),
" no_cuda " ,
false ,
true
);
}
}
2010-05-07 21:46:04 +00:00
if ( isset ( $project_has_beta ) && $project_has_beta ) {
2010-04-26 19:31:28 +00:00
$project_pref_descs [] = new PREF_BOOL (
tra (
" Run test applications? %1 This helps us develop applications, but may cause jobs to fail on your computer %2 " ,
" <br><span class=note> " ,
" </span> "
),
" allow_beta_work " ,
false
);
}
2010-06-17 19:11:00 +00:00
if ( defined ( " EMAIL_FROM " )) {
$x = " <br><span class=note> " . tra ( " Emails will be sent from %1; make sure your spam filter accepts this address. " , EMAIL_FROM ) . " </span> " ;
} else {
$x = " " ;
}
$privacy_pref_descs = array (
new PREF_BOOL (
tra ( " Is it OK for %1 and your team (if any) to email you? " , PROJECT ) . $x ,
" send_email " ,
true ,
false
),
new PREF_BOOL (
tra ( " Should %1 show your computers on its web site? " , PROJECT ),
" show_hosts " ,
true ,
false
),
);
2010-04-26 19:31:28 +00:00
2010-02-15 04:30:25 +00:00
define ( " DISK_LIMIT_DESC " , tra ( " Disk and memory usage " ));
2010-04-23 17:46:57 +00:00
define ( " CPU_LIMIT_DESC " , tra ( " Processor usage " ));
2010-02-15 04:30:25 +00:00
define ( " NETWORK_LIMIT_DESC " , tra ( " Network usage " ));
2010-04-23 17:46:57 +00:00
2006-08-13 21:51:15 +00:00
// These texts are used in multiple places in prefs_edit.php and add_venue.php
2010-02-15 04:30:25 +00:00
define ( " PREFS_FORM_DESC1 " , tra ( " These preferences apply to all the BOINC projects in which you participate. " ) . " <br><br> " );
define ( " PREFS_FORM_ERROR_DESC " ,
2010-02-17 21:12:31 +00:00
tra (
" %1Unable to update preferences.%2 The values marked in red below were out of range or not numeric. " ,
" <strong> " ,
" </strong> "
) .
2010-02-15 04:30:25 +00:00
" <br><br> "
);
2006-08-13 21:51:15 +00:00
2004-02-02 23:34:39 +00:00
global $text ;
global $parse_result ;
global $top_parse_result ;
global $in_project_specific ;
global $venue_name ;
2005-12-17 04:53:48 +00:00
// get default settings for disk space usage so the default user
// preferences match the settings used by the scheduler.
// Defaults are set if the tags are missing, they depend on
// which scheduler is running:
// - 'old' has the default hardcoded
// - 'new' uses config settings
// if running the old scheduler, set <scheduler_disk_space_check_hardcoded>
// in config.xml so the right default is set for minimum free disk space
//
function get_disk_space_config () {
global $config ;
2010-04-23 17:46:57 +00:00
$config = get_config ();
$dp -> disk_max_used_gb = parse_config ( $config , " <default_disk_max_used_gb> " );
$dp -> disk_max_used_pct = parse_config ( $config , " <default_disk_max_used_pct> " );
$dp -> disk_min_free_gb = parse_config ( $config , " <default_disk_min_free_gb> " );
// set some defaults if not found
2012-09-24 06:35:38 +00:00
if ( ! $dp -> disk_max_used_gb ) $dp -> disk_max_used_gb = 0 ; // no limit
if ( ! $dp -> disk_max_used_pct ) $dp -> disk_max_used_pct = 90 ; // 90 percent
if ( ! $dp -> disk_min_free_gb ) $dp -> disk_min_free_gb =. 1 ; // 100 MB
2010-04-23 17:46:57 +00:00
// set mininimum free space scheduler allows
// - depends on which scheduler is running
$dp -> new_sched_flag = 1 ;
$dp -> sched_disk_min_free_gb = $dp -> disk_min_free_gb ;
if ( parse_config ( $config , " scheduler_disk_space_check_hardcoded> " )) {
$dp -> new_sched_flag = 0 ;
$dp -> sched_disk_min_free_gb = 0 ;
}
2005-12-17 04:53:48 +00:00
2010-04-23 17:46:57 +00:00
return $dp ;
2005-12-17 04:53:48 +00:00
}
2005-02-13 06:13:33 +00:00
function check_venue ( $x ) {
2011-02-13 19:00:08 +00:00
if ( $x == " " ) return ;
2005-02-13 06:13:33 +00:00
if ( $x == " home " ) return ;
if ( $x == " work " ) return ;
if ( $x == " school " ) return ;
2010-02-15 04:30:25 +00:00
error_page ( tra ( " bad venue: %1 " , $x ));
2005-02-13 06:13:33 +00:00
}
function check_subset ( $x ) {
if ( $x == " global " ) return ;
if ( $x == " project " ) return ;
2010-02-15 04:30:25 +00:00
error_page ( tra ( " bad subset: %1 " , $x ));
2005-02-13 06:13:33 +00:00
}
2004-02-02 23:34:39 +00:00
// functions to parse preferences XML into a struct
//
function element_start_project ( $parser , $name , $attrs ) {
global $top_parse_result ;
global $parse_result ;
global $text ;
global $in_project_specific ;
global $venue_name ;
switch ( $name ) {
case " venue " :
$venue_name = $attrs [ " name " ];
$top_parse_result = $parse_result ;
2006-10-25 21:15:08 +00:00
$parse_result = default_prefs_project ();
2004-02-02 23:34:39 +00:00
break ;
case " project_specific " :
$in_project_specific = 1 ;
$text = " " ;
break ;
default :
if ( $in_project_specific ) {
$text = $text . " < $name > " ;
} else {
$text = " " ;
}
}
}
function element_start_global ( $parser , $name , $attrs ) {
global $top_parse_result ;
global $parse_result ;
global $text ;
global $venue_name ;
switch ( $name ) {
case " venue " :
$venue_name = $attrs [ " name " ];
$top_parse_result = $parse_result ;
2009-02-12 18:04:30 +00:00
$parse_result = default_prefs_global ();
2004-02-02 23:34:39 +00:00
break ;
}
$text = " " ;
}
function element_end_project ( $parser , $name ) {
global $text ;
global $parse_result ;
global $in_project_specific ;
global $top_parse_result ;
global $venue_name ;
2010-04-26 19:31:28 +00:00
global $project_pref_descs ;
2004-02-02 23:34:39 +00:00
2010-04-26 19:31:28 +00:00
foreach ( $project_pref_descs as $p ) {
if ( $p -> xml_parse ( $parse_result , $name , $text )) {
return ;
}
}
2004-02-02 23:34:39 +00:00
switch ( $name ) {
case " venue " :
$top_parse_result -> $venue_name = $parse_result ;
$parse_result = $top_parse_result ;
break ;
case " project_specific " :
$parse_result -> project_specific = $text ;
$in_project_specific = false ;
break ;
case " project_preferences " :
break ;
default :
if ( $in_project_specific ) {
$text = $text . " </ $name > " ;
} else {
//echo "Unknown tag: $name\n";
}
}
}
function element_end_global ( $parser , $name ) {
global $text ;
global $parse_result ;
global $top_parse_result ;
global $venue_name ;
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $disk_prefs ;
global $net_prefs ;
2004-02-02 23:34:39 +00:00
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
if ( $p -> xml_parse ( $parse_result , $name , $text )) {
return ;
}
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
if ( $p -> xml_parse ( $parse_result , $name , $text )) {
return ;
}
}
foreach ( $net_prefs as $p ) {
if ( $p -> xml_parse ( $parse_result , $name , $text )) {
return ;
}
}
2004-02-02 23:34:39 +00:00
switch ( $name ) {
case " venue " :
$top_parse_result -> $venue_name = $parse_result ;
$parse_result = $top_parse_result ;
break ;
case " mod_time " :
$parse_result -> mod_time = $text ;
break ;
case " global_preferences " :
break ;
default :
//echo "Unknown tag: $name\n";
}
}
function char_handler ( $parser , $x ) {
global $text ;
$text = $text . $x ;
}
2005-12-17 04:53:48 +00:00
2009-02-12 18:04:30 +00:00
// state of prefs before parsing; defines prefs for new users
2004-02-02 23:34:39 +00:00
//
function default_prefs_global () {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2010-04-22 23:19:49 +00:00
2010-04-23 17:46:57 +00:00
$p = null ;
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $pref ) {
$pref -> set_default ( $p );
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $pref ) {
$pref -> set_default ( $p );
}
foreach ( $net_prefs as $pref ) {
$pref -> set_default ( $p );
}
2004-02-02 23:34:39 +00:00
return $p ;
}
function default_prefs_project () {
2010-04-26 19:31:28 +00:00
global $project_pref_descs ;
2004-02-02 23:34:39 +00:00
$p = null ;
2012-09-24 06:35:38 +00:00
foreach ( $project_pref_descs as $pref ) {
2010-04-26 19:31:28 +00:00
$pref -> set_default ( $p );
}
2004-02-02 23:34:39 +00:00
$p -> project_specific = project_specific_prefs_default ();
return $p ;
}
// parse prefs from XML to a struct
//
function prefs_parse_project ( $prefs_xml ) {
global $parse_result ;
2009-02-12 18:04:30 +00:00
$parse_result = default_prefs_project ();
2004-02-02 23:34:39 +00:00
$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 ;
}
function prefs_parse_global ( $prefs_xml ) {
global $parse_result ;
2009-02-12 18:04:30 +00:00
$parse_result = default_prefs_global ();
2004-02-02 23:34:39 +00:00
$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 ;
}
////////////////////////////////////////////
//
2006-08-13 21:51:15 +00:00
// display preference subsets as Columns
//
function row_top ( $x , $ncols = 6 , $class = " heading " ) {
2007-07-19 23:22:19 +00:00
echo " <tr><td class= $class width=35%> $x </td> " ;
2010-07-14 19:20:31 +00:00
echo " <td class= $class width=10%><b> " . tra ( " Default " ) . " </b></td>
< td class = $class width = 10 %>< b > " .tra( " Home " ). " </ b ></ td >
< td class = $class width = 10 %>< b > " .tra( " School " ). " </ b ></ td >
< td class = $class width = 10 %>< b > " .tra( " Work " ). " </ b ></ td > " ;
2007-07-19 23:22:19 +00:00
echo " <td width=15%><br></td></tr> \n " ;
2006-08-13 21:51:15 +00:00
}
//
// row_defs - Display a value for all 4 venues in one row
//
function row_defs ( $pre , $item , $post , $type , $prefs ) {
2006-10-24 23:53:59 +00:00
$gen = $prefs -> $item ;
2009-11-24 04:37:47 +00:00
$hom = ( isset ( $prefs -> home ) && isset ( $prefs -> home -> $item )) ? $prefs -> home -> $item : " -- " ;
$schl = ( isset ( $prefs -> school ) && isset ( $prefs -> school -> $item )) ? $prefs -> school -> $item : " -- " ;
$wrk = ( isset ( $prefs -> work ) && isset ( $prefs -> work -> $item )) ? $prefs -> work -> $item : " -- " ;
2006-08-13 21:51:15 +00:00
echo " <tr><td class=fieldname> $pre </td> " ;
row_field ( $gen , $type );
row_field ( $hom , $type );
row_field ( $schl , $type );
row_field ( $wrk , $type );
echo " <td align=left> $post </td></tr> \n " ;
}
//
// row_field - Display each field value, with selectable display modes
//
function row_field ( $value , $type ) {
2007-07-19 23:22:19 +00:00
echo " <td class=f_val valign=top> " ;
2006-08-13 21:51:15 +00:00
$type = $value === " -- " ? " -- " : $type ;
2006-10-24 23:53:59 +00:00
switch ( $type ) {
case " yesno " :
2010-02-15 04:30:25 +00:00
echo $value ? tra ( " yes " ) : tra ( " no " );
2006-10-24 23:53:59 +00:00
break ;
2009-09-28 04:24:18 +00:00
case " noyes " :
2010-02-15 04:30:25 +00:00
echo $value ? tra ( " no " ) : tra ( " yes " );
2009-09-28 04:24:18 +00:00
break ;
2006-10-24 23:53:59 +00:00
case " limit " :
$x = max_bytes_display_mode ( $value );
$y = " $x " . BYTE_ABBR ;
2010-02-15 04:30:25 +00:00
echo $x ? " $y " : tra ( " no limit " );
2006-10-24 23:53:59 +00:00
break ;
2007-07-19 23:22:19 +00:00
case " minutes " :
if ( $value ) {
echo $value ;
} else {
echo '--' ;
}
break ;
2006-10-24 23:53:59 +00:00
default :
echo $value ;
break ;
}
echo " </td> " ;
2006-08-13 21:51:15 +00:00
}
//
// row_links - Display Edit/Add/Remove links for all venues in 1 row
2004-02-02 23:34:39 +00:00
//
2006-08-13 21:51:15 +00:00
function row_links ( $subset , $prefs ) {
2007-01-29 18:15:16 +00:00
global $g_logged_in_user ;
$tokens = url_tokens ( $g_logged_in_user -> authenticator );
2007-12-24 21:34:21 +00:00
$pre_add = " <a href=add_venue.php?venue= " ;
2006-10-24 23:53:59 +00:00
$pre_edit = " <a href=prefs_edit.php?venue= " ;
$pre_remove = " <a href=prefs_remove.php?venue= " ;
2011-02-14 19:49:30 +00:00
$post_add = " &subset= $subset &cols=1 $tokens > " . tra ( " Add " ) . " </a> " ;
$post_edit = " &subset= $subset &cols=1 $tokens > " . tra ( " Edit " ) . " </a> " ;
$post_remove = " &subset= $subset &cols=1 $tokens > " . tra ( " Remove " ) . " </a> " ;
$gen = " <a href=prefs_edit.php?subset= $subset &cols=1 $tokens > " . tra ( " Edit " ) . " </a> " ;
2006-10-24 23:53:59 +00:00
$hom = isset ( $prefs -> home ) ? $pre_edit . " home " . $post_edit : $pre_add . " home " . $post_add ;
$schl = isset ( $prefs -> school ) ? $pre_edit . " school " . $post_edit : $pre_add . " school " . $post_add ;
$wrk = isset ( $prefs -> work ) ? $pre_edit . " work " . $post_edit : $pre_add . " work " . $post_add ;
2006-08-13 21:51:15 +00:00
echo " <tr><td class=fieldname> </td> " ;
echo " <td> $gen </td> " ;
echo " <td> $hom </td> " ;
echo " <td> $schl </td> " ;
echo " <td> $wrk </td> " ;
echo " <td><br></td></tr> \n " ;
$hom = isset ( $prefs -> home ) ? $pre_remove . " home " . $post_remove : " <br> " ;
2006-10-24 23:53:59 +00:00
$schl = isset ( $prefs -> school ) ? $pre_remove . " school " . $post_remove : " <br> " ;
$wrk = isset ( $prefs -> work ) ? $pre_remove . " work " . $post_remove : " <br> " ;
2006-08-13 21:51:15 +00:00
echo " <tr><td class=fieldname> </td> " ;
echo " <td> </td> " ;
echo " <td> $hom </td> " ;
echo " <td> $schl </td> " ;
echo " <td> $wrk </td> " ;
echo " <td><br></td></tr> \n " ;
}
2010-04-22 17:45:33 +00:00
// Display all venues as columns next to descriptions
2006-08-13 21:51:15 +00:00
//
function prefs_show_columns_global ( $prefs ) {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2006-08-13 21:51:15 +00:00
row_top ( CPU_LIMIT_DESC );
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
$p -> show_cols ( $prefs );
}
2006-08-13 21:51:15 +00:00
row_top ( DISK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$p -> show_cols ( $prefs );
}
2006-08-13 21:51:15 +00:00
row_top ( NETWORK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
$p -> show_cols ( $prefs );
}
2006-10-24 23:53:59 +00:00
row_links ( " global " , $prefs );
2006-08-13 21:51:15 +00:00
}
2004-02-02 23:34:39 +00:00
function prefs_show_global ( $prefs ) {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2004-12-06 22:41:19 +00:00
row1 ( CPU_LIMIT_DESC );
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
$p -> show ( $prefs );
2004-02-02 23:34:39 +00:00
}
row1 ( DISK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$p -> show ( $prefs );
2005-12-17 04:53:48 +00:00
}
2004-02-02 23:34:39 +00:00
row1 ( NETWORK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
$p -> show ( $prefs );
2005-06-08 23:55:21 +00:00
}
2004-02-02 23:34:39 +00:00
}
2010-04-26 19:31:28 +00:00
function prefs_show_project ( $prefs , $columns = false ) {
global $project_pref_descs ;
2006-10-24 23:53:59 +00:00
if ( $columns ) {
2010-04-26 19:31:28 +00:00
foreach ( $project_pref_descs as $p ) {
$p -> show_cols ( $prefs );
2009-09-28 04:24:18 +00:00
}
2006-08-13 21:51:15 +00:00
} else {
2010-04-26 19:31:28 +00:00
foreach ( $project_pref_descs as $p ) {
$p -> show ( $prefs );
2009-09-28 04:24:18 +00:00
}
2006-08-13 21:51:15 +00:00
}
2004-02-02 23:34:39 +00:00
}
2010-06-17 19:11:00 +00:00
function prefs_show_privacy ( $user , $columns ) {
global $privacy_pref_descs ;
if ( $columns ) {
foreach ( $privacy_pref_descs as $p ) {
$p -> show_cols ( $user );
}
} else {
foreach ( $privacy_pref_descs as $p ) {
$p -> show ( $user );
}
2006-07-06 18:03:35 +00:00
}
2004-02-02 23:34:39 +00:00
}
2010-04-26 19:31:28 +00:00
function prefs_show_project_specific ( $prefs , $columns = false ) {
2006-10-24 23:53:59 +00:00
if ( $columns ) {
2004-02-02 23:34:39 +00:00
$project_specific_prefs = project_specific_prefs_parse ( $prefs -> project_specific );
2006-08-13 21:51:15 +00:00
$project_specific_prefs -> home = isset ( $prefs -> home ) ? project_specific_prefs_parse ( $prefs -> home -> project_specific ) : " " ;
$project_specific_prefs -> work = isset ( $prefs -> work ) ? project_specific_prefs_parse ( $prefs -> work -> project_specific ) : " " ;
$project_specific_prefs -> school = isset ( $prefs -> school ) ? project_specific_prefs_parse ( $prefs -> school -> project_specific ) : " " ;
} else {
$project_specific_prefs = project_specific_prefs_parse ( $prefs -> project_specific );
}
project_specific_prefs_show ( $project_specific_prefs , $columns );
2004-02-02 23:34:39 +00:00
}
function subset_name ( $subset ) {
2010-02-15 04:30:25 +00:00
if ( $subset == " global " ) return tra ( " Computing " );
2004-02-02 23:34:39 +00:00
return PROJECT ;
}
function prefs_display_venue ( $prefs , $venue , $subset ) {
2007-01-29 18:15:16 +00:00
global $g_logged_in_user ;
$tokens = url_tokens ( $g_logged_in_user -> authenticator );
2006-08-13 21:51:15 +00:00
$x = false ;
if ( isset ( $prefs -> $venue )) $x = $prefs -> $venue ;
2004-02-02 23:34:39 +00:00
if ( $x ) {
2010-02-15 04:30:25 +00:00
row1 ( tra ( " Separate preferences for %1 " , $venue ), 2 , " heading " );
2004-12-16 19:37:26 +00:00
echo " <tr><td colspan=2> " ;
start_table ();
2004-02-02 23:34:39 +00:00
if ( $subset == " global " ) {
prefs_show_global ( $x );
} else {
prefs_show_project ( $x );
2010-04-26 19:31:28 +00:00
prefs_show_project_specific ( $x );
2004-02-02 23:34:39 +00:00
}
2012-09-24 06:35:38 +00:00
row2 ( " <br> " ,
" <a href=prefs_edit.php?venue= $venue &subset= $subset $tokens > " . tra ( " Edit preferences " ) . " </a>
| < a href = prefs_remove . php ? venue = $venue & subset = $subset $tokens > " .tra( " Remove " ). " </ a >
" );
2004-12-16 19:37:26 +00:00
end_table ();
echo " </td></tr> \n " ;
2004-02-02 23:34:39 +00:00
} else {
2011-02-14 19:49:30 +00:00
row1 ( " <a href=add_venue.php?venue= $venue &subset= $subset $tokens > " . tra ( " Add separate preferences for %1 " , $venue ) . " </a> " , 2 , " heading " );
2004-02-02 23:34:39 +00:00
}
}
2006-08-13 21:51:15 +00:00
function print_prefs_display_project ( $user , $columns = false ) {
2004-02-02 23:34:39 +00:00
$project_prefs = prefs_parse_project ( $user -> project_prefs );
start_table ();
2010-02-15 04:30:25 +00:00
$switch_link = " <font size= \" -2 \" ><a href=prefs.php?subset=project&cols= " . ( int ) ! $columns . " > " . tra ( " (Switch View) " ) . " </a></font> " ;
2006-10-24 23:53:59 +00:00
if ( $columns ) {
2010-02-15 04:30:25 +00:00
row1 ( tra ( " Combined preferences " ) . $switch_link , 2 , " heading " );
2006-08-13 21:51:15 +00:00
echo " <tr><td colspan=2> " ;
2008-08-12 17:08:14 +00:00
start_table ();
2010-06-17 19:11:00 +00:00
prefs_show_privacy ( $user , true );
2006-08-13 21:51:15 +00:00
venue_show ( $user );
2010-02-15 04:30:25 +00:00
row_top ( tra ( " Project specific settings " ));
2006-08-13 21:51:15 +00:00
prefs_show_project ( $project_prefs , true );
2010-04-26 19:31:28 +00:00
prefs_show_project_specific ( $project_prefs , true );
2006-08-13 21:51:15 +00:00
row_links ( " project " , $project_prefs );
end_table ();
echo " </td></tr> \n " ;
} else {
if ( isset ( $project_prefs -> home ) || isset ( $project_prefs -> work ) || isset ( $project_prefs -> school )) {
2010-02-15 04:30:25 +00:00
row1 ( tra ( " Primary (default) preferences " ) . $switch_link , 2 , " heading " );
2006-10-24 23:53:59 +00:00
}
echo " <tr><td colspan=2> " ;
2008-08-12 17:08:14 +00:00
start_table ();
2010-04-26 19:31:28 +00:00
prefs_show_project ( $project_prefs , false );
2010-06-17 19:11:00 +00:00
prefs_show_privacy ( $user , false );
2006-10-24 23:53:59 +00:00
venue_show ( $user );
2010-04-26 19:31:28 +00:00
prefs_show_project_specific ( $project_prefs , false );
2007-01-29 22:57:10 +00:00
$tokens = url_tokens ( $user -> authenticator );
2010-02-15 04:30:25 +00:00
row2 ( " " , " <a href=prefs_edit.php?subset=project $tokens > " . tra ( " Edit %1 preferences " , PROJECT ) . " </a> " );
2006-10-24 23:53:59 +00:00
end_table ();
echo " </td></tr> \n " ;
prefs_display_venue ( $project_prefs , " home " , " project " );
prefs_display_venue ( $project_prefs , " school " , " project " );
prefs_display_venue ( $project_prefs , " work " , " project " );
2006-08-13 21:51:15 +00:00
}
2004-02-02 23:34:39 +00:00
end_table ();
}
2006-08-13 21:51:15 +00:00
function print_prefs_display_global ( $user , $columns = false ) {
2004-02-02 23:34:39 +00:00
$global_prefs = prefs_parse_global ( $user -> global_prefs );
2010-02-15 04:30:25 +00:00
echo " <span class=note> " .
tra ( " These apply to all BOINC projects in which you participate.<br>
2010-10-06 20:13:34 +00:00
On computers participating in multiple projects , the most recently modified preferences will be used . " ).
2010-02-15 04:30:25 +00:00
" </span><br><br> " ;
2007-10-30 18:16:29 +00:00
if ( isset ( $global_prefs -> mod_time )) {
2010-02-15 04:30:25 +00:00
echo tra ( " Preferences last modified: " ) . " " . pretty_time_str ( $global_prefs -> mod_time );
2007-10-30 18:16:29 +00:00
}
2010-02-15 04:30:25 +00:00
echo " <br><br> " ;
$switch_link = " <font size= \" -2 \" ><a href=prefs.php?subset=global&cols= " . ( int ) ! $columns . " > " . tra ( " (Switch View) " ) . " </a></font> " ;
2004-02-02 23:34:39 +00:00
start_table ();
2006-10-24 23:53:59 +00:00
if ( $columns ) {
2010-02-15 04:30:25 +00:00
row1 ( tra ( " Combined preferences " ) . $switch_link , 2 , " heading " );
2006-08-13 21:51:15 +00:00
echo " <tr><td colspan=2> " ;
2008-08-12 17:08:14 +00:00
start_table ();
2006-08-13 21:51:15 +00:00
prefs_show_columns_global ( $global_prefs );
end_table ();
echo " </td></tr> \n " ;
} else {
if ( isset ( $global_prefs -> home ) || isset ( $global_prefs -> work ) || isset ( $global_prefs -> school )) {
2010-02-15 04:30:25 +00:00
row1 ( tra ( " Primary (default) preferences " ) . $switch_link , 2 , " heading " );
2006-10-24 23:53:59 +00:00
}
echo " <tr><td colspan=2> " ;
2008-08-12 17:08:14 +00:00
start_table ();
2006-10-24 23:53:59 +00:00
prefs_show_global ( $global_prefs );
2007-01-29 22:57:10 +00:00
$tokens = url_tokens ( $user -> authenticator );
2012-09-24 06:35:38 +00:00
row2 ( " <br> " ,
" <a href=prefs_edit.php?subset=global $tokens > " . tra ( " Edit preferences " ) . " </a>
" );
2006-10-24 23:53:59 +00:00
end_table ();
echo " </td></tr> \n " ;
2004-02-02 23:34:39 +00:00
2006-10-24 23:53:59 +00:00
prefs_display_venue ( $global_prefs , " home " , " global " );
prefs_display_venue ( $global_prefs , " school " , " global " );
prefs_display_venue ( $global_prefs , " work " , " global " );
2006-08-13 21:51:15 +00:00
}
2004-02-02 23:34:39 +00:00
end_table ();
}
function print_prefs_display ( $user ) {
print_prefs_display_project ( $user );
echo " <br><br> \n " ;
print_prefs_display_global ( $user );
}
2006-08-13 21:51:15 +00:00
// This functions is used in prefs_edit.php to be able to display
// the prefs form in case of an error again.
// $error and $project_error should be an object of the form:
2007-01-29 18:15:16 +00:00
// $error->idle_time_to_run=true if an error occurred
2006-08-13 21:51:15 +00:00
// otherwise false
2007-01-29 18:15:16 +00:00
//
2006-10-25 21:15:08 +00:00
function print_prefs_form (
$action , $subset , $venue , $user , $prefs , $cols , $error = false ,
$project_error = false
){
2006-08-13 21:51:15 +00:00
if ( $action == " add " ) {
$script = " add_venue.php " ;
2010-02-15 04:30:25 +00:00
$submit_value = tra ( " Add preferences " );
2006-08-13 21:51:15 +00:00
}
if ( $action == " edit " ) {
$script = " prefs_edit.php " ;
2010-02-15 04:30:25 +00:00
$submit_value = tra ( " Update preferences " );
2006-08-13 21:51:15 +00:00
}
2006-10-24 23:53:59 +00:00
echo " <form action= $script ><input type=hidden name=subset value= $subset >
2007-01-29 18:15:16 +00:00
" .form_tokens( $user->authenticator );
2006-08-13 21:51:15 +00:00
if ( $venue ) {
echo " <input type=hidden name=venue value= $venue > \n " ;
}
if ( $cols ) {
echo " <input type=hidden name=cols value= $cols > \n " ;
}
start_table ();
if ( $subset == " global " ) {
prefs_form_global ( $user , $prefs , $error );
} else {
2010-04-26 19:31:28 +00:00
prefs_form_project ( $prefs , $error );
2006-08-13 21:51:15 +00:00
if ( ! $venue ) {
prefs_form_privacy ( $user );
venue_form ( $user );
}
2010-04-26 19:31:28 +00:00
prefs_form_project_specific ( $prefs -> project_specific , $project_error );
2006-08-13 21:51:15 +00:00
}
2009-04-07 18:21:39 +00:00
row2 ( " " , " <input type=submit value= \" $submit_value\ " name = \ " action \" > " );
2006-08-13 21:51:15 +00:00
end_table ();
echo " </form> \n " ;
}
2004-02-02 23:34:39 +00:00
////////////////////////////////////////////
//
// Functions to display preference subsets as forms
//
2006-08-13 21:51:15 +00:00
function prefs_form_global ( $user , $prefs , $error = false ) {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2010-02-15 04:30:25 +00:00
2004-12-06 22:41:19 +00:00
row1 ( CPU_LIMIT_DESC );
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
$p -> show_form_row ( $prefs , $error );
}
2004-02-02 23:34:39 +00:00
row1 ( DISK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$p -> show_form_row ( $prefs , $error );
}
2004-02-02 23:34:39 +00:00
row1 ( NETWORK_LIMIT_DESC );
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
$p -> show_form_row ( $prefs , $error );
}
2004-02-02 23:34:39 +00:00
}
function prefs_form_privacy ( $user ) {
2010-06-17 19:11:00 +00:00
global $privacy_pref_descs ;
foreach ( $privacy_pref_descs as $p ) {
$p -> show_form_row ( $user , false );
}
2004-02-02 23:34:39 +00:00
}
2010-04-26 19:31:28 +00:00
function prefs_form_project ( $prefs , $error = false ) {
global $project_pref_descs ;
foreach ( $project_pref_descs as $p ) {
$p -> show_form_row ( $prefs , $error );
2009-09-28 04:24:18 +00:00
}
2004-02-02 23:34:39 +00:00
}
2010-04-26 19:31:28 +00:00
function prefs_form_project_specific ( $prefs_xml , $error = false ) {
2004-02-02 23:34:39 +00:00
$prefs = project_specific_prefs_parse ( $prefs_xml );
2006-08-13 21:51:15 +00:00
project_specific_prefs_edit ( $prefs , $error );
2004-02-02 23:34:39 +00:00
}
2010-02-15 04:30:25 +00:00
// returns a set of translated yes/no radio buttons for editing prefs forms
// Example: prefs_form_radio_buttons("allow_beta_work", $user->allow_beta_work);
//
// @param string $name name of the radio buttons
// @param bool $yesno toggles the preset of the buttons; true=yes, false=no
2010-06-17 19:11:00 +00:00
//
2010-02-15 04:30:25 +00:00
function prefs_form_radio_buttons ( $name , $yesno ) {
$rb = tra ( " yes " ) . " <input type=radio name= $name value=yes "
. ( $yesno ? " checked " : " " )
. " > " . tra ( " no " ) . " <input type=radio name= $name value=no "
2010-03-04 04:16:00 +00:00
. ( $yesno ? " " : " checked " )
2010-02-15 04:30:25 +00:00
. " > \n " ;
return $rb ;
}
2004-02-02 23:34:39 +00:00
function venue_show ( $user ) {
2007-03-06 18:22:04 +00:00
$venue = $user -> venue ;
if ( $venue == '' ) $venue = '---' ;
2010-02-15 04:30:25 +00:00
row2 ( tra ( " Default computer location " ), $venue );
2004-02-02 23:34:39 +00:00
}
function venue_form ( $user ) {
2007-03-06 18:22:04 +00:00
$n = $h = $w = $s = '' ;
if ( $user -> venue == '' ) $n = 'selected' ;
if ( $user -> venue == 'home' ) $h = 'selected' ;
if ( $user -> venue == 'work' ) $w = 'selected' ;
if ( $user -> venue == 'school' ) $s = 'selected' ;
2010-02-15 04:30:25 +00:00
row2 ( tra ( " Default computer location " ),
2004-02-02 23:34:39 +00:00
" <select name=default_venue>
2007-03-06 18:22:04 +00:00
< option value = \ " \" $n >---
2010-02-15 04:30:25 +00:00
< option value = home $h > " .tra( " Home " ). "
< option value = work $w > " .tra( " Work " ). "
< option value = school $s > " .tra( " School " ). "
2004-03-20 01:35:37 +00:00
</ select > "
2004-02-02 23:34:39 +00:00
);
}
function venue_parse_form ( & $user ) {
$user -> venue = $_GET [ 'default_venue' ];
}
function venue_update ( $user ) {
mysql_query ( " update user set venue=' $user->venue ' where id= $user->id " );
}
////////////////////////////////////////////
//
// Functions to parse form elements, modifying a preferences structure
2007-07-19 23:22:19 +00:00
// prefs is preferences object to modify
// returns an object with errorvalues or false in success case
//
2004-02-02 23:34:39 +00:00
function prefs_global_parse_form ( & $prefs ) {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2006-08-13 21:51:15 +00:00
$error = false ;
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
$p -> parse_form ( $prefs , $error );
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$p -> parse_form ( $prefs , $error );
}
foreach ( $net_prefs as $p ) {
$p -> parse_form ( $prefs , $error );
}
2006-08-13 21:51:15 +00:00
return $error ;
2004-02-02 23:34:39 +00:00
}
function prefs_resource_parse_form ( & $prefs ) {
2010-04-26 19:31:28 +00:00
global $project_pref_descs ;
2006-08-13 21:51:15 +00:00
$error = false ;
2010-04-26 19:31:28 +00:00
foreach ( $project_pref_descs as $p ) {
$p -> parse_form ( $prefs , $error );
2009-09-28 04:24:18 +00:00
}
2006-08-13 21:51:15 +00:00
return $error ;
2004-02-02 23:34:39 +00:00
}
function prefs_privacy_parse_form ( & $user ) {
2010-06-17 19:11:00 +00:00
global $privacy_pref_descs ;
$error = false ;
foreach ( $privacy_pref_descs as $p ) {
$p -> parse_form ( $user , $error );
}
return $error ;
2004-02-02 23:34:39 +00:00
}
2010-06-17 19:11:00 +00:00
// Parse the project specific prefs form.
// For details see project/project_specific_prefs.inc
2010-04-26 19:31:28 +00:00
//
2004-02-02 23:34:39 +00:00
function prefs_project_parse_form ( & $prefs ) {
2006-08-13 21:51:15 +00:00
$error = false ;
$prefs -> project_specific = project_specific_prefs_parse_form ( $error );
return $error ;
2004-02-02 23:34:39 +00:00
}
////////////////////////////////////////////
//
// convert prefs from structure to XML
//
function global_prefs_make_xml ( $prefs , $primary = true ) {
2010-04-22 23:19:49 +00:00
global $cpu_prefs ;
2010-04-23 17:46:57 +00:00
global $disk_prefs ;
global $net_prefs ;
2010-04-22 23:19:49 +00:00
2006-08-13 21:51:15 +00:00
$xml = " " ;
2004-02-02 23:34:39 +00:00
if ( $primary ) {
$xml = " <global_preferences> \n " ;
$now = time ();
$xml = $xml . " <mod_time> $now </mod_time> \n " ;
}
2009-02-12 18:04:30 +00:00
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
$xml .= $p -> xml_string ( $prefs );
2004-02-02 23:34:39 +00:00
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$xml .= $p -> xml_string ( $prefs );
2004-02-02 23:34:39 +00:00
}
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
$xml .= $p -> xml_string ( $prefs );
2005-06-08 23:55:21 +00:00
}
2009-02-12 18:04:30 +00:00
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> home )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" home \" > \n " . global_prefs_make_xml ( $prefs -> home , false ) . " </venue> \n " ;
}
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> work )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" work \" > \n " . global_prefs_make_xml ( $prefs -> work , false ) . " </venue> \n " ;
}
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> school )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" school \" > \n " . global_prefs_make_xml ( $prefs -> school , false ) . " </venue> \n " ;
}
if ( $primary ) {
$xml = $xml . " </global_preferences> \n " ;
}
return $xml ;
}
// given a prefs structure, return the corresponding XML string
//
function project_prefs_make_xml ( $prefs , $primary = true ) {
2010-04-26 19:31:28 +00:00
global $project_pref_descs ;
2004-02-02 23:34:39 +00:00
$xml = " " ;
if ( $primary ) {
$xml = " <project_preferences> \n " ;
}
2010-04-26 19:31:28 +00:00
foreach ( $project_pref_descs as $p ) {
$xml .= $p -> xml_string ( $prefs );
2009-09-28 04:24:18 +00:00
}
2004-02-02 23:34:39 +00:00
if ( $prefs -> project_specific ) {
$x = trim ( $prefs -> project_specific );
$xml = $xml
. " <project_specific> \n $x\n </project_specific> \n " ;
}
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> home )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" home \" > \n " . project_prefs_make_xml ( $prefs -> home , false ) . " </venue> \n " ;
}
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> work )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" work \" > \n " . project_prefs_make_xml ( $prefs -> work , false ) . " </venue> \n " ;
}
2006-08-13 21:51:15 +00:00
if ( isset ( $prefs -> school )) {
2004-02-02 23:34:39 +00:00
$xml = $xml . " <venue name= \" school \" > \n " . project_prefs_make_xml ( $prefs -> school , false ) . " </venue> \n " ;
}
if ( $primary ) {
$xml = $xml . " </project_preferences> \n " ;
}
return $xml ;
}
////////////////////////////////////////////
//
// Update user's prefs in database, from a given structure
//
function global_prefs_update ( & $user , $prefs ) {
2010-01-18 15:19:23 +00:00
$prefs_xml = mysql_real_escape_string ( global_prefs_make_xml ( $prefs ));
2004-02-02 23:34:39 +00:00
$query = " update user set global_prefs=' $prefs_xml ' where id= $user->id " ;
$retval = mysql_query ( $query );
if ( ! $retval ) {
2012-09-24 06:35:38 +00:00
return 1 ;
2004-02-02 23:34:39 +00:00
}
$user -> global_prefs = $prefs_xml ;
2012-09-24 06:35:38 +00:00
return 0 ;
2004-02-02 23:34:39 +00:00
}
function project_prefs_update ( & $user , $prefs ) {
2010-01-18 15:19:23 +00:00
$prefs_xml = mysql_real_escape_string ( project_prefs_make_xml ( $prefs ));
2010-06-17 19:11:00 +00:00
$send_email = $user -> send_email ? 1 : 0 ;
$show_hosts = $user -> show_hosts ? 1 : 0 ;
$query = " update user set project_prefs=' $prefs_xml ', send_email= $send_email , show_hosts= $show_hosts where id= $user->id " ;
$retval = mysql_query ( $query );
2012-09-24 06:35:38 +00:00
if ( ! $retval ) {
return 1 ;
}
2004-02-02 23:34:39 +00:00
$user -> project_prefs = $prefs_xml ;
2012-09-24 06:35:38 +00:00
return 0 ;
2004-02-02 23:34:39 +00:00
}
?>