From 241298a40d6dcabc72f2390a35f8cad18308dd51 Mon Sep 17 00:00:00 2001 From: hecht Date: Sun, 11 Sep 2011 21:00:17 +0000 Subject: [PATCH] Wenn man aus dem Clan austritt und man ist der letzte User, dann wird der Clan geloescht. Ansonsten 2 dateien von dos2unix linebreaks umgewandelt. Noch weitere kleinere Bugfixes. --- ag/clan/c_markt.php | 26 +- ag/clan/clan_info.php | 1198 ++++++++++++++++++++------------------- ag/include/clan.inc.php | 156 ++++- 3 files changed, 760 insertions(+), 620 deletions(-) diff --git a/ag/clan/c_markt.php b/ag/clan/c_markt.php index fc26a6a..5c9b885 100644 --- a/ag/clan/c_markt.php +++ b/ag/clan/c_markt.php @@ -10,6 +10,9 @@ include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/config.inc.php'); include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/designfunctions.inc.php'); include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/fehlerausgabe.inc.php'); include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/parse.inc.php'); +include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan.inc.php'); + + // GET-Section // Kritisch (SQL-Injections) $item_id = validateUnsignedInteger($_GET['item_id'], null); @@ -19,14 +22,20 @@ $charm = $_GET['charm']; if($charm == 3) { - $item_info = mysql_fetch_array(mysql_query("SELECT id, preis, name, anzahl FROM clan_item WHERE id='$item_id' LIMIT 1")); - $user = mysql_Fetch_array(mysql_query("SELECT leader, co_leader, geld, id FROM clan WHERE id='$user_ida[clan]'")); + $item_info = mysql_fetch_assoc(mysql_query("SELECT * FROM clan_item WHERE id='$item_id' LIMIT 1")); + $user = getClan($user_ida['clan']); // mysql_Fetch_array(mysql_query("SELECT leader, co_leader, geld, id FROM clan WHERE id='$user_ida[clan]'")); if($user['leader'] != $user_ida['id'] AND $user['co_leader'] != $user_ida['id']) { displayErrorMessage(NULL,'Nur der Leader und der Co-Leader kann Clanitems kaufen!', displayHistoryBackLink()); exit; } + if($user['level'] >= $item_info['req_level']) { + $fehler_m = 'Euer Clan hat nicht das nötige Level'; + displayErrorMessage(NULL,$fehler_m, displayHistoryBackLink()); + exit; + } + if($user['geld'] < $item_info['preis']) { @@ -34,6 +43,7 @@ if($charm == 3) displayErrorMessage(NULL,$fehler_m, displayHistoryBackLink()); exit; } + $new_geld = $user[geld] - $item_info[preis]; mysql_query("UPDATE clan_item SET anzahl=anzahl-1 WHERE id=".$item_info[id]." LIMIT 1"); @@ -94,6 +104,8 @@ if(!$charm) $c_item[$row['item_id']] = 1; } + $clan = getClan($user_ida['clan']); + while($row = mysql_fetch_array($item_name)) { $info = ''; @@ -111,10 +123,12 @@ if(!$charm) = 1){ echo ''; - } else{ - echo ''; + } else if($clan['level'] < $row['req_level']){ + echo ''; + } else { + echo ''; } ?> @@ -129,4 +143,4 @@ if(!$charm) \ No newline at end of file +?> diff --git a/ag/clan/clan_info.php b/ag/clan/clan_info.php index 7898be5..5faceba 100644 --- a/ag/clan/clan_info.php +++ b/ag/clan/clan_info.php @@ -1,594 +1,604 @@ -verlassen)'; - } else{ - $member[] = $tmp; - } - if($row['id'] == $clan['leader']){ - $leader = $tmp; - } - if($row['id'] == $clan['co_leader']){ - $coleader = $tmp; - } - } - - $inv_qry = mysql_query('SELECT userid, TIMESTAMPDIFF(HOUR, now(), valid) as till FROM user_clan_invitations WHERE clanid = '.$clan['id'].' and valid > now()'); - $invited = array(); - - while($row = mysql_fetch_assoc($inv_qry)) { - $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig)'; - } - - ?> -
- - - - - - - - - - - - Macht übernehmen'; - } else { - echo ''; - } - } else{ - echo ''; - } - ?> - - - - '.$coleader.''; - } - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - '.$clan['homepage'].''; - } else{ - echo ''; - } - ?> - - - - - - - - - - - - - -
- Info
Leader:Keine Leader'.$leader.'
Co-Leader:
Clanzeichen:
Member ():',$member); ?>
Eingeladen', $invited); ?>
Level:
Erfahrung:
Homepage:Keine
Info:
 
-
- - - - - - - - - - - -
Nachricht an alle Clanmember schicken
 
 
-
-
Debug Daten (Kein Bug, dass die naechste Zeile etwas komisch aussieht)
-
- - verlassen)'; - } else if($kickable){ - $member[] = $tmp.' (kicken)'; - } else{ - $member[] = $tmp; - } - } - - $inv_qry = mysql_query('SELECT userid, TIMESTAMPDIFF(HOUR, now(), valid) as till FROM user_clan_invitations WHERE clanid = '.$clan['id'].' and valid > now()'); - $invited = array(); - - while($row = mysql_fetch_assoc($inv_qry)) { - $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig, zurückziehen)'; - } - - - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '.$clan['homepage'].''; - } else{ - echo ''; - } - ?> - - - - - - - - - - - - - - -
- Info
-
(edit) -
Leader:(edit) -
Co-Leader:(edit) -
Clanzeichen:(edit) -
Member ():',$member); ?>
Eingeladen', $invited); ?>
Level:
Erfahrung:
Homepage:(edit) - Keine
Info:(edit)
Clan auflösenClan - löschen
 
-
- - - - - - - - - - - -
Nachricht an alle Clanmember schicken
 
 
-
-
- '; - $clan = mysql_fetch_assoc(mysql_query($sql)); - $editable = $clan['leader'] == $user['id'] || $clan['co_leader'] == $user['id']; - if(!$editable){ - displayClanProfileReadOnly($clan, $user['clan'] == $clan['id'], $user['id']); - } else{ - displayClanProfileEditable($clan, $user['id']); - } -} - - -function setMeAsLeader($user){ - mysql_query('UPDATE clan set leader = '.$user['id'].' WHERE id = '.$user['clan'].' and leader is null and co_leader is null'); -} - -function sendClanNewsletter($user, $text){ - $qry = mysql_query('SELECT * FROM clan WHERE id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - - $errors = FALSE; - $sql = 'SELECT id FROM user WHERE clan='.$user['clan']; - $clans = mysql_query($sql); - while($row = mysql_fetch_assoc($clans)) { - $errors |= !sendMessage($user['nickname'], $row['id'], $clan['clanname'].' Nachricht', $text); - } - if($errors) { - displayErrorMessage(NULL,'Beim Versenden sind Fehler aufgetreten', 'weiter...'); - } else { - displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', 'weiter...'); - } -} - -function setProfile($what, $value1, $value2, $clanid, $rootlvl){ - if($rootlvl < 1) { - return 'Du hast keine Rechte um diese Aktion auszuführen!'; - } - switch($what){ - case 'Homepage': - mysql_query('UPDATE clan SET homepage = \''.$value1.'\' where id = '.$clanid); - return NULL; - case 'Clanzeichen': - mysql_query('UPDATE clan SET clanz_pre = \''.$value1.'\', clanz_suff = \''.$value2.'\' where id = '.$clanid); - return NULL; - case 'Banner': - mysql_query('UPDATE clan SET banner = \''.$value1.'\' where id = '.$clanid); - return NULL; - case 'Info': - mysql_query('UPDATE clan SET Info = \''.$value1.'\' where id = '.$clanid); - return NULL; - case 'Leadership': - $clan = getClan($clanid); - - if($value1 == 0 && $rootlvl == 2){$value1 = 'null';} - else if($rootlvl == 1) { $value1 = $clan['leader']; } - if($value2 == 0){$value2 = 'null';} - // okay, are we allowed to change?? If we have max members, it is not allowed to remove the co_leader - - $clan = getClan($clanid); - $members = getClanMembersCount($clanid); - $members_max = getMaximumMembers($clan['id']); - - if($members_max == $members && $clan['leader'] != $clan['co_leader'] && $value1 == $value2 || $value2 == 'null') { - // Okay, actually there are the max amount of users in the clan - // it is now not possible to change to a leader only clan!! - return 'Es ist nicht möglich den Co-Leader zu ändern, da der clan die maximale Anzahl Member besitzt!'; - } - - if($rootlvl == 1){ // the co leader may only set the co leader XD - $sql = 'UPDATE clan SET co_leader = '.$value2.' where id = '.$clanid; - //echo $sql.'
'; - mysql_query($sql); - } else if($rootlvl == 2) { // the leader may set the leader and the co leader - $sql = 'UPDATE clan SET leader = '.$value1.', co_leader = '.$value2.' where id = '.$clanid; - // echo $sql.'
'; - mysql_query($sql); - } - return NULL; - default: - return 'Error!'; - } -} - -function displayEdit($what, $clanid, $rootlvl){ - if($rootlvl < 1) { - $content = 'Du hast keine Rechte um diese Aktion auszuführen!'; - $what = 'ERROR'; - } - $clan = getCLan($clanid); - - $content = ''; - switch($what){ - case 'Homepage': - $content = ''; - break; - case 'Clanzeichen': - $content = 'Prefix: Suffix: '; - break; - case 'Banner': - $content = ''; - break; - case 'Leadership': - $member_qry = mysql_query('Select id, nickname from user where clan = '.$clanid); - $member[] = ''; - $member2[] = ''; - while($row = mysql_fetch_assoc($member_qry)){ - if($row['id'] == $clan['leader']) { - $member[] = ''; - } else { - $member[] = ''; - } - - if($row['id'] == $clan['co_leader']) { - $member2[] = ''; - } else { - $member2[] = ''; - } - - } - if($rootlvl == 2){ - $content = 'Leader:'; - } - $content .= 'Co-Leader:'; - break; - case 'Info': - $content = ''; - break; - case 'ERROR': - break; - default: - $content = 'Error '.$what.' unknown!'; - break; - } - - ?> -
- - - - - - - - - -
Ändern
-
-
- '; - mysql_query($sql); - if(mysql_affected_rows() > 0){ // Soll nur ausgeführt werden, wenn member wirklich gekickt wurde!! - $sql = 'Update chars set clan_train = NULL where besitzer = '.$member; - mysql_query($sql); - if($user['id'] != $member) { - sendMessage($user['nickname'], $member, 'Clan rauswurf!', 'Du wurdest von '.$user['nickname'].' aus deinem Clan geworfen. Du wirst dir wohl einen neuen suchen müssen!'); - } - } - } else{ - echo displayErrorMessage(NULL, 'Du kannst den Member nicht feuern!', displayHistoryBackLink()); - } -} - -function deleteClan($user){ - $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan'])); - if($user['id'] == $row['leader']){ - $qry = mysql_query('SELECT id FROM user WHERE clan = '.$user['clan']); - while($member = mysql_fetch_assoc($qry)) { - sendMessage($user['nickname'], $member['id'], 'Clan wurde gelöscht!', 'Dein Clan wurde von '.$user['nickname'].' gelöscht. Du wirst dir wohl einen neuen suchen müssen!'); - } - - mysql_query('DELETE FROM clan where id = '.$user['clan']); - } else{ - echo displayErrorMessage(NULL, 'Du kannst den Clan nicht auflösen!', displayHistoryBackLink()); - } -} - - - -if($action !== NULL) { // this is done to not require to reprogramm the whole stuff! - - $rootlvl = 0; - $clan = getClan($user_ida['clan']); - - if($clan['leader'] == $user_ida['id'] || ($clan['leader'] === null && ($clan['co_leader'] === null || $clan['co_leader'] = $user_ida['id']))) { - $rootlvl = 2; // leader or putsch!! - } else if($clan['co_leader'] = $user_ida['id']) { - $rootlvl = 1; // co_leader - } - - switch ($action) { - case 'edit': - $errorMsg = NULL; - $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user_ida['clan'])); - if($row['leader'] != $user_ida['id'] && $row['co_leader'] != $user_ida['id']){ - displayErrorMessage(NULL, 'Du bist weder Leader noch Co-Leader des Clans!', displayHistoryBackLink()); - } else if(isset($value1) || isset($value2)){ - $errorMsg = setProfile($what, $value1, $value2, $user_ida['clan'], $rootlvl); - } else{ - $errorMsg = displayEdit($what, $user_ida['clan'], $rootlvl); - $displayMore = false; - } - if($errorMsg !== NULL) { - echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); - $displayMore = false; - } - - break; - case 'fire': - fireMember($user_ida, $member); - if($user_ida['id'] == $member) { - $displayMore = false; - } - break; - case 'putsch': - setMeAsLeader($user_ida); - break; - case 'kill': - deleteClan($user_ida); - $displayMore = false; - break; - case 'reject': - $errorMsg = revokeInvitation($user_ida, $member); - if($errorMsg !== NULL) { - echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); - $displayMore = false; - } else { - displayErrorMessage('','Du hast die Einladung erfolgreich zurückgezogen!', 'weiter'); - $displayMore = false; - } - break; - case 'newsletter': - sendClanNewsletter($user_ida, $text); - $displayMore = false; - break; - default: - break; - } -} - -if($displayMore){ - displayClanProfile($clan_id, $user_ida); -} -?> +verlassen)'; + } else{ + $member[] = $tmp; + } + if($row['id'] == $clan['leader']){ + $leader = $tmp; + } + if($row['id'] == $clan['co_leader']){ + $coleader = $tmp; + } + } + + $inv_qry = mysql_query('SELECT userid, TIMESTAMPDIFF(HOUR, now(), valid) as till FROM user_clan_invitations WHERE clanid = '.$clan['id'].' and valid > now()'); + $invited = array(); + + while($row = mysql_fetch_assoc($inv_qry)) { + $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig)'; + } + + ?> +
+ + + + + + + + + + + + Macht übernehmen'; + } else { + echo ''; + } + } else{ + echo ''; + } + ?> + + + + '.$coleader.''; + } + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '.$clan['homepage'].''; + } else{ + echo ''; + } + ?> + + + + + + + + + + + + + +
+ Info
Leader:Keine Leader'.$leader.'
Co-Leader:
Clanzeichen:
Member ():',$member); ?>
Eingeladen', $invited); ?>
Level:
Erfahrung:
ELO-Wertung:
Homepage:Keine
Info:
 
