<?php
 $id = (int)$_GET['id'];
 $selectLink = $db->prepare("SELECT * FROM adm_links WHERE id=:id");
 $selectLink->bindParam(':id', $id, PDO::PARAM_INT);
 $selectLink->execute();

 $arrLink = $selectLink->fetch();
?>

<form name="frmCadLink" id="frmCadLink" enctype="multipart/form-data" method="post" class="form-padrao" action="miolo.php?miolo=updateLink">
	<input type="hidden" name="idLink" id="idLink" value="<?php echo $_GET['id']; ?>">
	<table border="0" class="tabela-conteudo" cellspacing="10">
		<tbody>
			<tr>
				<td colspan="2" class="titulos-internos"><?php echo $arrLink['titulo']; ?></td>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr class='linha-topo'>
				<th align='left'>T&iacute;tulo:</th>
			</tr>
			<tr>
				<th align='left' >
					<input type='text' name='titulo' id='titulo' maxlength='300' value='<?php echo $arrLink['titulo']; ?>'>
				</th>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr class='linha-topo'>
				<th align='left'>Sub t&iacute;tulo:</th>
			</tr>
			<tr>
				<th align='left' >
					<input type='text' name='subtitulo' id='subtitulo' size="60" maxlength='300' value='<?php echo $arrLink['subtitulo']; ?>'>
				</th>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr class='linha-topo'>
				<th align='left'>Resumo:</th>
			</tr>
			<tr>
				<th align='left' >
					<!-- <input type='text' name='resumo' id='resumo' maxlength='300' value=''> -->
					<textarea name="resumo" id="resumo" cols="92" rows="3"><?php echo $arrLink['resumo']; ?></textarea>
				</th>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr class="linha-topo">
				<th align='left'>Texto:</th>
			</tr>
			<tr>
				<th align='left'><textarea class='mceEditor' name='texto' id='texto' rows='20' cols='45'><?php echo $arrLink['texto'];?></textarea></th>
			</tr>
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr class='linha-topo'>
				<th align='left'>Vídeo:</th>
			</tr>
			<tr>
				<th align='left' class="inputCapa">
					<input type='text' name='video' id='video' size="80" value="<?php echo htmlentities($arrLink['video']); ?>" />
				</th>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr class='linha-topo'>
				<th align='left'>Capa:</th>
			</tr>
			<tr>
				<th align='left' class="inputCapa">
					<input type='file' accept="image/jpeg/gif/png" value="Buscar Arquivo" name='btnUpload' id="btnUpload" OnChange='capa.value=this.value;'>
					<input type='text' name='capa' id='capa' readonly='true'>
				</th>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<?php 
			if($arrLink['id'] == 1){
			?>
			<tr class="linha-topo">
				<th align="left">Fotos na Galeria</th>
			</tr>
			<tr>
				<th><table>
					<tr>
					<?php
						$cont = 1;
						$selectGallery = $db->prepare("SELECT idGallery, arquivo FROM adm_gallery_links WHERE id_link = '".$_GET['id']."'");
						$selectGallery->bindParam(':id', $id, PDO::PARAM_INT);
						$selectGallery->execute();

						$qtdGallery = $selectGallery->rowCount();
						$arrGallery = $selectGallery->fetchAll(PDO::FETCH_ASSOC);

						for ($i=0; $i < $qtdGallery; $i++) {
							
							$idImagemGallery = $resultGallery['idGallery'];
							$nomeImagemGallery = $resultGallery['arquivo'];
					?>

						<td class="editarFotoGallery">
							<a class="group1" href="imagens-site/galerias/<?php echo $arrGallery[$i]['idGallery']; ?>" id="galeria"><img src="imagens-site/galerias/thumbs/<?php echo $arrGallery[$i]['idGallery']; ?>" alt="" border="0px"></a><br>
							<input type="checkbox" name="chkFotoGaleria[]" id="chkFotoGaleria" value="<?php echo $resultGallery[$i]['arquivo']; ?>" align="center">&nbsp;&nbsp;&nbsp;Excluir
						</td>

					<?php
							if ($cont % 3 == 0) {
								
								echo "</tr>";
							}

							$cont++;
						}
					?>
				</table>
			</th>
			<tr class="linha-topo">
				<th align="left">Incluir Novo</th>
			</tr>
			<tr><td colspan="3">&nbsp;</td></tr>
			<tr class="linhaFotosGaleria">
				<th class="inputfotosGaleria" align="left">
					<input type="file" name="fotoGaleriaProduto[]" id="fotoGaleriaProduto" value="">&nbsp;<a href="#galeria" class="removerCampo"><img src="images/menos.png" width="18px" height="18px" alt="" border="0px"></a>
				</th>
			</tr>
			<tr>
				<th class="inputfotosGaleria" align="left">
					<a href="#galeria"  class="adicionarCampo"><img src="images/mais.png" width="18px" height="18px" alt="" border="0px"></a>
				</th>
			</tr>
			
			<tr><td>&nbsp;</td></tr>
			<?php } ?>
			<tr class="linha-topo">
				<th align="left">Palavras Chave:</th>
			</tr>
			<?php 
				$arrKeywords = explode(",", $arrLink['keywords']);
				foreach ($arrKeywords as $keyword) {
			?>
			<tr class="linhaPalavraChave">
				<th class="inputsProdutos" align="left">Conte&uacute;do:<a name="keyword" id="keyword"></a>
					<input type="text" maxlenght="200" name="keywords[]" id="keywords" value="<?php echo $keyword; ?>">&nbsp;<a href="#keyword" class="removerPalavraChave"><img src="images/menos.png" width="18px" height="18px" alt="" border="0px"></a>
				</th>
			</tr>
			<?php } ?>
			<tr>
				<th class="inputPalavraChave" align="left">
					<a href="#keyword"  class="adicionarPalavraChave"><img src="images/mais.png" width="18px" height="18px" alt="" border="0px"></a>
				</th>
			</tr>
			<tr>
				<th align='center' >
					<input type='button' value='Confirmar alterações' name='btnUpdate' id='btnUpdate' OnClick="javascript:frmCadLink.submit();">
					<input type='button' value='Limpar' name='btnLimpar' id='btnLimpar'>
				</th>
			</tr>
			<tr><td colspan="4">&nbsp;</td></tr>
		</tbody>
	</table>
</form>

<?php include 'paineis/inputs/divResultado.php'; ?>