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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/logicswapweb/aplicaciones/admon/usuariosWeb/fnc/usuarioWeb_old3.php
<?php
/********************************************************
clase UsuarioWeb: 
			utiliza la interfas de BD para realizar 
			las necesidades propias de registro y 
			verificacion de Usuarios de el sitio web
*********************************************************/

class UsuarioWeb extends Aplicacion{

var $fecha_actual;

var $contacto = "[email protected]";
var $alias ="";
var $azul = "[email protected]";
var $sitio = "DemoWeb";
var $aplicacion = "Usuarios Web";
var $fileRegistro;
var $fileUpdateRegistro;
var $fileFullRegistro;
var $fileMsgAplicaciones;
var $dirSetup;
var $subDir;
var $valores;
var $frmContacto ="frmContacto.html";
var $frmRecomendacion ="frmRecomendacion.html";
var $util;

/*
funcion: 		UsuarioWeb (constructor)
descripcion: 	inicializa interfaz de conexion de DB y control de errores
*/
function UsuarioWeb($fU ="actRegistro.php" ,$fR="addRegistro.php",$fC="comRegistro.php",$subDir="/panel_aplicaciones/",$dirSetup="aplicaciones/admon/usuariosWeb/") {
	$this->Aplicacion();
	$this->fecha_actual = date('Y-m-d');
	$this->util=new Utileria();
	$this->sitio = $_SERVER['SERVER_NAME'];
	$this->subdir = $subDir;
	$this->dirSetup =$dirSetup;
	$this->fileRegistro= "http://".$_SERVER['SERVER_NAME'].$subDir.$fR;
	$this->fileUpdateRegistro= "http://".$_SERVER['SERVER_NAME'].$subDir.$fU;
	$this->fileFullRegistro= "http://".$_SERVER['SERVER_NAME'].$subDir.$fC;
	$this->fileMsgAplicaciones = "http://".$_SERVER['SERVER_NAME'].$subDir."msgAplicaciones.php";
}

/*
*funcion loadUsuario()
*descripcion carga los valores de un usario en el vector 
*			 pre: el usuario debe existir
*/
function loadUsuario($campo,$valor){
	$sql="select * from usuario_web where {$campo}='$valor'";
	if($this->execute($sql)){
		$out=$this->getMensaje("[159]","confirmacion");
		$this->setSalida(true,$out,"loadUsuario($campo,$valor)",$this->aplicacion);
		$this->valores = $this->fetchRow();
		return true;
	}else{
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"loadUsuario($campo,$valor)",$this->aplicacion);
		return false;
	}	
}
/*
FUNCION: 		sendMail
DESCRIPCION: 	envia e-mail 
*/
function sendMail($to, $from, $suject, $mensaje, $cc=false, $bcc=false, $desde=false){	
	if(empty($desde)){
		$desde = $this->getCliente();
		if($desde=="incunsultable" || $desde=="indefinido"){
			$desde = $from;
		}
	}
	$header    = "From: \"".$desde."\" <".$from.">\n";
	if(!empty($cc)){
		$header .= "Cc: ".$cc."\n";
	}
	if(!empty($bcc)){
		$header   .= "Bcc: ".$bcc."\n";
	}
	
	$header   .= "Return-path: ".$from."\n";
	$header   .= "Errors-To: ".$this->azul."\n"; 
	$header   .= "Reply-To: ".$from."\n";	
    $header   .= "MIME-Version: 1.0\n";
    $header   .= "Content-Type: text/html; charset=iso-8859-1\n";
    $header   .= "X-Priority: 1\n";
    $header   .= "X-Mailer: PHP / ".phpversion()."\n";
  	if(mail($to, $suject, $mensaje , $header)){
		$this->setSalida(true,$this->getMensaje("[058]","confirmacion"),"sendMail($to)",$this->aplicacion);
		return true;
	}else{
		$this->setSalida(false,$this->getMensaje("[019]","error"),"sendMail($to)",$this->aplicacion);	
		return false;
	}
}  

/*
*funcion sendContacto()
*descripcion envia un correo electronico al administrador del sitio
*			 con la informacion del formulario de contacto.php
*/
function sendContacto($nombre, $email, $asunto, $ciudad, $telefono, $mensaje, $to, $cc, $bcc, $sujeto,$plantilla){
	$file = @file_get_contents($plantilla);
	if(!$file){	
		$this->setSalida(false,$this->getMensaje("[068]", "error"), "sendContacto()","sitio web");
		return false;
	}else{
		$nota = "";
		$mensaje1 = str_replace("[-sitio-]",$this->sitio,$file);
		$mensaje1 = str_replace("[-name-]",$nombre,$mensaje1);
		$mensaje1 = str_replace("[-email-]",$email,$mensaje1);
		$mensaje1 = str_replace("[-ciudad-]",$ciudad,$mensaje1);
		$mensaje1 = str_replace("[-asunto-]",$asunto,$mensaje1);
		$mensaje1 = str_replace("[-telefono-]",$telefono,$mensaje1);
		$mensaje1 = str_replace("[-mensaje-]",$mensaje,$mensaje1);
		$mensaje1 = str_replace("[-nota-]",$nota,$mensaje1);
		return $this->sendMail($to, $email, $sujeto, $mensaje1, $cc, $bcc, $nombre);
	}
}//end enviar contacto

