Added functions for correct training handling

pull/1/head
root 16 years ago
parent db0b2d2a9b
commit 23debde842

@ -814,5 +814,71 @@
return($text);
}
function fix_assurer_flag($userID)
{
// Update Assurer-Flag on users table if 100 points. Should the number of points be SUM(points) or SUM(awarded)?
// Note: If other tests are implemented an additional restriction for cats_passed would be needed here...
$query = mysql_query('UPDATE `users` AS `u` SET `assurer` = 1 WHERE `u`.`id` = \''.(int)intval($userID).
'\' AND EXISTS(SELECT 1 FROM `cats_passed` AS `tp` WHERE `tp`.`user_id` = `u`.`id`)'.
' AND (SELECT SUM(`points`) FROM `notary` AS `n` WHERE `n`.`to` = `u`.`id` AND `expire` < now()) >= 100'); // Challenge has been passed and non-expired points >= 100
// Reset flag if requirements are not met
$query = mysql_query('UPDATE `users` AS `u` SET `assurer` = 0 WHERE `u`.`id` = \''.(int)intval($userID).
'\' AND (NOT EXISTS(SELECT 1 FROM `cats_passed` AS `tp` WHERE `tp`.`user_id` = `u`.`id`)'.
' OR (SELECT SUM(`points`) FROM `notary` AS `n` WHERE `n`.`to` = `u`.`id` AND `n`.`expire` < now()) < 100)');
}
// returns 0 if $userID is an Assurer
// Otherwise :
// Bit 0 is always set
// Bit 1 is set if 100 Assurance Points are not reached
// Bit 2 is set if Assurer Test is missing
// Bit 3 is set if the user is not allowed to be an Assurer (assurer_blocked > 0)
function is_no_assurer($userID)
{
$Result = 0;
// Note: If other tests are implemented an additional restriction for cats_passed would be needed here...
$query = mysql_query('SELECT * FROM `cats_passed` AS `tp` WHERE `tp`.`user_id` = \''.(int)intval($userID).'\'');
if(mysql_num_rows($query) < 1)
{
$Result |= 5;
}
$query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now()');
$row = mysql_fetch_assoc($query);
if ($row['points'] < 100) {
$Result |= 3;
}
$query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
$row = mysql_fetch_assoc($query);
if ($row['assurer_blocked'] > 0) {
$Result |= 9;
}
return $Result;
}
// returns text message to be shown to the user given the result of is_no_assurer
function no_assurer_text($Status)
{
if ($Status == 0) {
$Result = _("You have passed the Assurer Challenge and collected at least 100 Assurance Points, you are an Assurer.");
} elseif ($Status == 3) {
$Result = _("You have passed the Assurer Challenge, but to become an Assurer you still have to reach 100 Assurance Points!");
} elseif ($Status == 5) {
$Result = _("You have at least 100 Assurance Points, if you want to become an assurer try the ").'<a href="https://cats.cacert.org/">Assurer Challenge</a>!';
} elseif ($Status == 7) {
$Result = _("To become an Assurer have to collect 100 Assurance Points and pass the ").'<a href="https://cats.cacert.org/">Assurer Challenge</a>!';
} elseif ($Status & 8 > 0) {
$Result = _("Sorry, you are not allowed to be an Assurer. Please contact ").'<a href="mailto:support@cacert.org">support@cacert.org</a>'._(" if you feel that this is not corect.");
} else {
$Result = _("You are not an Assurer, but the reason is not stored in the database. Please contact ").'<a href="mailto:support@cacert.org">support@cacert.org</a>.';
}
return $Result;
}
?>

Loading…
Cancel
Save