X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Faxletter%2Faxletter.inc.php;h=e238c41e1ed89e199cc54029f3f5c5dc34fc780a;hb=f0b77ba6ee05dd28da60dc8b299fdd4a9fdca8bd;hp=af34cac284c753948daa3a23c93686389f036594;hpb=fc9d9368a4c8781f26a34a8f28523073d645f508;p=platal.git diff --git a/modules/axletter/axletter.inc.php b/modules/axletter/axletter.inc.php index af34cac..e238c41 100644 --- a/modules/axletter/axletter.inc.php +++ b/modules/axletter/axletter.inc.php @@ -1,6 +1,6 @@ _head = ' ,'; if (!is_array($id)) { @@ -45,20 +47,21 @@ class AXLetter extends MassMailer } else { $res = XDB::query("SELECT * FROM axletter - WHERE id = {?} OR shortname = {?}", $id, $id); + WHERE id = {?} OR short_name = {?}", $id, $id); } if (!$res->numRows()) { - $this->_id = null; - return; + throw new MailNotFound(); } $id = $res->fetchOneRow(); } list($this->_id, $this->_shortname, $this->_title_mail, $this->_title, $this->_body, $this->_signature, $this->_promo_min, $this->_promo_max, - $this->_echeance, $this->_date, $this->_bits) = $id; + $this->_subset_to, $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 = (count($this->_subset_to) > 0); } protected function assignData(&$smarty) @@ -99,7 +102,9 @@ class AXLetter extends MassMailer protected function getAllRecipients() { - return "SELECT ni.user_id, IF(ni.user_id = 0, ni.email, a.alias) AS alias, + global $globals; + return "SELECT ni.user_id, IF(ni.user_id = 0, NULL, u.hruid) AS hruid, + IF(ni.user_id = 0, ni.email, CONCAT(a.alias, '@{$globals->mail->domain}')) AS alias, IF(ni.user_id = 0, ni.prenom, u.prenom) AS prenom, IF(ni.user_id = 0, ni.nom, IF(u.nom_usage='', u.nom, u.nom_usage)) AS nom, FIND_IN_SET('femme', IF(ni.user_id = 0, ni.flag, u.flags)) AS sexe, @@ -111,9 +116,9 @@ class AXLetter extends MassMailer LEFT JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) LEFT JOIN emails AS e ON(e.uid=u.user_id AND e.flags='active') WHERE ni.last < {?} AND {$this->subscriptionWhere()} - AND (e.email IS NOT NULL OR ni.user_id = 0) + AND (e.email IS NOT NULL OR FIND_IN_SET('googleapps', u.mail_storage) OR ni.user_id = 0) GROUP BY u.user_id"; - } + } static public function subscriptionState($uid = null) { @@ -122,8 +127,8 @@ class AXLetter extends MassMailer FROM axletter_ins WHERE user_id={?}", $user); return $res->fetchOneCell(); - } - + } + static public function unsubscribe($uid = null, $hash = false) { $user = is_null($uid) ? S::v('uid') : $uid; @@ -151,13 +156,13 @@ class AXLetter extends MassMailer static public function hasPerms() { - if (S::has_perms()) { + if (S::admin()) { return true; } - $res = XDB::query("SELECT 1 + $res = XDB::query("SELECT COUNT(*) FROM axletter_rights WHERE user_id = {?}", S::i('uid')); - return $res->fetchOneCell(); + return ($res->fetchOneCell() > 0); } static public function grantPerms($uid) @@ -177,7 +182,7 @@ class AXLetter extends MassMailer if (!is_numeric($uid)) { $res = XDB::query("SELECT id FROM aliases WHERE alias = {?}", $uid); $uid = $res->fetchOneCell(); - } + } if (!$uid) { return false; } @@ -186,7 +191,7 @@ class AXLetter extends MassMailer protected function subscriptionWhere() { - if (!$this->_promo_min && !$this->_promo_max) { + if (!$this->_promo_min && !$this->_promo_max && !$this->_subset) { return '1'; } $where = array(); @@ -196,6 +201,17 @@ class AXLetter extends MassMailer 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}))"; } + 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)"; + } else { + // No valid email + $where[] = "0"; + } + } return implode(' AND ', $where); } @@ -222,17 +238,17 @@ class AXLetter extends MassMailer } static public function listSent() - { - $res = XDB::query("SELECT IF(shortname IS NULL, id, shortname) as id, date, subject AS titre + { + $res = XDB::query("SELECT IF(short_name IS NULL, id, short_name) as id, date, subject AS titre FROM axletter - WHERE NOT (FIND_IN_SET('new', bits)) + WHERE NOT FIND_IN_SET('new', bits) AND NOT FIND_IN_SET('invalid', bits) ORDER BY date DESC"); return $res->fetchAllAssoc(); } - + static public function listAll() - { - $res = XDB::query("SELECT IF(shortname IS NULL, id, shortname) as id, date, subject AS titre + { + $res = XDB::query("SELECT IF(short_name IS NULL, id, short_name) as id, date, subject AS titre FROM axletter ORDER BY date DESC"); return $res->fetchAllAssoc();