<?php

/* PROGRAMAÇÃO BY: BINHO, FUNDADOR DA CTGAMES - TEAM SOFTWARES */

if($_GET["enviar"] == true) {
function formata($texto) {
	$msg1 = stripslashes($texto);
	$msg2 = html_entity_decode($msg1);
	$mensagem = nl2br($msg2);
	return $mensagem;
}
$personagem = $_GET["aticket_personagem"];
$assunto = $_GET["aticket_assunto"];
$msg = $_GET["aticket_msg"];
$ver_char = mssql_num_rows(mssql_query("select name from character where name='".$personagem."' and accountid='".$_SESSION["login"]."'"));
if($personagem == "" || $assunto == "" || empty($msg)) {
	exit($bbcode->bbcode('<div class="box_conteudo">Preencha todos os campos</div>'));
}
elseif($ver_char < 1) {
	exit($bbcode->bbcode('<div class="box_conteudo">Personagem inválido</div>'));
}
else{
	$data = date("d / m / Y");
	$data2 = "&aacute;s";
	$data3 = date("H:i");
	mssql_query("insert into ct_tickets (login,personagem,assunto,data,msg,status) values ('".$_SESSION["login"]."','".$personagem."','".formata($assunto)."','".$data." ".$data2." ".$data3."','".formata($msg)."','0')");
	exit($bbcode->bbcode('<div class="box_conteudo">Ticket enviado, aguarde a resposta</div>'));
}
}

