diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 82439329aa..b614a63ed4 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -945,6 +945,20 @@ class BoincConsentType { } +// Class to interface with SQL View latest_consent. Only read +// operations permitted. +class BoincLatestConsent { + static function lookup($clause) { + $db = BoincDb::get(); + return $db->lookup('latest_consent', 'BoincLatestConsent', $clause); + } + + static function enum($where_clause, $order_clause=null) { + $db = BoincDb::get(); + return $db->enum('latest_consent', 'BoincLatestConsent', $where_clause, $order_clause); + } +} + // DEPRECATED: use BoincDb::escape_string where possible // // apply this to any user-supplied strings used in queries diff --git a/html/inc/consent.inc b/html/inc/consent.inc index 59dcbf5922..1f939cd721 100644 --- a/html/inc/consent.inc +++ b/html/inc/consent.inc @@ -40,7 +40,7 @@ function consent_to_a_policy($user, $consent_type_id, $consent_flag, $consent_no function check_user_consent($user, $consent_name) { list($checkct, $ctid) = check_consent_type($consent_name); if ($checkct) { - $consent_result = BoincConsent::lookup("userid={$user->id} AND consent_type_id=$ctid ORDER BY consent_time DESC LIMIT 1"); + $consent_result = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id=$ctid"); if ( ($consent_result) and ($consent_result->consent_flag) ) { return TRUE; } diff --git a/html/inc/prefs_util.inc b/html/inc/prefs_util.inc index 8d5ac14b95..bd8fcf2a91 100644 --- a/html/inc/prefs_util.inc +++ b/html/inc/prefs_util.inc @@ -192,7 +192,7 @@ class PREF_CONSENT extends PREF { $this->tooltip_tr(); echo "$this->desc"; $consent_type_id = $this->consent_type_id; - $cr = BoincConsent::lookup("userid={$user->id} AND consent_type_id='{$consent_type_id} ORDER BY consent_time DESC LIMIT 1"); + $cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'"); if ($cr) { $this->show_value($user); } else { @@ -207,7 +207,7 @@ class PREF_CONSENT extends PREF { $this->tooltip_tr(); echo "$this->desc"; $consent_type_id = $this->consent_type_id; - $cr = BoincConsent::lookup("userid={$user->id} AND consent_type_id='{$consent_type_id}' ORDER BY consent_time DESC LIMIT 1"); + $cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'"); if ($cr) { $this->show_value($user); } else { @@ -225,7 +225,7 @@ class PREF_CONSENT extends PREF { function show_value($user) { $consent_type_id = $this->consent_type_id; - $cr = BoincConsent::lookup("userid={$user->id} AND consent_type_id='{$consent_type_id}' ORDER BY consent_time DESC LIMIT 1"); + $cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'"); if ($cr) { $value = $cr->consent_flag; } else { @@ -235,7 +235,7 @@ class PREF_CONSENT extends PREF { } function show_form($user, $error) { $consent_type_id = $this->consent_type_id; - $cr = BoincConsent::lookup("userid={$user->id} AND consent_type_id='{$consent_type_id}' ORDER BY consent_time DESC LIMIT 1"); + $cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'"); if ($cr) { if ($this->invert) { $checked = !$cr->consent_flag; @@ -262,7 +262,7 @@ class PREF_CONSENT extends PREF { // 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= BoincConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}' ORDER BY consent_time DESC LIMIT 1"); + $cr = BoincLatestConsent::lookup("userid={$user->id} AND consent_type_id='${consent_type_id}'"); if ( (($cr) and ($cr->consent_flag!=$flag)) or (!$cr) ) {