ClaveAudio_Web/tienda.php
2011-05-06 11:33:27 +00:00

382 lines
14 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// ####################################################
// tienda.php
// parte de shoop
// © ff 2005
// ini_set('display_errors', 1);
// wfcart siempre antes del inicio de sesion
include("_incl/wfCart.php");
session_start();
include('db.php');
include("_incl/shoopOfertas.php");
include("_incl/shoopBanners.php");
// ####################################################
// cargo el carrito o lo creo nuevo si fuera menester
$cart =& $_SESSION['cart'];
if(!is_object($cart)) $cart = new wfCart();
// ####################################################
// la pagina puede estar en tres estados: indice, categoria y busqueda.
// el estado viene dado por los valores que tengo en las variables de busqueda.
// cuando accedo por menu paso el mismo parametro ['cat'] que cuando accedo por
// busquedas.
$buscar_str = (isset($_REQUEST['buscar']) ? $_REQUEST['buscar'] : '');
$marcas_str = (isset($_REQUEST['marcas']) ? $_REQUEST['marcas'] : '');
$cat_str = (isset($_REQUEST['cat']) ? $_REQUEST['cat'] : '');
define('INDICE', 1);
define('CATEGORIA', 2);
define('BUSQUEDAS', 3);
$estado = 0;
$productos = array('');
$numProductos = 0;
// ####################################################
// determino en que estado debo mostrar la pagina
if(strlen($buscar_str) + strlen($marcas_str) + strlen($cat_str) == 0) {
// nadie ha buscado nada, ni por campo ni por menu = estoy en el ndice
$estado = INDICE;
$topLabel = '<img src="_imgs/titTiendaMain.gif">';
} else {
// ####################################################
// si no estoy en el indice hago aqui la busqueda en funcion de lo que ha pedido el usuario
// la hago en este momento porque saco el dato de secci—n del primer registro, en lugar de hacer
// dos busquedas, uno para obtener ese dato y otra para obtener el contenido de la pagina
$result = false;
$conn = db_connect();
if($conn) {
$query = 'SELECT prod_id, seccion_nombre, cat_nombre, fab_nombre, prod_modelo, prod_precio, prod_categoria_id
FROM shoop_secciones, shoop_productos, shoop_fabricantes, shoop_categorias
WHERE cat_seccion=seccion_code AND prod_fab_id=fab_id 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($cat_str) > 0 ? ' AND prod_categoria_id="' . $cat_str . '"' : '') .
' ORDER BY prod_categoria_id, fab_nombre, prod_modelo';
$result = mysql_query($query, $conn);
if($result) {
$numProductos = mysql_num_rows($result);
if($numProductos) {
$row = mysql_fetch_array($result);
// por que no controlo el numero de resultados en este momento?
// para empezar asumo que la base siempre tendra datos y, entonces:
// si busco por categoria siempre tendre un resultado como minimo
// si busco por un fabricante lo mismo (mentira, puedo buscar por fabricante y texto, pero eso est‡ controlad
// por el hecho de que si el array est‡ vacio, row[fab_nombre]Êdevuelve '';
// si busco por texto libre no me importa que no haya rows: en el label tengo el texto de busqueda
// en el interface es donde digo que no hay resultados.
mysql_data_seek($result, 0); // rebobino para volver luego a leer en condiciones.
if(strlen($buscar_str) + strlen($marcas_str) == 0){
$estado = CATEGORIA;
$categoria_label = '<a href="tienda.php" class="pielink">Tienda&nbsp;></a>&nbsp;' . $row['seccion_nombre'] . '&nbsp;>&nbsp;' . $row['cat_nombre'];
} else {
$estado = BUSQUEDA;
$categoria_label = '<a href="tienda.php" class="pielink">Tienda&nbsp;></a>&nbsp;Buscando: ' . (strlen($marcas_str) ? $row['fab_nombre'] . ' ' : '') . $buscar_str;
}
$topLabel = '<span class="seccion">' . $categoria_label . '</span>';
} else {
$topLabel = '<span class="seccion"><a href="tienda.php" class="pielink">Tienda&nbsp;></a></span>';
}
} else { // tengo un error!!!!
$topLabel = '<span class="error">Ha ocurrido un error intentando conectar con el servidor</span>';
}
}
}
// ####################################################
// llegados a este punto sabemos en que estado esta la pagina
// tenemos, incluso, los resultados de la busqueda, if any
?>
<!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>clave audio</title>
<link href="_incl/ca.css" rel="stylesheet" type="text/css" />
<link href="_incl/sformi.css" rel="stylesheet" type="text/css" />
<link href="_incl/banners.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="_incl/code.js"></script>
</head>
<body>
<?php
// ####################################################
// la banda superior y el menœ principal
include('top.htm');
// ####################################################
// esta es la tabla general que da forma a la pagina.
?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7"><img src="_bann/topTienda.jpg"></td></tr>
<tr>
<td><img src="_imgs/d.gif" width="168" height="12"></td>
<td><img src="_imgs/d.gif" width="12" height="12"></td>
<td><img src="_imgs/d.gif" width="168" height="12"></td>
<td><img src="_imgs/d.gif" width="12" height="12"></td>
<td><img src="_imgs/d.gif" width="168" height="12"></td>
<td><img src="_imgs/d.gif" width="12" height="12"></td>
<td><img src="_imgs/d.gif" width="168" height="12"></td></tr>
<tr>
<td valign="top">
<?php
// ####################################################
// la celda que contiene el buscador, el menu y el carrito.
?>
<table border="0" cellspacing="0" cellpadding="0" id="colIzda">
<tr>
<td bgcolor="#7A706A"><img src="_imgs/d.gif" width="6" height="12"></td>
<td bgcolor="#7A706A"><img src="_imgs/titSearch.gif" width="156" height="18"></td>
<td bgcolor="#7A706A" align="right"><img src="_imgs/crnr.gif" width="6" height="18"></td></tr></table>
<?php include("buscar.php"); ?>
<img src="_imgs/d.gif" width="168" height="12"><br>
<?php
$menu_cat = (strlen($cat_str) ? substr($cat_str, 0, 2) : '');
include("categorias.php");
?>
<img src="_imgs/d.gif" width="168" height="12"><br>
<?php include("carrito.php"); ?></td>
<td></td>
<td colspan="5" valign="top" width="528">
<?php
// ####################################################
// esta parte es comun: texto y destacado de 3 columnas.
?>
<table border="0" cellspacing="0" cellpadding="0" id="topClaim">
<?php
// ####################################################
// dependiendo de si estoy en el indice muestro el bienvenidos o el nombre de la secci—n/busqueda.
?>
<tr><td><?php echo $topLabel; ?><br><img src="_imgs/g.gif" width="528" height="1"></td></tr>
<tr><td>
<?php
// ####################################################
// este es el destacado que aparece en la parte superior de todas las paginas de la tienda.
// quiero una oferta de tipo dos de la categoria que me han pasado (o de cualquiera si no hay categora)
$miOferta = new shoopOfertas(1, $cat_str, 2);
if($miOferta->getNum()){
$arrayOferta = $miOferta->getNextOferta();
include('bann2.php');
array_push($productos, $arrayOferta['id_modelo']);
if(strlen($cat_str)) $numProductos--;
?>
</td></tr>
<tr><td background="_imgs/ptoshb.gif"><img src="_imgs/d.gif" width="168" height="8"></td></tr>
<?php
}
?>
</table>
<?php
// ####################################################
// si estoy en el indice (ver arriba) incluyo un texto de saludo y los accesos a las condiciones y el pedir mas info
if($estado == INDICE) {
?>
<table border="0" cellspacing="0" cellpadding="0" id="saludo">
<tr><td><img src="_imgs/d.gif" width="168" height="8"></td></tr>
<tr>
<td width="528" class="parr">Clave Audio lleva m&aacute;s de <b>13 a&ntilde;os</b> abierta al p&uacute;blico en la calle Padilla, 68, en el centro de Madrid. Abrimos
ahora esta tienda on line con el deseo de que nuestros productos, profesionalidad y conocimientos lleguen a un mayor n&uacute;mero de buenos aficionados al audio de alta calidad.<br>
<br>
La tienda online no abarca el enorme cat&aacute;logo de productos que podemos ofrecer. Si no encuentras un determinado producto, no dudes en consultarnos sobre precio y disponibilidad.<br><br>
<a href="clavefaq.php">Condiciones de uso de la tienda</a></td></tr>
<tr><td background="_imgs/ptoshb.gif"><img src="_imgs/d.gif" width="168" height="8"></td></tr>
</table>
<?php
// fin de texto de saludo en el indice
}
?>
<?php
// ####################################################
// todas las versiones llevan tres recomendaciones
// excepto si estoy en una busqueda
if($estado == CATEGORIA) {
$miOferta = new shoopOfertas(3, $cat_str);
if($miOferta->getNum() >= 3) {
?>
<table border="0" cellpadding="0" cellspacing="0" id="banners">
<tr>
<td><img src="_imgs/d.gif" width="168" height="6"></td>
<td><img src="_imgs/d.gif" width="12" height="1"></td>
<td><img src="_imgs/d.gif" width="168" height="1"></td>
<td><img src="_imgs/d.gif" width="12" height="1"></td>
<td><img src="_imgs/d.gif" width="168" height="1"></td>
</tr>
<tr>
<td>
<?php
$arrayOferta = $miOferta->getNextOferta();
include('bann3.php');
array_push($productos, $arrayOferta['id_modelo']);
$numProductos--;
?>
</td>
<td background="_imgs/ptosvb.gif"><img src="_imgs/d.gif" width="12" height="160"></td>
<td>
<?php
$arrayOferta = $miOferta->getNextOferta();
include('bann3.php');
array_push($productos, $arrayOferta['id_modelo']);
$numProductos--
?>
</td>
<td background="_imgs/ptosvb.gif"><img src="_imgs/d.gif" width="12" height="1"></td>
<td>
<?php
$arrayOferta = $miOferta->getNextOferta();
include('bann3.php');
array_push($productos, $arrayOferta['id_modelo']);
$numProductos--
?>
</td>
</tr>
<tr>
<td><img src="_imgs/d.gif" width="168" height="12"></td>
<td><img src="_imgs/d.gif" width="12" height="1"></td>
<td><img src="_imgs/d.gif" width="168" height="1"></td>
<td><img src="_imgs/d.gif" width="12" height="1"></td>
<td><img src="_imgs/d.gif" width="168" height="1"></td>
</tr>
</table>
<?php
// fin de los tres minibanners
}
}
// ####################################################
// ultima aparicion del indice: coloco un banner de tres columnas
if($estado == INDICE) {
?>
<table border="0" cellspacing="0" cellpadding="0" id="banner">
<tr><td width="528"><img src="_imgs/d.gif" width="528" height="12"></td></tr>
<tr><td width="528">
<?php
// el par‡metro que paso es el nœmero de baners de tipo 1 que quiero
$miBanner = new shoopBanners(1, 528);
if($miBanner->getNum()) {
echo $miBanner->getNextBanner();
}
?>
</td></tr>
</table>
<?php
// ####################################################
// el indice acaba aqui. ahora es el contenido de una pagina de categoria o de busquedas.
// vamos a ello.
} else {
// ####################################################
// primero miro si tengo un resultado de busqueda
// el mensaje de error para este fallo lo he mostrado ya en la cabecera de la pagina
// busca $toplabel
if($result && $numProductos) {
?>
<table border="0" cellspacing="0" cellpadding="0" width="528">
<?php
// ####################################################
// si estoy en modo categora no mostrare la misma cabecera que en modo buscar
if($estado == CATEGORIA) {
$colSpan='2';
?>
<tr>
<td colspan="2"><img src="_imgs/d.gif" width="2" height="6"></td></tr>
<tr>
<td colspan="2" class="tit azul">Otros productos en esta categor&iacute;a...</td></tr>
<tr>
<td colspan="2" background="_imgs/ptoshg.gif"><img src="_imgs/d.gif" width="2" height="1"></td></tr>
<?php
} else {
$colSpan='3';
?>
<tr>
<td colspan="3"><img src="_imgs/d.gif" width="2" height="6"></td></tr>
<tr>
<td colspan="3" class="tit azul">Resultados de su B&uacute;squeda por "<?php echo (strlen($marcas_str) ? $row['fab_nombre'] . ' ' : '') . $buscar_str; ?>"</td></tr>
<tr>
<td colspan="3" background="_imgs/ptoshg.gif"><img src="_imgs/d.gif" width="2" height="1"></td></tr>
<?php
}
$curSeccion='';
while ($row = mysql_fetch_array($result))
{
$prod_id = $row['prod_id'];
if(!in_array ($prod_id, $productos)) {
$prod_categoria = $row['cat_nombre'];
$prod_fab_id = $row['fab_nombre'];
$prod_modelo = $row['prod_modelo'];
$prod_precio = $row['prod_precio'];
$seccion_nombre = $row['seccion_nombre'];
$prod_categoria_id = $row['prod_categoria_id'];
if($estado != CATEGORIA && $seccion_nombre != $curSeccion){
$curSeccion = $seccion_nombre;
?>
<tr>
<td colspan="<?php echo $colSpan; ?>" class="lbl"><?php echo $seccion_nombre; ?><img src="_imgs/d.gif" width="15" height="18"></td></tr>
<?php
}
?>
<tr onMouseOver="overRow(this);" onMouseOut="outRow(this);">
<?php
if($estado != CATEGORIA){
?>
<td width="240" valign="top" class="data">&nbsp;&nbsp;&nbsp;<?php echo substr($prod_categoria, 0, 25) . (strlen($prod_categoria) > 25 ? '...' : ''); ?></td>
<?php
}
?>
<td width="330" valign="top" class="data"><?php echo '<a href="producto.php?id=' . $prod_id . '&cat=' . $prod_categoria_id . '" class="pielink"><b>' . $prod_fab_id . '</b> ' . $prod_modelo . '</a>'; ?></td>
<td width="100" valign="top" class="data" align="right"><?php echo ($prod_precio == -1 ? '<a href="javascript:doConsultar(' . $prod_id . ', \'precio\', \'' . componProducto($prod_categoria, $seccion_nombre) . str_replace('&', 'etperse', $prod_fab_id) . ' ' . str_replace('&', 'etperse', $prod_modelo) . '\');" class="pielink"><b>CONSULTAR</b></a>' : miNumberFormat($prod_precio) . '&euro;'); ?></td></tr>
<tr>
<td bgcolor="#EDEEF1" colspan="<?php echo $colSpan; ?>"><img src="_imgs/d.gif" width="2" height="1"></td></tr>
<?php
}
} // while
?>
</table>
<?php
} else {
echo 'no hay resultados';
}
}
?>
</td></tr>
<tr><td colspan="7"><img src="_imgs/d.gif" width="708" height="12"></td></tr>
<tr>
<td colspan="7"><?php include('pie.htm'); ?></td>
</tr>
<tr><td colspan="7"><img src="_imgs/d.gif" width="708" height="12"></td></tr>
</table>
</body>
</html>