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
2014-08-06 04:02:59 +00:00
// Copyright (C) 2014 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/>.
2014-08-06 04:02:59 +00:00
// functions for display and editing global preferences.
2004-02-02 23:34:39 +00:00
// 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
// - 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>
//
// Various functions are defined below for converting between these forms,
// and also to/from HTML form elements
2010-04-23 18:32:30 +00:00
include_once ( " ../inc/prefs_util.inc " );
2015-09-28 12:41:01 +00:00
include_once ( " ../inc/translation.inc " );
2010-04-22 23:19:49 +00:00
2015-07-14 12:47:31 +00:00
global $cpu_prefs ;
global $disk_prefs ;
global $mem_prefs ;
global $net_prefs ;
2010-04-22 23:19:49 +00:00
$cpu_prefs = array (
2015-02-20 21:47:20 +00:00
tra ( " Usage limits " ),
2014-12-13 01:54:26 +00:00
new PREF_NUM (
tra ( " Use at most " ),
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
2015-02-20 21:47:20 +00:00
tra ( " Keep some CPUs free for other applications. Example: 75% means use 6 cores on an 8-core CPU. " ),
2014-12-13 01:54:26 +00:00
" max_ncpus_pct " ,
2015-03-04 16:55:17 +00:00
// xgettext:no-php-format
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " % of the CPUs " ), 1 , 100 , 100 )
),
new PREF_NUM (
tra ( " Use at most " ),
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
2015-02-20 21:47:20 +00:00
tra ( " Suspend/resume computing every few seconds to reduce CPU temperature and energy usage. Example: 75% means compute for 3 seconds, wait for 1 second, and repeat. " ),
2014-12-13 01:54:26 +00:00
" cpu_usage_limit " ,
2015-03-04 16:55:17 +00:00
// xgettext:no-php-format
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " % of CPU time " ), 1 , 100 , 100 )
),
2015-02-20 21:47:20 +00:00
tra ( " When to suspend " ),
2010-04-22 23:19:49 +00:00
new PREF_BOOL (
2014-12-13 01:54:26 +00:00
tra ( " Suspend when computer is on battery " ),
2015-02-20 21:47:20 +00:00
tra ( " Check this to suspend computing on portables when running on battery power. " ),
2010-04-26 20:28:54 +00:00
" run_on_batteries " ,
false , true
2010-04-22 23:19:49 +00:00
),
new PREF_BOOL (
2014-12-13 01:54:26 +00:00
tra ( " Suspend when computer is in use " ),
2015-02-20 21:47:20 +00:00
tra ( " Check this to suspend computing and file transfers when you're using the computer. " ),
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 (
2014-12-13 01:54:26 +00:00
tra ( " Suspend GPU computing when computer is in use " ),
2015-02-20 21:47:20 +00:00
tra ( " Check this to suspend GPU computing when you're using the computer. " ),
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 (
2014-12-13 01:54:26 +00:00
tra ( " 'In use' means mouse/keyboard input in last " ),
2015-02-20 21:47:20 +00:00
tra ( " This determines when the computer is considered 'in use'. " ),
2010-04-22 23:19:49 +00:00
" idle_time_to_run " ,
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " minutes " ), 1 , 9999 , 3 ),
true
2010-04-22 23:19:49 +00:00
),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
2015-02-18 16:29:20 +00:00
tra ( " Suspend when no mouse/keyboard input in last " ),
tra ( " This allows some computers to enter low-power mode when not in use. " ),
2010-04-22 23:19:49 +00:00
" suspend_if_no_recent_input " ,
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " minutes " ), 0 , 9999 , 0 , 1 , 60 )
2010-04-22 23:19:49 +00:00
),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Suspend when non-BOINC CPU usage is above " ),
2015-02-20 21:47:20 +00:00
tra ( " Suspend computing when your computer is busy running other programs. " ),
2010-04-22 23:19:49 +00:00
" 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 (
2015-02-18 16:29:20 +00:00
tra ( " Compute only between " ),
2015-03-03 18:04:21 +00:00
tra ( " Compute only during a particular period each day. " ),
2010-04-22 23:19:49 +00:00
" start_hour " , " end_hour "
),
2015-02-20 21:47:20 +00:00
tra ( " Other " ),
2010-04-22 23:19:49 +00:00
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " Store at least " ),
2015-02-20 21:47:20 +00:00
tra ( " Store at least enough tasks to keep the computer busy for this long. " ),
2014-12-13 01:54:26 +00:00
" work_buf_min_days " ,
new NUM_SPEC ( tra ( " days of work " ), 0 , 10 , . 1 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " Store up to an additional " ),
2015-02-20 21:47:20 +00:00
tra ( " Store additional tasks above the minimum level. Determines how much work is requested when contacting a project. " ),
2014-12-13 01:54:26 +00:00
" work_buf_additional_days " ,
new NUM_SPEC ( tra ( " days of work " ), 0 , 10 , . 5 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
2015-11-09 06:42:51 +00:00
tra ( " Switch between tasks every " ),
2015-02-20 21:47:20 +00:00
tra ( " If you run several projects, BOINC may switch between them this often. " ),
2014-12-13 01:54:26 +00:00
" cpu_scheduling_period_minutes " ,
new NUM_SPEC ( tra ( " minutes " ), 1 , 9999 , 60 )
2010-04-22 23:19:49 +00:00
),
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " Request tasks to checkpoint at most every " ),
2015-10-09 22:35:37 +00:00
tra ( " This controls how often tasks save their state to disk, so that later they can be continued from that point. " ),
2014-12-13 01:54:26 +00:00
" disk_interval " ,
new NUM_SPEC ( tra ( " seconds " ), 0 , 9999999 , 60 )
2010-04-22 23:19:49 +00:00
),
);
2010-04-23 17:46:57 +00:00
$dp = get_disk_space_config ();
$disk_prefs = array (
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Use no more than " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the total amount of disk space used by BOINC. " ),
2010-04-23 17:46:57 +00:00
" disk_max_used_gb " ,
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " GB " ), 0 , 9999999 , $dp -> disk_max_used_gb , 1 , 100 )
2010-04-23 17:46:57 +00:00
),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Leave at least " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit disk usage to leave this much free space on the volume where BOINC stores data. " ),
2010-04-23 17:46:57 +00:00
" disk_min_free_gb " ,
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " GB free " ), 0 , 9999999 , $dp -> disk_min_free_gb , 1 , 1 )
2010-04-23 17:46:57 +00:00
),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Use no more than " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the percentage of disk space used by BOINC on the volume where it stores data. " ),
2010-04-23 17:46:57 +00:00
" disk_max_used_pct " ,
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
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
),
2007-03-29 03:29:41 +00:00
);
2010-04-23 17:46:57 +00:00
2014-12-13 01:54:26 +00:00
$mem_prefs = array (
2010-04-23 17:46:57 +00:00
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " When computer is in use, use at most " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the memory used by BOINC when you're using the computer. " ),
2014-12-13 01:54:26 +00:00
" ram_max_used_busy_pct " ,
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " % " ), 1 , 100 , 50 )
2010-04-23 17:46:57 +00:00
),
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " When computer is not in use, use at most " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the memory used by BOINC when you're not using the computer. " ),
2014-12-13 01:54:26 +00:00
" ram_max_used_idle_pct " ,
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " % " ), 1 , 100 , 90 )
2010-04-23 17:46:57 +00:00
),
new PREF_BOOL (
2014-12-13 01:54:26 +00:00
tra ( " Leave non-GPU tasks in memory while suspended " ),
2015-02-20 21:47:20 +00:00
tra ( " If checked, suspended tasks stay in memory, and resume with no work lost. If unchecked, suspended tasks are removed from memory, and resume from their last checkpoint. " ),
2014-12-13 01:54:26 +00:00
" leave_apps_in_memory " ,
2010-04-23 17:46:57 +00:00
false
),
new PREF_NUM (
2014-12-13 01:54:26 +00:00
tra ( " Page/swap file: use at most " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the swap space (page file) used by BOINC. " ),
2014-12-13 01:54:26 +00:00
" vm_max_used_pct " ,
2015-03-04 16:51:10 +00:00
// xgettext:no-php-format
2014-12-13 01:54:26 +00:00
new NUM_SPEC ( tra ( " % " ), 1 , 100 , 75 )
),
);
$net_prefs = array (
2015-02-20 21:47:20 +00:00
tra ( " Usage limits " ),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Limit download rate to " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the download rate of file transfers. " ),
2010-04-23 17:46:57 +00:00
" max_bytes_sec_down " ,
2015-02-20 21:47:20 +00:00
new NUM_SPEC ( tra ( " KB/second " ), 0 , 9999999 , 0 , 1000 , 100 )
2010-04-23 17:46:57 +00:00
),
2014-12-13 01:54:26 +00:00
new PREF_OPT_NUM (
tra ( " Limit upload rate to " ),
2015-02-20 21:47:20 +00:00
tra ( " Limit the upload rate of file transfers. " ),
2010-04-23 17:46:57 +00:00
" max_bytes_sec_up " ,
2015-02-20 21:47:20 +00:00
new NUM_SPEC ( tra ( " KB/second " ), 0 , 9999999 , 0 , 1000 , 100 )
2010-04-23 17:46:57 +00:00
),
2010-04-23 20:29:02 +00:00
new PREF_NUM2 (
2015-02-18 16:29:20 +00:00
tra ( " Limit usage to " ),
2015-02-20 21:47:20 +00:00
tra ( " Example: BOINC should transfer at most 2000 MB of data every 30 days. " ),
2010-04-23 20:29:02 +00:00
" daily_xfer_limit_mb " ,
" daily_xfer_period_days " ,
2015-02-19 07:35:11 +00:00
new NUM_SPEC ( tra ( " MB every " ), 0 , 9999999 , 0 , 1 , 10000 ),
2015-02-13 19:39:03 +00:00
new NUM_SPEC ( tra ( " days " ), 0 , 9999999 , 0 , 1 , 30 )
2010-04-23 20:29:02 +00:00
),
2015-02-20 21:47:20 +00:00
tra ( " When to suspend " ),
2014-12-13 01:54:26 +00:00
new PREF_HOUR_RANGE (
2015-02-18 16:29:20 +00:00
tra ( " Transfer files only between " ),
2015-03-03 18:04:21 +00:00
tra ( " Transfer files only during a particular period each day. " ),
2014-12-13 01:54:26 +00:00
" net_start_hour " , " net_end_hour "
),
2015-02-20 21:47:20 +00:00
tra ( " Other " ),
2010-04-23 17:46:57 +00:00
new PREF_BOOL (
2015-02-18 16:29:20 +00:00
tra ( " Skip data verification for image files " ),
2015-02-19 07:35:11 +00:00
tra ( " Check this only if your Internet provider modifies image files. Skipping verification reduces the security of BOINC. " ),
2010-04-23 17:46:57 +00:00
" dont_verify_images " ,
false
),
2014-12-13 01:54:26 +00:00
new PREF_BOOL (
2015-02-18 16:29:20 +00:00
tra ( " Confirm before connecting to Internet " ),
2015-02-20 21:47:20 +00:00
tra ( " Useful only if you have a modem, ISDN or VPN connection. " ),
2014-12-13 01:54:26 +00:00
" confirm_before_connecting " ,
false
),
new PREF_BOOL (
2015-02-18 16:29:20 +00:00
tra ( " Disconnect when done " ),
2015-02-20 21:47:20 +00:00
tra ( " Useful only if you have a modem, ISDN or VPN connection. " ),
2014-12-13 01:54:26 +00:00
" hangup_if_dialed " ,
false
),
2010-02-15 04:30:25 +00:00
);
2010-04-23 17:46:57 +00:00
2014-12-13 01:54:26 +00:00
define ( " CPU_LIMIT_DESC " , tra ( " Computing " ));
define ( " DISK_LIMIT_DESC " , tra ( " Disk " ));
define ( " MEM_LIMIT_DESC " , tra ( " Memory " ));
define ( " NETWORK_LIMIT_DESC " , tra ( " Network " ));
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 $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 () {
2014-08-06 04:02:59 +00:00
global $config ;
2010-04-23 17:46:57 +00:00
$config = get_config ();
2013-05-04 17:15:04 +00:00
$dp = new StdClass ;
2010-04-23 17:46:57 +00:00
$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
2014-12-13 01:54:26 +00:00
if ( ! $dp -> disk_min_free_gb ) $dp -> disk_min_free_gb = 1 ; // 1 GB
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
}
2014-12-13 01:54:26 +00:00
function group_header ( $t ) {
2014-12-18 19:31:34 +00:00
echo " <tr><th class=subheading> $t </th><td colspan=4><br></td></tr> \n " ;
2014-12-13 01:54:26 +00:00
}
2004-02-02 23:34:39 +00:00
// functions to parse preferences XML into a struct
//
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_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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
global $net_prefs ;
2004-02-02 23:34:39 +00:00
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $p ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-22 23:19:49 +00:00
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 ;
}
}
2014-12-13 01:54:26 +00:00
foreach ( $mem_prefs as $p ) {
if ( $p -> xml_parse ( $parse_result , $name , $text )) {
return ;
}
}
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-23 17:46:57 +00:00
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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
global $net_prefs ;
2010-04-22 23:19:49 +00:00
2013-05-04 05:12:26 +00:00
$p = new StdClass ;
2010-04-22 23:19:49 +00:00
foreach ( $cpu_prefs as $pref ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $pref )) continue ;
2010-04-22 23:19:49 +00:00
$pref -> set_default ( $p );
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $pref ) {
$pref -> set_default ( $p );
}
2014-12-13 01:54:26 +00:00
foreach ( $mem_prefs as $pref ) {
$pref -> set_default ( $p );
}
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $pref ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $pref )) continue ;
2010-04-23 17:46:57 +00:00
$pref -> set_default ( $p );
}
2004-02-02 23:34:39 +00:00
return $p ;
}
// parse prefs from XML to a struct
//
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 ;
}
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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-22 23:19:49 +00:00
$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 );
}
2014-12-13 01:54:26 +00:00
row_top ( MEM_LIMIT_DESC );
foreach ( $mem_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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-23 17:46:57 +00:00
$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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-22 23:19:49 +00:00
$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
}
2014-12-13 01:54:26 +00:00
row1 ( MEM_LIMIT_DESC );
foreach ( $mem_prefs as $p ) {
$p -> show ( $prefs );
}
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-23 17:46:57 +00:00
$p -> show ( $prefs );
2005-06-08 23:55:21 +00:00
}
2004-02-02 23:34:39 +00:00
}
function subset_name ( $subset ) {
2015-03-05 20:45:58 +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 ) {
2015-02-19 04:06:09 +00:00
echo " <h2> " . tra ( " Separate preferences for %1 " , $venue ) . " </h2> " ;
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 {
2015-02-19 04:06:09 +00:00
echo " <p><a href=add_venue.php?venue= $venue &subset= $subset $tokens > " . tra ( " Add separate preferences for %1 " , $venue ) . " </a> " ;
2004-02-02 23:34:39 +00:00
}
}
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 );
2014-12-24 19:32:32 +00:00
echo tra ( " These settings apply to all computers using this account except " )
. " <ul><li> "
. tra ( " computers where you have set preferences locally using the BOINC Manager " )
. " <li> "
. tra ( " Android devices " )
. " </ul>
" ;
2015-02-19 04:06:09 +00:00
$switch_link = " <font size= \" -1 \" ><a href=prefs.php?subset=global&cols= " . ( int ) ! $columns . " > " . tra ( " (Switch view) " ) . " </a></font> " ;
2006-10-24 23:53:59 +00:00
if ( $columns ) {
2015-02-19 04:06:09 +00:00
echo " <h2> " . tra ( " Combined preferences " ) . $switch_link . " </h2> " ;
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 ();
} else {
2013-08-04 22:12:34 +00:00
if ( isset ( $global_prefs -> home ) || isset ( $global_prefs -> work ) || isset ( $global_prefs -> school )) {
2015-02-19 04:06:09 +00:00
echo " <h2> " . tra ( " Primary (default) preferences " ) . $switch_link . " </h2> " ;
2006-10-24 23:53:59 +00:00
}
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 ();
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
}
2014-12-24 19:32:32 +00:00
if ( isset ( $global_prefs -> mod_time )) {
2015-02-19 04:06:09 +00:00
echo " <p> " . tra ( " Preferences last modified: " ) . " " . pretty_time_str ( $global_prefs -> mod_time ) . " <p> \n " ;
2014-12-24 19:32:32 +00:00
}
2004-02-02 23:34:39 +00:00
}
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
}
2014-10-02 19:15:54 +00:00
row2 ( " " , " <input class= \" btn btn-primary \" 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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-22 23:19:49 +00:00
$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 );
}
2014-12-13 01:54:26 +00:00
row1 ( MEM_LIMIT_DESC );
foreach ( $mem_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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) {
group_header ( $p );
continue ;
}
2010-04-23 17:46:57 +00:00
$p -> show_form_row ( $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 ;
}
2015-02-19 18:56:23 +00:00
// TODO: make this a subclass of PREF
//
define ( 'VENUE_DESC' , tra ( 'Default computer location' ));
define ( 'VENUE_TOOLTIP' , tra ( 'New computers will use this location for computing and project preferences.' ));
function tooltip_row2 ( $t , $x , $y ) {
echo " <tr title= \" $t\ " >
< td class = fieldname > $x </ td >
< td > $y </ td >
</ tr >
" ;
}
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 = '---' ;
2015-02-19 18:56:23 +00:00
tooltip_row2 ( VENUE_TOOLTIP , VENUE_DESC , $venue );
2004-02-02 23:34:39 +00:00
}
function venue_form ( $user ) {
2013-07-26 18:23:27 +00:00
$n = $h = $w = $s = $m = '' ;
2007-03-06 18:22:04 +00:00
if ( $user -> venue == '' ) $n = 'selected' ;
if ( $user -> venue == 'home' ) $h = 'selected' ;
if ( $user -> venue == 'work' ) $w = 'selected' ;
if ( $user -> venue == 'school' ) $s = 'selected' ;
2015-02-19 18:56:23 +00:00
tooltip_row2 (
VENUE_TOOLTIP ,
VENUE_DESC ,
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 " ). "
2015-02-19 18:56:23 +00:00
</ select >
" );
2004-02-02 23:34:39 +00:00
}
function venue_parse_form ( & $user ) {
$user -> venue = $_GET [ 'default_venue' ];
}
////////////////////////////////////////////
//
// 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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-22 23:19:49 +00:00
$p -> parse_form ( $prefs , $error );
}
2010-04-23 17:46:57 +00:00
foreach ( $disk_prefs as $p ) {
$p -> parse_form ( $prefs , $error );
}
2014-12-13 01:54:26 +00:00
foreach ( $mem_prefs as $p ) {
$p -> parse_form ( $prefs , $error );
}
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-23 17:46:57 +00:00
$p -> parse_form ( $prefs , $error );
}
2006-08-13 21:51:15 +00:00
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 ;
2014-12-13 01:54:26 +00:00
global $mem_prefs ;
2010-04-23 17:46:57 +00:00
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 ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-22 23:19:49 +00:00
$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
}
2014-12-13 01:54:26 +00:00
foreach ( $mem_prefs as $p ) {
$xml .= $p -> xml_string ( $prefs );
}
2010-04-23 17:46:57 +00:00
foreach ( $net_prefs as $p ) {
2014-12-13 01:54:26 +00:00
if ( is_string ( $p )) continue ;
2010-04-23 17:46:57 +00:00
$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 ;
}
////////////////////////////////////////////
//
// Update user's prefs in database, from a given structure
//
function global_prefs_update ( & $user , $prefs ) {
2013-11-23 06:46:19 +00:00
$prefs_xml = BoincDb :: escape_string ( global_prefs_make_xml ( $prefs ));
$retval = $user -> update ( " global_prefs=' $prefs_xml ' " );
2004-02-02 23:34:39 +00:00
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
}
?>