bug 1003: Make scripts resilient against working directory changes and
[cacert-devel.git] / scripts / cron / updatesort.php
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2008 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 require_once(dirname(__FILE__).'/../../includes/mysql.php');
20
21
22
23 //mysql_query("update users set assurer=0");
24 $query = "select notary.`to` as uid from notary group by notary.`to` having sum(points)>=100;";
25 $res = mysql_query($query);
26 while($row = mysql_fetch_assoc($res))
27 {
28 $query = "update users set `assurer`='1' where `id`='${row['uid']}'";
29 //echo $query."\n";
30 mysql_query($query);
31 }
32
33
34 mysql_query("update `locations` set `acount`=0");
35 $query = "SELECT `users`.`locid` AS `locid`, count(*) AS `total` FROM `users`
36 WHERE users.assurer='1' AND `users`.`locid` != 0 and users.listme=1
37 GROUP BY `users`.`locid`";
38 $res = mysql_query($query);
39 while($row = mysql_fetch_assoc($res))
40 {
41 $query = "update `locations` set `acount`='${row['total']}' where `id`='${row['locid']}'";
42 echo $query."\n";
43 mysql_query($query);
44 }
45
46
47 mysql_query("update `regions` set `acount`=0");
48 $query = "SELECT `users`.`regid` AS `regid`, count(*) AS `total` FROM `users`
49 WHERE users.assurer='1' AND `users`.`regid` != 0 and users.listme=1
50 GROUP BY `users`.`regid`";
51 $res = mysql_query($query);
52 while($row = mysql_fetch_assoc($res))
53 {
54 $query = "update `regions` set `acount`='${row['total']}' where `id`='${row['regid']}'";
55 echo $query."\n";
56 mysql_query($query);
57 }
58
59
60
61
62 mysql_query("update `countries` set `acount`=0");
63 $query = "SELECT `users`.`ccid` AS `ccid`, count(*) AS `total` FROM `users`
64 WHERE users.assurer='1' AND `users`.`ccid` != 0 and users.listme=1
65 GROUP BY `users`.`ccid`";
66 $res = mysql_query($query);
67 while($row = mysql_fetch_assoc($res))
68 {
69 $query = "update `countries` set `acount`='${row['total']}' where `id`='${row['ccid']}'";
70 echo $query."\n";
71 mysql_query($query);
72 }
73
74
75
76
77 ?>