From b0557ef1610911ea15f3befa80c9a6541b0e83a6 Mon Sep 17 00:00:00 2001
From: Shawn Kwang $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.