<?php
if(!defined('panel'))
	die('Nope.');
if(isset(Config::$_url[1])) { ?>
</div>
	<div class="main-content">
	
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
					</li>
					<li>
						<a href="<?php echo Config::$_PAGE_URL; ?>clan">Clans</a>
					</li>
						<?php
							$q = Config::$g_con->prepare('SELECT * FROM `clans` WHERE `clanID` = ?');
							$q->execute(array(Config::$_url[1]));
							while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>
					<li class="active"><?php echo $row->clanName; ?></li>
					<?php } ?>
				</ul><!-- /.breadcrumb -->

				<div class="nav-search" id="nav-search">
					<form method="POST" action="search">
						<span class="input-icon">
							<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
							<i class="ace-icon fa fa-search nav-search-icon"></i>
						</span>
					</form>
				</div> <!-- /.nav-search -->
			</div>	
			
<div class="page-content">
<?php
if(isset($_POST['submit'])) {
		//echo '<div class="alert alert-success">Ai r&#259;spuns cu succes reclama&#355;iei.</div>';
		
		$q = Config::$g_con->prepare('UPDATE `clans` SET `clanDescription` = ? WHERE `clanID` = ?');
		$q->execute(array($_POST['cinfo'],Config::$_url[1]));
}
if(isset($_POST['disable'])) {
		//echo '<div class="alert alert-success">Ai r&#259;spuns cu succes reclama&#355;iei.</div>';

		$q = Config::$g_con->prepare('UPDATE `clans` SET `clanActive` = 0 WHERE `clanID` = ?');
		$q->execute(array(Config::$_url[1]));
		$q = Config::$g_con->prepare('UPDATE `users` SET `Clan`= 0,`CRank`= 0,`ClanTag`= 0,`CWarns`= 0 WHERE `Clan` = ?');
		$q->execute(array(Config::$_url[1]));
}
if(isset($_POST['enable'])) {
		//echo '<div class="alert alert-success">Ai r&#259;spuns cu succes reclama&#355;iei.</div>';

		$q = Config::$g_con->prepare('UPDATE `clans` SET `clanExpire` = ?,`clanActive` = 1 WHERE `clanID` = ?');
		$q->execute(array((time()+90*43200),Config::$_url[1]));
}
?>
<div class="row-fluid">
	<?php
		$q = Config::$g_con->prepare('SELECT * FROM `clans` WHERE `clanID` = ?');
		$q->execute(array(Config::$_url[1]));
		while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>
<title>Clan: <?php echo $row->clanName ?> - <?php echo Config::$_SITE_NAME; ?></title>		
			<div class="page-header">
				<h1>Clan <?php echo $row->clanName ?></h1>
			</div>

<div class="row-fluid">
<div class="span3">
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-info red"></i>
<font color="white">
Clan info
</font
</h5>
</div>
<div class="widget-body">
<div class="widget-main"">
Name: <?php echo $row->clanName ?><br>
Tag: <?php echo $row->clanTag ?><br>
Members: <?php 
	$fac = Config::$g_con->prepare("SELECT * FROM `users` WHERE `Clan` = $row->clanID");
	$fac->execute();
	echo $fac->rowCount(); ?> / <?php echo $row->clanSlots ?><br><br>
<?php
$timestamp=$row->clanExpire;
?>						
Expires at: <b><?php echo gmdate("Y-m-d H:i:s", $timestamp); ?></b>
</div>
</div>
</div>
<br>
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-info red"></i>
<font color="white">
Clan ranks
</font>
</h5>
</div>
<div class="widget-body">
<div class="widget-main"">
1 - <?php echo $row->clanRankName1 ?><br>
2 - <?php echo $row->clanRankName2 ?><br>
3 - <?php echo $row->clanRankName3 ?><br>
4 - <?php echo $row->clanRankName4 ?><br>
5 - <?php echo $row->clanRankName5 ?><br>
6 - <?php echo $row->clanRankName6 ?><br>
7 - <?php echo $row->clanRankName7 ?><br>
</div>
</div>
</div>
</div>
<div class="span6">
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-user red"></i>
<font color="white">
Clan members
</font>
</h5>
</div>
<div class="widget-body">
<div class="widget-main"">
<ul>
	<?php
		$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `Clan` = ? ORDER BY `CRank` DESC');
		$q->execute(array(Config::$_url[1]));
		while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>
