c649fbf8701e3b9aaf84a1f392c37ac3b0f2d57d
[cacert.git] / scripts / assurer.php
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2009 CAcert Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 include_once("../includes/mysql.php");
20
21 $lines = "";
22 $fp = fopen("assurer.txt", "r");
23 while(!feof($fp))
24 {
25 $line = trim(fgets($fp, 4096));
26 $lines .= wordwrap($line, 75, "\n")."\n";
27 }
28 fclose($fp);
29
30 $query = "
31 select u.email, fname, lname, sum(n.points) from users u, notary n
32 where n.to=u.id
33 and not exists(select 1 from cats_passed cp where cp.user_id=u.id)
34 and exists(select 1 from notary n2 where n2.from=u.id and year(n2.`when`)>2007)
35 and (select count(*) from notary n3 where n3.from=u.id) > 1
36 group by email, fname, lname
37 having sum(points)>99;
38 ";
39 // echo $query;
40 // comment next line when starting to send mail not only to me
41 $res = mysql_query($query);
42 $xrows = mysql_num_rows($res);
43 while($row = mysql_fetch_assoc($res))
44 {
45 echo $row['pts']."..".$row['email']."...\n";
46 // uncomment next line to send mails ...
47 sendmail($row['email'], "[CAcert.org] Assurer Test", $lines, "teus@cacert.org", "", "", "CAcert Events Organisation", "returns@cacert.org", 1);
48 }
49 // 1x cc to events.cacert.org
50 sendmail("philipp@cacert.org", "[CAcert.org] Assurer Test", $lines, "teus@cacert.org", "", "", "CAcert Events Organisation", "returns@cacert.org", 1);
51 // 1x mailing report to events.cacert.org
52 sendmail("philipp@cacert.org", "[CAcert.org] Assurer Report", "assurer information sent to $xrows recipients.", "support@cacert.org", "", "", "CAcert Assurer Organisation", "returns@cacert.org", 1);
53 ?>