$signature = trim(Post::v('signature'));
$promo_min = Post::i('promo_min');
$promo_max = Post::i('promo_max');
+ $subset_to = preg_split("/[ ,;\:\n\r]+/", Post::v('subset_to'), -1, PREG_SPLIT_NO_EMPTY);
+ $subset = ( count($subset_to) > 0);
$echeance = Post::has('echeance_date') ?
preg_replace('/^(\d\d\d\d)(\d\d)(\d\d)$/', '\1-\2-\3', Post::v('echeance_date')) . ' ' . Post::v('echeance_time')
: Post::v('echeance');
$res = XDB::query("SELECT * FROM axletter WHERE FIND_IN_SET('new', bits)");
if ($res->numRows()) {
extract($res->fetchOneAssoc(), EXTR_OVERWRITE);
+ if ($subset) {
+ $res = XDB::query('SELECT email FROM axletter_subsets WHERE letter_id = {?}', $id);
+ $subset_to = $res->fetchColumn();
+ }
$saved = true;
} else {
XDB::execute("INSERT INTO axletter SET id = NULL");
case 'Aperçu':
$this->load('axletter.inc.php');
$al = new AXLetter(array($id, $short_name, $subject, $title, $body, $signature,
- $promo_min, $promo_max, $echeance, 0, 'new'));
+ $promo_min, $promo_max, $subset, $echeance, 0, 'new'));
$al->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
break;
case 'Confirmer':
XDB::execute("REPLACE INTO axletter
SET id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?},
- signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}",
- $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance);
+ signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}",
+ $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset);
+ if ($subset) {
+ XDB::execute('DELETE FROM axletter_subsets
+ WHERE letter_id = {?}', $id);
+ foreach ($subset_to as $email) {
+ $uid = $this->idFromMail(array('email' => $email));
+ if ($uid) {
+ XDB::execute('INSERT INTO axletter_subsets
+ SET letter_id = {?}, user_id = {?}, email = {?}',
+ $id, $uid, $email);
+ }
+ }
+ }
if (!$saved) {
global $globals;
$mailer = new PlMailer();
$page->assign('signature', $signature);
$page->assign('promo_min', $promo_min);
$page->assign('promo_max', $promo_max);
+ $page->assign('subset_to', implode("\n", $subset_to));
+ $page->assign('subset', $subset);
$page->assign('echeance', $echeance);
$page->assign('echeance_date', $echeance_date);
$page->assign('echeance_time', $echeance_time);