KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/logicswapweb/aplicaciones/admon/catalogo/fnc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/logicswapweb/aplicaciones/admon/catalogo/fnc/Catalogo.php
<?php

class Catalogo extends Aplicacion
{

	var $fecha_actual;
	var $aplicacion = "Catalogo";
	var $dirSetup = "/aplicaciones/admon/catalogo";
	var $categoria;
	var $producto;
	var $tokenNone="none";
	var $utileria;
	var $subProductos;
	var $img_categorias=true;
	var $img_cats_nivel; /* Permite o no colocar imagenes a cada nivel de categorias */
	var $prods_cats_nivel; /* Permite o no productos a cada nivel de categorias */
	var $sub_prods_cats_nivel; /* Permite o no productos a cada nivel de categorias */
	var $campos_cat_nivel;
	var $archivos;

	function Catalogo($subDir="/",$dirSetup="aplicaciones/admon/catalogo/")
	{	
		$this->Aplicacion();
		$this->fecha_actual = date('Y-m-d');
		$this->utileria  = new Utileria(); 
		$this->subDir = $subDir;
		$this->dirSetup = $dirSetup;
		$this->categoria = new Categoria($this);
		$this->producto = new Producto($this);
		$this->parametro = new parametro();
		$this->subProductos = true;
		$this->img_categorias = true;
		$this->archivos = false;

		$img_niveles = array();
		$img_niveles[0] = false;
		$img_niveles[1] = false;
		$img_niveles[2] = false;
		$img_niveles[3] = false;

		$prods_nivel = array();
		$prods_nivel[0] = false;
		$prods_nivel[1] = true;
		$prods_nivel[2] = true;
		$prods_nivel[3] = true;

		$sub_prods_nivel = array();
		$sub_prods_nivel[0] = true;
		$sub_prods_nivel[1] = true;
		$sub_prods_nivel[2] = true;
		$sub_prods_nivel[3] = true;

		$campos_nivel = array();
		$campos_nivel[0] = false;
		$campos_nivel[1] = false;
		$campos_nivel[2] = false;
		$campos_nivel[3] = false;

		$this->campos_cat_nivel 	= $campos_nivel;
		$this->sub_prods_cats_nivel = $sub_prods_nivel;
		$this->prods_cats_nivel 	= $prods_nivel;
		$this->img_cats_nivel 		= $img_niveles;
	} // fin  Catalogo	

	/********************************** Funciones para subir y eliminar imagenes *********************************************/
	function captureUpload($destDir,$nameCallback = false,$fieldName = '_upload',$maxFileSize = false){
	   //make sure something is there
		$this->reactivarDB();
	   if(!isset($_FILES[$fieldName]) || !isset($_FILES)|| !is_array($_FILES[$fieldName]) || !$_FILES[$fieldName]['name'])
		   return array(false,"El formulario no tiene la etiqueta enctype=\"multipart/form-data\"");
	   //normalize the file variable
	   $file = $_FILES[$fieldName];
	   if (!isset($file['type']))      $file['type']      = '';
	   if (!isset($file['size']))      $file['size']      = '';
	   if (!isset($file['tmp_name']))  $file['tmp_name']  = '';
	   $file['name'] = preg_replace('/[^a-zA-Z0-9\.\$\%\'\`\-\@\{\}\~\!\#\(\)\&\_\^]/','',str_replace(array(' ','%20'),array('_','_'),$file['name']));
	   //was it to big?
	   if($maxFileSize && ($file['size'] > $maxFileSize))
		   return array(false,"El tama�o del archivo es muy grande");
	   //normalize destDir
	   if(strlen($destDir)>0 && $destDir[strlen($destDir)-1] != "/")
		   $destDir = $destDir.'/';
	   //should we change the filename via a callback?
	   if($nameCallback)
		   $file['name'] = call_user_func_array($nameCallback, array($file,$destDir));
	   $i = 0;    
	   //if the filename already exists, append _copy_x (with extension)
	   if(strpos($file['name'],'.') !== false){
		   $bits = explode('.',$file['name']);
		   $ext = array_pop($bits);
		   while(file_exists($destDir.implode('.', $bits).($i?'_copy_'.$i:'').'.'.$ext)){
			   ++$i;
			   $file['name'] = implode('.',$bits).($i?'_copy_'.$i:'').'.'.$ext;
		   }
	   //if the filename already exists, append _copy_x (no extension)
	   } else {
		   while(file_exists($destDir.$file['name'].($i ?'_copy_'.$i:''))){
			   ++$i;
			   $file['name'] = $file['name'].($i?'_copy_'.$i:'');
		   }
	   }
	   //and now the big moment
	   if(!@copy($file['tmp_name'], $destDir.$file['name']))
		   return array(false,"Permission denied to copy the file");
	   else
		   return array(true,$file['name']);
	} 


