<?php
	//session_start();
	include("cabecalho.php");
	include("config/conexao.php");

	$empresa_id = $_SESSION['codCliente'];
	$result_rec  = " SELECT tic.*, GROUP_CONCAT(CONCAT(us.firstname,' ',us.realname) SEPARATOR '   ') as atendente ";
	$result_rec .= " FROM glpi_tickets tic ";
	$result_rec .= " LEFT JOIN glpi_tickets_users tus on tus.tickets_id = tic.id and tus.type = 2 ";
	$result_rec .= " LEFT JOIN glpi_users us on us.id = tus.users_id ";
	$result_rec .= " WHERE tic.empresa_id = '{$empresa_id}'"; 
	$result_rec .= " GROUP BY tic.id ORDER BY tic.id DESC";
	
	$resultado_rec = mysqli_query($conn, $result_rec);
	$number = mysqli_num_rows($resultado_rec);
	
	$result_obs = "SELECT id, CONCAT(firstname,' ',realname) as nome FROM glpi_users WHERE empresa_id = '{$empresa_id}' ORDER BY id";
	$resultado_obs = mysqli_query($conn, $result_obs);
	
	

?>

<!--<!DOCTYPE html>
<html lang="pt-br">

<head>
  <meta charset="utf-8">
  <title>Central de Atendimento</title>
  <meta name="author" content="">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="css/plugins/pace/pace.css" rel="stylesheet">
  <script src="js/pace/pace.js"></script>
  <link href="css/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href='css/fonts/google/fonte.css' rel="stylesheet" type="text/css">
  <link href="css/fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  <link href="css/plugins/datatables/datatables.css" rel="stylesheet">
  <link href="css/style.css" rel="stylesheet">
  <link href="css/upload.css" rel="stylesheet">
  		<style type="text/css">
			.carregando{
				color:#ff0000;
				display:none;
			}
		</style>
</head>

<body>
  <div id="wrapper">
    <!-- INICIO MENU DE NAVEGAÇÃO -->
<!--		<nav class="navbar-top" role="navigation">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".sidebar-collapse">
						<i class="fa fa-bars"></i> Menu
					</button>
					<div class="navbar-brand">					
						<a href="index">
							<img src="img/adapter_bco.svg"   style="width: 70%;">
						</a>
					</div>
				</div>
				<div class="nav-top">
					<!--<ul class="nav navbar-left">
						<li class="tooltip-sidebar-toggle">
							<a href="#" id="sidebar-toggle" data-toggle="tooltip" data-placement="right" title="Ocultar Barra Lateral">	
								<i class="fa fa-bars"></i>
							</a>	
						</li>
					</ul> -->
<!--					<ul class="nav navbar-right">
						<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">		
								<i class="fa fa-user"></i>&nbsp&nbsp<?php echo $_SESSION['usuarioNome']; ?>&nbsp&nbsp<i class="fa fa-caret-down"></i>
							</a>		
							<ul class="dropdown-menu dropdown-user">
								<li>
									<a href="">
										<i class="fa fa-user"></i> Dados Pessoais
									</a>
								</li>
								<li>
									<a href="#" data-toggle="modal" data-target="#AlterarSenha">
										<i class="fa fa-gear"></i> Configurações
									</a>
								</li>
								<li class="divider"></li>
								<li>
									<a class="logout_open" href="logoff.php">
										<i class="fa fa-sign-out"></i> Sair
									</a>
								</li>
							</ul>
						</li>
					</ul>
				</div>
			</nav>
    <!-- FIM MENU DE NAVEGAÇÃO -->
    <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 class="active"><i class="fa fa-comments"></i> Chamados</li>
              </ol>
            </div>
          </div>
        </div>
        <div class="portlet portlet-default">
          <div class="portlet-heading">
            <div class="portlet-title">
              <h4>Chamados Cadastrados</h4>
            </div>
            <div class="portlet-widgets">
 <!--             <button type="button" id="NovoUsuario" name="NovoUsuario" class="btn btn-default btn-xs">
                <i class="fa fa-comments"></i> Novo Chamados
			  </button>
