X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnewsletter.inc.php;h=426bc2729a8497fe81964d0bc9ed6e30d44cabfa;hb=0d602b8f5fe4fc8cd42dc61a442d14f32bb19056;hp=63e0b2e53d5da461e25f4968fb8bf28c6b5bbb58;hpb=0337d704b62718d7c77106c0e4c4e26fb02beacf;p=platal.git diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 63e0b2e..426bc27 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -1,6 +1,6 @@ addCssLink('css/nl.css'); + $page->addCssLink('nl.css'); } define('FEMME', 1); @@ -39,8 +38,10 @@ class NewsLetter // {{{ properties var $_id; + var $_shortname; var $_date; var $_title; + var $_title_mail; var $_head; var $_cats = Array(); var $_arts = Array(); @@ -50,39 +51,43 @@ class NewsLetter function NewsLetter($id=null) { - global $globals; - - if (isset($id)) { - if ($id == 'last') { - $res = $globals->xdb->query("SELECT MAX(id) FROM newsletter WHERE bits!='new'"); + if (isset($id)) { + if ($id == 'last') { + $res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'"); $id = $res->fetchOneCell(); - } - $res = $globals->xdb->query("SELECT * FROM newsletter WHERE id={?}", $id); - } else { - $res = $globals->xdb->query("SELECT * FROM newsletter WHERE bits='new'"); - } - $nl = $res->fetchOneAssoc(); - - $this->_id = $nl['id']; - $this->_date = $nl['date']; - $this->_title = $nl['titre']; - $this->_head = $nl['head']; - - $res = $globals->xdb->iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); - while (list($cid, $title) = $res->next()) { - $this->_cats[$cid] = $title; - } - - $res = $globals->xdb->iterRow( + } + $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()) { + insert_new_nl(); + } + $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; + } + + $res = XDB::iterRow( "SELECT a.title,a.body,a.append,a.aid,a.cid,a.pos FROM newsletter_art AS a INNER JOIN newsletter AS n USING(id) LEFT JOIN newsletter_cat AS c ON(a.cid=c.cid) WHERE a.id={?} ORDER BY c.pos,a.pos", $this->_id); - while (list($title, $body, $append, $aid, $cid, $pos) = $res->next()) { - $this->_arts[$cid]["a$aid"] = new NLArticle($title, $body, $append, $aid, $cid, $pos); - } + while (list($title, $body, $append, $aid, $cid, $pos) = $res->next()) { + $this->_arts[$cid]["a$aid"] = new NLArticle($title, $body, $append, $aid, $cid, $pos); + } } // }}} @@ -90,8 +95,7 @@ class NewsLetter function setSent() { - global $globals; - $globals->xdb->execute("UPDATE newsletter SET bits='sent' WHERE id={?}", $this->_id); + XDB::execute("UPDATE newsletter SET bits='sent' WHERE id={?}", $this->_id); } // }}} @@ -99,16 +103,27 @@ class NewsLetter function save() { - global $globals; - $globals->xdb->execute('UPDATE newsletter SET date={?},titre={?},head={?} WHERE id={?}', - $this->_date, $this->_title, $this->_head, $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 id() + + function id() + { + return is_null($this->_shortname) ? $this->_id : $this->_shortname; } // }}} // {{{ function title() - function title() - { return $this->_title; } + function title($mail = false) { + if ($mail) { + return $this->_title_mail; + } + return $this->_title; + } // }}} // {{{ function head() @@ -121,12 +136,12 @@ class NewsLetter function getArt($aid) { - foreach ($this->_arts as $key=>$artlist) { - if (isset($artlist["a$aid"])) { + foreach ($this->_arts as $key=>$artlist) { + if (isset($artlist["a$aid"])) { return $artlist["a$aid"]; } - } - return null; + } + return null; } // }}} @@ -134,22 +149,21 @@ class NewsLetter function saveArticle(&$a) { - global $globals; - if ($a->_aid>=0) { - $globals->xdb->execute('REPLACE INTO newsletter_art (id,aid,cid,pos,title,body,append) + 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 { - $globals->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->_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; - } + $this->_arts['a'.$a->_aid] = $a; + } } // }}} @@ -157,11 +171,10 @@ class NewsLetter function delArticle($aid) { - global $globals; - $globals->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('DELETE FROM newsletter_art WHERE id={?} AND aid={?}', $this->_id, $aid); + foreach ($this->_arts as $key=>$art) { + unset($this->_arts[$key]["a$aid"]); + } } // }}} @@ -170,24 +183,24 @@ class NewsLetter function footer($html) { global $globals; - $url = $globals->baseurl; - - if ($html) { - return '