<title>Cerere unban - <?php echo Config::$_SITE_NAME; ?></title>
</div>
	<div class="main-content">
		<div class="main-content-inner">
					<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">
								<a href="<?php echo Config::$_PAGE_URL; ?>unban">Unban requests</a>
							</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">

<?php
if(!defined('panel'))
	die('Nope.');
if(!isset($_SESSION['user'])) {
echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'login\'/>'; } else {
if(!isset($_GET['id'])) { 
	if(!isset($_GET['request'])) {
	?>

<h2>Your Unban Requests</h2>
<div class="row">
	<div class="col-xs-12 center">
		<div class="table-responsive" style="margin-left: 30px">
			<table id="sample-table-1" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>				
						<th>Title</th>
						<th>
						<i class="icon-time bigger-110 hidden-480"></i>
							Date
						</th>
						<th class="hidden-480">Status</th>
					</tr>
				</thead>
				<tbody>
				<?php
					$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `tip` = 1 AND `user` = ? ORDER BY `id` DESC, `status` DESC");
					$q->execute(array(Config::getData('users', 'name', $_SESSION['user'])));
					while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>				
					<tr>
						<td><a href="<?php echo Config::$_PAGE_URL ?>unban/?id=<?php echo $row->id ?>"> Unban request - <?php echo $row->user ?></a></td>
						<td><?php echo $row->data ?></td>
						<td><?php echo (!$row->status ? "Open" : "Closed") ?></td>
					</tr>
				<?php } ?>					
				</tbody>
			</table>				
		</div>
	</div>
</div>
	
		<form method="GET" action="">
			<input class="btn btn-small btn-danger" type="submit" name="request" value="New unban request">
		</form>
		<br>
		
<?php if(Config::getData('users', 'Admin', $_SESSION['user']) >= 6)  {?>
<div class="row">
	<div class="col-xs-12 center">
		<div class="table-responsive" style="margin-left: 30px">
			<table id="sample-table-1" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>				
						<th>Title</th>
						<th>
						<i class="icon-time bigger-110 hidden-480"></i>
							Date
						</th>
						<th class="hidden-480">Status</th>
					</tr>
				</thead>
				<tbody>
				<?php
					$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `tip` = 1 ORDER BY `id` DESC, `status` DESC");
					$q->execute();
					while($row = $q->fetch(PDO::FETCH_OBJ)) { ?>				
					<tr>
						<td><a href="<?php echo Config::$_PAGE_URL ?>unban/?id=<?php echo $row->id ?>"> Unban request - <?php echo $row->user ?></a></td>
						<td><?php echo $row->data ?></td>
						<td><?php echo (!$row->status ? "Open" : "Closed") ?></td>
					</tr>
				<?php } ?>					
				</tbody>
			</table>				
		</div>
	</div>
<?php }
	} else {
			$nume = Config::$g_con->prepare("SELECT `user` FROM `unban_requests` WHERE `user` = ? AND `status` = 0 AND `tip` = 1");
			$nume->execute(array(Config::getData("users", "name", $_SESSION['user'])));
			if($nume->rowCount()) {
				echo Config::message("yellow", "Ai depus deja o cerere. Vei primi un r&#259;spuns &#238;n cel mai scurt timp posibil. <a href='".Config::$_PAGE_URL."unban'>« Go back </a>");
			} else {
			$q = Config::$g_con->prepare("SELECT * FROM `bans` WHERE `PlayerName`=:name AND `Active` = 1");
			$q->execute(array(":name" => Config::getData('users', 'name', $_SESSION['user'])));
			if(!$q->rowCount()) echo Config::message('yellow',' You are not banned. <a href="'.Config::$_PAGE_URL.'unban/">Go back</a>');
			else {
				if(isset($_POST['submit'])) {


										
					echo '<br>';
			while($row = $q->fetch(PDO::FETCH_OBJ)) {

					@$text = htmlspecialchars($_POST['text']);

					//@$text = htmlspecialchars($_POST['text']);
					$user  = Config::getData('users', 'name', $_SESSION['user']);
					$qp = Config::$g_con->prepare("INSERT INTO `unban_requests`(`id`, `text`, `tip`, `user`, `data`, `status`, `idd`) VALUES ('', ?, 1, ?, CURRENT_TIMESTAMP, 0, id)");
					$qp->execute(array($text,$user));
					echo Config::message('success', '<center> Cererea a fost trimis&#259;. Vei fi redirec&#355;ionat &#238;n 5 secunde. </center>');
				//	mysql_query("INSERT INTO email (text, playerid) VALUES ('Your unban request has been created.', '".Config::getData('users', 'id', $_SESSION['user'])."'");
					echo '<br>';
					echo '<meta http-equiv="refresh" content="5;URL=\''.Config::$_PAGE_URL.'unban\'/>';
				
			}					} else {

						while($roww2 = $q->fetch(PDO::FETCH_OBJ)) {
						?>
	<div class="span8">

	<div class="alert alert-warning">
		Daca stii ca ai fost sanctionat corect, nu are rost sa faci cererea de unban. Nu vei fi debanat.
	</div>

		
		<h4>Creaza cerere unban</h4>
		<hr>
		<form method="POST" action="" accept-charset="UTF-8">
		Banat de:  <b><?php echo $roww2->AdminName ?></b><br/>
		Motiv ban:  <b><?php echo $roww2->Reason ?></b><br/>
		Data banului:  <b><?php echo $roww2->BanTimeDate ?></b><br/>
		<?php if($roww2->Permanent == 1)	{
			$expira = "permanent";
			} else {
			$expira = "". gmdate("Y-m-d H:i:s", $roww2->Time) ."";
		} ?>
		Banul expira pe:  <b><?php echo $expira ?></b><br/>




		<br/>
		<label for="text">Detalii: </label><br />
		<textarea  class="form-control" rows="5" name="text" cols="50" id="text"></textarea>
		<br/>


		<input class="btn btn-small btn-danger" type="submit" name="submit" value="Creaza cerere unban">

		</form>
	</div>

	<div class="span4">
		<h4>Info</h4>
		<ul>
			<li>Poate dura pana la 24 de ore pana se va raspunde la cererea de unban</li>
			<li>Daca ti s-a raspuns la cererea de unban si ti s-a zis ca banul ramane, nu crea alta.</li>
		</ul>

				<?php }
				}
			}
		}
	} 
} else {
	/* --- verificare pentru a nu posta daca cererea nu-i apartine ---
	if(Config::getData("users", "Admin", $_SESSION['user']) < 6) {
		$p = Config::$g_con->prepare("SELECT `id` FROM `unban_requests` WHERE `user` = :user AND `id` = :id");
		$p->bindParam(":user", Config::getData("users", "Name", $_SESSION['user']), PDO::PARAM_STR, 24);
		$p->bindParam(":id", $_GET['id'], PDO::PARAM_INT);
		$p->execute();
		if(!$p->rowCount()) {
			header("Location: ".Config::$_PAGE_URL.'unban');
		}
		
	}*/
	if(isset($_POST['submit']) && @$_POST['submit'] == 'Accepta' && (Config::getData("users", "Admin", $_SESSION['user'])) >= 6) {
		$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `id`= ? AND `tip` = 1");
		$id = $_GET['id'];
		$q->execute(array($id));
		while($row = $q->fetch(PDO::FETCH_OBJ)) {
			$close = Config::$g_con->prepare("INSERT INTO emails (Message, playerid, LinkPanel, giverid) VALUES 
			('Cererea ta de unban a fost acceptata de adminul ".Config::getData('users', 'name', $_SESSION['user']).".', '".Config::getID('users', 'id', $row->user)."', 'unban?id=".$id."', '".Config::getID('users', 'id', $_SESSION['user'])."')");
			//$q->bindParam(":id", $id, PDO::PARAM_INT);
			$close->execute();	}
		$user = Config::getData("unban_requests", "user", $_GET['id']);
		$acc = Config::$g_con->prepare("UPDATE `bans` SET `Active` = 0 WHERE `PlayerName` = ?");
		$acc->execute(array($user));
		$close = Config::$g_con->prepare("UPDATE `unban_requests` SET `status` = 1 WHERE `id` = ?");
		$close->execute(array($_GET['id']));
	}
	if(isset($_POST['submit']) && @$_POST['submit'] == 'Respinge' && (Config::getData("users", "Admin", $_SESSION['user'])) >= 6) {
		$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `id`= ? AND `tip` = 1");
		$id = $_GET['id'];
		$q->execute(array($id));
		while($row = $q->fetch(PDO::FETCH_OBJ)) {
			$close = Config::$g_con->prepare("INSERT INTO emails (Message, playerid, LinkPanel, giverid) VALUES 
			('Cererea ta de unban a fost inchisa de adminul ".Config::getData('users', 'name', $_SESSION['user']).". Daca a fost respinsa si postezi din nou, vei primi suspend in panel.', 
			'".Config::getID('users', 'id', $row->user)."', 
			'unban?id=".$id."', 
			'".Config::getID('users', 'id', $_SESSION['user'])."')");
			$close->execute(array($id));	}
		$close = Config::$g_con->prepare("UPDATE `unban_requests` SET `status` = 1 WHERE `id` = ?");
		$close->execute(array($_GET['id']));
	}
	if(isset($_POST['submit']) && @$_POST['submit'] == 'Post' && isset($_POST['text'])) {		
		$text = htmlspecialchars($_POST['text']);
		$user = Config::getData("users", "name", $_SESSION['user']);
		$id = $_GET['id'];
		if(!empty($text) && strlen($text) >= 5) {
			$q = Config::$g_con->prepare("INSERT INTO `reply_requests`(`id`, `text`, `tip`, `user`, `data`, `status`, `idd`) VALUES ('', ?, 0, ?, CURRENT_TIMESTAMP, 0, ?)");
			$q->execute(array($text,$user,$id));
			}
	}

	if(isset($_POST['submit']) && @$_POST['submit'] == 'Sterge' && (Config::getData("users", "Admin", $_SESSION['user'])) >= 6) {
		$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `id`=? AND `tip` = 1");
		$id = $_GET['id'];
		$q->execute(array($id));
		while($row = $q->fetch(PDO::FETCH_OBJ)) {
		$close = Config::$g_con->prepare("DELETE FROM `unban_requests` WHERE `id` = ?");
		$close->execute(array($_GET['id']));
		}
		echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'unban\'/>';
	}
	$q = Config::$g_con->prepare("SELECT * FROM `unban_requests` WHERE `id`= ? AND `tip` = 1");
	$id = $_GET['id'];
	$q->execute(array($id));
	while($row = $q->fetch(PDO::FETCH_OBJ)) {

		echo '<div class="span6">
			<h4>Unban request</h4>

			Nickname: <a href="'.Config::$_PAGE_URL.'profile/'.Config::getID('users', 'id', $row->user).'">'.$row->user.'</a><br/>
			Level: '.Config::getID("users", "Level", $row->user).'<br/>
			Faction: '.Config::getID("users", "Member", $row->user).'<br/>
			Hours played: '.Config::getID("users", "ConnectedTime", $row->user).'
			<hr>
				'. $row->text .'<br/>
			<hr>
			Topic status: <b>'.($row->status ? "<b> Closed </b>" : "<b> Open </b>").'</b><br>';
		$q = Config::$g_con->prepare("SELECT * FROM `bans` WHERE `PlayerName`= ? AND `Active` = 1");
		$q->execute(array(Config::getID('users', 'name', $row->user)));
		while($row1 = $q->fetch(PDO::FETCH_OBJ)) {
			echo 'Ban type: <b>'.($row1->IPBan ? "<b> IP Ban </b>" : "<b> Normal Ban </b>").'</b><br/>';
		}
			echo'<hr>
					
		</div>';
			echo "<div class='span6'>
					
					<div class='widget-box'>
						<div class='widget-header'>
							<h4 class='widget-title lighter smaller'>
								<i class='icon-rss red'></i>
								Comments
							</h5>
						</div>
						<div class='widget-body'>
						<div class='widget-main no-padding'>
						<div class='dialogs'>
						";
						$idd_count = Config::$g_con->prepare("SELECT * FROM `reply_requests` WHERE `idd`= ?");
						$idd_count->execute(array($_GET['id']));
						if(!$idd_count->rowCount())
							echo " 
								<div class='itemdiv dialogdiv'>
									<div class='body'>
										Momentan nu exist&#259; niciun r&#259;spuns la aceast&#259; cerere.
									</div>
								</div>
								 ";
						else {						
							$query = Config::$g_con->prepare("SELECT * FROM `reply_requests` WHERE `idd`= ? AND `tip` = 0 ORDER BY `id` ASC");
							$query->execute(array($_GET['id']));
							while($r = $query->fetch(PDO::FETCH_OBJ)) {
								?>
									<div class='itemdiv dialogdiv'>
										<div class='user'>
											<img alt="<?php echo $r->user ?>'s Avatar" src="<?php echo Config::$_PAGE_URL ?>assets/images/avatars/<?php echo (Config::getID("users", "Model", $r->user)) ?>.png"/>
										</div>
										<div class='body'>
											<div class='time'>
												<i class='icon-time'></i>
												<span class='green'>
													<?php echo $r->data ?> 
												</span>
											</div>
											<div class='text'>
												<p>
													<a href="<?php echo Config::$_PAGE_URL ?>profile/<?php echo Config::getID("users", "id", $r->user) ?>"><?php echo $r->user ?></a> <?php if(((Config::getID("users", "Admin", $r->user)) >0)) { ?><span class='label label-info arrowed arrowed-in-right'>Admin</span><?php } ?>
													<br/>
													<?php echo $r->text ?>
													<span class='pull-right'>
													</span>
												</p>
											</div>
										</div>
									</div>								
						<?php	} 
						}
						echo "
						</div>
						</div>
						";
						if(!Config::getData("unban_requests", "status", $_GET['id'])) {
							echo "
							<form class='form-horizontal' method='POST' style='margin: 0 15px 20px 60px;' action='".Config::$_PAGE_URL."unban/?id=".htmlspecialchars($_GET['id'])."'>
							<h5>Leave a reply</h5>
							<textarea class='input-block-level' placeholder='reply text...' name='text'></textarea>
							<br/>

							<input type='submit' name='submit' class='btn btn-small btn-danger' value='Post'/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							";
							if(Config::getData("users", "Admin", $_SESSION['user']) >= 6) {
							echo "
							<input type='submit' name='submit' class='btn btn-small btn-success' value='Accepta'/>
							<input type='submit' name='submit' class='btn btn-small btn-yellow' value='Respinge'/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type='submit' name='submit' class='btn btn-small btn-danger' value='Sterge'/>					
							<br>
							<font size='0.8px'>
								<i> * Acceptă - se scoate banul şi cererea se închide </i>
								<br>
								<i> * Respinge - banul rămâne  şi cererea se închide </i>
							</font>
							"; } echo "
							</form>";
						} else {
							echo '
							<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="".Config::$_PAGE_URL."unban/?id=".$_GET["id"]."">
							<h5>Leave a reply</h5>
							<textarea class="input-block-level" placeholder="You can\'t reply to this topic, reason: This topic is closed." name="text" disabled></textarea>
							<br/>
							<input type="submit" name="submit" class="btn btn-small btn-danger" value="Post" disabled style="color: white;"/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							</form>';
						}
						echo "
						</div> 
					</div> 
				</div>";
		echo '</div>';
	}
}
}
?>
