web: updated preferences for stats exports to use new consent table definitions.

This commit is contained in:
Shawn Kwang 2018-05-24 12:03:35 -05:00
parent 2d4f9e4236
commit b0557ef161
3 changed files with 45 additions and 43 deletions

View File

@ -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
),
);

View File

@ -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 "<td class=\"text-right \">$this->desc</td>";
$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 "<td class=\"text-right \">$this->desc</td>";
$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 "<td>" . readonly_checkbox($value) . "</td>";
}
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());
}
}

View File

@ -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 "<h2>Consent Type $cid deleted (dry-run).</h2>";
if ($consent_type) {
$myname = $consent_type->shortname;
$consent_type->delete_aux("consent_id = $cid");
echo "<h2>Consent Type ${myname} deleted.</h2>";
}
}
// 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.</font></p>");
}
if (empty($description)) {
admin_error_page("The new consent type must contain a description.</font></p>");
}
BoincConsentType::insert(
"(description) VALUES ('$description')"
"(shortname, description) VALUES ('$shortname', '$description')"
);
echo "<h2>Consent Type added.</h2>";
}
function mct_show_form() {
$_consenttypes = BoincConsentType::enum("");
$_consenttypes = BoincConsentType::enum(null, "ORDER BY protected DESC");
if (!in_rops()) {
echo "<b>You may not delete the first record (id=1) of the consent_type table.</b>";
echo "<b>'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.)</b>";
}
start_table("");
table_header(
"ID",
"Name",
"Description",
"Protected",
""
);
$rowi=1;
foreach ($_consenttypes as $ct) {
echo "<tr class=row$rowi><form action=manage_consent_types.php method=POST>\n";
echo "<tr><form action=manage_consent_types.php method=POST>\n";
echo "<input type=hidden name=consent_id value=$ct->consent_id>";
echo " <td>$ct->consent_id</td>";
echo " <td>$ct->shortname</td>";
echo " <td>$ct->description</td>";
if (!in_rops() and ($rowi!=1)) {
echo " <td>$ct->protected</td>";
if (!in_rops() and !($ct->protected)) {
echo "<td><input class=\"btn btn-default\" name=delete type=submit value=Delete>";
} else {
echo "<td>&nbsp;</td>";
}
echo "</form></tr>";
$rowi+=1;
}
end_table();
@ -89,11 +97,11 @@ function mct_show_form() {
start_table("align='center' ");
table_header("id", "Description", "&nbsp;");
table_header("Name", "Description", "&nbsp;");
echo "<TR>
<TD>(auto-incremented)</TD>
<TD> <input type='text' size='35' name='add_description' value=''></TD>
<TD> <input type='text' size='10' name='add_name' value=''> </TD>
<TD> <input type='text' size='35' name='add_description' value=''> </TD>
<TD align='center' >
<input type='submit' name='add_consenttype' value='Add Consent Type'></TD>
</TR>\n";