From b0557ef1610911ea15f3befa80c9a6541b0e83a6 Mon Sep 17 00:00:00 2001 From: Shawn Kwang Date: Thu, 24 May 2018 12:03:35 -0500 Subject: [PATCH] web: updated preferences for stats exports to use new consent table definitions. --- html/inc/prefs_project.inc | 2 +- html/inc/prefs_util.inc | 50 ++++++++++++++----------------- html/ops/manage_consent_types.php | 36 +++++++++++++--------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/html/inc/prefs_project.inc b/html/inc/prefs_project.inc index 8f30c36c8a..b3bcf991c5 100644 --- a/html/inc/prefs_project.inc +++ b/html/inc/prefs_project.inc @@ -142,7 +142,7 @@ $privacy_consent_descs = array( tra("Do you consent to %1 exporting your data?", PROJECT), tra("Data is exported to BOINC statistics aggregation Web sites."), "consent_data_export", - 2, + "STATSEXPORT", 0 ), ); diff --git a/html/inc/prefs_util.inc b/html/inc/prefs_util.inc index b883d0d3ae..fbe8fb30a1 100644 --- a/html/inc/prefs_util.inc +++ b/html/inc/prefs_util.inc @@ -23,6 +23,8 @@ // 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) { @@ -170,12 +172,12 @@ class PREF_BOOL extends PREF { } class PREF_CONSENT extends PREF { - public $consent_id; // the consent_id to configure + public $consent_name; // the consent_name to configure public $default; public $invert; // show to user in opposite sense - function __construct($desc, $tooltip, $tag, $consent_id, $default, $invert=false) { - $this->consent_id = $consent_id; + function __construct($desc, $tooltip, $tag, $consent_name, $default, $invert=false) { + $this->consent_name = $consent_name; $this->default = $default; $this->invert = $invert; parent::__construct($desc, $tooltip, $tag); @@ -187,8 +189,8 @@ class PREF_CONSENT extends PREF { global $venues; $this->tooltip_tr(); echo "$this->desc"; - $consent_id = $this->consent_id; - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); + $consent_name = $this->consent_name; + $cr = BoincConsent::lookup("userid={$user->id} AND consent_name='{$consent_name} ORDER BY consent_time DESC LIMIT 1"); if ($cr) { $this->show_value($user); } else { @@ -202,8 +204,8 @@ class PREF_CONSENT extends PREF { function consent_show($user) { $this->tooltip_tr(); echo "$this->desc"; - $consent_id = $this->consent_id; - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); + $consent_name = $this->consent_name; + $cr = BoincConsent::lookup("userid={$user->id} AND consent_name='{$consent_name}' ORDER BY consent_time DESC LIMIT 1"); if ($cr) { $this->show_value($user); } else { @@ -220,8 +222,8 @@ class PREF_CONSENT extends PREF { } function show_value($user) { - $consent_id = $this->consent_id; - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); + $consent_name = $this->consent_name; + $cr = BoincConsent::lookup("userid={$user->id} AND consent_name='{$consent_name}' ORDER BY consent_time DESC LIMIT 1"); if ($cr) { $value = $cr->consent_flag; } else { @@ -230,8 +232,8 @@ class PREF_CONSENT extends PREF { echo "" . readonly_checkbox($value) . ""; } function show_form($user, $error) { - $consent_id = $this->consent_id; - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); + $consent_name = $this->consent_name; + $cr = BoincConsent::lookup("userid={$user->id} AND consent_name='{$consent_name}' ORDER BY consent_time DESC LIMIT 1"); if ($cr) { if ($this->invert) { $checked = !$cr->consent_flag; @@ -250,22 +252,14 @@ class PREF_CONSENT extends PREF { function parse_form(&$user, &$error) { // This function parses the form AND performs the database update $tag = $this->tag; - $consent_id = $this->consent_id; + $consent_name = $this->consent_name; $formget = array_key_exists($tag, $_GET); if ($this->invert) $formget = !$formget; $flag = ($formget ? 1 : 0); - // if record exists modify it, otherwise create - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); - if ($cr) { - $cquery = "consent_flag=$flag WHERE userid = $user->id AND consent_id=$consent_id"; - $cr->update($cquery); - } else { - $mytime = time(); - BoincConsent::insert( - "(userid, consent_id, consent_time, consent_flag, consent_not_required, source) " . - "values($user->id, $consent_id, $mytime, $flag, 0, 'Webform')" - ); + $rc = consent_to_a_policy($user, $consent_name, $flag, 0, 'Webform', time()); + if (!$rc) { + error_page(tra("Database error:").BoincDb::error()); } } // xml_string should not be used for this class @@ -277,11 +271,11 @@ class PREF_CONSENT extends PREF { return false; } function set_default(&$user) { - $consent_id = $this->consent_id; - $cr = BoincConsent::lookup("userid=$user->id AND consent_id=$consent_id"); - if ($cr) { - $cquery = "consent_id=$consent_id, consent_flag=$this->default WHERE userid = $user->id AND consent_id=$consent_id"; - $cr->update($cquery); + $consent_name = $this->consent_name; + + $rc = consent_to_a_policy($user, $consent_name, $this->default, 0, 'Webform'); + if (!$rc) { + error_page(tra("Database error:").BoincDb::error()); } } diff --git a/html/ops/manage_consent_types.php b/html/ops/manage_consent_types.php index 260fa77ed3..4f889fb49d 100644 --- a/html/ops/manage_consent_types.php +++ b/html/ops/manage_consent_types.php @@ -24,55 +24,63 @@ require_once('../inc/util_ops.inc'); function mct_update() { $cid = post_int("consent_id"); $consent_type = BoincConsentType::lookup("consent_id = $cid"); - $consent_type->delete_aux("consent_id = $cid"); - echo "

Consent Type $cid deleted (dry-run).

"; + if ($consent_type) { + $myname = $consent_type->shortname; + $consent_type->delete_aux("consent_id = $cid"); + echo "

Consent Type ${myname} deleted.

"; + } } // This function adds a row to consent_type table. function add_consenttype() { + $shortname = BoincDb::escape_string(post_str('add_name')); $description = BoincDb::escape_string(post_str('add_description')); + if (empty($shortname)) { + admin_error_page("The new consent type must contain a short name.

"); + } if (empty($description)) { admin_error_page("The new consent type must contain a description.

"); } BoincConsentType::insert( - "(description) VALUES ('$description')" + "(shortname, description) VALUES ('$shortname', '$description')" ); echo "

Consent Type added.

"; } function mct_show_form() { - $_consenttypes = BoincConsentType::enum(""); + $_consenttypes = BoincConsentType::enum(null, "ORDER BY protected DESC"); if (!in_rops()) { - echo "You may not delete the first record (id=1) of the consent_type table."; + echo "'Protected' consent types are defined by BOINC. You may add project-specific consent types using this form. (Unprotected consent types are defined here by this project.)"; } start_table(""); table_header( - "ID", + "Name", "Description", + "Protected", "" ); - $rowi=1; foreach ($_consenttypes as $ct) { - echo "
\n"; + echo "\n"; echo "consent_id>"; - echo " $ct->consent_id"; + echo " $ct->shortname"; echo " $ct->description"; - if (!in_rops() and ($rowi!=1)) { + echo " $ct->protected"; + + if (!in_rops() and !($ct->protected)) { echo ""; } else { echo " "; } echo "
"; - $rowi+=1; } end_table(); @@ -89,11 +97,11 @@ function mct_show_form() { start_table("align='center' "); - table_header("id", "Description", " "); + table_header("Name", "Description", " "); echo " - (auto-incremented) - + + \n";