Backports
[platal.git] / bin / newsletter.send.php
CommitLineData
0337d704 1#!/usr/bin/php4 -q
2<?php
3/***************************************************************************
50a40a33 4 * Copyright (C) 2003-2006 Polytechnique.org *
0337d704 5 * http://opensource.polytechnique.org/ *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
22
23require('./connect.db.inc.php');
24require("newsletter.inc.php");
25
26$opt = getopt('i:h');
27
28if(empty($opt['i']) || isset($opt['h'])) {
29 echo <<<EOF
30usage: send_nl.php -i nl_id
31 sends the NewsLetter of id "id"
32EOF;
33 exit;
34}
35
36$id = intval($opt['i']);
37$nl = new NewsLetter($id);
38$nl->setSent();
39
40while(true) {
08cce2ff 41 $res = XDB::iterRow(
0337d704 42 "SELECT ni.user_id, a.alias,
43 u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
44 FIND_IN_SET('femme', u.flags),
a6dfd11d 45 q.core_mail_fmt AS pref
0337d704 46 FROM newsletter_ins AS ni
47 INNER JOIN auth_user_md5 AS u USING(user_id)
a6dfd11d 48 INNER JOIN auth_user_quick AS q ON(q.user_id = u.user_id)
0337d704 49 INNER JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
a6dfd11d 50 LEFT JOIN emails AS e ON(e.uid=u.user_id AND e.flags='active')
51 WHERE ni.last<{?} AND e.email IS NOT NULL
52 GROUP BY ni.user_id
0337d704 53 LIMIT 60", $id);
54 if (!$res->total()) { exit; }
55
56 $sent = Array();
57 while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt) = $res->next()) {
a6dfd11d 58 $sent[] = "user_id='$uid'";
59 $nl->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html');
0337d704 60 }
08cce2ff 61 XDB::execute('UPDATE newsletter_ins SET last={?} WHERE '.implode(' OR ', $sent), $id);
0337d704 62 sleep(60);
63}
64
65?>