tipo) ) $V_http->tipo = 1; // Especiales
if ( ! isset($V_http->tema) ) $V_http->tema = -1; // Todos
if ( ! isset($V_http->este_dia) ) $V_http->este_dia = 0; // Hoy
if ( ! isset($V_http->id) ) $V_http->id = 0; // id del programa
if ( ! isset($V_http->orden) ) $V_http->orden = "prog"; // prog|lug
if ( $V_http->q ) {
// Primero busco los que duran menos de 3
$programas = ProgActivos($V_http->tipo,$V_http->tema,$V_http->este_dia,
$V_http->id,$V_http->orden,3);
// Si no hay nada, busco los que duran 6
if ( ! is_array($programas) || ! count($programas) )
$programas = ProgActivos($V_http->tipo,$V_http->tema,$V_http->este_dia,
$V_http->id,$V_http->orden,6);
if ( ! is_array($programas) || ! count($programas) ) {
$error = "No hay resultados para esta búsqueda";
} else if ( $V_http->id ) {
// Especial para desplegar 1 programa en una ventana miniwin
$t = TPL_Crear("programa.htm");
$t = CargoListaProgramas_tpl($t,$programas);
TPL_Fin($t);
exit();
}
}
if ( isset($V_http->q) && ! isset($error) ) {
$tpl = SetTpl($V_http->tipo,$V_http->tema, $V_http->este_dia, $V_http->orden);
$t = TPL_Crear($tpl);
// En que sentido se ordena la salida de cines, teatros...
// Por programa o por lugar
if ( ($V_http->tipo == 1 || // Teatros
$V_http->tipo == 7) && // Cines
$V_http->orden != "prog" ) {
$t = CargoListaLugares_tpl($t,$programas);
} else {
$t = CargoListaProgramas_tpl($t,$programas);
}
// Solo en algunos dejo cambiar el orden de la salida
if ( $V_http->tipo != 1 && // Teatros
$V_http->tipo != 7) // Cines
$t = TPL_DelBlk($t,"cambiar_orden");
$t->setvar("tipo",$V_http->tipo);
$t->setvar("tema",$V_http->tema);
if ( $V_http->q == "x" )
$t->setvar("del_dia","Destacados de hoy");
else
$t->setvar("del_dia",$dia[$V_http->este_dia]);
$t->setvar("q",$V_http->q);
//Para que la lista de temas de un tipo este
// disponible en el frame principal
if ( $V_http->tipo > 0 ) {
$t = TPL_CargoBloque($t,"bloque_subseccion",
Temas($categoria,$V_http->tipo),"id_bloque_subseccion",
$V_http->tema);
}
} else {
$t = Set_TPLBuscar();
}
$t2 = TPL_Crear("portada.htm");
$t2->setvar("cartelera",$t->parse("ANY",$t->nombre));
$t2 = CotizacionMoneda($t2);
TPL_Fin($t2);
exit();
function Set_TPLBuscar(){
global $categoria, $V_http, $dia;
$t = TPL_Crear("buscar.htm");
$t = TPL_CargoBloque($t,"bloque_dia",$dia,"id_bloque_dia",$V_http->este_dia);
$t = TPL_CargoBloque($t,"bloque_seccion",Tipos($categoria),
"id_bloque_seccion",$V_http->tipo);
if ( $V_http->tipo < 0 ) {
$t = TPL_DelBlk($t, "bloque_temas");
} else {
$t = TPL_CargoBloque($t,"bloque_subseccion",
Temas($categoria,$V_http->tipo),"id_bloque_subseccion",
$V_http->tema);
}
return $t;
}
function Tipos($categoria) {
asort($categoria);
while (list($k,$v) = each($categoria)) {
$data[$k] = $v->nombre;
}
$data[-1] = "Todos";
return $data;
}
function Temas($categoria,$tipo) {
if ( $tipo < 0 ) return;
$temas = $categoria[$tipo]->temas;
asort($temas);
while (list($k,$v) = each($temas)) {
$data[$k] = $v;
}
$data[-1] = "Todos";
return $data;
}
function SetTpl($tipo,$tema,$dia,$orden) {
global $tpldir;
if ( $dia > 6 )
return "resumen_${orden}.htm";
else if ( is_file ("$tpldir/cartelera_${orden}_${tipo}_${tema}.htm") )
return "cartelera_${orden}_${tipo}_${tema}.htm";
else if ( is_file ("$tpldir/cartelera_${orden}_${tipo}.htm") )
return "cartelera_${orden}_${tipo}.htm";
return "cartelera_${orden}.htm";
}
//
// Programas Activos para el dia indicado (0=hoy)
//
// tipo = -1 => Todos los tipos. Implica dia < 7
// tema = -1 => Todos los temas
//
// dia = 7 => todos los < 30 dias y del tipo indicado
// dia = 8 => todos los > 30 dias y del tipo indicado
//
// Orden = prog|lug sacar el array ordenado por programa
// o por lugar
//
function ProgActivos ($tipo,$tema,$dia,$id=0,$orden="prog",$days_left=3) {
global $db,$HOY;
// Si no tengo tipo => no permito listado completo: default HOY
if ( $dia > 6 && $tipo < 0 ) $dia = 0;
if ( $id ) { // solo este programa
$restrict = "funcion.id_programa = $id";
} else if ( $dia == 8 ) { // empiezan dentro de mas de 30 dias
$este_dia = date('Y-m-d',$HOY+(30*SECSXDIA));
$restrict = "funcion.f_ini >= '$este_dia'";
} else if ( $dia == 7 ) { // activos o empiezan entre hoy los prox 30 dias
$este_dia = date('Y-m-d',$HOY+(30*SECSXDIA));
$restrict = "funcion.f_fin >= now() and funcion.f_ini <= '$este_dia'";
} else if ( $tipo < -1 ) { // especiales
$este_dia = date('Y-m-d',$HOY+($dia*SECSXDIA));
$restrict = "funcion.f_ini <= '$este_dia' and funcion.f_fin >= '$este_dia'
and datediff(funcion.f_fin, funcion.f_ini) <= $days_left";
} else { // activos este_dia
$este_dia = date('Y-m-d',$HOY+($dia*SECSXDIA));
$restrict = "funcion.f_ini <= '$este_dia' and funcion.f_fin >= '$este_dia'";
}
$entry = array();
if ( ! $id && $tipo >= 0 ) {
$restrict .= " and tipo=$tipo";
if ( $tema >= 0 )
$restrict .= " and tema=$tema";
}
$query = "select programas.*, lugares.*, funcion.*,
date_format(funcion.f_ini,'%d.%m.%y') as f_desde
from funcion left join lugares on funcion.id_lugar = lugares.id
left join programas on funcion.id_programa = programas.id
where $restrict order by funcion.f_ini";
// print "QR: $query
";
$db->Query($query);
if ( $orden == "lug" ) {
// Array de funciones: lugares x programas
while ( $funcion = $db->FetchRow() ) {
$id_func = $funcion['id'];
$id_progr = $funcion['id_programa'];
$id_lugar = $funcion['id_lugar'];
$funcion['speech'] = stripslashes($funcion['speech']);
$funcion['titulo'] = stripslashes($funcion['titulo']);
if ( strlen($funcion['speech']) < 10 ) continue;
$entry[$id_lugar][$id_progr] = $funcion;
}
} else { // default orden="prog"
// Array de funciones: programas x lugares
while ( $funcion = $db->FetchRow() ) {
$id_func = $funcion['id'];
$id_progr = $funcion['id_programa'];
$id_lugar = $funcion['id_lugar'];
$funcion['speech'] = stripslashes($funcion['speech']);
$funcion['titulo'] = stripslashes($funcion['titulo']);
if ( strlen( $funcion['speech'] ) < 10 ) continue;
$entry[$id_progr][$id_lugar] = $funcion;
}
}
return $entry;
}
function CargoListaProgramas_tpl($t,$entry) {
global $db;
$t->set_block($t->nombre,"lugares_lista","blk_lugares_lista");
$t->set_var("blk_lugares_lista","");
$t->set_block($t->nombre,"programas_lista","blk_programas_lista");
$t->set_var("blk_programas_lista","");
$prog_id = 0;
// Por cada programa, por cada lugar
while ( list($id_programa,$data) = each($entry) ) {
$programa = current($data);
while ( list($id_lugar,$row) = each($data) ) {
$t->set_var($row);
$t->parse("blk_lugares_lista","lugares_lista",true);
}
$t = ParsePrograma_tpl($t,$programa);
}
return $t;
}
function CargoListaLugares_tpl($t,$entry) {
$t->set_block($t->nombre,"programas_lista","blk_programas_lista");
$t->set_var("blk_programas_lista","");
$t->set_block($t->nombre,"lugares_lista","blk_lugares_lista");
$t->set_var("blk_lugares_lista","");
$prog_id = 0;
// Por cada lugar, por cada programa
while ( list($id_lugar,$data) = each($entry) ) {
$lugar = current($data);
while ( list($id_programa,$row) = each($data) ) {
$t->setvar($row);
$t->parse("blk_programas_lista","programas_lista",true);
}
$t->setvar($lugar);
$t->parse("blk_lugares_lista","lugares_lista",true);
$t->set_var("blk_programas_lista","");
}
return $t;
}
function CargoFotos($id) {
global $homedir, $wwwdir, $cant_fotos;
$foto = "$homedir/fotos/programas/$id";
$fotos = array();
$maxw = 150; $maxh = 150;
for ($i=0; $i<$cant_fotos; $i++) {
if ( is_file("${foto}_$i.jpg") ) {
$wh = getImgWH("${foto}_$i.jpg",$maxw,$maxh);
$w = $wh[0]; $h = $wh[1];
$fotos["foto_$i"] = "";
} else if ( is_file("${foto}_$i.png") ) {
$wh = getImgWH("${foto}_$i.png",$maxw,$maxh);
$w = $wh[0]; $h = $wh[1];
$fotos["foto_$i"] = "";
} else if ( is_file("${foto}_$i.gif") ) {
$wh = getImgWH("${foto}_$i.gif",$maxw,$maxh);
$w = $wh[0]; $h = $wh[1];
$fotos["foto_$i"] = "";
} else {
$fotos["foto_$i"] = "";
}
// print "CF: $id".$fotos["foto_$i"]."
";
}
return $fotos;
}
function getImgWH($file,$maxw,$maxh) {
$data = getimagesize($file);
/* Calculo la relacion W/H segun cada limite */
$x0 = $maxw / $data[0];
$x1 = $maxh / $data[1];
/* Tomo el menor de los dos y determino newh y neww */
$x = ( $x0 < $x1 ? $x0 : $x1 );
$newh = round($data[1] * $x);
$neww = round($data[0] * $x);
return array($neww,$newh);
}
function ParsePrograma_tpl($t,$row) {
global $homedir;
$fotos = CargoFotos($row['id_programa']);
$t->setvar($fotos);
$t = TipoTemaNotaApta_tpl($t,$row['tipo'],$row['tema'],
$row['nota'],$row['apta']);
$t->set_var($row);
$t->parse("blk_programas_lista","programas_lista",true);
$t->set_var("blk_lugares_lista","");
return $t;
}
function TipoTemaNotaApta_tpl($t,$tipo,$tema,$nota,$apta) {
global $categoria, $a_nota, $a_apta;
$t->set_var("id_tipo",$tipo);
$t->set_var("nombre_tipo",$categoria[$tipo]->nombre);
// reset($categoria[$tipo]->temas);
$t->set_var("id_tipo",$tipo);
$t->set_var("nombre_tipo",$categoria[$tipo]->nombre);
$a_tema = $categoria[$tipo]->temas;
foreach ( array('tema', 'nota','apta') as $x ) {
$t->set_var("id_$x",$$x);
$t->set_var("nombre_$x",${"a_$x"}[$$x]);
}
return $t;
}
?>