<title>Ticket - <?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>
								<a href="<?php echo Config::$_PAGE_URL; ?>tickets">Tickets</a>
							</li>
							<li class="active">Ticket</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(Config::$_url[1])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'tickets\'/>';
if(!isset($_SESSION['user'])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'login\'/>';
if(!Config::getData('users','Admin',$_SESSION['user']))
{
	$d = Config::$g_con->prepare('SELECT * FROM `tickets` WHERE `id` = ?');
	$d->execute(array(Config::$_url[1]));
	while($reply = $d->fetch(PDO::FETCH_OBJ)) 
	{
		if(Config::getData('users','name',$_SESSION['user']) !== $reply->Name)
		echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'tickets\'/>';
	}
}

$q = Config::$g_con->prepare('SELECT * FROM `tickets` WHERE `id` = ?');
$q->execute(array(Config::$_url[1]));
while($row = $q->fetch(PDO::FETCH_OBJ)) 
{

if(isset($_POST['send'])) {
if(!$_POST['text']) { echo '<div class="alert alert-danger">Nu poti trimite un mesaj gol.</div>'; }
	else if (strpos($_POST['text'], 'window.location') !== false) {
	}
	else if(Config::getData('users', 'Admin', $_SESSION['user']) >= 1){
			$text = htmlspecialchars($_POST['text']);
			echo '<div class="alert alert-success">Ai răspuns cu succes ticketului.</div>';

			$email = Config::$g_con->prepare("INSERT INTO emails (Message, playerid, LinkPanel, giverid) VALUES
				('".Config::getData('users', 'name', $_SESSION['user'])." a raspuns la ticket-ul tau.',
				'".Config::getID('users', 'id', $row->Name)."',
				'ticket/".Config::$_url[1]."',
				'".Config::getID('users', 'id', $_SESSION['user'])."')");
			$email->execute();

			$q = Config::$g_con->prepare('INSERT INTO `reply_tickets` (`text`, `user`, `idd`) VALUES (?, ?, ?)');
			$q->execute(array($text,Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));

			echo '<meta http-equiv="refresh" content="2">';
	}
	else {
		$text = htmlspecialchars($_POST['text']);

		$q = Config::$g_con->prepare('INSERT INTO `reply_tickets` (`text`, `user`, `idd`) VALUES (?, ?, ?)');
		$q->execute(array($text,Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));

		echo '<meta http-equiv="refresh" content="2">';
	}
}

if(isset($_POST['delete']) && Config::getData('users','Admin',$_SESSION['user']) >= 6) {
	$q = Config::$g_con->prepare('DELETE FROM `tickets` WHERE `id` = ?');
	$q->execute(array(Config::$_url[1]));
	
	echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'tickets\'/>';
}

if(isset($_POST['postclose']) && Config::getData('users','Admin',$_SESSION['user']) >= 1) {
	if(!$_POST['text']) echo '<div class="alert alert-danger">Nu po&#355;i trimite un mesaj gol.</div>';
	else if(Config::getData('users', 'Admin', $_SESSION['user']) >= 1){
		echo '<div class="alert alert-success">Ai raspuns cu succes tichetului si l-ai inchis.</div>';
		
		$q = Config::$g_con->prepare('INSERT INTO `reply_tickets` (`text`, `user`, `idd`) VALUES (?, ?, ?)');
		$q->execute(array(" ". $_POST['text'] ." <br /><b>Admin action:</b> Topic Closed!",Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));

		$email = Config::$g_con->prepare("INSERT INTO emails (Message, playerid, LinkPanel, giverid) VALUES 
			('".Config::getData('users', 'name', $_SESSION['user'])." a raspuns si a inchis ticket-ul tau.',
			'".Config::getID('users', 'id', $row->Name)."', 
			'ticket/".Config::$_url[1]."', 
			'".Config::getID('users', 'id', $_SESSION['user'])."')");
		$email->execute();				
				
		$q = Config::$g_con->prepare('UPDATE `tickets` SET `Status` = ? WHERE `id` = ?');
		$q->execute(array(1,Config::$_url[1]));		
		
		echo '<meta http-equiv="refresh" content="2">';
	}
}

if(isset($_POST['retrage'])) {
	echo '<div class="alert alert-danger">Ai inchis tichetul cu succes.</div>';

		$q = Config::$g_con->prepare('UPDATE `tickets` SET `Status` = ? WHERE `id` = ?');
		$q->execute(array(1,Config::$_url[1]));

		$text = "<b>User action:</b> Topic solved & closed!";
		$q = Config::$g_con->prepare('INSERT INTO `reply_tickets` (`text`, `user`, `idd`) VALUES (?, ?, ?)');
		$q->execute(array($text,Config::getData('users','name',$_SESSION['user']),Config::$_url[1]));
		
		echo '<meta http-equiv="refresh" content="2">';		
}

		$s = Config::$g_con->prepare('SELECT * FROM `tickets` WHERE `id` = ?');
		$s->execute(array(Config::$_url[1]));
			while($roww2 = $s->fetch(PDO::FETCH_OBJ)) { 
if($roww2->Status == 1) {
echo"<div class='alert alert-warning'>
This ticket is closed. Only admins can reply to it!
</div>";
} }
?>
<div class="row-fluid">
<div class="span6">
<h4>Ticket status</h4>
<hr>
<?php echo $row->Ticket ?><br/>
<hr>
Ticket type: <b><?php echo ($row->type ? 'Probleme cu platile pentru puncte premium' : 'Problema generala') ?></b><br/>
Ticket status: <b><?php echo ($row->Status ? 'Closed' : 'Open'); ?></b><br>
Created at: <b><?php echo $row->time ?></b><br/>
<br/>
<?php if($row->Name == Config::getData('users','name',$_SESSION['user']) && $row->Status == 0) { ?>
<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="" disabled>
<button name="retrage" type="submit" class="btn btn-small btn-success">Marcheaza ca rezolvat</button>
</form>
<?php } ?>
<hr>
<b>Nickname:</b> <a href="<?php echo Config::$_PAGE_URL; ?>profile/<?php echo $row->idd ?>"><?php echo $row->Name ?></a><br/>
<b>Level:</b> <?php echo Config::getID('users','Level',$row->Name) ?><br/>
<b>Faction:</b> <?php echo Config::getID('users','Member',$row->Name) ?>
<br/>
<b>Hours played:</b> <?php echo Config::getID('users','ConnectedTime',$row->Name) ?><br/>
<?php if(Config::getID('users','Email',$row->Name) == "email@yahoo.com") {
	$email = "(UNCONFIRMED)";
} else {
	$email = Config::getID('users','Email',$row->Name);
} ?>
<b>Email:</b> <?php echo $email ?><br>
<b>Premium points:</b> <?php echo Config::getID('users','PremiumPoints',$row->Name) ?><br>
<hr>
</div>
<div class="span6">
<h4>Comments</h4>
<hr>
<div class="widget-box ">
<div class="widget-header widget-header-flat widget-header-small">
<h4 class="lighter smaller">
<i class="icon-rss red"></i>
Comments
</h4>
</div>
<div class="widget-body">
<div class="widget-main no-padding">
<div class="dialogs">
	<?php
		$s = Config::$g_con->prepare('SELECT * FROM `reply_tickets` WHERE `idd` = ? ORDER BY `id` ASC');
		$s->execute(array(Config::$_url[1]));
		while($row2 = $s->fetch(PDO::FETCH_OBJ)) { ?>
<div class="itemdiv dialogdiv">
<div class="user">
<img alt="<?php echo Config::getID('users','name',$row2->user); ?>'s Avatar" src="<?php echo Config::$_PAGE_URL; ?>assets/images/avatars/<?php echo Config::getID('users','Model',$row2->user); ?>.png"/>
</div>
<div class="body ">
<div class="time">
<i class="icon-time"></i>
<span class="green">
<?php echo $row2->time ?>
</span>
</div>
<div class="text">

<a href="<?php echo Config::$_PAGE_URL; ?>profile/<?php echo Config::getID('users','id',$row2->user); ?>" title=""><?php echo Config::getID('users','name',$row2->user); ?></a>
<?php if($row->Name == Config::getID('users','name',$row2->user)) { echo'<span class="badge badge-info">ticket creator</span>'; } ?>
<?php if(Config::getID('users','Admin',$row2->user) > 0 && Config::getID('users','Admin',$row2->user) < 5) { echo'<span class="label label-purple arrowed arrowed-in-right">admin</span>'; } ?>
<?php if(Config::getID('users','Admin',$row2->user) >= 6) { echo'<span class="label label-purple arrowed arrowed-in-right">owner</span>'; } ?>

<br/>
<span class="comment">
<?php echo $row2->text ?>
</span>
<span class="pull-right">
</span>

</div>
</div>
</div>
<?php } ?>
</div>

<?php if(isset($_SESSION['user']) && (Config::getData('users','Admin',$_SESSION['user'])) > 0) { ?>
<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="" disabled>
<h5>Leave a reply</h5>
<textarea class="input-block-level" placeholder="ADMIN REPLY: reply text..." name="text"></textarea>
<br/><br/>
<input type="submit" name="send" class="btn btn-small btn-danger" value="Post"/>
<input type="submit" name="postclose" class="btn btn-small btn-danger" value="Post and close"/>
<?php if(Config::getData('users','Admin',$_SESSION['user']) >= 6) {	?>
<input type="submit" name="delete" class="btn btn-small btn-danger" value="Delete"/> <?php }?>
</form>
<?php } else if(isset($_SESSION['user']) && Config::getData('tickets','Status',Config::$_url[1]) == 0) { ?>
<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="" disabled>
<h5>Leave a reply</h5>
<textarea class="input-block-level" placeholder="reply text..." name="text"></textarea>
<br/><br/>
<input type="submit" name="send" class="btn btn-small btn-danger" value="Post"/>
<?php if(isset($_SESSION['user']) && (Config::getData('users','Admin',$_SESSION['user']))) { ?>
<input type="submit" name="postclose" class="btn btn-small btn-danger" value="Post and close"/>
<?php if(Config::getData('users','Admin',$_SESSION['user']) >= 6) {	?>
<input type="submit" name="delete" class="btn btn-small btn-danger" value="Delete"/> <?php }?>
<?php } ?>
</form>
<?php } else if(isset($_SESSION['user']) && ($row->Status) == 1) { ?>
<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="" disabled>
<h5>Leave a reply</h5>
<textarea class="input-block-level" placeholder="You can&#039;t reply to this topic, reason: This topic is closed." name="text" disabled></textarea>
<br/><br/>
<input type="submit" name="submit" class="btn btn-small btn-danger" value="Post" disabled />
<form>
<?php } else { ?>
<form class="form-horizontal" method="POST" style="margin: 0 15px 20px 60px;" action="" disabled>
<h5>Leave a reply</h5>
<textarea class="input-block-level" placeholder="You can&#039;t reply to this topic, reason: You are not logged in." name="text" disabled></textarea>
<br/><br/>
<input type="submit" class="btn btn-small btn-danger" value="Post" disabled />
<form>
<?php } ?>
</div> 
</div> 
</div> 
</div>
</div>
<?php } ?>
 
