"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); private $DIAS = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"); function __construct($pdo){ $this->pdo = $pdo; } function generaCalendario($usr, $usr_nombre, $mat, $gpo, $gpo_nom, $sub, $debug=false ){ $xtpl = new XTemplate('../tpl/plancatedra.tpl.html'); $this->mat = $mat; $this->gpo = $gpo; $this->gpo_nom = $gpo_nom; $this->sub = $sub; $this->usr = $usr; $this->usr_nombre = $usr_nombre; //------------------------- //Obtiene materias de profesor if(empty($sub)){ $stmt = $this->pdo->prepare('Select * from fs_materiadias(:usr, :mat, :gpo, NULL)'); }else{ $stmt = $this->pdo->prepare('Select * from fs_materiadias(:usr, :mat, :gpo, :sub)'); $stmt->bindParam(":sub", $sub); //echo "Select * from fs_materiadias($usr, $mat, $gpo, $sub)"; exit(); } $stmt->bindParam(":usr", $usr); $stmt->bindParam(":mat", $mat); $stmt->bindParam(":gpo", $gpo); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); $this->errorDesc = "Ocurrió un error al cargar los días de las materias"; }else{ $rs = $stmt->fetchAll(); $diasMatArr = array(); foreach($rs as $dia){ $diasMatArr[] = array( "dia"=> $dia["Dia_id"], "hora"=>substr($dia["Horario_hora"],0, 5)); } } $stmt->closeCursor(); $stmt = null; if($debug){ print_r($diasMatArr);exit(); } //Obtiene fechas de periodo $stmt = $this->pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)'); $stmt->bindParam(":periodo", $_SESSION["periodo_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); $this->errorDesc = "Ocurrió un error al cargar los datos del periodo"; }else{ $periodo_rs = $stmt->fetch(); } $stmt->closeCursor(); $fecha_min = $periodo_rs["Periodo_fecha_inicial"]; $fecha_max = $periodo_rs["Periodo_fecha_final"]; // ---- Obtiene fechas de vacaciones $stmt = $this->pdo->prepare('select * from fs_calendarioevento_categoria(:fini, :ffin, 2, :periodo)'); $stmt->bindParam(":fini", $fecha_min); $stmt->bindParam(":ffin", $fecha_max); $stmt->bindParam(":periodo", $_SESSION["periodo_id"]); if(!$stmt->execute()){ $this->errorDesc = "Ocurrió un error al cargar las fechas de vacaciones"; }else{ $vacaciones_rs = $stmt->fetchAll(); } $stmt->closeCursor(); $stmt = null; $vacacionesArr = array();//Guarda los días individuales de vacaciones foreach($vacaciones_rs as $evento){ $fecha = fechaGuion($evento["CalendarioEvento_fecha"]); switch($evento["CalendarioRepeticion_id"]){ case 1: //diario while (strtotime($fecha) <= strtotime($evento["CalendarioReglas_fecha_final"])) { $vacacionesArr[] = array("fecha"=> $fecha, "titulo"=>$evento["CalendarioEvento_titulo"]); $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 $vacacionesArr[] = array("fecha"=> $fecha, "titulo"=>$evento["CalendarioEvento_titulo"]); } $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 $vacacionesArr[] = array("fecha"=> $fecha, "titulo"=>$evento["CalendarioEvento_titulo"]); }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))); } $vacacionesArr[] = array("fecha"=> $fecha, "titulo"=>$evento["CalendarioEvento_titulo"]); } } $fecha = date ("Y-m-01", strtotime("+1 month", strtotime($fecha)));//siguiente mes primer día } break; default: //no se repite $vacacionesArr[] = array("fecha"=> $fecha, "titulo"=>$evento["CalendarioEvento_titulo"]); } } //----- Calcula fechas de clases $calendario = array(); $fechasArr = array(); $fecha = $fecha_min; $semOld=1; $cont = 0; while (strtotime($fecha) <= strtotime($fecha_max)) { if(date("w", strtotime($fecha)) == $diasMatArr[$cont%count($diasMatArr)]["dia"]) {//si es el día que quiero if($semOld != floor($cont/count($diasMatArr))+1){ $sem = floor($cont/count($diasMatArr))+1; $semOld = $sem; $calendario[] = array("semana"=>$sem-1, "fechas"=>$fechasArr); $fechasArr = array(); } $vacPos = $this->buscaVacacion($fecha, $vacacionesArr); if($vacPos === false){//no vacaciones $fechasArr[] = array("numSesion"=>$cont+1, "fecha"=>fechaSlash($fecha)." ".$diasMatArr[$cont%count($diasMatArr)]["hora"], "mes"=>date("n", strtotime($fecha)), "habil"=>true, "dia"=>$this->DIAS[date("w", strtotime($fecha))-1], "titulo"=>""); //Si el día de la fecha no es el día del siguiente evento O se reinicia el arreglo de días if(date("w", strtotime($fecha)) != $diasMatArr[$cont%count($diasMatArr)]["dia"] || ($cont+1)%count($diasMatArr)==0){ $fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha))); } }else{//vacaciones $fechasArr[] = array("numSesion"=> 0,"fecha"=>fechaSlash($fecha), "mes"=>date("n", strtotime($fecha)), "habil"=>false, "dia"=>$this->DIAS[date("w", strtotime($fecha))-1], "titulo"=>$vacacionesArr[$vacPos]["titulo"]); $aux = $cont/count($diasMatArr);//para que sean de la misma semana //mientras sea el mismodía de la misma semana if(date("w", strtotime($fecha)) != $diasMatArr[$cont%count($diasMatArr)]["dia"] || ($cont+1)%count($diasMatArr)==0){ while(date("w", strtotime($fecha)) == $diasMatArr[$cont%count($diasMatArr)]["dia"] && ($cont+1)%count($diasMatArr)!=0){ $cont++; } $fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha))); } } $cont++; }else{ $fecha = date ("Y-m-d", strtotime("+1 day", strtotime($fecha))); } } if($semOld != floor($cont/count($diasMatArr))){ $sem = floor($cont/count($diasMatArr))+1; }else{ $sem = floor($cont/count($diasMatArr)); } $calendario[] = array("semana"=>$sem, "fechas"=>$fechasArr); $cont = 1; $i=0; $j=0; for($i=0; $i< count($calendario); $i++){ for($j=0; $j< count($calendario[$i]["fechas"]); $j++){ if($calendario[$i]["fechas"][$j]["habil"]){ $calendario[$i]["fechas"][$j]["numSesion"] = $cont; $cont++; } } } //---Obtiebe contenido de sesiones plan cátedra if(isset($_POST["sub"]) && $_POST["sub"]!= ""){ $sub = filter_input(INPUT_POST, "sub", FILTER_SANITIZE_NUMBER_INT);//limpia texto $stmt = $this->pdo->prepare('Select * from fs_sesioncatedra(:mat, :usr, :gpo, :sub, NULL)'); $stmt->bindParam(":sub", $sub); }else{ $stmt = $this->pdo->prepare('Select * from fs_sesioncatedra(:mat, :usr, :gpo, NULL, NULL)'); } $stmt->bindParam(":usr", $usr); $stmt->bindParam(":mat", $mat); $stmt->bindParam(":gpo", $gpo); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); $this->errorDesc = "Ocurrió un error al cargar las sesiones del plan de cátedra"; }else{ $rs = $stmt->fetchAll(); $sesionesArr = array(); $ses_old = -1; $i = -1; foreach($rs as $ses){ if($ses_old != $ses["SesionCatedra_numero"]){ $i++; $sesionesArr[$i]=array("sesion"=>$ses["SesionCatedra_numero"], "subsesiones"=>array()); $ses_old = $ses["SesionCatedra_numero"]; } $sesionesArr[$i]["subsesiones"][] = array("desc"=>$ses["SesionCatedra_desc"], "tipo_id"=>$ses["SesionCatedraTipo_id"], "tipo"=>$ses["SesionCatedraTipo_desc"], "color"=>$ses["SesionCatedraTipo_color"]); //$diasMatArr[] = array( "dia"=> $dia["Dia_id"], "hora"=>substr($dia["Horario_hora"],0, 5)); } } /*if($debug ){ print_r($sesionesArr); exit(); }*/ $stmt->closeCursor(); $stmt = null; if(isset($sub)){ $stmt = $this->pdo->prepare('SELECT hg."Horario_hora", s."Salon_desc", s."Salon_desc_larga", d."Dia_desc" from fs_horariogrupo(:gpo, NULL, false) AS hg INNER JOIN "Dia" d ON hg."Dia_id" = d."Dia_id" INNER JOIN "Submateria_HorarioGrupo_Profesor" shgp ON hg."HorarioGrupo_id" = shgp."HorarioGrupo_id" AND shgp."Submateria_id" = :sub INNER JOIN "Salon" s ON shgp."Salon_id" = s."Salon_id" WHERE "Materia_id" = :mat ORDER BY d."Dia_id", hg."Horario_hora"' ); $stmt->bindParam(":sub", $sub); }else{ $stmt = $this->pdo->prepare('SELECT hg."Horario_hora", hg."Salon_desc", hg."Salon_desc_larga", d."Dia_desc" from fs_horariogrupo(:gpo, NULL, false) AS hg INNER JOIN "Dia" d ON hg."Dia_id" = d."Dia_id" WHERE "Materia_id" = :mat ORDER BY d."Dia_id", hg."Horario_hora"' ); } $stmt->bindParam(":gpo", $gpo); $stmt->bindParam(":mat", $mat); if(!$stmt->execute()){ //header("Location: ".$this->pag."?error=3"); return false; // print_r($stmt->errorInfo()); exit(); } $horario_rs = $stmt->fetchAll(); $stmt->closeCursor(); //print_r($horario_rs); exit; //---Tipo de sesiones plan cátedra $stmt = $this->pdo->prepare('Select * from fs_sesioncatedra_tipo(NULL)'); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); $this->errorDesc = "Ocurrió un error al cargar los días de las materias"; }else{ $tipoSesionArr = $stmt->fetchAll(); } $stmt->closeCursor(); $stmt = null; //--Nombre de materia $mat_nombre = ""; $mat_sem = ""; if(!isset($sub)){ $stmt = $this->pdo->prepare('Select "Materia_desc", "Materia_semestre" from fs_materia(:mat, NULL, NULL,NULL,NULL,0,NULL)'); $stmt->bindParam(":mat", $mat); if(!$stmt->execute()){ return false; //header("Location: ".$this->pag."?error=3"); exit(); } $mat_rs = $stmt->fetch(); $stmt->closeCursor(); $mat_nombre = $mat_rs["Materia_desc"]; $mat_sem = $mat_rs["Materia_semestre"]; unset($mat_rs); }else{ $stmt = $this->pdo->prepare('Select "Submateria_desc", "Materia_semestre" from fs_submateria(:mat, :sub)'); $stmt->bindParam(":mat", $mat); $stmt->bindParam(":sub", $sub); if(!$stmt->execute()){ //header("Location: ".$this->pag."?error=3"); return false; exit(); } $mat_rs = $stmt->fetch(); $stmt->closeCursor(); $mat_nombre = $mat_rs["Submateria_desc"]; $mat_sem = $mat_rs["Materia_semestre"]; unset($mat_rs); } //----- $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; $this->mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => [215, 279], 'orientation' => 'P', 'margin_left' => 14, 'margin_right' => 14, 'margin_top' => 27, 'margin_bottom' => 27, 'fontDir' => array_merge($fontDirs, [ __DIR__ . '/../../fonts/indivisaFont/ttf', ]), 'fontdata' => $fontData + [ 'indivisa-display' => [ 'R' => 'IndivisaDisplaySans-Regular.ttf', ], 'indivisa-title' => [ 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf', ], 'indivisa-text' => [ 'R' => 'IndivisaTextSans-Regular.ttf', ] ], 'default_font' => 'indivisa-text', ]); //$this->mpdf->SetDisplayMode('fullpage'); $xtpl->assign("MATERIA", $mat_nombre." ".$gpo_nom); $xtpl->assign("SEMESTRE", $mat_sem); $xtpl->assign("PERIODO", $periodo_rs["Periodo_desc"]); $xtpl->assign("PROFESOR", $usr_nombre); foreach($horario_rs as $h){ $hora = substr($h["Horario_hora"], 0, 5); if($h["Salon_desc"]==""){ $salon = "Salón pendiente"; }else{ $salon = $h["Salon_desc"]; if($h["Salon_desc_larga"] != ""){ $salon .=" (".$h["Salon_desc_larga"].")"; } } $xtpl->assign("DIA", $h["Dia_desc"]); $xtpl->assign("HORA", $hora); $xtpl->assign("SALON", $salon); $xtpl->parse("main.content.fechas"); } foreach($tipoSesionArr as $tses){ $xtpl->assign("COLOR", $tses["SesionCatedraTipo_color"]); $xtpl->assign("TIPO", $tses["SesionCatedraTipo_desc"]); $xtpl->parse("main.content.tipo"); } //--- $mes_old = 0; foreach($calendario as $semana){ foreach($semana["fechas"] as $dia){ if($mes_old != $dia["mes"]){ $mes_old = $dia["mes"]; $xtpl->assign("MES", mb_strtoupper($this->MESES[$mes_old])); $xtpl->parse("main.content.sesion.mes"); $xtpl->parse("main.content.sesion"); } $fechaArr = explode(" ",$dia["dia"]." ".fechaSlash($dia["fecha"])); if(count($fechaArr) == 2){ $fechaArr[] = "00:00:00"; } $xtpl->assign("FECHA_DIA", $fechaArr[0]); $xtpl->assign("FECHA", $fechaArr[1]); if($dia["habil"]){ $xtpl->assign("HORA", $fechaArr[2]); $xtpl->assign("SEMANA", $semana["semana"]); $xtpl->assign("SESION", $dia["numSesion"]); $sesArr = $this->obtieneSesiones($sesionesArr, $dia["numSesion"]); if(count($sesArr) > 0){ foreach($sesArr as $ses){ if($ses["tipo_id"] == 1) $xtpl->assign("COLOR", $this->getRGBA_color($ses["color"], 0.0)); else $xtpl->assign("COLOR", $this->getRGBA_color($ses["color"], 0.3)); $xtpl->assign("DESC", $ses["desc"]); $xtpl->parse("main.content.sesion.regular.tema"); } $xtpl->parse("main.content.sesion.regular"); }else{ $xtpl->assign("COLOR", $this->getRGBA_color("#ffffff", 0)); $xtpl->assign("DESC", ""); $xtpl->parse("main.content.sesion.regular"); } }else{ $xtpl->assign("HORA", ""); $xtpl->assign("DESC", $dia["titulo"]); $xtpl->parse("main.content.sesion.vacacion"); } $xtpl->parse("main.content.sesion"); } } $xtpl->parse("main.content"); $xtpl->parse("main"); $this->xtpl_text = $xtpl->text("main"); $this->mat_nombre = $mat_nombre; return true; } function getPlan(){ return $this->xtpl_text; } /** * Genera el pdf del plan de cátedra * @param string $stylesheet Estilos css * @param string $stylesheet Si es true se guarda en: /var/www/html/apsa/files/plancatedra/ */ function pdfPlan($stylesheet, $save=false){ $header = '

PLAN DE CÁTEDRA | FACULTAD DE INGENIERÍA

'; $this->mpdf->SHYlang = 'es'; $this->mpdf-> SetTitle('Plan de cátedra -' . $this->mat_nombre); $this->mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("Y").' Todos los derechos Reservados.'); $this->mpdf->SetHTMLHeader($header);//se pone como fondo $this->mpdf->SetHTMLFooter('');//se pone como fondo $this->mpdf->WriteHTML($stylesheet); if($this->errorDesc == "") $this->mpdf->WriteHTML($this->xtpl_text); else $this->mpdf->WriteHTML($this->errorDesc); if(!$save) $this->mpdf->Output("planCátedra_".getIniciales($this->mat_nombre)."_".$this->gpo_nom.".pdf", 'I'); else{ $target_dir = "/var/www/html/apsa/files/plancatedra/".$_SESSION["periodo_id"]; if (file_exists($target_dir)===false) { mkdir($target_dir, 0755, true); } $this->mpdf->Output($target_dir."/planCatedra_".getIniciales($this->mat_nombre)."_".$this->gpo_nom."_".date("Ymd_His").".pdf", 'F'); } } private function getRGBA_color($hex, $a=0){ list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x"); $style = "rgba($r,$g, $b,"; $style .= "$a)"; return $style; } private function buscaVacacion($fecha, $vacacionesArr){ $i=0; foreach($vacacionesArr as $vacacion){ if ($vacacion["fecha"] == $fecha){ return $i; } $i++; } return false; } private function obtieneSesiones($arr, $num){ foreach($arr as $ses){ if($ses["sesion"] == $num ){ return $ses["subsesiones"]; } } return array(); } } ?>