0337d704 |
1 | #!/usr/bin/php4 -q |
2 | <?php |
3 | /*************************************************************************** |
4 | * Copyright (C) 2003-2004 Polytechnique.org * |
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 | |
23 | require('./connect.db.inc.php'); |
24 | require("newsletter.inc.php"); |
25 | |
26 | $opt = getopt('i:h'); |
27 | |
28 | if(empty($opt['i']) || isset($opt['h'])) { |
29 | echo <<<EOF |
30 | usage: send_nl.php -i nl_id |
31 | sends the NewsLetter of id "id" |
32 | EOF; |
33 | exit; |
34 | } |
35 | |
36 | $id = intval($opt['i']); |
37 | $nl = new NewsLetter($id); |
38 | $nl->setSent(); |
39 | |
40 | while(true) { |
41 | $res = $globals->xdb->iterRow( |
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), |
45 | q.core_mail_fmt AS pref |
46 | FROM newsletter_ins AS ni |
47 | INNER JOIN auth_user_md5 AS u USING(user_id) |
48 | INNER JOIN auth_user_quick AS q ON(q.user_id = u.user_id) |
49 | INNER JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) |
50 | WHERE ni.last<{?} |
51 | LIMIT 60", $id); |
52 | if (!$res->total()) { exit; } |
53 | |
54 | $sent = Array(); |
55 | while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt) = $res->next()) { |
56 | $sent[] = "user_id='$uid'"; |
57 | $nl->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html'); |
58 | } |
59 | $globals->xdb->execute('UPDATE newsletter_ins SET last={?} WHERE '.implode(' OR ', $sent), $id); |
60 | sleep(60); |
61 | } |
62 | |
63 | ?> |