First commit of tag changes. bug-1444
[cacert-devel.git] / scripts / cron / updatesort.php
1 #!/usr/bin/php -q
2 <?php /*
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 require_once(dirname(__FILE__).'/../../includes/lib/account.php');
21
22
23 // Recalculate assurer flag for all accounts
24 if (!fix_assurer_flag()) {
25 fwrite(STDERR, "ERROR on fixing the assurer flag. Continuing anyway");
26 }
27
28
29 mysql_query("update `locations` set `acount`=0");
30 $query = "SELECT `users`.`locid` AS `locid`, count(*) AS `total` FROM `users`
31 WHERE users.assurer='1' AND `users`.`locid` != 0 and users.listme=1
32 GROUP BY `users`.`locid`";
33 $res = mysql_query($query);
34 while($row = mysql_fetch_assoc($res))
35 {
36 $query = "update `locations` set `acount`='${row['total']}' where `id`='${row['locid']}'";
37 echo $query."\n";
38 mysql_query($query);
39 }
40
41
42 mysql_query("update `regions` set `acount`=0");
43 $query = "SELECT `users`.`regid` AS `regid`, count(*) AS `total` FROM `users`
44 WHERE users.assurer='1' AND `users`.`regid` != 0 and users.listme=1
45 GROUP BY `users`.`regid`";
46 $res = mysql_query($query);
47 while($row = mysql_fetch_assoc($res))
48 {
49 $query = "update `regions` set `acount`='${row['total']}' where `id`='${row['regid']}'";
50 echo $query."\n";
51 mysql_query($query);
52 }
53
54
55
56
57 mysql_query("update `countries` set `acount`=0");
58 $query = "SELECT `users`.`ccid` AS `ccid`, count(*) AS `total` FROM `users`
59 WHERE users.assurer='1' AND `users`.`ccid` != 0 and users.listme=1
60 GROUP BY `users`.`ccid`";
61 $res = mysql_query($query);
62 while($row = mysql_fetch_assoc($res))
63 {
64 $query = "update `countries` set `acount`='${row['total']}' where `id`='${row['ccid']}'";
65 echo $query."\n";
66 mysql_query($query);
67 }
68
69
70 ?>