/*
*funcion sendRecomendacion()
*descripcion envia un correo electronico al administrador del sitio
*			 con la informacion del formulario de contacto.php
*/
function sendRecomendacion($dirEnc, $nombreE, $nombre, $email, $asunto, $ciudad, $telefono, $mensaje, $to, $cc, $bcc, $sujeto,$plantilla){
	$nombreE=strtoupper($nombreE);
	$linkEncuesta="<a href='".$dirEnc."'>".$nombreE."</a>";
	$file = @file_get_contents($plantilla);
	if(!$file){	
		$this->setSalida(false,$this->getMensaje("[068]", "error"), "sendRecomendacion()","sitio web");
		return false;
	}else{
		$nota = "";
		$mensaje1 = str_replace("[-sitio-]",$this->sitio,$file);
		$mensaje1 = str_replace("[-name-]",$nombre,$mensaje1);
		$mensaje1 = str_replace("[-encuesta-]",$linkEncuesta,$mensaje1);
		$mensaje1 = str_replace("[-email-]",$email,$mensaje1);
		$mensaje1 = str_replace("[-ciudad-]",$ciudad,$mensaje1);
		$mensaje1 = str_replace("[-asunto-]",$asunto,$mensaje1);
		$mensaje1 = str_replace("[-telefono-]",$telefono,$mensaje1);
		$mensaje1 = str_replace("[-mensaje-]",$mensaje,$mensaje1);
		$mensaje1 = str_replace("[-nota-]",$nota,$mensaje1);
		return $this->sendMail($to, $email, $sujeto, $mensaje1, $cc, $bcc, $nombre);
	}
}//end enviar contacto


/*
FUNCION: 		addUsuarioWeb
DESCRIPCION: 	ingresa informacion de un usuario en la DB
pre: 			el login y email no estan asignados
*/
function addUsuarioWeb($nombres, $apellidos, $email, $login, $password, $sexo, $fecha_nmto, $direccion, $ciudad, $pais, $telefono_fijo, $telefono_movil, $segundo_nombre, $cargo, $empresa, $zip, $extension, $state){
		$estado="preactivo";
		$fecha_sis = $this->fecha_actual;
		$sql="insert into usuario_web(nombres,apellidos,email,login,password,sexo,fecha_nmto,direccion,ciudad,pais,telefono_fijo,telefono_movil,fecha_ing, segundo_nombre, cargo, zip, empresa, extension, state) values";
		$sql.="('$nombres','$apellidos','$email','$login','$password','$sexo','$fecha_nmto','$direccion','$ciudad','$pais','$telefono_fijo','$telefono_movil','$fecha_sis','$segundo_nombre','$cargo','$zip','$empresa','$extension','$state')";
		
		if($this->execute($sql)){
			$out=$this->getMensaje("[051]","confirmacion");
			$this->setSalida(true,$out,"addUsuarioWeb",$this->aplicacion);
			return true;
		}else{
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"addUsuarioweb",$this->aplicacion);
			return false;
		}
}//end addUsuarioWeb

/*
*funcion modUsuarioWeb
*descripcion modifica un usuario del sitio en la base de datos
*pre: el login no existe y el email no existe para otro usuario
*	 diferente a el solicitado
*/

function modUsuarioWeb($nombres, $apellidos, $email, $login, $password, $sexo, $fecha_nmto, $direccion, $ciudad, $pais, $telefono_fijo, $telefono_movil,$id, $segundo_nombre, $cargo, $empresa, $zip, $extension, $state  ){
	if( ($login!="indefinido")&&($password!="indefinido") ){
		$sql = "update usuario_web set nombres='$nombres',apellidos='$apellidos',email='$email',login='$login',password='$password', sexo='$sexo', fecha_nmto='$fecha_nmto',direccion='$direccion',telefono_fijo='$telefono_fijo',telefono_movil='$telefono_movil',pais='$pais',ciudad='$ciudad',segundo_nombre='$segundo_nombre',cargo='$cargo',empresa='$empresa',zip='$zip',extension='$extension', state='$state'  where id='$id'";
		if ($this->execute($sql)) {
			$out=$this->getMensaje("[029]","confirmacion");
			$this->setSalida(true,$out,"modUsuarioWeb",$this->aplicacion);
			return true;
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"modUsuarioweb",$this->aplicacion);
			return false;
		}
	}else{
			$out=$this->getMensaje("[072]","confirmacion");
			$this->setSalida(true,$out,"modUsuarioweb",$this->aplicacion);
			return false;
	}
}//end modusuario

function modUsuarioWebEstado($est, $user, $nApli){
		$sql = "update usuario_web set estado='$est' where id='$user'";
		if ($this->execute($sql)) {
			$out=$this->getMensaje("[029]","confirmacion");
			$this->setSalida(true,$out,"modUsuarioWebEstado($est, $user, $nApli)", $nApli);
			return true;
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"modUsuarioWebEstado($est, $user, $nApli)", $nApli);
			return false;
		}
}

