178a0d39d815a06db2454b38637229215054038d
2 /***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once("massmailer.inc.php");
24 class AXLetter
extends MassMailer
34 function __construct($id)
36 parent
::__construct('axletter/letter.tpl', 'ax.css', 'ax/show');
37 $this->_head
= '<cher> <prenom>,';
41 $res = XDB
::query("SELECT *
43 WHERE FIND_IN_SET('sent', bits)
46 $res = XDB
::query("SELECT *
48 WHERE id = {?} OR shortname = {?}", $id, $id);
50 if (!$res->numRows()) {
54 $id = $res->fetchOneRow();
56 list($this->_id
, $this->_shortname
, $this->_title_mail
, $this->_title
,
57 $this->_body
, $this->_signature
, $this->_promo_min
, $this->_promo_max
,
58 $this->_echeance
, $this->_date
, $this->_bits
) = $id;
61 protected function assignData(&$smarty)
63 $smarty->assign_by_ref('am', $this);
66 public function body($format)
68 return format_text($this->_body
, $format);
71 public function signature($format)
73 return format_text($this->_signature
, $format, 10);
76 static public function create($subject, $title, $body, $signature, $promo_min, $promo_max, $date, $shortname = null
)
78 $id = AXLetter
::awaiting();
80 return new AXLetter($id);
82 XDB
::execute("INSERT INTO axletter (shortname, echeance, promo_min, promo_max,
83 subject, title, body, signature,
84 subject_ini, title_ini, body_ini, signature_ini)
85 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})",
86 $shortname, $date, $promo_min, $promo_max,
87 $subject, $title, $body, $signature, $subject, $title, $body, $signature);
88 return new AXLetter(XDB
::insertId());
91 public function update($subject, $title, $body, $signature, $promo_min, $promo_max, $date, $shortname = null
)
93 $this->_shortname
= $shortname;
94 $this->_title
= $title;
95 $this->_title_mail
= $subject;
97 $this->_signature
= $signature;
98 $this->_promo_min
= $promo_min;
99 $this->_promo_max
= $promo_max;
100 $this->_date
= $date;
101 return XDB
::execute("UPDATE axletter (shortname, subject, title, body, signature, promo_min, promo_max, echeance)
102 SET shorname={?}, subject={?}, title={?}, body={?}, signature={?},
103 promo_min={?}, promo_max={?}, echeance={?}
105 $shortname, $subject, $title, $body, $signature, $promo_min, $promo_max, $date, $this->_id
);
108 public function valid()
110 return XDB
::execute("UPDATE axletter
112 WHERE id = {?}", $this->_id
);
115 public function invalid()
117 return XDB
::execute("UPDATE axletter
118 SET bits = 'invalid', date = CURDATE()
119 WHERE id = {?}", $this->_id
);
122 protected function setSent()
124 XDB
::execute("UPDATE axletter
125 SET bits='sent', date=CURDATE()
126 WHERE id={?}", $this->_id
);
129 static public function subscriptionState($uid = null
)
131 $user = is_null($uid) ? S
::v('uid') : $uid;
132 $res = XDB
::query("SELECT 1
134 WHERE user_id={?}", $user);
135 return $res->fetchOneCell();
138 static public function unsubscribe($uid = null
)
140 $user = is_null($uid) ? S
::v('uid') : $uid;
141 XDB
::execute("DELETE FROM axletter_ins
142 WHERE user_id={?} OR hash = {?}", $user, $user);
145 static public function subscribe($uid = null
)
147 $user = is_null($uid) ? S
::v('uid') : $uid;
148 XDB
::execute("REPLACE INTO axletter_ins (user_id,last)
149 VALUES ({?}, 0)", $user);
152 static public function hasPerms()
154 if (S
::has_perms()) {
157 $res = XDB
::query("SELECT 1
159 WHERE user_id = {?}", S
::i('uid'));
160 return $res->fetchOneCell();
163 protected function subscriptionTable()
165 return 'axletter_ins';
168 protected function subscriptionWhere()
173 static public function awaiting()
175 $res = XDB
::query("SELECT id
177 WHERE FIND_IN_SET('new', bits)");
178 return $res->fetchOneCell();
181 static public function listSent()
183 $res = XDB
::query("SELECT IF(shortname IS NULL, id, shortname) as id, date, subject AS titre
185 WHERE NOT (FIND_IN_SET('new', bits))
186 ORDER BY date DESC");
187 return $res->fetchAllAssoc();
190 static public function listAll()
192 $res = XDB
::query("SELECT IF(shortname IS NULL, id, shortname) as id, date, subject AS titre
194 ORDER BY date DESC");
195 return $res->fetchAllAssoc();
199 // vim:set et sw=4 sts=4 sws=4: