You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
6.7 KiB

<?php
/*
*
* @copyright (c) 2009 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/config.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/fehlerausgabe.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/designfunctions.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/parse.inc.php');
// GET-Section
// Kritisch (SQL-Injections)
$clanid = validateUnsignedInteger($_GET['clanid'], null);
$poll1 = validateString($_GET['poll1']);
$poll2 = validateString('ASC');
$pagenum = validateUnsignedInteger($_GET['pagenum'], null);
// Unkritisch
$action = $_GET['action'];
$user = $user_ida;
function joinClan($user, $clanid){
$sql = 'SELECT * FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid.' and valid > now();';
$clan_user = mysql_fetch_assoc(mysql_query($sql));
if($clan_user){
$sql = 'Select *, (Select member - count(*) from user u where clan = c.id and ((c.leader is null || c.leader != u.id) and (c.co_leader is null || c.co_leader != u.id))) as freeslots from clan c where id = '.$clanid;
// echo $sql . '<br>';
$clan = mysql_fetch_assoc(mysql_query($sql));
if($clan['freeslots'] <= 0){
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen (Clan voll)!',displayHistoryBackLink());
return;
} else{
$sql = 'UPDATE user SET clan = '.$clanid.' WHERE id = '.$user['id'];
// echo $sql.'<br>';
mysql_query($sql);
// unset the leader if the user is moving from one clan to another
mysql_query('UPDATE clan SET leader = NULL WHERE leader = ' .$user['id']);
mysql_query('UPDATE clan SET co_leader = NULL WHERE co_leader = ' .$user['id']);
displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','<a href="index.php?as=clan/clan_info">weiter</a>');
}
} else{
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen!',displayHistoryBackLink());
return;
}
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
}
function denyClan($user, $clanid){
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
if(mysql_affected_rows() > 0){
displayErrorMessage('Abgelehnt','Du hast die Einladung erfolgreich abgelehnt!','<a href="index.php?as=clan/add">weiter</a>');
} else{
displayErrorMessage(NULL,'Einladung des Clans konnte nicht abgelehnt werden!',displayHistoryBackLink());
}
}
if ($action == 'accept') {
joinClan($user_ida, $clanid);
} else if ($action == 'deny') {
denyClan($user_ida, $clanid);
} else {
?>
<form action="index.php" method="GET">
<input type="hidden" name="as" value="clan/add"> <input type="hidden"
name="charm" value="1">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<th height="30" width="585" colspan="5" class="content">Erhaltene
Claneinladungen</th>
</tr>
<tr>
<th height="30" class="content">Clanname</th>
<th height="30" colspan="2" class="content">Deadline</th>
<th height="30" colspan="2" class="content">Reagieren</th>
<?php
$sql = 'SELECT * FROM user_clan_invitations WHERE userid = '.$user_ida['id'].' and valid > now();';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)){
?>
<tr>
<td height="30" align="center" class="content"><?php echo displayClanLink($row['clanid']); ?>
</td>
<td height="30" align="center" colspan="2" class="content"><?php echo $row['valid']; ?>
</td>
<td height="30" align="center" colspan="2" class="content"><a
href="index.php?as=clan/add&action=accept&clanid=<?php echo $row['clanid']; ?>">Akzeptieren</a>
| <a
href="index.php?as=clan/add&action=deny&clanid=<?php echo $row['clanid']; ?>">Ablehnen</a>
</td>
</tr>
<tr>
<td height="30" colspan="5" class="content"></td>
</tr>
<?php
}
if (!$poll1) {
$poll1 = 'clanname';
$poll2 = 'ASC';
}
if ($poll1 == 'clanname' AND $poll2 == 'ASC') {
$poll['clanname'] = 'DESC';
} else {
$poll['clanname'] = 'ASC';
}
if ($poll1 == 'leader' AND $poll2 == 'ASC') {
$poll['leader'] = 'DESC';
} else {
$poll['leader'] = 'ASC';
}
if ($poll1 == 'geld' AND $poll2 == 'ASC') {
$poll['geld'] = 'DESC';
} else {
$poll['geld'] = 'ASC';
}
$ready = 'clan/add&pagenum='.$pagenum;
?>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<th height="30" width="585" colspan="5" class="content">Übersicht
aller Clans</th>
</tr>
<tr>
<th height="33" width="96" valign="top" class="content"><?php echo '<a href="index.php?as='.$ready.'&poll1=clanname&poll2='.$poll['clanname'].'">Clanname</a>'; ?>
</th>
<th height="33" width="128" valign="top" class="content"><?php echo '<a href="index.php?as='.$ready.'&poll1=leader&poll2='.$poll['leader'].'">Leader</a>'; ?>
</th>
<th height="33" width="76" valign="top" class="content">Mitglieder</th>
<th height="33" width="98" valign="top" class="content"><?php echo '<a href="index.php?as='.$ready.'&poll1=geld&poll2='.$poll['geld'].'">Geld</a>'; ?>
</th>
<th height="33" width="76" valign="top" class="content">Info</th>
</tr>
<?php
$sql = 'SELECT c.clanz_pre, c.clanz_suff, c.clanname, c.geld, c.info, c.id, c.leader FROM clan c ORDER BY '.$poll1.' '.$poll2.' LIMIT '.($pagenum*20).',20';
$clan = mysql_query($sql);
while ($row = mysql_fetch_array($clan)) {
$mitglieder = mysql_num_rows(mysql_query('SELECT id FROM user WHERE clan='.$row['id']));
$z_v = array($row['clan_pre'], $row['clan_suff']);
?>
<tr>
<td height="35" width="96" valign="top" align="center"
class="content"><?php echo displayClanLink($row['id'], $row['clanname']); ?>
</td>
<td height="25" width="128" valign="top" align="center"
class="content"><?php echo displayUserLinkByID($row['leader']); ?>
</td>
<td height="25" width="76" valign="top" align="center"
class="content"><?php echo $mitglieder; ?>
</td>
<td height="25" width="98" valign="top" align="center"
class="content"><?php echo displayMoney($row['geld']); ?>
</td>
<td height="25" valign="top" align="center" class="content"><?php echo $row['info']; ?>
</td>
</tr>
<?php
// TODO: Seitenzahlen aus Designfunctions benutzen!!!
}
$Total = mysql_num_rows(mysql_query('SELECT id FROM clan'));
$url = '<a href="'.$_SERVER['PHP_SELF'].'?as=clan/add&pagenum=###PAGE###">###LABEL###</a>';
?>
<tr>
<td colspan="5" class="content"><?php echo displayPagelinksNew(20, $Total, $pagenum, $url); ?>
</td>
</tr>
</table>
</form>
<?php
}
?>