|
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/documentos/fnc/ |
Upload File : |
<?php
class Carpeta extends Aplicacion{
var $aplicacion = "documentos";
var $dirSetup = "/aplicaciones/admon/documentos";
/*constructor*/
function Carpeta(){
$this->Aplicacion();
}
/*agregar carpeta*/
function add_carpeta($nombre,$tipo,$permiso){
$this->setFiles(4);
$sql = "SELECT id FROM carpeta WHERE nivel='0' AND nombre='$nombre'";
$this->execute($sql);
$cant=$this->numRows();
if($cant==0){
$sql = "insert into carpeta values (default,'$tipo', '$nombre', NULL, '$permiso', '0')";
if($this->execute($sql)){
$this->mostrarMensaje($this->getMensaje("[200]","confirmacion"));
}elseif ($this->isDebuggerEnabled()) {
//$msg = "Error ".$this->getException();
//$this->mostrarMensaje($msg);
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}
}else{
$this->mostrarMensaje($this->getMensaje("[201]","confirmacion"));
echo "<script>window.open(\"../add_carpeta.php?nivel=0&nombre=$nombre&permiso=$permiso\",\"contenido\");</script>";
}
echo "<script>window.open(\"../index.php\",\"contenido\");</script>";
}
/*modificar carpeta*/
function mod_carpeta($nombre,$id,$permiso){
$this->setFiles(4);
$sql = "SELECT id FROM carpeta WHERE nivel='0' AND nombre='$nombre' AND id!='$id'";
$this->execute($sql);
$cant=$this->numRows();
if($cant==0){
$sql = "update carpeta set nombre ='$nombre', permiso='$permiso' where id='$id'";
if($this->execute($sql)){
$this->mostrarMensaje($this->getMensaje("[202]","confirmacion"));
}elseif ($this->isDebuggerEnabled()) {
//$msg = "Error ".$this->getException();
//$this->mostrarMensaje($msg);
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}
}else{
$this->mostrarMensaje($this->getMensaje("[201]","confirmacion"));
echo "<script>window.open(\"../mod_carpeta.php?nivel=0&id=$id\",\"contenido\");</script>";
}
echo "<script>window.open(\"../index.php\",\"contenido\");</script>";
}
/*eliminar carpeta*/
function eli_carpeta($id){
$this->setFiles(4);
$db1 = new DBManager('MySQL');
$db1->connect();
$db2 = new DBManager('MySQL');
$db2->connect();
$db3 = new DBManager('MySQL');
$db3->connect();
$id_ = $id;
$ar =1;
//se borran documentos y archivos de nivel 1 **********************************************
$sql="SELECT id, titulo FROM documentos WHERE carpeta='$id_'";
$db1->execute($sql);
//cantidad de documentos en esta subcarpeta
$cant_documentos= $db1->numRows();
if($cant_documentos>0){
while(( list($id, $titulo)=$db1->fetchRow()) && ($ar==1)){
$sql1= "SELECT id, fichero FROM archivo WHERE documento='$id'";
$db2->execute($sql1);
$cant_archivos = $db2->numRows();
$hecho =true;
if ($cant_archivos>0){
while( (list($id_arc, $fichero)=$db2->fetchRow()) && ($hecho==true)){
$rutafoto = "../docs/archivos/".$fichero;
//borrado del archivo
if (file_exists($rutafoto)){
if(unlink($rutafoto)){
$sql = "DELETE FROM archivo WHERE id = '$id_arc'";
if(!$this->execute($sql)){
$hecho = false;
$this->isDebuggerEnabled();
$msg = $this->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_archivos--;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error"));
$hecho =false;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error")." El archivo ".$fichero." no existe!");
$hecho =false;
}
}//end while archivos
}
if($cant_archivos==0){//no ahi mas archivos o no hubieron
$sql = "DELETE FROM documentos WHERE id = '$id'";
if(!$this->execute($sql)){
$hecho=false;
$this->isDebuggerEnabled();
$msg = $this->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_documentos--;
}
}
}//end while documentos
}//end if eliminar documento nivel 1
if($cant_documentos==0){
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//borro documentos y archivos de nivel 2
$sql="SELECT id, nombre FROM carpeta WHERE parent='$id_' AND tipo='subcarpeta'";
$db1->execute($sql);
$cant_carpetas = $db1->numrows();
$cant_documentos = 0;
$cant_archivos = 0;
if($cant_carpetas>0){
while(list($id, $nombre)=$db1->fetchRow()){
$idFinal=$id;
//se borran documentos y archivos de estos en nivel 4
$sql="SELECT id, titulo FROM documentos WHERE carpeta='$id'";
$db2->execute($sql);
$cant_documentos= $db2->numRows();
if($cant_documentos>0){
while( ( list($id_doc, $titulo_doc)=$db2->fetchRow() ) && ($ar==1)){
$sql1= "SELECT id, fichero FROM archivo WHERE documento='$id_doc'";
$this->execute($sql1);
$cant_archivos = $this->numRows();
if ($cant_archivos>0) {
$hecho=true;
while( (list($id_arc, $fichero)=$this->fetchRow()) && ($hecho==true)){
$rutafoto = "../docs/archivos/".$fichero;
//borrado del archivo o archivos
if (file_exists($rutafoto)){
if(unlink($rutafoto)){
$sql = "DELETE FROM archivo WHERE id = '$id_arc'";
if(!$db3->execute($sql) ){
$hecho =false;
$db3->isDebuggerEnabled();
$msg = $db3->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_archivos--;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error"));
$hecho =false;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error")." El archivo ".($fichero)." no existe!");
$hecho =false;
}
}//end while archivos
}
//se borra documento
if($cant_archivos==0){//no ahi mas archivos o no hubieron archivos
$sql = "DELETE FROM documentos WHERE id = '$id_doc'";
if(!$this->execute($sql) ){
$hecho=false;
$ar=5;
$this->isDebuggerEnabled();
$msg = $this->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_documentos--;
}
}
}//end while documentos
}//end if documentos>0
if($cant_documentos==0){//no ahi mas documentos o no hubieron
/////////////////////////////////////////////////////////////////////////////////////////////////////
//borro subcarpetas , documentos y archivos de nivel 3
$sql="SELECT id, nombre FROM carpeta WHERE parent='$idFinal' AND tipo='subcarpeta'";
$db1->execute($sql);
$cant_carpetas2 = $db1->numrows();
$cant_documentos2 = 0;
$cant_archivos = 0;
if($cant_carpetas2>0){
while(list($id, $nombre)=$db1->fetchRow()){
$idFinal2=$id;
//se borran documentos y archivos de estos en nivel 3
$sql="SELECT id, titulo FROM documentos WHERE carpeta='$id'";
$db2->execute($sql);
$cant_documentos2= $db2->numRows();
if($cant_documentos2>0){
while( ( list($id_doc, $titulo_doc)=$db2->fetchRow() ) && ($ar==1)){
$sql1= "SELECT id, fichero FROM archivo WHERE documento='$id_doc'";
$this->execute($sql1);
$cant_archivos = $this->numRows();
if ($cant_archivos>0) {
$hecho=true;
while( (list($id_arc, $fichero)=$this->fetchRow()) && ($hecho==true)){
$rutafoto = "../docs/archivos/".$fichero;
//borrado del archivo o archivos
if (file_exists($rutafoto)){
if(unlink($rutafoto)){
$sql = "DELETE FROM archivo WHERE id = '$id_arc'";
if(!$db3->execute($sql) ){
$hecho =false;
$db3->isDebuggerEnabled();
$msg = $db3->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_archivos--;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error"));
$hecho =false;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error")." El archivo ".$fichero." no existe!");
$hecho =false;
}
}//end while archivos
}
//se borra documento
if($cant_archivos==0){//no ahi mas archivos o no hubieron archivos
$sql = "DELETE FROM documentos WHERE id = '$id_doc'";
if(!$this->execute($sql) ){
$hecho=false;
$ar=5;
$this->isDebuggerEnabled();
$msg = $this->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_documentos2--;
}
}
}//end while documentos
}//end if documentos>0
if($cant_documentos2==0){//no ahi mas documentos o no hubieron
/*******************************************************************************************************************/
//borro subcarpetas , documentos y archivos de nivel 3
$sql="SELECT id, nombre FROM carpeta WHERE parent='$idFinal2' AND tipo='subcarpeta'";
$db1->execute($sql);
$cant_carpetas3 = $db1->numrows();
$cant_documentos3 = 0;
$cant_archivos = 0;
if($cant_carpetas3>0){
while(list($id, $nombre)=$db1->fetchRow()){
$idFinal3=$id;
//se borran documentos y archivos de estos en nivel 4
$sql="SELECT id, titulo FROM documentos WHERE carpeta='$id'";
$db2->execute($sql);
$cant_documentos3= $db2->numRows();
if($cant_documentos3>0){
while( ( list($id_doc, $titulo_doc)=$db2->fetchRow() ) && ($ar==1)){
$sql1= "SELECT id, fichero FROM archivo WHERE documento='$id_doc'";
$this->execute($sql1);
$cant_archivos = $this->numRows();
if ($cant_archivos>0) {
$hecho=true;
while( (list($id_arc, $fichero)=$this->fetchRow()) && ($hecho==true)){
$rutafoto = "../docs/archivos/".$fichero;
//borrado del archivo o archivos
if (file_exists($rutafoto)){
if(unlink($rutafoto)){
$sql = "DELETE FROM archivo WHERE id = '$id_arc'";
if(!$db3->execute($sql) ){
$hecho =false;
$db3->isDebuggerEnabled();
$msg = $db3->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_archivos--;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error"));
$hecho =false;
}
}else{
$this->mostrarMensaje($this->getMensaje("[200]","error"). "El archivo ($fichero) no existe!");
$hecho =false;
}
}//end while archivos
}
//se borra documento
if($cant_archivos==0){//no ahi mas archivos o no hubieron archivos
$sql = "DELETE FROM documentos WHERE id = '$id_doc'";
if(!$this->execute($sql) ){
$hecho=false;
$ar=5;
$this->isDebuggerEnabled();
$msg = $this->getException();
$this->mostrarMensaje($this->getMensaje("[016]","error"));
}else{
$cant_documentos3--;
}
}
}//end while documentos
}//end if documentos>0
if($cant_documentos3==0){//no ahi mas documentos o no hubieron
$sql="DELETE FROM carpeta WHERE parent='$idFinal2'";
if(!$this->execute($sql)){
$ar=6;
$this->mostrarMensaje($this->getMensaje("[203]","error"));
}else{
$cant_carpetas3--;
}
}
}//end while carpetas
}
/*********************************************************************************************************************/
$sql="DELETE FROM carpeta WHERE parent='$idFinal'";
if(!$this->execute($sql)){
$ar=6;
$this->mostrarMensaje($this->getMensaje("[203]","error")." ".$nombre);
}else{
$cant_carpetas2--;
}
}
}//end while carpetas
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$sql="DELETE FROM carpeta WHERE parent='$id_'";
if(!$this->execute($sql)){
$ar=6;
$this->mostrarMensaje($this->getMensaje("[016]","error")." ".$nombre);
}else{
$cant_carpetas--;
}
}
}//end while carpetas
}
if($cant_carpetas==0){
$sql= "DELETE FROM carpeta where id ='$id_'";
if(!$this->execute($sql)){
$ar=4;
$this->mostrarMensaje($this->getMensaje("[203]","error"));
}else{
$this->mostrarMensaje($this->getMensaje("[203]","confirmacion"));
echo "<script>window.open(\"../index.php\",\"contenido\");</script>";
}
}
}
}
/*
*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.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.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 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%') or (user.login 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=="bloqueado")
{
$imagen="<img src=\"img/usuarioBloqueado.gif\" onClick=\"fncConsultarUsr(\'$id\')\" height=\"15\" width=\"15\">";
}
if($estado=="preactivo")
{
$imagen="<img src=\"img/newslPreactivo.gif\" onClick=\"fncConsultarUsr(\'$id\')\">";
}
if($estado=="activo")
{
$imagen="<img src=\"img/vinculotema.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> </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> </TD></TR>";
$this->setSalida(false,$out,"listarUsuarios($apli,$inicio,$limite,$class)",$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.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.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 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%') or (user.login 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 panel_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;
}
}
/*
*funcion delSubscripcion()
*descripcion elimina un vinculo de un usuario con la aplicacion newsletter
*/
function delSubscripcion($vinc,$nApli)
{
$vec=explode("|",$vinc);
$id = $vec[0];
$sql="delete FROM panel_vinculo_web 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,$nApli)",$nApli);
return true;
}else
{
$out=trim($this->getMensaje("[027]","error")." ".$vec[1]);
$out.="\\n:Desc: ".trim($this->getException());
$this->setSalida(false,$out,"delSubscripcion($vinc,$nApli)",$nApli);
return false;
}
}
/*
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 carpeta where parent is NULL ";
}else
{
$sql = "select id, nombre from carpeta 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_carpeta=".$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_des, $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 printDocumentosWeb($id = NULL, $img='', $img_exp='', $pag_des, $solo_publico=false)
{
//require_once('./html_menu/TreeMenu.php');
$icon = './aplicaciones/admon/documentos/fnc/html_menu/images/folder.gif';
$expandedIcon = './aplicaciones/admon/documentos/fnc/html_menu/images/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 carpeta where parent is NULL";
}else
{
$sql = "select id, nombre from carpeta where parent = '$id' ";
}
if($solo_publico == true)$sql.=" and permiso like 'publico' ";
$sql.=" order by nombre";
$carpetas = array();
$nun_cats = 0;
if($this->execute($sql))
{
$nun_cats = $this->numRows();
if($nun_cats > 0)
{
while($carp = $this->fetchRow())
{
$carpetas[]['carpeta'] = $carp;
}
}
}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' => $expandedIcon, 'expanded' => false), array());
for($i = 0; $i < $nun_cats; $i++)
{
$cat = $carpetas[$i]['carpeta'];
$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/documentos/fnc/html_menu/images/', 'defaultClass' => 'treeMenuDefault'));
$listBox = &new HTML_TreeMenu_Listbox($menu, array('linkTarget' => '_self'));
$array2[]=$treeMenu;
$array2[]=$listBox;
return $array2;
}
function documentos($id_car,$ini)
{
$docu = new Documento();
$docu->documentos($id_car,$ini);
}
/*************** Ordo�ez ***************/
function chisteDelDia()
{
$sql = "select id, titulo, permiso from documentos where titulo like 'chiste del dia'";
$docs = $this->consultarCampos($sql, "chisteDelDia()");
$doc = $docs[0];
$sql = "select titulo, fichero from archivo where documento = ".$doc['id']." order by titulo";
$archs = $this->consultarCampos($sql, "chisteDelDia()");
if($archs && count($archs)> 0)
{
$c = rand(0, (count($archs)-1));
return $archs[$c];
}
return NULL;
}
/*
Esta funcion retorna un array con el contenido de una consulta donde se esperan varios resultados;
*/
/*
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;
}
}
// 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;
}
}
// $carp = array('id', 'nombre')
function auxXML($carp, $tabs="\t")
{
$xml = "\n".$tabs.'<node label="'.$carp['nombre'].'">';
$sql = "select id, nombre, permiso from carpeta where parent = ".$carp['id']." order by nombre";
$carpetas = $this->consultarCampos($sql, "auxXML($carp, $tabs)");
if($carpetas)
{
foreach($carpetas as $carp2)
{
$xml .= $this->auxXML($carp2, $tabs."\t");
}
}
$sql = "select id, titulo, permiso from documentos where carpeta = ".$carp['id']." order by titulo";
$docus = $this->consultarCampos($sql, "auxXML($carp)");
if($docus)
{
foreach($docus as $doc)
{
$xml .= "\n\t".$tabs.'<node label="'.$doc['titulo'].'">';
////////////////////////////////////////////////////////////////
$sql = "select titulo, fichero from archivo where documento = ".$doc['id']." order by titulo";
$archs = $this->consultarCampos($sql, "auxXML($carp)");
if($archs)
{
foreach($archs as $arch)
{
$xml .= "\n\t\t".$tabs.'<node label="'.$arch['titulo'].'" src="http://'.$_SERVER['SERVER_NAME'].$this->subDir.$this->dirSetup."/docs/archivos/".$arch['fichero'].'" artist="Jose Ordo�ez" />';
}
}
///////////////////////////////////////////////////////////////
$xml .= "\n\t".$tabs.'</node>';
}
}
$xml .= "\n".$tabs.'</node>';
return $xml;
}
function generarXML($permisos="todos", $id='')
{
if($permisos=="todos")
{
$sql = "select id, nombre, permiso from carpeta where parent is NULL order by nombre";
}else
{
$sql = "select id, nombre, permiso from carpeta where parent is NULL and permiso=".$permisos." order by nombre";
}
$carpetas = $this->consultarCampos($sql, "generarXML($permisos)");
echo count($carpetas);
if($carpetas)
{
$xml = "<node>";
foreach($carpetas as $carp)
{
$xml .= $this->auxXML($carp);
}
$xml .= "\n</node>";
return $xml;
}
}
function usuarioActivo($id_u='', $not)
{
if($id_u)
{
$sql = "select * FROM panel_vinculo_web where usuario_web = $id_u and aplicacion = 13";
$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("[248]","confirmacion"));
return false;
}
return true;
}
}
return false;
}
/*
$href = array('pag_carpetas', 'pag_archivo');
*/
function listarCarpetasWeb($id_carpeta = '', $pag=1, $limite = 10, $permisos_publico=true, $styles='', $nun_cols=2, $arch=false, $href='',$option_navs='')
{
$inicio = ($pag -1)*$limite;
$total_carpetas = 0;
$total_docs = 0;
$total_archs = 0;
$table = "<table ".$styles['table'].">";
if( $arch == false)
{
if($id_carpeta)
{
$sql = "select id, nombre, permiso from carpeta where parent = ".$id_carpeta." ";
}else
{
$sql = "select id, nombre, permiso from carpeta where parent is NULL ";
}
if($permisos_publico == true)
$sql .= " and permiso like 'publico' ";
$sql2 = $sql;
$sql .= " order by nombre limit $inicio, $limite";
$carpetas = $this->consultarCampos($sql, "auxXML($carp, $tabs)");
$nun_items = 0; // numero de elementos mostrados
if($carpetas && count($carpetas)>0)
{
$total_carpetas = count($carpetas);
$table .= "<tr ".$styles['tr']."><td>Categorias<b</td></tr><tr><td> <br></td></tr>";
$k = 0;
for($m = 0; $m < $total_carpetas; $m++)
{
if($k == $total_carpetas)break;
if($nun_items == 0)$table .= "<tr ".$styles['tr'].">";
for($i = 0; $i < $nun_cols; $i++)
{
if($k == $total_carpetas)break;
$carp2 = $carpetas[$k];
$table .= "<td ".$styles['td'].">";
$table .= '<a href="'.$href['pag_carpetas'].'id_carpeta='.$carp2['id'].'&archivo=false" '.$styles['href'].'>'.'<img src="images/vinetas/categoria.gif" border="0">'.$carp2['nombre'].'</a>';
$table .= " </td>";
$nun_items++;
$k++;
}
if($nun_items == $nun_cols)
{
$table .= "</tr>";
$nun_items = 0;
}
}
}
$nun_items = 0;
if($id_carpeta )
{
$sql = "select id, titulo, permiso from documentos where carpeta = ".$id_carpeta." ";
if($permisos_publico == true)
$sql .= " and permiso like 'publico' ";
$sql3 = $sql;
$sql .= " order by titulo limit $inicio, ".($limite - $total_carpetas);
$docus = $this->consultarCampos($sql, "auxXML($carp)");
if($docus && count($docus)>0)
{
$table .= "<tr ".$styles['tr']."><td>Personajes<b</td></tr><tr><td> <br></td></tr>";
$total_docs = count($docus);
$k = 0;
for($m = 0; $m < $total_docs; $m++)
{
if($k == $total_docs)break;
if($nun_items == 0)$table .= "<tr ".$styles['tr'].">";
for($i = 0; $i < $nun_cols; $i++)
{
if($k == $total_docs)break;
$doc = $docus[$k];
$table .= "<td ".$styles['td'].">";
$table .= '<a href="'.$href['pag_carpetas'].'id_carpeta='.$doc['id'].'&archivo=true" '.$styles['href'].'>'.'<img src="images/vinetas/categoria.gif" border="0">'.$doc['titulo'].'</a>';
//$table .= '<img src="images/vinetas/categoria.gif" border="0">'.$doc['titulo'];
$table .= " </td>";
$archivos = $this->listarArchivosDocumento($doc['id'], $inicio, $limite);
$k++;
}
if($nun_items == $nun_cols)
{
$table .= "</tr>";
$nun_items = 0;
}
}
}
}
}else
{
$sql = "select id, titulo, fichero from archivo where documento = ".$id_carpeta." ";
$sql4 = $sql;
$sql .= " order by titulo limit $inicio, $limite";
$archs = $this->consultarCampos($sql, "auxXML($carp)");
$nun_items = 0;
if($archs && count($archs)> 0)
{
$table .= "<tr ".$styles['tr']."><td>Postales Virtuales<b</td></tr><tr><td> <br></td></tr>";
$total_archs = count($archs);
$k = 0;
for($m = 0; $m < $total_archs; $m++)
{
if($k == $total_archs)break;
if($nun_items == 0)$table .= "<tr ".$styles['tr'].">";
for($i = 0; $i < $nun_cols; $i++)
{
if($k == $total_archs)break;
$arch = $archs[$k];
$table .= "<td ".$styles['td'].">";
if(eregi(".swf", $arch['fichero']) != 1)
{
$table .= '<a href="./aplicaciones/admon/documentos/docs/archivos/'.$arch['fichero'].'" '.$styles['href'].'>' .'<img src="images/download.gif" border="0">'.$arch['titulo'].'</a>';
}else
{
//$table .= '<a href="#" '.$styles['href'].' onClick="MM_openBrWindow("tarjetas.php?archivo='.$arch['fichero'].'">'.$arch['titulo'].'</a>';
$table .= '<a href="#" '.$styles['href'].' onClick="MM_openBrWindow(\'tarjetas.php?archivo='.$arch['fichero'].'\' ,\'\',\'width=576,height=384\')">'.''.$arch['titulo'].' (ver)</a>';
//$table .= '<a href="'.$href['pag_archivo'].'id_carpeta='.$id_carpeta.'&archivo=true&mostrarArchivo=true&id_archivo='.$arch['id'].'" '.$styles['href'].' onClick="MM_openBrWindow("tarjetas.php?archivo='.$arch['fichero'].'">'.$arch['titulo'].'</a>';
}
$table .= "</td>";
$nun_items++;
$k++;
}
if($nun_items == $nun_cols)
{
$table .= "</tr>";
$nun_items = 0;
}
}
}
}
if(($total_carpetas+$total_docs+$total_archs) == 0)
{
$table .= "<tr ".$styles['tr'].">";
$table .= "<td ".$styles['td'].">";
$table .= "No existen documentos registrados.";
$table .= "</td>";
$table .= "</tr>";
}
$table .= "</table>";
$total_items = 0;
if( $arch == false)
{
if($this->execute($sql2))
{
$total_items = $this->numRows();
if($this->execute($sql3))
{
$total_items += $this->numRows();
}else
{
$out=trim($this->getMensaje("[016]","error"));
/*$out.="\\n:Desc: ".trim($this->getException());
$this->setSalida(false,$out,"printCatalogoWeb($id , $img, $img_exp, $pag_des)",$this->id);
return false;*/
}
}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;*/
}
}else
{
if($this->execute($sql4))
{
$total_items += $this->numRows();
}else
{
$out=trim($this->getMensaje("[016]","error"));
/*$out.="\\n:Desc: ".trim($this->getException());
$this->setSalida(false,$out,"printCatalogoWeb($id , $img, $img_exp, $pag_des)",$this->id);
return false;*/
}
}
if($total_items > $limite)
{
$final = ceil($total_items/$limite);
if($final == 0)$final=1;
$atras = 1;
if( ($pag-1) >= 1) $atras = ($pag-1);
$sig = $final;
if(($pag+1) <= $final)$sig = ($pag+1);
if($option_navs)
{
$nav = '<table border="0" cellspacing="0" cellpadding="0"><tr>';
if($option_navs['inicio'] == true)
{
$nav .= '<td><a href="'.$option_navs['href'].'id_carpeta='.$id_carpeta.'&pag='.$pag.'" border="0"><img src="'.$option_navs['inicio'].'" border="0"></a></td>';
}
if($option_navs['atras'] == true)
{
$nav .= '<td><a href="'.$option_navs['href'].'id_carpeta='.$id_carpeta.'&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"> </td>';
}
if($option_navs['sig'] == true)
{
$nav .= '<td><a href="'.$option_navs['href'].'id_carpeta='.$id_carpeta.'&pag='. ($sig) .'"><img src="'.$option_navs['sig_image'].'" border="0"></a></td>';
}
if($option_navs['final'] == true)
{
$nav .= '<td><a href="'.$option_navs['href'].'id_carpeta='.$id_carpeta.'&pag='.$final.'"><img src="'.$option_navs['final'].'" border="0"></a></td>';
}
$nav .= '</tr></table>';
}
}else
{
$nav = '<table border="0" cellspacing="0" cellpadding="0"><tr>';
$nav .= '<td><img src="'.$option_navs['inicio'].'" border="0"></td>';
$nav .= '<td><img src="'.$option_navs['atras_image'].'" border="0"></td>';
$nav .= '<td><img src="'.$option_navs['sig_image'].'" border="0"></td>';
$nav .= '<td><img src="'.$option_navs['final'].'" border="0"></td>';
$nav .= '</tr></table>';
}
echo $table;
return $nav;
}
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 listarArchivosDocumento($id_docu=NULL, $inicio=0, $limite=5)
{
$sql = "select id, titulo, fichero from archivo where documento = ".$id_docu." ";
$sql .= " order by titulo limit $inicio, $limite";
$archs = $this->consultarCampos($sql, "auxXML($carp)");
if($archs && count($archs)> 0)
{
return $archs;
}
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 obtenerJerarquiaDeCarpetas($id_, $carp=0)
{
$arch = '';
$docu = '';
$out = array();
$carps = array();
$out[0] = false;
$out[1] = false;
// caso archivos
if($carp == 2)
{
$sql = "select id, titulo, fichero, documento from archivo where id = ".$id_." ";
$archs = $this->consultarCampos($sql, "obtenerJerarquiaDeCarpetas($id_, $carp)");
$arch = $archs[0];
$carp = 1;
$id_ = $arch['documento'];
$out[0] = $arch;
}
// caso documentos
if($carp == 1)
{
$sql = "select id, titulo, carpeta from documentos where id = ".$id_." ";
$docus = $this->consultarCampos($sql, "obtenerJerarquiaDeCarpetas($id_, $carp)");
$docu = $docus[0];
$carp = 0;
$id_ = $docu['carpeta'];
$out[1] = $docu;
}
if($carp == 0)
{
$sql = "select id, nombre, permiso, parent from carpeta where id = $id_ ";
$cs = $this->consultarCampos($sql, "obtenerJerarquiaDeCarpetas($id_, $carp)");
$carps[] = $cs[0];
$id_ = $cs[0]['parent'];
// caso carpetas
while($id_ != NULL)
{
$sql = "select id, nombre, permiso, parent from carpeta where id = $id_ ";
$cs = $this->consultarCampos($sql, "obtenerJerarquiaDeCarpetas($id_, $carp)");
$carps[] = $cs[0];
$id_ = $cs[0]['parent'];
}
$out[2] = $carps;
}
return $out;
}
function numeroMaximoDeSubcarpetasCreado($subCat = false)
{
if($subCat == true)
{
$sql = "SELECT count( *) FROM carpeta WHERE parent is not NULL group by parent";
}else
{
$sql = "SELECT count( *) FROM carpeta 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 numeroMaximoDeDocsPorCarpetaCreado()
{
$sql = "SELECT count(*) FROM documentos WHERE 1 group by carpeta";
$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 listarArchivos($id_doc, $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 archivo WHERE documento = '$id_doc' 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.')"> <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.')"> <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>Este producto no tiene ningún archivo asociado.<BR> </TD></>\');';
}
$script .= '</script>';
echo $script;
}
function numeroArchivos($id_doc)
{
$sql = "SELECT count(*) FROM archivo WHERE documento = '$id_doc'";
$num = $this->consultarCampo($sql, "numeroArchivos($id_pro)");
if($num) return $num;
return 0;
}
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;
//The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
/* case "php":
case "htm":
case "html":
case "txt": die("<b>Cannot be used for ". $file_extension ." files!</b>"); 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 descargarArchivo2($id_archivo){
//First, see if the file exists
$arch = $this->info_Archivo($id_archivo);
$ruta = "./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;
//The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
/* case "php":
case "htm":
case "html":
case "txt": die("<b>Cannot be used for ". $file_extension ." files!</b>"); 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;
}
}
?>