// okay we cannot accept the challenge so make it inactive!
// 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)!';
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}
}
@ -412,7 +412,7 @@ function getActiveChallengeIDs($clanid) {
return $array;
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);
$qry = db_query($sql);
while($row = mysqli_fetch_row($qry)) {
while($row = mysqli_fetch_row($qry)) {
$array[] = $row[0];
$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;
$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>';
// echo $sql . ' <br>';
db_query($sql);
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) {
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;
$event_ids = getEventIdsToFetch($charid);
// echo $sql . '<br>';
if (count($event_ids) > 0) {
$qry = db_query($sql);
$event = getEvent($event_ids[0]);
$row = mysqli_fetch_assoc($qry);
switch ($event['event_type']) {
switch ($row['event_type']) {
case EVENT_TEST:
case EVENT_TEST:
return 'Test';
return 'Test';
case EVENT_SCHATZ_SUCHE:
case EVENT_SCHATZ_SUCHE:
return 'Schatz Suche';
return 'Schatz Suche';
case EVENT_TURNIER:
case EVENT_TURNIER:
return 'Turnier';
return 'Turnier';
case EVENT_KAMPF:
case EVENT_KAMPF:
return 'Kampf';
return 'Kampf';
case EVENT_LIGA:
case EVENT_LIGA:
return 'Liga';
return 'Liga';
case EVENT_WANTED:
case EVENT_WANTED:
return 'Wanted';
return 'Wanted';
case EVENT_CLAN_FIGHT:
case EVENT_CLAN_FIGHT:
return 'Clanfight';
return 'Clanfight';
}
}
}
return NULL;
return NULL;
}
}
function getOngoingEventCount($charid) {
function string2EventType($text) {
$sql = 'SELECT count(*) FROM event_chars e WHERE abgeholt = FALSE AND char_id = ' .$charid;
switch($text) {
$row = mysqli_fetch_row(db_query($sql));
case 'Schatz Suche':
return $row[0];
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 getOngoingEventCount($charid, $type = NULL) {
function getEventStatusBlocked($charid) {
$event_ids = getEventIdsToFetch($charid, $type);
$sql = 'SELECT Timestampdiff(Second,now(),MAX(block_end)) FROM event_chars WHERE abgeholt = FALSE AND char_id = ' . $charid;
return count($event_ids);
// echo $sql . '<br>';
$row = mysqli_fetch_row(db_query($sql));
return $row[0];
}
}
function isEventToFetchAwaiting($charid) {
function isEventToFetchAwaiting($charid) {
$sql = 'SELECT count(*) FROM event_chars e WHERE abgeholt = FALSE AND char_id = ' .$charid;
return getOngoingEventCount($charid) > 0;
$row = mysqli_fetch_row(db_query($sql));
return $row[0] > 0;
}
}
function getEventIdsToFetch($char_id) {
function getEventStatusBlocked($charid) {
$sql = 'SELECT event_id FROM event_chars e WHERE block_end <now()andabgeholt =FALSEANDchar_id =' .$char_id . 'ORDERBYevent_idASC';
$event_ids = getEventIdsToFetch($charid);
$qry = db_query($sql);
if (count($event_ids) > 0) {
$result = array();
$sql = 'SELECT Timestampdiff(Second,now(),MAX(block_end)) FROM event_chars WHERE event_id = ' . $event_ids[0];
$row = mysqli_fetch_row(db_query($sql));
while ($row = mysqli_fetch_row($qry)) {
return $row[0];
$result[] = $row[0];
}
}
return $result;
return 0;
}
}
function abholenChar(array $user, $event_id, $char_id) {
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!';
return 'Der Char hat in diesem Event keinen Fight bestritten!';