<li><a href="<?php echo Config::$_PAGE_URL; ?>profile/<?php echo $row->id ?>"><?php echo $row->name ?></a> - rank <?php echo $row->CRank ?> - joined on <?php echo $row->ClanJoin ?></li>
	<?php } ?>
</ul>
<hr>
</div>
</div>
</div>
</div>
<div class="span3">
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-certificate red"></i>
<font color="white">
Clan description
</font>
</h5>
</div>
<div class="widget-body">
<?php
	$q = Config::$g_con->prepare('SELECT * FROM `clans` WHERE `clanID` = ?');
	$q->execute(array(Config::$_url[1]));
	while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>
<div class="widget-main"">
<span class="claninfo"><?php echo $row->clanDescription ?></span>
<?php if(isset($_SESSION['user'])&& Config::getData('users','Clan',$_SESSION['user']) == Config::$_url[1] && Config::getData('users','CRank',$_SESSION['user']) == 7) { ?>
<form action="" method="POST">
<textarea name="cinfo" class="span12" rows="15">
<?php echo $row->clanDescription ?>
</textarea>
<input type="submit" name="submit" value="Modifica" class="btn btn-success"/>
</form>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<br>
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-ticket red"></i>
<font color="white">
Clan logs
</font>
</h5>
</div>
<div class="widget-body">
<div class="widget-main"">
<ul>
	<?php
		$q = Config::$g_con->prepare('SELECT * FROM `clan_logs` WHERE `clanid` = ? ORDER BY `id` DESC LIMIT 25');
		$q->execute(array(Config::$_url[1]));
		while($rowc = $q->fetch(PDO::FETCH_OBJ)) { ?>
<li><?php echo $rowc->time ?><br /><?php echo $rowc->action ?></li>
	<?php } ?>

</ul>
</div>
</div>
</div>
<?php if(isset($_SESSION['user']) && Config::getData('users','Admin',$_SESSION['user']) >= 6) { ?>
<div class="widget-box">
<div class="widget-header widget-header-flat widget-header-small" style="background-color:#000000">
<h5>
<i class="icon-ticket red"></i>
<font color="white">
Admin tools
</font
</h5>
</div>
<div class="widget-body">
<div class="widget-main"">
<form method="POST" action="" disabled>
<br />
<input type="submit" name="disable" class="btn btn-small btn-danger" value="Disable Clan"/>
</form>
<form method="POST" action="" disabled>
<br />
<input type="submit" name="enable" class="btn btn-small btn-succes" value="Enable Clan"/>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } } else { ?>
<title>Clan list - <?php echo Config::$_SITE_NAME; ?></title>
</div>
	<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
					</li>			
					<li class="active">Clans</li>
				</ul><!-- /.breadcrumb -->

				<div class="nav-search" id="nav-search">
					<form method="POST" action="search">
						<span class="input-icon">
							<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
							<i class="ace-icon fa fa-search nav-search-icon"></i>
						</span>
					</form>
				</div> <!-- /.nav-search -->
			</div>	
			
<div class="page-content">
<div class="row-fluid"><div class="span12">
<div class="table-responsive">
	<table id="login-table" class="table table-striped table-hover table-bordered">
		<thead>
		<tr>			
			<td class="center">ID</td>
			<td>Name</td>
			<td>Tag</td>
			<td>Members</td>					
		</tr>
		</thead>
		<tbody>
			<?php
				$q = Config::$g_con->prepare('SELECT * FROM `clans` WHERE `clanActive` = 1');
				$q->execute();
				while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>
					<tr>
						<td class="center"><?php echo $row->clanID ?></td>
						<td><a href="<?php echo Config::$_PAGE_URL ?>clan/<?php echo $row->clanID ?>"><?php echo $row->clanName ?></a></td>
						<td><?php echo $row->clanTag ?></td>
						<td><?php 
							$fac = Config::$g_con->prepare("SELECT * FROM `users` WHERE `Clan` = $row->clanID");
							$fac->execute();
						echo $fac->rowCount(); ?> / <?php echo $row->clanSlots ?></td>
					</tr>
		<?php } ?>
		</tbody>
	</table>
<?php
}
?>
