<?php
	//session_start();
    //Incluindo a conexão com banco de dados     
	include("config/conexao.php"); 
	include("cabecalho.php");
	$empresa_id = $_SESSION['codCliente'];
	$id = $_GET['id'];
	$sql  = "SELECT * FROM glpi_tickets WHERE id = '{$id}' AND empresa_id = '{$empresa_id}'"; //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);

		
	$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);
        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 {



?>

<!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">
  		<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-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>
				  <i class="fa fa-user-circle-o"></i> <a href="atendimentos.php">Atendimentos</a>	
				</li>
                <li class="active"><i class="fa fa-pencil-square-o"></i> Editar</li>
              </ol>
            </div>
          </div>
        </div>
        <div class="portlet portlet-default">
			<form  action="config/script_chamado.php?acao=editar" method="POST" enctype="multipart/form-data">	
			  <div class="portlet-heading text-center">
				<div class="portlet-title">
				  <h4 >Editar Chamado</h4>
				</div>
				<div class="clearfix"></div>
			  </div>
			  <div class="portlet-body">
				  
					<div id="basicFormExample" class="panel-collapse collapse in">
				  <div class="portlet-body">
					<!------------------------>
					<div class= "row">
						<div class="col-lg-4">
							<div class="form-group">
							  <label for="TIPO"><b>Tipo:</b></label>
							  <input type="hidden" name="id_atend" id="id_atend" value="<?php echo $id; ?>" />
							  <select class="form-control" name="TIPO" id="TIPO">
								<option value= 0 >  </option>
								<option value= 1 >Incidente</option>
								<option value= 2 >Requisição</option>
							  </select>	
   							  <script>
								 TIPO.selectedIndex = <?php echo $row_rec['type']; ?>;
							  </script>							  
							</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>
		   				      <script>
								URGENCIA.selectedIndex = <?php echo $row_rec['urgency']; ?>
							  </script>
							</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>
		   				      <script>
								observadores.selectedIndex = <?php echo $row_rec['observadores']; ?>
							  </script>							  
							</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=<?php echo $row_rec['name']; ?> 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"><?php echo $row_rec['content']; ?></textarea>
							</div>
						</div>					
					</div>
<!--					<div class= "row">
						<div class="col-lg-12">
							<div class="form-group">
							  <label><b>Arquivos:</b></label>
							  <!--<input type="file" class="form-control" placeholder="" name="arquivos[]" id="arquivos" required="required" />-->
<!--							  <input name="uploads[]" type=file multiple />
							</div>
						</div>
					</div>
-->					<div class="row dropzone" id="dropzone">
						<!--<form action="upload.php" class="dropzone" id="meuPrimeiroDropzone">					-->
							<div class="fallback"> 
								<input name="fileToUpload" type="file" multiple /> 
							</div> 
						<!--</form>-->
					</div>


					
				   <!------------------------>
				  </div>
				</div>
			  

						
				
			  </div> 
			  <div class="portlet-footer text-center">
				<a class="btn btn-default" href="atendimentos.php">Cancelar</a>
				<button type="submit" id="SalvarChamado" name="SalvarChamado"  class="btn btn-green">
					<i class="fa fa-save"></i> Salvar <!--onclick="return ValidarCadastro();" -->
				</button>
			  </div> 
			</form>	  
        </div>
        <div class="row">
        </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').show(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();
				CATEGORIA.selectedIndex = <?php echo $row_rec['itilcategories_id']; ?>
				});
			} else {
				$('#CATEGORIA').html('<option value="">– Escolha Subcategoria –</option>');
			}
		});
	});
</script>

		<script>
			var meuDropzone = new Dropzone("#dropzone", {url:"upload.php"});	
			$("#dropzone").dropzone({ url: "upload.php" });
		  Dropzone.options.meuPrimeiroDropzone = {
		   paramName: "fileToUpload", 
		   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>
<?php }?>
