From e23fbd75f6ad9fb65e84b09e569322971dc15daf Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Fri, 15 Oct 2004 14:30:53 +0000 Subject: [PATCH] categories --- htdocs/admin/newsletter_cats.php | 33 ++++++++++++++++++++++++++ include/newsletter.inc.php | 44 +++++++++++++++++++++++++++++++++-- scripts/migration/0.9.1/newsleter.sql | 14 +++++++++++ templates/admin/index.tpl | 3 ++- 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 htdocs/admin/newsletter_cats.php diff --git a/htdocs/admin/newsletter_cats.php b/htdocs/admin/newsletter_cats.php new file mode 100644 index 0000000..927d965 --- /dev/null +++ b/htdocs/admin/newsletter_cats.php @@ -0,0 +1,33 @@ +describe('titre','intitulé',true); +$editor->describe('pos','position',true); + +$editor->assign('title', 'Gestion des catégories de la newsletter'); + +$editor->run(); +?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 8d291ff..3778bca 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -18,13 +18,53 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter.inc.php,v 1.2 2004-10-15 12:57:10 x2000habouzit Exp $ + $Id: newsletter.inc.php,v 1.3 2004-10-15 14:30:54 x2000habouzit Exp $ ***************************************************************************/ + +define('FEMME', 1); +define('HOMME', 0); + class NewsLetter { function NewsLetter() { } } +class NLArticle { + function NLArticle() { } +} + +class NLConstraint { + var $_func; + var $_arg; + + function NLConstraint($func, $arg) { + $this->_func = $func; + $this->_arg = $arg; + } + + function check($user) { return false; } +} + +class NLPromoConstraint { + function check($user) { + $promo = $user['promo']; + switch($this->_func) { + case 'eq': return ( $promo == $this->_arg ); + case 'neq': return ( $promo != $this->_arg ); + case 'geq': return ( $promo >= $this->_arg ); + case 'leq': return ( $promo <= $this->_arg ); + case 'odd': return ( $promo % 2 == 1 ); + case 'even': return ( $promo % 2 == 0 ); + default: return false; + } + } +} + +class NLSexeConstraint { + function check($user) { return $user['sexe'] == $_arg; } +} + + function get_nl_list() { global $globals; $res = $globals->db->query("SELECT id,date,titre FROM newsletter ORDER BY date DESC"); @@ -49,7 +89,7 @@ function unsubscribe_nl() { function subscribe_nl() { global $globals; - $globals->db->query("INSERT INTO newsletter_ins (user_id) VALUES ({$_SESSION['uid']})"); + $globals->db->query("REPLACE INTO newsletter_ins (user_id,last) SELECT {$_SESSION['uid']}, MAX(id) FROM newsletter WHERE bits!='new'"); } ?> diff --git a/scripts/migration/0.9.1/newsleter.sql b/scripts/migration/0.9.1/newsleter.sql index 6acec7b..19cce45 100644 --- a/scripts/migration/0.9.1/newsleter.sql +++ b/scripts/migration/0.9.1/newsleter.sql @@ -1,6 +1,20 @@ alter table newsletter change id id int not null; alter table newsletter change `date` `date` date not null; alter table newsletter add column bits enum('old','sent','new') default 'new' not null; +update newsletter set bits='old'; alter table newsletter_ins add column last int; alter table newsletter_ins add index (last); + +create table newsletter_cat ( + cid tinyint unsigned not null auto_increment, + pos tinyint unsigned not null, + titre varchar(128) not null, + PRIMARY KEY (cid), + INDEX (pos) +); +insert into newsletter_cat values(1,1,'Flash Info'); +insert into newsletter_cat values(2,2,'Communications institutionnelles'); +insert into newsletter_cat values(3,3,'Groupes X'); +insert into newsletter_cat values(4,4,'Activités polytechniciennes'); + diff --git a/templates/admin/index.tpl b/templates/admin/index.tpl index 08d9f4c..bd970de 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.8 2004-10-08 12:04:05 x2000habouzit Exp $ + $Id: index.tpl,v 1.9 2004-10-15 14:30:55 x2000habouzit Exp $ ***************************************************************************} @@ -68,6 +68,7 @@ Newsletter : + Catégories   |   Préparation   |   Archives   |   Adresses en panne -- 2.1.4