<?php
session_start();
include('../db.php');

if (!session_is_registered("clave_audio")) {
	include("../login.php");
	if (!$continuar) exit;
}
?>
<html>
<head>
<title>articulos</title>
<link href="../sformi.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
function doSubmit() { 
	document.formulario.submit();
}

function doDelete() {
	

}
</script>
</head>
<body>
<?php 

/*
if (!session_is_registered("sintogeo")) {
	include("../login.php");
	if (!$continuar) exit;
}
*/

if(isset($_REQUEST['op'])) {
	$operacion = $_REQUEST['op'];
	$id = $_REQUEST['id'];
} else {
	$operacion = "add";
}

?>
<?php
		$articulo_id = $articulo_tipo = $articulo_padre = $articulo_seccion = $articulo_titular = $articulo_entradilla = "";
		$articulo_texto = $articulo_enlace = $articulo_fecha_pub = $articulo_embargado = $articulo_views = "";

switch($operacion)
{
	case "add";

		break;

	case "edit";
		$conn = db_connect();
		if($conn) {
			$query = "SELECT articulo_id, articulo_id, articulo_tipo, articulo_padre, articulo_seccion, articulo_titular, articulo_entradilla, articulo_texto, articulo_enlace, articulo_fecha_pub, articulo_embargado, articulo_views, articulo_orden 
							FROM edito_articulos 
							WHERE articulo_id = " . $id;
			$result = mysql_query($query, $conn);
			if (mysql_num_rows($result)) {
				$row = mysql_fetch_array($result);
				$articulo_id = $row['articulo_id'];
				$articulo_tipo = $row['articulo_tipo'];
				$articulo_padre = $row['articulo_padre'];
				$articulo_seccion = $row['articulo_seccion'];
				$articulo_titular = $row['articulo_titular'];
				$articulo_entradilla = $row['articulo_entradilla'];
				$articulo_texto = $row['articulo_texto'];
				$articulo_enlace = $row['articulo_enlace'];
				$articulo_fecha_pub = $row['articulo_fecha_pub'];
				$articulo_views = $row['articulo_views'];
				$articulo_orden = $row['articulo_orden'];
			}
		}
		break;
}
?>
<form method="post" action="articulos_db.php" name="formulario">
<input name="op" type="hidden" value="<?= $operacion; ?>">
<input name="id" type="hidden" value="<?= $id; ?>">
<table width="541" border="0" cellpadding="0" cellspacing="0">
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td>
  <td>&nbsp;</td>
</tr>
<tr><td class= "lbl">Tipo</td>
  <td class= "lbl">Orden dentro del tipo </td>
</tr>
<tr><td width="230" class="data"><select name="articulo_tipo" style="width:200px">
		<option value="1" <?php if( $articulo_tipo == '1') echo 'selected'; ?>>Novedad</option>
		<option value="2" <?php if( $articulo_tipo == '2') echo 'selected'; ?>>Learning Center</option>
		<option value="3" <?php if( $articulo_tipo == '3') echo 'selected'; ?>>Instalaci&oacute;n</option>
		<option value="4" <?php if( $articulo_tipo == '4') echo 'selected'; ?>>Curiosidad</option>
		<option>-</option>
		<option value="5" <?php if( $articulo_tipo == '5') echo 'selected'; ?>>Home</option>
		<option value="6" <?php if( $articulo_tipo == '6') echo 'selected'; ?>>Tienda</option>
		<option value="7" <?php if( $articulo_tipo == '7') echo 'selected'; ?>>Ocasi&oacute;n</option>
		<option value="8" <?php if( $articulo_tipo == '8') echo 'selected'; ?>>Curiosidades</option> 
	</select></td>
  <td width="570" class="data"><input name="articulo_orden" type="text" size="4" maxlength="3"  value="<?= $articulo_orden; ?>" style="width:40;"></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
<tr><td class= "lbl">Titular</td></tr>
<tr><td width="400" class="data"><textarea name="articulo_titular" cols="80" rows="2"><?= $articulo_titular; ?></textarea></td></tr>
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
<tr><td class= "lbl">Entradilla</td></tr>
<tr><td width="400" class="data"><textarea name="articulo_entradilla" cols="80" rows="3"><?= $articulo_entradilla; ?></textarea></td></tr>
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
<tr><td class= "lbl">Texto</td></tr>
<tr><td width="400" class="data"><textarea name="articulo_texto" cols="80" rows="12"><?= $articulo_texto; ?></textarea></td></tr>
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
<tr><td class= "lbl">Enlace</td></tr>
<tr><td width="400" class="data"><input name="articulo_enlace" type="text" size="80" maxlength="255" value="<?= $articulo_enlace; ?>"></td></tr>
<tr><td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
</table>
</form>

<?php
	if($operacion == 'edit') {
?>
<form method="post" action="articulos_img.php" name="formulario2" enctype="multipart/form-data">
<table width="450" border="0" cellpadding="0" cellspacing="0" id="imagenes">
  <tr>
    <td><span class="lbl">Im&aacute;genes:</span>
	 <input name="id" type="hidden" value="<?= $id; ?>">
	 <input name="op" type="hidden" value="add">
     <input name="prod_imagen" type="file" style="width:250px" class="data">&nbsp;&nbsp;<a href="javascript:document.formulario2.submit();" class="button">[ a&ntilde;adir ]</a></td>
  </tr>
	<tr>
		<td>
			<table border="1" cellspacing="0" cellpadding="0" bordercolor="#333333" style="margin-top:10px; border-style:solid; border-color:#444444; border:1px; border-padding:1px;">
				<tr>
<?php
// mira las imagenes para este articulo 
	$query = 'SELECT galeria_imagen_name FROM edito_galeria_imagenes WHERE galeria_articulo_id = ' . $id . ' ORDER BY galeria_imagen_name';
	$result = mysql_query($query, $conn);
	if($result){
		while($row_img = mysql_fetch_array($result)) {
			$path_108 = '../../_pics/' . $row_img['galeria_imagen_name'] . '_108.jpg';
?>
				<td align="center"><img src="<?= $path_108; ?>" width="108" hspace="4" vspace="4"><br />
			  <a href="articulos_img.php?op=del&id=<?= $id; ?>&img=<?= $row_img['galeria_imagen_name']; ?>" class="button">[ eliminar ]</a></td>
<?php
		}
	}
?>
				</tr>
			</table>
		</td></tr>
</table>
</form>
<?php
	}
?>
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td><img src="_imgs/d.gif" width="100" height="10"></td></tr>
	<tr>
	  <td width="300">
		<a href="javascript:history.go(-1)" class="button">[ cancelar ]</a>&nbsp;&nbsp;<a href="javascript:doSubmit();" class="button">[ Ok ]</a>
	</td>
		<td>
<?php
	if($operacion == 'edit') {
?>
		<a href="articulos_db.php?op=del&id=<?= $id; ?>" onClick="return confirm('Est&aacute;s seguro de querer borrar este art&iacute;culo?')" class="button">[ borrar ]</a></td>
<?php
	}
?>
	</tr>
</table>
</body>
</html>