From: x2000habouzit Date: Sat, 16 Oct 2004 19:54:34 +0000 (+0000) Subject: newsletter is now quite editeable X-Git-Tag: xorg/old~1250 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=7ef8ddba4f03a2891d989654a40b3f6b4880d1d4;p=platal.git newsletter is now quite editeable --- diff --git a/htdocs/admin/newsletter.php b/htdocs/admin/newsletter.php new file mode 100644 index 0000000..6134cd3 --- /dev/null +++ b/htdocs/admin/newsletter.php @@ -0,0 +1,30 @@ +assign_by_ref('nl_list',get_nl_slist()); +$page->run(); +?> diff --git a/htdocs/admin/newsletter_edit.php b/htdocs/admin/newsletter_edit.php new file mode 100644 index 0000000..3173581 --- /dev/null +++ b/htdocs/admin/newsletter_edit.php @@ -0,0 +1,60 @@ +delArticle($_GET['del_aid']); + header("Location: ?nid=$nid"); +} + +if(isset($_POST['save'])) { + $eaid = $_GET['edit_aid']; + $art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append'], $eaid, $_POST['cid'], $_POST['pos']); + $nl->saveArticle($art); + header("Location: ?nid=$nid"); +} + +if(isset($_GET['edit_aid'])) { + $eaid = $_GET['edit_aid']; + if($eaid<0) { + if(!empty($_POST)) { + $art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append'], + $eaid, $_POST['cid'], $_POST['pos']); + } else { + $art = new NLArticle(); + } + } else { + $art = $nl->getArt($_GET['edit_aid']); + } + $page->assign('art', $art); +} + +$page->assign_by_ref('nl',$nl); + +$page->run(); +?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 4275623..8a252bc 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter.inc.php,v 1.7 2004-10-16 18:17:51 x2000habouzit Exp $ + $Id: newsletter.inc.php,v 1.8 2004-10-16 19:54:35 x2000habouzit Exp $ ***************************************************************************/ @@ -52,6 +52,7 @@ function enriched_to_text($input,$html=false) { class NewsLetter { var $_id; var $_date; + var $_title; var $_cats = Array(); var $_arts = Array(); @@ -70,6 +71,7 @@ class NewsLetter { $nl = mysql_fetch_assoc($res); $this->_id = $nl['id']; $this->_date = $nl['date']; + $this->_title = $nl['titre']; mysql_free_result($res); $res = $globals->db->query("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); @@ -78,33 +80,51 @@ class NewsLetter { } mysql_free_result($res); - $res = $globals->db->query("SELECT title,body,append,aid,cid,pos + $res = $globals->db->query("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) - ORDER BY a.pos"); + LEFT JOIN newsletter_cat AS c ON(a.cid=c.cid) + ORDER BY c.pos,a.pos"); while(list($title,$body,$append,$aid,$cid,$pos) = mysql_fetch_row($res)) { - $_arts["a$aid"] = new NLArticle($title,$body,$append,$aid,$cid,$pos); + $this->_arts[$cid]["a$aid"] = new NLArticle($title,$body,$append,$aid,$cid,$pos); } mysql_free_result($res); } + function getArt($aid) { + foreach($this->_arts as $key=>$artlist) { + if(isset($artlist["a$aid"])) return $artlist["a$aid"]; + } + return null; + } + function saveArticle(&$a) { global $globals; - if($a->_aid) { - $globals->db->query("REPLACE INTO newsletter_art (id,aid,cid,pos,title,body.append) + if($a->_aid>=0) { + $globals->db->query("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->db->query( "INSERT INTO newsletter_art - SELECT {$this->_id},MAX(aid)+1,0,IF(MAX(pos)<100,100,MAX(pos)+1),'{$a->_title}','{$a->_body}','{$a->_append}' + SELECT {$this->_id},MAX(aid)+1,{$a->_cid}, + ". ($a->_pos ? $a->_pos : "IF(MAX(pos)<100,100,MAX(pos)+1),").", + '{$a->_title}','{$a->_body}','{$a->_append}' FROM newsletter_art AS a WHERE a.id={$this->_id}"); $this->_arts['a'.$a->_aid] = $a; } } + function delArticle($aid) { + global $globals; + $globals->db->query("DELETE FROM newsletter_art WHERE id='{$this->_id}' AND aid='$aid'"); + foreach($this->_arts as $key=>$art) { + unset($this->_arts[$key]["a$aid"]); + } + } + function toHtml() { return "foo"; } @@ -118,13 +138,13 @@ class NLArticle { var $_body; var $_append; - function NLArticle($title,$body,$append,$aid=null,$cid=0,$pos=100) { + function NLArticle($title='',$body='',$append='',$aid=-1,$cid=0,$pos=0) { $this->_body = $body; $this->_title = $title; $this->_append = $append; $this->_aid = $aid; - $this->_cid = $aid; - $this->_pos = $aid; + $this->_cid = $cid; + $this->_pos = $pos; } function body() { return stripslashes(trim($this->_body)); } @@ -138,7 +158,8 @@ class NLArticle { } function toHtml() { - $title = ''.stripslashes($this->_title).''; + $title = '' + .stripslashes($this->_title).''; $body = enriched_to_text($this->_body,true); $app = enriched_to_text($this->_append,true); @@ -189,6 +210,15 @@ class NLSexeConstraint { } +function get_nl_slist() { + global $globals; + $res = $globals->db->query("SELECT id,date,titre FROM newsletter ORDER BY date DESC"); + $ans = Array(); + while($tmp = mysql_fetch_assoc($res)) $ans[] = $tmp; + mysql_free_result($res); + return $ans; +} + function get_nl_list() { global $globals; $res = $globals->db->query("SELECT id,date,titre FROM newsletter WHERE bits!='new' ORDER BY date DESC"); @@ -213,7 +243,9 @@ function unsubscribe_nl() { function subscribe_nl() { global $globals; - $globals->db->query("REPLACE INTO newsletter_ins (user_id,last) SELECT {$_SESSION['uid']}, MAX(id) FROM newsletter WHERE bits!='new'"); + $globals->db->query("REPLACE INTO newsletter_ins (user_id,last) + SELECT {$_SESSION['uid']}, MAX(id) + FROM newsletter WHERE bits!='new'"); } ?> diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index bd970de..65fc4b5 100644 --- a/templates/admin/index.tpl +++ b/templates/admin/index.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.tpl,v 1.9 2004-10-15 14:30:55 x2000habouzit Exp $ + $Id: index.tpl,v 1.10 2004-10-16 19:54:35 x2000habouzit Exp $ ***************************************************************************} @@ -68,6 +68,7 @@ Newsletter : + Liste   |   Catégories   |   Préparation   |   Archives   |   diff --git a/templates/admin/newsletter.tpl b/templates/admin/newsletter.tpl new file mode 100644 index 0000000..dd55006 --- /dev/null +++ b/templates/admin/newsletter.tpl @@ -0,0 +1,46 @@ +{*************************************************************************** + * Copyright (C) 2003-2004 Polytechnique.org * + * http://opensource.polytechnique.org/ * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *************************************************************************** + $Id: newsletter.tpl,v 1.1 2004-10-16 19:54:35 x2000habouzit Exp $ + ***************************************************************************} + + +
+ Lettre de Polytechnique.org +
+ +{dynamic} + + + + + + {foreach item=nl from=$nl_list} + + + + + {/foreach} +
datetitre
{$nl.date|date_format:"%Y-%m-%d"} + {$nl.titre|default:"[no title]"} +
+ +{/dynamic} + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/admin/newsletter_edit.tpl b/templates/admin/newsletter_edit.tpl new file mode 100644 index 0000000..9f36fff --- /dev/null +++ b/templates/admin/newsletter_edit.tpl @@ -0,0 +1,149 @@ +{*************************************************************************** + * Copyright (C) 2003-2004 Polytechnique.org * + * http://opensource.polytechnique.org/ * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *************************************************************************** + $Id: newsletter_edit.tpl,v 1.1 2004-10-16 19:54:35 x2000habouzit Exp $ + ***************************************************************************} + +{dynamic} +
+ Lettre de Polytechnique.org de {$nl->_date|date_format:"%B %Y"} +
+ +{if !$art} + + + + + + + + + + + {foreach from=$nl->_arts item=arts key=cat} + + + + + {foreach from=$arts item=art} + + + + + {/foreach} + {/foreach} +
+ {$nl->_title|default:"[no title]"} +
+ Créer un nouvel article ... + + [créer] +
+ {$nl->_cats[$cat]|default:"[no cat]"} +
+
+ {$art->toHtml()|smarty:nodefaults} +
+
+ Pos: {$art->_pos}
+ [edit]
+ [delete] +
+ +{else} + +

+[retour] +

+ +{if !$art->check()}

article trop long !

{/if} + + + + + + + + + +
Version texte
{$art->toText()}
Version html
+
+ {$art->toHtml()|smarty:nodefaults} +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Editer un article + +
Sujet + +
Catégorie + +
Position + +
Contenu + +
Ajouts (emails, contacts, tarifs, site web, ...) + +
+ + +
+
+ +{/if} + +{/dynamic} + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/newsletter/submit.tpl b/templates/newsletter/submit.tpl index 5ebe8e7..accf906 100644 --- a/templates/newsletter/submit.tpl +++ b/templates/newsletter/submit.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: submit.tpl,v 1.3 2004-10-16 18:17:51 x2000habouzit Exp $ + $Id: submit.tpl,v 1.4 2004-10-16 19:54:35 x2000habouzit Exp $ ***************************************************************************} @@ -51,39 +51,39 @@ il faut te limiter {/if}
- - - +
Version texte
+ + - - {if $art->check()} - - - - - - - - - - - - - - {/if} -
Version texte
{$art->toText()}
Version html
-
- {$art->toHtml()|smarty:nodefaults} -
-
Soumettre
- Si tu es content de ton article, tu peux le soummetre. - Sinon, tu peux continuer à l'éditer en dessous -
- - - - -
+ + {if $art->check()} + Version html + + +
+ {$art->toHtml()|smarty:nodefaults} +
+ + + + Soumettre + + + + Si tu es content de ton article, tu peux le soummetre. + Sinon, tu peux continuer à l'éditer en dessous + + + + + + + + + + + {/if} +

@@ -106,7 +106,7 @@ Les contacts, prix, adresses mail utiles, liens web, ... sont en sus, et sont Sujet - +