<?php
session_start();

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

include('../../_incl/code.php');
include('../db.php');

// si los campos de boesqueda est?n vac'os intento usar los que he guardado previamente en las cookies
$buscar_str = $_REQUEST['buscar'];
$marcas_str = $_REQUEST['marcas'];
$categorias_str = $_REQUEST['categorias'];


$longi = strlen($buscar_str) + strlen($marcas_str) + strlen($categorias_str);
if(!$longi) {
	if(isset($_COOKIE['clave_admin'])) {
	
		foreach ($_COOKIE['clave_admin'] as $name => $value) {
			switch($name){
				case 'buscar':
					$buscar_str = $value;
					break;
				case 'marcas':
					$marcas_str = $value;
					break;
				case 'categorias':
					$categorias_str = $value;
					break;
			}
		}
	}
} else {
	$time =  time() + 60 * 60 * 24 * 7;
	setcookie('clave_admin[buscar]', $buscar_str, $time);
	setcookie('clave_admin[marcas]', $marcas_str, $time);
	setcookie('clave_admin[categorias]', $categorias_str, $time);
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>productos</title>
<script language="javascript">function doBuscar(){document.buscador.submit();}</script>
<link href="../sformi.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.destacado {
	overflow: hidden;
	height: 140px;
	width: 528px;
	padding-top: 6px;
	border-top: 1px solid #666666;
}

.destacado_logo {
	overflow: hidden;
	position: relative;
	width: 186px;
	height: 42px;
}

.destacado_foto {
	overflow: hidden;
	position: relative;
	width: 247px;
	height: 95px;
}

.destacado_tipo {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	text-transform: uppercase;
	line-height: 10px;
	position: relative;
	top: 6px;
}

.destacado_datos {
	float: right;
	position: relative;
	overflow: hidden;
	height: 150px;
	width: 247px;
	padding-left: 12px;
	padding-top: 6px;
}

.destacado_modelo {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 15px;
	font-weight: bold;
	position: relative;
	top: 6px;
}

.destacado_precio {
	font-family: "Times New Roman", Times, serif;
	font-size: 36px;
	color: #CB2C54;
	font-weight: normal;
	position: relative;
	top: 2px;
}

.destacado_texto {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	position: relative;
}

.destacado_linea {
	width: 279px;
	height: 12px;
	position: relative;
	background: url(_imgs/ptoshb.gif);
}
.oferta_texto {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	position: relative;
	top: 14px;
}

.euro {
	font-size: 24px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color: #ACADB0;
	font-weight: normal;
}
.azul {
	color: #00539D;
}

-->
</style>
</head>
<body>
<!-- CONTENT -->
<form id="buscador" name="buscador" action="productos_foto.php" method="post">
<table border="0" cellspacing="0" cellpadding="2">
	<tr>
	  <td width="200"><a href="productos_edit.php?op=add" class="button">[ a&ntilde;adir
	      producto ]</a>&nbsp;<a href="productos.php" class="button">[ sin foto ]</a></td>
      <td width="100" bgcolor="#FFFF99"><div align="right"><input name="buscar" type="text" id="buscar" maxlength="20" style="width:100px;" class="data"></div></td>
      <td width="130" bgcolor="#FFFF99"><div align="center"><select name="marcas" id="marcas" style="width:130px;" class="data">
            <option value=""  selected>Marcas</option>
            <?php include("menu_marcas.php"); ?>
      </select></div></td>
      <td width="130" bgcolor="#FFFF99"><div align="center"><select name="categorias" id="categorias" style="width:130px;" class="data">
            <option value="" selected>Categor&iacute;as</option>
            <?php include("../../categorias2.htm"); ?>
      </select></div></td>
      <td width="60" align="right" bgcolor="#FFFF99"><div align="center"><span class="button"><a href="javascript:doBuscar();" class="labels">[ buscar ] </a></span></div></td>
    </tr>
	<tr><td colspan="5"><img src="../_imgs/d.gif" width="200" height="5"></td></tr>
 </table>
<table border="0" cellspacing="0" cellpadding="0">
<?php
$conn = db_connect();
if($conn) {
	$query = 'SELECT	prod_id, seccion_nombre, cat_nombre, cat_seccion, prod_fab_id, prod_modelo, prod_modelo, prod_precio, prod_descripcion
						FROM shoop_secciones, shoop_productos, shoop_categorias
						WHERE	cat_seccion=seccion_code AND prod_categoria_id=cat_codigo ' .  
								(strlen($buscar_str) > 0 ? ' AND prod_modelo LIKE "%' . $buscar_str . '%" ' : '') .
								(strlen($marcas_str) > 0 ? ' AND prod_fab_id=' . $marcas_str : '') .
								(strlen($categorias_str) > 0 ? ' AND prod_categoria_id="' . $categorias_str . '"' : '') . 
						' ORDER BY prod_categoria_id, prod_modelo';

	$result = mysql_query($query, $conn);
//	$num_results = mysql_num_rows($result);
?>
<?php
	$curSeccion='';
	while ($row = mysql_fetch_array($result))
	{
		$seccion_nombre = $row['seccion_nombre'];

		if($seccion_nombre != $curSeccion){
			$curSeccion = $seccion_nombre;
?>
		<tr>
			<td colspan="2" class="lbl"><?php echo $seccion_nombre; ?><img src="../_imgs/d.gif" width="15" height="20"></td>
		</tr>
<?php
		}
?>
	<tr>
		<td width="160" valign="top" class="data">
	<div class="destacado">
	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="247"><img src="_imgs/d.gif" width="247" height="1"></td>
			<td width="12"><img src="_imgs/d.gif" width="12" height="1"></td>
			<td width="279"><img src="_imgs/d.gif" width="279" height="1"></td>	</tr>
		<tr>
			<td width="247"  align="center" valign="middle">
				<div class="destacado_foto"><img src="../../_prds/<?php echo $row['prod_id']; ?>_247.jpg" border="0"></div>
				<div class="destacado_precio"><?php echo ($row['prod_precio'] <= 0 ? 'Consultar' : miNumberFormat($row['prod_precio']) . '<span class="euro">&euro;</span>'); ?></div></td>
			<td width="12"><img src="_imgs/d.gif" width="12"></td>
			<td width="279" valign="top">
				<div class="destacado_logo"><img src="../../_logos/b/<?php echo $row['prod_fab_id']; ?>.gif"></div>
				<div class="destacado_linea"><img src="../_imgs/d.gif" width="279" height="12"></div>
				<div class="destacado_tipo azul"><?php echo componProducto($row['cat_nombre'], $row['cat_seccion']); ?></div>
				<div class="destacado_modelo"><?php echo $row['prod_modelo']; ?></div>
				<div class="oferta_texto"><?php if(strlen($row['prod_descripcion'])) { echo substr($row['prod_descripcion'], 0, 150) . '...'; } ?></div></td></tr>
	</table>
</div></td>
		<td class="data" >&nbsp;&nbsp;<a href="productos_edit.php?op=edit&id=<?php echo $row['prod_id']; ?>" class="button">[ editar ]</a></td>
	</tr>
<?php
	}	// while
} else {	// IF CONN
	echo '<p>An error has occurred while accessing the database: ' . mysql_error();
}	 
?>
</table>
<!-- END OF CONTENT -->
</form>
</body>
</html>
