<?php
error_reporting(E_ALL);
ini_set('display_errors', 0 );
header('Content-Type: text/html; charset=utf-8');
include("../configuracao.php");//confirma no banco de dados
include("../inclusos/funcoes.php");
include("../seguranca.php"); // Inclui o arquivo com o sistema de seguran?a
protegePagina(); // Protege a página

?>
<!doctype html>
<html ng-app="myApp">
<head>
<title>MAX LAYOUTS</title>

<link rel="stylesheet" href="inclusos/styles.css">
<link href="inclusos/css_precopratico.css" rel="stylesheet" type="text/css">

<script src="https://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>

<script src="inclusos/script.js"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script src="js/gmaps.js" type="text/javascript"></script>


		<script type="text/javascript">
			$(document).ready(function(){
				$("a[rel=modal]").click( function(ev){
					ev.preventDefault();

					var id = $(this).attr("href");

					var alturaTela = $(document).height();
					var larguraTela = $(window).width();
	
					//colocando o fundo preto
					$('#mascara').css({'width':larguraTela,'height':alturaTela});
					$('#mascara').fadeIn(1000);	
					$('#mascara').fadeTo("slow",0.8);

					var left = ($(window).width() /2) - ( $(id).width() / 2 );
					var top = ($(window).height() / 2) - ( $(id).height() / 2 );
					
					$(id).css({'top':top,'left':left});
					$(id).show();	
 				});

 				$("#mascara").click( function(){
 					$(this).hide();
 					$(".window").hide();
 				});

 				$('.fechar').click(function(ev){
 					ev.preventDefault();
 					$("#mascara").hide();
 					$(".window").hide();
 				});
			});
			
			function preLoad() {
			$("#loading").hide();
			}
			
			$(function(){
			$("#loading").show();
			});
			
			$(document).ready(function () {
			   $('input').keypress(function (e) {
					var code = null;
					code = (e.keyCode ? e.keyCode : e.which);                
					return (code == 13) ? false : true;
			   });
			});		
						
		</script>
        
	<script type="text/javascript">
			function FormataCnpj(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
					if (tam == 10)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
					if (tam == 15)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
				}
			}
		</script> 
        
	<script type="text/javascript">
			function FormataCpf(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 11)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(3, 5) + '.';
					if (tam == 9)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(3, 5) + '-' + vr.substr(6, 11);
				}
			}
		</script>           



     
        <style type="text/css">
.map{
    height:200px;
    border:1px solid #999 !important;
    -webkit-box-shadow: 0 0 5px #999 !important;
    -moz-box-shadow: 0 0 5px #999 !important;
    box-shadow: 0 0 5px #999 !important; 
    display: none;
}
        </style> 


	<!-- Add mousewheel plugin (this is optional) -->
	<script type="text/javascript" src="js/lib/jquery.mousewheel-3.0.6.pack.js"></script>

	<!-- Add fancyBox main JS and CSS files -->
	<script type="text/javascript" src="js/source/jquery.fancybox.js?v=2.1.5"></script>
	<link rel="stylesheet" type="text/css" href="js/source/jquery.fancybox.css?v=2.1.5" media="screen" />

	<!-- Add Button helper (this is optional) -->
	<link rel="stylesheet" type="text/css" href="js/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
	<script type="text/javascript" src="js/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>

	<!-- Add Thumbnail helper (this is optional) -->
	<link rel="stylesheet" type="text/css" href="js/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7" />
	<script type="text/javascript" src="js/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>

	<!-- Add Media helper (this is optional) -->
	<script type="text/javascript" src="js/source/helpers/jquery.fancybox-media.js?v=1.0.6"></script>

	<script type="text/javascript">