/*
*funcion existEmail
*descripcion consulta si el email ya esta asinado a otro usuario del panel
*pre: email tiene un valor valido para una direccion de correo
*/
function existEmail($email, $user=false){
	if(!$user){
		$sql="select * from usuario_web where email='$email'";
	}else{
		$sql="select * from usuario_web where email='$email' and id!='$user'";
	}
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$out=$this->getMensaje("[053]","confirmacion");
			$this->setSalida(true,$out,"existEmail",$this->aplicacion);
			return true;
		}else{
			$out=$this->getMensaje("[052]","confirmacion");
			$this->setSalida(false,$out,"existEmail",$this->aplicacion);
			return false;
		}
	} else {
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"existEmail",$this->aplicacion);
		return false;
	}
}

/***********************************************************
funcion existLogin
descripcion consulta si el login ya esta asinado a otro usuario web
pre: el login tiene un valor valido para login de usuario
************************************************************/
function existLogin($log,$user=false){
	if(!$user){
		$sql="select * from usuario_web where login='$log'";
	}else{
		$sql="select * from usuario_web where login='$log' and id!='$user'";
	}
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$out=$this->getMensaje("[055]","confirmacion");
			$this->setSalida(true,$out,"existLogin",$this->aplicacion);
			return true;
		}else{
			$out=$this->getMensaje("[054]","confirmacion");
			$this->setSalida(false,$out,"existLogin",$this->aplicacion);
			return false;
		}
	} else {
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"existLogin",$this->aplicacion);
		return false;
	}
}

/*
*funcion validarUsuario
*descripcion verifica que exista un usuario que concuerde 
*			con el login y el password solicitados
*pre: el login y el password traen valores validos
*/

function validarUsuario($login,$password){
	if( ($login!="indefinido") && ($password!="indefinido") ){
		$sql="select * from usuario_web where login='$login' and password='$password'";
		if ($this->execute($sql)) {
			if($this->numRows()>0){
				$out=trim($this->getMensaje("[057]","confirmacion"));
				$this->setSalida(true,$out,"validarUsuario($login,$password)",$this->aplicacion);
				return true;
			}else{
				$out=trim($this->getMensaje("[006]","error"));
				$this->setSalida(false,$out,"validarUsuario($login,$password)",$this->aplicacion);
				return false;
			}
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"validarUsuario($login,$password)",$this->aplicacion);
			return false;
		}
	}else{
		$out=trim($this->getMensaje("[056]","confirmacion"));
		$this->setSalida(false,$out,"validarUsuario($login,$password)",$this->aplicacion);
		return false;
	}
}

/*
funcion getUsuario()
descripcion devuelve un vector con toda la informacion del 
			usuario solicitado
*/
function getUsuario($campo,$valor){
	$sql="select * from usuario_web where $campo='$valor'";
	if(!empty($id)){
		$sql="select * from usuario_web where id='$id'";
	}
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$out=$this->getMensaje("[026]","confirmacion");
			$this->setSalida(true,$out,"getUsuario($campo,$valor)",$this->aplicacion);
			return $this->fetchRow();
		}else{
			if($campo=="login"){
				$out=$this->getMensaje("[300]","confirmacion");
				$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
				return false;
			}
			if($campo=="email"){
				$out=$this->getMensaje("[301]","confirmacion");
				$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
				return false;
			}
			
			$out=$this->getMensaje("[027]","confirmacion");
			$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
			return false;
		}		
	} else {
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
		return false;
	}	
	
}
/*
funcion getPassword()
descripcion devuelve un el password de un usuario dado su login
*/
function getPassword($valor){
	$sql="select password from usuario_web where login='$valor'";
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$out=$this->getMensaje("[026]","confirmacion");
			$this->setSalida(true,$out,"getPassword($valor)",$this->aplicacion);
			list($pass)=$this->fetchRow();
			return $pass;
		}else{
			$out=$this->getMensaje("[027]","confirmacion");
			$this->setSalida(false,$out,"getPassword($valor)",$this->aplicacion);
			return false;
		}		
	} else {
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"getPassword($valor)",$this->aplicacion);
		return false;
	}	
	
}

