<?

//-------------------------------fim da autenticação---------------------//

    include("authentication.php");

	include("conexao_e_agenda.php");

	include("funcoes.php");

	$id_usuario = $_SESSION["id_usuario"];

	$hora_i = $_SESSION["hora_i"];

	$hora_f = $_SESSION["hora_f"];	

    $nome_usuario = $_SESSION["nome_usuario"];

//-------------------------------fim da autenticação---------------------//

  if (isset($_GET['id_tcomp'])){

	  $id_tcomp=$_GET['id_tcomp'];

  } else {

	  $id_tcomp="1";

  }

   

 //$funcao = $_GET["funcao"];

 //$funcao_exc = $_GET["funcao_exc"]; 



// if ($_GET['id_tcomp'] == 0){

//  $funcao = "inc";

//  $desc_funcao = "INCLUSÃO";  

// } else {

// $funcao = "alt";

// if($funcao_exc == 'exc'){ 

// $desc_funcao = "EXCLUSÃO"; 

// } else {

 $desc_funcao = "ALTERAÇÃO";

// }

// }

  $funcao = "alt";

 $sql_peca="select * from historia where id='$id_tcomp'";

 $result_peca=mysqli_query($conexao,$sql_peca) or die (mysqli_error($conexao));		  

 $linha=mysqli_fetch_array($result_peca);

 //}

$desc_funcao2 = "INCLUSÃO";

$for = 'formulario'; // nome do formulário	

$voltar = -1;

$origem = "cad_historia_alt.php";

$categoria = "historia";  

?>

<html>

<head>

<title><? echo $empresa; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="estilo.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/mascara.js"></script>

<script type="text/javascript" src="lightbox.js"></script>

