Source code taken from cacert-20110820.tar.bz2
[cacert.git] / includes / lib / account.php
1 <?php
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
20 function fix_assurer_flag($userID)
21 {
22 // Update Assurer-Flag on users table if 100 points.
23 // Should the number of points be SUM(points) or SUM(awarded)?
24 $query = mysql_query('UPDATE `users` AS `u` SET `assurer` = 1 WHERE '.
25 '`u`.`id` = \''.(int)intval($userID).'\' AND '.
26 'EXISTS(SELECT 1 FROM `cats_passed` AS `cp`, `cats_variant` AS `cv` '.
27 'WHERE `cp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 AND '.
28 '`cp`.`user_id` = `u`.`id`) AND '.
29 '(SELECT SUM(`points`) FROM `notary` AS `n` WHERE `n`.`to` = `u`.`id` '.
30 'AND (`n`.`expire` > now() OR `n`.`expire` IS NULL)) >= 100');
31 // Challenge has been passed and non-expired points >= 100
32
33 if (!$query) {
34 return false;
35 }
36
37 // Reset flag if requirements are not met
38 $query = mysql_query('UPDATE `users` AS `u` SET `assurer` = 0 WHERE '.
39 '`u`.`id` = \''.(int)intval($userID).'\' AND '.
40 '(NOT EXISTS(SELECT 1 FROM `cats_passed` AS `cp`, `cats_variant` AS '.
41 '`cv` WHERE `cp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 '.
42 'AND `cp`.`user_id` = `u`.`id`) OR '.
43 '(SELECT SUM(`points`) FROM `notary` AS `n` WHERE `n`.`to` = `u`.`id` '.
44 'AND (`n`.`expire` > now() OR `n`.`expire` IS NULL)) < 100)');
45
46 if (!$query) {
47 return false;
48 }
49
50 return true;
51 }