Viewing file: dt_nota_back.php (18.19 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php class dt_nota extends toba_datos_tabla {
function get_listado($filtro=array(),$order='ORDER BY t_n.id_nota DESC') { $where = array();
if (isset($filtro['id_nota'])) { $where[] = "t_n.id_nota = '".$filtro['id_nota']."'"; }
if (isset($filtro['titulo'])) { $where[] = "t_n.titulo ILIKE ".quote("%{$filtro['titulo']}%"); }
if (isset($filtro['visible']) and count($filtro['visible'])>0) { foreach($filtro['visible'] as $visible_en){ switch($visible_en){ case 'principal': $where[] = "principal = 1"; break; case 'secundaria': $where[] = "secundaria = 1"; break; case 'newsletter': $where[] = "newsletter = 1"; break; case 'newsletter2': $where[] = "newsletter2 = 1"; break; } } }
if (isset($filtro['fecha_desde'])) { list($y,$m,$d)=explode("-",$filtro['fecha_desde']); //2011-03-31 $fecha_desde = $y."-".$m."-".$d; $where[] = "t_n.fecha_alta >= ".quote($fecha_desde); } if (isset($filtro['fecha_hasta'])) { list($y,$m,$d)=explode("-",$filtro['fecha_hasta']); //2011-03-31 $fecha_hasta = $y."-".$m."-".$d." 23:59:59"; $where[] = "t_n.fecha_alta <= ".quote($fecha_hasta); }
if (isset($filtro['usuario_alta'])) { $where[] = "t_n.usuario_alta ILIKE ".quote("%{$filtro['usuario_alta']}%"); } if (isset($filtro['estado'])) { $where[] = "t_n.estado = '".$filtro['estado']."'"; }
if (isset($filtro['id_seccion'])) { $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '".$filtro['id_seccion']."') "; }
if (isset($filtro['secciones']) and count($filtro['secciones'])>0) { $primero = true; foreach($filtro['secciones'] as $id_seccion){ if($primero){ $primero = false; $in_secciones.= $id_seccion; }else{ $in_secciones.= ','.$id_seccion; } } $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion IN ($in_secciones) ) "; }
if (isset($filtro['limit'])) { $limit = "limit '".$filtro['limit']."' "; }
$sql = "SELECT t_n.id_nota, t_n.volanta, t_n.titulo, t_n.bajada, t_n.nota, t_n.foto, CASE WHEN t_n.foto IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto||'\" height=\"100\" width=\"100\">' ELSE '' END as url_foto, t_n.epigrafe, t_n.video, t_n.principal, t_n.orden_principal, t_n.secundaria, t_n.orden_secundaria, t_n.newsletter, t_n.orden_newsletter, t_n.newsletter2, t_n.orden_newsletter2, t_n.fecha_alta, t_n.usuario_alta, t_n.estado, t_n.id_galeria, CASE WHEN t_n.estado='A' THEN 'Activa' WHEN t_n.estado='I' THEN 'Inactiva' WHEN t_n.estado='V' THEN 'Vista Previa' ELSE t_n.estado END as estado_descripcion, t_g.nombre as id_galeria_nombre, t_n.id_nota||' .'||t_n.titulo as descripcion, t_n.lecturas, t_n.autor, t_n.foto_autor, CASE WHEN t_n.foto_autor IS NOT NULL THEN '<img src=\"fotos/'||t_n.foto_autor||'\" height=\"100\" width=\"100\">' ELSE '' END as url_foto_autor FROM nota as t_n LEFT OUTER JOIN galeria as t_g ON (t_n.id_galeria = t_g.id_galeria) $order $limit";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); } $datos = toba::db('tdfonline')->consultar($sql);
//---seteamos secciones a modo de string--------------- if(count($datos)>0){ foreach($datos as $key=>$dato){ $sql = "SELECT t_s.id_seccion, t_s.nombre FROM seccion_nota as t_sn, seccion as t_s WHERE t_sn.id_seccion = t_s.id_seccion AND t_sn.id_nota = '".$dato['id_nota']."' ORDER BY nombre ASC"; $secciones = toba::db('tdfonline')->consultar($sql); $pri = true; if(count($secciones)>0){ foreach($secciones as $s=>$seccion){ if($pri){ $datos[$key]['secciones'] = $seccion['nombre']; $pri = false; }else{ $datos[$key]['secciones'].= ', '.$seccion['nombre']; } if($s == 10){ file_put_contents('/opt/apex_tdfonline/proyectos/tdfonline/php/datos/cons_secc_'.$dato['id_nota'], $sql); break; } } }
} } //-----------------------------------------------------
return $datos; }
function get_semaforo_estado($id_nota){ $sql = "SELECT estado FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
/* WHEN t_n.estado='A' THEN 'Activa' WHEN t_n.estado='I' THEN 'Inactiva' WHEN t_n.estado='V' THEN 'Vista Previa' ELSE t_n.estado */ switch ($dato['estado']) { case 'A': $semaforo = '<div class="semaforo_activa">A</>'; break; case 'I': $semaforo = '<div class="semaforo_inactiva">I</>'; break;
case 'V': $semaforo = '<div class="semaforo_vistaprevia">B</>'; break; default: $semaforo = '<div class="semaforo_indefinido">'.$dato['estado'].'</>'; }
return $semaforo; }
function get_last_nota(){ $sql = "SELECT max(id_nota) as id_nota FROM nota"; $dato = toba::db('tdfonline')->consultar_fila($sql);
return $dato['id_nota'];
}
function get_foto($id_nota = '') { #if(!empty($id_nota)){ $sql = "SELECT foto FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); #} }
function get_foto_autor($id_nota = '') { #if(!empty($id_nota)){ $sql = "SELECT foto_autor FROM nota WHERE id_nota = '$id_nota'"; return toba::db('tdfonline')->consultar_fila($sql); #} }
function activar_desactivar($id_nota){
$sql = "SELECT estado FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
if($dato['estado']== 'A'){ $estado = 'I'; }elseif($dato['estado']== 'I'){ $estado = 'A'; }else{ return false; }
$sql = "UPDATE nota SET estado = '$estado' WHERE id_nota = '$id_nota'"; toba::db('tdfonline')->ejecutar($sql); return true; }
function set_portada($array_datos,$sector_visibilidad){ switch ($sector_visibilidad) { case 'principal': $sql = "UPDATE nota SET principal = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET principal = 1, orden_principal = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
break;
case 'secundaria': $sql = "UPDATE nota SET secundaria = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET secundaria = 1, orden_secundaria = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
break;
}
return true; }
function set_newsletter($array_datos,$sector_visibilidad){ $sql = "UPDATE nota SET $sector_visibilidad = 0 WHERE estado = 'A'"; toba::db('tdfonline')->ejecutar($sql);
foreach($array_datos as $dato){ if(!empty($dato['id_nota'])){ $sql = "UPDATE nota SET $sector_visibilidad = 1, orden_$sector_visibilidad = '".$dato['orden']."' WHERE estado = 'A' AND id_nota = '".$dato['id_nota']."'"; toba::db('tdfonline')->ejecutar($sql); } }
return true; }
function set_lecturas($id_nota){
$sql = "SELECT lecturas FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$lecturas = $dato['lecturas'] + 1;
$sql = "UPDATE nota SET lecturas = $lecturas WHERE id_nota = '$id_nota'"; if(toba::db('tdfonline')->ejecutar($sql)){ return true; }else{ return false; } }
function eliminar_nota($id_nota) { $sql = "SELECT foto, foto_autor FROM nota WHERE id_nota = '$id_nota'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$sql = "DELETE FROM nota WHERE id_nota = '$id_nota'"; if (toba::db('tdfonline')->ejecutar($sql)){
if(!empty($dato['foto'])){ $folder_path = "../www/fotos/"; $nombre_archivo = $dato['foto']; $destino=$folder_path.$nombre_archivo; if(unlink($destino)){ //return true; }else{ //return false; } }
if(!empty($dato['foto_autor'])){ $folder_path = "../www/fotos/"; $nombre_archivo = $dato['foto_autor']; $destino=$folder_path.$nombre_archivo; if(unlink($destino)){ //return true; }else{ //return false; } }
return true; }else{ return false; } }
function get_descripciones() { $sql = "SELECT id_nota, titulo as descripcion_html FROM nota ORDER BY titulo"; return toba::db('tdfonline')->consultar($sql); }
//----------------------------------------------------------------------------------- //---- Descripciones para portada borrador ------------------------------------------ //-----------------------------------------------------------------------------------
function get_activas($filtro=array()){
if (isset($filtro['id_seccion'])) { $where[] = "t_n.id_nota IN (select id_nota from seccion_nota where id_seccion = '".$filtro['id_seccion']."') "; }
$sql = "SELECT t_n.id_nota, t_n.titulo, t_n.fecha_alta, t_n.usuario_alta, '#'||t_n.id_nota||' '||t_n.fecha_alta||' | '||t_n.titulo as descripcion FROM nota as t_n WHERE t_n.estado = 'A' ORDER BY t_n.id_nota DESC";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); }
return toba::db('tdfonline')->consultar($sql);
}
function get_activas_1(){ $filtro['id_seccion'] = 1; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_2(){ $filtro['id_seccion'] = 2; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_3(){ $filtro['id_seccion'] = 3; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_4(){ $filtro['id_seccion'] = 4; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_5(){ $filtro['id_seccion'] = 5; $datos = $this->get_activas($filtro); return $datos; } function get_activas_6(){ $filtro['id_seccion'] = 6; $datos = $this->get_activas($filtro); return $datos; } function get_activas_7(){ $filtro['id_seccion'] = 7; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_8(){ $filtro['id_seccion'] = 8; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_9(){ $filtro['id_seccion'] = 9; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_10(){ $filtro['id_seccion'] = 10; // $datos = $this->get_activas($filtro); return $datos; }
function get_activas_11(){ $filtro['id_seccion'] = 11; $datos = $this->get_activas($filtro); return $datos; } function get_activas_12(){ $filtro['id_seccion'] = 12; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_13(){ $filtro['id_seccion'] = 13; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_14(){ $filtro['id_seccion'] = 14; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_15(){ $filtro['id_seccion'] = 15; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_16(){ $filtro['id_seccion'] = 16; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_17(){ $filtro['id_seccion'] = 17; $datos = $this->get_activas($filtro); return $datos; } function get_activas_18(){ $filtro['id_seccion'] = 18; $datos = $this->get_activas($filtro); return $datos; } function get_activas_19(){ $filtro['id_seccion'] = 19; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_20(){ $filtro['id_seccion'] = 20; $datos = $this->get_activas($filtro); return $datos; }
function get_activas_21(){ $filtro['id_seccion'] = 21; $datos = $this->get_activas($filtro); return $datos; }
function publicar() {
$sql ="SELECT id_nota, volanta, titulo, bajada, nota, foto, epigrafe, video, principal, secundaria, fecha_alta, usuario_alta, estado , id_galeria, orden_principal, orden_secundaria, newsletter, orden_newsletter, newsletter2, orden_newsletter2, lecturas, autor, foto_autor FROM nota";
$datos = toba::db('tdfonline')->consultar($sql);
if(count($datos)>0){
$cont_inserts = 0; $cont_updates = 0;
foreach($datos as $dato){ $dato['volanta'] = str_replace("'", "'", $dato['volanta']); $dato['titulo'] = str_replace("'", "'", $dato['titulo']); $dato['bajada'] = str_replace("'", "'", $dato['bajada']); $dato['nota'] = str_replace("'", "'", $dato['nota']); $dato['epigrafe']= str_replace("'", "'", $dato['epigrafe']);
$sql ="SELECT count(id_nota) as existe FROM nota WHERE id_nota= ".$dato['id_nota']; $res = toba::db('web_tdfonline')->consultar_fila($sql); if($res['existe'] == 0){ //insertar
$sql ="INSERT INTO nota( id_nota, volanta, titulo, bajada, nota, foto, autor, foto_autor , epigrafe, video, principal, secundaria, fecha_alta, usuario_alta, estado "; if(!is_null($dato['id_galeria'])){ $sql.=" , id_galeria"; } if(!is_null($dato['orden_principal'])){ $sql.=" , orden_principal"; } if(!is_null($dato['orden_secundaria'])){ $sql.=" , orden_secundaria"; } if(!is_null($dato['newsletter'])){ $sql.=" , newsletter"; } if(!is_null($dato['orden_newsletter'])){ $sql.=" , orden_newsletter"; } if(!is_null($dato['newsletter2'])){ $sql.=" , newsletter2"; } if(!is_null($dato['orden_newsletter2'])){ $sql.=" , orden_newsletter2"; } if(!is_null($dato['lecturas'])){ $sql.=" , lecturas"; }
$sql.=") VALUES ('".$dato['id_nota']."', '".$dato['volanta']."', '".$dato['titulo']."', '".$dato['bajada']."', '".$dato['nota']."', '".$dato['foto']."', '".$dato['autor']."' , '".$dato['foto_autor']."' , '".$dato['epigrafe']."', '".$dato['video']."', '".$dato['principal']."', '".$dato['secundaria']."', '".$dato['fecha_alta']."', '".$dato['usuario_alta']."', '".$dato['estado']."' "; if(!is_null($dato['id_galeria'])){ $sql.=" , '".$dato['id_galeria']."'"; } if(!is_null($dato['orden_principal'])){ $sql.=" , '".$dato['orden_principal']."'"; } if(!is_null($dato['orden_secundaria'])){ $sql.=" , '".$dato['orden_secundaria']."'"; } if(!is_null($dato['newsletter'])){ $sql.=" , '".$dato['newsletter']."'"; } if(!is_null($dato['orden_newsletter'])){ $sql.=" , '".$dato['orden_newsletter']."'"; } if(!is_null($dato['newsletter2'])){ $sql.=" , '".$dato['newsletter2']."'"; } if(!is_null($dato['orden_newsletter2'])){ $sql.=" , '".$dato['orden_newsletter2']."'"; } if(!is_null($dato['lecturas'])){ $sql.=" , '".$dato['lecturas']."'"; } $sql.=")";
try { toba::db('web_tdfonline')->ejecutar($sql); $cont_inserts++; } catch (Exception $e) { toba::notificacion()->agregar("Error ($sql) al insertar Nota: ".$e->getMessage(), "error"); }
}else{ //actualizar
$sql = "UPDATE nota SET volanta='".$dato['volanta']."', titulo='".$dato['titulo']."', bajada='".$dato['bajada']."', nota='".$dato['nota']."', foto='".$dato['foto']."', autor='".$dato['autor']."', foto_autor='".$dato['foto_autor']."', epigrafe='".$dato['epigrafe']."', video='".$dato['video']."', principal='".$dato['principal']."', secundaria='".$dato['secundaria']."' , fecha_alta='".$dato['fecha_alta']."', usuario_alta='".$dato['usuario_alta']."', estado='".$dato['estado']."'"; if(!is_null($dato['id_galeria'])){ $sql.=", id_galeria='".$dato['id_galeria']."'"; } if(!is_null($dato['orden_principal'])){ $sql.=", orden_principal='".$dato['orden_principal']."'"; } if(!is_null($dato['orden_secundaria'])){ $sql.=", orden_secundaria='".$dato['orden_secundaria']."'"; } if(!is_null($dato['newsletter'])){ $sql.=", newsletter='".$dato['newsletter']."'"; } if(!is_null($dato['orden_newsletter'])){ $sql.=", orden_newsletter='".$dato['orden_newsletter']."'"; } if(!is_null($dato['newsletter2'])){ $sql.=", newsletter2='".$dato['newsletter2']."'"; } if(!is_null($dato['orden_newsletter2'])){ $sql.=", orden_newsletter2='".$dato['orden_newsletter2']."'"; } if(!is_null($dato['lecturas'])){ $sql.=", lecturas='".$dato['lecturas']."'"; } $sql.="WHERE id_nota = '".$dato['id_nota']."'"; try { toba::db('web_tdfonline')->ejecutar($sql); $cont_updates++; } catch (Exception $e) { toba::notificacion()->agregar("Error ($sql) al actualizar Nota: ".$e->getMessage(), "error"); } } }
toba::notificacion()->agregar("Resultado Nota: $cont_updates actualizaciones. $cont_inserts insersiones", "info");
}
}
} ?>
|