3 /***************************************************************************
4 * Copyright (C) 2003-2011 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 /** Check if there is some pending validations,
24 * and if so sends notification email.
27 $M_PERIOD = "INTERVAL 3 HOUR"; // 3 hour lap (old validations)
28 $R_PERIOD = "INTERVAL 6 HOUR"; // 6 hour lap (very old validations)
30 require 'connect.db.inc.php';
31 require 'plmailer.php';
33 $res = XDB
::query("SELECT count(r.stamp), UNIX_TIMESTAMP(MIN(r.stamp)),
34 sum(r.stamp < NOW() - $M_PERIOD), sum(r.stamp < NOW() - $R_PERIOD)
36 list($nb, $age, $nbold, $nbveryold) = $res->fetchOneRow();
38 $age = (time() - intval($age)) / 86400;
41 $head = "[Autodestruction du serveur] ";
43 $head = "[Armageddon imminent] ";
45 $head = "[Guerre nucléaire] ";
47 $head = "[ET Téléphone maison] ";
49 $head = "[Réveil !] ";
50 } elseif (!empty($nbveryold)) {
59 $plural = $nb == 1 ?
'' : 's';
61 $mymail = new PlMailer();
62 $mymail->setFrom('validation@' . $globals->mail
->domain
);
63 $mymail->addTo('validation@' . $globals->mail
->domain
);
64 $mymail->setSubject($head . "Il y a $nb validation$plural non effectuée$plural");
67 "Il y a $nb validation$plural à effectuer\n"
68 . (empty($nbold) ?
'' : "dont $nbold depuis le dernier mail !!!\n")
69 . (empty($nbveryold) ?
'' : "et dont *$nbveryold* " . ($nbveryold == 1 ?
'est' : 'sont') . ' en retard de plus de 6h !!!')
71 . "https://www.polytechnique.org/admin/validate\n\n"
72 . "Par catégorie :\n";
73 $res = XDB
::iterRow('SELECT type, count(*)
77 while (list($type, $nb) = $res->next()) {
78 $message .= "- $type : $nb\n";
81 $message = wordwrap($message, 78);
82 $mymail->setTxtBody($message);
85 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: