2004-02-04 01:21:51 +00:00
|
|
|
<?php
|
2007-12-21 23:39:25 +00:00
|
|
|
|
2007-12-24 21:34:21 +00:00
|
|
|
// Sample code for project-specific preferences.
|
|
|
|
// These prefs may include:
|
|
|
|
//
|
|
|
|
// - preferences for your application graphics
|
2008-12-18 21:25:51 +00:00
|
|
|
// - application selection
|
|
|
|
// (i.e. if you have multiple apps, let user choose among them)
|
2008-08-12 22:09:28 +00:00
|
|
|
//
|
|
|
|
// Edit this file accordingly,
|
|
|
|
// and put your version in html/project_specific/project_specific_prefs.inc
|
|
|
|
|
|
|
|
// Select standard prefs here:
|
|
|
|
|
|
|
|
define ('COLOR_PREFS', false);
|
|
|
|
define ('GFX_CPU_PREFS', true);
|
2010-04-27 17:54:29 +00:00
|
|
|
define ('APP_SELECT_PREFS', true);
|
2008-08-12 22:09:28 +00:00
|
|
|
$project_has_beta = false;
|
2007-12-24 21:34:21 +00:00
|
|
|
|
2008-08-12 22:09:28 +00:00
|
|
|
// Project-specific prefs are represented in three ways:
|
2007-12-24 21:34:21 +00:00
|
|
|
// - as an XML document (stored in the DB in this form)
|
|
|
|
// - as a PHP structure
|
|
|
|
// - as a set of HTTP GET form variables
|
2004-02-04 01:21:51 +00:00
|
|
|
|
2007-12-24 21:34:21 +00:00
|
|
|
// This file exports the following functions
|
|
|
|
// (called from html/inc/prefs.inc):
|
|
|
|
//
|
|
|
|
// project_specific_prefs_default()
|
|
|
|
// Returns XML for default preferences
|
|
|
|
// project_specific_prefs_parse($xml)
|
|
|
|
// Parse prefs as XML, return prefs as PHP structure
|
|
|
|
// project_specific_prefs_show($prefs, $columns=false)
|
|
|
|
// Show prefs as HTML (non-editable)
|
|
|
|
// project_specific_prefs_edit($prefs, $error)
|
|
|
|
// Show prefs as HTML, editable.
|
|
|
|
// $error is a struct indicating which values were erroneous
|
|
|
|
// (value X is erroneous if $error->X is set)
|
|
|
|
// project_specific_prefs_parse_form(&$error)
|
|
|
|
// Parse form variables into XML, and return it.
|
|
|
|
// Also error-check values, and return errors in $errors->*
|
2004-02-04 01:21:51 +00:00
|
|
|
|
|
|
|
function option($name, $val) {
|
2007-12-24 21:34:21 +00:00
|
|
|
$x = ($name == $val) ? "selected" : "";
|
|
|
|
return "<option name='$name' $x>$name\n";
|
|
|
|
}
|
|
|
|
|
2010-02-16 01:06:03 +00:00
|
|
|
define('COLOR_DESC', tra('Color scheme for graphics'));
|
|
|
|
define("MAX_GFX_CPU_PCT_DESC", tra("Maximum CPU % for graphics%10 ... 100%2", "<br><span class=note>", "</span>"));
|
|
|
|
define('APP_SELECT_DESC', tra('Run only the selected applications'));
|
|
|
|
define('ACCEPT_ANY_DESC', tra('If no work for selected applications is available, accept work from other applications?'));
|
2007-12-24 21:34:21 +00:00
|
|
|
|
2011-11-09 07:41:49 +00:00
|
|
|
// stuff related to app filtering.
|
2007-12-24 21:34:21 +00:00
|
|
|
// Note: in this implementation, if a user selects all apps,
|
|
|
|
// no <app_id> elements are included in their prefs,
|
|
|
|
// which means that if the project adds a new app such users will run it also.
|
|
|
|
//
|
2008-08-12 22:09:28 +00:00
|
|
|
if (APP_SELECT_PREFS) {
|
2011-11-03 19:19:36 +00:00
|
|
|
$app_array = array();
|
|
|
|
$apps = BoincApp::enum("deprecated=0");
|
|
|
|
foreach($apps as $app) {
|
|
|
|
$app_array[] = array($app->id, $app->user_friendly_name);
|
|
|
|
}
|
2007-12-24 21:34:21 +00:00
|
|
|
} else {
|
|
|
|
$app_array = null;
|
|
|
|
}
|
|
|
|
|
2012-05-18 17:48:50 +00:00
|
|
|
// see if we have any beta apps
|
|
|
|
//
|
|
|
|
$apps = BoincApp::enum("deprecated=0");
|
|
|
|
foreach($apps as $app) {
|
|
|
|
if ($app->beta) {
|
|
|
|
$project_has_beta = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-24 21:34:21 +00:00
|
|
|
function selected_app_text($prefs) {
|
|
|
|
global $app_array;
|
|
|
|
if (isset($prefs->app_ids)) {
|
2004-02-04 01:21:51 +00:00
|
|
|
$x = "";
|
2007-12-24 21:34:21 +00:00
|
|
|
foreach ($app_array as $app) {
|
|
|
|
$app_id = $app[0];
|
|
|
|
$app_name = $app[1];
|
|
|
|
if (in_array($app_id, $prefs->app_ids)) {
|
2010-02-16 01:06:03 +00:00
|
|
|
$x .= "$app_name: ".tra("yes")."<br>";
|
2007-12-24 21:34:21 +00:00
|
|
|
} else {
|
2010-02-16 01:06:03 +00:00
|
|
|
$x .= "$app_name: ".tra("no")."<br>";
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-02-16 01:06:03 +00:00
|
|
|
$x = tra("(all applications)");
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
2007-12-24 21:34:21 +00:00
|
|
|
return $x;
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function project_specific_prefs_default() {
|
2008-08-12 22:09:28 +00:00
|
|
|
$x = "";
|
|
|
|
if (COLOR_PREFS) {
|
|
|
|
$x .= "<color_scheme>Tahiti Sunset</color_scheme>\n";
|
|
|
|
}
|
|
|
|
if (GFX_CPU_PREFS) {
|
|
|
|
$x .= "<max_gfx_cpu_pct>20</max_gfx_cpu_pct>\n";
|
|
|
|
}
|
|
|
|
return $x;
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
function project_specific_prefs_edit($prefs, $error=false) {
|
2007-12-24 21:34:21 +00:00
|
|
|
global $app_array;
|
2008-08-12 22:09:28 +00:00
|
|
|
if (COLOR_PREFS) {
|
|
|
|
$x = $prefs->color_scheme;
|
|
|
|
$y = "<select name=color_scheme>
|
|
|
|
".option("Tahiti Sunset", $x)
|
|
|
|
.option("Desert Sands", $x)."
|
|
|
|
</select>
|
|
|
|
";
|
|
|
|
row2(COLOR_DESC, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GFX_CPU_PREFS) {
|
|
|
|
$y = "<input size=5 name=max_gfx_cpu_pct value='$prefs->max_gfx_cpu_pct'>";
|
|
|
|
row2(MAX_GFX_CPU_PCT_DESC, $y, isset($error->max_gfx_cpu_pct));
|
|
|
|
}
|
|
|
|
if (APP_SELECT_PREFS) {
|
2007-12-24 21:34:21 +00:00
|
|
|
$x = "";
|
|
|
|
foreach ($app_array as $app) {
|
|
|
|
$app_id = $app[0];
|
|
|
|
$app_name = $app[1];
|
|
|
|
if (isset($prefs->app_ids)) {
|
|
|
|
$present = in_array($app_id, $prefs->app_ids);
|
|
|
|
} else {
|
|
|
|
$present = true;
|
|
|
|
}
|
|
|
|
$checked = $present?"checked":"";
|
|
|
|
$x .= "<input type=checkbox name=app_id_$app_id $checked> $app_name<br>";
|
|
|
|
}
|
|
|
|
row2(APP_SELECT_DESC, $x);
|
2008-08-12 22:09:28 +00:00
|
|
|
$checked = $prefs->allow_non_preferred_apps?"checked":"";
|
|
|
|
row2(ACCEPT_ANY_DESC, "<input type=checkbox name=allow_non_preferred_apps $checked>");
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
function project_specific_prefs_parse_form(&$error) {
|
2007-12-24 21:34:21 +00:00
|
|
|
global $app_array;
|
2008-08-12 22:09:28 +00:00
|
|
|
$x = "";
|
|
|
|
if (COLOR_PREFS) {
|
2010-09-04 22:13:27 +00:00
|
|
|
$color_scheme = sanitize_tags($_GET["color_scheme"]);
|
2008-08-12 22:09:28 +00:00
|
|
|
$x .= "<color_scheme>$color_scheme</color_scheme>\n";
|
|
|
|
}
|
|
|
|
if (GFX_CPU_PREFS) {
|
2010-09-04 22:13:27 +00:00
|
|
|
$max_gfx_cpu_pct = sanitize_numeric($_GET["max_gfx_cpu_pct"]);
|
2008-08-12 22:09:28 +00:00
|
|
|
if (!verify_numeric($max_gfx_cpu_pct, 0, 100)) $error->max_gfx_cpu_pct = true;
|
|
|
|
$x .= "<max_gfx_cpu_pct>$max_gfx_cpu_pct</max_gfx_cpu_pct>\n";
|
|
|
|
}
|
2007-12-24 21:34:21 +00:00
|
|
|
|
2008-08-12 22:09:28 +00:00
|
|
|
if (APP_SELECT_PREFS) {
|
2011-11-09 07:41:49 +00:00
|
|
|
$y = "<apps_selected>\n";
|
2007-12-24 21:34:21 +00:00
|
|
|
$some_unchecked = false;
|
|
|
|
foreach ($app_array as $app) {
|
|
|
|
$app_id = $app[0];
|
|
|
|
$present = isset($_GET["app_id_$app_id"]);
|
|
|
|
if ($present) {
|
2008-11-24 20:27:18 +00:00
|
|
|
$y .= "<app_id>$app_id</app_id>\n";
|
2007-12-24 21:34:21 +00:00
|
|
|
} else {
|
|
|
|
$some_unchecked = true;
|
|
|
|
}
|
|
|
|
}
|
2011-11-09 07:41:49 +00:00
|
|
|
$y .= "</apps_selected>\n";
|
|
|
|
|
2007-12-24 21:34:21 +00:00
|
|
|
if ($some_unchecked) {
|
|
|
|
$x .= $y;
|
|
|
|
}
|
2008-08-12 22:09:28 +00:00
|
|
|
if (isset($_GET["allow_non_preferred_apps"])) {
|
|
|
|
$x .= "<allow_non_preferred_apps>1</allow_non_preferred_apps>\n";
|
|
|
|
}
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $x;
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2006-08-13 21:51:15 +00:00
|
|
|
function project_specific_prefs_show($prefs, $columns=false) {
|
2007-12-24 21:34:21 +00:00
|
|
|
global $app_array;
|
2006-08-13 21:51:15 +00:00
|
|
|
if ($columns) {
|
2008-08-12 22:09:28 +00:00
|
|
|
if (COLOR_PREFS) {
|
|
|
|
row_defs(COLOR_DESC,"color_scheme", "", "", $prefs);
|
|
|
|
}
|
|
|
|
if (GFX_CPU_PREFS) {
|
|
|
|
row_defs(MAX_GFX_CPU_PCT_DESC, "max_gfx_cpu_pct", "", "", $prefs);
|
|
|
|
}
|
|
|
|
if (APP_SELECT_PREFS) {
|
2007-12-24 21:34:21 +00:00
|
|
|
$prefs->app_id_text = selected_app_text($prefs);
|
|
|
|
if ($prefs->home) $prefs->home->app_id_text = selected_app_text($prefs->home);
|
|
|
|
if ($prefs->school) $prefs->school->app_id_text = selected_app_text($prefs->school);
|
|
|
|
if ($prefs->work) $prefs->work->app_id_text = selected_app_text($prefs->work);
|
|
|
|
row_defs(APP_SELECT_DESC, "app_id_text", "", "", $prefs);
|
2008-08-12 22:09:28 +00:00
|
|
|
row_defs(ACCEPT_ANY_DESC, "allow_non_preferred_apps_text", "", "", $prefs);
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
2004-02-04 01:21:51 +00:00
|
|
|
} else {
|
2008-08-12 22:09:28 +00:00
|
|
|
if (COLOR_PREFS) {
|
|
|
|
row2(COLOR_DESC, $prefs->color_scheme);
|
|
|
|
}
|
|
|
|
if (GFX_CPU_PREFS) {
|
|
|
|
row2(MAX_GFX_CPU_PCT_DESC, $prefs->max_gfx_cpu_pct);
|
|
|
|
}
|
|
|
|
if (APP_SELECT_PREFS) {
|
2007-12-24 21:34:21 +00:00
|
|
|
row2(APP_SELECT_DESC, selected_app_text($prefs));
|
2008-08-12 22:09:28 +00:00
|
|
|
row2(ACCEPT_ANY_DESC, $prefs->allow_non_preferred_apps_text);
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
2004-02-04 01:21:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function project_specific_prefs_parse($prefs_xml) {
|
2013-05-04 17:15:04 +00:00
|
|
|
$prefs = new StdClass;
|
2008-08-12 22:09:28 +00:00
|
|
|
if (COLOR_PREFS) {
|
|
|
|
$prefs->color_scheme = parse_element($prefs_xml, "<color_scheme>");
|
|
|
|
}
|
|
|
|
if (GFX_CPU_PREFS) {
|
|
|
|
$prefs->max_gfx_cpu_pct = parse_element($prefs_xml, "<max_gfx_cpu_pct>");
|
|
|
|
}
|
|
|
|
if (APP_SELECT_PREFS) {
|
|
|
|
$cursor = 0;
|
|
|
|
while ($thisxml = parse_next_element($prefs_xml, "<app_id>", $cursor)) {
|
|
|
|
if (is_numeric($thisxml)) {
|
|
|
|
$n = (int) $thisxml;
|
|
|
|
$prefs->app_ids[] = $n;
|
|
|
|
}
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
2008-08-12 22:09:28 +00:00
|
|
|
$prefs->allow_non_preferred_apps = parse_element($prefs_xml, "<allow_non_preferred_apps>");
|
|
|
|
$prefs->allow_non_preferred_apps_text = $prefs->allow_non_preferred_apps?"yes":"no";
|
2007-12-24 21:34:21 +00:00
|
|
|
}
|
2004-02-04 01:21:51 +00:00
|
|
|
return $prefs;
|
|
|
|
}
|
2007-12-21 23:39:25 +00:00
|
|
|
|
|
|
|
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
|
|
|
|
|
|
|
|
?>
|