tieneAcceso()){ $return["error"] = "Error! No tienes permisos para realizar esta acción."; }else if(!isset($_POST["mes"], $_POST["anho"], $_POST["perfiles"])){ $return["error"] = "Error! No se recibió la información para generar el calendario."; }else{ $mes = filter_input(INPUT_POST, "mes", FILTER_SANITIZE_NUMBER_INT);//limpia texto $anho = filter_input(INPUT_POST, "anho", FILTER_SANITIZE_NUMBER_INT);//limpia texto //$fecha_min = fechaGuion(trim(filter_input(INPUT_POST, "fecha_min", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto //$fecha_max = fechaGuion(trim(filter_input(INPUT_POST, "fecha_max", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $perfiles = implode(',', $_POST["perfiles"]); $return["error"] = ""; $eventos_display = 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"; }else{ $periodo_rs = $stmt->fetch(); } $stmt->closeCursor(); $eventoObj = new Evento(0, "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_display = array_merge($eventos_display, $eventoObj->getEventList($mes, $anho)); $eventoObj = new Evento(0, "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_display = array_merge($eventos_display, $eventoObj->getEventList($mes, $anho)); $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('d/m/Y', strtotime($fecha_rs["FechaImportante_inicial"].' - 1 month ')); $fecha_max = date('d/m/Y', 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, true)'); $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(); $return["error"] .= "Ocurrió un error al obtener los eventos.".$t[2]; $error = true; } if(!$error){ $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["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); } } $stmt = $pdo->prepare('Select * from fs_insigniageneral(:id)'); $stmt->bindParam(":id", $evento["CalendarioEvento_id"]); if($stmt->execute()){ $insignia_rs = $stmt->fetch(); $stmt->closeCursor(); } $eventoObj->addInsignia($insignia_rs["Insignia_id"], $insignia_rs["InsigniaTipo_id"], $insignia_rs["InsigniaTipo_desc"],$insignia_rs["InsigniaTipo_color"], $insignia_rs["Puesto_id"], $insignia_rs["Puesto_desc"], $insignia_rs["Insignia_hasEvidencia"], $insignia_rs["Insignia_evidencia_desc"], $insignia_rs["InsigniaGeneral_inscripciones_inicial"], $insignia_rs["InsigniaGeneral_inscripciones_final"]); //Agrega atributos $stmt = $pdo->prepare('Select * from fs_insignia_atributoegreso(:id, NULL)'); $stmt->bindParam(":id", $insignia_rs["Insignia_id"]); if($stmt->execute()){ $atr_rs = $stmt->fetchAll(); $stmt->closeCursor(); foreach($atr_rs as $atr){ $eventoObj->addAtributo($atr); } } //Total de insignias asignadas $stmt = $pdo->prepare('Select COUNT("Usuario_id") AS total from fs_insigniaalumno(:id)'); $stmt->bindParam(":id", $insignia_rs["Insignia_id"]); if($stmt->execute()){ $total_rs = $stmt->fetch(); $stmt->closeCursor(); $eventoObj->addTotalInsignias($total_rs["total"]); } //-- 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(); $return["error"] .= "Ocurrió un error al obtener las fechas editadas.".$t[2]; $error = true; break; } 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_display = array_merge($eventos_display, $eventoObj->getEventList($mes, $anho)); } }//foreach }//not error $return["eventos"] = $eventos_display; } $return["json"] = json_encode($return); echo json_encode($return); ?>