<?php
 include_once('conexao.php');
 include_once('controller.php');
 include_once('funcao.php');
 include_once('DAO/DAOequipe.php');
 include_once('classes/equipe.php');
 
 $instance     = new funcao();
 $conn         = new Conexao();
 $equipe  = new DAOequipe();
 $z  = new equipe();
 //$encoding = mb_internal_encoding();
 
  if($_GET["acao"] == 'editar'){
	 $acao = 'atulizado';

 }else{
	  $acao = 'gravado'; 
	  
      
 }


	
	if(!empty($_GET["equ_id"])){

		$result = $equipe->pesquisarequipe($_GET["equ_id"]);
		foreach($result as $row){

			$equ_id = $row["equ_id"]; 
			$equ_nome = $row["equ_nome"]; 			
			$equ_descricao = $row["equ_descricao"]; 			
			$equ_status = $row["equ_status"]; 					
			$equ_imagem = $row["equ_imagem"]; 			

		}

	} 
	
	if (isset($_POST["equ_nome"])) {
		
		if (isset($_FILES['file']) && !empty($_FILES['file']['name']))
		{
		  $file_name = $_FILES['file']['name'];
          $file_type = $_FILES['file']['type'];
          $file_size = $_FILES['file']['size'];
          $file_error = $_FILES['file']['error'];
          $file_tmp_name = $_FILES['file']['tmp_name'];
   	$maxSize	= 1024 * 1024 * 2;
   	$permite 	= array('image/jpeg', 'image/gif', 'image/png');
   	
   	$extensao = @end(explode('.', $file_name));
   	$novoNome = @md5(mt_rand(1,10000).$_FILES['name']).".$extensao";
   	$destino = 'uploads/equipe/';
   	
          if($file_error != 0){
   		//echo "$file_name : ".$errorMsg[$file_error];
   		$instance->alerta("Erro Desconhecido ao inserir logo!","view-equipe.php");
   		//echo("<script language = 'javascript'> alert('Erro Desconhecido!'); </script>");
   		//echo "1";
   		return;
   	}else if(!in_array($file_type, $permite)){
   		//echo "$file_name : Erro Arquivo não Suportado!";
   		$instance->alerta("Formato de Arquivo($file_type) não Suportado!","view-equipe.php");
   		//echo("<script language = 'javascript'> alert('Formato de Arquivo não Suportado!'); </script>");
   		//echo "2";
   		return;
   	}else if($file_size > $maxSize){
   		//echo "$file_name : Erro imagem ultrapassa o limite de 5MB";
   		$instance->alerta("Logo ultrapassa o limite de 5MB!","view-equipe.php");
   		//echo("<script language = 'javascript'> alert('Imagem ultrapassa o limite de 5MB!'); </script>");
   		//echo "3";
   		return; 
   	}else{
   		move_uploaded_file($file_tmp_name,$destino.$novoNome);
   		//echo $novoNome;
   		//return;
   	}
      }else{$novoNome = $equ_imagem;}
	  	$z->setEqu_imagem($novoNome);	
		$z->setEqu_id($_GET["equ_id"]);
		$z->setEqu_nome($_POST["equ_nome"]);
		$z->setEqu_descricao($_POST["equ_descricao"]);
		$z->setEqu_status($_POST["equ_status"]);
		
		$equipe->Atualizar($z);
		
		

		/*
		if ($equipe->Atualizar($z)){
			 $msg = "equipe Atualizado com Sucesso!";
		}else{
			$msg = "ERRO: ao cadastrar META!";
		}
			$instance->alerta("equipe Cadastrado com Sucesso!","view-equipe.php");
			*/
			$link_destino = $_POST['link_destino'];
			header("Location: $link_destino");

		
	}
