<?php include "includes/header.php";?>

<?php include "includes/navbar.php";?>

  <div id="wrapper">

    <!-- Sidebar -->
   <?php include "includes/sidebar.php";?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item">
            <a href="#">Ola</a>
          </li>
          <li class="breadcrumb-item active"><?php echo $_SESSION['nome'];?></li>
        </ol>

        <!-- Icon Cards-->
        <div class="row">
		
		
		
		
		
		
		
         <div class="container">
		  <div class="col-sm-4">
		  <h2><font color='green'>Actualizar dados de  clientes</font></h2>
		   <form action="" method="post" enctype="multipart/form-data">
		   
		   <?php 
		   if(isset($_GET['editar']) && !empty($_GET['editar'])){
			   
			   $id_edit_cliente = $_GET['editar'];
			   
			   $sel = "SELECT * FROM clientes WHERE id_cliente = '$id_edit_cliente'";
			   $link_this = mysqli_query($con,$sel);
			   while($row = mysqli_fetch_assoc($link_this)){
			
		   ?>
		   		    
			<div class="form-group">
			  <label for="nome_cliente">Nome do cliente</label>
			  <input type="text" name="nome_cliente" class="form-control" value="<?php echo $row['nome_cliente'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="bairro">Bairro</label>
			  <input type="text" name="bairro" class="form-control" value="<?php echo $row['bairro'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="Avenida">Avenida</label>
			  <input type="text" name="avenida" class="form-control" value="<?php echo $row['avenida'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="quarteirao">Quarteirao</label>
			  <input type="number" name="quarteirao" class="form-control" value="<?php echo $row['quarteirao'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="casa">Casa</label>
			  <input type="text" name="casa" class="form-control" value="<?php echo $row['casa'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="nuit">Nuit</label>
			  <input type="number" name="nuit" class="form-control" value="<?php echo $row['nuit'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="bi">B.I</label>
			  <input type="text" name="bi" class="form-control" value="<?php echo $row['bi'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="local_emissao">Local de emissao</label>
			  <select required name="local_emissao" class="form-control">
			   <option></option>
			   <option>Matola</option>
			   <option>Maputo</option>
			   <option>Gaza</option>
			   <option>Inhambane</option>
			   <option>Manica</option>
			   <option>Sofala</option>
			   <option>Tete</option>
			   <option>Zambezia</option>
			   <option>Nampula</option>
			   <option>Niassa</option>
			   <option>Cabo Delegado</option>
			     </select>
			 </div>
			 
			 <div class="form-group">
			  <label for="aic">Arquivo de Identificação Civil</label>
			  <input type="text" name="aic" class="form-control" value="<?php echo $row['aic'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="bi">Data de nascimento</label>
			  <input type="date" name="data_nasc" class="form-control" autocomplete="off" value="<?php echo $row['data_nasc'];?>" required/>
			 </div>
			 
			 
			 <div class="form-group">
			  <label for="vendedor">Vendedor/Agente</label>
			 <select required name="vendedor" class="form-control">
			 <option></option>
			 <?php busca_users();?>
			 </select>
			 </div>
		   
		   
		   <div class="form-group">
			  <label for="cell1">Contacto 1</label>
			  <input type="number" name="cell1" class="form-control" value="<?php echo $row['cell1'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="cell2">Contacto 2</label>
			  <input type="number" name="cell2" class="form-control" value="<?php echo $row['cell2'];?>" required/>
			 </div>
			 
			 <div class="form-group">
			  <label for="cell3">Email</label>
			  <input type="email" name="cell3" class="form-control" value="<?php echo $row['cell3'];?>" required/>
			 </div>
			 
			 	 <div class="form-group">
			  <label for="cell3">Imagem</label>
			  <input type="file" name="foto" class="form-control" autocomplete="off">
			 </div>
			 
			 <div class="form-group">
			 
			  <input type="submit" name="up_cli" class="btn btn-primary btn-block" value="Enviar"/>
			 </div>
		   
		   
		   
		     <?php }
			   
			   
		if(isset($_POST['up_cli'])){
				   
		$nome_cliente = $_POST['nome_cliente'];
		$bairro = $_POST['bairro'];
		$avenida = $_POST['avenida'];
		$quarteirao = $_POST['quarteirao'];
		$casa = $_POST['casa'];
		$nuit = $_POST['nuit'];
		$bi = $_POST['bi'];
		$local_emissao = $_POST['local_emissao'];
		$aic = $_POST['aic'];
		$data_nasc = $_POST['data_nasc'];
		
		$vendedor = $_POST['vendedor'];
		$cell1 = $_POST['cell1'];
		$cell2 = $_POST['cell2'];
		$cell3 = $_POST['cell3']; 
		
		$foto = $_FILES['foto']['name'];
		$foto_tmp = $_FILES['foto']['tmp_name'];
		move_uploaded_file($foto_tmp,"img/$foto");
		
		$actualiza_cliente = "UPDATE clientes SET nome_cliente='$nome_cliente',bairro='$bairro',avenida='$avenida',
		quarteirao='$quarteirao',casa='$casa',nuit='$nuit',bi='$bi',local_emissao='$local_emissao',aic='$aic',vendedor='$vendedor',cell1='$cell1',cell2='$cell2',cell3='$cell3',
		data_nasc='$data_nasc',foto ='$foto' WHERE id_cliente='$id_edit_cliente'";
		$ligar_isso = mysqli_query($con,$actualiza_cliente);
		
		if($ligar_isso){
			
			echo "<script>alert('Dados de $nome_cliente actualizados com sucesso')</script>";
			echo "<script>window.open('lista_clientes.php','_self')</script>";
		
		}else{
			
			echo "<script>alert('Ocorreu um erro ao actualizar dados de $nome_cliente')</script>";
			echo "<script>window.open('lista_clientes.php','_self')</script>";
		}
				   
				   
			   }
			   
		   }
		   
		   
		   ?>
		   
		   
		   </form>
		  
		  
		  </div>
		 
		 </div>
        
        
        </div>

     
        

      </div>
      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include "includes/footer.php";?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
 <?php include "includes/logout_modal.php";?>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>

</body>

</html>
