valid) {
$clave_ulsa = intval(substr($lti->info["ext_user_username"], 2));//clave como entero
if(substr_count($lti->info["context_label"], "-")<3){
echo "
Error
No se puede hacer la consulta porque el shortaname no es válido.
";
exit();
}
$tmp = explode("-", $lti->info["context_label"]);//Shortname
$gpo_nom = $tmp[0];
if($gpo_nom == "ELECTIVA"){
$electiva = true;
}
$iniciales = $tmp[1];
$mat = $tmp[3];
$periodo_id = $lti->info["custom_periodo"]; //Obtenerlo de parametros
$submateria = false;
if($gpo_nom != "ELECTIVA"){
//Obtiene id gpo a partir de nombre
$stmt = $pdo->prepare('SELECT * FROM fs_grupo(NULL, :per, :nombre)');
$stmt->bindParam(":per", $periodo_id);
$stmt->bindParam(":nombre", $gpo_nom);
if(!$stmt->execute()){
echo "Error al consultar la clave de usuario";
exit();
}else{
$gpo_rs = $stmt->fetch();
if(empty($gpo_rs)){
echo "No existe el grupo";
exit();
}
$gpo = $gpo_rs["Grupo_id"];
}
$stmt->closeCursor();
//----------
$stmt = $pdo->prepare('Select * from fs_profesoresmateriagrupo(:per, :mat, :gpo, NULL, NULL, NULL)');
$stmt->bindParam(":mat", $mat);
$stmt->bindParam(":per", $periodo_id);
$stmt->bindParam(":gpo", $gpo);
if(!$stmt->execute()){
$t = $stmt->errorInfo();
echo "Ocurrió un error al obtener los datos de los profesores ".$t[2];
exit();
}
$profesor_rs = $stmt->fetchAll();
$stmt->closeCursor();
$usr = $profesor_rs[0]["Usuario_id"];
$usr_nombre = $profesor_rs[0]["Usuario_nombre"]." ".$profesor_rs[0]["Usuario_apellidos"];
//----------
$stmt = $pdo->prepare('Select * from fs_syllabus(:periodo, :prof, :mat, :gpo, NULL )');
$stmt->bindParam(":periodo", $periodo_id);
$stmt->bindParam(":mat", $mat);
$stmt->bindParam(":gpo", $gpo);
foreach ($profesor_rs as $pr){
$usr = $pr["Usuario_id"];
$usr_nombre = $pr["Usuario_nombre"]." ".$pr["Usuario_apellidos"];
$stmt->bindParam(":prof", $usr);
if(!$stmt->execute()){
$errorDesc = "Error al cargar los datos del alumno";
echo $errorDesc;
print_r($stmt->errorInfo());
exit();
}
$syllabus_rs = $stmt->fetch();
if(!empty($syllabus_rs)){
break;
}
}
$stmt->closeCursor();
}else{
$usr = $tmp[4];
$stmt = $pdo->prepare('Select * from fs_usuario(:id)');
$stmt->bindParam(":id", $usr);
if(!$stmt->execute()){
$t = $stmt->errorInfo();
echo "Ocurrió un error al obtener los datos de los profesores ".$t[2];
exit();
}
$profesor_rs = $stmt->fetch();
$stmt->closeCursor();
$usr_nombre = $profesor_rs["Usuario_nombre"]." ".$profesor_rs["Usuario_apellidos"];
//----------
$stmt = $pdo->prepare('Select * from fs_syllabus(:periodo, :prof, NULL, NULL, :sub )');
$stmt->bindParam(":periodo", $periodo_id);
$stmt->bindParam(":prof", $usr);
$stmt->bindParam(":sub", $mat);
if(!$stmt->execute()){
$errorDesc = "Error al cargar los datos del alumno";
echo $errorDesc;
print_r($stmt->errorInfo());
exit();
}
$syllabus_rs = $stmt->fetch();
$gpo = $syllabus_rs["Grupo_id"];
$stmt->closeCursor();
$submateria = true;
}
// -------------
$stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, NULL )');
$stmt->bindParam(":periodo", $periodo_id);
if(!$stmt->execute()){
$errorDesc = "Error al cargar los datos del alumno";
echo $errorDesc;
print_r($stmt->errorInfo());
exit();
}
$periodo_rs = $stmt->fetch();
$stmt->closeCursor();
$fecha_min = $periodo_rs["Periodo_fecha_inicial"];
$fecha_max = $periodo_rs["Periodo_fecha_final"];
//Obtiene materias de profesor
if(!$submateria){
$stmt = $pdo->prepare('Select * from fs_materiadias(:usr, :mat, :gpo, NULL)');
$stmt->bindParam(":mat", $mat);
}else{
echo "Select * from fs_materiadias($usr, NULL, $gpo, $mat)";
$stmt = $pdo->prepare('Select * from fs_materiadias(:usr, NULL, :gpo, :sub)');
$stmt->bindParam(":sub", $mat);
}
//echo "Select * from fs_materiadias($usr, $mat, $gpo, $sub)"; exit();
$stmt->bindParam(":usr", $usr);
$stmt->bindParam(":gpo", $gpo);
if(!$stmt->execute()){
//print_r($stmt->errorInfo());
$errorDesc = "Ocurrió un error al cargar los días de las materias";
echo $errorDesc;
exit();
}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;
//-----
// ---- Obtiene fechas de vacaciones
$stmt = $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()){
$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
$MESES = array(1=>"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
$DIAS = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
$calendario = array();
$fechasArr = array();
$fecha = $fecha_min;
$semOld=1;
$cont = 0;
if(count($diasMatArr)==0){
echo "No hay días registrados
";exit();
}else{
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 = 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"=>$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"=>$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);
$mesMin = $calendario[0]["fechas"][0]["mes"];
$mesMax = $calendario[count($calendario)-1]["fechas"][0]["mes"];
$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($electiva){
$stmt = $pdo->prepare('Select * from fs_sesioncatedra(NULL, :usr, :gpo, :sub, NULL)');
$stmt->bindParam(":sub", $mat);
}else{
$stmt = $pdo->prepare('Select * from fs_sesioncatedra(:mat, :usr, :gpo, NULL, NULL)');
$stmt->bindParam(":mat", $mat);
}
$stmt->bindParam(":usr", $usr);
$stmt->bindParam(":gpo", $gpo);
if(!$stmt->execute()){
//print_r($stmt->errorInfo());
$errorDesc = "Ocurrió un error al cargar las sesiones del plan de cátedra";
}else{
$rs = $stmt->fetchAll();
$sesionesArr = array();
$ses_old = -1;
$subsesionArr = array();
$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));
}
}
//print_r($sesionesArr); exit();
$stmt->closeCursor();
$stmt = null;
if($electiva){
$stmt = $pdo->prepare('SELECT * FROM fs_submateria_materia(:gpo, :usr, :sub)');
$stmt->bindParam(":gpo", $gpo);
$stmt->bindParam(":usr", $usr);
$stmt->bindParam(":sub", $mat);
if(!$stmt->execute()){
$errorDesc = "Error al cargar los datos de la materia";
echo $errorDesc;
print_r($stmt->errorInfo());
exit();
}
$submat_rs = $stmt->fetch();
$stmt = $pdo->prepare('Select * 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(":mat", $submat_rs["materia_id"]);
}else{
$stmt = $pdo->prepare('Select * 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(":mat", $mat);
}
$stmt->bindParam(":gpo", $gpo);
if(!$stmt->execute()){
$errorDesc = "Error al cargar los datos del horario";
echo $errorDesc;
print_r($stmt->errorInfo());
exit();
}
$horario_rs = $stmt->fetchAll();
$stmt->closeCursor();
//---Tipo de sesiones plan cátedra
$stmt = $pdo->prepare('Select * from fs_sesioncatedra_tipo(NULL)');
if(!$stmt->execute()){
//print_r($stmt->errorInfo());
$errorDesc = "Ocurrió un error al cargar los días de las materias";
}else{
$tipoSesionArr = $stmt->fetchAll();
}
$stmt->closeCursor();
$stmt = null;
}else{
$errorDesc = $lti->message;
$errorDesc .="- No se pueden obtener los datos del curso para generar el pdf.";
echo $errorDesc;
exit();
}
//-----
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$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',
]);
//$mpdf->SetDisplayMode('fullpage');
$stylesheet = "";
$xtpl = new XTemplate('../apsa/tpl/plancatedra.tpl.html');
$mat_nombre = isset($syllabus_rs["Submateria_desc"])?$syllabus_rs["Submateria_desc"]:$syllabus_rs["Materia_desc"];
$xtpl->assign("MATERIA", $mat_nombre." ".$gpo_nom);
$xtpl->assign("SEMESTRE", $syllabus_rs["Materia_semestre"]);
$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.fechas");
}
foreach($tipoSesionArr as $tses){
$xtpl->assign("COLOR", $tses["SesionCatedraTipo_color"]);
$xtpl->assign("TIPO", $tses["SesionCatedraTipo_desc"]);
$xtpl->parse("main.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($MESES[$mes_old]));
$xtpl->parse("main.sesion.mes");
$xtpl->parse("main.sesion");
}
$fechaArr = explode(" ",$dia["dia"]." ".fechaSlash($dia["fecha"]));
$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 = getSesiones($sesionesArr, $dia["numSesion"]);
if(count($sesArr) > 0){
foreach($sesArr as $ses){
if($ses["tipo_id"] == 1)
$xtpl->assign("COLOR", getRGBA_color($ses["color"], 0.0));
else
$xtpl->assign("COLOR", getRGBA_color($ses["color"], 0.3));
$xtpl->assign("DESC", $ses["desc"]);
$xtpl->parse("main.sesion.regular.tema");
}
$xtpl->parse("main.sesion.regular");
}else{
$xtpl->assign("COLOR", getRGBA_color("#ffffff", 0));
$xtpl->assign("DESC", "");
$xtpl->parse("main.sesion.regular");
}
}else{
$xtpl->assign("DESC", $dia["titulo"]);
$xtpl->parse("main.sesion.vacacion");
}
$xtpl->parse("main.sesion");
}
}
$xtpl->parse("main");
//echo $stylesheet;
//$xtpl->out("main"); exit;
$header = '
 |
PLAN DE CATEDRA | FACULTAD DE INGENIERÍA |
';
$mpdf->SHYlang = 'es';
$mpdf-> SetTitle('Plan de cátedra -' . $mat_nombre);
$mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("Y").' Todos los derechos Reservados.');
$mpdf->SetHTMLHeader($header);//se pone como fondo
$mpdf->SetHTMLFooter('
');//se pone como fondo
$mpdf->WriteHTML($stylesheet);
if(!isset($errorDesc))
$mpdf->WriteHTML($xtpl->text("main"));
else
$mpdf->WriteHTML($errorDesc);
$mpdf->Output("planCátedra_".getIniciales($mat_nombre)."_".$gpo_nom.".pdf", 'I');
?>