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/Categoria_old2.php
<?php 

class Categoria
{
	var $catalogo;

	function Categoria(&$catalg)
	{
		$this->catalogo = $catalg;
		$this->catalogo->Aplicacion();
	}

   function captureUpload($destDir,$nameCallback = false,$fieldName = '_upload',$maxFileSize = false){
   //make sure something is there
	$this->catalogo->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_producto($nivel,$nombre,$referencia,$valor,$titulo,$img_pri,$img_sec,$descripcion,$permiso,$id,$ids,$idss,$name_categoria,$name_subcategoria,$name_subcategorias,$estado,$estado_oferta,$valor_oferta,$ancho,$alto,$fecha_fin){
	$this->catalogo->setFiles(4);
	$this->catalogo->reactivarDB();
	$descripcion = $this->catalogo->utileria->parseInput2DB($descripcion);
	if($nivel==1){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$id' AND referencia='$referencia' and tipo='p'";
	}
	if($nivel==2){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$ids' AND referencia='$referencia' and tipo='p'";
	}
	if($nivel==3){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$idss' AND referencia='$referencia' and tipo='p'";
	}	

	$this->catalogo->execute($sql);
	$cant=$this->catalogo->numRows($cant);

	if($cant==0 || $referencia=="-1"){
	
		if($referencia=="-1")$referencia="humor";
		$response = NULL;
		if($nivel==1){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin) VALUES('$id','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin')";
		}
		if($nivel==2){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin) VALUES('$ids','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin')";
		}
		if($nivel==3){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin) VALUES('$idss','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin')";
		}
		if (!$this->catalogo->execute($sql)) {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
		} else {
			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->catalogo->mostrarMensaje($msg);
				}
				//sql para registrar fichero en la DB
				$producto = $this->catalogo->insertId();
				
				$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$producto','principal','$titulo','$response','$ancho','$alto')";
				
				if(!$this->catalogo->execute($sql2)){
					$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
				}else{
					//$msg.="Archivo ".$titulo." principal. Cargado en DB!";
				}
			}
		
			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->catalogo->mostrarMensaje($msg);
				}
				//sql para registrar fichero en la DB
				$tipo = $this->catalogo->insertId();
				$proporcion=$ancho/$alto;
				$ancho_sec=314;
				$alto_sec=$ancho_sec/$proporcion;
				$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$producto','$tipo','$titulo','$response','$ancho_sec','$alto_sec')";
				
				if(!$this->catalogo->execute($sql2)){
					$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
				}else{
					//$msg.="Archivo ".$titulo." reducida. Cargado en DB!";
				}
			}
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[254]","confirmacion"));			
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[255]","confirmacion"));
		echo "<script>window.open(\"../add_producto.php?nivel=$nivel&id=$id&ids=$ids&idss=$idss&name_categoria=$name_categoria&name_subcategoria=$name_subcategoria&name_subcategorias=$name_subcategorias&nombre=$nombre&referencia=$referencia&valor=$valor&estado=$estado&estado_oferta=$estado_oferta&valor_oferta=$valor_oferta&titulo=$titulo&img_pri=$img_pri&img_sec=$img_sec&descripcion=$descripcion&permiso=$permiso\",\"contenido\");</script>";
	}		
	echo "<script>window.open(\"../listar_categoria.php?nivel=$nivel&id=$id&ids=$ids&idss=$idss\",\"contenido\");</script>";
}