/*
*funcion recoverPassword
*descripcion envia un email con la informacion registrada
*			 por el usuario, recuperandola, ya sea por el email o por el login
*			 a la direccion de correo registrada por este
*/
function recoverPassword($campo,$valor,$plantilla,$retrive){
	$sal = $this->getUsuario($campo,$valor);
	if (!empty($sal)) {
		$file = @file_get_contents($plantilla);
		if(!$file){
			$out=$this->getMensaje("[018]","error")."($plantilla)";
			$this->setSalida(false,$out,"recoverPassword($campo,$valor)",$this->aplicacion);
			return false;
		}else{
			$sujeto = "Informaci�n de registro en ".$this->sitio;
			$nombre =ucwords(strtolower($sal['nombres'])." ".strtolower($sal['apellidos']));
			$clave=$this->util->mascara($sal['password']);
			$enlace = $retrive."?data=".$clave."&email=".$sal['email'];
			$enlace2 = $this->fileMsgAplicaciones."?tarea=delUsuarioWeb&seleccion=".$sal['id']."|".$sal['email']."|".$clave;
			if($sal['sexo']=="M"){$sexo = "Masculino";}elseif($sal['sexo']=="F"){$sexo="Femenino";}else{$sexo="indefinido";}
			$nota =". Thank you for using our services";
			$mensaje = str_replace("[-sujeto-]",$sujeto,$file);
			$mensaje = str_replace("[-color-]",$this->color,$mensaje);
			$mensaje = str_replace("[-nombre-]",$nombre,$mensaje);
			$mensaje = str_replace("[-login-]",$sal['login'],$mensaje);
			$mensaje = str_replace("[-password-]",$sal['password'],$mensaje);
			$mensaje = str_replace("[-fecha_nmto-]",$this->util->fecha($sal['fecha_nmto']),$mensaje);
			$mensaje = str_replace("[-direccion-]",$sal['direccion'],$mensaje);
			$mensaje = str_replace("[-ciudad-]",$sal['ciudad'],$mensaje);
			$mensaje = str_replace("[-pais-]",$sal['pais'],$mensaje);
			$mensaje = str_replace("[-estado-]",$sal['estado'],$mensaje);
			$mensaje = str_replace("[-telefono_fijo-]",$sal['telefono_fijo'],$mensaje);
			$mensaje = str_replace("[-telefono_movil-]",$sal['telefono_movil'],$mensaje);
			$mensaje = str_replace("[-enlace-]",$enlace,$mensaje);
			$mensaje = str_replace("[-nota-]",$nota,$mensaje);
			$mensaje = str_replace("[-enlace2-]",$enlace2,$mensaje);			
			$email = $sal['email'];
			if($this->sendMail($email, $this->contacto, $sujeto, $mensaje,false, false, false)){
				$out=$this->getMensaje("[073]","confirmacion")." ".$email;
				$this->setSalida(true,$out,"recoverPassword($campo,$valor,$plantilla,$retrive)",$this->aplicacion);
				return true;
			}else{
				$out=$this->getMensaje("[024]","error")." ".$email;
				$this->setSalida(false,$out,"recoverPassword($campo,$valor,$plantilla,$retrive)",$this->aplicacion);
				return false;		
			}
		}
	} else {
		$out=$this->salida['msg'];
		$this->setSalida(false,$out,"recoverPassword($campo,$valor)",$this->aplicacion);
		return false;
	}	
}

/*
funcion getCliente
descripcion trae el cliente en el que esta instalado el panel
*/
function getCliente(){
	$sql="select valor from parametro where nombre='cliente' and aplicacion='9999'";	
	if($this->execute($sql)){
		if($this->numRows()>0){
			list($cliente)=$this->fetchRow();
			return $cliente;
		}else{
			$out=trim($this->getMensaje("[013]","confirmacion"));
			$this->setSalida(false,$out,"getCliente",$this->aplicacion);		
			return "indefinido";
		}
	}else{
		$out=trim($this->getMensaje("[008]","error"));
		$out.="\\n::".trim($this->getException());
		$this->setSalida(false,$out,"getCliente",$this->aplicacion);
		return "inconsultable";
	}
}

