<?php
if(!defined('panel'))
	die('Nope.');
if(!isset($_SESSION['user']) && !isset(Config::$_url[1])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'complaints\'/>';
if(!isset($_SESSION['user'])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'\'/>';
if(isset(Config::$_url[1])) $user = (int)Config::$_url[1];
else $user = $_SESSION['user'];
$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `id` = ?');
$q->execute(array($user));
if(!$q->rowCount()) {
	echo '
<title>Error! Invalid ID</title>
	<div class="breadcrumbs" id="breadcrumbs">
		<ul class="breadcrumb">
			<li>
				<i class="icon-home home-icon"></i>
				<a href="../">Home</a>
			</li>
			<li>
				<a href="../factionslist">Factions</a>
			</li>
			<li class="active">Invalid ID.</li>
		</ul>

		<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="alert alert-danger">Error! Invalid ID.</div>';
	echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'complaints\'/>';
	return;
}
$data = $q->fetch(PDO::FETCH_OBJ);
if(Config::$_url[1] == Config::getData('users','id',$_SESSION['user'])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'complaints\'/>';

?>
<title>Add Complaint - <?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">Create Complaint</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(Config::getData('users','ConnectedTime',$_SESSION['user']) <= 10) { die('<div class="alert alert-danger">Trebuie sa ai minim 10 ore jucate pentru a putea crea o reclamatie.</div>'); }

if(isset($_POST['submit'])) {	
	if(!$_POST['links'] && !$_POST['desc']) { echo '<div class="alert alert-danger">Completează toate campurile.</div>'; }
	else if (strpos($_POST['links'], 'window.location') !== false) {
	}
	else if (strpos($_POST['desc'], 'window.location') !== false) {
	}		
	else { 
		echo '<div class="alert alert-success">Reclamatie creata cu succes.</div>';
		echo '<meta http-equiv="refresh" content="2;URL=\''.Config::$_PAGE_URL.'complaints\'/>';
		
		if($_POST['reasoncomplaint'] == "1") {
			$faction = $data->Member;
		} else {
			$faction = 0;
		}
		$q = Config::$g_con->prepare('INSERT INTO `complaints` (`playername`, `createdby`, `reasoncomplaint`, `evidence`, `details`, `ip`, `factionid`) VALUES (?, ?, ?, ?, ?, ?, ?)');
  		$q->execute(array($data->name,Config::getData('users','name',$_SESSION['user']),$_POST['reasoncomplaint'],$_POST['links'],$_POST['desc'],$_SERVER['SERVER_ADDR'],$faction));
 		$qp = Config::$g_con->prepare("INSERT INTO emails (Message, LinkPanel, playerid)
			VALUES ('".Config::getData('users','name',$_SESSION['user'])." ti-a facut o reclamatie.','complaints', '".Config::getID('users', 'id', $data->name)."')");		$qp->execute();
  }
}
if($data->Admin >0) { ?>	
<div class="alert alert-danger">
Reclamatiile impotriva unui admin/helper se fac DOAR pentru chestii grave.<br>Orice reclamatie facuta pentru un mute/kick va fi ignorata iar playerul ce a facut reclamatia va fi sanctionat cu suspend 5 - 30 zile in panel.<br>Daca stii ca esti vinovat si faci reclamatie doar pentru a vedea dovezile vei fi sanctiont cu suspend 5-30 zile in panel.<br>Daca ti s-a raspuns la o reclamatie si ti s-a zis ca sunt dovezi insuficiente, in 99% din cazuri si adminul ce va raspunde la reclamatiile pentru admini va spune acelasi lucru.<br>Nu crea reclamatii daca nu e ceva grav sau poti fi sanctionat cu suspend 5-30 zile in panel.
</div>	
<?php } ?>
	
<div class="span4">
<h4>Player reclamat</h4>
<ul>
<li>Nickname: <?php echo $data->name ?></li>
<li>Factiune: <?php echo Config::$factions[$data->Member] ?></li>
<li>Level: <?php echo $data->Level ?></li>
<li>Ore jucate: <?php echo $data->ConnectedTime ?></li>
</ul>
<h4>Info</h4>
<ul>
<li>Inainte de a reclama un player, cititi <a href="http://wster-rpg.cf/forum/index.php?/topic/1-regulament-server/">regulamentul serverului</a>. Daca faceti reclamatie unui lider, cititi si <a href="http://wster-rpg.cf/forum/index.php?/topic/2-regulament-lideri/">regulamentul liderilor</a>.</li>
<li>Puteti uploada imagini pe site-uri ca <a href="http://imgur.com" target="_blank">imgur</a>.</li>
</ul>
</div>
<div class="span6">
<h4>Creaza o reclamatie</h4>
<form method="POST" action="" accept-charset="UTF-8">
<label for="name">Motiv reclamatie</label><br />
<select name="reasoncomplaint">
	<?php if($data->Member > 0) { ?><option value="1">Factiune</option><?php } ?>
	<option value="2">DM</option>
	<option value="3">Jigniri, injurii, limbaj vulgar</option>
	<option value="4">Inselatorie</option>
	<option value="5">Altceva (abuz, comportament non RP)</option>
	<?php if($data->Admin > 0 or $data->Helper > 0) { ?><option value="6">Abuz admin/helper</option><?php } ?>
	<?php if($data->Leader >0) { ?><option value="7">Greseli ca lider</option><?php } ?>
</select> 

<br/><br />

<div>
	<label for="form-field-8">Dovezi (screenshot-uri, video-uri)</label>
	<textarea class="form-control" id="form-field-6" rows="3" name="links" cols="50"></textarea>
</div>
<br />
<div>
	<label for="form-field-8">Detalii</label>
	<textarea class="form-control" id="form-field-6" rows="3" name="desc" cols="50"></textarea>
</div>
<br />
<input class="btn btn-small btn-danger" name="submit" type="submit" value="Post complaint">
</form>
</div>