function add_SubProducto($nivel,$nombre,$referencia,$valor,$titulo,$img_pri,$img_sec,$descripcion,$permiso,$id,$ids,$idss,$name_categoria,$name_subcategoria,$name_subcategorias,$estado,$estado_oferta,$valor_oferta,$ancho,$alto,$fecha_fin, $parent){
	$this->catalogo->setFiles(4);
	$this->catalogo->reactivarDB();
	$descripcion = $this->catalogo->utileria->parseInput2DB($descripcion);
	if($nivel==1){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$id' AND referencia='$referencia' and tipo='s' and parent='$parent'";
	}
	if($nivel==2){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$ids' AND referencia='$referencia' and tipo='s' and parent='$parent'";
	}
	if($nivel==3){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$idss' AND referencia='$referencia' and tipo='s' and parent='$parent'";
	}	

	$this->catalogo->execute($sql);
	$cant=$this->catalogo->numRows();
	if($cant==0 || $referencia=="-1"){
	
		if($referencia=="-1")$referencia="humor";
		$response = NULL;
		if($nivel==1){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin, tipo, parent) VALUES('$id','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin', 's', '$parent')";
		}
		if($nivel==2){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin, tipo, parent) VALUES('$ids','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin', 's', '$parent')";
		}
		if($nivel==3){
			$sql = "INSERT into catalogo_producto (categoria,nombre,referencia,valor,estado,estado_oferta,valor_oferta,descripcion,permiso,fecha_fin, tipo, parent) VALUES('$idss','$nombre','$referencia','$valor','$estado','$estado_oferta','$valor_oferta','$descripcion','$permiso','$fecha_fin', 's', '$parent')";
		}
		if (!$this->catalogo->execute($sql)) {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
		} else {
			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->catalogo->mostrarMensaje($msg);
				}
				//sql para registrar fichero en la DB
				$producto = $this->catalogo->insertId();
				
				$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$producto','principal','$titulo','$response','$ancho','$alto')";
				
				if(!$this->catalogo->execute($sql2)){
					$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
				}else{
					//$msg.="Archivo ".$titulo." principal. Cargado en DB!";
				}
			}
		
			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->catalogo->mostrarMensaje($msg);
				}
				//sql para registrar fichero en la DB
				$tipo = $this->catalogo->insertId();
				$proporcion=$ancho/$alto;
				$ancho_sec=314;
				$alto_sec=$ancho_sec/$proporcion;
				$sql2 = "INSERT into catalogo_imagen (producto,tipo,titulo,fichero,ancho,alto) values('$producto','$tipo','$titulo','$response','$ancho_sec','$alto_sec')";
				
				if(!$this->catalogo->execute($sql2)){
					$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
				}else{
					//$msg.="Archivo ".$titulo." reducida. Cargado en DB!";
				}
			}
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[280]","confirmacion"));			
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[255]","confirmacion"));
		echo "<script>window.open(\"../add_producto.php?nivel=$nivel&id=$id&ids=$ids&idss=$idss&name_categoria=$name_categoria&name_subcategoria=$name_subcategoria&name_subcategorias=$name_subcategorias&nombre=$nombre&referencia=$referencia&valor=$valor&estado=$estado&estado_oferta=$estado_oferta&valor_oferta=$valor_oferta&titulo=$titulo&img_pri=$img_pri&img_sec=$img_sec&descripcion=$descripcion&permiso=$permiso\",\"contenido\");</script>";
	}		
	echo "<script>window.open(\"../listar_subproductos.php?nivel=$nivel&id=$id&ids=$ids&idss=$idss&id_pro=$parent\",\"contenido\");</script>";
}