/*
*funcion vincAplicaciones()
*descripcion relaciona el usuario con todas aplicaciones 
			 instalads en el cliente
*nota:  funciona temporalmente para esta version
		se espera que en una posterior los usuarios sean
		quienes escojan la aplicacion
*/
function vincAplicaciones($user){
	$sql="select id from panel_aplicacion where estado=1";
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$ides =array(); $i=0;
			while(list($id)=$this->fetchRow()){
				$ides[$i]=$id;
				$i++;
			}
			$fallos=0;
			foreach($ides as $key=>$val){
				$sql="insert into vinculo_web (usuario_web,aplicacion,estado) values ('$user','$val','activo')";
				if(!$this->execute($sql)){
					$out=$this->getMensaje("[070]","confirmacion");
					$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
					$fallos++;
				}
			}
			if($fallos==0){
				$out=$this->getMensaje("[071]","confirmacion");
				$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
				return true;
			}else{
				$out=$this->getMensaje("[069]","confirmacion");
				$this->setSalida(false,$out,"vincAplicaciones($user)",$this->aplicacion);
				return false;			
			}
		}else{
			$out=$this->getMensaje("[012]","confirmacion");
			$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
			return true;
		}		
	} else {
		$out=trim($this->getMensaje("[007]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"vincAplicaciones($user)",$this->aplicacion);
		return false;
	}	
}
function vincAplicacionesNews($user){//esta funcion se implemento unicamente para migrar la base de datos que habia antes
	$sql="select id from panel_aplicacion where estado=1";
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$ides =array(); $i=0;
			while(list($id)=$this->fetchRow()){
				$ides[$i]=$id;
				$i++;
			}
			$fallos=0;
			foreach($ides as $key=>$val){
				if($val!=10){
					$sql="insert into vinculo_web (usuario_web,aplicacion,estado) values ('$user','$val', 'activo')";
				}else{
					$sql="insert into vinculo_web (usuario_web,aplicacion,estado) values ('$user','$val','activo')";
				}
				if(!$this->execute($sql)){
					$out=$this->getMensaje("[070]","confirmacion");
					$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
					$fallos++;
				}
			}
			if($fallos==0){
				$out=$this->getMensaje("[071]","confirmacion");
				$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
				return true;
			}else{
				$out=$this->getMensaje("[069]","confirmacion");
				$this->setSalida(false,$out,"vincAplicaciones($user)",$this->aplicacion);
				return false;			
			}
		}else{
			$out=$this->getMensaje("[012]","confirmacion");
			$this->setSalida(true,$out,"vincAplicaciones($user)",$this->aplicacion);
			return true;
		}		
	} else {
		$out=trim($this->getMensaje("[007]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"vincAplicaciones($user)",$this->aplicacion);
		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=false){
	if(empty($find)){
		if(empty($apli)){
			if($est=="todos"){
				$sql="select id, nombres, apellidos, login, email,estado from usuario_web where 1 order by nombres asc limit $inicio,$limite";
				$ests ="";
			}else{
				$sql="select id, nombres, apellidos, login, email,estado from usuario_web where estado='$est' order by nombres asc limit $inicio,$limite";
				$ests = $est."s";
			}
		}else{
			if($est=="todos"){
				if($apli!="todas"){
					$sql="select user.id, user.nombres, user.apellidos, user.login, user.email, user.estado from usuario_web as user, vinculo_web as vinc where vinc.usuario_web=user.id and vinc.aplicacion='$apli' order by nombres asc limit $inicio,$limite";
				}else{
					$sql="select user.id, user.nombres, user.apellidos, user.login, user.email, user.estado from usuario_web as user where 1 order by nombres asc limit $inicio,$limite";
				}
			}else{
				if($apli!="todas"){
					$sql="select user.id, user.nombres, user.apellidos, user.login, user.email, user.estado from usuario_web as user, vinculo_web as vinc where vinc.usuario_web=user.id and vinc.aplicacion='$apli' and user.estado='$est' order by user.nombres asc limit $inicio,$limite";
				}else{
					$sql="select user.id, user.nombres, user.apellidos, user.login, user.email, user.estado from usuario_web as user where user.estado='$est' order by user.nombres asc limit $inicio,$limite";
				}
			}
		}
	}else{
		$sql="select user.id, user.nombres, user.apellidos, user.login, user.email, user.estado from usuario_web as user
		      where (user.nombres like '%$find%') or (user.apellidos like '%$find%') or (user.email like '%$find%') or (user.login like '%$find%') order by user.nombres asc limit $inicio,$limite";
		$ests="<br> que coincidan con la busqueda ($find)";
	}

	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=="bloqueado"){
					$imagen="<img src=\"img/usuarioBloqueado.gif\" onClick=\"fncConsultarUsr(\'$id\')\" height=\"15\" width=\"15\">";
				}else{
					$imagen="<img src=\"img/usuario.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\" class=\"$class\"><BR>$out $ests<BR>&nbsp;</TD></TR>');";
    	}
		echo "</script>";
		return $sql;
	}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,$inicio,$limite,$class)",$nApli);
		return false;
	}
	
}
/*
funcion cantidadUsuarios
descripcion devuelve el nuemro de usuarios en el panel diferentes de azulDigital
*/
function cantidadUsuarios($nApli,$apli,$est,$find){
	if(empty($find)){
		if(empty($apli)){
			if($est=="todos"){
				$sql="select id from usuario_web where 1";
			}else{
				$sql="select id from usuario_web where estado='$est'";
			}
		}else{
			if($est=="todos"){
				if($apli!="todas"){
					$sql="select user.id from usuario_web as user, vinculo_web as vinc where vinc.usuario_web=user.id and vinc.aplicacion='$apli'";
				}else{
					$sql="select user.id from usuario_web as user where 1";
				}
			}else{
				if($apli!="todas"){
					$sql="select user.id from usuario_web as user, vinculo_web as vinc where vinc.usuario_web=user.id and vinc.aplicacion='$apli' and user.estado='$est'";
				}else{
					$sql="select user.id from usuario_web as user where user.estado='$est'";
				}
			}
		}
	}else{
		$sql="select user.id from usuario_web as user
		      where (user.nombres like '%$find%') or (user.apellidos like '%$find%') or (user.email like '%$find%') or (user.login like '%$find%') order by user.nombres asc limit $inicio,$limite";
	}

	//$sql="select * from usuario_web where 1";
	if($this->execute($sql)){
		$out=trim($this->getMensaje("[025]","confirmacion"));
		$this->setSalida(true,$out,"cantidadUsuarios($nApli)",$nApli);	
		return $this->numRows();
	}else{
		$out=trim($this->getMensaje("[026]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"cantidadUsuarios($nApli)",$nApli);
		return false;
	}
}

/*
funcion delVinculo
descripcion remueve un vinculo de un usuario con todas las aplicaciones
*/
function delVinculo($user,$nApli){

	$sql="delete from vinculo_web where id='$user'";
	if($this->execute($sql)){
		$out=$this->getMensaje("[020]","confirmacion");
		$this->setSalida(true,$out,"delVinculo($user)",$nApli);
		return true;
	}else{ 
		$out=$this->getMensaje("[010]","error");
		$out.=trim($this->getException());
		$this->setSalida(false,$out,"delVinculo($user)",$nApli);
		return false;
	}

}
/*
*funcion delVinculoNews
*descripcion remueve un vinculo de un usuario con el newsletter
*			 utiliza el id del vinculo_web en user
*/
function delVinculoNews($user,$nApli){

	$sql="delete from news_vinculo where vinculo='$user'";
	if($this->execute($sql)){
		$out=$this->getMensaje("[020]","confirmacion");
		$this->setSalida(true,$out,"delVinculoNews($user,$nApli)",$nApli);
		return true;
	}else{ 
		$out=$this->getMensaje("[010]","error");
		$out.=trim($this->getException());
		$this->setSalida(false,$out,"delVinculoNews($user,$nApli)",$nApli);
		return false;
	}

}

function delUsuarioWeb($user,$nApli){
	$sql="delete from usuario_web where id='$user'";
	if($this->execute($sql)){
		$out=$this->getMensaje("[082]","confirmacion");
		$this->setSalida(true,$out,"delUsuarioWeb($user,$nApli)",$nApli);
		return true;
	}else{ 
		$out=$this->getMensaje("[026]","error");
		$out.=trim($this->getException());
		$this->setSalida(false,$out,"delUsuarioWeb($user,$nApli)",$nApli);
		return false;
	}
}
/*
*funcion delVinculoWeb()
*descripcion elimana un vinculo web de la DB
*/
function delVinculosWeb($user){
	$sql="delete from vinculo_web where usuario_web='$user'";
	if($this->execute($sql)){
		return true;
	}else{
		$out=trim($this->getMensaje("[026]","error"));
		$out.="\\n::".trim($this->getException());
		$this->setSalida(false,$out,"delVinculoWeb($vinculo)",$this->aplicacion);
		return false;
	}	
}

/*
*funcion add_carpeta()
*descripcion elimana un vinculo web de la DB
*/

function add_carpeta($id_usuario){
	if ($this->existeCarpeta('id_usuario',$id_usuario) == 0){
		$user 			= $this->getUsuario('id',$id_usuario);
		$nombre_carpeta = strtoupper( '['.$user['id'].'] '.$user['nombres'].' '.$user['apellidos'] );
		$parent 		= 1; // Id Carpeta FTP usuarios sys, tabla carpeta
		$permiso		= 'publico'; 
		$nivel			= 1;
		
		$sql = "insert into carpeta (tipo,nombre,parent,permiso,nivel,id_usuario) values ('subcarpeta', '$nombre_carpeta', $parent, '$permiso', $nivel, $id_usuario)";
		
		if($this->execute($sql)){
			// Aqui se crea una carpeta de Uloap y otra de Download
			$nombre_carpeta = "UPLOAD";
			$parent 		= $this->insertId(); // Id Carpeta FTP usuarios sys, tabla carpeta
			$permiso		= 'publico'; 
			$nivel			= 2;
	
			$sql = "insert into carpeta (tipo,nombre,parent,permiso,nivel,id_usuario) values ('subcarpeta', '$nombre_carpeta', $parent, '$permiso', $nivel, $id_usuario)";
			if(!$this->execute($sql)){
				echo "Error creando carpeta UPLOAD";
			}

			$nombre_carpeta = "DOWNLOAD";

			$sql = "insert into carpeta (tipo,nombre,parent,permiso,nivel,id_usuario) values ('subcarpeta', '$nombre_carpeta', $parent, '$permiso', $nivel, $id_usuario)";
			if(!$this->execute($sql)){
				echo "Error creando carpeta DOWNLOAD";
			}
						
			$this->mostrarMensaje($this->getMensaje("[200]","confirmacion"));
		}else{
			$msg = "Error ".$this->getException();
			$this->mostrarMensaje($msg);
			$this->mostrarMensaje($this->getMensaje("[016]","error"));
		}
	}else{
		$this->mostrarMensaje("Space FTP already created.");
	}
	echo '<script> window.close(); </script>';
}

function existeCarpetaAsignada($id_usuario){
		$sql = "select id from carpeta where id_usuario = $id_usuario AND nivel=1";
		if ($this->execute($sql)) {
			return $this->numRows();
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"modUsuarioWebEstado($est, $user, $nApli)", $nApli);
			return false;
		}
}

function getNombreCaperta($id_usuario){
		$sql = "select nombre from carpeta where id_usuario = $id_usuario and nivel=1";
		if ($this->execute($sql)) {
			if($this->numRows()>0){
				list ($nombre) = $this->fetchRow();
				return ($nombre);
			}
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"modUsuarioWebEstado($est, $user, $nApli)", $nApli);
			return false;
		}
}


