tieneAcceso()){
$objSesion->terminaSesion();
}
$objSesion->validaPeriodoUsuario();//si no tiene periodo manda a main
function findCategoria($list, $id){
for($i=0; $i< count($list); $i++){
if(intval($list[$i]["id"]) == intval($id))
return $i;
}
return -1;
}
?>
printMenu();
$perfiles = '1,2,3,4';
$eventos_list = array();//eventos con todas las fechas para pintarse. Arreglo de Objeto evento
$error = false;
//-------------------------
//Obtiene fechas de periodo
$stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)');
$stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
if(!$stmt->execute()){
//print_r($stmt->errorInfo());
$errorDesc ="Ocurrió un error al cargar los datos del periodo.";
$error = true;
}else{
$periodo_rs = $stmt->fetch();
}
if(!$error){
$stmt->closeCursor();
$mes=date("m", strtotime($periodo_rs["Periodo_fecha_inicial"]));
$anho=date("Y", strtotime($periodo_rs["Periodo_fecha_inicial"]));
$eventoObj = new Evento(-2, "Inicio de cursos","",0, "Fechas importantes", PERIODO_COLOR, $_SESSION["periodo_id"], $periodo_rs["Periodo_fecha_inicial"], true,"","", false);
$eventoObj->addFecha($periodo_rs["Periodo_fecha_inicial"]);
$eventos_list = array_merge($eventos_list, $eventoObj->getEventList_All($periodo_rs["Periodo_fecha_inicial"], $periodo_rs["Periodo_fecha_final"]));
$eventoObj = new Evento(-1, "Fin de cursos","",0, "Fechas importantes", PERIODO_COLOR, $_SESSION["periodo_id"], $periodo_rs["Periodo_fecha_final"], true,"","", false);
$eventoObj->addFecha($periodo_rs["Periodo_fecha_final"]);
$eventos_list = array_merge($eventos_list, $eventoObj->getEventList_All($periodo_rs["Periodo_fecha_inicial"], $periodo_rs["Periodo_fecha_final"]));
}
$stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 2)');//extras
$stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
if(!$stmt->execute()){
$errorDesc = "Ocurrió un error al cargar las fechas del periodo.";
$error = true;
}else{
$fecha_rs = $stmt->fetch();
if(is_array($fecha_rs) && count($fecha_rs) > 0){
$eventoObj = new Evento(0, "Exámenes Extraordinarios", "",0, "Fechas importantes", EXTRAS_COLOR, $_SESSION["periodo_id"], $fecha_rs["FechaImportante_inicial"], true,"","", false);
$fecha = $fecha_rs["FechaImportante_inicial"];
$diasArr = array(1,2,3,4,5);
while (strtotime($fecha) <= strtotime($fecha_rs["FechaImportante_final"])) {
if(in_array(date("w", strtotime($fecha)), $diasArr) ){//si es el día que quiero
$eventoObj->addFecha($fecha);
}
$fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha)));
}
$eventos_list = array_merge($eventos_list, $eventoObj->getEventList_All($periodo_rs["Periodo_fecha_inicial"], $periodo_rs["Periodo_fecha_final"]));
}
}
$stmt->closeCursor();
$stmt = null;
//-------------------------
// Obtiene fecha máxima y min
$stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 3)');//periodo
$stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
if(!$stmt->execute()){
$errorDesc = "Ocurrió un error al cargar las fechas del periodo.";
}else{
$fecha_rs = $stmt->fetch();
$fecha_min = date('Y-m-d', strtotime($fecha_rs["FechaImportante_inicial"].' - 1 month '));
$fecha_max = date('Y-m-d', strtotime($fecha_rs["FechaImportante_final"].' + 1 month '));
}
$stmt->closeCursor();
$stmt = null;
//--Obtiene todos los eventos dentro del rango del periodo para los perfiles indicados
$stmt = $pdo->prepare('Select * from fs_calendarioevento(:per, :fecha_i, :fecha_f, :perf, false)');
$stmt->bindParam(":per", $_SESSION["periodo_id"]);
$stmt->bindParam(":fecha_i", $fecha_min);
$stmt->bindParam(":fecha_f", $fecha_max);
$stmt->bindParam(":perf", $perfiles);
unset($perfiles);
if(!$stmt->execute()){
$t = $stmt->errorInfo();
$errorDesc = "Ocurrió un error al obtener los eventos.";
$error = true;
}
$eventos_rs = $stmt->fetchAll();
$stmt->closeCursor();
//Recorre eventos
foreach($eventos_rs as $evento){
$eventoObj = new Evento($evento["CalendarioEvento_id"], $evento["CalendarioEvento_titulo"],$evento["CalendarioEvento_desc"],$evento["CalendarioCategoria_id"], $evento["CalendarioCategoria_desc"], $evento["CalendarioCategoria_color"], $evento["Periodo_id"] ,$evento["CalendarioEvento_fecha"], $evento["CalendarioEvento_todo_dia"], $evento["CalendarioEvento_hora_inicial"],$evento["CalendarioEvento_hora_final"]);
$stmt = $pdo->prepare('Select * from fs_calendarioevento_perfil(:id)');
$stmt->bindParam(":id", $evento["CalendarioEvento_id"]);
if($stmt->execute()){
$perf_rs = $stmt->fetchAll();
$stmt->closeCursor();
foreach($perf_rs as $perf){
$eventoObj->addPerfil($perf);
}
}else{
$errorDesc = "Error al obtener perfiles.";
$error = true;
}
if(!$error){
//-- Calcular posibles fechas e insertar fechas en objeto --
$fecha = fechaGuion($evento["CalendarioEvento_fecha"]);
switch($evento["CalendarioRepeticion_id"]){
case 1: //diario
while (strtotime($fecha) <= strtotime($evento["CalendarioReglas_fecha_final"])) {
$eventoObj->addFecha($fecha);
$fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha)));
}
break;
case 2: //semanal
$diasArr = explode(",", $evento["CalendarioReglas_dias_str"]);
while (strtotime($fecha) <= strtotime($evento["CalendarioReglas_fecha_final"])) {
if(in_array(date("w", strtotime($fecha)), $diasArr) ){//si es el día que quiero
$eventoObj->addFecha($fecha);
}
$fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha)));
}
break;
case 3://mensual
$diasArr = explode(",", $evento["CalendarioReglas_dias_str"]);
//reglas
$weekTxt = array(1=>"first", 2=>"second", 3=>"third", 4=>"fourth", -1=>"last");
$dayname = array("sun", "mon", "tue", "wed", "thu", "fri", "sat");
$fecha = date ("Y-m-01", strtotime($fecha));//empieza a revisar en el primer día del mes
$semana = $evento["CalendarioReglas_semana"];
while (strtotime($fecha) <= strtotime($evento["CalendarioReglas_fecha_final"])) {
foreach($diasArr as $d){
//echo "-->". intval(date("w", strtotime($fecha)))." == ". intval($d)."[".$fecha."]";
if($semana == 1 && intval(date("w", strtotime($fecha))) == intval($d) ){//si el día actual es el que quiero lo guarda
$eventoObj->addFecha($fecha);
}else{//si no calcula siguiente día
if(intval(date("w", strtotime($fecha))) == intval($d)){
$fechaTmp = date ("Y-m-d", strtotime($weekTxt[$semana-1]." ".$dayname[$d], strtotime($fecha)));
}else{
$fechaTmp = date ("Y-m-d", strtotime($weekTxt[$semana]." ".$dayname[$d], strtotime($fecha)));
}
$eventoObj->addFecha($fechaTmp);
}
}
$fecha = date ("Y-m-01", strtotime("+1 month", strtotime($fecha)));//siguiente mes primer día
}
break;
default: //no se repite
$eventoObj->addFecha($fecha);
}
//Obtiene eventos modificados (fechas que cambiaron)
$stmt = $pdo->prepare('Select * from fs_calendarioeventoeditado(:id)');
$stmt->bindParam(":id", $eventoObj->id_db);
if(!$stmt->execute()){
$t = $stmt->errorInfo();
$errorDesc = "Ocurrió un error al obtener las fechas editadas.".$t[2];
$error = true;
}
}
if(!$error){
//modifica fechas
$eventosEditados_rs = $stmt->fetchAll();
$stmt->closeCursor();
foreach($eventosEditados_rs as $modif){
$eventoObj->replaceFecha($modif["CalendarioEventoEditado_fecha_origen"], $modif["CalendarioEventoEditado_fecha_nueva"], $modif["CalendarioEventoEditado_hora_inicial"], $modif["CalendarioEventoEditado_hora_final"]);
}
//Quitar fechas de excepción
foreach(explode(",", $evento["CalendarioEvento_excepcion_str"]) as $ex){
$eventoObj->removeFecha($ex);
}
//Descompone el objeto en un arreglo con todas las fechas y agrega a lista al total del calendario
$eventos_list = array_merge($eventos_list, $eventoObj->getEventList_All($fecha_min, $fecha_max));
}
}//foreach
//Agrupar por categoría
$stmt = $pdo->prepare('Select * from fs_calendariocategoria(NULL)');
if(!$stmt->execute()){
$t = $stmt->errorInfo();
$errorDesc = "Ocurrió un error al obtener las fechas editadas.".$t[2];
$error =true;
}else{
$cat_rs = $stmt->fetchAll();
}
$categoria_list = array();
foreach($cat_rs as $cat){
$categoria_list[] = array("id"=>$cat["CalendarioCategoria_id"], "desc"=>$cat["CalendarioCategoria_desc"], "color"=>$cat["CalendarioCategoria_color"], "total"=>0);
}
foreach($eventos_list as $evento){
$pos = findCategoria($categoria_list, $evento["categoria"]);
if($pos >= 0){
$categoria_list[$pos]["total"]++;
}
}
?>
Eventos en el periodo
|
Categoría |
Total de eventos |
| "> |
|
|