New PlMailer based on Hermes code:
[platal.git] / bin / newsletter.send.php
CommitLineData
ee68ddc1 1#!/usr/bin/php5 -q
0337d704 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
1e33266a 23require_once('./connect.db.inc.php');
24require_once('../classes/plmailer.php');
25require_once("newsletter.inc.php");
0337d704 26
27$opt = getopt('i:h');
28
29if(empty($opt['i']) || isset($opt['h'])) {
30 echo <<<EOF
31usage: send_nl.php -i nl_id
32 sends the NewsLetter of id "id"
33EOF;
34 exit;
35}
36
37$id = intval($opt['i']);
38$nl = new NewsLetter($id);
39$nl->setSent();
40
41while(true) {
08cce2ff 42 $res = XDB::iterRow(
0337d704 43 "SELECT ni.user_id, a.alias,
44 u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
45 FIND_IN_SET('femme', u.flags),
a6dfd11d 46 q.core_mail_fmt AS pref
0337d704 47 FROM newsletter_ins AS ni
48 INNER JOIN auth_user_md5 AS u USING(user_id)
a6dfd11d 49 INNER JOIN auth_user_quick AS q ON(q.user_id = u.user_id)
0337d704 50 INNER JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
a6dfd11d 51 LEFT JOIN emails AS e ON(e.uid=u.user_id AND e.flags='active')
52 WHERE ni.last<{?} AND e.email IS NOT NULL
53 GROUP BY ni.user_id
0337d704 54 LIMIT 60", $id);
55 if (!$res->total()) { exit; }
56
57 $sent = Array();
58 while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt) = $res->next()) {
a6dfd11d 59 $sent[] = "user_id='$uid'";
60 $nl->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html');
0337d704 61 }
08cce2ff 62 XDB::execute('UPDATE newsletter_ins SET last={?} WHERE '.implode(' OR ', $sent), $id);
0337d704 63 sleep(60);
64}
65
66?>