$(document).ready(function() {
			/*
			 *  Simple image gallery. Uses default settings
			 */

			$('.fancybox').fancybox();

			/*
			 *  Different effects
			 */

			// Change title type, overlay closing speed
			$(".fancybox-effects-a").fancybox({
				helpers: {
					title : {
						type : 'outside'
					},
					overlay : {
						speedOut : 0
					}
				}
			});

			// Disable opening and closing animations, change title type
			$(".fancybox-effects-b").fancybox({
				openEffect  : 'none',
				closeEffect	: 'none',

				helpers : {
					title : {
						type : 'over'
					}
				}
			});

			// Set custom style, close if clicked, change title type and overlay color
			$(".fancybox-effects-c").fancybox({
				wrapCSS    : 'fancybox-custom',
				closeClick : true,

				openEffect : 'none',

				helpers : {
					title : {
						type : 'inside'
					},
					overlay : {
						css : {
							'background' : 'rgba(238,238,238,0.85)'
						}
					}
				}
			});

			// Remove padding, set opening and closing animations, close if clicked and disable overlay
			$(".fancybox-effects-d").fancybox({
				padding: 0,

				openEffect : 'elastic',
				openSpeed  : 150,

				closeEffect : 'elastic',
				closeSpeed  : 150,

				closeClick : true,

				helpers : {
					overlay : null
				}
			});

			/*
			 *  Button helper. Disable animations, hide close button, change title type and content
			 */

			$('.fancybox-buttons').fancybox({
				openEffect  : 'none',
				closeEffect : 'none',

				prevEffect : 'none',
				nextEffect : 'none',

				closeBtn  : false,

				helpers : {
					title : {
						type : 'inside'
					},
					buttons	: {}
				},

				afterLoad : function() {
					this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
				}
			});


			/*
			 *  Thumbnail helper. Disable animations, hide close button, arrows and slide to next gallery item if clicked
			 */

			$('.fancybox-thumbs').fancybox({
				prevEffect : 'none',
				nextEffect : 'none',

				closeBtn  : false,
				arrows    : false,
				nextClick : true,

				helpers : {
					thumbs : {
						width  : 50,
						height : 50
					}
				}
			});

			/*
			 *  Media helper. Group items, disable animations, hide arrows, enable media and button helpers.
			*/
			$('.fancybox-media')
				.attr('rel', 'media-gallery')
				.fancybox({
					openEffect : 'none',
					closeEffect : 'none',
					prevEffect : 'none',
					nextEffect : 'none',

					arrows : false,
					helpers : {
						media : {},
						buttons : {}
					}
				});

			/*
			 *  Open manually
			 */

			$("#fancybox-manual-a").click(function() {
				$.fancybox.open('1_b.jpg');
			});

			$("#fancybox-manual-b").click(function() {
				$.fancybox.open({
					href : 'iframe.html',
					type : 'iframe',
					padding : 5
				});
			});

			$("#fancybox-manual-c").click(function() {
				$.fancybox.open([
					{
						href : '1_b.jpg',
						title : 'My title'
					}, {
						href : '2_b.jpg',
						title : '2nd title'
					}, {
						href : '3_b.jpg'
					}
				], {
					helpers : {
						thumbs : {
							width: 75,
							height: 50
						}
					}
				});
			});


		});
    </script>
	<style type="text/css">
		.fancybox-custom .fancybox-skin {
			box-shadow: 0 0 50px #222;
		}
		.fancybox-wrap{
			top:80;
		}
	</style>         
   
<link href="js/dist/css/custom-alert.min.css" rel="stylesheet">  
<script src="js/dist/js/custom-alert.js" language="javascript"></script>

<meta charset="utf-8">
</head>
<body onLoad="preLoad();">
<?php
//GERADOR DE CAMPOS POST

//echo GerarCamposPost("tarefa", "linha_tarefa");

$idtarefa 	= $_GET['idtarefa'];

if($idtarefa == ""){
	$acao		 	= "Salvar";
}else{
	$acao 			= "Alterar";	
}

//Recebe Ação
$acao_bd		    = $_GET['acao'];
$acao_bd		   .= $_POST['acao'];

//RECEBE DADOS

$idtarefa .= $_POST['idtarefa'];
$data = $_POST['data'];
$idcliente = $_POST['idcliente'];
$idvenda = $_POST['idpedido'];
$tarefa = $_POST['tarefa'];
$idsolicitante = $_POST['idsolicitante'];
$dataentrada = $_POST['dataentrada'];
$dataprazo = $_POST['dataprazo'];
$prioridade = $_POST['prioridade'];
$assunto = $_POST['assunto'];
$data_criacao = date('Y-m-d');
$idusuario = $_SESSION['usuarioID'];
$status = $_POST['status'];
//Dados da Tabela
$tabela                 ="tarefas";

$campos_tabela = "data, idcliente, idvenda, tarefa, idsolicitante, dataentrada, dataprazo, prioridade, assunto, data_criacao, idusuario, status";

$campos_value = "'$data', '$idcliente', '$idvenda', '$tarefa', '$idsolicitante', '$dataentrada', '$dataprazo', '$prioridade', '$assunto', '$data_criacao', '$idusuario', '$status'";

