.
// classes for different kinds of global preferences. See prefs.inc
// PREF_BOOL: boolean
// PREF_NUM: a number, possibly constrained to a range
// PREF_NUM2: a pair of numbers (e.g. transfer limit)
// PREF_HOUR_RANGE: a range of hours
require_once("../inc/consent.inc");
$venues = array("home", "school", "work");
function check_venue($x) {
if ($x == "") return;
if ($x == "home") return;
if ($x == "work") return;
if ($x == "school") return;
error_page(tra("bad venue: %1", $x));
}
function check_subset($x) {
if ($x == "global") return;
if ($x == "project") return;
error_page(tra("bad subset: %1", $x));
}
abstract class PREF {
public $desc; // short description
public $tooltip; // longer description, shown as tooltip
public $tag; // the pref's primary XML tag
function __construct($desc, $tooltip, $tag) {
$this->desc = $desc;
$this->tooltip = $tooltip;
$this->tag = $tag;
}
abstract function show_value($prefs);
abstract function show_form($prefs, $error);
abstract function parse_form(&$prefs, &$error);
abstract function xml_string($prefs);
abstract function xml_parse(&$prefs, $name, $text);
abstract function set_default(&$prefs);
function tooltip_tr() {
if ($this->tooltip) {
echo "
tooltip\">";
} else {
echo "
";
}
}
// multi-column display (read only)
//
function show_cols($prefs) {
global $venues;
$this->tooltip_tr();
echo "
";
}
function parse_form(&$user, &$error) {
// This function parses the form AND performs the database update
$tag = $this->tag;
$consent_type_id = $this->consent_type_id;
$formget = array_key_exists($tag, $_GET);
if ($this->invert) $formget = !$formget;
$flag = ($formget ? 1 : 0);
// Check to see if latest consent of this name is already
// given, i.e., consent_flag set to "formget". If not, consent
// to this consent type.
$cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'");
if ( (($cr) and ($cr->consent_flag!=$flag)) or
(!$cr) ) {
$rc = consent_to_a_policy($user, $consent_type_id, $flag, 0, 'Webform', time());
if (!$rc) {
error_page(tra("Database error:").BoincDb::error());
}
}
}
// xml_string should not be used for this class
function xml_string($prefs) {
return "";
}
// xml_parse should not be used for this class
function xml_parse(&$prefs, $name, $text) {
return false;
}
function set_default(&$user) {
$consent_type_id = $this->consent_type_id;
$rc = consent_to_a_policy($user, $consent_type_id, $this->default, 0, 'Webform');
if (!$rc) {
error_page(tra("Database error:").BoincDb::error());
}
}
}
class NUM_SPEC {
public $suffix;
public $min;
public $max;
public $default;
public $default2;
// for optional prefs where the default is zero (ignored)
// this is the value if they check the box
public $scale;
function __construct($suffix, $min, $max, $default, $scale=1, $default2=0) {
$this->suffix = " $suffix";
$this->min = $min;
$this->max = $max;
$this->default = $default;
$this->default2 = $default2;
$this->scale = $scale;
}
function value_str($v) {
$v /= $this->scale;
if ($v < $this->min || $v > $this->max) {
$v = $this->default;
}
if ($v == 0) {
$v = "--- ";
}
$v .= "$this->suffix ";
return $v;
}
function form_str($tag, $v, $had_error, $disabled=false, $id=null) {
if (is_numeric($v)) {
$v /= $this->scale;
if (!$had_error && ($v < $this->min || $v > $this->max)) {
$v = $this->default;
}
}
if ($disabled) $v = "";
$i = $id?"id=\"$id\"":"";
return ' $this->suffix ";
}
function form_convert($in, &$out, &$error) {
$error = false;
if ($in == "") $in = 0;
if (!is_numeric($in)) {
$error = true;
$out = $in;
return;
}
$out = $in*$this->scale;
if ($out < $this->min || $out > $this->max) {
$error = true;
}
}
function get_default() {
if ($this->default) return $this->default;
return $this->default2;
}
}
// a numeric item
//
class PREF_NUM extends PREF {
public $num_spec;
function __construct($desc, $tooltip, $tag, $num_spec) {
$this->num_spec = $num_spec;
parent::__construct($desc, $tooltip, $tag);
}
function show_value($prefs) {
$tag = $this->tag;
echo "
\n";
}
// see if we have any beta apps or app versions
//
function project_has_beta() {
$apps = BoincApp::enum("deprecated=0 and beta>0");
if (count($apps)) return true;
$avs = BoincAppVersion::enum("deprecated=0 and beta>0");
if (count($avs)) return true;
return false;
}
?>