X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter%2Faxletter.inc.php;h=53c7dd3039af3d2b0eeb146f8b3ee25311438374;hb=7b094a73666cee7650946254c82800e25965db41;hp=d13985e9f663d489295028e93055fba2fe86ccc2;hpb=c12cc82e1d97b51e19b294942ea9450a34d929cd;p=platal.git diff --git a/modules/axletter/axletter.inc.php b/modules/axletter/axletter.inc.php index d13985e..53c7dd3 100644 --- a/modules/axletter/axletter.inc.php +++ b/modules/axletter/axletter.inc.php @@ -1,6 +1,6 @@ _id, $this->_shortname, $this->_title_mail, $this->_title, $this->_body, $this->_signature, $this->_promo_min, $this->_promo_max, - $this->_subset_to, $this->_echeance, $this->_date, $this->_bits) = $id; + $this->_subset_to, $this->_subset_rm, $this->_echeance, $this->_date, $this->_bits) = $id; if ($this->_date == '0000-00-00') { $this->_date = 0; } - $this->_subset_to = explode("\n", $this->_subset_to); + $this->_subset_to = ($this->_subset_to ? explode("\n", $this->_subset_to) : null); $this->_subset = (count($this->_subset_to) > 0); } @@ -105,21 +106,21 @@ class AXLetter extends MassMailer $user = is_null($uid) ? S::v('uid') : $uid; $res = XDB::query("SELECT 1 FROM axletter_ins - WHERE user_id={?}", $user); + WHERE uid={?}", $user); return $res->fetchOneCell(); } static public function unsubscribe($uid = null, $hash = false) { $user = is_null($uid) ? S::v('uid') : $uid; - $field = !$hash ? 'user_id' : 'hash'; + $field = !$hash ? 'uid' : 'hash'; if (is_null($uid) && $hash) { return false; } - $res = XDB::query("SELECT * + $res = XDB::query("SELECT uid FROM axletter_ins WHERE $field={?}", $user); - if (!$res->numRows()) { + if ($res->numRows() != 1) { return false; } XDB::execute("DELETE FROM axletter_ins @@ -130,7 +131,7 @@ class AXLetter extends MassMailer static public function subscribe($uid = null) { $user = is_null($uid) ? S::v('uid') : $uid; - XDB::execute("REPLACE INTO axletter_ins (user_id,last) + XDB::execute("REPLACE INTO axletter_ins (uid,last) VALUES ({?}, 0)", $user); } @@ -141,32 +142,32 @@ class AXLetter extends MassMailer } $res = XDB::query("SELECT COUNT(*) FROM axletter_rights - WHERE user_id = {?}", S::i('uid')); + WHERE uid = {?}", S::i('uid')); return ($res->fetchOneCell() > 0); } static public function grantPerms($uid) { if (!is_numeric($uid)) { - $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid); + $res = XDB::query("SELECT uid FROM aliases WHERE alias = {?}", $uid); $uid = $res->fetchOneCell(); } if (!$uid) { return false; } - return XDB::execute("INSERT IGNORE INTO axletter_rights SET user_id = {?}", $uid); + return XDB::execute("INSERT IGNORE INTO axletter_rights SET uid = {?}", $uid); } static public function revokePerms($uid) { if (!is_numeric($uid)) { - $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid); + $res = XDB::query("SELECT uid FROM aliases WHERE alias = {?}", $uid); $uid = $res->fetchOneCell(); } if (!$uid) { return false; } - return XDB::execute("DELETE FROM axletter_rights WHERE user_id = {?}", $uid); + return XDB::execute("DELETE FROM axletter_rights WHERE uid = {?}", $uid); } protected function subscriptionWhere() @@ -174,19 +175,24 @@ class AXLetter extends MassMailer if (!$this->_promo_min && !$this->_promo_max && !$this->_subset) { return '1'; } + /* TODO: refines this filter on promotions by using userfilter. */ $where = array(); if ($this->_promo_min) { - $where[] = "((ni.user_id = 0 AND ni.promo >= {$this->_promo_min}) OR (ni.user_id != 0 AND u.promo >= {$this->_promo_min}))"; + $where[] = "((ni.uid = 0 AND ni.promo >= {$this->_promo_min}) OR (ni.uid != 0 AND pd.promo >= 'X{$this->_promo_min}'))"; } if ($this->_promo_max) { - $where[] = "((ni.user_id = 0 AND ni.promo <= {$this->_promo_max}) OR (ni.user_id != 0 AND u.promo <= {$this->_promo_max}))"; + $where[] = "((ni.uid = 0 AND ni.promo <= {$this->_promo_max}) OR (ni.uid != 0 AND pd.promo <= 'X{$this->_promo_max}'))"; } if ($this->_subset) { require_once("emails.inc.php"); $ids = ids_from_mails($this->_subset_to); $ids_list = implode(',', $ids); - if(count($ids_list) > 0) { - $where[] = "ni.user_id IN ($ids_list)"; + if(count($ids) > 0) { + if ($this->_subset_rm) { + $where[] = "ni.uid NOT IN ($ids_list)"; + } else { + $where[] = "ni.uid IN ($ids_list)"; + } } else { // No valid email $where[] = "0";