<SCRIPT language="javascript">

  function AbreCalendario(largura,altura,formulario,campo,tmpx) {

    vertical   = (screen.height/2) - (altura/2);

    horizontal = (screen.width/2) - (largura/2);

    var jan = window.open('calendario.php?formulario='+formulario+'&campo='+campo+'&tmpx='+tmpx,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,copyhistory=0,screenX='+screen.width+',screenY='+screen.height+',top='+vertical+',left='+horizontal+',width='+largura+',height='+altura);

    jan.focus();

  }

</SCRIPT>

<style type="text/css">

<!--

.style1 {

	color: #FFFFFF;

	font-weight: bold;

}

-->

</style>

</head>



<body>

<?php include("cabecalho_e_clube.php"); ?>

<br>

<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="cant_cinza_form_peq">

  <tr class="verdana1">

    <td width="552" height="20" bgcolor="#666666"><div align="left"><font color="#FFFFFF"><strong> &nbsp;&nbsp;&nbsp;&nbsp; CADASTRO - HIST&Oacute;RIA</strong></font></div>

    <div align="center"><strong> <a href="index.php" class="link-bco"></a> </strong></div></td>

  </tr>

  <tr class="verdana1">

    <td height="18" bgcolor="#CCCCCC">&nbsp;&nbsp;&nbsp;&nbsp;<strong>VOC&Ecirc; 

      EST&Aacute; EXECUTANDO:</strong> <? echo $desc_funcao; ?></td>

  </tr>

  <tr class="verdana1">

    <td height="10">&nbsp;</td>

  </tr>

  <tr>

    <td height="46"><div align="right">

      <form name="<? echo $for; ?>" method="post" action="cad_historia_exec_alt.php">

        <input name="id_tcomp" type="hidden" id="id_tcomp" value="<? echo $id_tcomp; ?>">

        <input name="campo_funcao" type="hidden" id="campo_funcao" value="<? echo $funcao; ?>">

        <input name="funcao_exc" type="hidden" id="funcao_exc" value="<? echo $funcao_exc; ?>">

        <table width="100%" border="0" cellspacing="0" cellpadding="3">

          <? if($funcao == "alt"){ ?>

          <? } else { ?>

          <? } ?>

          <tr>

            <td colspan="2" class="verdana1"><div align="left"><strong>&nbsp;&nbsp;&nbsp;T&Iacute;TULO:</strong>

                <input name='titulo' type='text' class="caixa_preto_9" id="titulo" size=80 maxlength='80' value="<? if ($funcao == 'alt') echo $linha['titulo']; ?>">

            </div></td>

            </tr>

          <tr>

            <td colspan="2" class="verdana1"><strong> &nbsp;&nbsp;&nbsp;DESCRI&Ccedil;&Atilde;O:</strong></td>

          </tr>

          <tr>

            <td colspan="2" class="verdana1"><strong>

              <textarea name="texto" cols="45" rows="20" wrap="physical" id="texto"><? echo $linha['texto']; ?></textarea>

            </strong></td>

          </tr>

            <? if($funcao == "alt"){ ?>

          <tr>

            <td colspan="2" class="verdana1">&nbsp;&nbsp;&nbsp;<strong>SITUA&Ccedil;&Atilde;O:</strong>

              <input type="radio" name="situacao" style="border:none" value="d" <?  if ($linha['situacao'] == "d") echo "checked"; ?>>

              <span class="textosimples"> Vis&atilde;o Dispon&iacute;vel</span>&nbsp;&nbsp;&nbsp;

              <input type="radio" name="situacao" style="border:none" value="i" <?  if ($linha['situacao'] == "i") echo "checked"; ?>>

              <span class="textosimples">Vis&atilde;o Indispon&iacute;vel</span>&nbsp;</td>

            </tr> 

            <tr>

            <td width="28%" class="verdana1">&nbsp;</td>

            <td width="72%" class="verdana1">&nbsp;</td>

          </tr>         

          <? } ?>

          <tr>

            <td height="25" class="verdana1"><div align="center">

             <? if (($consulta == "")and($funcao == 'alt')) { ?>

              <input name="Button22" type="button" class="botao1" value="Voltar" onClick="window.location='<? echo $_SESSION['voltando'] ?>'">

              <? } if (($consulta == "")and($funcao == 'inc')) { ?>

              <input name="Button22" type="button" class="botao1" value="Voltar" onClick="window.location='<? echo $_SESSION['voltando'] ?>'">

              <? } ?>

            </div></td>

            <td height="25" class="verdana1">&nbsp;

                  <? if ($funcao == 'inc') { ?>

                  <input name="Button2" type="submit" class="botao1" value="Incluir">

                  <? } if (($funcao == 'alt') and ($funcao_exc == "")) {  ?>

                  <input name="Button2" type="submit" class="botao1" value="Atualizar">&nbsp;&nbsp;

                  <? } ?>        </td>

          </tr>

         </table>

      </form>

    </div></td>

  </tr>

  <? if($funcao == "alt"){ ?>

  <tr>

    <td height="143"><br><br><form action="upfoto.php?" method=post  ENCTYPE="multipart/form-data"> 

		<input name="id_c" type="hidden" id="id_c" value="<? echo $id_tcomp; ?>">

        <input name="categoria" type="hidden" id="categoria" value="<? echo $categoria; ?>">

        <input name="origem" type="hidden" id="origem" value="<? echo $origem; ?>">

        <input name="tipo" type="hidden" id="tipo" value="f">

        <table width="579" border=0 align=center cellpadding=0 cellspacing=0 class="cant_cinza_form_peq">

          <tr>

            <td height="20" colspan="2" align=center bgcolor="#666666" class="texto"><font color="#FFFFFF">Inclus&atilde;o 

              de Fotos</font></td>

          </tr>

          <tr>

            <td height="4" colspan="2" align=center bgcolor="#999999" class="texto"><span class="verdana_preto_10_bolder_2">Envie 

              a foto em formato .jpg ou .gif </span></td>

          </tr>

          <tr>

            <td height="25" colspan="2" align=center bgcolor="#999999"><div align="center"><span class="verdana_preto_10_bolder_2"> Procure a Foto a ser enviada:</span>

                    <input name="documento" type="file" class="caixa_preto_9" size="40">

            </div></td>

          </tr>

          <tr>

            <td width="106" height="2" align=center bgcolor="#999999"><div align="right"><span class="style2"><span class="textosimples style2"><strong>&nbsp;Legenda: </strong></span></span></div></td>

            <td width="471" align=center bgcolor="#999999"><textarea name="titulo" cols="60" rows="3" class="caixa_preto_9" id="titulo"></textarea></td>

          </tr>

          <tr>

            <td height="3" align=center bgcolor="#999999"><div align="right"><span class="style2"><span class="textosimples style2"><strong>Autor da Foto: </strong></span></span></div></td>

            <td height="25" align=center bgcolor="#999999"><div align="left">

                <input name='autor' type='text' class="caixa_preto_9" id="autor" size=60 maxlength='80'>

            </div></td>

          </tr>

          <tr>

            <td height="30" colspan="2" align=center bgcolor="#999999"><input name="submit" type=reset class="botao1" value="Limpar" style="cursor:hand">

              &nbsp;

              <input type="SUBMIT"  name="Submit" class="botao1" style="cursor:hand" value="Enviar foto"></td>

          </tr>

        </table>

    </form>

    <br></td>

  </tr> <? } ?>  

</table>

<br>

<br /><? if($funcao == "alt"){ ?>

<div align="center">

  <table width="727" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="cant_cinza">

    <tr>

      <td height="25" colspan="2" bgcolor="#9A0000"><div align="center" class="texto style1">RELA&Ccedil;&Atilde;O DE FOTOS</div></td>

    </tr>

    <?

 $sql_fotos="select * from fotos where categoria='$categoria' and fk_categoria='$id_tcomp' order by id asc";

 $result_fotos=mysqli_query($conexao,$sql_fotos) or die (mysqli_error($conexao));		

 while($linha_fotos=mysqli_fetch_array($result_fotos)){

  $data_foto = $linha_fotos["dt_foto"];

  $id_foto = $linha_fotos["id"];

  $nome_foto = $linha_fotos['caminho_foto'];             

   ?>

    <tr class="textosimples" bgcolor="<? if ($par = !$par) $cor = '#bbb3d3'; else $cor = '#F5F5F5'; echo $cor;// alterna a variavel par entre 0 e 1?>">

      <td><br>

          <div align="center">

            <? 

			  if($linha_fotos['caminho_foto']!=""){

			  print "<img src=\"../fotos"."/mini/".$linha_fotos['caminho_foto']."\" border='0'>";

			  } else {

			  print "<img src=\"../fotos"."/"."sem_fotografia.jpg"."\" border='0'>";

			  } ?>

          </div>

        <? if(($_GET["funcao2"]=="alt_arq") and ($_GET['id_foto']==$id_foto)){ 

 $sql_arqs="select * from fotos where id='".$_GET['id_foto']."'";

 $result_arqs=mysqli_query($conexao,$sql_arqs) or die (mysqli_error($conexao));		

 $linha_arqs=mysqli_fetch_array($result_arqs);

 $titulo = $linha_arqs["titulo"];

 $autor = $linha_arqs["autor"];

?>

          <br>

          <form name="formulario" method="post" action="upfoto_alterar.php">

            <table width="419" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">

              <input name="id_c" type="hidden" id="id_c" value="<? echo $id_tcomp; ?>">

              <input name="id_arquivo" type="hidden" id="id_arquivo" value="<? echo $_GET['id_foto']; ?>">

              <input name="origem" type="hidden" id="origem" value="<? echo $origem; ?>">

              <input name="quem" type="hidden" id="quem" value="<? echo $linha_arqs['caminho_foto']; ?>">

              <tr>

                <td width="458" height="10" class="texto style1"><div align="center">Modo de Altera&ccedil;&atilde;o</div></td>

              </tr>

              <tr>

                <td height="20" class="verdana1">&nbsp;&nbsp;Legenda:</td>

              </tr>

              <tr>

                <td height="25"><textarea name="titulo" cols="65" rows="3" id="titulo"><? echo $titulo; ?></textarea></td>

              </tr>

              <tr>

                <td height="20" class="verdana1">&nbsp;&nbsp;Autor:</td>

              </tr>

              <tr>

                <td height="20"><input name="autor" type="text" id="autor" value="<? echo $autor; ?>" size="65" maxlength="80"></td>

              </tr>

              <tr>

                <td height="20"><span class="verdana1">&nbsp;&nbsp;Foto do destaque? Sim

                  <input type="checkbox" name="destaque" style="border:none" value="d" <?  if ($linha_arqs['destaque'] == "d") echo "checked"; ?>>

                </span></td>

              </tr>

              <tr>

                <td height="30"><input name="Button23" type="submit" class="botao1" value="Alterar">

                </td>

              </tr>

            </table>

            <div align="center"></div>

          </form>

          <? } ?>

          <br></td>

      <td><strong>Nome:</strong>&nbsp; <a href="../fotos/<? echo $nome_foto; ?>" class="texto" rel="lightbox" border="0"><? echo $nome_foto; ?></a><br>

          <? echo "<strong>Legenda:</strong> ".$linha_fotos['titulo']; ?> <br>

          <? echo "<strong>Autor:</strong> ".$linha_fotos['autor']; ?>

          <? if($_GET["funcao2"]!="alt_arq"){

	   echo "<br><br><a href='$origem?id_tcomp=$id_tcomp&&id_foto=$id_foto&&funcao2=alt_arq' method='get' target='_self'><center><img src='btn_alterar.gif' border='0'></center></font></a>";

       echo "&nbsp;<br><br><a href='upfoto_excluir.php?id_c=$id_tcomp&&id_arquivo=$id_foto&&origem=$origem&&quem=$nome_foto&&funcao_exc=exc' method='get' target='_self'><center><img src='btn_excluir.gif' border='0'></center></font></a>"; } ?>

        &nbsp;&nbsp;</td>

    </tr>

    <tr bgcolor="<? echo $cor;// alterna a variavel par entre 0 e 1?>">

      <td>&nbsp;</td>

      <td height="25" class="verdana1"> Foto do destaque? [

        <?  echo situacao(d,Sim,Nao,$linha_fotos['destaque']); ?>

        ] </td>

    </tr>

    <? }?>

    <tr>

      <td colspan="2" bgcolor="#CCCCCC">&nbsp;</td>

    </tr>

  </table>

  <br>

</div><? } ?>

</body>

</html>