	function add_img_categoria( $titulo='',$img_pri='',$img_sec='', $ancho='', $alto='', $id_categ)
	{
		//$this->setFiles(4);
		$sql = "SELECT id FROM catalogo_imagen WHERE producto='$id_categ' AND titulo='$titulo' AND tipo like '%categoria%'";
		if($this->execute($sql))
		{
			$cant=$this->numRows();
		}
		if($cant==0)
		{
					if($img_pri!="none")
					{ 
						//se sube el fichero al servidor
						list($success,$response) = $this->captureUpload('../archivos/',false,'img_pri');						
						if(!$success)
						{ 
							$msg = "archivo: ".$response;
							$this->mostrarMensaje($msg);
						}
						//sql para registrar fichero en la DB
						
						
						$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$id_categ','categoria-principal','$titulo','$response','$ancho','$alto')";
						
						if(!$this->execute($sql2))
						{
							$this->mostrarMensaje($this->getMensaje("[016]","error"));
						}
					}
			
					if($img_sec!="none")
					{ 
						//se sube el fichero al servidor
						list($success,$response) = $this->captureUpload('../archivos/',false,'img_sec');						
						if(!$success)
						{ 
							$msg = "archivo: ".$response;
							$this->mostrarMensaje($msg);
						}
						//sql para registrar fichero en la DB
						$tipo = $this->insertId();
						$proporcion=$ancho/$alto;
						$ancho_sec=314;
						$alto_sec=$ancho_sec/$proporcion;
						$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$id_categ','categoria-$tipo','$titulo','$response','$ancho_sec','$alto_sec')";
						
						if(!$this->execute($sql2))
						{
							$this->mostrarMensaje($this->getMensaje("[016]","error"));
						}
					}
					
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[259]","confirmacion"));
			return false;
		}
		return true;
	}
	function eliminar_imagenes_categoria($id_cat)
	{
		//$this->setFiles(4);
		$db= new DBManager('MySQL');
		$db->connect();
	
		$sql1= "select id, fichero FROM catalogo_imagen where producto='$id_cat' and tipo like '%categoria%'";
		$cant;
		if($this->execute($sql1))
		{
			$cant = $this->numRows();
			while(list($id, $fichero)=$this->fetchRow())
			{
				$rutafoto = "../archivos/".$fichero;
				//borrado del archivo o archivos
				if (file_exists($rutafoto))
				{
					if(unlink($rutafoto))
					{
						$sql = "delete FROM catalogo_imagen where id = '$id'";
						if(!$db->execute($sql) )
						{
							$db->isDebuggerEnabled();
							$msg = $db->getException();
							$this->mostrarMensaje($this->getMensaje("[016]","error"));
						}else
						{
							$cant--;
						}
					}else
					{
						$this->mostrarMensaje($this->getMensaje("[200]","error"));
					}
				}else
				{
					$this->mostrarMensaje($this->getMensaje("[200]","error")." EL archivo ".$fichero." no existe!");
				}
			}
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));
		}	
	}

	/**********************************************************************************/



	function add_categoria($nombre,$descripcion,$tipo,$permiso, $titulo='',$img_pri='',$img_sec='', $ancho='', $alto='')
	{
		//$this->setFiles(2);
		$sql = "SELECT id FROM catalogo_categoria WHERE nivel='0' AND nombre='$nombre'";
		$this->execute($sql);

		$cant=$this->numRows();
		$this->utileria  = new Utileria();
		$descripcion = $this->utileria->parseInput2DB($descripcion);


		if($cant==0)
		{	
			$sql = "insert into catalogo_categoria (nombre, descripcion, tipo, permiso, nivel) values ('$nombre','$descripcion','$tipo','$permiso','0')";
			if($this->execute($sql))
			{
				$out=trim($this->getMensaje("[250]","confirmacion"));
				$this->setSalida(true,$out,"add_categoria($nombre,$descripcion,$tipo,$permiso)",$this->aplicacion);	

				/* Si el catalogo incluye imagenes por categoria */
				if($this->img_categorias === true && $this->img_cats_nivel[0] === true)
				{
					$id_categ = $this->insertId();
					$this->add_img_categoria($titulo,$img_pri,$img_sec, $ancho, $alto, $id_categ);

				}				
			}else
			{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));
			}
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[204]","error"));
			return false;
		}
			return true;
	} // fin  add_categoria

	function mod_categoria($id_,$nombre,$descripcion,$permiso)
	{
		//$this->setFiles(4);
		$this->utileria  = new Utileria();
		$descripcion = $this->utileria->parseInput2DB($descripcion);
		$sql = "SELECT id FROM catalogo_categoria WHERE nivel='0' AND nombre='$nombre' AND id!='$id_'";
		$this->execute($sql);
		$cant=$this->numRows();
		if($cant==0)
		{		
			$sql = "update catalogo_categoria set nombre ='$nombre', descripcion='$descripcion', permiso='$permiso'  where id='$id_'";
			if($this->execute($sql))
			{
				$this->mostrarMensaje($this->getMensaje("[252]","confirmacion"));
				return true;
			}else
			{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));
				return false;
			}	
		}
		else
		{
			$this->mostrarMensaje($this->getMensaje("[251]","confirmacion"));
			return false;
		}		
		return true;
	
	} // fin  mod_categoria

	function add_subcategoria($nivel,$nombre,$tipo,$descripcion,$permiso,$id,$name_categoria,$ids, $idss, $name_subcategoria, $titulo='',$img_pri='',$img_sec='', $ancho='', $alto='')
	{
		//$this->setFilesApli(4);
		$this->utileria  = new Utileria();
		$descripcion = $this->utileria->parseInput2DB($descripcion);

		if($nivel==1){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='1' AND parent='$id' AND nombre='$nombre'";
		}
		if($nivel==2){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='2' AND parent='$ids' AND nombre='$nombre'";
		}	
		if($nivel==3){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='3' AND parent='$idss' AND nombre='$nombre'";
		}	

		$this->execute($sql);
		$cant=$this->numRows();
		if($cant==0)
		{

			if($nivel==1)
			{
				$sql = "insert into catalogo_categoria (nombre, tipo, descripcion, permiso, parent, nivel) values ('$nombre','$tipo','$descripcion','$permiso','$id','$nivel')";
			}
			if($nivel==2)
			{
				$sql = "insert into catalogo_categoria (nombre, tipo, descripcion, permiso, parent, nivel) values ('$nombre','$tipo','$descripcion','$permiso','$ids','$nivel')";	
			}
			if($nivel==3)
			{
				$sql = "insert into catalogo_categoria (nombre, tipo, descripcion, permiso, parent, nivel) values ('$nombre','$tipo','$descripcion','$permiso','$idss','$nivel')";	
			}
			
			if ($this->execute($sql)) 
			{
				$this->mostrarMensaje($this->getMensaje("[250]","confirmacion"));
				$id_categ = $this->insertId();
				/* Si el catalogo incluye imagenes por categoria */
				if($this->img_categorias === true  && $this->img_cats_nivel[$nivel] === true)
				{
					
					$this->add_img_categoria($titulo,$img_pri,$img_sec, $ancho, $alto, $id_categ);
				}
			}else
			{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));		
			}				
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[204]","error"));
			return false;
		}
		return $id_categ;
	} // fin add_subcategoria



	/*modificar subcategoria*/
	function mod_subcategoria($nivel,$nombre,$descripcion,$permiso,$id,$ids,$idss)
	{						
		//$this->setFiles(4);
		if($nivel==1){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='1' AND parent='$id' AND nombre='$nombre' AND id!='$ids'";
		}
		if($nivel==2){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='2' AND parent='$ids' AND nombre='$nombre' AND id!='$idss'";
		}	
		if($nivel==3){
			$sql = "SELECT id FROM catalogo_categoria WHERE nivel='3' AND parent='$ids' AND nombre='$nombre' AND id!='$idss'";
		}	
		
		if(!$this->execute($sql))
		{
			$out=trim($this->getMensaje("[016]","error"));		
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"mod_subcategoria($nivel,$nombre,$descripcion,$permiso,$id,$ids,$idss)",$this->nombre);
			return false;
	
		}
		$cant=$this->numRows();
		$descripcion = $this->utileria->parseInput2DB($descripcion);
	
		if($cant==0)
		{
			
			if($nivel==1)
			{
				$sql = "update catalogo_categoria set nombre ='$nombre', descripcion='$descripcion', permiso='$permiso' where id='$ids'";
			}
			if($nivel==2)
			{
				$sql = "update catalogo_categoria set nombre ='$nombre', descripcion='$descripcion', permiso='$permiso' where id='$idss'";
			}	
			if($nivel==3)
			{
				$sql = "update catalogo_categoria set nombre ='$nombre', descripcion='$descripcion', permiso='$permiso' where id='$idss'";
			}	

			if ($this->execute($sql)) {
				$this->mostrarMensaje($this->getMensaje("[252]","confirmacion"));
			} 
			else 
			{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));
			}
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[251]","confirmacion"));
			return false;
		}
		return true;
	}
	
	function eliminar_categoria($nivel,$id,$ids,$idss)
	{
		if($nivel == 3)
		{
			$this->eliminar_categoria_aux($idss);
		}

		if($nivel == 2)
		{
			$this->eliminar_categoria_aux($idss);
		}
		if($nivel == 1)
		{
			$sql="SELECT id FROM catalogo_categoria WHERE parent='$ids' AND tipo='subcategoria'";
			$res = $this->consultarCampos($sql, "eliminar_categoria($nivel,$id,$ids,$idss)");
			
			
			if($res && count($res) > 0)
			{
				foreach($res as $r)
				{
					$this->eliminar_categoria_aux($r[0]);
				}
			}
			$this->eliminar_categoria_aux($ids);
		}

		if($nivel == 0)
		{
			$sql="SELECT id FROM catalogo_categoria WHERE parent='$id' AND tipo='subcategoria'";
			$res = $this->consultarCampos($sql, "eliminar_categoria($nivel,$id,$ids,$idss)");
			
			if($res && count($res) > 0)
			{
				foreach($res as $r)
				{

					$sql="SELECT id FROM catalogo_categoria WHERE parent='$r[0]' AND tipo='subcategoria'";
					$res2 = $this->consultarCampos($sql, "eliminar_categoria($nivel,$id,$ids,$idss)");
					
					if($res2 && count($res2) > 0)
					{
						foreach($res2 as $r2)
						{
							$this->eliminar_categoria_aux($r2[0]);
						}
					}

					$this->eliminar_categoria_aux($r[0]);
				}
			}
			$this->eliminar_categoria_aux($id);
		}
		

	}

	function eliminar_categoria_aux($id_cat)
	{

		$sql="SELECT id FROM catalogo_producto WHERE categoria='$id_cat'";
		$this->execute($sql);
			//cantidad de productos en esta subcarpeta
		$cant_documentos= $this->numRows(); 
		if($cant_documentos>0)
		{
			while(( list($id_pro)=$this->fetchRow()) )
			{
					$this->categoria->eli_producto($id_pro,'','','','', 1);
			}
		} 
			
		$this->eli_campos_cat($id_cat);
		if($this->img_categorias === true)$this->eliminar_imagenes_categoria($id_cat);

		$sql = "DELETE FROM catalogo_categoria WHERE id = '$id_cat'";
		if(!$this->execute($sql))
		{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));
		}else
		{
			$this->mostrarMensaje($this->getMensaje("[253]","confirmacion"));
		}
	}




	function fecha($fecha_ing)
	{
		if(substr(substr($fecha_ing,5),0,2)=="01")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Enero ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="02")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Febrero ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="03")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Marzo ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="04")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Abril ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="05")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Mayo ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="06")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Junio ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="07")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Julio ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="08")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Agosto ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="09")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Septiembre ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="10")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Octubre ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="11")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Noviembre ".$dia." del ".$ano;
		}
		if(substr(substr($fecha_ing,5),0,2)=="12")
		{
			$dia=substr(substr($fecha_ing,8),0,2);
			$ano=substr($fecha_ing,0,4);
			$fechaing="Diciembre ".$dia." del ".$ano;
		}
		return $fechaing;
	} 

	// Esta funcion solo sirve para consultas donde se nesecita
	// conocer el valor de un campo espesifico.
	// ej: $sql="SELECT nombre FROM catalogo_producto WHERE id='$id_pro'";
	// $func es el nombre del metodo desde donde se invoca a consultarCampo,
	// esto para poder mostrar el error adecuadamente
	function consultarCampo($sql, $func)
	{
		//$this->setFiles(4);
		if($this->execute($sql))
		{
			$n = $this->fetchRow();	
			return $n[0];		
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));		
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,$func,$this->nombre);
			return false;
		}
	}

	/*
	Esta funcion retorna un array con el contenido de una consulta donde se esperan varios resultados;
	*/
	function consultarCampos($sql, $func)
	{
		//$this->setFiles(4);
		$array = array();
		$i = 0;
		if($this->execute($sql))
		{			
			while($row = $this->fetchRow())
			{
				$array[] = $row;
				$i++;
			}	
			if($i > 0)
				return $array;	
			else return NULL;
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));		
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,$func,$this->nombre);
			return NULL;
		}
	}


	function getNombreProducto($id_pro)
	{
		$sql="SELECT nombre FROM catalogo_producto WHERE id ='$id_pro'";
		return $this->consultarCampo($sql, "getNombreProducto(id_pro)");
	} // fin function getNombreProducto

	function getInfoCategoriaWeb($id)
	{
		$this->utileria = new Utileria();
		$sql = "SELECT id,nombre,descripcion,permiso FROM catalogo_categoria WHERE id = ".$id;
		
		if($this->execute($sql))
		{
			$cat = array();
			$cat = $this->fetchRow();
			$cat[2] = $cat['descripcion'] = $this->utileria->parseDB2Html($cat['descripcion']);
			return $cat;
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"info_categoriaDBInput($nivel, $id, $ids, $ids)",$this->nombre);
			return NULL;	
	
		}
	}
	function getNombreCategoria($id)
	{
		$sql="select nombre from catalogo_categoria where id='$id'";
		return $this->consultarCampo($sql, "getNombreCategoria(id)");
	}

	function existeVinculo($id_usuario, $aplic, $adm=0)
	{
		if($adm == 1)
		{
			$sql = "SELECT id FROM vinculo WHERE usuario_panel='$id_usuario' AND aplicacion='$aplic' AND administrador='SI'";
			return $this->consultarCampo($sql, "existeVinculo(id_usuario, aplic, adm=0)");
			
		}else
		{
			return false;
		}
	}



	function listarProductosCatalogo($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin=1, $find='')
	{
			//$this->setFiles(4);
			$limite = $this->limite; /* numero de registros a mostrar */
			$inicio = $this->inicioPagina($nun_pag);
			if($nivel>0)
			{
				$sql = "SELECT id, nombre, referencia, permiso FROM catalogo_producto WHERE categoria = '$id' and tipo='p' order by id asc LIMIT $inicio,$limite";
			}
			if($find)
			{
					    $sql = "select id, nombre, permiso FROM catalogo_producto WHERE (nombre like '%$find%') or (descripcion like '%$find%') and tipo='p' order by nombre asc LIMIT $inicio,$limite";
			}

			$script = 	'';
			if($this->execute($sql))
			{
				
				$i=1;
				$j=0;
				$subCat = array();
				$subCat = $this->consultarCampos($sql, "listarCategoria($nivel)");

				if ($subCat && $this->numRows()>0) 
				{
					foreach($subCat as $row)
					{
						list($idd, $nombre, $referencia, $permiso) = $row;
						if($permiso=="publico")
						{
									$permiso="Public";
						}else
						{
							if($permiso==$id_usuario)
							{
										$permiso="Private";
							}else
							{
										$permiso="Private";
							}
						}
						$cant = $this->getNumeroProductos($nivel+1, $idsc);
						if($admin==1)
						{ 
							$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
						}else
						{
							if($permiso=="Privado")
							{
										$script.='t.AddLine(\'<IMG src="img/docu.gif"><a class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'\');';
							}else
							{ 
									$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\' \',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
							}
						}
						$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
						$j++;
					}
					
				} else 
				{
					$out=trim($this->getMensaje("[276]","confirmacion"));
					$script .= "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";
				}
				
				
			}
			
			
			return $script;
			
	} /* fin metodo listarCategoria */

	function listarSubProductosCatalogo($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin=1, $find='')
	{
			$limite = $this->limite; /* numero de registros a mostrar */
			$inicio = $this->inicioPagina($nun_pag);
			if($id)
			{
				$sql = "SELECT id, nombre, referencia, permiso FROM catalogo_producto WHERE parent = '$id' order by referencia asc LIMIT $inicio,$limite";
			}
			if($find)
			{
				$sql = "select id, nombre, permiso FROM catalogo_producto WHERE (nombre like '%$find%') or (descripcion like '%$find%') and parent = '$id' order by referencia asc LIMIT $inicio,$limite";
			}

			$script = 	'<script>';
			
			$i=1;
			$j=0;
			$subCat = array();
			$subCat = $this->consultarCampos($sql, "listarCategoria($nivel)");

			if ($subCat && $this->numRows()>0) 
			{
				$script .= 	'var t = new SortTable("t");
						t.AddColumn("titulo","nowrap","left","");
						t.AddColumn("referencia","center","left","")
			 			t.AddColumn("permiso","","center","");
						t.AddColumn("Numero","","center","");
						t.AddColumn("Seleccion","","center","");';
				foreach($subCat as $row)
				{	//print_r($row); echo "<br>";
					list($idd, $nombre, $referencia, $permiso) = $row;
					//echo "($idd, $nombre, $referencia, $permiso)<br>";
					if($permiso=="publico")
					{
								$permiso="Public";
					}else
					{
						if($permiso==$id_usuario)
						{
									$permiso="Private";
						}else
						{
									$permiso="Private";
						}
					}
					$cant = $this->getNumeroProductos($nivel+1, $idsc);
					if($admin==1)
					{ 
						$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
					}else
					{
						if($permiso=="Private")
						{
									$script.='t.AddLine(\'<IMG src="img/docu.gif"><a class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'\');';
						}else
						{ 
								$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\' \',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
						}
					}
					$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
					$j++;
				}
				$script .= "t.WriteRows();";					
			} else 
			{
				$out=trim($this->getMensaje("[274]","confirmacion"));
				$script .= "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";
			}
			
			$script .=	'</script>';
			echo $script;
			
	} 





	function listarCategoria2($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin=1, $find='')
	{
			$limite = $this->limite; /* numero de registros a mostrar */
			$inicio = $this->inicioPagina($nun_pag);
			if($nivel==1)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre asc LIMIT $inicio,$limite";
			}elseif($nivel==2)
			{
				 $sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre asc LIMIT $inicio,$limite";
			}elseif($nivel==3)
			{
				 $sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre asc LIMIT $inicio,$limite";
			}else
			{
				/* nivel 0, listar catalogo */
				 $sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL order by nombre asc LIMIT $inicio,$limite";
				
			}
			if($find)
			{
					    $sql = "id, nombre, permiso FROM catalogo_categoria WHERE (nombre like '%$find%') or (descripcion like '%$find%') order by nombre asc LIMIT $inicio,$limite";
			}
			
			if($this->execute($sql))
			{
				$script = 	'var t = new SortTable("t");
							t.AddColumn("titulo","nowrap","left","");';
				if($nivel > 0) $script.= 't.AddColumn("referencia","center","left","");';
	 
				$script.='	t.AddColumn("permiso","","center","");
						t.AddColumn("Numero","","center","");
						t.AddColumn("Seleccion","","center","");';				
				$i=1;
				$j=0;
				$subCat = array();
				$subCat = $this->consultarCampos($sql, "listarCategoria($nivel)");

				if ($subCat && $this->numRows()>0) 
				{
					foreach($subCat as $row)
					{
						list($idsc, $nombre, $permiso) = $row;
						if($permiso=="publico")
						{
									$permiso="Public";
						}else
						{
							if($permiso==$id_usuario)
							{
										$permiso="Propietario";
							}else
							{
										$permiso="Private";
							}
						}
						$cant = $this->getNumeroProductos($nivel+1, $idsc);
						if($admin==1)
						{ 
		
							$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
							if($nivel>0)$script .= '\'&nbsp;\',';
							$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
		
						}else
						{
							if($permiso=="Privado")
							{
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif">&nbsp;<A class="texto1"> '.$nombre.' </A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'\');';
							}else
							{ 
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
							}
						}
						$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
						$j++;
					}
					if($j < $limite)
					{
						$script .= $this->listarProductosCatalogo($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin, $find);
					}
					$script .= "t.WriteRows();";
				} else 
				{
					//$out=trim($this->getMensaje("[276]","confirmacion"));
					//$script .= "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";
					$script .= $this->listarProductosCatalogo($id, $nivel, 1, $permiso, $id_usuario, $admin, $find);
					$script .= "t.WriteRows();";
				}
				
				
			}else
			{
				$out=trim($this->getMensaje("[067]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				echo "<TR><TD colspan=\"4\" align=\"center\"><BR>$out<BR>&nbsp;</TD></TR>";
				$this->setSalida(false,$out,"listarCategoria2($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin, $find)",$this->nombre);
				
			}

			
			$sql1 = "SELECT count(*) FROM catalogo_categoria WHERE parent = '$id'";
			$sql2 = "SELECT count(*) FROM catalogo_producto WHERE categoria = '$id' and tipo='p'";
			$tp = $this->getNumeroProductos($nivel, $id);

			$tc = $this->consultarCampo($sql1, "listarCategoria2($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin, $find)");
			$tpc = $this->consultarCampo($sql2, "listarCategoria2($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin, $find)");

			$array = array();
			$array[] = $tp;
			$array[] = $tp+$tc; // numero total de productos
			$array[] = $tc; // numero total de categorias
			$array[] = $tpc; // numero total de productos en esta categoria
			$array[] = $script;
			return $array;
			
	}




		
		function listarCategoria($id, $nivel, $nun_pag, $permiso, $id_usuario, $admin=1)
		{
			$sql = "";
			$totalProductos = 0;
			if($nivel==1)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre ";
			}elseif($nivel==2)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre ";
			}elseif($nivel==3)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = '$id' order by nombre";
			}else
			{
				/* nivel 0, listar catalogo */
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL order by nombre ";
				
			}

			$script = 	'var t = new SortTable("t");
						t.AddColumn("titulo","nowrap","left","");';
			if($nivel > 0) $script.= 't.AddColumn("referencia","center","left","");';
	 
			$script.='	t.AddColumn("permiso","","center","");
						t.AddColumn("Numero","","center","");
						t.AddColumn("Seleccion","","center","");';
			$limite = $this->limite; /* numero de registros a mostrar */
			$ini = $this->inicioPagina($nun_pag);
			$write=0; 

			$subCat = array();
			$subCat = $this->consultarCampos($sql, "listarCategoria($nivel)");
			$cant = 0;
			$valdoc = 0;	
			$j=0;		
			$sub = count($subCat);
			$aux = $sub;
			$i = 1;
	
			if($subCat && $sub>0)
			{
				/*
					Primero mostramos las subcategorias.
				*/
				foreach($subCat as $subc)
				{
					if($j<$limite)
					{
						list($idsc, $nombre, $permiso) = $subc;
		
						/*
							Este if se usa solo para mostrar los registros correspondientes
							al numero de pagina dado por la entrada $nun_pag
						*/
						if($write>=$ini)
						{
						  if($i == 1)
						  {
							$i++;
							if($permiso=="publico"){
									$permiso="Public";
							}
							else
							{
								if($permiso==$id_usuario)
								{
										$permiso="Private";
								}
								else
								{
										$permiso="Private";
								}
							}
							/* Se cuentan el numero de productos que contiene esta subcategoria */
							$cant = $this->getNumeroProductos($nivel+1, $idsc);
							$valdoc += $cant;
							if($admin==1)
							{ 
		
								$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
								if($nivel>0)$script .= '\'&nbsp;\',';
								$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
		
							}else
							{
								if($permiso=="Privado")
								{
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif">&nbsp;<A class="texto1"> '.$nombre.' </A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'\');';
								}else
								{ 
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
								}
							}
							$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
						  } /*  fin if($i==1) */
						else
						{
							if($permiso=="publico")
							{
									$permiso="Public";
							}
							else
							{
								if($permiso==$id_usuario)
								{
										$permiso="Private";
								}
								else
								{
										$permiso="Private";
								}
							}
		
							$cant = $this->getNumeroProductos($nivel+1, $idsc);
							$valdoc += $cant;
		
							if($admin==1)
							{ 
		
								$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
								if($nivel>0)$script .= '\'&nbsp;\',';
								$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
		
							}else
							{
								if($permiso=="Privado")
								{
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif">&nbsp;<A class="texto1"> '.$nombre.' </A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'\');';
								}else
								{ 
									$script .= 't.AddLine(\'<IMG src="./img/folder.gif" onClick="fncListarDocus('.$idsc.')">&nbsp;<A class="texto1" onClick="fncListarDocus('.$idsc.')"> '.$nombre .'</A>\',';
									if($nivel>0)$script .= '\'&nbsp;\',';
									$script .='\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$cant.'</div>\',\'<INPUT class="radio" name="docu" type="radio" value="c'.$idsc.'">\');';
								}
							}
							$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
							
						} /* $i != 1 */
						$j++;
						} /* fin if($write>=$ini) */
						$write++;
					} /* fin if($j<$limite) */
				} /* fin foreach($subCat as $sub) */
	
			} /* fin  if(count($subCat)>0) */

			$aux1 = $aux - $write;
			$totalProductos = $valdoc;
			$doc = 0;
			if($nivel > 0)
			{
				$sql = "SELECT id, nombre, referencia, permiso FROM catalogo_producto WHERE categoria = '$id'  and tipo='p' order by referencia ";
				$prods = $this->consultarCampos($sql, "listarCategoria(nivel))");
				$doc = count($prods);		
				$totalProductos += $doc;
				
				if ($prods && $doc>0 && $aux1==0) 
				{
					//while ((list($idd, $nombre, $referencia, $permiso) = $db->fetchRow()) && ($j<$limite)) {
					foreach($prods as $prod)
					{
						list($idd, $nombre, $referencia, $permiso) = $prod;
						if($j<$limite)
						{
						if($write>=$ini)
						{
							if($i==1){ 
								$i++;
								
								if($permiso=="publico"){
										$permiso="Public";
								}
								else{
									if($permiso==$id_usuario){
											$permiso="Private";
									}
									else{
											$permiso="Private";
									}
								}		
								if($admin==1){ 
									$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
								 }else{
									if($permiso=="Privado"){
										$script.='t.AddLine(\'<IMG src="img/docu.gif"><a class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'\');';
									}else{ 
										$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\' \',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
									}
								}
								$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'" \');';
													
							}else{
							
								if($permiso=="publico"){
										$permiso="Public";
								}
								else{
									if($permiso==$id_usuario){
											$permiso="Private";
									}
									else{
											$permiso="Private";
									}
								}
								if($admin==1){ 
									$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
								 }else{
									if($permiso=="Privado"){
										$script.='t.AddLine(\'<IMG src="img/docu.gif"><a class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\'\',\'\');';
									}else{ 
										$script.='t.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$idd.')"><a onClick="fncModificarPro('.$idd.')" class="texto1">&nbsp;&nbsp;'.$nombre.'</a>\',\'<center>'.$referencia.'</center>\',\'<center>'.$permiso.'</center>\',\' \',\'<INPUT class="radio" name="docu" type="radio" value="'.$idd.'">\');';
									}
								}
								$script.='t.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'. $j .'"\');';
		
							}
							$j++;
						} /* fin if($write>=$ini) */
						$write++;
						} /* fin $j<$limite */
						
					} /* fin foreach */
				 } /* if ($doc>0 && $aux1==0) */
			} /* fin if nivel > 0 */
			else
			{
				$doc = $totalProductos;
			}
			if($sub == 0 && $doc == 0)
			{
				$out=trim($this->getMensaje("[274]","confirmacion"));
				$script.= "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";

			}
			$script.='t.WriteRows();';
			$array = array();
			$array[] = $totalProductos;
			$array[] = $doc; // numero total de productos
			$array[] = $sub; // numero total de categorias
			$array[] = $valdoc;
			$array[] = $script;
			return $array;
	} /* fin metodo listarCategoria */

	
	function listarCatalogoWeb($nivel, $id_cat, $id_cats1, $id_cats2, $inicio,$limite,$class, $num_cols, $whit_produsc, $img_v, $pag_des, $img_p, $id_prod='', $find='', $tipo_cat='')
	{
		$id_cat_final = $id_cat; 
		if($id_cats1 || $id_cats2 || $id_prod || !$find)
		{
			if($nivel == 0)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL order by nombre  limit $inicio, $limite";
			}
			if($nivel == 1)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent ='$id_cat' order by nombre  limit $inicio, $limite";
			}
			if($nivel == 2)
			{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent ='$id_cats1' order by nombre  limit $inicio, $limite";
				$id_cat_final = $id_cats1;
			}
			if($nivel == 3)
			{
				$id_cat_final = $id_cats2;
				//$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent ='$id_cats2' order by nombre  limit $inicio, $limite";
			}

			if($whit_produsc == 1)
			{
				$sql="SELECT id, nombre FROM catalogo_producto WHERE categoria='$id_cat_final' and tipo='p'";
	
			}
		
		}else
		{
			if($find)
			{
				
				if($tipo_cat)
				{
					if($tipo_cat == 2)
					{
						if($whit_produsc == 0)
						{
							$sql_int = " (id=".$tipo_cat." or parent=".$tipo_cat.") and ";
						}else
						{
							$sql_int = " (categoria=".$tipo_cat." ) and ";
						}
					}else
					{
						if($whit_produsc == 0)
						{
							$sql_int = " (id=".$tipo_cat." or parent=".$tipo_cat.") and ";
						}else
						{
							$sql_int = " (categoria <> 2 ) and ";
						}
					}
				}
				if($whit_produsc == 0)
				{
				$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE ".$sql_int." (nombre like '%$find%' or descripcion like '%$find%') order by nombre  limit $inicio, $limite";
				}else
				{
				$sql="SELECT id, nombre FROM catalogo_producto WHERE ".$sql_int." (nombre like '%$find%' or descripcion like '%$find%') and tipo='p' order by nombre  limit $inicio, $limite";
				}
			}
		}
		if($find){
		$pag_des .= "?buscar=".$find."&";
		$num_cols = 1;
		}
		else $pag_des .= "?";
		//echo $sql;
		$table = "<table ".$class['class_table'].">";

		$title = "Categorias";
		if($whit_produsc == 1)
		{
			$title = "Items";
		}
		if($find)$table .= "<tr><th>".$title."</th></tr>";
		if($this->execute($sql))
		{
			$nun_cats = $this->numRows();
			$mod = $nun_cats % $num_cols;
			if($mod > 0)($nun_cats + $mod);
			$rows = ($nun_cats / $num_cols);
			
			
			for($i=0; $i < $rows; $i++)
			{
				$table .= "<tr>";
				for($j=0; $j < $num_cols; $j++)
				{
					if($whit_produsc == 0)
					{
						$cat = $this->fetchRow();
						if($cat)
						{
							if($nivel == 0)
							{
			
							$table .= "<td>".$img_v."</td><td><a ".$class['class_link']." href=\"".$pag_des."nivel=".($nivel+1)."&id_cat=".$cat[0]."\" >".$cat[1]."</a></td>";
							}
							if($nivel == 1)
							{
							$table .= "<td>".$img_v."</td><td><a ".$class['class_link']."href=\"".$pag_des."nivel=".($nivel + 1)."&id_cat=$id_cat&id_cats1=".$cat[0]."\" >".$cat[1]."</a></td>";
							}
							if($nivel == 2)
							{
							$table .= "<td>".$img_v."</td><td><a ".$class['class_link']."href=\"".$pag_des."nivel=".($nivel + 1)."&id_cat=$id_cat&id_cats1=$id_cats1&id_cats2=".$cat[0]."\" >".$cat[1]."</a></td>";
							}
						}
					}else
					{
						$prod = $this->fetchRow();
						/*if($nivel == 0)
						{
		
						$table .= "<td>".$img_v."</td><td><a href=\"".$pag_des."?nivel=".($nivel+1)."&id_cat=".$cat[0]."\" >".$cat[1]."</a></td>";
						}*/
						if($prod)
						{
							if($nivel == 1)
							{
							$table .= "<td>".$img_p."</td><td><a ".$class['class_link']." href=\"".$pag_des."nivel=".($nivel + 1)."&id_cat=$id_cat&id_cats1=$id_cats1&id_pro=".$prod[0]."\" >".$prod[1]."</a></td>";
							}
							if($nivel == 2)
							{
							$table .= "<td>".$img_p."</td><td><a ".$class['class_link']." href=\"".$pag_des."nivel=".($nivel + 1)."&id_cat=$id_cat&id_cats1=$id_cats1&id_cats2=$id_cats2&id_pro=".$prod[0]."\" >".$prod[1]."</a></td>";
							}
							if($nivel == 3)
							{
							$table .= "<td>".$img_p."</td><td><a ".$class['class_link']." href=\"".$pag_des."nivel=".($nivel + 1)."&id_cat=$id_cat&id_cats1=$id_cats1&id_cats2=$id_cats2&id_pro=".$prod[0]."\" >".$prod[1]."</a></td>";
							}
						}
					}
				}
				$table .= "</tr>";
			}
			if($nun_cats == 0)
			{
				$out=trim($this->getMensaje("[276]","confirmacion"));
				$out.=trim($this->getException());
				$table .="<tr><td>".$out."</td></tr>";
			}
				
		} else 
		{

		}
		$table .= "</table>";
		echo $table;
	
		if($find)
		{
			if($whit_produsc == 0)
			{
				$this->listarCatalogoWeb($nivel, $id_cat, $id_cats1, $id_cats2, $inicio,$limite,$class, $num_cols, 1, $img_v, $pag_des, $img_p, $id_prod, $find, $tipo_cat);
			}
		}
				
	}

	function numItemsCatalogoWeb($nivel, $id_cat, $id_cats1, $id_cats2, $whit_produsc, $find='')
	{
		$id_cat_final = $id_cat;
		if($nivel == 0)
		{
			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL";
		}
		if($nivel == 1)
		{
			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent ='$id_cat'";
		}
		if($nivel == 2)
		{
			$id_cat_final = $id_cats1;
			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent ='$id_cats1'";
		}
		if($nivel == 3)
		{
			$id_cat_final = $id_cats2;
		}
		if($whit_produsc == 1)
		{
			$sql="SELECT id, nombre FROM catalogo_producto WHERE categoria='$id_cat_final' and tipo='p'";

		}
		if($find)
		{

			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE (nombre like '%$find%' or descripcion like '%$find%') order by nombre";
			$sql1="SELECT id, nombre FROM catalogo_producto WHERE (nombre like '%$find%' or descripcion like '%$find%') and tipo='p' order by nombre";
			if($this->execute($sql))
			{
				$nun_cats = $this->numRows();
				if($this->execute($sql1))
				{
					$nun_cats1 = $this->numRows();
					return 	$nun_cats+$nun_cats1;				
						
				} else 
				{
					return $nun_cats;
				}
					
			} else 
			{
				return 0;
			}

		}
		if($this->execute($sql))
		{
			$nun_cats = $this->numRows();
			return $nun_cats;
				
		} else 
		{
			return 0;
		}
	}



	/* Esta funcion devuelve el numero de productos total registrado en una categoria
	 especifica, incluyendo los productos en las subcategorias respectivas.
	 Parametros:
		$nivel corresponde a los diferentes rangos en la jerarquia.
			1 nivel raiz, 2 nivel 2 ....

		$id_cat corresponde al identificador de la categoria en cuestion
	*/
	function getNumeroProductos($nivel, $id_cat, $est='', $find='')
	{
		$sql = "";
		$totalProductos = 0;
		if($nivel == 1)
		{
			$sql = "select id from catalogo_categoria where parent = '$id_cat'";
			$categs_nivel2 = $this->consultarCampos($sql, "getNumeroProductos(nivel, id_cat)");
			
			// si tiene subcategorias entonces cuenta los productos contenidos en estas
			if($categs_nivel2 && count($categs_nivel2) >  0)
			{
				foreach($categs_nivel2 as $cats)
				{
					$ids = $cats['id'];

					// buscamos subcategorias del ultimo nivel.
					$sql = "select id from catalogo_categoria where parent = '$ids'";
					$categs_nivel3 = $this->consultarCampos($sql, "getNumeroProductos(nivel, id_cat)");

					if($categs_nivel3 && count($categs_nivel3) > 0)
					{
						/*
							En este bucle se cuentan los productos contenidos
							en las ultimas subcategorias, las de nivel 3
						*/
						foreach($categs_nivel3 as $catss)
						{
							$idss = $catss['id'];
							
							$sql = "select count(*) FROM catalogo_producto where categoria = '$idss' and tipo='p'";
							$totalSubss = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
							$totalProductos+=$totalSubss;
						}
					} /* fin categorias de nivel 3 */
					/*
						Se adicionan los productos que pertenecen especificamente a esta
						categoria, es decir, que no se tienen en cuenta los que pertencen
						a las subcategorias.
					*/
					$sql = "select count(*) FROM catalogo_producto where categoria = '$ids'  and tipo='p'";
					$totalSubs = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
					$totalProductos+=$totalSubs;
					
				} /* fin foreach nivel 2 */
			} /* fin categorias de nivel 2 */
			
			/*
				Se adicionan los productos que pertenecen especificamente a la
				categoria raiz.
			*/
			$sql = "select count(*) FROM catalogo_producto where categoria = '$id_cat' and tipo='p'";
			$totalSubc = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
			$totalProductos+=$totalSubc;
			return $totalProductos;
			
		} /* fin if nivel 1 */
		elseif($nivel == 2)
		{
			$sql = "select id from catalogo_categoria where parent = '$id_cat'";
			$categs_nivel3 = $this->consultarCampos($sql, "getNumeroProductos(nivel, id_cat)");
			
			// si tiene subcategorias entonces cuenta los productos contenidos en estas
			if($categs_nivel3 && count($categs_nivel3) >  0)
			{
				foreach($categs_nivel3 as $catss)
				{
					$idss = $catss['id'];					
					$sql = "select count(*) FROM catalogo_producto where categoria = '$idss'  and tipo='p'";
					$totalSubss = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
					$totalProductos+=$totalSubss;
					
				} /* fin foreach de nivel 3 */
			} /* fin count nivel 3 */
			/*
				Se adicionan los productos que pertenecen especificamente a esta
				categoria, es decir, que no se tienen en cuenta los que pertencen
				a las subcategorias.
			*/
			$sql = "select count(*) FROM catalogo_producto where categoria = '$id_cat'  and tipo='p'";
			$totalSubs = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
			$totalProductos+=$totalSubs;
			return $totalProductos;

		} /* fin nivel 2 */
		elseif($nivel == 3)
		{
			$sql = "select count(*) FROM catalogo_producto where categoria = '$id_cat'  and tipo='p'";
			$totalSubss = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
			$totalProductos+=$totalSubss;
			return $totalProductos;
		} /*  fin nivel 3 */
		if($find)
		{
			$sql = "SELECT count(*) FROM catalogo_producto
					where ((nombre like '%$find%') or (referencia like '%$find%') or (id like '%$find%'))  and tipo='p' order by nombre asc";
			$totalProductos = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
			return $totalProductos;
		}
		if($est)
		{
			if($est=='todos')
				$sql = "select count(*) FROM catalogo_producto where tipo='p'";
			else
				$sql = "select count(*) FROM catalogo_producto where estado = '$est' and tipo='p'";

			$totalProductos = $this->consultarCampo($sql, "getNumeroProductos(nivel, id_cat)");
			return $totalProductos;
		}
	
		// nose produjeron resultados
	} /* fin metodo getNumeroProductos($nivel, $id_cat) */


		/**
		* Elimina un vinculo de un usuario con la aplicacion carrito de compras.
		*
		* @param string $vinc cadena compuesta por el id del vinculo a modificar y el email del usuario correspondiente separados por "|". ej: 12|[email protected]
		* @return boolean retorna falso si algun error ocurre
		* @access public
		*/
		function delSubscripcion($vinc)
		{
			$vec=explode("|",$vinc);
			$id = $vec[0];
			//$sql="delete from vinculo_web where usuario_web='$id' and aplicacion = '$this->id'";
			$sql="update vinculo_web set estado='eliminado' where usuario_web ='$id' and aplicacion = '$this->id'";
			if($this->execute($sql))
			{
					$out=$this->getMensaje("[098]","confirmacion")." ".$vec[1];
					$this->setSalida(true,$out,"delSubscripcion($vinc)",$this->id);
					return true;
			}else
			{
					$out=trim($this->getMensaje("[027]","error")." ".$vec[1]);
					$out.="\\n:Desc: ".trim($this->getException());
					$this->setSalida(false,$out,"delSubscripcion($vinc)",$this->id);
					return false;
			}

		}

		/*
		*funcion listarUsuarios
		*descripcion trae todos los usuarios disponibles
		*			 apli: id de la aplicacion relacionada con los usuarios a listar
		*			 est: estado de los usuarios que se quieren listar
		*/
		function listarUsuarios($apli = false,$inicio,$limite,$class,$nApli,$est, $find='')
		{
		
			if($est=="todos")
			{
					$sql="select  user.id, user.nombres, user.apellidos, user.login, user.email, vinc.estado from usuario_web as user, vinculo_web as vinc where vinc.estado <> 'eliminado' and vinc.usuario_web=user.id and vinc.aplicacion='$apli' order by user.nombres limit $inicio, $limite";
			}else
			{
					$sql="select  user.id, user.nombres, user.apellidos, user.login, user.email, vinc.estado from usuario_web as user, vinculo_web as vinc where vinc.estado <> 'eliminado' and vinc.usuario_web=user.id and vinc.aplicacion='$apli' and vinc.estado='$est' order by user.nombres limit $inicio, $limite";
			}
			if($find)
			{
					    $sql = "select user.id, user.nombres, user.apellidos, user.login, user.email, vinc.estado
						from usuario_web as user, vinculo_web as vinc
					    where vinc.estado <> 'eliminado' and user.id = vinc.usuario_web and vinc.aplicacion='$this->id' and ((user.nombres like '%$find%') or (user.email like '%$find%') or (user.apellidos like '%$find%')) order by user.nombres asc LIMIT $inicio,$limite";
			}
			
			if($this->execute($sql))
			{
				echo '<script>var t = new SortTable("t");t.AddColumn("ico","width=\"20\"","center","");t.AddColumn("Nombre","nowrap","","");t.AddColumn("Login","nowrap","",""); t.AddColumn("tipo","","center",""); t.AddColumn("Seleccion","","center","");';
				$i=1;
				$j=0;
				if ($this->numRows()>0) 
				{
					while(list($id,$nombre,$apellido,$login,$email,$estado)=$this->fetchRow())
					{
						if($estado!='eliminado')
						{
							if($estado=="bloqueado")
							{
								$imagen="<img src=\"img/newslBloqueado.gif\" onClick=\"fncConsultarUsr(\'$id\')\" height=\"15\" width=\"15\">";
							}
							if($estado=="activo")
							{
								$imagen="<img src=\"img/vinculotema.gif\" onClick=\"fncConsultarUsr(\'$id\')\">";
							}
							if($estado=="preactivo")
							{
								$imagen="<img src=\"img/newslPreactivo.gif\" onClick=\"fncConsultarUsr(\'$id\')\">";
							}
							
							$nombre=ucfirst(strtolower($nombre))." ".ucfirst(strtolower($apellido));
							if(strlen($nombre)>31)
							{
								$nombre=substr($nombre,0,30)."...";
							}
							echo "t.AddLine('$imagen','<!--$nombre--><a class=\"arial12\" onClick=\"fncConsultarUsr(\'$id\')\">$nombre </a>', '<!--$email--><a class=\"arial12\" onClick=\"fncConsultarUsr(\'$id\')\">$email</a>','$login', '<INPUT class=\"radio\" name=\"usuario_$j\" type=\"checkbox\" value=\"$id|$email\">');";
							echo "t.AddLineProperties('id=\"tr_$j\" class=\"$class\" align=\"left\" onMouseOver=\"mOvr(this,\'#faff95\',\'tr_$j\');\" onMouseOut=\"mOut(this,\'#FFFFFF\',\'tr_$j\')\"');"; 
			
							$j++;
						}
					}
					echo "t.WriteRows();";
				} else 
				{
					$out=trim($this->getMensaje("[023]","confirmacion"));
					echo "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";
				}
				echo "</script>";
				return true;
			}else
			{
				$out=trim($this->getMensaje("[026]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				echo "<TR><TD colspan=\"4\" align=\"center\"><BR>$out<BR>&nbsp;</TD></TR>";
				$this->setSalida(false,$out,"listarUsuarios($apli = false,$inicio,$limite,$class,$nApli,$est, $find)",$this->nombre);
				return false;
			}
			
		}
		/*
		funcion cantidadUsuarios
		descripcion devuelve el nuemro de usuarios en esta aplicacion
		*/
		function cantidadUsuarios($nApli, $est, $find='')
		{
			$sql = '';

			if($est=="todos")
			{
					$sql="select  user.id from usuario_web as user, vinculo_web as vinc where  vinc.estado <> 'eliminado' and vinc.usuario_web=user.id and vinc.aplicacion='$this->id' ";
			}else
			{
					$sql="select  user.id from usuario_web as user, vinculo_web as vinc where  vinc.estado <> 'eliminado' and vinc.usuario_web=user.id and vinc.aplicacion='$this->id' and vinc.estado='$est'";
			}
			if($find)
			{
					    $sql = "select user.id, vinc.estado
						from usuario_web as user, vinculo_web as vinc
					    where  vinc.estado <> 'eliminado' and  user.id = vinc.usuario_web and vinc.aplicacion='$this->id' and ((user.nombres like '%$find%') or (user.email like '%$find%') or (user.apellidos like '%$find%'))";
			}
			
			if($this->execute($sql))
			{
				$out=trim($this->getMensaje("[025]","confirmacion"));
				$this->setSalida(true,$out,"cantidadUsuarios($nApli)",$this->nombre);	
				return $this->numRows();
			}else
			{
				$out=trim($this->getMensaje("[026]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"cantidadUsuarios($nApli)",$this->nombre);
				return false;
			}
		}


		
		/*
		*funcion modVinculoWeb()
		*descripcion modifica un vinculo de un usuario con la aplicacion newsletter
		*/
		function modVinculoWeb($vinc,$est,$nApli)
		{
			$vec=explode("|",$vinc);
			$id = $vec[0];
			$sql="update vinculo_web set estado='$est' where usuario_web ='$id' and aplicacion = '$this->id'";
			if($this->execute($sql))
			{
				if($est=="activo"){$nms="[094]";}
				if($est=="bloqueado"){$nms="[100]";}
				$out=$this->getMensaje($nms,"confirmacion")." ".$vec[1];
				$this->setSalida(true,$out,"modVinculoWeb($vinc,$est,$nApli)",$nApli);
				return true;
			}else
			{
				$out=trim($this->getMensaje("[027]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"modVinculoWeb($vinc,$est,$nApli)",$nApli);
				return false;
			}
		}

		function getEstadoUsuario($id)
		{
			$sql="select vw.estado from vinculo_web as vw where vw.aplicacion = '$this->id' and vw.usuario_web = '$id'";
			if($this->execute($sql))
			{
				$out=trim($this->getMensaje("[044]","confirmacion"));
				$this->setSalida(true,$out,"getEstadoUsuario($id)",$this->nombre);	
				list($est) = $this->fetchRow();
				
				return $est;
			}else
			{
				$out=trim($this->getMensaje("[027]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"getEstadoUsuario($id)",$this->nombre);
				return false;
			}
		}

		function accionPermitida($id_user_panel, $acc='adicionar')
		{
			
			$sql = "SELECT id FROM panel_vinculo WHERE usuario_panel='$id_user_panel' AND aplicacion='$this->id' AND $acc='SI'";
			if($this->execute($sql))
			{
				$out=$this->getMensaje("[021]","confirmacion");
				$this->setSalida(true,$out,"accionPermitida($id_user_panel, $acc)",$this->id);
				if($this->numRows() > 0)
					return true;
				else
					return false;
			}else
			{
				$out=trim($this->getMensaje("[009]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"accionPermitida($id_user_panel, $acc)",$this->id);
				return false;
			}
		}

		function usuarioEsAdministrador($id_user_panel)
		{
			
			$sql = "SELECT tipo FROM panel_usuario WHERE id='$id_user_panel'";
			if($this->execute($sql))
			{
				$out=$this->getMensaje("[021]","confirmacion");
				$this->setSalida(true,$out,"usuarioEsAdministrador($id_user_panel)",$this->id);
				if($this->numRows() > 0)
				{
					list($t)=$this->fetchRow();
					if($t == 1 || $t == 2)	return true;
					else return false;
				}			
				else
					return false;
			}else
			{
				$out=trim($this->getMensaje("[009]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"usuarioEsAdministrador($id_user_panel)",$this->id);
				return false;
			}
		}
		
		/*
			Lista los productos en el panel
		*/
		function listarProductos($inicio,$limite,$class, $est, $find='', $id_user_panel, $tipo_user)
		{
			$admin = 0;
			/*
				$tipo_user == 1 --> azul, $tipo_user == 2 --> administrador, $tipo_user == 3 --> dedicado a aplicacion
			*/
			if($tipo_user == 1 || $tipo_user == 2)
			{
				$admin = 1;
			}
			
			if($panel->usuario->tipo==3)
			{

				if($this->usuarioEsAdministrador($id_user_panel))
					$admin = 1;
			}   	
		
			$sql = '';
			if($est=="todos")
			{
				$sql = "SELECT id, nombre,referencia,permiso,estado FROM catalogo_producto WHERE  tipo='p' order by nombre limit $inicio,$limite";
			}else
			{
				$sql = "SELECT id, nombre,referencia,permiso,estado FROM catalogo_producto WHERE estado='$est' and tipo='p' order by nombre limit $inicio,$limite";
			}
			
			if($find)
			{
					    $sql = "SELECT id, nombre,referencia,permiso,estado FROM catalogo_producto
					    where ((nombre like '%$find%') or (referencia like '%$find%') or (id like '%$find%'))  and tipo='p' order by nombre asc LIMIT $inicio,$limite";
			}
			
			if($this->execute($sql))
			{
				echo '<script>var t = new SortTable("t");
					t.AddColumn("titulo","width=\"20\"","left","");
					t.AddColumn("referencia","nowrap","","");
					t.AddColumn("permiso","nowrap","","");
					t.AddColumn("estado","","center",""); 
					t.AddColumn("Seleccion","","center","");';
				
				$i=1;
				$j=0;
				if ($this->numRows()>0) 
				{
					while(list($id,$nombre,$referencia,$permiso,$estado)=$this->fetchRow())
					{
						
						if ($estado=='disponible'){
							$estado = 'Available'; 
						}
						if ($estado=='nuevo'){
							$estado = 'New';
						}						
						if ($estado=='destacado'){
							$estado = 'Outstanding';
						}		
						if ($estado=='promocion'){
							$estado = 'Supply';
						}						
						if ($estado=='no_disponible'){
							$estado = 'NonAvailable';
						}		
						
						if($permiso=="publico"){
								$permiso="Public";
						}
						else{
							if($permiso==$id_usuario){
									$permiso="Private";
							}
							else{
									$permiso="Private";
							}
						}

						if($admin==1)
						{
							echo 't.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$id.')"> &nbsp;<A class="texto1" onClick="fncModificarPro('.$id.')"> '.$nombre.' </A>\',\'<div class="texto1">'.$referencia.'</div>\',\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$estado.'</div>\',\'<INPUT class="radio" name="sel" type="radio" value="c'.$id.'">\' );';            
						}else
						{
							if($permiso=="Privado")
							{
								echo 't.AddLine(\'<IMG src="img/docu.gif"> &nbsp;<A class="texto1"> '.$nombre.' </A>\',\'<div class="texto1">'.$referencia.'.</div>\',\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$estado.'</div>\',\'<INPUT class="radio" disabled name="sel" type="radio" value="c'.$id.'"> \' ); ';           
							}else
							{ 
								echo 't.AddLine(\'<IMG src="img/docu.gif" onClick="fncModificarPro('.$id.')"> &nbsp;<A class="texto1" onClick="fncModificarPro('.$id.')">  '.$nombre.' </A>\',\'<div class="texto1">'.$referencia.'</div>\',\'<div class="texto1">'.$permiso.'</div>\',\'<div class="texto1">'.$estado.'</div>\',\'<INPUT class="radio" name="sel" type="radio" value="c'.$id.'"> \' );';            
							}
						}
						echo 't.AddLineProperties(\'align="center" valign="bottom" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'.$j.'; "\');';	
						$j++;
					}
					echo "t.WriteRows();";
				} 
				else 
				{
					$out=trim($this->getMensaje("[274]","confirmacion"));
					//$out.="\\n:Desc: ".trim($this->getException());
					echo "document.write('<TR><TD colspan=\"4\" align=\"center\"><BR>$out<BR>&nbsp;</TD></TR>');";
				}
				echo "</script>";
				return true;
			}else
			{
				$out=trim($this->getMensaje("[039]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				echo "<TR><TD colspan=\"4\" align=\"center\"><BR>$out<BR>&nbsp;</TD></TR>";
				$this->setSalida(false,$out,"listarProductos($inicio,$limite,$class, $est, $find='', $id_user_panel, $tipo_user)",$this->nombre);
				return false;
			}
		}

		/*
			retorna la informacion de un producto en un array para mostrar en html.
		*/
		function getInfoProducto($id_prod)
		{
			
			$sql="SELECT id, categoria,referencia,nombre,descripcion,valor,permiso,estado,estado_oferta,valor_oferta,fecha_fin,tipo,parent FROM catalogo_producto WHERE id='$id_prod'";
			if($this->execute($sql))
			{
				list($id_p, $categoria,$referencia,$nombre,$descripcion,$valor,$permiso,$estado,$estado_oferta,$valor_oferta,$fecha_fin,$tipo,$parent)=$this->fetchRow();
				if (empty($parent)){
					$parent=0;
				}
				$prod = array();
				$prod['id'] = $id_p;
				$prod['categoria'] = $categoria;
				$prod['referencia'] = $referencia;
				$prod['tipo'] = $tipo;				
				$prod['parent'] = $parent;
				$prod['nombre'] = $nombre;
				$prod['descripcion'] = $this->utileria->parseDB2Html($descripcion);
				$prod['valor'] = $valor;
				$prod['permiso'] = $permiso;
				$prod['estado'] = $estado;
				$prod['estado_oferta'] = $estado_oferta;
				$prod['valor_oferta'] = $valor_oferta;
				$prod['fecha_fin'] = $fecha_fin;
				return $prod;
			}else
			{
				$out=trim($this->getMensaje("[255]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"registrarPedido($cliente_info, $prods)",$this->nombre);
				return false;
			}
		}


		/*
			retorna el nombre de las imagenes principales relacionadas con el producto identificado por
			$id_pro
		*/
		function getImagenes2($id_pro, $links='', $w='', $h='', $pag=1, $limit=4, $cat=true)
		{
			$ruta = '';
			if($cat==true)$ruta = 'aplicaciones/admon/catalogo/archivos/';
			$inicio = ($pag - 1)*$limit; 
			//$inicio++;
			$imagenes = array();
			$sql = "SELECT fichero FROM catalogo_imagen WHERE producto='$id_pro' AND tipo='principal' order by id limit $inicio,$limit";
			if($this->execute($sql))
			{	
				while(list($fichero)=$this->fetchRow())
				{
					$imagenes[]=$ruta.$fichero;
				}

				return $imagenes;
			}else
			{
				$out=trim($this->getMensaje("[256]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"getImagenes($id_pro)",$this->nombre);
				return false;			
			}
				
		}

		/*
			retorna el nombre de las imagenes principales relacionadas con el producto identificado por
			$id_pro
		*/
		function getImagenes($id_pro)
		{
			$imagenes = array();
			$sql = "SELECT fichero FROM catalogo_imagen WHERE producto='$id_pro' AND tipo='principal'";
			if($this->execute($sql))
			{	
				while(list($fichero)=$this->fetchRow())
				{
					$imagenes[]=$fichero;
				}
				return $imagenes;
			}else
			{
				$out=trim($this->getMensaje("[256]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"getImagenes($id_pro)",$this->nombre);
				return false;			
			}
				
		}

		function validar_fecha($fecha_fin){
			$mes_fin=substr(substr($fecha_fin,5),0,2);
			$dia_fin=substr(substr($fecha_fin,8),0,2);
			$anio_fin=substr($fecha_fin,0,4);
						
			$fecha_act = date('Y-m-d');
			$mes_act=substr(substr($fecha_act,5),0,2);
			$dia_act=substr(substr($fecha_act,8),0,2);
			$anio_act=substr($fecha_act,0,4);
					
			if($anio_fin>$anio_act){
				return true;
			}elseif($anio_fin<$anio_act){
				return false;
			}elseif($anio_fin=$anio_act){
				if($mes_fin>$mes_act){
					return true;
				}elseif($mes_fin<$mes_act){
					return false;
				}elseif($mes_fin=$mes_act){
					if($dia_fin>$dia_act){
						return true;
					}elseif($dia_fin<=$dia_act){
						return false;
					}
				}
			}
		}
/*
	function img_producto($id_pro){
		$src = './aplicaciones/admon/catalogo/archivos/';
		$parametros = new Parametros();
		$proporcion=$parametros->getAncho()/$parametros->getAlto();
		$anchoSec=140;
		$altoSec=$anchoSec/$proporcion;
	
		$index=0;
		$sql = "SELECT fichero FROM catalogo_imagen WHERE producto='$id_pro' AND tipo='principal'";
		if($this->execute($sql)){	
			while(list($fichero)=$this->fetchRow()){
				$imagenes[$index]=$src.$fichero;
				$index++;
			}
		}else{
			echo "<scrip>alert('�Impossible to consult the database!');</script>";
		}
		if($index > 1)
		{
			echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR><TD><form name="Oneslideform">';
			echo '<DIV align="center"><TABLE width="100%" border="1" cellspacing="0" cellpadding="4" bordercolor="#999999">';
			echo '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
			echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
			echo '</TD></TR><TR><TD ><DIV align="center"><SELECT class="listado" name="Oneslide" onChange="Onechange();">';
			for($i=0;$i<$index;$i++){
				if($i==0)
					echo '<OPTION value="'.$imagenes[$i].'"  selected>Imagen '.($i+1).'</OPTION>';
				else	
					echo '<OPTION value="'.$imagenes[$i].'">Imagen '.($i+1).'</OPTION>';
			}		
			echo '</SELECT></TD></TR><TR><TD><DIV align="center">';
			echo '<img src="aplicaciones/admon/catalogo/img/atras1.gif" title="Atras" onClick="Oneprevious();">&nbsp;&nbsp;&nbsp;&nbsp;';
			echo '<INPUT name="Oneslidebutton" type=button class="botones" title="AutoPlay" onClick="Oneap(this.value);" value="Play" style="vertical-align:top ">&nbsp;&nbsp;&nbsp;&nbsp;';
			echo '<img src="aplicaciones/admon/catalogo/img/adelante1.gif" title="Adelante" onClick="Onenext();">';
			echo '</DIV></TD></TR></TABLE></DIV></form></TD></TR></TABLE>';
		}else
		{
			if($index == 1)
			{
				echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR><TD><form name="Oneslideform">';
				echo '<DIV align="center"><TABLE width="100%" border="0" cellspacing="0" cellpadding="4" bordercolor="#999999">';
				echo '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
				echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
				echo '</TD></TR><TR><TD ><DIV align="center"></TD></TR><TR></TR></TABLE></DIV></form></TD></TR></TABLE>';
			}
		}
		if($index > 0)return true;
		return false;
	}*/

	/*
	
	*/





	function img_producto($id_pro){
		$src = './aplicaciones/admon/catalogo/archivos/';
		$parametros = new Parametros();
		$proporcion=$parametros->getAncho()/$parametros->getAlto();
		$anchoSec=170;
		$altoSec=$anchoSec/$proporcion;
		$links='';
		$index=0;
		$sql = "SELECT titulo, fichero FROM catalogo_imagen WHERE producto='$id_pro' AND tipo='principal'";
		if($this->execute($sql)){	
			while(list($tit, $fichero)=$this->fetchRow()){
				if(eregi("color", $tit) != 1)
				{
					$imagenes[$index]=$src.$fichero;
					$index++;
				}
			}
		}else{
			echo "<scrip>alert('�Impossible to consult the database!');</script>";
		}

		if($index)
		{
			echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" height="100%" class="contenido"><TR><TD><form name="Oneslideform">';
			echo '<DIV align="center"><TABLE width="100%" height="100%" border="0" cellspacing="0" cellpadding="4" bordercolor="#999999">';
			echo '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
			echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
			echo '</TD></TR><TR><TD ><DIV align="left" class="contenido"><SELECT class="listado" name="Oneslide" onChange="Onechange();" style ="visibility :hidden" size="1" width="10">';
				for($i=0;$i<$index;$i++){
					if($i==0)
						echo '<OPTION value="'.$imagenes[$i].'"  selected>Imagen '.($i+1).'</OPTION>';
					else
					{	
						echo '<OPTION value="'.$imagenes[$i].'">Imagen '.($i+1).'</OPTION>';
					}
					if($index > 1)$links .= '<label id="label_'.$i.'" onMouseOut="rollOutMenu2(\'label_'.$i.'\')" onMouseOver="Onechange2('.$i.', \'label_'.$i.'\');">'.($i+1).'&nbsp;</label>';
				}		
				echo '</SELECT>';
				echo $links.'</TD></TR><TR><TD><DIV align="center">';

			echo '</TD></TR></TABLE></DIV></form></TD></TR></TABLE>';
		}else
		{
			if($index == 1)
			{
				echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR><TD><form name="Oneslideform">';
				echo '<DIV align="center"><TABLE width="100%" border="0" cellspacing="0" cellpadding="4" bordercolor="#999999">';
				echo '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
				echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
				echo '</TD></TR><TR><TD ><DIV align="center"></TD></TR><TR></TR></TABLE></DIV></form></TD></TR></TABLE>';
			}
		}
		if($index > 0)return true;
		return false;
	}


	function prods_categoria_gmoda($id_cat, $gama, &$array, $num_pag=1, $limit=3)
	{
		$inicio = (($num_pag - 1) * $limit);
		$sql = "SELECT id, nombre FROM catalogo_producto WHERE categoria=$id_cat  and tipo='p' order by nombre limit $inicio, $limit";
		$prods = array();
		if($this->execute($sql)){	
			while($row=$this->fetchRow()){
					$prods[]=$row;
			}
			$array = array_merge($array, $prods);
		}else{
			/*echo "<scrip>alert('�Impossible to consult the database!');</script>";*/
				$out=trim($this->getMensaje("[016]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out," prods_categoria_gmoda($id_cat, $gama, $array, $num_pag, $limit)",$this->nombre);
				return false;	
		}

		$sql = "SELECT id FROM catalogo_categoria WHERE parent=$id_cat";
		$marcs = $this->consultarCampos($sql, "gmoda($id, $gama, $marcas)");

		if($marcs && count($marcs))
		{	
			foreach($marcs as $marc)
			{
				$this->prods_categoria_gmoda($marc['id'], $gama, $array);
			}
			
		}else{
			/*echo "<scrip>alert('�Impossible to consult the database!');</script>";*/
				$out=trim($this->getMensaje("[016]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out," prods_categoria_gmoda($id_cat, $gama, $array, $num_pag, $limit)",$this->nombre);
				return false;	
		}
		
	}

	function numero_prods_categoria_gmoda_calzado($id_cat, $gama)
	{
		$inicio = (($num_pag - 1) * $limit);
		$sql = "SELECT count(*) as nun FROM catalogo_producto WHERE categoria=$id_cat  and tipo='p' order by nombre";
		$prods = 0;
		if($this->execute($sql))
		{	
			$row = $this->fetchRow();
			$prods = $row['nun'];
		}else
		{
				$out=trim($this->getMensaje("[016]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"numero_prods_categoria_gmoda($id_cat, $gama)",$this->nombre);
				return 0;	
		}

		return $prods;
		
	}
	function img_producto_gmoda($id_cat, $gama, $pri='', $num_pag=1, $limit, $linea=false){
		$prods = array();

		
		$this->prods_categoria_gmoda($id_cat, $gama, $prods, $num_pag, $limit);

		//print_r($prods);

		$src = './aplicaciones/admon/catalogo/archivos/';
		$parametros = new Parametros();
		$proporcion=$parametros->getAncho()/$parametros->getAlto();
		$anchoSec=70;
		$altoSec=$anchoSec/$proporcion;
	
		$index=0;


		$img = 1;
		$table = '';
		$script = '<script>';// var prods = Array();';
		$script2 = '';
		$prod = '';
		$ps = 0;
		//$table = "<table aling=\"center\">";
		foreach($prods as $pr)
		{	//echo "<br>";
			$prod = '';
			$sql = "SELECT titulo, fichero FROM catalogo_imagen WHERE producto=".$pr['id']." AND tipo='principal'";
			if($this->execute($sql)){	
				$imagenes = '';
				$imagenes = array();
				while(list($tit, $fichero)=$this->fetchRow())
				{					
					if(eregi("color", $tit) != 1)
					{
						$imagenes[$index]=$src.$fichero;
						if(!$pri)$index++;
					}
				}
			}else{
				echo "<scrip>alert('�Impossible to consult the database!');</script>";
			}
			//$table .= "<tr aling=\"center\"><td aling=\"center\">";
			if($index > 1 && !$pri)
			{
				$table .= '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR><TD><form name="Oneslideform">';
				$table .= '<DIV align="center"><TABLE width="100%" border="1" cellspacing="0" cellpadding="4" bordercolor="#999999">';
				$table .= '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
				$table .= '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
				$table .= '</TD></TR><TR><TD ><DIV align="center"><SELECT class="listado" name="Oneslide" onChange="Onechange();">';
				for($i=0;$i<$index;$i++){
					if($i==0)
						$table .= '<OPTION value="'.$imagenes[$i].'"  selected>Imagen '.($i+1).'</OPTION>';
					else	
						$table .= '<OPTION value="'.$imagenes[$i].'">Imagen '.($i+1).'</OPTION>';
				}		
				$table .= '</SELECT></TD></TR><TR><TD><DIV align="center">';
				$table .= '<img src="aplicaciones/admon/catalogo/img/atras1.gif" title="Atras" onClick="Oneprevious();">&nbsp;&nbsp;&nbsp;&nbsp;';
				$table .= '<INPUT name="Oneslidebutton" type=button class="botones" title="AutoPlay" onClick="Oneap(this.value);" value="Play" style="vertical-align:top ">&nbsp;&nbsp;&nbsp;&nbsp;';
				$table .= '<img src="aplicaciones/admon/catalogo/img/adelante1.gif" title="Adelante" onClick="Onenext();">';
				$table .= '</DIV></TD></TR></TABLE></DIV></form></TD></TR></TABLE>';
			}else
			{
				if($pri)
				{	
   				    //$table .= '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR align="center"><TD align="center">';
					//$table .= '<a href="" onMouseOver="roll_over2(\'img_princ\', \''.$imagenes[0].'\', '.$pr['id'].' )">';
					$table .= '<IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'"  border="0" id="img_'.$ps.'">';
					//$table .= '</a>';
					//$table .= '</TD></TR></TABLE>';
					$p = $this->getInfoProducto($pr['id']);
					$prod = 'var p'.$ps.' = Array("'.$p['id'].'", "'.$p['nombre'].'", "'.$p['descripcion'].'", "'.$p['referencia'].'", "'.$p['valor_oferta'].'", "'.$p['valor'].'", "'.$p['fecha_fin'].'");';
					$script .= $prod.'prods['.$ps.'] = p'.$ps.';';
					if($ps == 0)
					{
						$script2 = '<script>roll_over2(\'img_princ\', \''.$imagenes[0].'\', '.$pr['id'].' );</script>';
					}
					$ps++;
				}
			}
			//$table .= "</td></tr>";
			$img++;
		}
		$script .= '</script>';
		//$table .= "</table>";
		
		//echo $script;
		echo $table;
		//echo $script2;
		
		if($index > 0)return true;
		return false;
	}
	/*
	function img_producto_gmoda($id_cat, $gama, $pri='', $num_pag=1, $limit){
		$prods = array();

		
		$this->prods_categoria_gmoda($id_cat, $gama, $prods, $num_pag, $limit);

		//print_r($prods);

		$src = './aplicaciones/admon/catalogo/archivos/';
		$parametros = new Parametros();
		$proporcion=$parametros->getAncho()/$parametros->getAlto();
		$anchoSec=70;
		$altoSec=$anchoSec/$proporcion;
	
		$index=0;


		$img = 1;
		foreach($prods as $pr)
		{	//echo "<br>";
			$sql = "SELECT fichero FROM catalogo_imagen WHERE producto=".$pr['id']." AND tipo='principal'";
			if($this->execute($sql)){	
				$imagenes = '';
				$imagenes = array();
				while(list($fichero)=$this->fetchRow())
				{					
					$imagenes[$index]=$src.$fichero;
					if(!$pri)$index++;
				}
			}else{
				echo "<scrip>alert('�Impossible to consult the database!');</script>";
			}
			
			if($index > 1 && !$pri)
			{
				echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR><TD><form name="Oneslideform">';
				echo '<DIV align="center"><TABLE width="100%" border="1" cellspacing="0" cellpadding="4" bordercolor="#999999">';
				echo '<TR><TD></TD></TR><TR><TD bgcolor="#FFFFFF">';
				echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'" name="Oneshow" border="0"></A></DIV>';
				echo '</TD></TR><TR><TD ><DIV align="center"><SELECT class="listado" name="Oneslide" onChange="Onechange();">';
				for($i=0;$i<$index;$i++){
					if($i==0)
						echo '<OPTION value="'.$imagenes[$i].'"  selected>Imagen '.($i+1).'</OPTION>';
					else	
						echo '<OPTION value="'.$imagenes[$i].'">Imagen '.($i+1).'</OPTION>';
				}		
				echo '</SELECT></TD></TR><TR><TD><DIV align="center">';
				echo '<img src="aplicaciones/admon/catalogo/img/atras1.gif" title="Atras" onClick="Oneprevious();">&nbsp;&nbsp;&nbsp;&nbsp;';
				echo '<INPUT name="Oneslidebutton" type=button class="botones" title="AutoPlay" onClick="Oneap(this.value);" value="Play" style="vertical-align:top ">&nbsp;&nbsp;&nbsp;&nbsp;';
				echo '<img src="aplicaciones/admon/catalogo/img/adelante1.gif" title="Adelante" onClick="Onenext();">';
				echo '</DIV></TD></TR></TABLE></DIV></form></TD></TR></TABLE>';
			}else
			{
				if($pri)
				{	
					echo '<TABLE border="0" cellspacing="0" cellpadding="0" width ="100%" class="contenido"><TR align="right"><TD align="right">';
					echo '<a href="" onMouseOver="roll_over2(\'img_princ\', \''.$imagenes[0].'\' )"><IMG src="'.$imagenes[0].'" width="'. $anchoSec .'" height="'. $altoSec .'"  border="0"></a>';
					echo '</TD></TR></TABLE>';
				}
			}
			$img++;
		}
		if($index > 0)return true;
		return false;
	}
*/

	/*function camp_producto($id_pro)
	{
		$sql = "SELECT titulo,contenido FROM catalogo_campo WHERE producto='$id_pro' and tipo = 'p'";
		
		if($this->execute($sql))
		{
			echo '<TABLE width="200" border="0" cellpadding="0" cellspacing="0">';
			while(list($titulo,$contenido)=$this->fetchRow())
			{
				echo '<tr><td class="usuario">'.$titulo.'</td></tr>';
				echo '<tr><td class="contenido" aling="center"><div align="justify" style=" width:234; height:20; overflow:auto">'.$contenido.'</div></td></tr>';		
				//echo '<tr><td>&nbsp;</td></tr>';		
			}
			echo '</table>';
		}else
		{
			echo "�Impossible to consult the database!";
		}
	}*/

	function mostrarImagenesPanel($id_pro, $id_user_panel)
	{
		$mod = $this->accionPermitida($id_user_panel, 'modificar');
		$del = $this->accionPermitida($id_user_panel, 'eliminar');
		$adm = $this->usuarioEsAdministrador($id_user_panel);
		$parametros = new Parametros();

		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id_pro'and tipo like '%principal%' and tipo not like '%categoria%' group by titulo ORDER BY titulo";
		$imag=0;
		if($this->execute($sql))
		{

			$i=1;
			//echo '<table aling="rigth">';
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				if($tipo=="principal" && eregi('categoria', $tipo)!=1)
				{
					$imag++;
										
					echo '<tr>
					<td align=left>&nbsp;</td>
					<td align="left" valign="top">&nbsp;</td>';
										
					$proporcion=$parametros->getAncho()/$parametros->getAlto();
					$ancho=160;
					$alto=$ancho/$proporcion;
					echo '<td align="left" valign="top"><strong>Tittle: </strong>'.$titulo.'</td>';
					if(eregi('color', $titulo) == 1 || eregi('logo', $titulo) == 1)echo '<td align="left" valign="top"><img src="archivos/'.$fichero.'" width="'.$ancho.'" height="50" border="1"><br>';
 					else echo '<td align="left" valign="top"><img src="archivos/'.$fichero.'" width="'.$ancho.'" height="'.$alto.'" border="1"><br>';

					if($mod==true || $adm)
					{
						echo '<input class="boton1" name="'.$id.'" type="button" value="Changue" onClick="fncModificarImg(this.name)" style="width:69">';
					}
										
					if($del==true  || $adm)
					{
						echo '<input class="boton1" name="'.$id.'" type="button" value="Delete" onClick="fncEliminarImg(this.name)" style="width:69"></td>';
					}

					$i++;
										
					echo '</tr><tr>
								<td align=left>&nbsp;</td>
								<td colspan="3" align="right">&nbsp;</td>
							</tr>';
										
				}									
			}
			//echo '</table>';
		}						
								
	return $imag;

	}
	
	function mostrarColoresWeb_gmoda($id_pro, $vert=false)
	{

		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id_pro' and titulo like '%color%' and tipo like '%categoria%' ORDER BY titulo";
		$imag=0;
		if($this->execute($sql))
		{

			$i=1;
			echo '<table aling="left" cellpadding="0" cellspacing="1">';
			if($vert==false) echo '<tr>';	
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				if(eregi('pri', $tipo) == 1)
				{
					$scr = "./aplicaciones/admon/catalogo/archivos/";
					if($vert==true) echo '<tr>';									
					//echo '<td align="left" valign="top">'.$titulo.'</td>';
					echo '<td align="left" valign="top"><img src="'.$scr.$fichero.'" width="20" height="10" border="0"></td>';										
					if($vert==true)echo '</tr>';
										
				}									
			}
			if($vert==false) echo '</tr>';	
			echo '</table>';
		}						
	}
		
		/*
		Crea un nodo con la informacion de todas las subcategorias que contiene la
		categoria $id.
		*/
		function treeMenuWeb($id = NULL, $nom_cat = NULL, $icon, $expandedIcon, $pag_dest, $solo_publico=false)
		{
				//require_once('./html_menu/TreeMenu.php');
				$node1 = NULL;
				if($id == NULL)
				{
					$sql = "select id, nombre from catalogo_categoria where parent is NULL ";
				}else
				{
					$sql = "select id, nombre from catalogo_categoria where parent = '$id' ";
				}

				if($solo_publico == true)$sql.=" and permiso = 'publico' ";
				$sql.=" order by nombre";

				$categs = array();
				$nun_cats = 0;
				if($this->execute($sql))
				{
					$nun_cats = $this->numRows();
					if($nun_cats > 0)
					{
						while($categ = $this->fetchRow())
						{
							$categs[]['categoria'] = $categ;
						}
					}
				}else
				{
					$out=trim($this->getMensaje("[009]","error"));
					$out.="\\n:Desc: ".trim($this->getException());
					$this->setSalida(false,$out,"$id, $nom_cat, $icon, $expandedIcon",$this->id);
					return false;
				}
				
				$node1   = new HTML_TreeNode(array('text' => $nom_cat, 'link' => $pag_dest."?id_categoria=".$id, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => false), array());

				for($i = 0; $i < $nun_cats; $i++)
				{
					$cat = $categs[$i]['categoria'];
					//$categs[$i]['categorias'] = $this->treeMenuWeb($cat[0]);
					$node1->addItem($this->treeMenuWeb($cat[0], $cat[1], $icon, $expandedIcon, $pag_dest, $solo_publico));
					//$array[] = $node1;
					
				}
				return $node1;	
		}

		/*
		Genera una cadena para mostrar en un menu dinamico el contenido de la categoria $id.
		Para esto usamos el archivo TreeMenu.js y TreeMenu.php
		*/
		function printCatalogoWeb($id = NULL, $img='', $img_exp='', $pag_des, $solo_publico=false)
		{
			//require_once('./html_menu/TreeMenu.php');
			$icon         = 'folder.gif';
    		$expandedIcon = 'folder-expanded.gif';
			$this->reactivarDB();
			$array = array();
			if(!$img)$icon  = $img;
			if($img_exp)$expandedIcon = $img_exp;
			if($id == NULL)
			{
				$sql = "select id, nombre from catalogo_categoria where parent is NULL ";
			}else
			{
				$sql = "select id, nombre from catalogo_categoria where parent = '$id' ";
			}
			if($solo_publico == true)$sql.=" and permiso = 'publico' ";
			$sql.=" order by nombre";
			$categs = array();
			$nun_cats = 0;
			if($this->execute($sql))
			{
				$nun_cats = $this->numRows();
				if($nun_cats > 0)
				{
					while($categ = $this->fetchRow())
					{
						$categs[]['categoria'] = $categ;
					}
				}
			}else
			{
				$out=trim($this->getMensaje("[009]","error"));
				$out.="\\n:Desc: ".trim($this->getException());
				$this->setSalida(false,$out,"printCatalogoWeb($id , $img, $img_exp, $pag_des)",$this->id);
				return false;
			}
			$node1   = new HTML_TreeNode(array('text' => $nom_cat, 'link' => "test.php", 'icon' => $icon, 'expandedIcon' => NULL, 'expanded' => false), array());
			for($i = 0; $i < $nun_cats; $i++)
			{
				$cat = $categs[$i]['categoria'];
				$array[] = $this->treeMenuWeb($cat[0], $cat[1], $icon, $expandedIcon, $pag_des, $solo_publico);					
			}
			$menu  = new HTML_TreeMenu();
			for($i = 0; $i < $nun_cats; $i++)
			{
				$menu->addItem($array[$i]);		
			}
			// Create the presentation class
			$array2 = array();
			$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => './aplicaciones/admon/catalogo/fnc/html_menu/images2', 'defaultClass' => 'treeMenuDefault'));
			$listBox  = &new HTML_TreeMenu_Listbox($menu, array('linkTarget' => '_self'));

			$array2[]=$treeMenu;
			$array2[]=$listBox;

			return $array2;
		}

 
	function info_categoriaDBInput($nivel, $id, $ids, $idss)
	{
		$this->utileria = new Utileria();
		if($nivel==0)
		{
		$sql = "SELECT id,nombre,descripcion,permiso FROM catalogo_categoria WHERE id = ".$id;
		}
		if($nivel==1)
		{
			$sql = "SELECT id,nombre,descripcion,permiso FROM catalogo_categoria WHERE id = ".$ids;
		}
		if($nivel==2)
		{
			$sql = "SELECT id,nombre,descripcion,permiso FROM catalogo_categoria WHERE id = ".$idss;
		}
		if($nivel==3)
		{
			$sql = "SELECT id,nombre,descripcion,permiso FROM catalogo_categoria WHERE id = ".$idss;
		}

		if($this->execute($sql))
		{
			$cat = array();
			$cat = $this->fetchRow();
			$cat[2] = $cat['descripcion'] = $this->utileria->parseDB2Input($cat['descripcion']);
			return $cat;
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"info_categoriaDBInput($nivel, $id, $ids, $ids)",$this->nombre);
			return NULL;	
	
		}
	}

	/* dise�os tropicales */
	function mostrarImagenesPanelCategoria($id_pro, $id_user_panel)
	{
		$mod = $this->accionPermitida($id_user_panel, 'modificar');
		$del = $this->accionPermitida($id_user_panel, 'eliminar');
		$adm = $this->usuarioEsAdministrador($id_user_panel);
		$parametros = new Parametros();	
		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id_pro' and tipo like '%categoria-pri%' ORDER BY titulo";
		$imag=0;
		if($this->execute($sql))
		{

			$i=1;
			echo '<table aling="center" class="texto1" width="100%">';
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				if($tipo!="principal")
				{
					$imag++;
										
					echo '<tr>';
										
					$proporcion=$parametros->getAncho()/$parametros->getAlto();
					$ancho=160;
					$alto=$ancho/$proporcion;
					echo '<td align="left" valign="top">T&iacute;tulo: '.$titulo.'</td><td>&nbsp;</td>';
					if(eregi("color", $titulo) == 1 )echo '<td align="left" valign="top"><img src="archivos/'.$fichero.'" width="'.$ancho.'" height="50" border="1"><br>';
					else
					{
					if(eregi("logo", $titulo) == 1 )echo '<td align="left" valign="top"><img src="archivos/'.$fichero.'" border="1"><br>';
 					else echo '<td align="left" valign="top" width="75%"><img src="archivos/'.$fichero.'" width="'.$ancho.'" height="'.$alto.'" border="1"><br>';
					}
					if($mod==true || $adm)
					{
						echo '<input class="boton1" name="'.$id.'" type="button" value="Cambiar" onClick="fncModificarImg(this.name)" style="width:69">';
					}
										
					if($del==true  || $adm)
					{
						echo '<input class="boton1" name="'.$id.'" type="button" value="Eliminar" onClick="fncEliminarImg(this.name)" style="width:69"></td>';
					}

					$i++;
										
					echo '</tr><tr>
								<td align=left>&nbsp;</td>
								<td colspan="3" align="right">&nbsp;</td>
							</tr>';
										
				}									
			}
			echo '</table>';
		}						
								
	return $imag;

	}

	/* dise�os tropicales */
	function mostrarImagenesCategoriaWeb($id_pro, $princ=true, $w='', $h='', $info=false)
	{

		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id_pro' and tipo like '%categoria%' and titulo not like '%color%' ORDER BY titulo";
		if(!$w)$w=428;
		if(!$h)$h=340;
		$imag='';
		if($this->execute($sql))
		{

			$i=1;
			
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				
				if($princ == true)
				{
					if(eregi("categoria-pri",$tipo)==1)
 					$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
				}else
				{
 					$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
				}		
				break;							
			}
		}	


	if($url == true)
	{	
		if($fichero)
		return 	$this->dirSetup.'archivos/'.$fichero;	
	}
			
	if($info==true)
	{
		$array = array();
		$array[] = $this->dirSetup.'archivos/'.$fichero;
		$array[] = $imag;
		return $array;
	}
	return $imag;
	}


	/* dise�os tropicales */
	function mostrarImagenesProductoWeb($id_pro, $princ=true, $w='', $h='', $info=false)
	{

		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id_pro'  and titulo not like '%color%'  ORDER BY titulo";
		
		$imag='';
		if($this->execute($sql))
		{

			$i=1;
			if(!$w)$w=374;
			if(!$h)$h=331;
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				if(eregi("categoria",$tipo)!=1 && eregi("color",$titulo)!=1)
				{
					if($princ == true)
					{
						if(eregi("principal",$tipo)==1)
						$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
					}else
					{
						$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
					}		
					break;	
				}
										
			}
		}						
	
	if($url == true)
	{	
		if($fichero)
		return 	$this->dirSetup.'archivos/'.$fichero;	
	}
	if($info==true)
	{
		$array = array();
		$array[] = $this->dirSetup.'archivos/'.$fichero;
		$array[] = $imag;
		return $array;
	}
	return $imag;

	}

	/* parasoles */
	/*
	Muestra las categorias principales mediante imagenes
	*/
	function mostrarMenuPrincipalCategorias($img_menues, $pagina_dest, $propiedades_tabla='', $w='', $h='', $text=false)
	{
			$table = '<table'.$propiedades_tabla.' width="165" border="0" cellspacing="0" cellpadding="0">';
		$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL";
		$img = false;
		if($img_menues && count($img_menues)>0) $img = true;
	
		if($this->execute($sql))
		{
				if(!$w)$w=165;
				if(!$h)$h=16;
				$nc = 0;
				while(list($id_cat, $nombre_cat, $permiso_cat) = $this->fetchRow())
				{
					if($nc == 0)$table .= '<tr width="165" >';
					$table .= '<td height="16" class="algo">';
					$table .= '<a href="'.$pagina_dest.'?id='.$id_cat.'" style="text-decoration:none; " border="0">';
					if($img == false)
					{
						$table .= $nombre_cat;
					}else
					{
						$link = false;
						foreach($img_menues as $imagen)
						{ 
							//echo "<br>".$imagen['nombre']." = ". $nombre_cat;
							if(eregi($imagen['nombre'], $nombre_cat) == 1)
							{
								$table .= '<img src="'.$imagen['file'].'" width="'.$w.'" height="'.$h.'" border="0">';
								$link = true;
								break;
							}
						}
						if($link == false)
						{
							$table .= $nombre_cat;
						}
					}
					$table .= '</a>';
					$table .= '</td>';
					if($text==true) $table.='<td class="catalogo1">'.$nombre_cat.'</td>';
					$nc++;
					if($nc == $nun_cols)
					{	
						$nc = 0;
						$table.='</tr>';
					}
				}
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"mostrarMenuPrincipalCategorias($img_menue, $w, $hs)",$this->nombre);
			//return NULL;	
			foreach($img_menues as $imagen)
			{
				$table .= '<tr><td height="16" class="algo">';
				$table .= '<img src="'.$imagen['src'].'>';
				$table .= '</td></tr>';
	
			}
		
		}
		$table .= "</table>";
		echo $table;
	
	}

	function catalogos($id_car,$ini, $solo_publico=false,$bus_referencia='')
	{
		$db2 = new Componente();
		$ruta = "./aplicaciones/admon/catalogo/archivos/";
		if($bus_referencia != ''){		
			$nombre_carpeta = "Busqueda Por Referencia!.";
			if($id_car != ''){
				$wel = "categoria='$id_car' AND referencia like '%$bus_referencia%'";	
			}else{
				$wel = "referencia like '%$bus_referencia%'";
			}
		}else{
			$sql = "SELECT nombre FROM catalogo_categoria WHERE id='$id_car'";
			$this->execute($sql);
			
			list($nombre_carpeta) = $this->fetchRow();
			$wel = "categoria='$id_car'";
		}
		
		echo '<div align="center" class="menu1">Categoria: '.$nombre_carpeta.'</div><br>';
		//$parametros=new Parametros();
		$id_tmp=NULL;
		$id_tmp1=NULL;
		$tabla=0;
		$control=0;
		$sql = "SELECT id,categoria,referencia,nombre,descripcion,valor,estado,estado_oferta,fecha_fin,valor_oferta,permiso FROM catalogo_producto WHERE $wel and tipo='p' ";
		if($solo_publico == true)$sql.=" and permiso like 'publico' ";
		$sql.=" order by nombre";
		$this->execute($sql);
		if($this->numRows())
		{	
			$i = 1; $j=0; $limite =10; $write=0;
			while((list($id_pro, $categoria,$referencia,$nombre,$descripcion,$valor,$estado,$estado_oferta,$fecha_fin,$valor_oferta,$permiso) = $this->fetchRow()))
			{
				$sql2="SELECT id,producto,tipo,fichero,ancho,alto FROM catalogo_imagen WHERE producto='$id_pro' and tipo not like '%categoria%' order by id limit 0, 1";
				$db2->execute($sql2);	
				if($estado=="disponible")
				{
					$estado="Producto disponible";
				}elseif($estado=="no disponible")
				{
					$estado="Producto no disponible";			
				}elseif($estado=="nuevo")
				{
					$estado="Producto nuevo";			
				}elseif($estado=="promocion")
				{
					$mes_fin=substr(substr($fecha_fin,5),0,2);
					$dia_fin=substr(substr($fecha_fin,8),0,2);
					$anio_fin=substr($fecha_fin,0,4);
					
					$fecha_act = date('Y-m-d');
					$mes_act=substr(substr($fecha_act,5),0,2);
					$dia_act=substr(substr($fecha_act,8),0,2);
					$anio_act=substr($fecha_act,0,4);
				
					if($anio_fin>$anio_act)
					{
						$estado="Producto en oferta";
					}elseif($anio_fin<$anio_act)
					{
						$estado="Oferta finalizada";
					}elseif($anio_fin=$anio_act)
					{
						if($mes_fin>$mes_act)
						{
							$estado="Producto en oferta";
						}elseif($mes_fin<$mes_act)
						{
							$estado="Oferta finalizada";
						}elseif($mes_fin=$mes_act)
						{
							if($dia_fin>$dia_act)
							{
								$estado="Producto en oferta";
							}elseif($dia_fin<=$dia_act)
							{
								$estado="Oferta finalizada";
							}
						}
					}
				}	 
				$imagen_existe = false;
				while((list($id_img,$producto,$tipo,$fichero,$ancho,$alto) = $db2->fetchRow()) && ($j<$limite))
				{	
					$imagen_existe = true;
					if($id_img!=$id_tmp && $id_pro!=$id_tmp1 )
					{
						$id_tmp=$id_img;
						$id_tmp1=$id_pro;
						$this->cantidad++;
						if($write>=$ini)
						{
							if($i==1)
							{ 
								$i++;
											
								$tabla++;
								if($control==0)
								{
									echo '<tr>';
								}
								$parametros =new  Parametros();
								$proporcion=$parametros->getAncho()/$parametros->getAlto();
								//$proporcion=$this->parametros->getAncho()/$this->parametros->getAlto();
								$anchoSec=160;
								$altoSec=$anchoSec/$proporcion;
								echo '<td width="50%">';
								if($fichero){
								echo '<table width="100%" border="0" >';
								echo '<tr><td onMouseover="this.bgColor=\'#e0e0e0\'" onMouseout="this.bgColor=\'#ffffff\'" valign="middle" align="center"><a onClick="return fncVisualizarProd('.$id_pro.')" title="Ver mas" style="cursor:hand"><img src="'.$ruta.$fichero.'" width="'.$anchoSec.'" height="'.$altoSec.'"></a></td></tr>';				
								echo '</table>';
								}
								echo '<table width="100%" border="0">';
								echo '<tr><td valign="top" width="40%" align="right"><strong>Nombre: </strong></td><td width="50%"  align="left">'.$nombre.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Referencia: </strong></td><td width="50%" align="left">'.$referencia.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Status: </strong></td><td width="50%"  align="left">'.$estado.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"></td><td width="50%" align="right"><a onClick="return fncVisualizarProd('.$id_pro.')" title="Ver mas" style="cursor:hand; text-decoration:none; font-size:10px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000" onMouseover="this.style.color=\'0000FF\'" onMouseOut="this.style.color=\'000000\';"><strong>Ver mas</strong></a></td></tr>';	
								echo '</table></td>';
							
								if($control==1)
								{
									echo '</tr>';
									$control++;
								}
							
								if($control==2)
								{
									$control=0;
								}else
								{
									$control++;	
								}	
							
							}else
							{
							
								$tabla++;
								if($control==0)
								{
									echo '<tr>';
								}
								
								$proporcion=$parametros->getAncho()/$parametros->getAlto();
								$anchoSec=160;
								$altoSec=$anchoSec/$proporcion;
								echo '<td width="50%">';
								echo '<table width="100%" border="0">';
								echo '<tr><td onMouseover="this.bgColor=\'#e0e0e0\'" onMouseout="this.bgColor=\'#ffffff\'" valign="middle" align="center"><a onClick="return fncVisualizarProd('.$id_pro.')" style="cursor:hand" title="Ver mas"><img src="'.$ruta.$fichero.'" width="'.$anchoSec.'" height="'.$altoSec.'"></a></td></tr>';				
								echo '</table><table width="100%" border="0">';
								echo '<tr><td valign="top" width="40%" align="right"><strong>Nombre: </strong></td><td width="50%"  align="left">'.$nombre.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Referencia: </strong></td><td width="50%"  align="left">'.$referencia.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Status: </strong></td><td width="50%"  align="left">'.$estado.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"></td><td width="50%" align="right"><a onClick="return fncVisualizarProd('.$id_pro.')" title="Ver mas" style="cursor:hand; text-decoration:none; font-size:10px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000" onMouseover="this.style.color=\'0000FF\'" onMouseOut="this.style.color=\'000000\';"><strong>Ver mas</strong></a></td></tr>';
								echo '</table></td>';
								
								if($control==1)
								{
									echo '</tr>';
									$control++;
								}
								
								if($control==2)
								{
									$control=0;
								}else
								{
									$control++;	
								}				
						
							}
							$j++;
						}
						$write++;
					}
				}
				if($imagen_existe == false)
				{
								echo '<td width="50%">';
								echo '<table width="100%" border="0" >';
								echo '<tr><td onMouseover="this.bgColor=\'#e0e0e0\'" onMouseout="this.bgColor=\'#ffffff\'" valign="middle" align="center"><a onClick="return fncVisualizarProd('.$id_pro.')" title="Ver mas" style="cursor:hand"><img src="'.$ruta."/producto.gif".'" width="'.$anchoSec.'" height="'.$altoSec.'"></a></td></tr>';				
								echo '</table>';
								
								echo '<table width="100%" border="0">';
								echo '<tr><td valign="top" width="40%" align="right"><strong>Nombre: </strong></td><td width="50%"  align="left">'.$nombre.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Referencia: </strong></td><td width="50%" align="left">'.$referencia.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"><strong>Status: </strong></td><td width="50%"  align="left">'.$estado.'</td></tr>';	
								echo '<tr><td valign="top" width="40%" align="right"></td><td width="50%" align="right"><a onClick="return fncVisualizarProd('.$id_pro.')" title="Ver mas" style="cursor:hand; text-decoration:none; font-size:10px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000" onMouseover="this.style.color=\'0000FF\'" onMouseOut="this.style.color=\'000000\';"><strong>Ver mas</strong></a></td></tr>';	
								echo '</table></td>';			
				}
			}
		} else 
		{
				echo '<tr><td width="100%" ><div align="center">No hay productos registrados en esta categoria.</div></td></tr>';       
		}
			
		if($tabla%2!=0)
		{
			echo '<td></td></tr>';
		}
	}

	
	/*
	Muestra las categorias principales mediante imagenes
	*/
	/*
	Muestra las categorias principales mediante imagenes
	*/
	function mostrarMenuCategorias($nivel, $id, $ids, $idss ,$pagina_dest, $prods=false,$num_cols=1, $styles='', $img=true, $desc=true, $num_pag=1, $n_items=10, $sub=false, $id_prod_='', $images_nav='', $info=true, $w='', $h='', $option_navs='', $url_image=false)
	{
		if(!$images_nav)
		{
			$images_nav = array();
			$images_nav['inicio']='<img src="images/nav/inicio2.png" border="0"  height="14">';
			$images_nav['atras']='<img src="images/nav/atras.gif" border="0"  height="14">';
			$images_nav['sig']='<img src="images/nav/sig.gif" border="0"  height="14">';
			$images_nav['final']='<img src="images/nav/final2.png" border="0"  height="14">';
		}
		$inicio = ($num_pag-1)*$n_items;
		$limite = $n_items;
	

		$table = '<table '.$styles['table'].'>';
		$id_cat=$id;
		if($nivel == 0)
		{
			$sql = "SELECT id, nombre, permiso, descripcion FROM catalogo_categoria WHERE parent is NULL  order by nombre ";
	
		}else
		{
			if($nivel == 1)
			{
				$id_cat=$id;
				$sql = "SELECT id, nombre, permiso, descripcion  FROM catalogo_categoria WHERE parent = $id  order by nombre ";
			}else
			{
				if($nivel == 2)
				{
					$id_cat=$ids;
					$sql = "SELECT id, nombre, permiso, descripcion  FROM catalogo_categoria WHERE parent = $ids  order by nombre ";
				}else
				{
					$id_cat=$idss;
				}
			}
		}
	
		if($prods==true)
		{
			$sql = "SELECT id, nombre, permiso, descripcion  FROM catalogo_producto WHERE categoria = $id_cat and tipo='p' order by nombre ";
			
			if($sub == true)
			{
				$sql = "SELECT id, nombre, permiso, descripcion  FROM catalogo_producto WHERE parent = $id_prod_ and tipo='s' order by nombre ";
			}
		}
		$sql2=$sql;
		$sql.="limit $inicio, $limite";
		//echo $sql;
		$im_links = array();
		$im_links_source = array();
		$res=0;
		$img_inicial =false;
		$script2='';
		$resultados = $this->consultarCampos($sql, "mostrarMenuCategorias($nivel, $id, $ids, $idss ,$pagina_dest, $prods,$nun_cols, $propiedades_tabla, $img)");
		if($resultados)
		{
			$res = count($resultados);
			$k = 0;
			
			$script='';
			while($k < $res)
			{
				$table .= '<tr '.$styles['tr'].' >';
				for($j = 0; $j < $num_cols; $j++)				
				{	if($k >= $res )break;
					list($id_, $nombre_, $permiso_, $descripcion_) = $resultados[$k];
					$item = $resultados[$k];
					if(true)
					{
						$table .= '<td '.$styles['td'].'  width="'.(100/$res).'%" >';
	
						$sub_prod = '';
						if($sub == true)$sub_prod = '&sub_p=true&pro_r='.$id_prod_;
						$ahref='';
						if($nivel == 0)
						{
							$ahref.= '<a href="'.$pagina_dest.'id='.$id_.'&actual='.$nombre_.$sub_prod.'" style="text-decoration:none; " border="0" ';
						}
						if($nivel == 1)
						{
							if($prods==false)
								$ahref.= '<a href="'.$pagina_dest.'id='.$id.'&ids='.$id_.'&actual='.$nombre_.'&nivel='.($nivel+1).$sub_prod.'" style="text-decoration:none; " border="0" ';
							else
								$ahref.='<a href="'.$pagina_dest.'id='.$id.'&id_pro='.$id_.'&actual='.$nombre_.'&nivel='.($nivel+1).$sub_prod.'" style="text-decoration:none; " border="0" ';
		
						}
						if($nivel == 2)
						{
							if($prods==false)
								$ahref.= '<a href="'.$pagina_dest.'id='.$id.'&ids='.$ids.'&idss='.$id_.'&actual='.$nombre_.$sub_prod.'" style="text-decoration:none; " border="0" ';
							else
								$ahref.= '<a href="'.$pagina_dest.'id='.$id.'&ids='.$ids.'&id_pro='.$id_.'&actual='.$nombre_.$sub_prod.'" style="text-decoration:none; " border="0" ';
		
						}
						if($nivel == 3)
						{
							if($prods==false)
								$ahref.= '<a href="'.$pagina_dest.'id='.$id.'&ids='.$ids.'&idss='.$idss.'&id_pro='.$id_.'&actual='.$nombre_.$sub_prod.'" style="text-decoration:none; " border="0" ';
							else
								$ahref.= '<a href="'.$pagina_dest.'id='.$id.'&ids='.$ids.'&idss='.$idss.'&id_pro='.$id_.'&actual='.$nombre_.$sub_prod.'" style="text-decoration:none; " border="0" ';
						}
		
						if($img == false)
						{
							$table .= $nombre_;
						}else
						{
							$link = false;
							if($prods==false)
							{
								$imagen=$this->mostrarImagenesCategoriaWeb($id_, false, $w, $h, true, $url_image);
							}else
							{
								$imagen=$this->mostrarImagenesProductoWeb($id_, false, $w, $h, true, $url_image);
							}
							
							if($imagen)
							{
								$table .= '<table>';
								if($desc == true) $table .= '<tr><td class="catalogo1">'.$nombre_.'</td></tr>';
								$table .= '<tr><td>';
								$img_link = $ahref.'onMouseOver="roll_over2(\'img_princ\', \''.$imagen[0].'\' , '.$id_.')"'.'>'.$imagen[1].'</a>';
								$im_links[] = $img_link;
								$item['image_url'] = $imagen;
								$resultados[$k] = $item;
								$im_links_source[] = $imagen;
								$table .= $ahref.' '.'>'.$imagen[1].'</a>';
								$table .= '</td></tr></table>';
								$link = true;
								//$p = $this->getInfoProducto($pr['id']);
								$prodscript= 'var p'.($k).' = Array("'.$id_.'", "'.$nombre_.'", "'.$descripcion_.'", "'.$permiso_.'");';
								$script .= $prodscript.'prods['.($k).'] = p'.($k).';';
								
								if($imagen_inicial == false)
								{
									$script2 = '<script>roll_over2(\'img_princ\', \''.$imagen[0].'\', '.$id_.' );</script>';
								}
							}
							
		
							if($link == false)
							{
								$table .= $nombre_cat;
							}
						}
						//$table .= '</a>';
						$table .= '</td>';
						if($desc == true)
						{
							//$table .= '<td class="algo"><div align="justify">'.$this->utileria->parseDB2Html($descripcion_).'</div></td>';;
						}
						$k++;
					}/*else
					{
						return $resultados;
					}*/
				}
				$table .= '</tr>';
			
			}
		}else
		{
			$out=trim($this->getMensaje("[016]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"mostrarMenuPrincipalCategorias($img_menue, $w, $hs)",$this->nombre);
			//return NULL;	
		
		}
		$table .= "</table>";
		//if($info == true)echo $table;
		
		/* calculamos numero total de paginas */
		if($this->execute($sql2));
		$res = $this->numRows();
	
		$final = ceil($res/$n_items);
		if($final == 0)$final=1;
		$atras = 1;
		if( ($num_pag-1) >= 1) $atras = ($num_pag-1);
	
		$sig = $final;
		if(($num_pag+1) <= $final)$sig = ($num_pag+1);
	 
		
		if($res>$n_items)
		{
			if($prods==true) $linea_ = "&linea=false";
	
			if($option_navs)
			{
				$nav = '<table border="0"  cellspacing="0" cellpadding="0"><tr>';
				if($option_navs['inicio'] == true)
				{
				$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. '1' .'" border="0"><img src="'.$option_navs['inicio'].'" border="0"></a></td>';
				}
				if($option_navs['atras'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. ($atras) .'"><img src="'.$option_navs['atras_image'].'"  border="0"></a></td>';
				}
				if($option_navs['pag'] == true)
				{
					$nav .= '<td class="algo"><img src="'.$option_navs['pag_image'].'" width="59" height="14"></td>';
					//$nav .= '<td class="algo">pag '.$num_pag.'</td>';
				}else
				{
					$nav .= '<td class="algo">&nbsp;</td>';
				}

				if($option_navs['sig'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. ($sig) .'"><img src="'.$option_navs['sig_image'].'"  border="0"></a></td>';
				}
				if($option_navs['final'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='.$final.'"><img src="'.$option_navs['final'].'"  border="0"></a></td>';
				}
				$nav .= '</tr></table>';
			}else
			{
				$nav = '<table><tr><td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. '1' .'" border="0">'.$images_nav['inicio'].'</a></td><td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. ($atras) .'">'.$images_nav['atras'].'</a></td><td class="algo">pag '.$num_pag.'</td><td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='. ($sig) .'">'.$images_nav['sig'].'</a></td><td><a href="'.$option_navs['href'].'nivel='.$nivel.$linea_.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag='.$final.'">'.$images_nav['final'].'</a></td></tr></table>';
			}
			$im_links['nav'] = $nav;
			//if($info == true)echo $nav;
		}/*else
		{
			$nav = '<table border="0"  cellspacing="0" cellpadding="0"><tr>';
			$nav .= '<td width="49" height="14"><img src="images/lf_B_previous.jpg" width="19" height="14"></td>
              <td width="49"><img src="images/lf_B_vermas.jpg" width="49" height="14"></td>
              <td width="19"><img src="images/lf_B_next.jpg" width="19" height="14"></td>';
			$nav .= '</tr></table>';
			$im_links['nav'] = $nav;
		}*/
		//$table.=$nav;

		if($url_image == true)
		{
			return $resultados;
		}
		if($info==true)
		{
			echo $table.'<script>'.$script.'</script>'.$script2;
			return $nav;
		}else
		{
			
			return $im_links;
		}
	}

	/*
		$inf, define que informacion se mostrara de los campos, 1 muestra solo titulo, 2 mustra solo el contenido y 3 muestra ambos.
		$primero_titulo, define el orden en que muestra los campos, true muestra primero el titulo y luego el contenido, false los muestra en forma invertida
		$style, array con los estilos definidos para <tr>, <td>, <table>
	*/
	function obtenerCamposWeb($id_pro, $primero_titulo=true, $inf=3, $style='', $tipo='p')
	{
		$sql = "SELECT id, titulo, contenido from catalogo_campo WHERE producto='$id_pro' and tipo='$tipo' order by id";
		
		$campos = $this->consultarCampos($sql, "obtenerCamposWeb($id_pro)");

		$table = '<table '.$style['table'].'>';
		if($campos && count($campos)>0)
		{
			
			foreach($campos as $campo)
			{
				if($inf == 3)
				{
					$table .= '<tr '.$style['tr'].'>';
					$text1 = '';
					$text2 = '';
					$style1 = '';
					$style2 = '';
					if($primero_titulo==true)
					{
						$text1 = $campo['titulo'].'';
						$text2 = $this->utileria->parseDB2Html($campo['contenido']);
						$style1 = $style['td-titulo'];
						$style2 = $style['td-contenido'];
					}else
					{
						$text2 = $campo['titulo'];
						$text1 = $this->utileria->parseDB2Html($campo['contenido']);
						$style2 = $style['td-titulo'];
						$style1 = $style['td-contenido'];
					}
					$table .= '<td '.$style1.'>'.$text1;		
					$table .= '</td>';
					$table .= '<td '.$style2.'>'.$text2;		
					$table .= '</td>';
				}else
				{
					$text = '';
					if($inf == 1)
					{
						$text = $campo['titulo'];
					}else
					{
						$text = $campo['contenido'];
					}
					$table .= '<td '.$style['td'].'>'.$text;		
					$table .= '</td>';
				}
				$table .= '</tr>';
			}			
		}
		$table .= '</table>';
		echo $table;
	}

	/* agregar campo*/
	function add_campo_cat($titulo,$contenido,$id_cat, $show_mesage=false){					
		//$this->setFiles(4);
		$this->reactivarDB();
		$this->utileria = new Utileria();
		$sql = "SELECT id from catalogo_campo WHERE producto='$id_cat' AND titulo='$titulo' AND tipo='c'";
		$this->execute($sql);
		$cant=$this->numRows();
		if($cant==0){	
			$contenido = $this->utileria->parseInput2DB($contenido);
			$sql="insert into catalogo_campo (producto,titulo,contenido, tipo) values ('$id_cat','$titulo','".$this->utileria->parseInput2DB($contenido)."', 'c')";
		
			if($this->execute($sql)){
				if($show_mesage==true)$this->mostrarMensaje($this->getMensaje("[262]","confirmacion"));
			}else{
				if($show_mesage==true)$this->mostrarMensaje($this->getMensaje("[016]","error"));
				return false;
			}
		}else{
			if($show_mesage==true)$this->mostrarMensaje($this->getMensaje("[263]","confirmacion"));
			return false;
		}			
		return true;
	}
	/* modificar campo*/
	function mod_campo_cat($titulo,$contenido,$id_cam){
		//$this->setFiles(4);
		$this->reactivarDB();
		$sql = "SELECT id from catalogo_campo WHERE producto='$id_cam' AND titulo='$titulo' AND id!='$id_cam' AND tipo='c'";
		$this->execute($sql);
		$cant=$this->numRows();
		if($cant==0){	
			$contenido = $this->utileria->parseInput2DB($contenido);
			$sql="update catalogo_campo set titulo='$titulo', contenido='$contenido' where id='$id_cam'";
			if($this->execute($sql)){
				$this->mostrarMensaje($this->getMensaje("[264]","confirmacion"));
			}else{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));
				return false;
			}
		}else{
			$this->mostrarMensaje($this->getMensaje("[263]","confirmacion"));
			return false;
		}		
		return true;	
	}
	
	/* eliminar campo*/
	function eli_campo_cat($id_cam){					
		//$this->setFiles(4);
		$this->reactivarDB();
		$sql="delete from catalogo_campo where id = '$id_cam' AND tipo='c'";
		if($this->execute($sql)){
			$this->mostrarMensaje($this->getMensaje("[265]","confirmacion"));
		}else{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));			
		}
	}
	
	function eli_campos_cat($id_cat)
	{
		$this->reactivarDB();
		$sql="delete from catalogo_campo where producto = '$id_cat' AND tipo='c'";
		if(!$this->execute($sql))
		{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));			
		}
	}
	function ver_productos($query){
		$this->reactivarDB();	
		$sql = "SELECT p.nombre,i.fichero,p.id FROM catalogo_producto p, catalogo_imagen i WHERE p.id = i.producto AND p.estado = '$query' AND i.tipo = 'principal' ORDER by RAND() LIMIT 1";
		if($this->execute($sql)){
			list($nombre,$fichero,$id_) = $this->fetchRow();
			echo '<a href="#" onClick="fncVisualizarProd('.$id_.')"><img src="aplicaciones/admon/catalogo/archivos/'.$fichero.'" width="137" height="134" border="0"></a><br>
                          <span class="style7">'.$nombre.'</span>';
		}else{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));			
		}
	
	}

	function mostrarCamposPanelProductosCatalogo($id_pro, $userModificar= "disabled", $userEliminar= "disabled", $userAdicionar= "disabled", $userAdministrar= "disabled", $styles='')
	{
		$sql="SELECT id,titulo,contenido from catalogo_campo WHERE producto='$id_pro' and tipo='p' ORDER BY titulo";
		if($this->execute($sql))
		{
			$i=1;
			$camp=$this->numRows();
			//echo '<table aling="center" class="texto1" width="100%"><tr aling="center"><td>';
			echo '<table '.$styles['table'].'>';
			while(list($id,$titulo,$contenido)=$this->fetchRow())
			{
				echo '<tr '.$styles['tr-titulo'].'>';
				echo '<td '.$styles['td-titulo'].'>';
				echo '<strong>T&iacute;tulo:</strong></td>';
				echo '<td '.$styles['td-contenido'].'>';
				echo '<strong>Contenido:</strong></td>';
				echo '</tr><tr><td '.$styles['td-titulo'].'>'.$titulo.'</td><td '.$styles['td-contenido'].'>';
				echo '<div align="justify" class="listado" style=" width:327; height:40; overflow:auto">';
				echo $this->utileria->parseDB2Html($contenido);
				echo '</div>';
				echo '</td>';
				echo '</tr>';
		
				echo '<tr '.$styles['tr-contenido'].'>'; 
				if($userModificar!= "disabled")
				{
					echo '<td>';
					echo '<input '.$styles['boton'].' name="'.$id.'" type="button" value="Cambiar" onClick="fncModificarCam(this.name)" style="width:69">';
					//echo '</td>';
				}
				if($userEliminar!= "disabled")
				{
					echo '<td>';
					echo '<input '.$styles['boton'].' name="'.$id.'" type="button" value="Eliminar" onClick="fncEliminarCam(this.name)" style="width:69">';
					//echo '</td>';
				}
				echo '</td>';
				echo '</tr>'; 

				$i++;

			}
			//echo '</table><br><br><br>';
			echo '</td></tr></table>';
		}					
	}

	function mostrarCamposPanelCategoriaCatalogo($id_cat, $userModificar= "disabled", $userEliminar= "disabled", $userAdicionar= "disabled", $userAdministrar= "disabled", $styles='')
	{
		$sql="SELECT id,titulo,contenido from catalogo_campo WHERE producto='$id_cat' and tipo='c' ORDER BY titulo";
		if($this->execute($sql))
		{
			$i=1;
			$camp=$this->numRows();
			//echo '<table aling="center" class="texto1" width="100%"><tr aling="center"><td>';
			echo '<table '.$styles['table'].'>';
			while(list($id,$titulo,$contenido)=$this->fetchRow())
			{
				echo '<tr '.$styles['tr-titulo'].'>';
				echo '<td '.$styles['td-titulo'].'>';
				echo '<strong>T&iacute;tulo:</strong></td>';
				echo '<td '.$styles['td-contenido'].'>';
				echo '<strong>Contenido:</strong></td>';
				echo '</tr><tr><td '.$styles['td-titulo'].'>'.$titulo.'</td><td '.$styles['td-contenido'].'>';
				echo '<div align="justify" class="listado" style=" width:327; height:40; overflow:auto">';
				echo $this->utileria->parseDB2Html($contenido);
				echo '</div>';
				echo '</td>';
				echo '</tr>';
		
				echo '<tr '.$styles['tr-contenido'].'>'; 
				if($userModificar!= "disabled")
				{
					echo '<td>';
					echo '<input '.$styles['boton'].' name="'.$id.'" type="button" value="Cambiar" onClick="fncModificarCam(this.name)" style="width:69">';
					//echo '</td>';
				}
				if($userEliminar!= "disabled")
				{
					echo '<td>';
					echo '<input '.$styles['boton'].' name="'.$id.'" type="button" value="Eliminar" onClick="fncEliminarCam(this.name)" style="width:69">';
					//echo '</td>';
				}
				echo '</td>';
				echo '</tr>'; 

				$i++;

			}
			//echo '</table><br><br><br>';
			echo '</td></tr></table>';
		}					
	}


	function eli_imagen_categoria($id_img)
	{
		//$this->setFiles(4);
		$this->reactivarDB();
		$sql="select tipo,fichero, producto, titulo FROM catalogo_imagen where id='$id_img'";
		if($this->execute($sql)){
			list($id_pri,$fichero, $producto, $titulo)=$this->fetchRow();
		}else{
			$this->mostrarMensaje($this->getMensaje("[016]","error"));
		}
	
		$rutafoto="../archivos/".$fichero;
		if (file_exists($rutafoto)){
			if(!unlink($rutafoto)){
				$this->mostrarMensaje($this->getMensaje("[200]","error")." ".$rutafoto);
				
			}else{
				$sql="delete FROM catalogo_imagen where id = '$id_img'";
				if($this->execute($sql)){
					$msg="Imagen principal eliminada con �xito!";	
				}else{
					$this->mostrarMensaje($this->getMensaje("[016]","error"));					
				}
			}
		}else{
			$this->mostrarMensaje($this->getMensaje("[207]","error"));	
			$sql="delete FROM catalogo_imagen where id = '$id_img'";
			if($this->execute($sql)){
					$msg="Imagen principal eliminada con �xito!";	
			}else{
					$this->mostrarMensaje($this->getMensaje("[016]","error"));					
			}
		}
		
		$sql="select id, fichero FROM catalogo_imagen where producto='$producto' and titulo='$titulo' and tipo like '%categoria%'";

		if($this->execute($sql)){
				list($id_sec, $fichero)=$this->fetchRow();
		}else{
				$this->mostrarMensaje($this->getMensaje("[016]","error"));
		}
	
		$rutafoto="../archivos/".$fichero;
		if (file_exists($rutafoto)){
			if(!unlink($rutafoto)){
				$this->mostrarMensaje($this->getMensaje("[200]","error")." ".$rutafoto);
			}else{
				$sql="delete FROM catalogo_imagen where id = '$id_sec'";
				if($this->execute($sql)){
					$this->mostrarMensaje($this->getMensaje("[261]","confirmacion"));
				}else{
					$this->mostrarMensaje($this->getMensaje("[016]","error"));				
				}
			}
		}else{
				$this->mostrarMensaje($this->getMensaje("[207]","error"));	
		}
		return true;
	}

	function obtenerImagenLogo($id, $w='', $h='', $princ=true)
	{
		$sql="SELECT id,tipo,titulo,fichero FROM catalogo_imagen WHERE producto='$id' and tipo like '%categoria%' and titulo  like '%logo%' ORDER BY titulo";
		if(!$w)$w=428;
		if(!$h)$h=340;
		$imag='';
		if($this->execute($sql))
		{

			$i=1;
			
			while(list($id,$tipo,$titulo,$fichero)=$this->fetchRow())
			{
				
				if($princ == true)
				{
					if(eregi("categoria-pri",$tipo)==1)
 					$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
				}else
				{
 					$imag = '<img src="'.$this->dirSetup.'archivos/'.$fichero.'" width="'.$w.'" height="'.$h.'" border="0">';
				}		
				break;							
			}
		}						
		if($info==true)
		{
			$array = array();
			$array[] = $this->dirSetup.'archivos/'.$fichero;
			$array[] = $imag;
			return $array;
		}
		return $imag;
	}

	function info_producto($id_pro){
		$sql = "SELECT referencia,nombre,descripcion,valor,estado,estado_oferta,valor_oferta,fecha_fin FROM catalogo_producto WHERE id='$id_pro'";
	
		if($this->execute($sql)){
			if(list($info['referencia'],$info['nombre'],$info['descripcion'],$info['valor'],$info['estado'],$info['estado_oferta'],$info['valor_oferta'],$info['fecha_fin'])=$this->fetchRow()){
				return $info;
			}
		}else{
			echo "�Impossible to consult the database!";
		}
	}

	function img_producto_panel_aplicaciones($id_pro)
	{
		$parametros = new Parametros();
		$proporcion=$parametros->getAncho()/$parametros->getAlto();
		$anchoSec=265;
		$altoSec=$anchoSec/$proporcion;
	
		$index=0;
		$sql = "SELECT fichero FROM catalogo_imagen WHERE producto='$id_pro' ";
		if($this->execute($sql)){	
			while(list($fichero)=$this->fetchRow()){
				$imagenes[$index]=$this->dirSetup.'/archivos/'.$fichero;
				$index++;
			}
		}else{
			echo "<scrip>alert('�Impossible to consult the database!');</script>";
		}
		if($index == 0)$imagenes[]=$this->dirSetup.'/archivos/producto.gif';
		echo '<TABLE border="0" cellspacing="0" cellpadding="0"><TR><TD><form name="Oneslideform">';
		echo '<DIV align="center"><TABLE width="'.$anchoSec.'" border="1" cellspacing="0" cellpadding="4" bordercolor="#999999">';
		echo '<TR><TD bgcolor="#330099"></TD></TR><TR><TD bgcolor="#FFFFFF">';
		echo '<DIV align="center"><A href="javascript:Onetransport()"><IMG src="'.$imagenes[0].'" width="'.$anchoSec.'" height="'.$altoSec.'" name="Oneshow" border="0"></A></DIV>';
		echo '</TD></TR><TR><TD bgcolor="#e0e0e0"><DIV align="center"><SELECT class="listado" name="Oneslide" onChange="Onechange();">';
		for($i=0;$i<$index;$i++)
		{
			if($i==0)
				echo '<OPTION value="'.$imagenes[$i].'"  selected>Imagen '.($i+1).'</OPTION>';
			else	
				echo '<OPTION value="'.$imagenes[$i].'">Imagen '.($i+1).'</OPTION>';
		}		
		echo '</SELECT></TD></TR><TR><TD bgcolor="#e0e0e0"><DIV align="center">';
		echo '<img src="aplicaciones/admon/catalogo/img/atras1.gif" title="Atras" onClick="Oneprevious();">&nbsp;&nbsp;&nbsp;&nbsp;';
		echo '<INPUT name="Oneslidebutton" type=button class="botones" title="AutoPlay" onClick="Oneap(this.value);" value="Play" style="vertical-align:top ">&nbsp;&nbsp;&nbsp;&nbsp;';
		echo '<img src="aplicaciones/admon/catalogo/img/adelante1.gif" title="Adelante" onClick="Onenext();">';
		echo '</DIV></TD></TR></TABLE></DIV></form></TD></TR></TABLE>';
	}


	function buscarTodasSubCategorias($id, &$array)
	{
		$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = $id order by id";
		$array2 = $this->consultarCampos($sql, "buscarTodasSubCategorias($id, $array)");
		if($array2 && count($array2)>0)
		{
			$i = 0;
			foreach($array2 as $cat)
			{ 			
				$this->buscarTodasSubCategorias($cat[0], $array);
				$i++;
			}
			$array = array_merge($array, $array2);
		}

	}
	function obtenerSubcategorias($id, $prin=false)
	{
		$all_categorias = array();
		if($prin == true)
		{
			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE id = $id";
			$cat_princ = $this->consultarCampos($sql,"productoCategoria($id)" );
			$cat = $cat_princ[0];
			$all_categorias[] = $cat;
		}
		$this->buscarTodasSubCategorias($id, $all_categorias);
		return $all_categorias;
	}

	function obtenerProductosCategoria($id, $estado_producto='destacado', $num=2)
	{
		$sql = "SELECT id, nombre, permiso, descripcion, referencia  FROM catalogo_producto WHERE categoria = $id and tipo='p' and estado like '%$estado_producto%' order by nombre limit 0, $num";
		$prods = $this->consultarCampos($sql,"obtenerProductosCategoria($id, $estado_producto)" );
		if($prods && count($prods)>0)
		{
			return $prods;
		}else
		{
			return NULL;
		}
	}

	/*
		Obtiene un producto con estado dado por '$estado_producto' de la categoria con identificador '$id'
	*/
	function productoCategoria($id, $estado_producto='destacado', $num=2)
	{
		$all_categorias = $this->obtenerSubcategorias($id, true);

		$prods2 = array();
		$i = 0;
		$total_prods = 0;
		foreach($all_categorias as $categ)
		{
			
			$prods = $this->obtenerProductosCategoria($categ['id'], $estado_producto, $num);
			
			if($prods && count($prods) > 0)
			{ 
				$total_prods += count($prods);
				$prods2 = array_merge($prods2, $prods);
				$i++;
				if($total_prods >= $num)break;
			}
		}
		if($i > 0)return $prods2;
		return NULL;
	}

	/*
		retorna un array con los identificadores de la categorias
		ej: [2|9|11], corresponde a los 3 niveles de profundidad
			[2|9], corresponde a los 2 primeros niveles de profundidad
			[2], corresponde al primer nivel de profundidad
	*/
	function obtenerJerarquiaDeCategorias($id_pro)
	{
		$cats = array();
		$nivel = 0;
		$sql = "SELECT categoria  FROM catalogo_producto WHERE id = $id_pro and tipo='p'";
		$cat3 = $this->consultarCampo($sql, "obtenerJerarquiaDeCategorias($id_pro)");
		if($cat3)
		{
			$nivel++;
			$sql = "SELECT parent FROM catalogo_categoria WHERE id = $cat3";
			$cat2 = $this->consultarCampo($sql, "obtenerJerarquiaDeCategorias($id_pro)");

			if($cat2)
			{
				$nivel++;
				$sql = "SELECT parent FROM catalogo_categoria WHERE id = $cat2";
				$cat1 = $this->consultarCampo($sql, "obtenerJerarquiaDeCategorias($id_pro)");
				if($cat1)
				{
					$cats[0] = $cat1;
					$cats[1] = $cat2;
					$cats[2] = $cat3;
					return $cats;
				}
				$cats[0] = $cat2;
				$cats[1] = $cat3;
				return $cats;
			}
			$cats[0] = $cat3;
			return $cats;
		}
		return NULL;
	}

	
	function mostrarSubcategorias($idt,$nivel){
		$db2 = new Componente();
		$sql2 = "SELECT id,nombre,nivel FROM catalogo_categoria WHERE parent = $idt";
		if($db2->execute($sql2)){
			while(list($id_parent,$nombre,$nivel)=$db2->fetchRow()){
				for($g=0;$g<$nivel;$g++){$separa .= '&nbsp;&nbsp;'; }
				echo '<option value="'.$id_parent.'">'.$separa.'-'.$nombre.'</option>';
				$this->mostrarSubcategorias($id_parent,1);
			}
		}
	
	}



	function mostrarCategorias(){
		$parametros = new parametro();
		$cant = $parametros->getNumSub();
		$sql = "SELECT id,nombre FROM catalogo_categoria WHERE tipo like 'categoria'";
		if($this->execute($sql)){	
			while(list($id,$nombre)=$this->fetchRow()){
				echo '<option value="'.$id.'">'.$nombre.'</option>';
				$this->mostrarSubcategorias($id,1);
			}
		}	
	}

	function obtenerNombresDeJerarquiaDeCategorias($id_pro)
	{
		$cats = array();
		$nivel = 0;
		$sql = "SELECT categoria  FROM catalogo_producto WHERE id = $id_pro and tipo='p'";
		$cat3 = $this->consultarCampo($sql, "obtenerJerarquiaDeCategorias($id_pro)");
		
		if($cat3)
		{
			$nombre_cat_ = $this->getNombreCategoria($cat3);
			$nivel++;
			$sql = "SELECT parent, nombre FROM catalogo_categoria WHERE id = $cat3";
			$cat22 = $this->consultarCampos($sql, "obtenerJerarquiaDeCategorias($id_pro)");

			if($cat22)
			{
				$cat2 = $cat22[0];
				$nivel++;
				$sql = "SELECT parent, nombre FROM catalogo_categoria WHERE id = ".$cat2['parent']."";
				$cat11 = $this->consultarCampos($sql, "obtenerJerarquiaDeCategorias($id_pro)");
				if($cat11)
				{
					$cat1 = $cat11[0];
					$cats[0] = $cat1['nombre'];
					$cats[1] = $cat2['nombre'];
					$cats[2] = $nombre_cat_;
					return $cats;
				}
				$cats[0] =  $cat2['nombre'];
				$cats[1] = $nombre_cat_;
				return $cats;
			}
			$cats[0] = $nombre_cat_;
			return $cats;
		}
		return NULL;
	}


	function productosPorCategoriaWeb($id=NULL, $estado_producto='destacado', $option_navs='', $ahref='', $w='', $h='', $num_pag=1, $n_items=2, $ids='', $nivel=1, $numProdsPorCate=2, $url=false)
	{
		
		$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent = $id order by id";
		if(!$id)
		{
			$sql = "SELECT id, nombre, permiso FROM catalogo_categoria WHERE parent is NULL  order by id";
		}

		$array2 = $this->consultarCampos($sql, "productosPorCategoriaWeb($id, $estado_producto)");
		$resultados = array();
		$numero_productos = 0;
		$res = 0;

		$inicio = ($num_pag -1)*$n_items;

		if($array2 && count($array2)>0)
		{
			foreach($array2 as $cat)
			{ 			
				$prs = $this->productoCategoria($cat['id'], $estado_producto, $numProdsPorCate);
				if($prs && count($prs) > 0)
				{ 
					$res += count($prs);
					$num_prods_cate = 0;
					foreach($prs as $p)
					{	
						if($inicio <= $numero_productos)
						{ //echo "($numero_productos-$inicio) >= $n_items)";
							if(($numero_productos-$inicio) >= $n_items || $num_prods_cate >= $numProdsPorCate)break;
							$imagen=$this->mostrarImagenesProductoWeb($p['id'], false, $w, $h, false, $url);
							$p['imagen'] = $imagen;
							$id_cats = $this->obtenerJerarquiaDeCategorias($p['id']);
							$image_ref = '<a href="'.$ahref.'?id='.$id_cats[0].'&ids='.$id_cats[1].'&idss='.$id_cats[2].'&id_pro='.$p['id'].'">'.$p['imagen'].'</a>';
							
							$p['ahref'] = $image_ref;
							$resultados[] = $p;
							$num_prods_cate++;
						}
						$numero_productos++;
					}
					if(($numero_productos-$inicio) >= $n_items)break;
				}
				
			}
		}

		$id = $ids['id'];
		$ids = $ids['ids'];
		$idss = $ids['idss'];
	
		$final = ceil($res/$n_items);
		if($final == 0)$final=1;
		$atras = 1;
		if( ($num_pag-1) >= 1) $atras = ($num_pag-1);
	
		$sig = $final;
		if(($num_pag+1) <= $final)$sig = ($num_pag+1);
	 
		
		if($res>$n_items)
		{
			if($option_navs)
			{
				$nav = '<table border="0"  cellspacing="0" cellpadding="0"><tr>';
				if($option_navs['inicio'] == true)
				{
				$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. '1' .'" border="0"><img src="'.$option_navs['inicio_image'].'" border="0"></a></td>';
				}
				if($option_navs['atras'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. ($atras) .'"><img src="'.$option_navs['atras_image'].'"  border="0"></a></td>';
				}
				if($option_navs['pag'] == true)
				{
					$nav .= '<td class="algo"><img src="'.$option_navs['pag_image'].'" width="59" height="14"></td>';
					//$nav .= '<td class="algo">pag '.$num_pag.'</td>';
				}else
				{
					$nav .= '<td class="algo">&nbsp;</td>';
				}

				if($option_navs['sig'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. ($sig) .'"><img src="'.$option_navs['sig_image'].'"  border="0"></a></td>';
				}
				if($option_navs['final'] == true)
				{
					$nav .= '<td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='.$final.'"><img src="'.$option_navs['final_image'].'"  border="0"></a></td>';
				}
				$nav .= '</tr></table>';
			}else
			{
				$nav = '<table><tr><td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. '1' .'" border="0">'.$images_nav['inicio'].'</a></td><td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. ($atras) .'">'.$images_nav['atras'].'</a></td><td class="algo">pag '.$num_pag2.'</td><td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='. ($sig) .'">'.$images_nav['sig'].'</a></td><td><a href="'.$option_navs['href'].'nivel='.$nivel.'&id='.$id.'&ids='.$ids.'&idss='.$idss.'&num_pag2='.$final.'">'.$images_nav['final'].'</a></td></tr></table>';
			}
			$im_links['nav'] = $nav;
		}else
		{
			$nav = '<table border="0"  cellspacing="0" cellpadding="0"><tr>';
			$nav .= '<td width="49" height="14"><img src="images/lf_B_previous.jpg" width="19" height="14"></td>
              <td width="59"><img src="images/lf_B_vermas.jpg" width="59" height="14"></td>
              <td width="19"><img src="images/lf_B_next.jpg" width="19" height="14"></td>';
			$nav .= '</tr></table>';
			$im_links['nav'] = $nav;
		}

		$resultados['nav'] = $nav;
		return $resultados;

	}

	function numeroProductosCategoria($id)
	{
		$sql = "SELECT count(*)  FROM catalogo_producto WHERE categoria = $id and tipo='p'";
		$num = $this->consultarCampo($sql, "numeroProductosCategoria($id)");
		if($num) return $num;
		return 0;
	}

	function numeroMaximoDeSubcategoriasCreado($subCat = false)
	{
		if($subCat == true)
		{
		$sql = "SELECT  count( *) FROM catalogo_categoria WHERE parent is not NULL group by parent";
		}else
		{
		$sql = "SELECT  count( *) FROM catalogo_categoria WHERE parent is NULL ";
		}
		$array = $this->consultarCampos($sql, "numeroMaximoDeSubcategoriasCreado()");
		$max = 0;
		if($array && count($array)>0)
		{
			foreach($array as $a)
			{
				if($a[0] > $max)
					$max = $a[0];
			}
		}
		return $max;
	}

	function numeroMaximoDeProductosPorCategoriaCreado()
	{

		$sql = "SELECT count(*) FROM catalogo_producto WHERE 1 group by categoria";
		$array = $this->consultarCampos($sql, "numeroMaximoDeProductosPorCategoriaCreado()");
		$max = 0;
		if($array && count($array)>0)
		{
			foreach($array as $a)
			{
				if($a[0] > $max)
					$max = $a[0];
			}
		}
		return $max;
	}

	function numeroSubCategoriasCategoria($id = '')
	{
		$sql = "SELECT count(*) FROM catalogo_categoria WHERE parent = $id";
		if(!$id)
		{
			$sql = "SELECT count(*) FROM catalogo_categoria WHERE parent is NULL";
		}
		
		$num = $this->consultarCampo($sql, "numeroSubCategoriasCategoria($id)");
		if($num) return $num;
		return 0;
	}

	function numeroImagenesProducto($id_pro)
	{
		$sql = "SELECT count(*) FROM catalogo_imagen WHERE producto = $id_pro and tipo = 'principal' ";
		$num = $this->consultarCampo($sql, "numeroImagenesProducto($id_pro)");
		if($num) return $num;
		return 0;
	}

	function numeroCamposProducto($id_pro)
	{
		$sql = "SELECT count(*) FROM catalogo_campo WHERE producto = $id_pro and tipo = 'p' ";
		$num = $this->consultarCampo($sql, "numeroCamposProducto($id_pro)");
		if($num) return $num;
		return 0;
	}

	function usuarioActivo($id_u='', $not)
	{
		if($id_u)
		{
			$sql = "select * from vinculo_web where usuario_web = $id_u and aplicacion = 12";
			$vincs = $this->consultarCampos($sql, "usuarioActivo($id_u)");
			if($vincs && count($vincs) > 0)
			{
				$vin = $vincs[0];
				if($vin['estado'] != 'activo')
				{
					if(!$not)$this->mostrarMensaje($this->getMensaje("[249]","confirmacion"));
					return false;
				}
				return true;
			}			
		}
		return false;
	}
	
	
	function showSolutions($id_categoria,$carritoData){
		$db = new DBManager('MySql');
		$db->connect();
		$db2 = new DBManager('MySql');
		$db2->connect();
		
		
		if ($id_categoria == 1){
			//Obtengo nombre de la categoria
			$sql_namecate = "SELECT nombre FROM catalogo_categoria WHERE id = $id_categoria";
			$this->execute($sql_namecate);
			list($categoria) = $this->fetchRow();
			$categoria = strtoupper($categoria);
		
			//Muestra Migratios Solutions con la estructura dada
			$sql_1 = "SELECT id,nombre,descripcion FROM catalogo_categoria WHERE parent=$id_categoria AND tipo='subcategoria' order by(nombre) asc";
			if ($this->execute($sql_1)){
				if ($this->numRows() > 0){
					echo '<table width="100%" border="0" bgcolor="#DBECF7" class="tbleoutlinetable">';
					echo '<tr><td colspan="2" class="style26" align="center">'.$categoria.'</td></tr> <tr><td colspan="2">&nbsp;</td></tr>';
					while (list($id_cat_a,$nombre,$descripcion)=$this->fetchRow()){
						$descripcion = $this->utileria->parseDB2Html($descripcion);
						echo '<tr><td colspan="2" align="center" valign="top" class="style26"> <a href="catalogue.php?id_cat='.$id_cat_a.'"> '.$nombre.'</a></td></tr>';
					} // While_1
					echo '</table>';
				}
			}else{
				echo "No se ejecuto SQL_1: ".$this->getException();
			}// sql_1
		}else{
			if ($id_categoria == 2){
				//Obtengo nombre de la categoria
				$sql_namecate = "SELECT nombre FROM catalogo_categoria WHERE id = $id_categoria";
				$this->execute($sql_namecate);
				list($categoria) = $this->fetchRow();
				$categoria = strtoupper($categoria);
		
				//Muestra Migratios Solutions con la estructura dada
				$sql_1 = "SELECT id,nombre,descripcion FROM catalogo_categoria WHERE parent=$id_categoria AND tipo='subcategoria' order by(nombre) asc";
				if ($this->execute($sql_1)){
					if ($this->numRows() > 0){
						echo '<table width="100%" border="0" bgcolor="#DBECF7" class="tbleoutlinetable">';
						echo '<tr><td colspan="2" class="style26" align="center">'.$categoria.'</td></tr> <tr><td colspan="2">&nbsp;</td></tr>';
						while (list($id_cat_a,$nombre,$descripcion)=$this->fetchRow()){
							$descripcion = $this->utileria->parseDB2Html($descripcion);
							echo '<tr><td colspan="2" align="center" valign="top" class="style26"> <a href="catalogue.php?id_cat='.$id_cat_a.'"> '.$nombre.'</a></td></tr>';
						} // While_1
						echo '</table>';
					}
				}else{
					echo "No se ejecuto SQL_1: ".$this->getException();
				}// sql_1
			}else{
				//Muestra los productos de una categoria en especial, sin subcarpetas
				$this->show_productos_lineal($id_categoria,$carritoData);
			}
		}
	}
	

	function showSolutionsOld($id_categoria,$carritoData){
		$db = new DBManager('MySql');
		$db->connect();
		$db2 = new DBManager('MySql');
		$db2->connect();
		
		
		if ($id_categoria == 1){
			//Obtengo nombre de la categoria
			$sql_namecate = "SELECT nombre FROM catalogo_categoria WHERE id = $id_categoria";
			$this->execute($sql_namecate);
			list($categoria) = $this->fetchRow();
			$categoria = strtoupper($categoria);
		
			//Muestra Migratios Solutions con la estructura dada
			$sql_1 = "SELECT id,nombre,descripcion FROM catalogo_categoria WHERE parent=$id_categoria AND tipo='subcategoria' order by(nombre) asc";
			if ($this->execute($sql_1)){
				if ($this->numRows() > 0){
					echo '<table width="100%" border="0" bgcolor="#DBECF7" class="tbleoutlinetable">';
					echo '<tr><td colspan="2" class="style26" align="center">'.$categoria.'</td></tr> <tr><td colspan="2">&nbsp;</td></tr>';
					while (list($id_cat_a,$nombre,$descripcion)=$this->fetchRow()){
						$descripcion = $this->utileria->parseDB2Html($descripcion);
						echo '<tr><td colspan="2" align="center" valign="top" class="style26"> <a href="catalogue.php?id_cat='.$id_cat_a.'"> '.$nombre.'</a></td></tr>';
					} // While_1
					echo '</table>';
				}
			}else{
				echo "No se ejecuto SQL_1: ".$this->getException();
			}// sql_1
		}else{
			//Muestra los productos de una categoria en especial, sin subcarpetas
			$this->show_productos_lineal($id_categoria,$carritoData);
		}
	}
	

	function showSolutionsOld1($id_categoria,$carritoData){
		$db = new DBManager('MySql');
		$db->connect();
		$db2 = new DBManager('MySql');
		$db2->connect();
		
		
		//Obtengo nombre de la categoria
		$sql_namecate = "SELECT nombre FROM catalogo_categoria WHERE id = $id_categoria";
		$this->execute($sql_namecate);
		list($categoria) = $this->fetchRow();
		$categoria = strtoupper($categoria);
		
		//Muestra Migratios Solutions con la estructura dada
		$sql_1 = "SELECT id,nombre,descripcion FROM catalogo_categoria WHERE parent=$id_categoria AND tipo='subcategoria' order by(nombre) asc";
		if ($this->execute($sql_1)){
			if ($this->numRows() > 0){
				echo '<table width="100%" border="0" bgcolor="#DBECF7" class="tbleoutlinetable">';
				echo '<tr><td colspan="2" class="style26" align="center">'.$categoria.'</td></tr> <tr><td colspan="2">&nbsp;</td></tr>';
				while (list($id_cat_a,$nombre,$descripcion)=$this->fetchRow()){
					$descripcion = $this->utileria->parseDB2Html($descripcion);
					echo '<tr><td colspan="2" align="center" valign="top" class="style26"> <a href="catalogue.php?id_cat='.$id_cat_a.'"> '.$nombre.'</a></td></tr>';
				} // While_1
				echo '</table>';
			}
		}else{
			echo "No se ejecuto SQL_1: ".$this->getException();
		}// sql_1
	}
	

	function getArechivosProductosXCategoria($id_producto){
		$ruta = './aplicaciones/admon/catalogo/archivos/';
		$db_c = new DBManager('MySql');
		$db_c->connect();
	
		$db_f = new DBManager('MySql');
		$db_f->connect();
		
		$sql_files = "SELECT id,titulo,fichero FROM catalogo_archivos WHERE producto = $id_producto";
		if ($db_f->execute($sql_files)){
			if ($db_f->numRows() > 0){
				while (list($id_archivo,$titulo,$archivo)=$db_f->fetchRow()){	
					$cadena .= '<br><a href="download_info.php?id_archivo='.$id_archivo.'" target="_blank">DownLoad: '.$titulo.'</a>';
				}
				return $cadena;
			}
		}
	}	
	
	
	function show_productos_lineal($id_categoria,$carritoData){
		$db = new DBManager('MySql');
		$db->connect();
		$db2 = new DBManager('MySql');
		$db2->connect();
		
		$sql_namecate = "SELECT nombre FROM catalogo_categoria WHERE id = $id_categoria";
		$this->execute($sql_namecate);
		list($categoria) = $this->fetchRow();
		$categoria = strtoupper($categoria);

		$sql_prd = "SELECT id, nombre, referencia, valor, descripcion, tipo, parent FROM catalogo_producto WHERE categoria=$id_categoria AND tipo='p' ORDER BY (referencia) asc";
		if ($db2->execute($sql_prd)){
			if ($db2->numRows() > 0){
				echo '<table border="1" cellpadding="0" cellspacing="0" bordercolor="#DBECF7" bgcolor="#FFFFFF">';
				echo '<tr><td colspan="5" class="style26">'.$categoria.'</td><tr>';
				echo '<tr bgcolor="#DBECF7"> <td>P/No.</td> <td>Product Name</td> <td>Description</td> <td>Price</td> <td>Buy</td>  </tr>';
				while (list($id_prd,$nombre_producto,$referencia,$precio,$descripcion,$tipo,$parent)=$db2->fetchRow()){
					if(empty($parent)){
						$parent=0;
					}
					$precio = '$ '.number_format($precio,2,'.',',');
					$descripcion = $this->utileria->parseDB2Html($descripcion);
					echo '<tr>
							  <td width="20%" height="93" valign="middle" class="maintxt"><span class="style28"><span class="style32">'.$referencia.'</span></span></td>							  
							  <td width="30%" height="93" align="center" valign="middle" class="maintxt"><span class="style25">'.$nombre_producto.'</span></td>
							  <td width="35%" class="maintxt" align="left">'.$descripcion.$this->getArechivosProductosXCategoria($id_prd).'</td>
							  <td width="15%" valign="middle" class="maintxt">'.$precio.'</td>';
								if (!$this->productoAgregado($carritoData,$id_prd)){ //No lo ha metido al carrito
									echo '<td width="20%" height="93" valign="middle" class="maintxt"><input type="submit" name="Submit" value="Add to Cart" onclick=MM_openBrWindow("fnc/main.php?tarea=agregarItem&id_pro='.$id_prd.'&cantidad=1&tipo='.$tipo.'&parent='.$parent.'","addP","width=10,height=10")></td>';
								}else{
									echo '<td width="20%" height="93" valign="middle" class="maintxt"> <img src="images/chulo.gif"> <br> Added to Cart</td>';							
								}
					echo 	  '</tr>';
				}//While Prd
				echo '</table>';
			}else{
				echo "Sorry, there aren't products to show.";
			}
		}else{
			echo "No se ejecuto SQL_PRD: ".$db2->getException();
		}//sql_pdr
	}

	function listaCategoriasNivel_1($categoria_producto){
	
		$sql = "SELECT parent FROM catalogo_categoria WHERE id=$categoria_producto";
		if ($this->execute($sql)){
			if ($this->numRows() > 0){
				list($parent)=$this->fetchRow();
			}
		}
		
//		if (!empty($parent)){
			$sql = "SELECT id,nombre FROM catalogo_categoria WHERE tipo='subcategoria' AND nivel=1";
			if ($this->execute($sql)){
				if ($this->numRows() > 0){
					echo '<select name="subcategoria" class="texto1">';
					while (list($id_cat,$nombre_cat)=$this->fetchRow()){
						if ($id_cat==$categoria_producto){
							echo '<option value="'.$id_cat.'" selected> '.$nombre_cat.' </option>';
						}else{
							echo '<option value="'.$id_cat.'"> '.$nombre_cat.' </option>';
						}
					}
					echo '</select>';
				}
			}
		
//		}
		
	}
	

	function getListadoCategoriasNivel_0($categoria_producto){
			$sql = "SELECT id,nombre FROM catalogo_categoria WHERE nivel=0";
			if ($this->execute($sql)){
				if ($this->numRows() > 0){
					echo '<select name="categoria" id="categoria" class="texto1"  onChange="cargaSubcategorias();">';
					while (list($id_cat,$nombre_cat)=$this->fetchRow()){
						if ($id_cat==$categoria_producto){
							echo '<option value="'.$id_cat.'" selected> '.$nombre_cat.' </option>';
						}else{
							echo '<option value="'.$id_cat.'"> '.$nombre_cat.' </option>';
						}
					}
					echo '</select>';
				}
			}
	}

	function getListadoSubCategorias($id_categoria){
			$sql = "SELECT id,nombre FROM catalogo_categoria WHERE parent=$id_categoria";
			if ($this->execute($sql)){
				if ($this->numRows() > 0){
					echo '<select name="subcategoria" id="subcategoria" class="texto1" >';
					while (list($id_cat,$nombre_cat)=$this->fetchRow()){
						if ($id_cat==$id_categoria){
							echo '<option value="'.$id_cat.'" selected> '.$nombre_cat.' </option>';
						}else{
							echo '<option value="'.$id_cat.'"> '.$nombre_cat.' </option>';
						}
					}
					echo '</select>';
				}else{
					$id_cat = false;
					echo '<select name="subcategoria" id="subcategoria" class="texto1" >';
					echo '<option value="'.$id_cat.'" selected> There are not Sub-categories </option>';						
					echo '</select>';
				}
			}
	}


	function getListadoSubCategoriasLoad($id_categoria,$id_subcategoria){
			$sql = "SELECT id,nombre FROM catalogo_categoria WHERE parent=$id_categoria";
			if ($this->execute($sql)){
				if ($this->numRows() > 0){
					echo '<select name="subcategoria" id="subcategoria" class="texto1" >';
					while (list($id_cat,$nombre_cat)=$this->fetchRow()){
						if ($id_cat==$id_subcategoria){
							echo '<option value="'.$id_cat.'" selected> '.$nombre_cat.' </option>';
						}else{
							echo '<option value="'.$id_cat.'"> '.$nombre_cat.' </option>';
						}
					}
					echo '</select>';
				}else{
					$id_cat = false;
					echo '<select name="subcategoria" id="subcategoria" class="texto1" >';
					echo '<option value="'.$id_cat.'" selected> There are not Sub-categories </option>';						
					echo '</select>';
				}
			}
	}
	
	
	function productoAgregado($prods,$id_producto){
		$i=0;
		while($prods2=$prods[$i]){
			$pr++;
			if ($id_producto == $prods2['id_pro']){
				return true;
			}
			$i++;
		}
		return false;
	}


}/* fin clase Catalogo */

?>

Anon7 - 2021