//INSERIR REGISTROS
if($acao_bd == "Salvar"){
	$salvar = Salvar($tabela,  $campos_tabela, $campos_value);

// RETORNA ULTIMO ID INSERIDO
	$id_insert = mysql_insert_id();
	$redireciona = VerificaSql($salvar, "manutencao_tarefa_lytebox.php?idtarefa=".$id_insert."", "manutencao_tarefa_lytebox.php");
}

//ATUALIZANDO REGISTRO
if($acao_bd == "Alterar"){

$campos_alterar = "data='$data', idcliente='$idcliente', idvenda='$idvenda', tarefa='$tarefa', idsolicitante='$idsolicitante', dataentrada='$dataentrada', dataprazo='$dataprazo', prioridade='$prioridade', assunto='$assunto', data_criacao='$data_criacao', idusuario='$idusuario', status='$status'";

    $atualizar = Alterar($tabela, $campos_alterar, "idtarefa", $idtarefa);
	$redireciona = VerificaSql($atualizar, "manutencao_tarefa_lytebox_final.php?idtarefa=".$idtarefa."", "manutencao_tarefa_lytebox_final.php?idtarefa=".$idtarefa."");
}

//EXCLUINDO REGISTRO
if($_GET['excluir'] == "sim"){
    $deletar = Excluir($tabela, "idtarefa", $idtarefa);	
	$redireciona = VerificaSql($deletar, "manutencao_tarefa_lytebox.php", "manutencao_tarefa_lytebox.php?idtarefa=".$idtarefa."");
} 

if($acao == "Alterar"){

	$selecionar_tarefa = Seleciona("tarefas", "WHERE idtarefa='".$idtarefa."'", "") or die(mysql_error());
	while($linha_tarefa=mysql_fetch_array($selecionar_tarefa)){
		
$idtarefa = $linha_tarefa['idtarefa']; 
$data = $linha_tarefa['data']; 
$idcliente = $linha_tarefa['idcliente']; 
$idvenda = $linha_tarefa['idvenda']; 
$tarefa = $linha_tarefa['tarefa']; 
$idsolicitante = $linha_tarefa['idsolicitante']; 
$dataentrada = $linha_tarefa['dataentrada']; 
$dataprazo = $linha_tarefa['dataprazo']; 
$prioridade = $linha_tarefa['prioridade']; 
$assunto = $linha_tarefa['assunto']; 
$data_criacao = $linha_tarefa['data_criacao']; 
$idusuario = $linha_tarefa['idusuario']; 	
$status = $linha_tarefa['status']; 	

	}
}


