semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
@ -243,10 +242,12 @@ function cancelChallengeRequest($challenged_clan, array $user) {
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$challenged_clan . ' AND clan_requester = ' .$user['clan'] . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
return 'Konnte die Herausforderung nicht zurückziehen, da diese Herausforderung nicht exisitiert!';
}
// TODO: Check if this conditions are redundant
@ -277,10 +278,12 @@ function denyChallengeRequest($challenge_requester, array $user) {
return 'Nur der Leader, Co-Leader oder freigeschaltete Mitglieder können Herausforderungen anderer Clans ablehnen!!';
}
$clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())'));
$sql = 'SELECT * FROM clan_challenge_requests WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())';
return 'Konnte die Herausforderung nicht annehmen, da diese Herausforderung nicht exisitiert!';
return 'Konnte die Herausforderung nicht ablehnen, da diese Herausforderung nicht exisitiert!';
}
// TODO: Check if this conditions are redundant
@ -291,7 +294,7 @@ function denyChallengeRequest($challenge_requester, array $user) {
}
// okay seems to be okay
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan. ' AND active = TRUE');
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenge_requester. ' AND active = TRUE');
return NULL;
}
@ -352,6 +355,38 @@ function getOpenChallengeIDs($clanid) {
return $array;
}
function getActiveChallengeIDs($clanid) {
// before doing anything check if we are locked
$array = array();
if(isClanLocked($clanid)) {
return $array;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE AND enddate > now() ORDER BY cc.date DESC ' . $addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
// returns the last challenge ids (beginning with the latest to the first)
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
$addition = '';
if($limit !== null && is_numeric($limit)) {
$addition = ' LIMIT ' .$limit;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE AND enddate <now()ORDERBYcc.dateDESC'.$addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
function getParticipatingClanIDs($clan_challenge_id) {
$array = array();
$sql = 'SELECT clan_id FROM clan_challenge_clans AS ccp WHERE clan_challenge_id = ' . $clan_challenge_id;
@ -380,21 +415,6 @@ function getParticipatingCharIDs($clan_challenge_id, $clan_id) {
return $array;
}
// returns the last challenge ids (beginning with the latest to the first)
function getHistoricalChallengeIDs($clanid, $limit = NULL) {
$addition = '';
if($limit !== null && is_numeric($limit)) {
$addition = ' LIMIT ' .$limit;
}
$sql = 'SELECT cc.clan_challenge_id FROM clan_challenges AS cc inner join clan_challenge_clans AS ccp ON cc.clan_challenge_id = ccp.clan_challenge_id WHERE clan_id = ' . $clanid . ' AND calculated = TRUE ORDER BY cc.date DESC ' . $addition;
$qry = mysql_query($sql);
while($row = mysql_fetch_row($qry)) {
$array[] = $row[0];
}
// return the ids
return $array;
}
function getClanLockedTime($clan_id) {
$sql = 'SELECT TIMESTAMPDIFF(SECOND, NOW(), locked_until) FROM clan_locked WHERE clanid = ' . $clan_id;
$row = mysql_fetch_row(mysql_query($sql));
@ -432,6 +452,9 @@ function isClanLocked($clanid) {
$sql = 'INSERT INTO clan_locked(clanid, locked_until) values('.$clanid.', TIMESTAMPADD(HOUR, 24, CURRENT_TIMESTAMP))';
// echo $sql.'<br>';
mysql_query($sql);
// FIXME: We were not locked but now we are! -> deactivate all outstanding clan_challenge_requests
mysql_query('UPDATE clan_challenge_requests SET active = FALSE WHERE (clan_challenged = '.$clanid.' OR clan_requester = '.$clanid);
mysql_query('DELETE FROM clan_challenges WHERE calculated = FALSE AND clan_challenge_id IN (SELECT clan_challenge_id from clan_challenge_clans WHERE clan_id = '.$clanid.')');