X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnewsletter.inc.php;h=f9146157dd8e9df8e899a4bad0435f98545a09c5;hb=28c20b86be8b40cecba0d83080879f81c49e07ad;hp=236026c7b643a9389d9bc81b19555717a0df1ae8;hpb=ed76a506a12cf15a03232d142d5bfd0c2c882b92;p=platal.git diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 236026c..f914615 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -1,6 +1,6 @@ addCssLink('nl.css'); -} - -define('FEMME', 1); -define('HOMME', 0); - -// }}} // {{{ class NewsLetter -class NewsLetter +class NewsLetter extends MassMailer { - // {{{ properties - - var $_id; - var $_shortname; - var $_date; - var $_title; - var $_head; - var $_cats = Array(); - var $_arts = Array(); + public $_date; + public $_cats = array(); + public $_arts = array(); - // }}} - // {{{ constructor - - function NewsLetter($id=null) + function __construct($id = null) { + parent::__construct('newsletter/nl.mail.tpl', 'nl.css', 'nl/show', 'newsletter', 'newsletter_ins'); if (isset($id)) { if ($id == 'last') { $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'"); @@ -59,23 +41,27 @@ class NewsLetter } else { $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'"); if (!$res->numRows()) { - insert_new_nl(); + NewsLetter::create(); } - $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'"); + $res = XDB::query("SELECT * FROM newsletter WHERE bits='new' ORDER BY id DESC LIMIT 1"); + } + if ($res->numRows() != 1) { + throw new MailNotFound(); } $nl = $res->fetchOneAssoc(); - $this->_id = $nl['id']; - $this->_shortname = $nl['short_name']; - $this->_date = $nl['date']; - $this->_title = $nl['titre']; - $this->_head = $nl['head']; + $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; } - + $res = XDB::iterRow( "SELECT a.title,a.body,a.append,a.aid,a.cid,a.pos FROM newsletter_art AS a @@ -88,265 +74,110 @@ class NewsLetter } } - // }}} - // {{{ function setSent() - - function setSent() + public function save() { - XDB::execute("UPDATE newsletter SET bits='sent' WHERE id={?}", $this->_id); + XDB::execute('UPDATE newsletter SET date={?},titre={?},titre_mail={?},head={?},short_name={?} WHERE id={?}', + $this->_date, $this->_title, $this->_title_mail, $this->_head, $this->_shortname,$this->_id); } - // }}} - // {{{ function save() - - function save() + public function getArt($aid) { - XDB::execute('UPDATE newsletter SET date={?},titre={?},head={?},short_name={?} WHERE id={?}', - $this->_date, $this->_title, $this->_head, $this->_shortname,$this->_id); + foreach ($this->_arts as $key=>$artlist) { + if (isset($artlist["a$aid"])) { + return $artlist["a$aid"]; + } + } + return null; } - // }}} - // {{{ function id() - - function id() + public function saveArticle(&$a) { - return is_null($this->_shortname) ? $this->_id : $this->_shortname; + if ($a->_aid >= 0) { + XDB::execute('REPLACE INTO newsletter_art (id, aid, cid, pos, title, body, append) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', + $this->_id, $a->_aid, $a->_cid, $a->_pos, + $a->_title, $a->_body, $a->_append); + $this->_arts['a' . $a->_aid] = $a; + } else { + XDB::execute('INSERT INTO newsletter_art + SELECT {?}, MAX(aid)+1, {?}, ' + . ($a->_pos ? intval($a->_pos) : 'MAX(pos)+1') + . ', {?}, {?}, {?} + FROM newsletter_art AS a + WHERE a.id = {?}', + $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id); + $this->_arts['a' . $a->_aid] = $a; + } } - // }}} - // {{{ function title() - - function title() - { return $this->_title; } - - // }}} - // {{{ function head() - - function head() - { return $this->_head; } - - // }}} - // {{{ function getArt() - - function getArt($aid) + public function delArticle($aid) { - foreach ($this->_arts as $key=>$artlist) { - if (isset($artlist["a$aid"])) { - return $artlist["a$aid"]; - } - } - return null; + XDB::execute('DELETE FROM newsletter_art WHERE id={?} AND aid={?}', $this->_id, $aid); + foreach ($this->_arts as $key=>$art) { + unset($this->_arts[$key]["a$aid"]); + } } - // }}} - // {{{ function saveArticle() - - function saveArticle(&$a) + protected function assignData(&$smarty) { - if ($a->_aid>=0) { - XDB::execute('REPLACE INTO newsletter_art (id,aid,cid,pos,title,body,append) - VALUES ({?},{?},{?},{?},{?},{?},{?})', - $this->_id, $a->_aid, $a->_cid, $a->_pos, - $a->_title, $a->_body, $a->_append); - $this->_arts['a'.$a->_aid] = $a; - } else { - XDB::execute( - 'INSERT INTO newsletter_art - SELECT {?},MAX(aid)+1,{?},'.($a->_pos ? intval($a->_pos) : 'MAX(pos)+1').',{?},{?},{?} - FROM newsletter_art AS a - WHERE a.id={?}', - $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id); - $this->_arts['a'.$a->_aid] = $a; - } + $smarty->assign_by_ref('nl', $this); } - // }}} - // {{{ function delArticle() - - function delArticle($aid) + protected function setSent() { - XDB::execute('DELETE FROM newsletter_art WHERE id={?} AND aid={?}', $this->_id, $aid); - foreach ($this->_arts as $key=>$art) { - unset($this->_arts[$key]["a$aid"]); - } + XDB::execute("UPDATE newsletter SET bits='sent' WHERE id={?}", $this->_id); } - // }}} - // {{{ function footer - - function footer($html) + static public function subscriptionState($uid = null) { - global $globals; - $url = 'https://www.polytechnique.org'; - - if ($html) { - return '