#!/usr/bin/perl use Common; use CGI qw /param cookie/; use DBI; use HTML::Entities; use strict; use Vista; use Date::Calc qw/Add_Delta_Days Add_Delta_YMD Today/; use Repetir; my $user_id = &loguea_usuario; unless (defined $user_id and $user_id) { print "Location: http://www.speedy.com.ar/speedynegocios/b/agenda.html\n\n"; exit; } my $vista_id = param('v') || 1; my $fecha = param('t') || time; my $funcion = param('f') || 'ingreso_agenda'; my $ag_evento_id = param('ae') || 0; my $ag_diaria_id = param('ad') || 0; my $vrec = param('vrec'); #Indica si mostrar los recordatorios my $vrep = param('vrep'); #Indica si mostrar las repeticiones my $vinv = param('vinv'); #Indica si mostrar las invitaciones my $vrep = param('vrep'); #Indica si mostrar las repeticiones my $reload = param('reload') || 0; #Indica si la página se está refrescando my $evento_id = param('ev') || 0; my $aname = param('aname'); #Indica el desplazamiento adentro de la pagina my $dbh = DBI->connect(@::DBI_AGENDA) || &error_html("Error de Conexión"); SWITCH: { &ingreso_agenda , last SWITCH if ($funcion=~/ingreso_agenda/); &opciones_agenda , last SWITCH if ($funcion=~/opciones_agenda/); &guarda_agenda , last SWITCH if ($funcion=~/guarda_agenda/); &vista_agenda , last SWITCH if ($funcion=~/ver_ag/); &edita_evento , last SWITCH if ($funcion=~/ver_ev/); &guarda_evento, last SWITCH if ($funcion =~/guarda_evento|guarda_y_nuevo/); &confirma_borrar_evento, last SWITCH if ($funcion =~/bor_ev/); &baja_evento, last SWITCH if ($funcion =~/baja_evento/); &baja_inv, last SWITCH if ($funcion =~/baja_inv/); &envia_invitacion, last SWITCH if ($funcion =~/envia_inv/); &busca_evento_terra, last SWITCH if ($funcion =~/bus_ev_terra/); &aviso_legal, last SWITCH if ($funcion =~/aviso_legal/); &ayuda, last SWITCH if ($funcion =~/ayuda/); &portada, last SWITCH if ($funcion =~/portada_dia/); } $dbh->disconnect; #---------------------------------------------------------------------------- # Script que ingresa a la agenda #---------------------------------------------------------------------------- sub ingreso_agenda { #Verifica si el usuario ya tiene agenda asociada my @row = $dbh->selectrow_array(<<'SQL', undef, $user_id); SELECT vista_id FROM agenda WHERE agenda_id = ? SQL $vista_id = (defined $row[0])?$row[0]:1; #Si ya tiene agenda asociada, entonces muestra la agenda en base a la vista seleccionada #Si no, ingresa directamente a configurar la agenda (scalar(@row) > 0)?&vista_agenda:&opciones_agenda; } #---------------------------------------------------------------------------- # Script que edita las opciones de la agenda #---------------------------------------------------------------------------- sub opciones_agenda { my @f = localtime(time); $f[5] += 1900; my $hr = &datos_usuario($user_id); my $tmp = new HTML::Template('filename' => "$::DIR_TEMPLATES/opciones.html"); my $txt = &html_bienvenido($user_id); $tmp->param('OP_BIENVENIDA' => $txt); $tmp->param('OP_FECHA' => $fecha); $txt = &calendario_dia($dbh, $user_id, 0, @f); $tmp->param('CALENDARIO' => $txt); $txt = &html_opciones($user_id, $hr->{'mail'}, 1, $dbh); $tmp->param('FORM_OPCIONES' => $txt); $txt = ''; $tmp->param('URL_MODIFICAR' => $txt); print "Content-type:text/html\n\n"; print $tmp->output; } #---------------------------------------------------------------------------- # Guarda en la BD las opciones de la agenda #---------------------------------------------------------------------------- sub guarda_agenda { &guarda_bd_agenda($user_id, $dbh); &vista_agenda; } #---------------------------------------------------------------------------- # #---------------------------------------------------------------------------- sub vista_agenda { my $tmp; if ($vista_id==1) { $tmp = new HTML::Template(filename => 'templates/vista_diaria.html'); $tmp = &vista_diaria($tmp, $dbh, $fecha, $user_id); } elsif ($vista_id==2) { $tmp = new HTML::Template(filename => 'templates/vista_semana.html'); $tmp = &vista_semana($tmp, $dbh, $fecha, $user_id) } elsif ($vista_id == 3) { $tmp = new HTML::Template(filename => 'templates/vista_mensual.html'); $tmp = &vista_mensual($tmp, $dbh, $fecha, $user_id) } else { $tmp = new HTML::Template(filename => 'templates/vista_anual.html'); $tmp = &vista_anual($tmp, $dbh, $fecha, $user_id) } print "Content-type:text/html\n\n"; print $tmp->output } #---------------------------------------------------------------------------- # HTML de edición de eventos #---------------------------------------------------------------------------- sub edita_evento { my ($categoria_id, $titulo, $domicilio, $lugar_d, $telefono, $privado, $comentario, $fevento); my (@afecha, @hdesde, @hhasta); my $opt_categ; my $tipo_repeticion_id; my @row; @afecha = localtime($fecha); $afecha[5] += 1900; #Obtiene los datos del evento if ($ag_diaria_id and !$reload){ @row = $dbh->selectrow_array(<<'SQL', undef, $ag_diaria_id, $user_id); SELECT unix_timestamp(ad.fecha), time_format(ad.hora_desde, '%H:%i'), time_format(ad.hora_hasta, '%H:%i'), ad.categoria_id, ad.titulo, ad.lugar_d, ad.domicilio, ad.telefono, ad.privado, ad.comentario, ad.ag_evento_id, ae.tipo_repeticion_id, ae.evento_id, date_format(ae.fecha, '%Y/%m/%d') FROM agenda_diaria ad, agenda_evento ae WHERE ad.ag_diaria_id = ? AND ad.ag_evento_id = ae.ag_evento_id AND ae.agenda_id = ? SQL $fecha = $row[0]; @hdesde = split(':', $row[1]); @hhasta = split(':', $row[2]); $categoria_id = $row[3]; $titulo = encode_entities $row[4]; $lugar_d = encode_entities $row[5]; $domicilio = encode_entities $row[6]; $telefono = encode_entities $row[7]; $privado = ($row[8] == 1)?'CHECKED':''; $comentario = encode_entities $row[9]; $ag_evento_id = $row[10]; @afecha = localtime($fecha); $afecha[5] += 1900; $tipo_repeticion_id = $row[11]; $evento_id = $row[12]; $fevento = $row[13]; } elsif($reload) { $afecha[3] = param('dia_desde'); $afecha[4] = param('mes_desde'); $afecha[5] = param('anio_desde'); $hdesde[0] = param('hora_desde'); $hdesde[1] = param('min_desde'); $hhasta[0] = param('hora_hasta'); $hhasta[1] = param('min_hasta'); $categoria_id = param('categoria_id') || undef; $titulo = param('titulo') || undef; $lugar_d = param('lugar_d') || undef; $domicilio = param('domicilio') || undef; $telefono = param('telefono') || undef; $privado = (defined param('privado'))?'CHECKED':''; $comentario = param('comentario') || undef; $tipo_repeticion_id = param('repetir'); $fevento = param('fevento') || undef; } elsif (!$ag_diaria_id and $evento_id) { my $dbhev = DBI->connect(@::DBI_EVENTO) || &error_html("Error de conexion"); @row = $dbhev->selectrow_array(<<'SQL', undef, $evento_id); SELECT unix_timestamp(e.fecha), time_format(e.hora, '%H:%i'), time_format(e.hora_hasta, '%H:%i'), e.detalle, e.tipo_repeticion_id, e.lugar_id, date_format(e.fecha, '%Y/%m/%d') FROM eventos e WHERE e.evento_id = ? SQL $fecha = $row[0]; @hdesde = split(':', $row[1]); @hhasta = split(':', $row[2]); $titulo = encode_entities $row[3]; @afecha = localtime($fecha); $afecha[5] += 1900; $tipo_repeticion_id = $row[4]; $lugar_d = $row[5]; $domicilio = ''; $telefono = ''; $fevento = $row[6]; $dbhev->disconnect; } #Arma el select de categoría my $ar = $dbh->selectall_arrayref('select categoria_id, detalle from categoria_evento order by detalle') || &error_html($dbh->errstr); $opt_categ .= &arma_opts($categoria_id, $ar); #Arma el select de mes my $opt_mesdesde = &cb_meses($afecha[4]); #Arma el select de hora my $opt_hdesde = &cb_horas((scalar(@hdesde))?$hdesde[0]:$afecha[2]); my $opt_hhasta = &cb_horas((scalar(@hhasta))?$hhasta[0]:$afecha[2] + 1); #Arma el select de minutos my $opt_mdesde = &cb_minutos((scalar(@hdesde))?$hdesde[1]:$afecha[1]); my $opt_mhasta = &cb_minutos((scalar(@hhasta))?$hhasta[1]:$afecha[1]); my $tmp = new HTML::Template('filename' => "$::DIR_TEMPLATES/edita_evento.html"); my @f = localtime($fecha); $f[5] += 1900; $tmp->param('CALENDARIO' => &calendario_dia($dbh, $user_id, 0, @f)); $tmp->param('VA_DIARIA_ID' => $ag_diaria_id); $tmp->param('VA_AG_EVENTO_ID' => $ag_evento_id); $tmp->param('VA_VISTA_ID' => $vista_id); $tmp->param('VA_VREC' => $vrec); $tmp->param('VA_VREP' => $vrep); $tmp->param('VA_VINV' => $vinv); $tmp->param('VA_FECHA' => $fecha); $tmp->param('VA_EVENTO_ID' => $evento_id); $tmp->param('VA_FEVENTO' => $fevento); $tmp->param('VA_TITULO' => $titulo); $tmp->param('VA_CATEG' => $opt_categ); $tmp->param('VA_PRIVADO' => $privado); $tmp->param('VA_LUGARD' => $lugar_d); $tmp->param('VA_DOMICILIO' => $domicilio); $tmp->param('VA_TELEFONO' => $telefono); $tmp->param('VA_COMENTARIO' => $comentario); $tmp->param('VA_MESDESDE' => $opt_mesdesde); $tmp->param('VA_DIADESDE' => $afecha[3]); $tmp->param('VA_ANIODESDE' => $afecha[5]); $tmp->param('VA_HORADESDE' => $opt_hdesde); $tmp->param('VA_MINDESDE' => $opt_mdesde); $tmp->param('VA_HORAHASTA' => $opt_hhasta); $tmp->param('VA_MINHASTA' => $opt_mhasta); if ($tipo_repeticion_id > 0 and $ag_evento_id) { $tmp->param('IF_ACTUALIZA' => 1); } $tmp->param('VA_ANAME' => $aname); #$tmp->param('VA_' => ); #$tmp->param('VA_' => ); #$tmp->param('VA_' => ); #$tmp->param('VA_' => ); $tmp->param(&html_repetir); $tmp->param(&html_recordatorio); $tmp->param(&html_invitacion); print "Content-type:text/html\n\n"; print $tmp->output(); } #--------------------------------------------------------------------------- # Arma el HTML de repetición #--------------------------------------------------------------------------- sub html_repetir { my %hvar; my (@fecha_hasta, $tipo_frecuencia_id, $frecuencia, $dia_repeticion, $tipo_repeticion); my ($opt_mhasta, $opt_dia, $opt_cada4, $opt_cada5, $orden_repeticion, $repetir_hasta); my @repetir = ('','', '', '', '',''); #Obtengo los datos del esquema if ($ag_evento_id and !$reload) { my @row = $dbh->selectrow_array(<<'SQL', undef, $ag_evento_id); SELECT date_format(fecha_hasta, "%d/%m/%Y"), tipo_repeticion_id, tipo_frecuencia_id, frecuencia, orden_repeticion, dia_repeticion FROM agenda_evento WHERE ag_evento_id = ? SQL $repetir_hasta = 1; if (defined $row[0]){ @fecha_hasta = split('/', $row[0]); $fecha_hasta[1]--; $repetir_hasta = 2; } $tipo_repeticion = $row[1]; $repetir[$tipo_repeticion] = 'CHECKED'; $tipo_frecuencia_id = $row[2]; $frecuencia = $row[3]; $orden_repeticion = $row[4]; $dia_repeticion = ($row[1] == 5)?index($row[5], '1'):$row[5]; } elsif($reload) { #Es un reload $tipo_repeticion = param('repetir')||0; $repetir[$tipo_repeticion] = 'CHECKED'; if ($tipo_repeticion == 4) { $frecuencia = param('cada4'); $dia_repeticion = '0000000'; my @dias = param('dia4'); substr($dia_repeticion,$_,1) = 1 foreach (@dias); } elsif ($tipo_repeticion==5) { $frecuencia = param('cada5'); $orden_repeticion = param('orden5') || 1; $dia_repeticion = param('dia5'); } $repetir_hasta = param('repetir_hasta'); @fecha_hasta = (param('dia_hasta'), param('mes_hasta'), param('anio_hasta')) if (defined param('mes_hasta')); } elsif (!$ag_evento_id and $evento_id) { #Si es nuevo y viene de un evento de la BD de Terra, entonces obtiene los datos my @row = $dbh->selectrow_array(<<'SQL', undef, $evento_id); SELECT date_format(fecha_hasta, "%d/%m/%Y"), tipo_repeticion_id, tipo_frecuencia_id, frecuencia, orden_repeticion, dia_repeticion FROM evento.eventos WHERE evento_id = ? SQL $repetir_hasta = 1; if (defined $row[0]){ @fecha_hasta = split('/', $row[0]); $fecha_hasta[1]--; $repetir_hasta = 2; } $tipo_repeticion = $row[1]; $repetir[$tipo_repeticion] = 'CHECKED'; $tipo_frecuencia_id = $row[2]; $frecuencia = $row[3]; $orden_repeticion = $row[4]; $dia_repeticion = ($row[1] == 5)?index($row[5], '1'):$row[5]; } #Si el evento es de terra y no tiene repeticiones, no se muestra nada, ni el recuadro if ($evento_id and !$tipo_repeticion) { $hvar{'MUESTRA_REP'} = 0; return \%hvar; } else { $hvar{'MUESTRA_REP'} = 1; $hvar{'REP_IMG'} = ($vrep)?'img/bt_menos.gif':'img/bt_mas.gif'; $hvar{'REP_IMG_ALT'} = ($vrep)?'':'alt="Ver más"'; } #Si no se muestra, entonces pone todo hidden unless ($vrep) { $hvar{'REP_INTERIOR'} = 0; $hvar{'REP_HIDDENS'} .=<< "EOF"; EOF foreach (0..6) { next unless (substr($dia_repeticion, $_, 1)); $hvar{'REP_HIDDENS'} .= sprintf "\n", $_; } return \%hvar; } $hvar{'REP_INTERIOR'} = 1; #Fecha $opt_mhasta = &cb_meses($fecha_hasta[1]); $opt_dia = &cb_dias($dia_repeticion); foreach (1..4){ $opt_cada4 .= sprintf '\n", $i, ($repetir[5] and $orden_repeticion==$i)?'SELECTED':'', $::ORDEN[$i] ; } $hvar{'REP_TIPO_5_DIA'} = $opt_dia; $hvar{'REP_TIPO_5_CADA'} = $opt_cada5; $hvar{'REP_HASTA_1'} = ($repetir_hasta == 1)?'CHECKED':''; $hvar{'REP_HASTA_2'} = ($repetir_hasta == 2)?'CHECKED':''; $hvar{'REP_HASTA_DIA'} = $fecha_hasta[0]; $hvar{'REP_HASTA_MES'} = $opt_mhasta; $hvar{'REP_HASTA_ANIO'} = $fecha_hasta[2]; return %hvar; } #--------------------------------------------------------------------------- # Arma el HTML de recordatorios #--------------------------------------------------------------------------- sub html_recordatorio { my %hvars; my ($sms_rec, $sms_minuto, $mail_rec, $mail_minuto, $mail_dir, $sms_minuto2, $mail_minuto2); my @row; my $op_smsrec; my $op_smsrec2; my $op_mailrec; my $op_mailrec2; #Obtiene el mail default @row = $dbh->selectrow_array('select mail, user_sms_id from agenda where agenda_id = ?', undef, $user_id); $mail_dir = $row[0]; my $user_sms_id = $row[1]; #Obtengo los datos ingresados si el evento existe if ($ag_diaria_id and !$reload) { @row = $dbh->selectrow_array(<<'SQL', undef, $ag_diaria_id); SELECT sms_rec, sms_minuto, mail_rec, mail_minuto, mail_dir, sms_minuto2, mail_minuto2 FROM agenda_alerta WHERE ag_diaria_id = ? SQL $sms_rec = ($row[0] == 1)?'CHECKED':''; $sms_minuto = $row[1]; $mail_rec = ($row[2] == 1)?'CHECKED':''; $mail_minuto = $row[3]; $mail_dir = ($row[4])?$row[4]:$mail_dir; $sms_minuto2 = $row[5]; $mail_minuto2 = $row[6]; } elsif($reload) { $sms_rec = (defined param('sms_rec'))?'CHECKED':''; $mail_rec = (defined param('mail_rec'))?'CHECKED':''; $sms_minuto = param('sms_minuto') || undef if ($sms_rec); $sms_minuto2 = param('sms_minuto2') || undef if ($sms_rec); $mail_dir = param('mail_dir') || undef; if ($mail_rec) { $mail_minuto = param('mail_minuto') || undef; $mail_minuto2 = param('mail_minuto2') || undef; } } $hvars{'REC_IMG'} = ($vrec)?'img/bt_menos.gif':'img/bt_mas.gif'; $hvars{'REC_IMG_ALT'} = ($vrec)?'':'alt="Ver más"'; $hvars{'REC_USER_SMS_ID'} = $user_sms_id; unless ($vrec) { $hvars{'REC_INTERIOR'} = 0; $hvars{'REC_HIDDENS'} .= "\n" if ($sms_rec); $hvars{'REC_HIDDENS'} .= "\n" if ($mail_rec); $hvars{'REC_HIDDENS'} .=<< "EOF"; EOF return \%hvars; } $hvars{'REC_INTERIOR'} = 1; $op_smsrec = &cb_recordar($sms_minuto); $op_mailrec = &cb_recordar($mail_minuto); $op_smsrec2 = &cb_recordar($sms_minuto2); $op_mailrec2 = &cb_recordar($mail_minuto2); $op_smsrec2 = '' . $op_smsrec2; $op_mailrec2 = '' . $op_mailrec2; $hvars{'REC_SMS_REC'} = $sms_rec; $hvars{'REC_SMS_MINUTO'} = $op_smsrec; $hvars{'REC_SMS_MINUTO2'} = $op_smsrec2; $hvars{'REC_MAIL_REC'} = $mail_rec; $hvars{'REC_MAIL_MINUTO'} = $op_mailrec; $hvars{'REC_MAIL_MINUTO2'} = $op_mailrec2; $hvars{'REC_MAIL_DIR'} = $mail_dir; return \%hvars; } #--------------------------------------------------------------------------- # Arma el HTML de invitaciones #--------------------------------------------------------------------------- sub html_invitacion { my %hvars; my $ar; my $estado_id = -1; my $usu_terra = param('usu_terra') || undef; my $usu_no_terra = param('usu_no_terra') || undef; my $msg_invitado; #Obtengo los datos ingresados si el evento existe if ($ag_diaria_id and !$reload) { $ar = $dbh->selectall_arrayref('SELECT msg_invitado FROM agenda_evento WHERE ag_evento_id = ?', undef, $ag_evento_id); $msg_invitado = encode_entities $ar->[0]->[0]; } elsif($reload) { $msg_invitado = param('msg_invitado') || undef; } $hvars{'INV_IMG'} = ($vinv)?'img/bt_menos.gif':'img/bt_mas.gif'; $hvars{'INV_IMG_ALT'} = ($vinv)?'':'alt="Ver más"'; unless ($vinv) { $hvars{'INV_INTERIOR'} = 0; $hvars{'INV_HIDDENS'} .=<< "EOF"; EOF return \%hvars; } $hvars{'INV_INTERIOR'} = 1; $hvars{'INV_USU_TERRA'} = $usu_terra; $hvars{'INV_USU_NO_TERRA'} = $usu_no_terra; $hvars{'INV_MSG_INV'} = $msg_invitado; my @loop_est; if ($ag_evento_id) { $ar = $dbh->selectall_arrayref(<<'SQL', undef, $ag_evento_id) || &error_html($dbh->errstr); SELECT participante_id, estado_id, alias, mail FROM evento_participante WHERE ag_evento_id = ? ORDER BY estado_id, mail, alias SQL $estado_id = -1; for my $row(@{$ar}) { my %row; unless ($estado_id == $row->[1]) { $row{'INV_LO_CAB'} = 1; $row{'INV_LO_CAB_NAME'} = $::H_ESTADO{$row->[1]}; $estado_id = $row->[1]; } $row{'INV_LO_ALIAS'} = (defined $row->[2] and $row->[2])? $row->[2]: $row->[3]; $row{'INV_LO_PID'} = $row->[0]; $row{'INV_LO_AGID'} = $ag_diaria_id; $row{'INV_LO_VINV'} = $vinv; $row{'INV_LO_VREP'} = $vrep; $row{'INV_LO_VREC'} = $vrec; push @loop_est, \%row; } } $hvars{'INV_LO_ESTADOS'} = \@loop_est if (scalar(@loop_est)); return \%hvars; } #--------------------------------------------------------------------------- # Arma el select de meses #--------------------------------------------------------------------------- sub cb_meses { my $mes = shift; my $opt; foreach (0..11) { $opt .= sprintf "\n", $_, ($_ == $mes)?'SELECTED':'', $::MESES[$_]; } return $opt; } #--------------------------------------------------------------------------- # Arma el select de dias #--------------------------------------------------------------------------- sub cb_dias { my $dia = shift; my $opt; foreach (0..6) { $opt .= sprintf "\n", $_, ($_ == $dia)?'SELECTED':'', $::DIAS[$_]; } return $opt; } #---------------------------------------------------------------------------- # Rutina que da de alta o actualiza un evento #---------------------------------------------------------------------------- sub guarda_evento { my $ar; #las _bd, son las reales, las que van en la BD #las _pr, son las de proceso my @fdesde_pr; my $actualizar = param('actualizar') || 'todas'; my $tipo_repeticion_id = param('repetir') || 0; if (!$ag_evento_id or $actualizar =~ /sola/ or ($tipo_repeticion_id==0 and $actualizar =~ /todas/)) { @fdesde_pr = (param('anio_desde'), param('mes_desde'), param('dia_desde')); } else { @fdesde_pr = split('/', param('fevento')); $fdesde_pr[1]--; } $fdesde_pr[1]++; my $fdesde_bd = sprintf '%d/%d/%d', $fdesde_pr[0], $fdesde_pr[1], $fdesde_pr[2]; my $fhasta_bd = undef; my @fhasta_pr = undef; my @fechas; my @usu_terra; my @usu_no_terra; my $hora_desde = sprintf '%d:%d:00', param('hora_desde'), param('min_desde'); my $hora_hasta = sprintf '%d:%d:00', param('hora_hasta'), param('min_hasta'); my $categoria_id = param('categoria_id') || undef; my $titulo = param('titulo') || 'Evento'; my $comentario = param('comentario') || undef; my $lugar_d = param('lugar_d') || undef; my $domicilio = param('domicilio') || undef; my $telefono = param('telefono') || undef; my $privado = (defined param('privado'))?1:0; my $tipo_repeticion_id = param('repetir') || 0; my $repetir_hasta = param('repetir_hasta') || 1; my $sms_rec = (defined param('sms_rec'))?1:0; my $mail_rec = (defined param('mail_rec'))?1:0; my $msg_invitado = param('msg_invitado') || undef; @usu_terra = separa_por_coma(param('usu_terra')); @usu_no_terra = separa_por_coma(param('usu_no_terra')); my ($frecuencia, $tipo_frecuencia_id, $orden_repeticion, $dia_repeticion, @dias_rep); my ($sms_minuto, $mail_minuto, $mail_dir, $sms_minuto2, $mail_minuto2); my ($fecha_sms, $fecha_sms2, $fecha_mail, $fecha_mail2); #Verifica hasta cuando es la repeticion. #Si tiene repeticiones y tiene fecha_hasta. Si la fecha_hasta es menor que 3 meses para adelante #entonces se toma esa como fecha de proceso, si no es el último días del 3er mes. #Si tiene repeticiones y no fecha_hasta (por siempre), entonces es el último días del 3er mes if ($tipo_repeticion_id and $repetir_hasta == 2) { #Si tiene reptir con fecha hasta @fhasta_pr = (param('anio_hasta'), param('mes_hasta') + 1, param('dia_hasta')); $fhasta_bd = sprintf '%d/%d/%d', $fhasta_pr[0], $fhasta_pr[1], $fhasta_pr[2]; my @fhmas4 = Add_Delta_YMD(Today(), 0, 4, 0); $fhmas4[2] = 1; @fhmas4 = Add_Delta_Days(@fhmas4,-1); @fhasta_pr = (Date_to_Days(@fhasta_pr) <= Date_to_Days(@fhmas4))?@fhasta_pr:@fhmas4; } elsif ($tipo_repeticion_id and $repetir_hasta == 1){ @fhasta_pr = Add_Delta_YMD(Today(), 0, 4, 0); $fhasta_pr[2] = 1; @fhasta_pr = Add_Delta_Days(@fhasta_pr,-1); } #Obtiene un array con las fechas a insertar el evento, de acuerdo al tipo de repeticion if ($tipo_repeticion_id == 1) { #Repetir cada día $frecuencia = 1; $tipo_frecuencia_id = 1; @fechas = &repetir_1(@fdesde_pr, @fhasta_pr); } elsif ($tipo_repeticion_id == 2) { #Repetir cada mes $frecuencia = 1; $tipo_frecuencia_id = 3; @fechas = &repetir_2(@fdesde_pr, @fhasta_pr); } elsif ($tipo_repeticion_id == 3) { #Repetir cada 1 año $frecuencia = 1; $tipo_frecuencia_id = 4; $fechas[0] = join("/", @fdesde_pr); #Acá no debería hacerse ningún cálculo, porque solo es 3 meses para adelante } elsif ($tipo_repeticion_id == 4) { #Repetir cada (1-2-3-4) semanas los días (lun-mar-mie-jue-vie-sab-dom) $frecuencia = param('cada4') || 1; $tipo_frecuencia_id = 2; $dia_repeticion = '0000000'; @dias_rep = param('dia4'); for (@dias_rep) { substr($dia_repeticion,$_,1) = 1; } #si no se seleccionó ningún día, se toma el día de la semana de la fecha del evento if ($dia_repeticion eq '0000000') { $_ = Day_of_Week(@fdesde_pr); $_ = 0 if ($_ == 7); substr($dia_repeticion,$_,1) = 1; } @fechas = &repetir_4(@fdesde_pr, @fhasta_pr, $frecuencia, $dia_repeticion); } elsif ($tipo_repeticion_id == 5) { #Repetir el (primero-segundo-tercero-cuarto-ultimo) (lun-mar-mie-jue-vie-sab-dom) cada (1-2-3-4) meses $frecuencia = param('cada5') || 1; $tipo_frecuencia_id = 3; $dia_repeticion = '0000000'; substr($dia_repeticion, param('dia5'), 1) = 1; $orden_repeticion = param('orden5') || 1; @fechas = &repetir_5(@fdesde_pr, @fhasta_pr, $frecuencia, $dia_repeticion, $orden_repeticion); } else { $fechas[0] = join("/", @fdesde_pr); } #Obtengo el huso horario del usuario $ar = $dbh->selectall_arrayref('select huso_horario_id from agenda where agenda_id = ?', undef, $user_id) || &error_html($dbh->errstr); my $huso_id = $ar->[0]->[0]; if ($sms_rec) { $sms_minuto = param('sms_minuto') || 0; $sms_minuto2 = param('sms_minuto2') || 0; } if ($mail_rec) { $mail_minuto = param('mail_minuto') || 0; $mail_minuto2 = param('mail_minuto2') || 0; $mail_dir = param('mail_dir') || undef; } $dbh->do('LOCK TABLES agenda_evento WRITE, agenda_diaria WRITE, agenda_alerta WRITE, evento_participante WRITE, evento_alerta WRITE') || &error_html($dbh->errstr); if ($ag_evento_id) { #Es una actualización #Se actualizan todas las fechas if ($actualizar =~ /todas/ ){ #Se actualiza el evento padre (tabla agenda_evento) $dbh->do(<<'SQL', undef, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $hora_desde, $hora_hasta, $fhasta_bd, $tipo_repeticion_id, $tipo_frecuencia_id, $frecuencia, $orden_repeticion, $dia_repeticion, $msg_invitado, $ag_evento_id) || &error_html($dbh->errstr); UPDATE agenda_evento set categoria_id = ?, titulo = ?, comentario = ?, lugar_d = ?, domicilio = ?, telefono = ?, privado = ?, hora_desde = ?, hora_hasta = ?, fecha_hasta = ?, tipo_repeticion_id = ?, tipo_frecuencia_id = ?, frecuencia = ?, orden_repeticion = ?, dia_repeticion = ?, msg_invitado = ? WHERE ag_evento_id = ? SQL $dbh->do(<<'SQL', undef, $sms_rec, $sms_minuto, $sms_minuto2, $mail_minuto2, $mail_rec, $mail_minuto, $mail_dir, $ag_evento_id) || &error_html($dbh->errstr); UPDATE evento_alerta set sms_rec = ?, sms_minuto = ?, sms_minuto2 = ?, mail_minuto2 = ?, mail_rec = ?, mail_minuto = ?, mail_dir = ? WHERE ag_evento_id = ? SQL #Obtengo todas las fechas del evento my $ar = $dbh->selectall_arrayref('select date_format(fecha, "%Y/%m/%d"), ag_diaria_id from agenda_diaria where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); my %h_fechas = map {$_->[0] , $_->[1]} @{$ar}; foreach (@fechas) { my $fstring = sprintf '%04d/%02d/%02d', split('/', $_); if (exists $h_fechas{$fstring}) { #Si existe, la borro del hash delete($h_fechas{$fstring}); } else { #Si no existe, hay que darla de alta $dbh->do(<<'SQL', undef, $ag_evento_id, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $fstring, $hora_desde, $hora_hasta) || &error_html($dbh->errstr); INSERT into agenda_diaria (ag_evento_id, categoria_id, titulo, comentario, lugar_d, domicilio, telefono, privado, fecha, hora_desde, hora_hasta) VALUES (?,?,?,?,?,?,?,?,?,?,?) SQL } } #se borran las que ahora no van for my $id(values(%h_fechas)) { $dbh->do('delete from agenda_alerta where ag_diaria_id = ?', undef, $id) || &error_html($dbh->selectall_arrayref); $dbh->do('delete from agenda_diaria where ag_diaria_id = ?', undef, $id) || &error_html($dbh->selectall_arrayref); } #Si el evento no tiene repeticion, entonces se actualiza la fecha unless ($tipo_repeticion_id) { $dbh->do(<<'SQL', undef, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $hora_desde, $hora_hasta, $fdesde_bd, $ag_evento_id) || &error_html($dbh->errstr); UPDATE agenda_diaria set categoria_id = ?, titulo = ?, comentario = ?, lugar_d = ?, domicilio = ?, telefono = ?, privado = ?, hora_desde = ?, hora_hasta = ?, fecha = ? WHERE ag_evento_id = ? SQL } #Si el evento tiene repeticion, entonces se actualizan todos los datos menos la fecha else { $dbh->do(<<'SQL', undef, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $hora_desde, $hora_hasta, $ag_evento_id) || &error_html($dbh->errstr); UPDATE agenda_diaria set categoria_id = ?, titulo = ?, comentario = ?, lugar_d = ?, domicilio = ?, telefono = ?, privado = ?, hora_desde = ?, hora_hasta = ? WHERE ag_evento_id = ? SQL } #Obtiene todas las instancias del evento $ar = $dbh->selectall_arrayref('select ag_diaria_id, date_format(fecha, "%Y/%m/%d"), time_format(hora_desde, "%H:%i:00") from agenda_diaria where ag_evento_id = ?', undef, $ag_evento_id); for (@{$ar}) { $fecha_sms = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto, $_->[1], $_->[2]):undef; $fecha_sms2 = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto2, $_->[1], $_->[2]):undef; $fecha_mail = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto, $_->[1], $_->[2]):undef; $fecha_mail2 = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto2, $_->[1], $_->[2]):undef; $dbh->do(<<'SQL', undef, $_->[0], $sms_rec, $sms_minuto, $mail_rec, $mail_minuto, $mail_dir, $ag_evento_id , $sms_minuto2, $mail_minuto2, $fecha_sms, $fecha_sms2, $fecha_mail, $fecha_mail2) || &error_html($dbh->errstr); REPLACE INTO agenda_alerta (ag_diaria_id, sms_rec, sms_minuto, mail_rec, mail_minuto, mail_dir, ag_evento_id, sms_minuto2, mail_minuto2, fecha_sms, fecha_sms2, fecha_mail, fecha_mail2) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) SQL } } #Se actualiza solo ese evento else { $dbh->do(<<'SQL', undef, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $fdesde_bd, $hora_desde, $hora_hasta, $ag_diaria_id) || &error_html($dbh->errstr); UPDATE agenda_diaria set categoria_id = ?, titulo = ?, comentario = ?, lugar_d = ?, domicilio = ?, telefono = ?, privado = ?, fecha = ?, hora_desde = ?, hora_hasta = ? WHERE ag_diaria_id = ? SQL $fecha_sms = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto, $fdesde_bd, $hora_desde):undef; $fecha_sms2 = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto2, $fdesde_bd, $hora_desde):undef; $fecha_mail = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto, $fdesde_bd, $hora_desde):undef; $fecha_mail2 = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto2, $fdesde_bd, $hora_desde):undef; $dbh->do(<<'SQL', undef, $sms_rec, $sms_minuto, $mail_rec, $mail_minuto, $mail_dir, $sms_minuto2, $mail_minuto2, $fecha_sms, $fecha_sms2, $fecha_mail, $fecha_mail2, $ag_diaria_id) || &error_html($dbh->errstr); UPDATE agenda_alerta set sms_rec =?, sms_minuto = ?, mail_rec = ?, mail_minuto = ?, mail_dir = ?, sms_minuto2 = ?, mail_minuto2 = ?, fecha_sms = ?, fecha_sms2 = ?, fecha_mail = ?, fecha_mail2 = ? WHERE ag_diaria_id = ? SQL } } #Es nuevo, inserta el evento else { $dbh->do(<<'SQL', undef, $user_id, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $fdesde_bd, $hora_desde, $hora_hasta, $fhasta_bd, $tipo_repeticion_id, $tipo_frecuencia_id, $frecuencia, $orden_repeticion, $dia_repeticion, $evento_id, $msg_invitado) || &error_html($dbh->errstr); INSERT into agenda_evento (agenda_id, categoria_id, titulo, comentario, lugar_d, domicilio, telefono, privado, fecha, hora_desde, hora_hasta, fecha_hasta, tipo_repeticion_id, tipo_frecuencia_id, frecuencia, orden_repeticion, dia_repeticion, evento_id, msg_invitado) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) SQL $ar = $dbh->selectall_arrayref('select last_insert_id()') || &error_html($dbh->errstr); $ag_evento_id = $ar->[0]->[0]; #Agrega el recordatorio $dbh->do(<<'SQL', undef, $ag_evento_id, $sms_rec, $sms_minuto, $mail_rec, $mail_minuto, $mail_dir, $sms_minuto2, $mail_minuto2) || &error_html($dbh->errstr); INSERT INTO evento_alerta (ag_evento_id, sms_rec, sms_minuto, mail_rec, mail_minuto, mail_dir, sms_minuto2, mail_minuto2) VALUES (?, ?, ?, ?, ?, ?, ?, ?) SQL foreach (@fechas) { #Agrega los diarios $dbh->do(<<'SQL', undef, $ag_evento_id, $categoria_id, $titulo, $comentario, $lugar_d, $domicilio, $telefono, $privado, $_, $hora_desde, $hora_hasta) || &error_html($dbh->errstr); INSERT into agenda_diaria (ag_evento_id, categoria_id, titulo, comentario, lugar_d, domicilio, telefono, privado, fecha, hora_desde, hora_hasta) VALUES (?,?,?,?,?,?,?,?,?,?,?) SQL $ar = $dbh->selectall_arrayref('select last_insert_id()') || &error_html($dbh->errstr); $ag_diaria_id = $ar->[0]->[0]; $fecha_sms = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto, $_, $hora_desde):undef; $fecha_sms2 = ($sms_rec > 0)?&obtiene_fecha($huso_id, $sms_minuto2, $_, $hora_desde):undef; $fecha_mail = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto, $_, $hora_desde):undef; $fecha_mail2 = ($mail_rec > 0)?&obtiene_fecha($huso_id, $mail_minuto2, $_, $hora_desde):undef; $dbh->do(<<'SQL', undef, $ag_diaria_id, $sms_rec, $sms_minuto, $mail_rec, $mail_minuto, $mail_dir, $sms_minuto2, $mail_minuto2, $ag_evento_id, $fecha_sms, $fecha_sms2, $fecha_mail, $fecha_mail2) || &error_html($dbh->errstr); INSERT INTO agenda_alerta (ag_diaria_id, sms_rec, sms_minuto, mail_rec, mail_minuto, mail_dir, sms_minuto2, mail_minuto2, ag_evento_id, fecha_sms, fecha_sms2, fecha_mail, fecha_mail2) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) SQL } } #Se agregan los usuarios foreach (@usu_no_terra) { $dbh->do(<<"SQL", undef, $ag_evento_id, $_) || &error_html($dbh->errstr); INSERT INTO evento_participante(ag_evento_id, estado_id, mail) VALUES (?, 0, ?) SQL } foreach (@usu_terra) { $dbh->do(<<"SQL", undef, $ag_evento_id, $_) || &error_html($dbh->errstr); INSERT INTO evento_participante(ag_evento_id, estado_id, alias) VALUES (?, 0, ?) SQL } $ag_diaria_id = 0; $ag_evento_id = 0; $dbh->do('UNLOCK TABLES') || &error_html($dbh->errstr); @fdesde_pr[1]--; $fecha = timelocal(0,0,0, reverse(@fdesde_pr)); if ($funcion =~ /guarda_evento/) { &vista_agenda; } else { $reload = 0; $vrec = 0; $vrep = 0; $vinv = 0; &edita_evento; } } sub confirma_borrar_evento { my $tmp = new HTML::Template('filename' => "$::DIR_TEMPLATES/confirma_borrar_evento.html"); my @f = localtime($fecha); $f[5] += 1900; $tmp->param('CALENDARIO' => &calendario_dia($dbh, $user_id, 0, @f)); $tmp->param('FORM_QUICK' => &form_evento_quick); my @row = $dbh->selectrow_array(<<'SQL', undef, $ag_diaria_id, $user_id); SELECT ad.ag_evento_id, ad.titulo, ae.tipo_repeticion_id FROM agenda_diaria ad, agenda_evento ae WHERE ad.ag_diaria_id = ? AND ad.ag_evento_id = ae.ag_evento_id AND ae.agenda_id = ? SQL $row[1] = encode_entities $row[1]; $tmp->param('VA_AG_DIARIA_ID' => $ag_diaria_id); $tmp->param('VA_EVENTO_ID' => $row[0]); $tmp->param('VA_REPETIR' => $row[2]); $tmp->param('VA_FECHA' => $fecha); $tmp->param('VA_VISTA_ID' => $vista_id); $tmp->param('VA_NAME_EV' => $row[1]); #Tiene repeticiones entonces da la opción de borrar solo una fecha o todas $tmp->param('TIENE_REP' => 1) if ($row[2] > 0); print "Content-type:text/html\n\n"; print $tmp->output(); } #---------------------------------------------------------------------------- # Script da de baja un evento (completo o un dia) #---------------------------------------------------------------------------- sub baja_evento { my $repetir = param('repetir'); $dbh->do('LOCK TABLES agenda_evento WRITE, agenda_diaria WRITE, agenda_alerta WRITE, evento_participante WRITE, evento_alerta WRITE') || &error_html($dbh->errstr); if ($ag_diaria_id) { #Entonces borra solo el evento $dbh->do('delete from agenda_alerta where ag_diaria_id = ?', undef, $ag_diaria_id) || &error_html($dbh->errstr); $dbh->do('delete from agenda_diaria where ag_diaria_id = ?', undef, $ag_diaria_id) || &error_html($dbh->errstr); } else { $dbh->do('delete from agenda_alerta where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); $dbh->do('delete from agenda_diaria where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); } if ($repetir == 0 or ($repetir > 0 and !$ag_diaria_id)) { $dbh->do('delete from evento_participante where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); $dbh->do('delete from evento_alerta where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); $dbh->do('delete from agenda_evento where ag_evento_id = ?', undef, $ag_evento_id) || &error_html($dbh->errstr); } $dbh->do('UNLOCK TABLES') || &error_html($dbh->errstr); &vista_agenda; } sub separa_por_coma { my $texto = shift; $texto =~ s/\s//g; my @dir = split(',', $texto); return @dir; } #---------------------------------------------------------------------------- # Da de baja un participante del evento #---------------------------------------------------------------------------- sub baja_inv { my $participante_id = param('pid'); $dbh->do('LOCK TABLES evento_participante WRITE') || &error_html($dbh->errstr); $dbh->do('delete from evento_participante where participante_id = ?', undef, $participante_id) || &error_html($dbh->errstr); $dbh->do('UNLOCK TABLES') || &error_html($dbh->errstr); $funcion = 'ver_ev'; edita_evento; } #---------------------------------------------------------------------------- # Pone un participante en estado no enviado para que se le mande la invitación nuevamente #---------------------------------------------------------------------------- sub envia_invitacion { my $participante_id = param('pid'); my $msg_invitado = param('msg_invitado') || undef; $dbh->do('LOCK TABLES evento_participante WRITE, agenda_evento WRITE') || &error_html($dbh->errstr); $dbh->do('update evento_participante set estado_id = 0 where participante_id = ?', undef, $participante_id) || &error_html($dbh->errstr); $dbh->do('update agenda_evento set msg_invitado = ? where ag_evento_id = ?', undef, $msg_invitado, $ag_evento_id) || &error_html($dbh->errstr); $dbh->do('UNLOCK TABLES') || &error_html($dbh->errstr); $funcion = 'ver_ev'; edita_evento; } #---------------------------------------------------------------------------- # Script que arma el html de busqueda de eventos en Terra #---------------------------------------------------------------------------- sub busca_evento_terra{ my $tipo_evento_id = param('tipo_evento_id') || 0; my $detalle = param('detalle') || ''; my $fdesde = param('fdesde') || join('/', reverse(Today())); my ($fdesde_dia, $fdesde_mes, $fdesde_anio) = split('/', $fdesde); my $fhasta = param('fhasta') || undef; my ($fhasta_dia, $fhasta_mes, $fhasta_anio) = split('/', $fhasta) if (defined $fhasta); my $offset = param('offset') || 0; # my %h_orden = ('detalle' => '', 'fecha' => ''); # $h_orden{param('orden') || 'detalle'} = 'CHECKED'; my @f = localtime($fecha); $f[5] += 1900; my $tmp = new HTML::Template('filename' => "$::DIR_TEMPLATES/busqueda.html"); $tmp->param('CAB_FECHA' => $fecha); $tmp->param('CALENDARIO' => &calendario_dia($dbh, $user_id, 0, @f)); my $dbhev = DBI->connect(@::DBI_EVENTO) || &error_html("Error de conexion"); my $opt_tipos = "\n"; my $ar = $dbhev->selectall_arrayref('select tipo_evento_id, detalle from tipo_evento order by detalle') || &error_html($dbh->errstr); $opt_tipos .= &arma_opts($tipo_evento_id, $ar); $tmp->param('CAB_FECHA' => $fecha); $tmp->param('BUS_VISTA_ID' => $vista_id); $tmp->param('BUS_OFFSET' => $offset); $tmp->param('BUS_FDESDE' => $fdesde); $tmp->param('BUS_FHASTA' => $fhasta); $tmp->param('BUS_DETALLE' => $detalle); $tmp->param('BUS_TIPOS' => $opt_tipos); $tmp->param('BUS_FDESDE_DIA' => $fdesde_dia); $tmp->param('BUS_FDESDE_MES' => $fdesde_mes); $tmp->param('BUS_FDESDE_ANIO' => $fdesde_anio); $tmp->param('BUS_FHASTA_DIA' => $fhasta_dia); $tmp->param('BUS_FHASTA_MES' => $fhasta_mes); $tmp->param('BUS_FHASTA_ANIO' => $fhasta_anio); $tmp->param('BUS_PAGER' => $::PAGER_EV); $fdesde = join('/', reverse(split('/', $fdesde))); $fhasta= join('/', reverse(split('/', $fhasta))) if (defined $fhasta); my $sql =<< 'EOF'; SELECT e.evento_id, e.detalle, t.detalle, date_format(e.fecha, '%d/%m/%Y'), date_format(e.fecha_hasta, '%d/%m/%Y'),time_format(e.hora, '%H:%i'), time_format(e.hora_hasta,'%H:%i'), tipo_repeticion_id, orden_repeticion, dia_repeticion, frecuencia FROM eventos e, tipo_evento t, eventos_prog p WHERE e.tipo_evento_id = t.tipo_evento_id AND (p.fecha_evento >= ?) AND e.evento_id = p.evento_id AND (e.detalle like ? OR t.detalle like ?) EOF $sql .= ($tipo_evento_id)?' AND e.tipo_evento_id = ? ':' AND e.tipo_evento_id > ? '; $sql .= " AND p.fecha_evento <= '$fhasta' " if (defined $fhasta and $fhasta); $sql .= ' GROUP BY e.evento_id ORDER BY e.detalle '; #Si tiene 4 o más caracteres el destalle busca que estén en cualquier parte del nombre #Si tiene - de 4 entonces que empiece con el nombre my $detalle_busq = (length($detalle) >= 4)?"%$detalle%":"$detalle%"; my $ar = $dbhev->selectall_arrayref($sql, undef, $fdesde, $detalle_busq, $detalle_busq, $tipo_evento_id) || &error_html($dbh->errstr); my $total = scalar(@{$ar}); $tmp->param('BUS_TOTAL' => $total); if ($total > $::PAGER_EV) { $tmp->param('VER_PAGINADO' => 1); if ($offset) { $tmp->param('PAG_HAY_ANTERIOR' => 1); $tmp->param('PAG_CANT_ANTERIOR' => "$::PAGER_EV anteriores"); } if ($total > ($::PAGER_EV+$offset)) { $tmp->param('PAG_HAY_SIGUIENTE' => 1); $tmp->param('PAG_CANT_SIGUIENTE' => "$::PAGER_EV siguientes"); } } $dbhev->disconnect; my $repetir; my $color; my @loop_res; for (my $i = $offset; $i < $total && $i < $offset + $::PAGER_EV; $i++) { my $row = $ar->[$i]; my %res; my $url = uf_evento($row->[0])->{'url'}; $row->[3] .= sprintf ' - %s', $row->[4] if (defined $row->[4] and $row->[3] != $row->[4]); $row->[5] = ($row->[5] == $row->[6])?$row->[5]:"$row->[5] - $row->[6]"; $res{'RES_EVENTO'} = $row->[1]; $res{'RES_EVENTO_ID'} = $row->[0]; $res{'RES_FECHA'} = $row->[3]; $res{'RES_HORA'} = $row->[5]; $res{'RES_TIPO'} = $row->[2]; $res{'RES_URL'} = $url; $res{'RES_IF_COLOR'} = ($i%2 != 0)?1:'#ffffff'; push @loop_res, \%res; } $tmp->param('BUS_RESULTA' => \@loop_res); print "Content-type:text/html\n\n"; print $tmp->output(); } sub aviso_legal { &vista_aviso($dbh, $fecha, $user_id); } sub ayuda { &vista_ayuda($dbh, $fecha, $user_id); } sub portada { my $tmp = new HTML::Template('filename' => "$::DIR_TEMPLATES/dia_portada.html"); &vista_diaria_portada($tmp, $dbh, $user_id); print "Content-type:text/html\n\n"; print $tmp->output(); }