pdf_syllabus.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. //ini_set('display_errors', 1);
  3. //error_reporting(E_ALL);
  4. require_once './ims-blti/blti.php';
  5. setlocale(LC_TIME, 'es_MX.UTF-8');
  6. require_once("../include/nocache.php");
  7. require_once("../include/bd_pdo.php");
  8. require_once("../include/util.php");
  9. include_once('../include/xTemplate/xtemplate.class.php'); // including mpdf.php
  10. include_once('../include/mpdf/autoload.php'); // including mpdf.php
  11. $lti = new BLTI("Pl4n&Syll4bus", false, false);
  12. if (!$lti->valid) {//si está fuera de moodle consulta por variables get (para pruebas)
  13. if(!empty($_GET["shortname"]) && !empty($_GET["periodo"]) && !empty($_GET["username"])){
  14. $clave_ulsa = intval(substr($_GET["username"], 2));//clave como entero
  15. $tmp = explode("-", $_GET["shortname"]);//Shortname
  16. $gpo_nom = $tmp[0];
  17. $iniciales = $tmp[1];
  18. $mat = $tmp[3];
  19. $periodo_id = $_GET["periodo"]; //Obtenerlo de parametros
  20. }else{
  21. $errorDesc = $lti->message;
  22. $errorDesc .="- No se pueden obtener los datos del curso para generar el pdf.";
  23. echo $errorDesc;
  24. exit();
  25. }
  26. }else {// LTI de conexión a moodle
  27. if(substr_count($lti->info["context_label"], "-")<3){//valida que el shortname tenga 3 o más -
  28. echo "<h1>Error</h1><p>No se puede hacer la consulta porque el shortaname no es válido.</p>";
  29. exit();
  30. }
  31. $clave_ulsa = intval(substr($lti->info["ext_user_username"], 2));//clave como entero
  32. $tmp = explode("-", $lti->info["context_label"]);//Shortname
  33. $gpo_nom = $tmp[0];// Gpo
  34. $iniciales = $tmp[1]; //Iniciales de materia
  35. $mat = $tmp[3];//ID materia
  36. $periodo_id = $lti->info["custom_periodo"]; //Obtener periodo de parametros de herramienta externa
  37. }
  38. if($gpo_nom != "ELECTIVA"){//No es electiva
  39. //Obtiene id gpo a partir de nombre
  40. $stmt = $pdo->prepare('SELECT * FROM fs_grupo(NULL, :per, :nombre)');
  41. $stmt->bindParam(":per", $periodo_id);
  42. $stmt->bindParam(":nombre", $gpo_nom);
  43. if(!$stmt->execute()){
  44. echo "Error al consultar la clave de usuario";
  45. exit();
  46. }else{
  47. $gpo_rs = $stmt->fetch();
  48. if(empty($gpo_rs)){
  49. echo "No existe el grupo";
  50. exit();
  51. }
  52. $gpo = $gpo_rs["Grupo_id"];
  53. }
  54. $stmt->closeCursor();
  55. //----------
  56. $stmt = $pdo->prepare('Select * from fs_profesoresmateriagrupo(:per, :mat, :gpo, NULL, NULL)');
  57. $stmt->bindParam(":per", $periodo_id);
  58. $stmt->bindParam(":mat", $mat);
  59. $stmt->bindParam(":gpo", $gpo);
  60. if(!$stmt->execute()){
  61. $t = $stmt->errorInfo();
  62. echo "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  63. exit();
  64. }
  65. $profesor_rs = $stmt->fetchAll();
  66. $stmt->closeCursor();
  67. $usr = $profesor_rs[0]["Usuario_id"];
  68. $usr_nombre = $profesor_rs[0]["Usuario_nombre"]." ".$profesor_rs[0]["Usuario_apellidos"];
  69. //----------
  70. $stmt = $pdo->prepare('Select * from fs_syllabus(:periodo, :prof, :mat, :gpo, NULL )');
  71. $stmt->bindParam(":periodo", $periodo_id);
  72. $stmt->bindParam(":mat", $mat);
  73. $stmt->bindParam(":gpo", $gpo);
  74. $syllabus_rs = array();
  75. foreach ($profesor_rs as $pr){
  76. $usr = $pr["Usuario_id"];
  77. $usr_nombre = $pr["Usuario_nombre"]." ".$pr["Usuario_apellidos"];
  78. $stmt->bindParam(":prof", $usr);
  79. if(!$stmt->execute()){
  80. $errorDesc = "Error al cargar los datos del alumno";
  81. echo $errorDesc;
  82. print_r($stmt->errorInfo());
  83. exit();
  84. }
  85. //$syllabus_rs = $stmt->fetch();
  86. $s_rs = $stmt->fetch();
  87. if(!empty($s_rs)){
  88. //break;
  89. $syllabus_rs[] = $s_rs;
  90. }
  91. }
  92. $stmt->closeCursor();
  93. }else{
  94. $usr = $tmp[4];//Último campo del shortname es is del usuario de electiva
  95. $stmt = $pdo->prepare('Select * from fs_usuario(:id)');
  96. $stmt->bindParam(":id", $usr);
  97. if(!$stmt->execute()){
  98. $t = $stmt->errorInfo();
  99. echo "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  100. exit();
  101. }
  102. $profesor_rs = $stmt->fetch();
  103. $stmt->closeCursor();
  104. $usr_nombre = $profesor_rs["Usuario_nombre"]." ".$profesor_rs["Usuario_apellidos"];
  105. //----------
  106. $stmt = $pdo->prepare('Select * from fs_syllabus(:periodo, :prof, NULL, NULL, :sub )');
  107. $stmt->bindParam(":periodo", $periodo_id);
  108. $stmt->bindParam(":prof", $usr);
  109. $stmt->bindParam(":sub", $mat);
  110. if(!$stmt->execute()){
  111. $errorDesc = "Error al cargar los datos del alumno";
  112. echo $errorDesc;
  113. print_r($stmt->errorInfo());
  114. exit();
  115. }
  116. $syllabus_rs = [];
  117. //$syllabus_rs = $stmt->fetch();
  118. $s_rs = $stmt->fetch();
  119. $syllabus_rs[] = $s_rs;
  120. $gpo = $syllabus_rs["Grupo_id"];
  121. $stmt->closeCursor();
  122. }
  123. if(empty($syllabus_rs) || count($syllabus_rs)==0){
  124. echo "<h1 style='text-align:center; margin:2em 0'>No hay contenido guardado para el syllabus</h1>";
  125. exit();
  126. }
  127. // -------------
  128. $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, NULL )');
  129. $stmt->bindParam(":periodo", $periodo_id);
  130. if(!$stmt->execute()){
  131. $errorDesc = "Error al cargar los datos del alumno";
  132. echo $errorDesc;
  133. print_r($stmt->errorInfo());
  134. exit();
  135. }
  136. $periodo_rs = $stmt->fetch();
  137. $stmt->closeCursor();
  138. $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"');
  139. $stmt->bindParam(":gpo", $gpo);
  140. $stmt->bindParam(":mat", $mat);
  141. if(!$stmt->execute()){
  142. $errorDesc = "Error al cargar los datos del horario";
  143. echo $errorDesc;
  144. print_r($stmt->errorInfo());
  145. exit();
  146. }
  147. $horario_rs = $stmt->fetchAll();
  148. $stmt->closeCursor();
  149. //-----
  150. $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
  151. $fontDirs = $defaultConfig['fontDir'];
  152. $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
  153. $fontData = $defaultFontConfig['fontdata'];
  154. $mpdf = new \Mpdf\Mpdf([
  155. 'mode' => 'utf-8',
  156. 'format' => [215, 279],
  157. 'orientation' => 'P',
  158. 'margin_left' => 14,
  159. 'margin_right' => 14,
  160. 'margin_top' => 27,
  161. 'margin_bottom' => 27,
  162. 'fontDir' => array_merge($fontDirs, [
  163. __DIR__ . '/../fonts/indivisaFont/ttf',
  164. ]),
  165. 'fontdata' => $fontData + [
  166. 'indivisa-display' => [
  167. 'R' => 'IndivisaDisplaySans-Regular.ttf',
  168. ],
  169. 'indivisa-title' => [
  170. 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
  171. ],
  172. 'indivisa-text' => [
  173. 'R' => 'IndivisaTextSans-Regular.ttf',
  174. ]
  175. ],
  176. 'default_font' => 'indivisa-text',
  177. ]);
  178. //$mpdf->SetDisplayMode('fullpage');
  179. $stylesheet = "<style>";
  180. $stylesheet .= file_get_contents('../css/indivisa.css'); // external css
  181. $stylesheet .= file_get_contents('../apsa/css/syllabus.css'); // external css
  182. $stylesheet .= "</style>";
  183. $xtpl = new XTemplate('../apsa/tpl/syllabus.tpl.html');
  184. $i=0;
  185. foreach($syllabus_rs as $data){
  186. $mat_nombre = isset($data["Submateria_desc"])?$data["Submateria_desc"]:$data["Materia_desc"];
  187. $xtpl->assign("MATERIA", $mat_nombre." ".$gpo_nom);
  188. $xtpl->assign("SEMESTRE", $data["Materia_semestre"]);
  189. $xtpl->assign("PERIODO", $periodo_rs["Periodo_desc"]);
  190. $xtpl->assign("PROFESOR", $usr_nombre);
  191. foreach($horario_rs as $h){
  192. $hora = substr($h["Horario_hora"], 0, 5);
  193. if($h["Salon_desc"]==""){
  194. $salon = "Salón pendiente";
  195. }else{
  196. $salon = $h["Salon_desc"];
  197. if($h["Salon_desc_larga"] != ""){
  198. $salon .=" (".$h["Salon_desc_larga"].")";
  199. }
  200. }
  201. $xtpl->assign("DIA", $h["Dia_desc"]);
  202. $xtpl->assign("HORA", $hora);
  203. $xtpl->assign("SALON", $salon);
  204. $xtpl->parse("main.content.fechas");
  205. }
  206. //---Atributos
  207. //Obtiene mapa
  208. $stmt = $pdo->prepare('select * from fs_atributoegreso_materia(:mat)');
  209. $stmt->bindParam(":mat", $mat);
  210. if(!$stmt->execute()){
  211. header("Location: ".$pag."?error=5");
  212. }else{
  213. $atributos_rs = $stmt->fetchAll();
  214. }
  215. //----
  216. $datos = array(
  217. array("titulo"=>"Información de la asignatura", "bd"=>"informacion", "subbloques"=>
  218. array(
  219. array("subtitulo"=>"Descripción","bd"=>"desc", "nobreak"=>false),
  220. array("subtitulo"=>"Objetivos","bd"=>"obj", "nobreak"=>false),
  221. array("subtitulo"=>"Capacidades y habilidades que desarrollar","bd"=>"capacidades", "nobreak"=>false),
  222. array("subtitulo"=>"Prerrequisitos","bd"=>"prerrequisitos", "nobreak"=>false),
  223. array("subtitulo"=>"Temario","bd"=>"temario", "nobreak"=>false),
  224. array("subtitulo"=>"Construcción de la calificación final","bd"=>"calificacion", "nobreak"=>true),
  225. array("subtitulo"=>"Fechas importantes","bd"=>"fechas", "nobreak"=>true),
  226. )
  227. ),
  228. array("titulo"=>"Lineamientos generales", "bd"=>"", "subbloques"=>
  229. array(
  230. array("subtitulo"=>"De la asistencia y puntualidad","bd"=>"asistencia", "nobreak"=>false),
  231. array("subtitulo"=>"Del comportamiento en clase","bd"=>"comportamiento", "nobreak"=>false),
  232. array("subtitulo"=>"De los exámenes","bd"=>"examenes", "nobreak"=>false),
  233. array("subtitulo"=>"De las tareas, prácticas y exposiciones","bd"=>"tareas", "nobreak"=>false),
  234. array("subtitulo"=>"Trabajos de investigación","bd"=>"investigacion", "nobreak"=>false),
  235. )
  236. ),
  237. array("titulo"=>"Bibliografía recomendada", "bd"=>"bibliografia", "subbloques"=>
  238. array(
  239. array("subtitulo"=>"","bd"=>"", "nobreak"=>true, "texto"=>"La/el docente que imparte la presente materia, en sus opiniones, posturas o críticas, citas o referencias de consulta, por la metodología didáctica que utiliza, por las herramientas pedagógicas de apoyo en la práctica educativa y, el desarrollo de los contenidos que integran el programa de la presente asignatura o por la implementación del modelo educativo de la Universidad, no tiene por objeto obstaculizar, restringir, impedir, menoscabar, anular o suprimir la orientación sexual, identidad o expresión de género de su alumnado; por ello, partiendo de su derecho de libertad de cátedra, enseña y promueve la construcción de conocimientos con objetividad e imparcialidad, sin censura ni restricciones, propiciando el debate y el análisis de los temas para enriquecer el aprendizaje, sin tener más límite que el respeto a los derechos del estudiantado."),
  240. )
  241. )
  242. );
  243. $atributos = false;
  244. foreach($datos as $bloque){
  245. $xtpl->assign("TITULO", $bloque["titulo"]);
  246. if($bloque["bd"]!= ""){
  247. $xtpl->assign("INFO", $data["Syllabus_".$bloque["bd"]]);
  248. $xtpl->parse("main.content.bloque.titulo.info");
  249. $xtpl->parse("main.content.bloque.titulo");
  250. $xtpl->parse("main.content.bloque");
  251. }
  252. if(!$atributos ){
  253. $atributos = true;
  254. if(count($atributos_rs) > 0){
  255. $html = "<ul>";
  256. foreach($atributos_rs as $atr){
  257. $html.="<li><b>Atributo {$atr["AtributoEgreso_id"]} nivel {$atr["AtributoNivel_desc"]}:</b> {$atr["AtributoEgreso_desc"]}</li>";
  258. }
  259. $html.="</ul>";
  260. $xtpl->assign("SUBTITULO", "Atributos de egreso");
  261. $xtpl->assign("INFO", $html);
  262. $xtpl->parse("main.content.bloque.subbloque");
  263. $xtpl->parse("main.content.bloque");
  264. }
  265. }
  266. foreach($bloque["subbloques"] as $subbloque){
  267. $xtpl->assign("SUBTITULO", $subbloque["subtitulo"]);
  268. if($subbloque["bd"]!= ""){
  269. $xtpl->assign("INFO", $data["Syllabus_".$subbloque["bd"]]);
  270. }else{
  271. $xtpl->assign("INFO", $subbloque["texto"]);
  272. }
  273. if($subbloque["nobreak"]) $xtpl->parse("main.content.bloque.subbloque_nobreak");
  274. else $xtpl->parse("main.content.bloque.subbloque");
  275. $xtpl->parse("main.content.bloque");
  276. }
  277. }
  278. $i++;
  279. if($i < count($syllabus_rs)){
  280. $xtpl->parse("main.content.pagebreak");
  281. }
  282. $xtpl->parse("main.content");
  283. }
  284. $xtpl->parse("main");
  285. /*if(isset($lti->info["html"])){
  286. echo $stylesheet;
  287. $xtpl->out("main"); exit;
  288. }*/
  289. //echo $stylesheet;
  290. //$xtpl->out("main"); exit;
  291. $header = '<table style="width:100%"><tr>
  292. <td><img src="../img/logopdf.png" width="40mm" class=""></td>
  293. <td align="right"><h1 class="titulo">SYLLABUS | FACULTAD DE INGENIERÍA</h1></td>
  294. </tr></table>';
  295. $mpdf->SHYlang = 'es';
  296. $mpdf-> SetTitle('Syllabus -' . $mat_nombre);
  297. $mpdf-> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. '.date("Y").' Todos los derechos Reservados.');
  298. $mpdf->SetHTMLHeader($header);//se pone como fondo
  299. $mpdf->SetHTMLFooter('<img src="../img/footer_docs.png" >');//se pone como fondo
  300. $mpdf->WriteHTML($stylesheet);
  301. if(!isset($errorDesc))
  302. $mpdf->WriteHTML($xtpl->text("main"));
  303. else
  304. $mpdf->WriteHTML($errorDesc);
  305. $mpdf->Output("syllabus_".getIniciales($mat_nombre)."_".$gpo_nom.".pdf", 'I');//Inline Download
  306. ?>