pdf_mihorario.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /* AJAX
  3. * Genera nombramientos en pdf
  4. * Recibe:
  5. * id (de usuario)
  6. * Return:
  7. * imprime pdf
  8. */
  9. setlocale(LC_TIME, 'es_MX.UTF-8');
  10. require_once("../../include/nocache.php");
  11. require_once("../../include/constantes.php");
  12. require_once("../../include/bd_pdo.php");
  13. require_once("../../include/util.php");
  14. require_once("../../classes/ValidaSesion.php");
  15. include_once('../../include/xTemplate/xtemplate.class.php'); // including mpdf.php
  16. include_once('../../include/mpdf/autoload.php'); // including mpdf.php
  17. $pag = "../perfil.php";
  18. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  19. $objSesion = new ValidaSesion($pdo, 20, APSA);
  20. if(!$objSesion->tieneAcceso()){
  21. header("Location: ".$pag."?error=3");
  22. exit();
  23. }
  24. unset($objValida);
  25. if(!isset($_SESSION["periodo_id"]) || $_SESSION["periodo_id"] ==""){
  26. echo "Necesitas seleccionar un periodo.";
  27. exit();
  28. }
  29. //$usr = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  30. $usr = $_SESSION["usuario_id"];
  31. //Obtiene horario del usuario
  32. /*$stmt = $pdo->prepare('Select * from fs_mihorario(:usr, :per, 3)');//Obtiene todo el calendario
  33. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  34. $stmt->bindParam(":per", $_SESSION["periodo_id"]);
  35. if(!$stmt->execute()){
  36. //$t = $stmt->errorInfo();
  37. echo "Ocurrió un error al obtener los horarios ";
  38. exit();
  39. }*/
  40. if(isset($_POST["fecha"]) && $_POST["fecha"] != ""){
  41. $filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  42. }
  43. if(!isset($filter_fecha)){
  44. $stmt = $pdo->prepare('Select * from fs_mihorario(:usr, :per, 3)');//Obtiene todo el calendario
  45. $stmt->bindParam(":per", $_SESSION["periodo_id"]);
  46. }else{
  47. $stmt = $pdo->prepare('Select * from fs_mihorariofull(:usr, :fecha, 3)');//Obtiene todo el calendario
  48. $stmt->bindParam(":fecha", $filter_fecha);
  49. }
  50. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  51. if($stmt->execute())
  52. $horario_rs = $stmt->fetchAll();
  53. /*$horaMin = horaMin($horario_rs, "Hora_inicio");
  54. $horaMax = horaMax($horario_rs, "Hora_final");*/
  55. $horaMin = HORA_INICIO.":00";
  56. $horaMax = HORA_FINAL.":00";
  57. $stmt->closeCursor();
  58. //---
  59. $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
  60. if(!$stmt->execute()){
  61. echo "Error al obtener los días";
  62. exit();
  63. }
  64. $dias_rs = $stmt->fetchAll();
  65. $stmt->closeCursor();
  66. //---
  67. $stmt = $pdo->prepare('Select * from fs_usuario(:usr)');
  68. $stmt->bindParam(":usr", $usr);
  69. if(!$stmt->execute()){
  70. echo "Error al obtener los datos del usuario";
  71. exit();
  72. }
  73. $usr_rs = $stmt->fetch();
  74. $stmt->closeCursor();
  75. $nombre_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
  76. unset($usr_rs);
  77. //---
  78. $stmt = $pdo->prepare('Select * from fs_superiorusuario(:usr, NULL)');
  79. $stmt->bindParam(":usr", $usr);
  80. //$stmt->bindParam(":puesto", $puesto_id);
  81. if(!$stmt->execute()){
  82. echo "Error al obtener los datos del usuario superior";
  83. exit();
  84. }
  85. $usr_rs = $stmt->fetch();
  86. $stmt->closeCursor();
  87. $nombreSup_usr = $usr_rs["Usuario_apellidos"]." ".$usr_rs["Usuario_nombre"];
  88. unset($usr_rs);
  89. //Obtiene 2 corrreos
  90. $stmt = $pdo->prepare('Select * from fs_contacto(:id, 3 , NULL) ORDER BY "PerfilContacto_id"');//3 correo, Null todos
  91. $stmt->bindParam(":id", $usr);
  92. if(!$stmt->execute()){
  93. echo "Error al obtener los datos del correo";
  94. exit();
  95. }else{
  96. $contacto_rs = $stmt->fetchAll();
  97. $correos = array();
  98. $c_i = 0;
  99. $c_j = 0;
  100. for($c_j=0; $c_j< count($contacto_rs); $c_j++ ){
  101. if( strpos($contacto_rs[$c_j]["Contacto_valor"], "lasalle.mx") !== false || strpos($contacto_rs[$c_j]["Contacto_valor"], "lasallistas.org.mx") !== false ){
  102. $correos[] = $contacto_rs[$c_j]["Contacto_valor"];
  103. $c_i++;
  104. }
  105. }
  106. $datos["correo1"] = "";
  107. $datos["correo2"] = "";
  108. if($c_i>0){
  109. $datos["correo1"] = $correos[0];
  110. }
  111. if($c_i>1){
  112. $datos["correo2"] = $correos[1];
  113. }
  114. }
  115. $stmt->closeCursor(); // cierra conexion de resultado
  116. //-----
  117. $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
  118. $fontDirs = $defaultConfig['fontDir'];
  119. $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
  120. $fontData = $defaultFontConfig['fontdata'];
  121. $mpdf = new \Mpdf\Mpdf([
  122. 'mode' => 'utf-8',
  123. 'format' => [215, 279],
  124. 'orientation' => 'P',
  125. 'fontDir' => array_merge($fontDirs, [
  126. __DIR__ . '/../../fonts/indivisaFont/ttf',
  127. ]),
  128. 'fontdata' => $fontData + [
  129. 'indivisa-display' => [
  130. 'R' => 'IndivisaDisplaySans-Regular.ttf',
  131. ],
  132. 'indivisa-title' => [
  133. 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
  134. ],
  135. 'indivisa-text' => [
  136. 'R' => 'IndivisaTextSans-Regular.ttf',
  137. ]
  138. ],
  139. 'default_font' => 'indivisa-text',
  140. ]);
  141. //$mpdf->SetDisplayMode('fullpage');
  142. $stylesheet = "<style>";
  143. $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
  144. $stylesheet .= file_get_contents('../css/mihorario_reporte.css'); // external css
  145. $stylesheet .= "</style>";
  146. //echo $stylesheet;
  147. $xtpl = new XTemplate('../tpl/mihorario_reporte.tpl.html');
  148. $xtpl->assign("NOMBRE", $nombre_usr);
  149. if($datos["correo1"] != ""){
  150. $xtpl->assign("CORREO", $datos["correo1"]);
  151. $xtpl->parse("main.datos.correo");
  152. }
  153. if($datos["correo2"] != ""){
  154. $xtpl->assign("CORREO", $datos["correo2"]);
  155. $xtpl->parse("main.datos.correo");
  156. }
  157. $xtpl->assign("PUESTO", "");
  158. $xtpl->assign("AREA", "");
  159. $xtpl->assign("SUPERIOR", $nombreSup_usr);
  160. $xtpl->assign("HOY", date("d/m/Y"));
  161. $xtpl->assign("PERIODO", $_SESSION["periodo_desc"]);
  162. $xtpl->parse("main.datos");
  163. foreach($dias_rs as $dia){
  164. $xtpl->assign("DIA", $dia["Dia_desc"]);
  165. $xtpl->parse("main.header");
  166. }
  167. $rs_i = 0;
  168. $spacerArr = array(1=>0,0,0,0,0,0);
  169. $total_tipo = array(1=>0,0,0);
  170. //$horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
  171. for($h = date('H', strtotime($horaMin)); $h < date('H', strtotime($horaMax)); $h++){
  172. $xtpl->assign("HORA", date('H', strtotime($h.":00")));
  173. $xtpl->assign("FRACCIONES", FRACCION_HORA);
  174. $xtpl->parse("main.hora_row.hora");
  175. for($f = 0; $f < FRACCION_HORA; $f++){
  176. foreach($dias_rs as $dia){
  177. if($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]){
  178. $size = $horario_rs[$rs_i]["Duracion"]/(60/FRACCION_HORA);
  179. $spacerArr[$dia["Dia_id"]] = $size -1;
  180. $xtpl->assign("DURACION_SIZE", $size);
  181. $xtpl->assign("COLOR", $horario_rs[$rs_i]["TipoHorario_color"]);
  182. $xtpl->assign("TIPO", $horario_rs[$rs_i]["TipoHorario_desc"]);
  183. $total_tipo[$horario_rs[$rs_i]["TipoHorario_id"]]+= $horario_rs[$rs_i]["Duracion"]/60;
  184. $xtpl->assign("HORA_I", date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])));
  185. $xtpl->assign("HORA_F", date('H:i', strtotime($horario_rs[$rs_i]["Hora_final"])));
  186. $xtpl->parse("main.hora_row.td.td_mihorario.hora");
  187. $salon = "";
  188. do{
  189. if($horario_rs[$rs_i]["Salon_desc"] != "") $salon = "Salón: ".$horario_rs[$rs_i]["Salon_desc"];
  190. else if($horario_rs[$rs_i]["Materia_desc"] != "") $salon = "<em>Pendiente</em>";
  191. $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]);
  192. $xtpl->assign("GRUPO", $horario_rs[$rs_i]["Grupo_desc"]." ".$horario_rs[$rs_i]["Carrera_prefijo"]);
  193. if($horario_rs[$rs_i]["Materia_desc"] != "")
  194. $xtpl->parse("main.hora_row.td.td_mihorario.texto");
  195. $rs_i++;
  196. }while($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i-1]["Hora_inicio"])) == date('H:i', strtotime($horario_rs[$rs_i]["Hora_inicio"])) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]);
  197. $xtpl->assign("SALON", $salon);
  198. $xtpl->parse("main.hora_row.td.td_mihorario");
  199. }else{
  200. if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
  201. $xtpl->parse("main.hora_row.td.td_vacio");
  202. else
  203. $spacerArr[$dia["Dia_id"]]--;
  204. }
  205. $xtpl->parse("main.hora_row.td");
  206. }
  207. $xtpl->parse("main.hora_row");
  208. }
  209. }
  210. $xtpl->parse("main.logo");
  211. $stmt = $pdo->prepare('Select * from fs_tipohorario(NULL, NULL)');
  212. $stmt->execute();
  213. $tipo_rs = $stmt->fetchAll();
  214. $stmt->closeCursor();
  215. foreach($tipo_rs as $tipo){
  216. $xtpl->assign("COLOR", $tipo["TipoHorario_color"]);
  217. $xtpl->assign("DESC", $tipo["TipoHorario_desc"]);
  218. $xtpl->assign("TOTAL", $total_tipo[$tipo["TipoHorario_id"]]);
  219. $xtpl->parse("main.tipo_row");
  220. }
  221. $xtpl->assign("COLOR", '#fff');
  222. $xtpl->assign("DESC", "Total de horas");
  223. $xtpl->assign("TOTAL", $total_tipo[1]+$total_tipo[2]+$total_tipo[3]);
  224. $xtpl->parse("main.tipo_row");
  225. $xtpl->parse("main");
  226. //$xtpl->out("main"); exit();
  227. $mpdf->WriteHTML($stylesheet);
  228. if(!isset($errorDesc))
  229. $mpdf->WriteHTML($xtpl->text("main"));
  230. else
  231. $mpdf->WriteHTML($errorDesc);
  232. $mpdf->Output("horariousuario.pdf", 'I');
  233. ?>