Viewing file: dt_carta.php (7.11 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php class dt_carta extends toba_datos_tabla { function get_listado($filtro=array(), $order = 'ORDER BY t_c.id_carta DESC', $limit='', $offset='') { $where = array();
if (isset($filtro['id_carta'])) { $where[] = "t_c.id_carta = '".$filtro['id_carta']."'"; }
if (isset($filtro['titulo'])) { $where[] = "t_c.titulo ILIKE ".quote("%{$filtro['titulo']}%"); }
if (isset($filtro['fecha_desde'])) { list($y,$m,$d)=explode("-",$filtro['fecha_desde']); //2011-03-31 $fecha_desde = $y."-".$m."-".$d; $where[] = "t_c.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_c.fecha_alta <= ".quote($fecha_hasta); }
if (isset($filtro['usuario_alta'])) { $where[] = "t_c.usuario_alta ILIKE ".quote("%{$filtro['usuario_alta']}%"); } if (isset($filtro['estado'])) { $where[] = "t_c.estado = '".$filtro['estado']."'"; } if (isset($filtro['portada'])) { $where[] = "t_c.portada = '".$filtro['portada']."'"; }
if (isset($filtro['limit'])) { $limit = "limit '".$filtro['limit']."' "; }
$sql = "SELECT t_c.id_carta, t_c.volanta, t_c.titulo, t_c.bajada, t_c.texto, t_c.foto, CASE WHEN t_c.foto IS NOT NULL THEN '<img src=\"fotos/'||t_c.foto||'\" height=\"100\" width=\"100\">' ELSE '' END as url_foto, t_c.epigrafe, t_c.portada, t_c.fecha_alta, t_c.usuario_alta, t_c.estado, t_c.orden, t_c.lecturas FROM carta as t_c $order $limit $offset";
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); }
$datos = toba::db('tdfonline')->consultar($sql);
if(count($datos)>0){ foreach($datos as $key => $dato){ switch($dato['estado']){
case '0': $datos[$key]['estado_descripcion'] = 'Pendiente'; break;
case '1': $datos[$key]['estado_descripcion'] = 'Aprobado'; break;
case '2': $datos[$key]['estado_descripcion'] = 'Rechazado'; break;
case '3': $datos[$key]['estado_descripcion'] = 'Cancelado'; break;
default: $datos[$key]['estado_descripcion'] = 'Sin definir'; } } }
return $datos; }
function get_cantidad($filtro=array()) { $where = array();
if (isset($filtro['id_carta'])) { $where[] = "t_c.id_carta = '".$filtro['id_carta']."'"; }
if (isset($filtro['titulo'])) { $where[] = "t_c.titulo ILIKE ".quote("%{$filtro['titulo']}%"); }
if (isset($filtro['fecha_desde'])) { list($y,$m,$d)=explode("-",$filtro['fecha_desde']); //2011-03-31 $fecha_desde = $y."-".$m."-".$d; $where[] = "t_c.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_c.fecha_alta <= ".quote($fecha_hasta); }
if (isset($filtro['usuario_alta'])) { $where[] = "t_c.usuario_alta ILIKE ".quote("%{$filtro['usuario_alta']}%"); } if (isset($filtro['estado'])) { $where[] = "t_c.estado = '".$filtro['estado']."'"; } if (isset($filtro['portada'])) { $where[] = "t_c.portada = '".$filtro['portada']."'"; }
$sql = "SELECT count(t_c.id_carta) as cantidad FROM carta as t_c"; if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); }
$dato = toba::db('tdfonline')->consultar_fila($sql); return $dato['cantidad']; }
function get_last_carta(){ $sql = "SELECT max(id_carta) as id_carta FROM carta"; $dato = toba::db('tdfonline')->consultar_fila($sql);
return $dato['id_carta'];
}
function get_foto($id_carta = '') { #if(!empty($id_carta)){ $sql = "SELECT foto FROM carta WHERE id_carta = '$id_carta'"; return toba::db('tdfonline')->consultar_fila($sql); #} }
function activar_desactivar($id_carta){
$sql = "SELECT estado FROM carta WHERE id_carta = '$id_carta'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
if($dato['estado']== 'A'){ $estado = 'I'; }elseif($dato['estado']== 'I'){ $estado = 'A'; }else{ return false; }
$sql = "UPDATE carta SET estado = '$estado' WHERE id_carta = '$id_carta'"; toba::db('tdfonline')->ejecutar($sql); return true; }
function set_portada($array_datos){ $sql = "UPDATE carta SET portada = 0 WHERE portada = 1"; toba::db('tdfonline')->ejecutar($sql); foreach($array_datos as $dato){ if(!empty($dato['id_carta'])){ $sql = "UPDATE carta SET portada = 1 WHERE id_carta = '".$dato['id_carta']."'"; toba::db('tdfonline')->ejecutar($sql); return true; } } }
function set_lecturas($id_carta){
$sql = "SELECT lecturas FROM carta WHERE id_carta = '$id_carta'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$lecturas = $dato['lecturas'] + 1;
$sql = "UPDATE carta SET lecturas = $lecturas WHERE id_carta = '$id_carta'"; if(toba::db('tdfonline')->ejecutar($sql)){ return true; }else{ return false; } }
function set_estado($id_carta,$estado){ $sql = "UPDATE carta SET estado = '$estado' WHERE id_carta = '$id_carta'"; toba::db('tdfonline')->ejecutar($sql); }
function eliminar_carta($id_carta) { $sql = "SELECT foto FROM carta WHERE id_carta = '$id_carta'"; $dato = toba::db('tdfonline')->consultar_fila($sql);
$sql = "DELETE FROM carta WHERE id_carta = '$id_carta'"; 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; } } }else{ return false; } }
function get_descripciones() { $sql = "SELECT id_carta, titulo as descripcion_html FROM carta ORDER BY titulo"; return toba::db('tdfonline')->consultar($sql); }
//----------------------------------------------------------------------------------- //---- Descripciones para portada borrador ------------------------------------------ //-----------------------------------------------------------------------------------
//retorna un array con las cartas aprobadas por el moderardor function get_activas($filtro=array()){
$sql = "SELECT t_c.id_carta, t_c.titulo, t_c.fecha_alta, t_c.usuario_alta, t_au.nombre as usuario_nombre, '#'||t_c.id_carta||' '||t_c.fecha_alta||' | '||t_c.titulo as descripcion FROM carta as t_c LEFT OUTER JOIN desarrollo.apex_usuario as t_au ON (t_au.usuario = t_c.usuario_alta) WHERE t_c.estado = '1'"; //AND t_c.portada = 1
if (count($where)>0) { $sql = sql_concatenar_where($sql, $where); }
return toba::db('tdfonline')->consultar($sql); }
}
?>
|