-->			  <a href="#" class="btn btn-default btn-xs" data-toggle="modal" data-target="#NovoAtendimento" data-placement="top" title="Novo"> 
				<i class="fa fa-comments"></i> Novo Chamado 
			  </a>	
            </div>
            <div class="clearfix"></div>
          </div>
          <div class="portlet-body">
            <div class="table-responsive"><br>
              <table id="DataTable" class="table table-striped table-bordered table-hover table-green">
                <thead>
                  <tr>
                    <th style="width: 5%; text-align: center;">Id</th>
                    <th style="width: 20%; text-align: center;">Titulo</th>
                    <th style="width: 10%; text-align: center;">Status</th>
                    <th style="width: 12%; text-align: center;">Data Abertura</th>
					<th style="width: 12%; text-align: center;">Última Atualização</th>
		    <th style="width: 10%; text-align: center;">SLA</th>	
                    <th style="width: 10%; text-align: center;">Atribuido para técnico</th>
                    <th style="width: 10%; text-align: center;">Opções</th>
                  </tr>
                </thead>
                <tbody>
                  <?php while($row_rec = mysqli_fetch_assoc($resultado_rec)){ ?>
                  <tr id="<?php echo $row_rec['id']; ?>" class="gradeU">
                    <td style="text-align: center;">
                      <?php echo $row_rec['id']; ?>
                    </td>
                    <td style="text-align: center;">
                      <?php echo ($row_rec['name']); ?>
                    </td>
                    <td style="text-align: center;">  
					  <?php
						if ($row_rec['status'] == 1 ){
							echo "Novo";
						} elseif ($row_rec['status'] == 2 ){
							echo "Processado (atribuído)";
						} elseif ($row_rec['status'] == 3 ) {
							echo "Processado (planejado)";
						} elseif ($row_rec['status'] == 4 ) {
							echo "Pendente";
						} elseif ($row_rec['status'] == 5 ) {
							echo "Solucionado";
						} else {
							echo "Fechado";
						}
					  ?>
                    </td>
					<td style="text-align: center;">
                      <?php echo $row_rec['date']; ?>
                    </td>
                    <td style="text-align: center;">
                      <?php echo $row_rec['date_mod']; ?>
                    </td>
		    <td style="text-align: center;">
		      <?php echo $row_rec['time_to_resolve'];?>	 
		    </td>		
                    <td style="text-align: center;">
                      <?php echo utf8_encode($row_rec['atendente']); ?>
                    </td>
                    <td class="center" style="text-align: center;">
                      <a href="editachamado.php?id=<?php echo $row_rec['id']; ?>" class="btn btn-default btn-xs"  title="Editar">
                        <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                      </a>
                      <a href="acompanhar.php?id=<?php echo $row_rec['id']; ?>" class="btn btn-default btn-xs"  title="Acompanhar">
                        <i class="fa fa-tasks" aria-hidden="true"></i>
                      </a>					  					  
                    </td>
                  </tr>
                  <?php } ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <div class="row">
        </div>
      </div> 
    </div>
  </div>

  <!-- -------------------------------------------------------------------------------------------------------------------------->
  <!-- -------------------------------------------------------------------------------------------------------------------------->
    <div class="modal modal-flex fade" id="NovoAtendimento" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
      <div class="modal-dialog">
		 <form  action="config/script_chamado.php?acao=cadastrar" 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 Atendimento
				</h4>
			  </div>
			 <div class="modal-body">
				<div id="basicFormExample" class="panel-collapse collapse in">
				  <div class="portlet-body">
					<p>
					  <b>
						<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> ATENÇÃO!
					  </b> Preencha os campos abaixo para a abertura do chamado.
					</p>
					<!------------------------>
	
				<div class= "row">
						<div class="col-lg-4">
							<div class="form-group">
							  <label for="TIPO"><b>Tipo:</b></label>
							  <input type="hidden" name="id_user" id="id_user" value="<?php echo $_SESSION['usuarioId']?>" />
							  <select class="form-control" name="TIPO" id="TIPO">
								<option value= 0 >  </option>
								<option value= 1 >Incidente</option>
								<option value= 2 >Requisição</option>
							  </select>						  
							</div>
						</div>
						<div class="col-lg-4">
							<div class="form-group">
							  <label for="CATEGORIA"><b>Categoria:</b></label>			
							  <span class="carregando">Aguarde, carregando...</span>
							  <select class="form-control" name="CATEGORIA" id="CATEGORIA">
								  <option value="">Escolha a categoria</option>
							  </select>
							</div>
						</div>
						<div class="col-lg-4">
							<div class="form-group">
							  <label for="URGENCIA"><b>Urgência:</b></label>
							  <select class="form-control" name="URGENCIA" id="URGENCIA">
								   <option value= 5 >Muito Alta</option>
								   <option value= 4 >Alta</option>
								   <option value= 3 >Média</option>
								   <option value= 2 >Baixa</option>
								   <option value= 1 >Muito Baixa</option>
							  </select>
							</div>
						</div>
					</div>				
					<div class= "row">
						<div class="col-lg-12">
							<div class="form-group">
							  <label for="observadores"><b>Observadores:</b></label>
							  <select class="form-control" name="observadores" id="observadores" multiple><?php
							  	while ($row_obs = mysqli_fetch_assoc($resultado_obs) ) {
									echo '<option value = '.$row_obs['id'].'>'.$row_obs['nome'].'</options>';
								}?>	
							  </select>
							</div>
						</div>
						<div class="col-lg-12">
							<div class="form-group">
							  <label><b>Título:</b></label>
							  <input type="text" class="form-control" placeholder="" name="titulo" id="titulo" value="" required="required" />
							</div>
						</div>
						<div class="col-lg-12">
							<div class="form-group">
							  <label><b>Descrição:</b></label>
							  <textarea class="form-control" rows="10" placeholder="Descreva detalhadamente o problema." name="descricao" id="descricao" value=""></textarea>
							</div>
						</div>	
<!--					<div class="col-lg-12">
							<div class="form-group">
								<label><b>Arquivos:</b></label>
								<input type="file" class="form_control" placeholder="Selecione os arquivos" id="arquivos" name="arquivos[]" multiple>
							</div>
						</div>	
-->					</div>
					<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 class="modal-footer">
				<button type="button" id="CancelarCadastro" name="CancelarCadastro" class="btn btn-default" data-dismiss="modal">Cancelar</button>
				<button type="submit" id="SalvarChamado" name="SalvarChamado"  class="btn btn-green">
				  <i class="fa fa-save"></i> Salvar
				</button>
			  </div>
			</div>
		</form>	
      </div>
    </div>
 
  <!-- -------------------------------------------------------------------------------------------------------------------------->
  <div class="modal modal-flex fade" id="Erro" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title" id="TituloModal" style="color:white;"></h4>
        </div>
        <div class="modal-body">
          <div id="basicFormExample" class="panel-collapse collapse in">
            <div class="portlet-body">
              <p style="text-align: justify;" id="TextError"></p>
              <p style="text-align: justify;" id="descError"></p>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
        </div>
      </div>
    </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>
