<?php
    //Incluindo a conexão com banco de dados   
	include("config/conexao.php"); 
    include("cabecalho.php");
	
	//Chamado
	$id = $_GET['id'];
	$cliente = $_SESSION['codCliente']; 	
	$sql  = "SELECT * FROM glpi_tickets WHERE id = '{$id}' and empresa_id ='{$cliente}'  "; //INNER JOIN glpi_useremails um on u.id = um.users_id 
	$res = mysqli_query($conn, $sql);	
	$row_rec = mysqli_fetch_array($res);
	$row = mysqli_num_rows($res);
	//Acompanhamentos
	$sql1  = "SELECT * FROM glpi_itilfollowups WHERE items_id = '{$id}' AND timeline_position = 4 Order By id DESC";
	$res1 = mysqli_query($conn, $sql1);
	$row1  = mysqli_num_rows($res1);
	//Documentos
 	$sql2  = "SELECT * FROM glpi_documents WHERE tickets_id = '{$id}' ";
	$res2 = mysqli_query($conn, $sql2);
	$row2  = mysqli_num_rows($res2);
	//Tasks
  	$sql4  = "SELECT * FROM glpi_tickettasks WHERE tickets_id = '{$id}' AND timeline_position = 4 Order By id DESC";
	$res4 = mysqli_query($conn, $sql4);
	$row4  = mysqli_num_rows($res4);
	//Solução
  	$sql3  = "SELECT * FROM glpi_itilsolutions WHERE items_id = '{$id}' ";
	$res3 = mysqli_query($conn, $sql3);
	$row3  = mysqli_num_rows($res3);
	//Aceite
  	$sql5  = "SELECT * FROM glpi_itilfollowups WHERE items_id = '{$id}' AND timeline_position = 1 Order By id DESC";
	$res5 = mysqli_query($conn, $sql5);
	$row5  = mysqli_num_rows($res5);



 
	$atend = 'hidden';
	$arquivo = 'hidden';
	$task = 'hidden';
	$solu = 'hidden';
	$fechamento = 'hidden';

	if ($row == 0){ ?>
 		<script language="JavaScript" type="text/javascript"> alert ("Não é possível acessar a sua solicitação.")</script>
                <script language="JavaScript">window.location.href="../atendimentos.php";</script> 
	<?php } else {	
	
?>

    <div id="page-wrapper">
      <div class="page-content">
        <div class="row">
          <div class="col-lg-12">
            <div class="page-title">
              <ol class="breadcrumb">
                <li>
                  <i class="fa fa-home"></i> <a href="home.php">Home</a>
                </li>
				<li>
				  <i class="fa fa-comments"></i> <a href="atendimentos.php">Atendimentos</a>	
				</li>
                <li class="active"><i class="fa fa-tasks"></i> Acompanhar</li>
              </ol>
            </div>
          </div>
        </div>
		<?php $teste = 'hidden'; ?>
				<div>
					<div class="row">
						<div class="col-lg-4">
							<a href="#" class="btn btn-primary btn-lg btn-block" role="button" aria-pressed="true" data-toggle="modal" data-target="#NovoAcompanhamento" data-placement="top" title="Novo"> 
								<i class="fa fa-comments"></i>Acompanhamento 
								<?php 
									$target = "NovoAcompanhamento";
									$titulo = "Novo Acompanhamento";
									$caminho = "acao=cadacomp";
								?>
							</a>
						</div>				
						<div class="col-lg-4">
							<a href="#" class="btn btn-info btn-lg btn-block" role="button" aria-pressed="true" data-toggle="modal" data-target="#NovoArquivo" data-placement="top" title="Novo">  
								Enviar Arquivo   
							</a>
						</div>						
<!--						<div class="col-lg-3">
							<a href="#" class="btn btn-warning btn-lg btn-block" role="button" aria-pressed="true">      Tarefa    </a>
						</div>
-->						<div class="col-lg-4">
							<a href="#" class="btn btn-success btn-lg btn-block" role="button" aria-pressed="true" data-toggle="modal" data-target="#NovaFechamento" data-placement="top" title="Fechar">
								Fechar Chamado							
							</a>
						</div>
					</div>
				</div>	
<br>

		<!-- Fechamento --->
		<?php if ($row5 > 0){ 
				$fechamento = '';
				while($row5 = mysqli_fetch_assoc($res5)){ ?>
				<div <?php echo $fechamento;?>>		  
					<?php
						if ($row5['users_id'] == $_SESSION['usuarioId']){ ?>
							<div class="box-fechamento right-block"><?php
						} else {?> 	
							<div class="box-fechamento left-block"><?php
						} ?>	
								<!------------------------>
								<dl class="dl-vertical">
									<dt>Descrição:</dt>
									<dd><?php echo utf8_encode(str_replace("&lt;p&gt;","",str_replace("&lt;/p&gt;","",$row5['content']))); ?></dd>
								<dl>
							   <!------------------------>	
						  </div>
							   
				</div>
				<?php 
			}
		} 
		?>					
		<!-- Solução --->
		<?php if ($row3 > 0){ 
				$solu = '';
				while($row3 = mysqli_fetch_assoc($res3)){ ?>
				<div <?php echo $solu;?>>
					<?php
						if ($row3['users_id'] == $_SESSION['usuarioId']){ ?>
							<div class="box-solucao right-block"><?php
						} else {?> 	
							<div class="box-solucao left-block"><?php
						} ?>	
								<!------------------------>
								<dl class="dl-vertical">
									<dt>Descrição:</dt>
									<dd><?php echo utf8_encode(str_replace("&lt;p&gt;","",str_replace("&lt;/p&gt;","",$row3['content']))); ?></dd>
								<dl>
							   <!------------------------>	
							</div>  
				</div>
				<?php 
			}
		} 
		?>	
		<!-- Tasks --->
                <?php if($row4 > 0) {
	$task = '';
				while($row4 = mysqli_fetch_assoc($res4)){ ?>
				<div <?php echo $task;?>>
					<?php
						if ($row4['users_id'] == $_SESSION['usuarioId']){ ?>
							<div class="box-tasks right-block"><?php
						} else {?> 	
							<div class="box-tasks left-block"><?php
						} ?>	
								<!------------------------>
								<dl class="dl-vertical">
									<dt>Descrição:</dt>
									<dd><?php echo utf8_encode(str_replace("&lt;p&gt;","",str_replace("&lt;/p&gt;","",$row4['content']))); ?></dd>
								<dl>
							   <!------------------------>	
							</div>  
				</div>
				<?php 
			}
		} 
		?>



		


		<!-- Documentos --->
		<?php if ($row2 > 0){ 
				$arquivo = ''; 
				if ($row4['users_id'] == $_SESSION['usuarioId']){ ?>
					<div class="box-arquivo right-block" <?php echo ($arquivo);?>><?php
				} else {?> 	
					<div class="box-arquivo left-block" <?php echo ($arquivo);?>><?php
				} 
				while($row2 = mysqli_fetch_assoc($res2)){ ?>				
         					<!------------------------>
							<dl class="dl-vertical">
								<dt>Documentos</dt>
								<dd><a href="../../glpi/files/<?php echo ($row2['filepath']); ?>"><?php echo $row2['filename']; ?></a></dd>
							<dl>									 
						   <!------------------------>
						 		

				<?php 
			 } ?>
			 </div> <?php
		} 
		?>				
		<!-- Acompanhamento --->
		<?php if ($row1 > 0){ 
				$atend = '';
				while($row1 = mysqli_fetch_assoc($res1)){ ?>

				<div <?php echo $atend;?>>
					<?php
						if ($row1['users_id'] == $_SESSION['usuarioId']){ ?>
							<div class="box-atendimento right-block"><?php
						} else {?> 	
							<div class="box-atendimento left-block"><?php
						} ?>	
										<!------------------------>
										<dl class="dl-vertical">
											<dt>Acompanhamento</dt>
											<dt>Descrição:</dt>
											<dd><?php echo (str_replace("&lt;p&gt;","",str_replace("&lt;/p&gt;","",$row1['content']))); ?></dd>
										<dl>
									   <!------------------------>	
							</div>					
				<?php 
			}
		} 
		?>
		<!-- Chamado --->
		<div class="box-chamado center-block">
					<h3 class="text-center">CHAMADO</h3>
					<!------------------------>
					<dl class="dl-vertical">
						<dt>Título:</dt>
						<dd><?php echo ($row_rec['name']); ?></dd>
						<br>
						<dt>Descrição:</dt>
						<dd><?php echo ($row_rec['content']); ?></dd>
					<dl>
				   <!------------------------>	
		</div>
      </div>
    </div>
  </div>
<?php } ?>
  <!-- -------------------------------------------------------------------------------------------------------------------------->
    <div class="modal modal-flex fade" id="NovoAcompanhamento" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
      <div class="modal-dialog">
		 <form  action="config/script_chamado.php?acao=cadacomp" method="POST" enctype="multipart/form-data">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" id="CloseModal" name="CloseModal" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="flexModalLabel" style="color:white;">
				  <i class="fa fa-comments"></i> Novo Acompanhamento
				</h4>
			  </div>
			 <div class="modal-body">
				<div id="basicFormExample" class="panel-collapse collapse in">
				  <div class="portlet-body">
					<!------------------------>
	
					<div class= "row">		
						<div class= "row">
							<div class="col-lg-12">
								<div class="form-group">
								  <label><b>Descrição:</b></label>
								  <input type="hidden" name="ID_USUARIO" id="ID_USUARIO" value="<?php echo $_SESSION['usuarioId']; ?>"/>
								  <input type="hidden" name="id_ticket" id="id_ticket" value="<?php echo $id; ?>"/>
								  <textarea class="form-control" rows="10" placeholder="Descreva detalhadamente o problema." name="descricao" id="descricao"></textarea>
								</div>
							</div>					
						</div>
					</div>	
				   <!------------------------>
				  </div>
			    </div>
			  </div>	
			  <div class="modal-footer">
				<button type="button" id="Cancelar" name="Cancelar" class="btn btn-default" data-dismiss="modal">Cancelar</button>
				<button type="submit" id="Salvar" name="Salvar" onclick="return ValidarCadastro();" class="btn btn-green">
				  <i class="fa fa-save"></i> Salvar
				</button>
			  </div>
			</div>
		</form>	
      </div>
    </div>
  <!-- -------------------------------------------------------------------------------------------------------------------------->
     <div class="modal modal-flex fade" id="NovoArquivo" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
      <div class="modal-dialog">
		 <form  action="config/script_chamado.php?acao=cadarq" method="POST" enctype="multipart/form-data">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" id="CloseModal" name="CloseModal" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="flexModalLabel" style="color:white;">
				  <i class="fa fa-comments"></i> Novo Arquivo
				</h4>
			  </div>
			 <div class="modal-body">
				<div id="basicFormExample" class="panel-collapse collapse in">
				  <div class="portlet-body">
					<!------------------------>
	
					<div class= "row">		
						<div class= "row">
							<div class="col-lg-12">
								<div class="form-group">
								  <label><b>Descrição:</b></label>
								  <input type="hidden" name="ID_USUARIO" id="ID_USUARIO" value="<?php echo $_SESSION['usuarioId']; ?>"/>
								  <input type="hidden" name="id_ticket" id="id_ticket" value="<?php echo $id; ?>"/>
  								  <div class="row dropzone" id="dropzone">
									<!--<form action="upload.php" class="dropzone" id="meuPrimeiroDropzone">					-->
										<div class="fallback"> 
											<input type="file" placeholder="Selecione os arquivos" id="arquivos" name="arquivos[]"  multiple /> 
										</div> 
									<!--</form>-->
								  </div> 					
								</div>
							</div>					
						</div>
					</div>	
				   <!------------------------>
				  </div>
			    </div>
			  </div>	
			  <div class="modal-footer">
				<button type="button" id="Cancelar" name="Cancelar" class="btn btn-default" data-dismiss="modal">Cancelar</button>
				<button type="submit" id="Salvar" name="Salvar" onclick="return ValidarCadastro();" class="btn btn-green">
				  <i class="fa fa-save"></i> Salvar
				</button>
			  </div>
			</div>
		</form>	
      </div>
    </div>
  <!-- --------------------------------------------------------------------------------------------------------------------------> 
    <div class="modal modal-flex fade" id="NovaFechamento" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
      <div class="modal-dialog">
		 <form  action="config/script_chamado.php?acao=cadafech" method="POST" enctype="multipart/form-data">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" id="CloseModal" name="CloseModal" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="flexModalLabel" style="color:white;">
				  <i class="fa fa-comments"></i> Fechamento
				</h4>
			  </div>
			 <div class="modal-body">
				<div id="basicFormExample" class="panel-collapse collapse in">
				  <div class="portlet-body">
					<!------------------------>
	
					<div class= "row">		
						<div class= "row">
							<div class="col-lg-12">
								<div class="form-group">
								  <label><b>Descrição:</b></label>
								  <input type="hidden" name="ID_USUARIO" id="ID_USUARIO" value="<?php echo $_SESSION['usuarioId']; ?>"/>
								  <input type="hidden" name="id_ticket" id="id_ticket" value="<?php echo $id; ?>"/>
								  <textarea class="form-control" rows="10" placeholder="Descreva detalhadamente o problema." name="descricao" id="descricao"></textarea>
								</div>
							</div>					
						</div>
					</div>	
				   <!------------------------>
				  </div>
			    </div>
			  </div>	
			  <div class="modal-footer">
				<button type="button" id="Cancelar" name="Cancelar" class="btn btn-default" data-dismiss="modal">Cancelar</button>
				<button type="submit" id="Salvar" name="Salvar" onclick="return ValidarCadastro();" class="btn btn-green">
				  <i class="fa fa-save"></i> Salvar
				</button>
			  </div>
			</div>
		</form>	
      </div>
    </div>

  <!-- --------------------------------------------------------------------------------------------------------------------------> 
  
  
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>		
  <script src="js/jquery/jquery-1.8.1.js"></script>
  <script src="js/jquery/jquery.maskedinput.js"></script>
  <!--<script src="js/jquery/jquery.cadastro.usuario.js"></script>-->
  <script src="js/bootstrap/bootstrap.min.js"></script>
  <script src="js/slimscroll/jquery.slimscroll.min.js"></script>
  <script src="js/popupoverlay/jquery.popupoverlay.js"></script>
  <script src="js/popupoverlay/defaults.js"></script>
  <script src="js/popupoverlay/logout.js"></script>
  <script src="js/hisrc/hisrc.js"></script>
  <script src="js/datatables/jquery.dataTables.js"></script>
  <script src="js/datatables/datatables-bs3.js"></script>
  <script src="js/jquery/jquery.Layout.js"></script>

		<script type="text/javascript">
		$(function(){
			$('#TIPO').change(function(){
				if( $(this).val() ) {
					$('#CATEGORIA').hide();
					$('.carregando').show();
					$.getJSON('config/categorias.php?search=',{TIPO: $(this).val(), ajax: 'true'}, function(j){
						var options = '<option value="">Escolha Subcategoria</option>';	
						console.log(options);
						for (var i = 0; i < j.length; i++) {
							options += '<option value="' + j[i].id + '">' + j[i].completename + '</option>';
						}	
						$('#CATEGORIA').html(options).show();
						$('.carregando').hide();
					});
				} else {
					$('#CATEGORIA').html('<option value="">– Escolha Subcategoria –</option>');
				}
			});
		});
		</script>
		<script>
//			var meuDropzone = new Dropzone("#dropzone", {url:"update.php"});	
//			$("#dropzone").dropzone({ url: "update.php" });
			var meuDropzone = new Dropzone("#dropzone");
			$("#dropzone").dropzone();
			Dropzone.options.dropzone = {
		   paramName: "arquivos", 
		   dictDefaultMessage: "Arraste seus arquivos para cá!",
		   maxFilesize: 300, 
		   accept: function(file, done) {
			 if (file.name == "olamundo.png") {
			   done("Arquivo não aceito.");
			 } else {
			   done();
			}
		  }
		 }			
			
		</script> 		
	
</body>

</html>
