// okay we cannot accept the challenge so make it inactive!
db_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenge_id = ' .$clan_challenge_id);
db_query('UPDATE clan_challenge_requests SET active = FALSE WHERE clan_challenged = ' .$clan_challenge['clan_challenged']. ' AND clan_requester = ' .$clan_challenge['clan_requester']. ' AND challenged_time = "' .$clan_challenge['challenged_time']. '"');
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}
@ -412,7 +412,7 @@ function getActiveChallengeIDs($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;
$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 ';
$qry = db_query($sql);
while($row = mysqli_fetch_row($qry)) {
$array[] = $row[0];
@ -448,6 +448,7 @@ function getHistoricalChallengeIDs($clanid, $limit = NULL) {
}
$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;
@ -181,65 +182,81 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $endTime
// echo $sql . ' <br>';
db_query($sql);
}
db_query('UPDATE event_chars SET block_begin = \''.date("Y-m-d H:i:s",$startTimestamp).'\', block_end = \''.date("Y-m-d H:i:s",$endTimestamp).'\' WHERE event_id = ' . $event_id);
}
function getEventIdsToFetch($char_id, $type = NULL) {
$sql_appendix = ($type === NULL) ? '' : ' inner join events e on ec.event_id = e.event_id AND event_type = '.$type;
$sql = 'SELECT ec.event_id FROM event_chars ec '.$sql_appendix.' WHERE block_begin <= now() AND (block_end <now()ANDabgeholt =FALSE)ANDchar_id =' .$char_id . 'ORDERBYec.event_idASC';
$qry = db_query($sql);
$result = array();
while ($row = mysqli_fetch_row($qry)) {
$result[] = $row[0];
}
return $result;
}
function getEventStatus($charid) {
$sql = 'SELECT event_type FROM event_chars ec inner join events e on ec.event_id = e.event_id where (block_end > now() or abgeholt = FALSE) and char_id = ' . $charid;
// echo $sql . '<br>';
$qry = db_query($sql);
$row = mysqli_fetch_assoc($qry);
switch ($row['event_type']) {
case EVENT_TEST:
return 'Test';
case EVENT_SCHATZ_SUCHE:
return 'Schatz Suche';
case EVENT_TURNIER:
return 'Turnier';
case EVENT_KAMPF:
return 'Kampf';
case EVENT_LIGA:
return 'Liga';
case EVENT_WANTED:
return 'Wanted';
case EVENT_CLAN_FIGHT:
return 'Clanfight';
$event_ids = getEventIdsToFetch($charid);
if (count($event_ids) > 0) {
$event = getEvent($event_ids[0]);
switch ($event['event_type']) {
case EVENT_TEST:
return 'Test';
case EVENT_SCHATZ_SUCHE:
return 'Schatz Suche';
case EVENT_TURNIER:
return 'Turnier';
case EVENT_KAMPF:
return 'Kampf';
case EVENT_LIGA:
return 'Liga';
case EVENT_WANTED:
return 'Wanted';
case EVENT_CLAN_FIGHT:
return 'Clanfight';
}
}
return NULL;
}
function getOngoingEventCount($charid) {
$sql = 'SELECT count(*) FROM event_chars e WHERE abgeholt = FALSE AND char_id = ' .$charid;
$row = mysqli_fetch_row(db_query($sql));
return $row[0];
function string2EventType($text) {
switch($text) {
case 'Schatz Suche':
return EVENT_SCHATZ_SUCHE;
case 'Turnier':
return EVENT_TURNIER;
case 'Kampf':
return EVENT_KAMPF;
case 'Liga':
return EVENT_LIGA;
case 'Wanted':
return EVENT_WANTED;
case 'Clanfight':
return EVENT_CLAN_FIGHT;
default:
return NULL;
}
}
function getEventStatusBlocked($charid) {
$sql = 'SELECT Timestampdiff(Second,now(),MAX(block_end)) FROM event_chars WHERE abgeholt = FALSE AND char_id = ' . $charid;
// echo $sql . '<br>';
$row = mysqli_fetch_row(db_query($sql));
return $row[0];
function getOngoingEventCount($charid, $type = NULL) {
$event_ids = getEventIdsToFetch($charid, $type);
return count($event_ids);
}
function isEventToFetchAwaiting($charid) {
$sql = 'SELECT count(*) FROM event_chars e WHERE abgeholt = FALSE AND char_id = ' .$charid;
$row = mysqli_fetch_row(db_query($sql));
return $row[0] > 0;
return getOngoingEventCount($charid) > 0;
}
function getEventIdsToFetch($char_id) {
$sql = 'SELECT event_id FROM event_chars e WHERE block_end <now()andabgeholt =FALSEANDchar_id =' .$char_id . 'ORDERBYevent_idASC';
$qry = db_query($sql);
$result = array();
while ($row = mysqli_fetch_row($qry)) {
$result[] = $row[0];
function getEventStatusBlocked($charid) {
$event_ids = getEventIdsToFetch($charid);
if (count($event_ids) > 0) {
$sql = 'SELECT Timestampdiff(Second,now(),MAX(block_end)) FROM event_chars WHERE event_id = ' . $event_ids[0];
$row = mysqli_fetch_row(db_query($sql));
return $row[0];
}
return $result;
return 0;
}
function abholenChar(array $user, $event_id, $char_id) {
@ -272,9 +289,32 @@ function abholenChar(array $user, $event_id, $char_id) {
return 'Der Char hat in diesem Event keinen Fight bestritten!';