function existeCarpeta($campo,$valor){
	$sql="select * from carpeta where $campo='$valor'";
	if ($this->execute($sql)) {
		if($this->numRows()>0){
			$out=$this->getMensaje("[026]","confirmacion");
			$this->setSalida(true,$out,"getUsuario($campo,$valor)",$this->aplicacion);
			return $this->numRows();
		}else{
			$out=$this->getMensaje("[027]","confirmacion");
			$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
			return false;
		}		
	} else {
		$out=trim($this->getMensaje("[017]","error"));
		$out.="\\n:Desc: ".trim($this->getException());
		$this->setSalida(false,$out,"getUsuario($campo,$valor)",$this->aplicacion);
		return false;
	}	
	
}

function showFilesToDownLoad($id_usuario){
	$band = true;
	$db = new DBManager('MySql');
	$db->connect();
	
	$db_1 = new DBManager('MySql');
	$db_1->connect();

	$sql_1	=	"select id from carpeta where id_usuario = $id_usuario AND nombre='DOWNLOAD' ";
	if ($this->execute($sql_1)) {
		if($this->numRows()>0){
			list ($id_carpeta) = $this->fetchRow();
			$sql_2 = "SELECT id,titulo,texto,fecha_ing FROM documentos WHERE carpeta = $id_carpeta";
			if ($db->execute($sql_2)){
				if($db->numRows()>0){
					echo '<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" >';
					echo '<tr class="style6" bgcolor="#0000FF"><td>File Name</td><td>Description</td><td>File</td><td>Size (Kb)</td> <td>Date (Y-m-d)</td> <td>Time</td> </tr>';
					while (list($id_documento,$titulo,$descripcion,$fecha_ingreso) = $db->fetchRow() ){
						//echo $titulo.'<br>';
						$sql_3 = "SELECT id,titulo,fichero,hora FROM archivo WHERE documento = $id_documento";
						if ($db_1->execute($sql_3)){
							if($db_1->numRows()>0){
								while (list($id_archivo,$nombre_archivo,$archivo,$hora)= $db_1->fetchRow() ){
									$fichero = './aplicaciones/admon/documentos/docs/archivos/'.$archivo;
									$tamano = filesize ($fichero);
									$tamano = $tamano/1024;
									if ($band==true){
										$color = "#DBECF7";	
										$band = false;
									}else{
										$color = "#FFFFFF";	
										$band = true;
									}
									echo '<tr bgcolor="'.$color.'"><td><a href="download_file.php?id_archivo='.$id_archivo.'" target="_blank">'.$titulo.'</a></td> <td>'.$descripcion.'</td> <td>'.$archivo.'</td> <td>'.$tamano.'</td> <td>'.$fecha_ingreso.'</td> <td>'.$hora.'</td> </tr>';
								}
							}else{
								echo "No files found.";
							}
						}else{
							echo "SQL error.".$sql_3;
						}
					}
					echo '</table>';
				}else{
					echo "No files founds.";
				}
			}
		}else{
			echo "You don't have a space asigned.";
		}		
	} else {
		echo "SQL Error.".$sql_1;
	}	
}