+
+ + + + + + + + + + + +
Nachricht an alle Clanmember schicken
 
 
+
+
Debug Daten (Kein Bug, dass die naechste Zeile etwas komisch aussieht)
+
+ + verlassen)'; + } else if($kickable){ + $member[] = $tmp.' (kicken)'; + } else{ + $member[] = $tmp; + } + } + + $inv_qry = mysql_query('SELECT userid, TIMESTAMPDIFF(HOUR, now(), valid) as till FROM user_clan_invitations WHERE clanid = '.$clan['id'].' and valid > now()'); + $invited = array(); + + while($row = mysql_fetch_assoc($inv_qry)) { + $invited[] = displayUserLinkByID($row['userid']) . ' (noch ' . $row['till'] . 'h gültig, zurückziehen)'; + } + + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '.$clan['homepage'].''; + } else{ + echo ''; + } + ?> + + + + + + + + + + + + + + +
+ Info
+
(edit) +
Leader:(edit) +
Co-Leader:(edit) +
Clanzeichen:(edit) +
Member ():',$member); ?>
Eingeladen', $invited); ?>
Level:
Erfahrung:
ELO-Wertung:
Homepage:(edit) + Keine
Info:(edit)
Clan auflösenClan + löschen
 
+
+ + + + + + + + + + + +
Nachricht an alle Clanmember schicken
 
 
+
+
+ '; + $clan = mysql_fetch_assoc(mysql_query($sql)); + $editable = $clan['leader'] == $user['id'] || $clan['co_leader'] == $user['id']; + if(!$editable){ + displayClanProfileReadOnly($clan, $user['clan'] == $clan['id'], $user['id']); + } else{ + displayClanProfileEditable($clan, $user['id']); + } +} + + +function setMeAsLeader($user){ + mysql_query('UPDATE clan set leader = '.$user['id'].' WHERE id = '.$user['clan'].' and leader is null and co_leader is null'); +} + +function sendClanNewsletter($user, $text){ + $qry = mysql_query('SELECT * FROM clan WHERE id = ' . $user['clan']); + $clan = mysql_fetch_assoc($qry); + + $errors = FALSE; + $sql = 'SELECT id FROM user WHERE clan='.$user['clan']; + $clans = mysql_query($sql); + while($row = mysql_fetch_assoc($clans)) { + $errors |= !sendMessage($user['nickname'], $row['id'], $clan['clanname'].' Nachricht', $text); + } + if($errors) { + displayErrorMessage(NULL,'Beim Versenden sind Fehler aufgetreten', 'weiter...'); + } else { + displayErrorMessage(NULL,'Nachricht erfolgreich verschickt', 'weiter...'); + } +} + +function setProfile($what, $value1, $value2, $clanid, $rootlvl){ + if($rootlvl < 1) { + return 'Du hast keine Rechte um diese Aktion auszuführen!'; + } + switch($what){ + case 'Homepage': + mysql_query('UPDATE clan SET homepage = \''.$value1.'\' where id = '.$clanid); + return NULL; + case 'Clanzeichen': + mysql_query('UPDATE clan SET clanz_pre = \''.$value1.'\', clanz_suff = \''.$value2.'\' where id = '.$clanid); + return NULL; + case 'Banner': + mysql_query('UPDATE clan SET banner = \''.$value1.'\' where id = '.$clanid); + return NULL; + case 'Info': + mysql_query('UPDATE clan SET Info = \''.$value1.'\' where id = '.$clanid); + return NULL; + case 'Leadership': + $clan = getClan($clanid); + + if($value1 == 0 && $rootlvl == 2){$value1 = 'null';} + else if($rootlvl == 1) { $value1 = $clan['leader']; } + if($value2 == 0){$value2 = 'null';} + // okay, are we allowed to change?? If we have max members, it is not allowed to remove the co_leader + + $clan = getClan($clanid); + $members = getClanMembersCount($clanid); + $members_max = getMaximumMembers($clan['id']); + + if($members_max == $members && $clan['leader'] != $clan['co_leader'] && ($value1 == $value2 || $value2 == 'null')) { + // Okay, actually there are the max amount of users in the clan + // it is now not possible to change to a leader only clan!! + return 'Es ist nicht möglich den Co-Leader zu ändern, da der clan die maximale Anzahl Member besitzt!'; + } + + if($rootlvl == 1){ // the co leader may only set the co leader XD + $sql = 'UPDATE clan SET co_leader = '.$value2.' where id = '.$clanid; + //echo $sql.'
'; + mysql_query($sql); + } else if($rootlvl == 2) { // the leader may set the leader and the co leader + $sql = 'UPDATE clan SET leader = '.$value1.', co_leader = '.$value2.' where id = '.$clanid; + // echo $sql.'
'; + mysql_query($sql); + } + return NULL; + default: + return 'Error!'; + } +} + +function displayEdit($what, $clanid, $rootlvl){ + if($rootlvl < 1) { + $content = 'Du hast keine Rechte um diese Aktion auszuführen!'; + $what = 'ERROR'; + } + $clan = getCLan($clanid); + + $content = ''; + switch($what){ + case 'Homepage': + $content = ''; + break; + case 'Clanzeichen': + $content = 'Prefix: Suffix: '; + break; + case 'Banner': + $content = ''; + break; + case 'Leadership': + $member_qry = mysql_query('Select id, nickname from user where clan = '.$clanid); + $member[] = ''; + $member2[] = ''; + while($row = mysql_fetch_assoc($member_qry)){ + if($row['id'] == $clan['leader']) { + $member[] = ''; + } else { + $member[] = ''; + } + + if($row['id'] == $clan['co_leader']) { + $member2[] = ''; + } else { + $member2[] = ''; + } + + } + if($rootlvl == 2){ + $content = 'Leader:'; + } + $content .= 'Co-Leader:'; + break; + case 'Info': + $content = ''; + break; + case 'ERROR': + break; + default: + $content = 'Error '.$what.' unknown!'; + break; + } + + ?> +
+ + + + + + + + + +
Ändern
+
+
+ '; + mysql_query($sql); + if(mysql_affected_rows() > 0){ // Soll nur ausgeführt werden, wenn member wirklich gekickt wurde!! + $sql = 'Update chars set clan_train = NULL where besitzer = '.$member; + mysql_query($sql); + if($user['id'] != $member) { + sendMessage($user['nickname'], $member, 'Clan rauswurf!', 'Du wurdest von '.$user['nickname'].' aus deinem Clan geworfen. Du wirst dir wohl einen neuen suchen müssen!'); + } else if(getClanMembersCount($user['clan']) == 0) { + mysql_query('DELETE FROM clan WHERE id =' .$user['clan']); + } + } + } else{ + echo displayErrorMessage(NULL, 'Du kannst den Member nicht feuern!', displayHistoryBackLink()); + } +} + +function deleteClan($user){ + $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user['clan'])); + if($user['id'] == $row['leader']){ + $qry = mysql_query('SELECT id FROM user WHERE clan = '.$user['clan']); + while($member = mysql_fetch_assoc($qry)) { + sendMessage($user['nickname'], $member['id'], 'Clan wurde gelöscht!', 'Dein Clan wurde von '.$user['nickname'].' gelöscht. Du wirst dir wohl einen neuen suchen müssen!'); + } + + mysql_query('DELETE FROM clan where id = '.$user['clan']); + } else{ + echo displayErrorMessage(NULL, 'Du kannst den Clan nicht auflösen!', displayHistoryBackLink()); + } +} + + + +if($action !== NULL) { // this is done to not require to reprogramm the whole stuff! + + $rootlvl = 0; + $clan = getClan($user_ida['clan']); + + if($clan['leader'] == $user_ida['id'] || ($clan['leader'] === null && ($clan['co_leader'] === null || $clan['co_leader'] = $user_ida['id']))) { + $rootlvl = 2; // leader or putsch!! + } else if($clan['co_leader'] = $user_ida['id']) { + $rootlvl = 1; // co_leader + } + + switch ($action) { + case 'edit': + $errorMsg = NULL; + $row = mysql_fetch_assoc(mysql_query('SELECT leader, co_leader from clan where id = '.$user_ida['clan'])); + if($row['leader'] != $user_ida['id'] && $row['co_leader'] != $user_ida['id']){ + displayErrorMessage(NULL, 'Du bist weder Leader noch Co-Leader des Clans!', displayHistoryBackLink()); + } else if(isset($value1) || isset($value2)){ + $errorMsg = setProfile($what, $value1, $value2, $user_ida['clan'], $rootlvl); + } else{ + $errorMsg = displayEdit($what, $user_ida['clan'], $rootlvl); + $displayMore = false; + } + if($errorMsg !== NULL) { + echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); + $displayMore = false; + } + + break; + case 'fire': + fireMember($user_ida, $member); + if($user_ida['id'] == $member) { + $displayMore = false; + } + break; + case 'putsch': + setMeAsLeader($user_ida); + break; + case 'kill': + deleteClan($user_ida); + $displayMore = false; + break; + case 'reject': + $errorMsg = revokeInvitation($user_ida, $member); + if($errorMsg !== NULL) { + echo displayErrorMessage(NULL, $errorMsg, displayHistoryBackLink()); + $displayMore = false; + } else { + displayErrorMessage('','Du hast die Einladung erfolgreich zurückgezogen!', 'weiter'); + $displayMore = false; + } + break; + case 'newsletter': + sendClanNewsletter($user_ida, $text); + $displayMore = false; + break; + default: + break; + } +} + +if($displayMore){ + displayClanProfile($clan_id, $user_ida); +} +?> diff --git a/ag/include/clan.inc.php b/ag/include/clan.inc.php index 5f8de7a..c6dfd9c 100644 --- a/ag/include/clan.inc.php +++ b/ag/include/clan.inc.php @@ -160,33 +160,149 @@ function inviteUser(array $user, $userid, array $clan = NULL){ } } +define("DAVY_BACK_FIGHT", 1); +define("SURVIVAL", 2); +/** + * + * Challenge an other clan (Davy Back Fight) + * @param array $user the user array + * @param int $clanid the id of the clan to challenge + * @param int $validTime the amount of hours that the challenge is valid + */ +function challengeClan(array $user, $clanid, $type = DAVY_BACK_FIGHT, $anzahl, $validTime = 24) { + $qry = mysql_query('SELECT * FROM clan WHERE id = ' . $user['clan']); + $clan = mysql_fetch_assoc($qry); -function challengeClan(array $user, array $charids, $clanid, $validTime = 24) { - if($clan === NULL) { - $qry = mysql_query('Select * from clan where id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - } + $oclan = mysql_fetch_assoc(mysql_query('SELECT * FROM clan WHERE id = ' . $clanid)); - if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ - return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!'; - } - // TODO: Further implementation - return NULL; + if(!$clan || !$oclan) { + return 'Entweder bist du nicht in einem Clan oder der andere Clan existiert nicht mehr!!'; + } + + if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ + return 'Nur der Leader, bzw. der Co-Leader kann andere Clans herausfordern!!'; + } + + + // Fordere heraus! + mysql_query('INSERT INTO clan_challenge(clan_requester, clan_challenged, type, anzahl, valid, accepted) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', false)'); + + if(mysql_affected_rows() > 0) { + if(is_numeric($oclan['leader'])) { + sendMessage($user['nickname'], $oclan['leader'], 'Davy Back Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Davy Back Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); + } + if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { + sendMessage($user['nickname'], $oclan['co_leader'], 'Davy Back Fight Herausforderung', 'Der Clan '.$oclan['clanname'].' hat euch zu einem Davy Back Fight herausgefordert! Über "Mein Clan" könnt ihr die Herausforderung annehmen!'); + } + } else { + return 'Konnte den anderen Clan nicht herausfordern!!'; + } + + return NULL; } -function acceptChallenge(array $user, array $charids) { - if($clan === NULL) { - $qry = mysql_query('Select * from clan where id = ' . $user['clan']); - $clan = mysql_fetch_assoc($qry); - } - if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ - return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!'; - } - // TODO: Further implementation - return NULL; +function acceptChallenge($challengeid, array $user) { + $qry = mysql_query('Select * from clan where id = ' . $user['clan']); + $clan = mysql_fetch_assoc($qry); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + if($clan['leader'] != $user['id'] && $clan['co_leader'] != $user['id']){ + return 'Nur der Leader, bzw. der Co-Leader kann herausforderungen anderer Clans annehmen!!'; + } + + $clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge WHERE clan_challenge_id = ' .$challengeid)); + + if($user['clan'] != $clan_challenge['clan_challenged']) { + return 'Du kannst die Herausforderung nicht annehmen, da du nicht im herausgeforderten Clan bist!'; + } + + // The user must be in the challanged clan + $oclan = mysql_fetch_assoc('SELECT * FROM clan WHERE id = '.$clan_challenge['clan_requester']); + + mysql_query('UPDATE clan_challenge SET accepted = TRUE WHERE clan_challenge_id = ' .$challengeid); + + if(mysql_affected_rows() > 0) { + if(is_numeric($oclan['leader'])) { + sendMessage($user['nickname'], $oclan['leader'], 'Davy Back Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Davy Back Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!'); + } + if(is_numeric($oclan['co_leader']) && $oclan['leader'] != $oclan['co_leader']) { + sendMessage($user['nickname'], $oclan['co_leader'], 'Davy Back Fight', 'Der Clan '.$oclan['clanname'].' hat eure Herausforderungen zu einem Davy Back Fight angenommen! Über "Mein Clan" könnt ihr nun Chars anmelden!'); + } + } else { + return 'Du kannst die Herausforderungen nicht annehmen. Wurde die Herausforderung schon angenommen?'; + } + + return NULL; +} + + +function getOpenChallengesByUser(array $user) { + $qry = mysql_query('SELECT * FROM clan_challenge WHERE accepted = FALSE AND clan_requester = '.$user['clan'].' OR clan_challenged = '.$user['clan']); + $array = array(); + while($row = mysql_fetch_assoc($qry)) { + $array[] = $row; + } + return $array; } +function getOpenChallengesByClanId($clanid) { + $qry = mysql_query('SELECT * FROM clan_challenge WHERE accepted = FALSE AND clan_requester = '.$clanid.' OR clan_challenged = '.$clanid); + $array = array(); + while($row = mysql_fetch_assoc($qry)) { + $array[] = $row; + } + return $array; +} + + +/** + * This function lets a user take part in the clan fight! The clan fight will be calculated if all chars have been registered. + * A challenge can only be joined if there is no other char of the same user joined. If the given slot is free and the challangeid is valid. + * @param int $challengeid the id of the challenge + * @param array $user the user array + * @param int $charid the id of the char that should join + */ +function joinChallenge($challengeid, array $user, $charid, $slot ) { + $qry = mysql_query('Select * from clan where id = ' . $user['clan']); + $clan = mysql_fetch_assoc($qry); + + if(!$clan) { + return 'Du bist in keinem Clan!!'; + } + + $clan_challenge = mysql_fetch_assoc(mysql_query('SELECT * FROM clan_challenge WHERE clan_challenge_id = ' .$challengeid)); + + if($user['clan'] != $clan_challenge['clan_challenged'] && $user['clan'] != $clan_challenge['clan_requester'] ) { + return 'Du kannst an der Herausforderung nicht teilnehmen, da du nicht in einem teilnehmenden Clan bist!'; + } + + $char = getChar($charid); + + if($user['id'] != $char['besitzer']) { + return 'Du kannst den Char nicht an der Herausforderung teilnehmen lassen, da er dir nicht gehört!'; + } + + // query all clan_challange_participants to see if the user already has a char in competition! + + +} + +/** + * This function does the calculation of the clan fight. + * @param int $challengeid the id of the challenge + */ +function calculateChallenge($challengeid) { + +} + + + + + ?>