+ public function sendToAll()
+ {
+ $this->setSent();
+ $query = "SELECT u.user_id, a.alias,
+ u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
+ FIND_IN_SET('femme', u.flags),
+ q.core_mail_fmt AS pref
+ FROM {$this->subscriptionTable()} AS ni
+ INNER JOIN auth_user_md5 AS u USING(user_id)
+ INNER JOIN auth_user_quick AS q ON(q.user_id = u.user_id)
+ INNER 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 ({$this->subscriptionWhere()}) AND e.email IS NOT NULL
+ GROUP BY u.user_id
+ LIMIT 60";
+ while (true) {
+ $res = XDB::iterRow($query);
+ if (!$res->total()) {
+ exit;
+ }
+ $sent = array();
+ while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt) = $res->next()) {
+ $sent[] = "user_id='$uid'";
+ $this->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html');
+ }
+ XDB::execute("UPDATE {$this->subscriptionTable()}
+ SET {$this->subscriptionUpdate()}
+ WHERE " . implode(' OR ', $sent));
+ sleep(60);
+ }
+ }
+
+ abstract protected function assignData(&$smarty);
+ abstract protected function setSent();
+ abstract static public function subscribe($uid = -1);
+ abstract static public function unsubscribe($uid = -1);
+ abstract static public function subscriptionState($uid = -1);
+
+ abstract protected function subscriptionTable();
+ abstract protected function subscriptionWhere();
+ abstract protected function subscriptionUpdate();
+}
+
+// }}}
+// {{{ class NewsLetter
+
+class NewsLetter extends MassMailer
+{
+ public $_date;
+ public $_cats = Array();
+ public $_arts = Array();
+
+ function __construct($id = null)
+ {
+ parent::__construct('newsletter/nl.tpl', 'nl.css', 'nl/show');
+ if (isset($id)) {
+ if ($id == 'last') {
+ $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'");
+ $id = $res->fetchOneCell();
+ }
+ $res = XDB::query("SELECT * FROM newsletter WHERE id={?} OR short_name={?} LIMIT 1", $id, $id);
+ } else {
+ $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
+ if (!$res->numRows()) {
+ Newsletter::create();
+ }
+ $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
+ }
+ $nl = $res->fetchOneAssoc();
+
+ $this->_id = $nl['id'];
+ $this->_shortname = $nl['short_name'];
+ $this->_date = $nl['date'];
+ $this->_title = $nl['titre'];
+ $this->_title_mail = $nl['titre_mail'];
+ $this->_head = $nl['head'];
+
+ $res = XDB::iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos");
+ while (list($cid, $title) = $res->next()) {
+ $this->_cats[$cid] = $title;
+ }