function showFilesUpLoad($id_usuario){
	$band = true;
	$db = new DBManager('MySql');
	$db->connect();
	
	$db_1 = new DBManager('MySql');
	$db_1->connect();

	$sql_1	=	"select id from carpeta where id_usuario = $id_usuario AND nombre='UPLOAD' ";
	if ($this->execute($sql_1)) {
		if($this->numRows()>0){
			list ($id_carpeta) = $this->fetchRow();
			$sql_2 = "SELECT id,titulo,texto,fecha_ing,tipo FROM documentos WHERE carpeta = $id_carpeta";
			if ($db->execute($sql_2)){
				if($db->numRows()>0){
					echo '<table border="1" width="100%" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" >';
					echo '<tr class="style6" bgcolor="#0000FF"><td>File Name</td><td>Description</td><td>File</td><td>Size (Kb)</td> <td>Date (Y-m-d)</td> <td>Time</td> <td>Service</td> </tr>';
					while (list($id_documento,$titulo,$descripcion,$fecha_ingreso,$tipo) = $db->fetchRow() ){
						$sql_3 = "SELECT id,titulo,fichero,hora FROM archivo WHERE documento = $id_documento";
						if ($db_1->execute($sql_3)){
							if($db_1->numRows()>0){
								while (list($id_archivo,$nombre_archivo,$archivo,$hora)= $db_1->fetchRow() ){
									$fichero = './aplicaciones/admon/documentos/docs/archivos/'.$archivo;
									$tamano = filesize ($fichero);
									$tamano = $tamano/1024;
									if ($band==true){
										$color = "#DBECF7";	
										$band = false;
									}else{
										$color = "#FFFFFF";	
										$band = true;
									}
									echo '<tr bgcolor="'.$color.'"><td><a href="download_file.php?id_archivo='.$id_archivo.'" target="_blank">'.$titulo.'</a></td> <td>'.$descripcion.'</td> <td>'.$archivo.'</td> <td>'.$tamano.'</td> <td>'.$fecha_ingreso.'</td> <td>'.$hora.'</td> <td>'.$tipo.'</td> </tr>';
								}
							}else{
								echo "No files found.";
							}
						}else{
							echo "SQL error.".$sql_3;
						}
					}
					echo '</table>';
				}else{
					echo "No files founds.";
				}
			}
		}else{
			echo "You don't have a space asigned.";
		}		
	} else {
		echo "SQL Error.".$sql_1;
	}	
}