?>
<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
<script type="text/javascript">
function EnviarFormulario()
{
    document.forms["cadastro"].submit();
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="208" align="center" bgcolor="#D9D9D9" class="TituloCinzaEscuro" style="padding-left: 5px; cursor:pointer" onclick="location.href='manutencao_tarefa_lytebox.php';"> ATIVIDADES</td>
        <td align="right" bgcolor="#D9D9D9">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
       <form name="cadastro" id="cadastro" method="post" action="manutencao_tarefa_lytebox.php" enctype="multipart/form-data">
      <input type="hidden" name="acao" value="<?php echo $acao;?>">
      <input type="hidden" name="idtarefa" value="<?php echo $idtarefa;?>"> 
    <td colspan="2"><table width="100%" border="0" align="center" cellpadding="6" cellspacing="0">
        <tr>
          <td width="50%" align="center" valign="middle" bgcolor="#D9D9D9"><table width="100%" border="0" cellspacing="0" cellpadding="4">
            <tr>
              <td valign="top" bgcolor="#FFFFFF"><!-- INICIO DIV -->
                <table width="100%" border="0" align="center" cellpadding="6" cellspacing="0">
                  <tr>
                    <td width="50%" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="4">
                      <tr>
                        <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="3" cellpadding="3">
                          <tbody>
                            <tr>
                              <td><strong style="color: #000000;  font-size: 13px;">DATA DA SOLICITAÇÃO: <?php echo InverteDataNovoSeparador($data, "-", "/");?></strong></td>
                              <td><strong style="color: #000000;  font-size: 13px;">SOLICITADO POR: 
                                <?php
                            
                            if($idsolicitante == ""){
                            $idsolicitante = $_SESSION['usuarioID'];	
                            }
                            $SelecionaClientes = Seleciona("usuarios", "WHERE idusuario='$idsolicitante'", "ORDER BY nome ASC") or die(mysql_error());
                            while($linha_dadosclientes=mysql_fetch_array($SelecionaClientes)){
                            $id_usuario = $linha_dadosclientes['idusuario'];					  
                            ?>
                                <?php echo $linha_dadosclientes['nome'] ;?>
                                </option>
                                <?php
                            }
                            ?>
                              </strong></td>
                              <td><strong style="color: #000000;  font-size: 13px;">PRAZO: <?php echo InverteDataNovoSeparador($dataprazo, "-", "/");?></strong></td>
                              </tr>
                          </tbody>
                        </table></td>
                      </tr>
                      <tr>
                        <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="3" cellpadding="3">
                          <tbody>
                            <tr>
                              <td><strong style="color: #000000;  font-size: 13px;">TITULO: <?php echo $tarefa;?></strong></td>
                              <td><strong style="color: #000000;  font-size: 13px;">CLIENTE: 
                                <?php
                                $SelecionaClientes = Seleciona("clientes", "WHERE CodCli='$idcliente'", "ORDER BY Fantasia ASC") or die(mysql_error());
                                while($linha_dadosclientes=mysql_fetch_array($SelecionaClientes)){
                                $id_cliente = $linha_dadosclientes['CodCli'];					  
                                ?>
                                <?php echo $linha_dadosclientes['Fantasia'];?>
                                <?php
                                }
                                ?>
                                </select>
                              </strong></td>
                              <td><strong style="color: #000000;  font-size: 13px;">PEDIDO: <span style="color: #000000; font-size: 13px;"><?php echo $idvenda;?></span></strong></td>
                              </tr>
                          </tbody>
                        </table></td>
                      </tr>
                      <tr>
                        <td colspan="2" valign="top"><table width="100%" border="0" cellspacing="3" cellpadding="3">
                          <tbody>
                            <tr>
                              <td width="72%"><strong style="color: #000000;  font-size: 13px;">DESCRIÇÃO: <?php echo html_entity_decode($assunto); ?></strong></td>
                              <td width="28%"><strong style="color: #000000;  font-size: 13px;">PRIORIDADE: <?php echo $prioridade;?></strong></td>
                              </tr>
                            </tbody>
                          </table></td>
                      </tr>
                      <tr>
                        <td width="50%" rowspan="2" valign="top"><table width="100%" border="0" cellspacing="3" cellpadding="3">
                          <tbody>
                            <tr>
                              <td width="94" align="right"><strong style="color: #000000;  font-size: 13px;">STATUS: </strong></td>
                              <td width="279"><span style="color: #000000;  font-size: 13px;">
                                <select name="status" size="1" required class="form-campos" id="status" style="width:100%; height: 30px;">
                                  <option value="">Selecione o Status</option>
                                  <option value="Finalizado" <?php if($status == "Finalizado"){ echo "selected";}?>>Finalizado</option>
                                  <option value="Andamento" <?php if($status == "Andamento"){ echo "selected";}?>>Andamento</option>
                                  <option value="Cancelado" <?php if($status == "Cancelado"){ echo "selected";}?>>Cancelado</option>
                                  </select>
                                </span></td>
                              </tr>
                            </tbody>
                        </table></td>
                        <td valign="top"><strong style="color: #000000;  font-size: 13px;">ANEXOS:</strong></td>
                      </tr>
                      <tr>
                        <td valign="top">
                          <iframe src="upload_arquivos_iframe_exibe.php?idtarefa=<?php echo $idtarefa;?>" width="100%" height="80" frameborder="0" scrolling="no"></iframe>
                        </td>
                      </tr>
                      <tr>
                        <td align="right" valign="top">&nbsp;</td>
                        <td align="right" valign="top"><table width="400" border="0" cellspacing="0" cellpadding="2">
                          <tbody>
                            <tr>
                              <td><input name="button" type="submit" class="BoxVerde" id="button" value="Salvar" style="width: 100px; height: 35px;"></td>
                              <td><?php if($acao != "Salvar"){;?>
                                <table width="70" border="0" align="right" cellpadding="2" cellspacing="0" onclick="location.href='manutencao_tarefa_lytebox.php?idtarefa=<?php echo $idtarefa;?>&amp;excluir=sim';" class="BoxMenuVermelho" style="width: 100px; height: 35px; color:#FFFFFF;"">
                                  <tr>
                                    <td height="25" align="center" class="TextoMenuBranco">Excluir</td>
                                    </tr>
                                  </table>
                                <?php }?></td>
                              </tr>
                            </tbody>
                          </table></td>
                      </tr>
                      </table></td>
                    </tr>
                  </table>                <!-- FIM DIV --></td>
            </tr>
            </table></td>
        </tr>
        </table></td>
            </form>
  </tr>
</table>
</body>
</html>