?>
<!DOCTYPE html>
<html class="loading" lang="pt-br" data-textdirection="ltr">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
      <meta name="description" content="Micromaq Soluções em Impressão">
      <meta name="keywords" content="admin template, robust admin template, dashboard template, flat admin template, responsive admin template, web app, crypto dashboard, bitcoin dashboard">
      <!--<meta name="author" content="PIXINVENT">-->
      <title><?php include "titulo.php" ?></title>
      <link rel="apple-touch-icon" href="images/ico/apple-icon-120.png">
      <!--Favicon-->
      <link rel="icon" href="../img/core-img/favicon.png">
      <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i%7CMuli:300,400,500,700" rel="stylesheet">
	  	
		<link rel="stylesheet" type="text/css" href="fonts/feather/style.min.css">
		<link rel="stylesheet" type="text/css" href="fonts/simple-line-icons/style.min.css">
		<link rel="stylesheet" type="text/css" href="fonts/flag-icon-css/css/flag-icon.min.css">
		<link rel="stylesheet" type="text/css" href="vendors/css/extensions/pace.css">
		<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
		
      <!-- BEGIN VENDOR CSS-->
      <link rel="stylesheet" href="assets/font-awesome-4.7.0/css/font-awesome.min.css">
	
	  
	  <!--<link rel="stylesheet" type="text/css" href="vendors/css/extensions/sweetalert.css">-->
     
	 <link rel="stylesheet" type="text/css" href="vendors/css/forms/selects/select2.min.css">
      <link rel="stylesheet" type="text/css" href="vendors/css/forms/icheck/icheck.css">
      <link rel="stylesheet" type="text/css" href="vendors/css/forms/icheck/custom.css">
      <link rel="stylesheet" type="text/css" href="vendors/css/charts/morris.css">
      <link rel="stylesheet" type="text/css" href="vendors/css/extensions/unslider.css">
      <link rel="stylesheet" type="text/css" href="vendors/css/weather-icons/climacons.min.css">
      <!-- END VENDOR CSS-->
      <!-- BEGIN ROBUST CSS-->
      <link rel="stylesheet" type="text/css" href="css/app.min.css">
      <!-- END ROBUST CSS-->
      <!-- BEGIN Page Level CSS-->
      <link rel="stylesheet" type="text/css" href="css/core/menu/menu-types/horizontal-top-icon-menu.min.css">
      <link rel="stylesheet" type="text/css" href="css/core/colors/palette-climacon.css">
      <link rel="stylesheet" type="text/css" href="css/pages/users.min.css">
      <!-- END Page Level CSS-->
      <!-- BEGIN Custom CSS-->
      <link rel="stylesheet" type="text/css" href="assets/css/style.css">
      <!-- END Custom CSS-->
      <style>
         .card.card-fullscreen {
		display: block;
		z-index: 9999;
		position: fixed;
		width: 100% !important;
		height: 100% !important;
		top: 99px;
		right: 0;
		left: 0;
		bottom: 0;
		overflow: auto;
		}
		 
		 form .form-actions {
		 border-top: 1px solid #FFF;
		 padding: 1px 0;
		 margin-top: 20px;
		 }	
		 
		 @media screen and (max-width: 700px) {
			div.dt-buttons {
				float: none;
				width: 100%;
				text-align: center;
				margin-bottom: 3.5em;
			}	
}
		 
			 
      </style>
   </head>
   <body class="horizontal-layout horizontal-top-icon-menu 2-columns   menu-expanded" data-open="hover" data-menu="horizontal-menu" data-col="2-columns">
      <!-- Menu-->
      <?php include "menu.php" ?>
	  
	  
	   <?php
	   function selected( $value, $selected ){
			return $value==$selected ? ' selected="selected"' : '';
			}
	   ?>
   
      <!-- Horizontal navigation-->
      <div class="app-content content">
         <div class="content-wrapper">		
		   <div class="content-header row">
			  <div class="content-header-left col-md-6 col-12 mb-2">
				<h3 class="content-header-title"><i class="icon-note"></i>Cadastros</h3>
				<h5 class="content-header-title" style="margin-left: 7px;"><i class="ft-corner-down-right"></i><a href="view-lista-equipe.php" style="font-size: 12px;">Listar Equipe</a></h5>
				<h5 class="content-header-title" style="margin-left: 17px;"><i class="ft-corner-down-right"></i><a href="view-equipe.php" style="font-size: 12px;">Cadastrar Equipe
			  </div>        
			</div>
			
       <div class="content-body">
               <!-- Basic form layout section start -->
               <section id="basic-form-layouts">
                  <div class="row justify-content-md-center">
                     <div class="col-md-8">
                        <div class="card" style="margin-top: -100px;">
                           <div class="card-header">
                              <h4 class="card-title" id="basic-layout-card-center">Cadastro de Equipe</h4>
                              <a class="heading-elements-toggle"><i class="fa fa-ellipsis-v font-medium-3"></i></a>
                              <div class="heading-elements">
                                 <ul class="list-inline mb-0">
								 
								    <li><a href="view-lista-equipe.php"><i class="ft-eye" style="font-size: 19px;"></i>
									<li><a data-action="collapse"><i class="ft-minus" style="font-size: 19px;"></i></a></li>
									<li><a data-action="reload"><i class="ft-rotate-cw" style="font-size: 19px;"></i></a></li>
									<li><a data-action="expand"><i class="ft-maximize" style="font-size: 19px;"></i></a></li>
									<li><a data-action="close"><i class="ft-x" style="font-size: 19px;"></i></a></li>
                                 </ul>
                              </div>
                           </div>
                           <div class="card-content collapse show">
                              <div class="card-body">	

									<script>
									//FUNÇÃO QUE CHECA FOMRULÁRIO ANTES DE ENVIAR

										function check_form(destino){
											
											if(destino == '1'){
												$("#link_destino").val('view-equipe.php');
											}else{
												$("#link_destino").val('view-lista-equipe.php');
											};
											
											if(!$("#equ_nome").val()){
												Swal.fire({
												  icon: 'error',
												  title: 'Oops...',
												  text: 'Preencher todos os campos obrigatórios!'
												  });
												return false;
											}
											
											Swal.fire({
											  position: 'center',
											  icon: 'success',
											  title: 'equipe <?php echo $acao; ?> com sucesso!',
											  showConfirmButton: false,
											  timer: 1200
											});
											
											setTimeout(function(){ 
												document.getElementById("myForm").submit();
											}, 1200);
											
										}

									</script>							  
								<form id="myForm" method="post" enctype="multipart/form-data" style="line-height: 1.2;">
                                 <!--<form class="form" style="line-height: 1.2;">-->
                                    <div class="form-body">
                                       <div class="row">
									   
									   <!--INPUT SERVA PARA GRAVAR O LINK DE DESTINO DO LOCATION APOS INSERÇÃO-->
									   <input type="hidden" id="link_destino" name="link_destino" value="" >
									   								 
						
										  
										  	  <div class="col-md-2">
                                             <div class="form-group">
                                                <label>Status</label>
                                                <div class="form-group">
                                                   <select class="select2 form-control" id="equ_status" name="equ_status" value="<?php echo $equ_status; ?>">
                                                      <optgroup label="">			                                                  
														<option value="ATIVO"<?php echo selected( 'ATIVO', $equ_status); ?>>ATIVO</option>	
														<option value="INATIVO"<?php echo selected( 'INATIVO', $equ_status); ?>>INATIVO</option>	
                                                      </optgroup>
                                                   </select>
                                                </div>
                                             </div>
                                          </div> 
                                          <div class="col-md-5">
                                             <div class="form-group">
                                                <label for="Títuli">Nome</label>
                                                <input type="text" class="form-control" id="equ_nome" name="equ_nome" value="<?php echo $equ_nome; ?>" style="font-size: 12px;" placeholder="" >
                                             </div>
                                          </div> 
										  
										     <div class="col-md-5">
                                             <div class="form-group">
                                                <label for="Títuli">Cargo</label>
                                                <input type="text" class="form-control" id="equ_descricao" name="equ_descricao" value="<?php echo $equ_descricao; ?>" style="font-size: 12px;" placeholder="" >
                                             </div>
                                          </div> 
										  
										  
									

												  
                                       </div>
		
										  
						
										  
										 
										  <div class="row">
										 
										  <div class="col-md-2">
										  <div class="form-group" style="border-radius: 1%;margin-top: 1px;" >
										  <label for="Nome">Imagem</label>
										  
										
										  <?php if (isset($equ_imagem)) { ?>
											<a href="#" onClick="ampliaimagem('<?php echo $equ_imagem ?>')" title="Foto Atual" data-toggle="modal" data-target="#myModalImagem" ><img src="uploads/equipe/<?php echo $equ_imagem ?>" width="100%" height="100%" style="border-radius: 1%;margin-top: 1px;" /></a>
										  <?php } ?>
											</div>
											</div>
											</div>
										  <div class="row">
										     <div style="" class="form-group col-md-5">
											 
                              <div class="body" style="padding-bottom: 1px;">
                                 <div style="" class="input-group image-preview">
                                    <input id="file" name="file" value="<?php echo $equ_imagem; ?>" style="display: none;" type="text" class="form-control image-preview-filename" disabled="disabled"> <!-- don't give a name === doesn't send on POST/GET -->
                                    <label for="exampleInputEmail1"></label><br>
                                    <span class="input-group-btn" style="margin-top: -10px;margin-left: -11px;">
                                       <!-- image-preview-clear button -->
                                       <button type="button" class="btn btn-default image-preview-clear" style="display:none;">
                                       <span class="flaticon-cross" aria-hidden="true"></span>
                                       </button>
                                       <!-- image-preview-input -->
                                       <div class="btn btn-default image-preview-input">
                                          <span class="glyphicon glyphicon-folder-open"></span>
                                          <span class="image-preview-input-title">Selecionar</span>
                                          <input style="width: 100%;" value="<?php echo $equ_imagem; ?>" type="file" accept="image/png, image/jpeg, image/gif" id="file" name="file"/> <!-- rename it -->
                                       </div>
                                    </span>
                                 </div>
                              </div>
							  </div>
										  
										  
									 
								          </div>
										  					   
							   
                                    </div>
                                    <div class="form-actions center">
									

									 <?php if($acao == 'gravado'){ ?>
                                       <button onClick="check_form(1)" type="button" name="enviar_inc_novo" id="" class="btn btn-success">
                                       <i class="fa fa-check-square-o"></i> Salvar e Incluir Novo
                                       </button>
									 <?}?> 
									  
									   <button onClick="check_form(2)" type="button" name="enviar" id="" class="btn btn-success">
									   <i class="fa fa-check-square-o"></i> Salvar
									   </button>
									 
									   
									   <a href="view-lista-equipe.php">
                                       <button type="button" class="btn btn-danger mr-1">
                                       <i class="ft-x"></i> Cancelar
                                       </button>
									</a>
                                    </div>
									</form>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </section>
               <!-- // Basic form layout section end -->
            </div>
         </div>
      </div>
	  
	  
	  
	  
      <!-- ////////////////////////////////////////////////////////////////////////////-->
      <?php include "footer.php" ?>
	  
	   <!-- Ampliar imagem -->
      <div class="modal fade" id="myModalImagem" role="dialog">
         <div class="modal-dialog modal-lg">
            <!-- Modal content-->
            <div class="modal-content" style="width: 50%;margin-left: 35%;margin-right: 35%;margin-top: 20%;">
               <div class="modal-header">
                  <h4 class="modal-title">Foto Ampliada</h4>
                  <button data-toggle="tooltip" title="Fechar" onclick="atualiza()" target="Iframe" href="view-equipe.php" type="button" class="btn btn-default" data-dismiss="modal" style="float: right;position: relative;margin-top: -31px;">X</button>
               </div>
               <div class="modal-body">
                  <!-- Iframe -->
                  <div id="imagem12" >
                  </div>
               </div>
            </div>
         </div>
      </div>
	  	  
	  <script src="js/sweetalert2@10.js"></script>
      <!-- BEGIN VENDOR JS-->
      <script src="vendors/js/vendors.min.js"></script>
      <!-- BEGIN VENDOR JS-->
      <!-- BEGIN PAGE VENDOR JS--> 
      <script src="vendors/js/ui/jquery.sticky.js"></script>
      <script src="vendors/js/charts/jquery.sparkline.min.js"></script>
	  <!--<script src="vendors/js/extensions/sweetalert.min.js"></script>-->
      <script src="vendors/js/forms/select/select2.full.min.js"></script>
      <!-- END PAGE VENDOR JS-->
      <!-- BEGIN ROBUST JS-->
      <script src="js/core/app-menu.min.js"></script>
      <script src="js/core/app.min.js"></script>
      <script src="js/scripts/customizer.min.js"></script>
      <!-- END ROBUST JS-->
      <!-- BEGIN PAGE LEVEL JS-->
      <script src="js/scripts/ui/breadcrumbs-with-stats.min.js"></script>
	  <script src="js/scripts/extensions/sweet-alerts.min.js"></script>
      <script src="js/scripts/forms/select/form-select2.min.js"></script>
	  <script src="js/scripts/navs/navs.min.js"></script>
      <!-- END PAGE LEVEL JS-->
	  <!--Máscara-->
	   <script src="vendors/js/forms/extended/inputmask/jquery.inputmask.bundle.min.js"></script>
	   <script src="js/scripts/forms/extended/form-inputmask.min.js"></script>
	   
	   
	   <!--<script src="js/jquery.3.2.1.min.js"></script>-->
	   
	   
   </body>
   <!-- Mirrored from pixinvent.com/bootstrap-admin-template/robust/html/ltr/horizontal-top-icon-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 12 Feb 2021 19:25:59 GMT -->
</html>
	
	  
	  <script>
	 // INICIO FUNÇÃO DE MASCARA MAIUSCULA
	function maiuscula(z){
		v = z.value.toUpperCase();
		z.value = v;
						 }
	//FIM DA FUNÇÃO MASCARA MAIUSCULA
	</script>
	
	<script>
	

			
		
		//AmpliarImagem
		function ampliaimagem(imagem){
		document.getElementById("imagem12").innerHTML  = '<img src="uploads/equipe/'+imagem+'" width="100%" height="100%" />';

           } 
		
	
	</script>