if($_GET["ver"] == true) {
$id = $_GET["id"];
$dados = mssql_fetch_row(mssql_query("select personagem,msg,status from ct_tickets where id='".$id."'"));
$foto = mssql_fetch_row(mssql_query("select imagem from character where name='".$dados[0]."'"));
$cargo = mssql_fetch_row(mssql_query("select cargo from ct_equipe where login='".$_SESSION["login"]."'"));
if($cargo[0] > 1) {
	$op = '<a href="javascript: void(0);" onclick="loading(\'?go=ticket&fechar=true&id='.$id.'\' ,\'ticket\');">Fechar ticket</a>';
}
if($dados[2] > 0) {
	$st = '<a href="javascript: void(0);" onclick="loading(\'?go=ticket&abrir=true&id='.$id.'\' ,\'ticket\');">| Abrir ticket</a>';
}
	echo '
<div class="about-team-page-top-wrap" style="padding-bottom: 0px; margin-top: -5px;">
    <div class="top-title" style="width: 100%;">
        <h2 style="color: #fff; font-size: 30px; margin-left: 30px; border-color: darkgray;">VISUALIZACAO DE TICKETS.</h2>
    </div>
</div>
<div class="match-list-wrap">
<br />
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><div align="center"><img src="images/personagens/'.$foto[0].'" width="120" height="140" /></div></td>
      </tr>
    </table></td>
    <td width="80%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td style="padding-left: 10px; color:#fff;">Enviado por: <strong>'.$dados[0].'</strong></td>
    <td align="right"><a href="javascript: void(0);" onclick="loading(\'?go=ticket&deletar=true&id='.$id.'\' ,\'ticket\');">Deletar ticket</a> | '.$op.' '.$st.'</td>
  </tr>
</table>
</td>
      </tr>
      <tr>
        <td style="padding-left: 10px; color:#fff;">'.$dados[1].'</td>
      </tr>
    </table></td>
  </tr>
</table>
<br />
<br />
</div>';
if($dados[2] == 0) {
	echo '<div class="box_conteudo" align="right"><label><input type="submit" name="responder" id="responder" onclick="loading(\'?go=ticket&comentar=true&id='.$id.'\', \'ticket\');" value="Responder" /></label></div>';
}
else{
	echo $bbcode->bbcode('<div class="box_conteudo" align="right">Este ticket não pode ser comentada</div>');
}
echo '<div id="ticket"></div>';
$coments = mssql_query("select personagem,msg from CT_TICKETS_COMENTARIOS where ticketid='".$id."'");
for($i=0;$i<mssql_num_rows($coments);$i++) {
$pega_coments = mssql_fetch_row($coments);
$imagem = mssql_fetch_row(mssql_query("select imagem from character where name='".$pega_coments[0]."'"));
echo '
<div class="about-team-page-top-wrap" style="padding-bottom: 0px; margin-top: -5px;">
    <div class="top-title" style="width: 100%;">
        <h2 style="color: #fff; font-size: 30px; margin-left: 30px; border-color: darkgray;">RESPOSTAS.</h2>
    </div>
</div>
<div class="match-list-wrap">
<br />
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><div align="center"><img src="images/personagens/'.$imagem[0].'" width="120" height="140" /></div></td>
      </tr>
    </table></td>
    <td width="80%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>

    <td style="padding-left: 10px; color:#fff">Respondido por: <strong>'.$pega_coments[0].'</strong></td>
  </tr>
</table>
</td>
      </tr>
      <tr>
        <td style="padding-left: 10px; color:#ff;"><font color="#fff">'.$pega_coments[1].'</font></td>
      </tr>
    </table></td>
  </tr>
</table>

<br><br>
</div>';
}
}
if($_GET["deletar"] == true) {
$id = $_GET["id"];
mssql_query("delete ct_tickets where id='".$id."'");
mssql_query("delete ct_tickets_comentarios where ticketid='".$id."'");
exit($bbcode->bbcode('<div class="box_conteudo" STYLE="COLOR:#FFF">Ticket deletado com sucesso</div>'));
}
if($_GET["comentar"] == true) {
$id = $_GET["id"];
   echo $bbcode->bbcode('
<div class="about-team-page-top-wrap" style="padding-bottom: 0px; margin-top: -5px;">
    <div class="top-title" style="width: 100%;">
        <h2 style="color: #fff; font-size: 30px; margin-left: 30px; border-color: darkgray;">Responder Ticket.</h2>
    </div>
</div>
<div class="match-list-wrap" style="color: #FFF">
<br />
<br />
   Personagem: <select name="char" id="char">');
   $perso = mssql_query("select name from character where accountid='".$_SESSION["login"]."'");
   for($i=0;$i<mssql_num_rows($perso);$i++) {
   	$pega = mssql_fetch_row($perso); 
	echo $bbcode->bbcode('<option value="'.$pega[0].'">'.$pega[0].'</option>');
}
   echo $bbcode->bbcode('</select>
   <br>
   <br>
  <label><textarea name="comentario" id="comentario" cols="45" rows="5"  style="position:relative; left:20px;"></textarea>
    <br>
    <br>
  </label><label><input type="submit" name="comentar" id="comentar" onclick="loading(\'?go=ticket&inserir=true&id='.$id.'\'+\'&char=\'+document.getElementById(\'char\').value+\'&comentario=\'+document.getElementById(\'comentario\').value, \'ticket\');" value="Responder"  style="position:relative; left:20px;"/></label>
  <br>
  <br>
</div>');
}
if($_GET["inserir"] == true) {
function formata($texto) {
	$msg1 = stripslashes($texto);
	$msg2 = html_entity_decode($msg1);
	$mensagem = nl2br($msg2);
	return $mensagem;
}
$id = $_GET["id"];
$char = $_GET["char"];
$msg = $_GET["comentario"];
if($char == "" || empty($msg)) {
	exit($bbcode->bbcode('<div class="box_conteudo" STYLE="COLOR:#FFF">Preencha todos os campos</div>'));
}
else{
	mssql_query("insert into CT_TICKETS_COMENTARIOS (personagem,msg,ticketid) values ('$char','".formata($msg)."','$id')");
	echo $bbcode->bbcode('<div class="box_conteudo" STYLE="COLOR:#FFF">Ticket respondido com sucesso</div>');
}
}

if($_GET["fechar"] == true) {
mssql_query("update ct_tickets set status='1' where id='".$_GET["id"]."'");
exit($bbcode->bbcode('<div class="box_conteudo" STYLE="COLOR:RED">Ticket fechado com sucesso</div>'));
}
if($_GET["abrir"] == true) {
mssql_query("update ct_tickets set status='0' where id='".$_GET["id"]."'");
exit($bbcode->bbcode('<div class="box_conteudo" STYLE="COLOR:#6C0">Ticket aberto com sucesso</div>'));
}
?>