function info_Archivo($id_archivo)
{
	$sql = "select id, titulo, fichero from archivo where id = ".$id_archivo." ";
	$archs = $this->consultarCampos($sql, "info_Archivo($id_archivo)");
	if($archs && count($archs) > 0)
	{
		return $archs[0];
	}
	return NULL;
}

function info_ArchivoCatalogo($id_archivo)
{
	$sql = "select id, titulo, fichero from catalogo_archivos where id = ".$id_archivo." ";
	$archs = $this->consultarCampos($sql, "info_Archivo($id_archivo)");
	if($archs && count($archs) > 0)
	{
		return $archs[0];
	}
	return NULL;
}


function descargarArchivo($id_archivo){
	
	   //First, see if the file exists
		$arch = $this->info_Archivo($id_archivo);

		$ruta = "./aplicaciones/admon/documentos/docs/archivos/";
	
		$file =  $ruta.$arch['fichero'];
	   //Gather relevent info about file
	   $len = filesize($file);
	   $filename = basename($file);
	   $file_extension = strtolower(substr(strrchr($filename,"."),1));
	
	   //This will set the Content-Type to the appropriate setting for the file
	   switch( $file_extension ) {
		case "pdf": $ctype="application/pdf"; break;
		 case "exe": $ctype="application/octet-stream"; break;
		 case "zip": $ctype="application/zip"; break;
		 case "doc": $ctype="application/msword"; break;
		 case "xls": $ctype="application/vnd.ms-excel"; break;
		 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
		 case "gif": $ctype="image/gif"; break;
		 case "png": $ctype="image/png"; break;
		 case "jpeg":
		 case "jpg": $ctype="image/jpg"; break;
		 case "mp3": $ctype="audio/mpeg"; break;
		 case "wav": $ctype="audio/x-wav"; break;
		 case "mpeg":
		 case "mpg":
		 case "mpe": $ctype="video/mpeg"; break;
		 case "mov": $ctype="video/quicktime"; break;
		 case "avi": $ctype="video/x-msvideo"; break;
		 default: $ctype="application/force-download";
	   }
	
	   //Begin writing headers
	   header("Pragma: public");
	   header("Expires: 0");
	   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	   header("Cache-Control: public");
	   header("Content-Description: File Transfer");
	  
	   //Use the switch-generated Content-Type
	   header("Content-Type: $ctype");
	
	   //Force the download
	   $header="Content-Disposition: attachment; filename=".$filename.";";
	   header($header );
	   header("Content-Transfer-Encoding: binary");
	   header("Content-Length: ".$len);
	   @readfile($file);
	   exit;
}



	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 getIdCarpetaUpLoad($id_usuario){
		$sql = "select id from carpeta where id_usuario = $id_usuario and nivel=2 and nombre='UPLOAD'";
		if ($this->execute($sql)) {
			if($this->numRows()>0){
				list ($id) = $this->fetchRow();
				return ($id);
			}
		} else {
			$out=trim($this->getMensaje("[017]","error"));
			$out.="\\n:Desc: ".trim($this->getException());
			$this->setSalida(false,$out,"modUsuarioWebEstado($est, $user, $nApli)", $nApli);
			return false;
		}
}


function descargarArchivoCatalogo($id_archivo){
	
	   //First, see if the file exists
		$arch = $this->info_ArchivoCatalogo($id_archivo);

		$ruta = "./aplicaciones/admon/documentos/docs/archivos/";
	
		$file =  $ruta.$arch['fichero'];
	   //Gather relevent info about file
	   $len = filesize($file);
	   $filename = basename($file);
	   $file_extension = strtolower(substr(strrchr($filename,"."),1));
	
	   //This will set the Content-Type to the appropriate setting for the file
	   switch( $file_extension ) {
		case "pdf": $ctype="application/pdf"; break;
		 case "exe": $ctype="application/octet-stream"; break;
		 case "zip": $ctype="application/zip"; break;
		 case "doc": $ctype="application/msword"; break;
		 case "xls": $ctype="application/vnd.ms-excel"; break;
		 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
		 case "gif": $ctype="image/gif"; break;
		 case "png": $ctype="image/png"; break;
		 case "jpeg":
		 case "jpg": $ctype="image/jpg"; break;
		 case "mp3": $ctype="audio/mpeg"; break;
		 case "wav": $ctype="audio/x-wav"; break;
		 case "mpeg":
		 case "mpg":
		 case "mpe": $ctype="video/mpeg"; break;
		 case "mov": $ctype="video/quicktime"; break;
		 case "avi": $ctype="video/x-msvideo"; break;
		 default: $ctype="application/force-download";
	   }
	
	   //Begin writing headers
	   header("Pragma: public");
	   header("Expires: 0");
	   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	   header("Cache-Control: public");
	   header("Content-Description: File Transfer");
	  
	   //Use the switch-generated Content-Type
	   header("Content-Type: $ctype");
	
	   //Force the download
	   $header="Content-Disposition: attachment; filename=".$filename.";";
	   header($header );
	   header("Content-Transfer-Encoding: binary");
	   header("Content-Length: ".$len);
	   @readfile($file);
	   exit;
}



}//end class cliente
?>

Anon7 - 2021