|
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 : |
<?php
/********************************************************
clase Noticias:
utiliza la interfas de BD para realizar
las necesidades propias consulta de noticias para el home
*********************************************************/
class Noticia extends Aplicacion{
var $fileImagenDefault = "default.jpg";
var $lengthLista =5;
var $aplicacion = "Noticias";
var $tokenNone="none";
var $utileria;
var $archivos;
var $pathSetup="./aplicaciones/admon/noticias/";
function Noticia(){
$this->Aplicacion();
$this->archivos = true;
$this->utileria = new Utileria();
}
/*
*descripcion captura la ultima noticia ingresada
*
*/
function getNoticiaHome(){
$sql = "select * from noticias where 1 order by noticia_id desc";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[161]","confirmacion"));
$this->setSalida(true,$out,"getNoticiaHome()","noticias");
return $this->fetchRow();
}else{
$out=trim($this->getMensaje("[160]","confirmacion"));
$this->setSalida(false,$out,"getNoticiaHome()","noticias");
return $this->tokenNone;
}
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"getNoticiaHome()",$this->aplicacion);
return false;
}
}
function cantTemasNoticias(){
$sql="select noticiatema_id from noticia_temas";
if($this->execute($sql)){
if($this->numRows()>0){
return ($this->numRows());
}
}
}
function nombresTemasNoticias(){
$sql="select noticiatema_id,noticiatema_titulo from noticia_temas order by noticiatema_id ";
if($this->execute($sql)){
if($this->numRows()>0){
$i=0;
while(list($noticiatema_id,$noticiatema_titulo)=$this->fetchRow()){
$arrNames[$i]=$noticiatema_id."/".$noticiatema_titulo;
$i++;
}
return ($arrNames);
}
}
}
function nombresNoticias($id_tema=false){
$sql="select noticia_id, noticia_titulo from noticias where noticia_tema='$id_tema' ";
if($this->execute($sql)){
if($this->numRows()>0){
$i=0;
while(list($noticia_id,$noticia_titulo)=$this->fetchRow()){
$arrEventos[$i]=$noticia_id."/".$noticia_titulo;
$i++;
}
return ($arrEventos);
}
}
}
function mostrarNoticias(){
$numTemas = $this->cantTemasNoticias();
$temas = $this->nombresTemasNoticias();
echo "<table>";
for($i=0; $i<$numTemas; $i++){
echo "<tr>";
$temaNombre = explode ("/", $temas[$i]);
$elTema = strtoupper($temaNombre[1]);
echo "<td><img src='images/iconot.gif' width='24' height='23'></td><td> <a href='listNoticiasTema.php?seleccion=$temaNombre[0]' class='titunoti'>$elTema</a>";
echo "</tr>";
$numEventos = $this->cantidadNoticias($temaNombre[0]);
$eventos = $this->nombresNoticias($temaNombre[0]);
for($j=0; $j<$numEventos; $j++){
$eventoNombre = explode ("/", $eventos[$j]);
$event = strtoupper($eventoNombre[1]);
echo "<tr>";
echo "<td></td><td><a href='noticias.php?seleccion=$eventoNombre[0]' class='noti'>• $event</a> </td>";
echo "</tr><tr></tr>";
}
echo "<tr></tr>";
unset( $eventos );
}
echo "<tr></tr>";
echo "</table>";
}
/*
*descripcion captura las ultima noticias segun posicion
*
*/
function notiIndex($op){
$sql = "select noticia_id,noticia_titulo,noticia_resumen from noticias order by noticia_fechapublic desc LIMIT $op,1";
if($this->execute($sql)){
list($a,$b,$c) = $this->fetchRow();
return array($a,$b,$c);
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"notiIndex($op)",$this->aplicacion);
return false;
}
}
/*
*descripcion captura la noticia solicitada
*
*/
function getNoticia($noticia){
$sql = "select * from noticias where noticia_id='$noticia'";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[161]","confirmacion"));
$this->setSalida(true,$out,"getNoticia($noticia)","noticias");
return $this->fetchRow();
}else{
$out=trim($this->getMensaje("[160]","confirmacion"));
$this->setSalida(false,$out,"getNoticia($noticia)","noticias");
return $this->tokenNone;
}
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"getNoticia($noticia)",$this->aplicacion);
return false;
}
}
/*
*descripcion captura la ultima noticia para la seccion solicitada
*/
function getNoticiaSeccion($seccion){
$sql = "select * from noticias where noticia_tema='$seccion' order by noticia_id desc limit 0,1";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[161]","confirmacion"));
$this->setSalida(true,$out,"getNoticia($noticia)","noticias");
return $this->fetchRow();
}else{
$out=trim($this->getMensaje("[160]","confirmacion"));
$this->setSalida(false,$out,"getNoticia($noticia)","noticias");
return $this->tokenNone;
}
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"getNoticia($noticia)",$this->aplicacion);
return false;
}
}
/*
*funcion getImagen()
*descripcion devuelve un arreglo con los valores de la imagen de una noticia dada.
* noticia: id de la noticia solicitada
* tipo: {home | principal | general}
* el tipo = general conyevaria a devolver un arreglo de arreglos
* donde cada arreglo contiene los valores de una de sus imagenes
*/
function getImagen($noticia,$tipo){
$sql = "select * from noticia_imagenes where noticia_id='$noticia' and imagen_tipo='$tipo'";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[162]","confirmacion"));
$this->setSalida(true,$out,"getNoticia($noticia)","noticias");
if($tipo!="general"){
return $this->fetchRow();
}else{
$vec=array();
while($row=$this->fetchRow()){
$vec[]=$row;
}
return $vec;
}
}else{
$out=trim($this->getMensaje("[163]","confirmacion"));
$this->setSalida(false,$out,"getNoticia($noticia)","noticias");
return $this->tokenNone;
}
}else{
$out=trim($this->getMensaje("[064]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"getNoticia($noticia)",$this->aplicacion);
return false;
}
}
/*
*funcion getTema
*descripcion devuelve el nombre del tema al que pertenece la noticia
*/
function getNameTema($tema){
$sql="select noticiatema_titulo from noticia_temas where noticiatema_id='$tema'";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[165]","confirmacion"));
$this->setSalida(true,$out,"getNameTema($tema)","noticias");
list($tm)=$this->fetchRow();
return $tm;
}else{
$out=trim($this->getMensaje("[164]","confirmacion"));
$this->setSalida(false,$out,"getNameTema($tema)","noticias");
return $this->tokenNone;
}
}else{
$out=trim($this->getMensaje("[066]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"getNameTema($tema)",$this->aplicacion);
return false;
}
}
/*
*funcion showListSecciones
*descripci�n despliega una tabla con la lista de las secciones disponibles para noticias
*/
function showListSecciones($vineta,$hdArea,$fileRef){
$sql="select noticiatema_id, noticiatema_titulo, noticiatema_descripcion from noticia_temas";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[165]","confirmacion"));
$this->setSalida(true,$out,"showListSecciones($vineta,$hdArea,$fileRef)","noticias");
echo "<table width=\"100%\">";
while(list($id,$tm,$des)=$this->fetchRow()){
echo "<tr><td width=\"40px\" valing=\"middle\" rowspan=\"2\"><img src=\"$vineta\"></td><td width=\"4\"> </td>";
echo "<td><a $hdArea href=\"{$fileRef}?seleccion=$id\">$tm</a></td>";
echo "</tr>\n";
echo "<tr><td> </td><td class=\"texto\">".$this->util->preWrap($des,60)."</td></tr>";
echo "<tr><td> </td><td> </td></tr>";
}
echo "</table>";
}else{
$out=trim($this->getMensaje("[164]","confirmacion"));
$this->setSalida(false,$out,"showListSecciones($vineta,$hdArea,$fileRef)","noticias");
echo "<table width=\"100%\">";
echo "<tr><td><img src=\"$vineta\"></td><td width=\"4\"> </td>";
echo "<td $hdArea >No hay secciones de noticias registradas!!!</td>";
echo "</tr>\n";
echo "</table>";
}
}else{
$out=trim($this->getMensaje("[066]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"showListSecciones($vineta,$hdArea,$fileRef)",$this->aplicacion);
echo "<table>";
echo "<tr><td><img src=\"$vineta\"></td><td width=\"4\"> </td>";
echo "<td $hdArea >$out</td>";
echo "</tr>\n";
echo "</table>";
}
}
/*
*funcion showListNoticias
*descripci�n despliega una tabla con la lista de las noticias disponibles para el tema solicitado
*/
function showListNoticias($tema,$vineta,$hdArea,$hdContenido,$fileRef){
$sql="select * from noticias where noticia_tema='$tema' order by noticia_titulo asc";
if($this->execute($sql)){
if($this->numRows()>0){
$out=trim($this->getMensaje("[161]","confirmacion"));
$this->setSalida(true,$out,"showListNoticias($tema,$vineta,$hdArea,$hdContenido,$fileRef)","noticias");
echo "<table>";
while($row=$this->fetchRow()){
echo "<tr><td align=\"left\"><a $hdArea href=\"{$fileRef}?seleccion=".$row['noticia_id']."\"><img src=\"$vineta\" border=\"0\"></a></td><td width=\"4\"> </td>";
echo "<td align=\"left\"><a $hdArea href=\"{$fileRef}?seleccion=".$row['noticia_id']."\">".$row['noticia_titulo']."</a></td>";
echo "</tr>\n";
echo "<tr><td></td><td></td><td align=\"left\"><div $hdContenido align=\"justity\">".$this->parseoSalida(substr($row['noticia_resumen'],0,210))."...</div></td></tr>";
}
echo "</table>";
}else{
$out=trim($this->getMensaje("[166]","confirmacion"));
$this->setSalida(false,$out,"showListNoticias($tema,$vineta,$hdArea,$hdContenido,$fileRef)","noticias");
echo "<table>";
echo "<tr><td><img src=\"$vineta\"></td><td width=\"4\"> </td>";
echo "<td $hdArea >$out</td>";
echo "</tr>\n";
echo "</table>";
}
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"showListNoticias($tema,$vineta,$hdArea,$hdContenido,$fileRef)",$this->aplicacion);
echo "<table>";
echo "<tr><td><img src=\"$vineta\"></td><td width=\"4\"> </td>";
echo "<td $hdArea >$out</td>";
echo "</tr>\n";
echo "</table>";
}
}
/*
*
*/
function showListNoticiasBarra($cantidad=2,$tema){
if($tema==1){
$estilo="titupublic";
}else{
$estilo="tituencue";
}
$sql="select * from noticias WHERE noticia_tema=$tema order by noticia_id desc limit 0,$cantidad";
if($this->execute($sql)){
if($this->numRows()>0){
while($row=$this->fetchRow()){ //$this->util->preWrap(
echo '<table border="0" cellpadding="0" cellspacing="0">
<tr>
<br>
<td valign="top" class="titupublic"><div align="left"><strong><a class="texto3" href="noticias.php?seleccion='.$row[0].'"><span class="texto3"><strong>'.$row[3].'<strong></span></a> </strong></div></td>
</tr>
<tr>
<td height="15" valign="top" class="negro">
<div align="left">
<p align="justify"><a class="noti" href="noticias.php?seleccion='.$row[0].'">'.$this->parseoSalida(substr($row[6],0,50)).' ...'."-".$row[1].'</a> <br> <a class="texto2" href="noticias.php?seleccion='.$row[0].'"><strong>Ver Más>> </strong></a> </p>
</div></td>
</tr>
</table>';
}
return true;
}else{
$out=trim($this->getMensaje("[166]","confirmacion"));
$this->setSalida(false,$out,"showListNoticiasBarra($cantidad)","noticias");
echo "<table width=\"160\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo '<tr>
<td width="10" rowspan="2" valign="top"><div align="center"><img src="../img/cuadrito.gif" width="10" height="9"> </div></td>
<td width="150" valign="top" class="noticias"><div align="center"><strong></strong></div></td>
</tr>';
echo "</table>";
return false;
}
}else{
$out=trim($this->getMensaje("[063]","error"));
$out.="\\n::".trim($this->getException());
$this->setSalida(false,$out,"showListNoticiasBarra($cantidad)",$this->aplicacion);
echo "<table width=\"160\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo '<tr>
<td width="10" rowspan="2" valign="top"><div align="center"><img src="../img/cuadrito.gif" width="10" height="9"> </div></td>
<td width="150" valign="top" class="noticias"><div align="center"><strong></strong></div></td>
</tr>';
echo "</table>";
return false;
}
}
/*
*funcion cantidadNoticias($tema)
*descripcion devuelve la cantidad de noticias ya sea para un tema o para todo en general
*/
function cantidadNoticias($tema){
$sql="select count(*) from noticias where noticia_tema='$tema'";
if(empty($tema)){
$sql="select count(*) from noticias where 1";
}
$this->execute($sql);
list($cn)=$this->fetchRow();
return $cn;
}
function parseoSalida($cadena){
$cadena = str_replace("[r][n]","<br>", $cadena);
$cadena = str_replace("[n][n]","<br><br>", $cadena);
$cadena = str_replace("[n]","<br>", $cadena);
$cadena = str_replace("[c]", "\"", $cadena);
$cadena = str_replace("[b]", "\\", $cadena);
$cadena = str_replace("[p]", "$", $cadena);
return $cadena;
}
/*
funcion paginas
descripcion devuelve el numero de paginas que se obtienen
en la consulta dado un limite y un total de
lineas de la consulta
*/
function paginas($total){
$lim=$this->lengthLista;
$val = ceil($total/$lim);
return $val;
}
/*
funcion inicioPagina
descripcion devuelve el indice donde debe empezar la
consulta en la nueva pagina
*/
function inicioPagina($ini){
$val =($ini-1)*($this->lengthLista);
return $val;
}
// Esta funcion solo sirve para consultas donde se nesecita
// conocer el valor de un campo espesifico.
// ej: $sql="SELECT nombre FROM catalogo_producto WHERE id='$id_pro'";
// $func es el nombre del metodo desde donde se invoca a consultarCampo,
// esto para poder mostrar el error adecuadamente
function consultarCampo($sql, $func)
{
//$this->setFiles(4);
if($this->execute($sql))
{
$n = $this->fetchRow();
return $n[0];
}else
{
$out=trim($this->getMensaje("[016]","error"));
$out.="\\n:Desc: ".trim($this->getException());
$this->setSalida(false,$out,$func,$this->nombre);
return false;
}
}
/*
Esta funcion retorna un array con el contenido de una consulta donde se esperan varios resultados;
*/
function consultarCampos($sql, $func)
{
//$this->setFiles(4);
$array = array();
$i = 0;
if($this->execute($sql))
{
while($row = $this->fetchRow())
{
$array[] = $row;
$i++;
}
if($i > 0)
return $array;
else return NULL;
}else
{
$out=trim($this->getMensaje("[016]","error"));
$out.="\\n:Desc: ".trim($this->getException());
$this->setSalida(false,$out,$func,$this->nombre);
return NULL;
}
}
function informacion($id_not)
{
$sql = "select noticia_titulo from noticias where noticia_id = ".$id_not;
$r = $this->consultarCampos($sql, "informacion($id_not)");
return $r[0];
}
function listarArchivos($id_not)
{
$sql = "select id, titulo, fichero from noticia_archivos where noticia = ".$id_not;
$archs = $this->consultarCampos($sql, "informacion($id_not)");
$ruta = "./aplicaciones/admon/noticias/archivos/";
if($archs && count($archs)>0)
{
$table = '<table border="0">';
foreach($archs as $ar)
{
$table .= '<tr><td>';
$table .= '<a href="'.$ruta.$ar['fichero'].'" class="texto2">'.$ar['titulo'].'</a>';
$table .= '</td></tr>';
}
$table .= '</table>';
}
echo $table;
}
}//endclass
?>