/*modificar producto*/
function mod_sub_producto($nivel,$nombre,$referencia,$valor,$descripcion,$id_pro,$permiso,$id,$name_categoria,$ids,$name_subcategoria,$idss,$name_subcategorias,$estado,$estado_oferta,$valor_oferta,$fecha_fin){
	$this->catalogo->setFiles(4);
	$this->catalogo->reactivarDB();
	if($nivel==1){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria= '$id' AND referencia = '$referencia' AND id != '$id_pro' and tipo='s'";
		
	}elseif($nivel==2){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$ids' AND referencia='$referencia' AND id!='$id_pro' and tipo='s'";
	}elseif($nivel==3){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$idss' AND referencia='$referencia' AND id!='$id_pro' and tipo='s'";
	}else{
		$sql = "SELECT categoria FROM catalogo_producto WHERE id='$id_pro' and tipo='s'";
		$this->catalogo->execute($sql);
		list($categoria)=$this->catalogo->fetchRow();
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$categoria' AND referencia='$referencia' AND id!='$id_pro' and tipo='s'";		
	}
	$this->catalogo->execute($sql);
	$cant=$this->catalogo->numRows();
	$descripcion = $this->catalogo->utileria->parseInput2DB($descripcion);
	if($cant==0){	
		$sql = "update catalogo_producto SET nombre='$nombre',referencia='$referencia',valor='$valor',descripcion='$descripcion',permiso='$permiso',estado='$estado',estado_oferta='$estado_oferta',valor_oferta='$valor_oferta',fecha_fin='$fecha_fin' WHERE id = '$id_pro'";
		if (!$this->catalogo->execute($sql)) {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
		} else {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[256]","confirmacion"));
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[255]","confirmacion"));
		return false;
	}	
	return true;	
}

/*modificar producto*/
function mod_producto($nivel,$nombre,$referencia,$valor,$descripcion,$id_pro,$permiso,$id,$name_categoria,$ids,$name_subcategoria,$idss,$name_subcategorias,$estado,$estado_oferta,$valor_oferta,$fecha_fin,$subcategoria,$categoria){
	$this->catalogo->setFiles(4);
	$this->catalogo->reactivarDB();
	if($nivel==1){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$id' AND referencia='$referencia' AND id!='$id_pro' and tipo='p'";
	}elseif($nivel==2){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$ids' AND referencia='$referencia' AND id!='$id_pro' and tipo='p'";
	}elseif($nivel==3){
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$idss' AND referencia='$referencia' AND id!='$id_pro' and tipo='p'";
	}else{
		$sql = "SELECT categoria FROM catalogo_producto WHERE id='$id_pro' and tipo='p'";
		$this->catalogo->execute($sql);
		list($categoria)=$this->catalogo->fetchRow();
		$sql = "SELECT id FROM catalogo_producto WHERE categoria='$categoria' AND referencia='$referencia' AND id!='$id_pro' and tipo='p'";		
	}	
	$this->catalogo->execute($sql);
	$cant=$this->catalogo->numRows();
	$descripcion = $this->catalogo->utileria->parseInput2DB($descripcion);
	if($cant==0){	

		if ($subcategoria){
			$sql = "update catalogo_producto SET nombre='$nombre',referencia='$referencia',valor='$valor',descripcion='$descripcion',permiso='$permiso',estado='$estado',estado_oferta='$estado_oferta',valor_oferta='$valor_oferta',fecha_fin='$fecha_fin', categoria='$subcategoria' WHERE id = '$id_pro'";
		}else{
			$sql = "update catalogo_producto SET nombre='$nombre',referencia='$referencia',valor='$valor',descripcion='$descripcion',permiso='$permiso',estado='$estado',estado_oferta='$estado_oferta',valor_oferta='$valor_oferta',fecha_fin='$fecha_fin', categoria='$categoria' WHERE id = '$id_pro'";
		}
		if (!$this->catalogo->execute($sql)) {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
		} else {
			$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[256]","confirmacion"));
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[255]","confirmacion"));
		return false;
	}	
	return true;	
}

/*eliminar producto*/
function eli_producto($id_pro,$nivel=0,$id=0,$ids=0,$idss=0, $mostrar=0){
	$this->catalogo->setFiles(4);
	$this->catalogo->reactivarDB();
	///////
	$sql_P = "select tipo from catalogo_producto where id = ".$id_pro;
	$this->catalogo->execute($sql_P);
	$Dtipo=$this->catalogo->fetchRow();
	///////
	$sql = "select id from catalogo_producto where parent = ".$id_pro;
	$sub_prods = $this->catalogo->consultarCampos($sql, "eli_producto($id_pro,$nivel,$id,$ids,$idss, $mostrar)");
	/* pendiente, borrar subproductos*/
	$id_=$id;
	$db= new DBManager('MySQL');
	$db->connect();

	$sql1= "select id, fichero FROM catalogo_imagen where producto='$id_pro' and tipo not like '%categoria%'";
	$cant;
	if($this->catalogo->execute($sql1)){
		$cant = $this->catalogo->numRows();
		while(list($id, $fichero)=$this->catalogo->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();
						if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
					}else{
						$cant--;
					}
				}else{
					if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[200]","error"));
				}
			}else{
				if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[200]","error")." EL archivo ".$fichero." no existe!");
			}
		}
	}else{
		if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	}

	$sql1= "select id from catalogo_campo where producto='$id_pro' and tipo='p'";
	$cant;
	if($this->catalogo->execute($sql1)){
		$cant = $this->catalogo->numRows();
		while(list($id, $fichero)=$this->catalogo->fetchRow()){
			$sql = "delete from catalogo_campo where id = '$id'";
			if(!$db->execute($sql) ){
				$db->isDebuggerEnabled();
				$msg = $db->getException();
				if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
			}else{
				$cant--;
			}
		}
	}else{
		if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	}
	$sqlP = "DELETE FROM catalogo_producto WHERE parent = '$id_pro'";
	$this->catalogo->execute($sqlP);
	$sql = "DELETE FROM catalogo_producto WHERE id = '$id_pro'";
	if ( (!$this->catalogo->execute($sql))||($cant>0) ) {
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	} else {
		if($Dtipo[0]=='p'){
			if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[257]","confirmacion"));		
		}else{
			if($mostrar == 0)$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[281]","confirmacion"));	
		}
	}
}

/*eliminar promocion*/
function eli_promocion($id_pro){
	$this->catalogo->reactivarDB();
	$id_=$id;
	$db= new DBManager('MySQL');
	$db->connect();

	$sql1= "select id, fichero FROM catalogo_imagen where producto='$id_pro' and tipo not like '%categoria%'";
	$cant;
	if($this->catalogo->execute($sql1)){
		$cant = $this->catalogo->numRows();
		while(list($id, $fichero)=$this->catalogo->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->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
					}else{
						$cant--;
					}
				}else{
					$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[200]","error"));
				}
			}else{
				$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error")." EL archivo ".$fichero." no existe!");
			}
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	}

	$sql1= "select id from catalogo_campo where producto='$id_pro'";
	$cant;
	if($this->catalogo->execute($sql1)){
		$cant = $this->catalogo->numRows();
		while(list($id, $fichero)=$this->catalogo->fetchRow()){
			$sql = "delete from catalogo_campo where id = '$id'";
			if(!$db->execute($sql) ){
				$db->isDebuggerEnabled();
				$msg = $db->getException();
				$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
			}else{
				$cant--;
			}
		}
	}else{
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	}
	
	$sql = "DELETE FROM catalogo_producto WHERE id = '$id_pro'";
	if ( (!$this->catalogo->execute($sql))||($cant>0) ) {
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[016]","error"));
	} else {
		$this->catalogo->mostrarMensaje($this->catalogo->getMensaje("[257]","confirmacion"));
	}
	/*echo "<script>window.open(\"../l_productos.php?estado=promocion\",\"contenido\");</script>";	*/
}
}
?>

Anon7 - 2021