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/noticias/fnc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/logicswapweb/aplicaciones/admon/noticias/fnc/Archivo.php
<?php 
class Archivo extends Componente{

	/*constructor*/
	function Archivo()
	{
		$this->DBManager('MySQL');
		$this->connect();
	}
	
	/*cargar archivo*/
	function captureUpload($destDir,$nameCallback = false,$fieldName = '_upload',$maxFileSize = false)
	{
	   //make sure something is there
	   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:'');
		   }
	   }
		//$this->mostrarMensaje( $destDir.$file['name']);
	   //and now the big moment
	   if(!@copy($file['tmp_name'], $destDir.$file['name']))
		   return array(false,"Permiso denegado para copiar el archivo");
	   else
		   return array(true,$file['name']);
	} 
	
	/* modificar archivo*/
	function mod_archivo($titulo,$archivo,$file,$id_arc,$id_not)	
	{					
		$sql = "SELECT id FROM noticia_archivos WHERE noticia='$id_not' AND titulo='$titulo' AND id!='$id_arc'";
		$this->execute($sql);
		$cant=$this->numRows();
		if($cant==0){	
			
			$response;
			$rutafoto ="../archivos/".$file;
			if (file_exists($rutafoto)){
				if(!unlink($rutafoto)){
					$this->mostrarMensaje("Error: no se pudo borrar el archivo ".$file." del servidor \\nPermiso denegado");
				}
				list($success,$response) = $this->captureUpload('../archivos/',false,'archivo');						
				if(!$success){ 
					$this->mostrarMensaje("Error: ".$response);
				}else{
					$sql="update noticia_archivos set titulo='$titulo', fichero='$response' where id='$id_arc'";
				}
			}else{
				list($success,$response) = $this->captureUpload('../archivos/',false,'archivo');						
				if(!$success){ 
					$this->mostrarMensaje("Error: ".$response);
				}else{
					$sql="update archivo set titulo='$titulo', fichero='$response' where id='$id_arc'";
				}		
			}
			if($this->execute($sql)){
				$this->mostrarMensaje("Archivo modificado con �xito!");	
				return true;
			}else{
				$this->mostrarMensaje("�imposible consultar la base de datos!");	
			}
		}else{
			$this->mostrarMensaje("Ya existe un archivo con el mismo nombre. Especifique otro nombre de archivo.");
			
		}
		return false;
	}

	// 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;
		}
	}

	/* agregar archivo*/
	/*
		$titulo = id_producto
	*/
	function add_archivo($id_not, $titulo,$archivo)
	{		
		if($id_not)
		{
			$sql = "SELECT id FROM noticia_archivos WHERE noticia=$id_not and titulo like '$titulo'";
			$this->execute($sql);
			$cant=$this->numRows();	

			if($cant==0)
			{			
				$response;
				list($success,$response) = $this->captureUpload('../archivos/',false,'archivo');						
				if(!$success)
				{ 
						$this->mostrarMensaje("Error: ".$response);
						return false;
				}else
				{
						$sql="insert into noticia_archivos (noticia, titulo, fichero) values ('$id_not','$titulo','$response')";
						if($this->execute($sql))
						{
							$this->mostrarMensaje("Archivo adicionado con �xito!");
						}else
						{
							$this->mostrarMensaje("�Imposible consultar la base de datos!");
							return false;
						}
				}
			}else
			{
				$this->mostrarMensaje("Ya existe un archivo con este nombre!");
				return false;
			}
			
		}else
		{
			$this->mostrarMensaje("No existe el documento especificado!");
			return false;

		}
		return true;
	}
	
	/* eliminar archivo*/
	function eli_archivo($id_arc)
	{					
		$sql="select fichero from noticia_archivos where id='$id_arc'";
		$this->execute($sql);
		if(list($fichero)=$this->fetchRow())
		{
			//borro archivos
			$rutafoto="../archivos/".$fichero;
			if (file_exists($rutafoto)){
				if(!unlink($rutafoto)){
					$this->mostrarMensaje("Error: no se pudo borrar el archivo del servidor \\nPermiso denegado!");	
				}else{
				$sql="delete from noticia_archivos where id = '$id_arc'";
					if($this->execute($sql)){
						$this->mostrarMensaje("Archivo eliminado con �xito!");	
					}else{
						$this->mostrarMensaje("�imposible consultar la base de datos!!");					
					}
				}
			}else{
				$sql="delete from noticia_archivos where id = '$id_arc'";
				if($this->execute($sql)){
					$this->mostrarMensaje("Archivo eliminado con �xito!");	
				}else{
					$this->mostrarMensaje("�imposible consultar la base de datos!!");					
				}		
			}
		}else{
			$this->mostrarMensaje("�imposible consultar la base de datos!");		
		}
		return true;
	
	}
	function listarArchivos($id_not, $nun_pag=1, $limite=10)
	{
		$inicio = ($nun_pag -1)*$limite;
		$script = '<script>
					var t = new SortTable("t");
					t.AddColumn("Nombre","nowrap","left","");   
					t.AddColumn("File","nowrap","left","");   	
					t.AddColumn("Numero","","center","");';
		
		$sql = "SELECT id, titulo, fichero FROM noticia_archivos WHERE noticia = '$id_not' ORDER BY titulo limit $inicio, $limite";
		$this->execute($sql);
		if($this->numRows()>0){ 
			$i = 1;  $limite =10; $write=0;
			while ((list($id, $titulo, $fichero)=$this->fetchRow())) {
					if($i==1){ 
										
						$script .= 't.AddLine(\'<input type="hidden" name="mat" value="'.$id.'"><IMG src="../img/disket.gif" onClick="fncModificarArchivo('.$id.')" border="0"> &nbsp;<A onClick="fncModificarArchivo('.$id.')" class="texto1" > '.$titulo.' </A>\',\'<A onClick="fncModificarArchivo('.$id.')" style=" width: 150; font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:12px; font-weight:normal " > '.$fichero.' </A>\',\'<input type="radio" name="sel" value="'.$id.'" style=" border-width:0">\' ); ';           
						$script .= 't.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'.$i.'"\');';
						
					}else{						
						$script .= 't.AddLine(\'<input type="hidden" name="mat" value="'.$id.'"><IMG src="../img/disket.gif" onClick="fncModificarArchivo('.$id.')"  border="0"> &nbsp;<A onClick="fncModificarArchivo('.$id.')" style=" width: 150; font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:12px; font-weight:normal " > '.$titulo.' </A>\',\'<A onClick="fncModificarArchivo('.$id.')" style=" width: 150; font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:12px; font-weight:normal " > '.$fichero.' </A>\',\'<input type="radio" name="sel" value="'.$id.'" style=" border-width:0">\' );';            
						$script .= 't.AddLineProperties(\'align="center" onMouseOver="mOvr(this,\\\'#FAFF95\\\');" onMouseOut="mOut(this,\\\'#FFFFFF\\\')" id="tr_'.$i.'" \');';
						
					}
					$i++;  
			}
				
			$script .= 't.WriteRows();';
			 
		}else{
			$msg = "No hay Archivos Registrados";       
			
			$script .= 'document.write(\'<TR><TD colspan="3" align="center"><BR>Esta noticia no tiene ning&uacute;n archivo asociado.<BR>&nbsp;</TD></>\');';
		}
		$script .= '</script>';
		echo $script;
	}


	function numeroArchivos($id_not)
	{

		$sql = "SELECT count(*) FROM noticia_archivos WHERE  noticia = '$id_not'";
		$num = $this->consultarCampo($sql, "numeroArchivos($id_not)");
		if($num) return $num;
	
		return 0;
	}

}

?>

Anon7 - 2021