pdf_nombramientos.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. /* AJAX
  6. * Genera nombramientos en pdf
  7. * Recibe:
  8. * fecha_inicial
  9. * fecha_final
  10. * fecha_inicial_extras
  11. * fecha_final_extras
  12. * Return:
  13. * imprime pdf
  14. */
  15. setlocale(LC_TIME, 'es_MX.UTF-8');
  16. require_once("../../include/nocache.php");
  17. require_once("../../include/bd_pdo.php");
  18. require_once("../../include/util.php");
  19. require_once("../../include/constantes.php");
  20. require_once("../../classes/ValidaSesion.php");
  21. include_once('../../include/xTemplate/xtemplate.class.php'); // including mpdf.php
  22. include_once('../../include/mpdf/autoload.php'); // including mpdf.php
  23. function generaMarcaDeAgua($marca, $carpeta) {
  24. $imagen = imagecreatetruecolor(344,143); // Crear la imagen de 591x379
  25. $textColor = imagecolorallocate($imagen, 224, 224, 224); //Colores del texto
  26. $transparente = imagecolorallocate ($imagen, 0, 0, 0); //Color que cambiará a transparene
  27. imagecolortransparent($imagen, $transparente); // Hacer el fondo transparente
  28. for ($cont = 0; $cont < 5; $cont++) { $marca .= $marca; }
  29. // Escribirlo
  30. for ($cont=1; $cont <= 50; $cont++){
  31. if ($cont%2 == 0)
  32. $val = -5;
  33. else
  34. $val = 5;
  35. imagestring($imagen,1, $val, 10*$cont, $marca, $textColor); //Escribe el texto
  36. }
  37. header('Content-Type: image/png');
  38. imagepng($imagen, $carpeta.'marca.png'); //Genera la imagen
  39. imagedestroy($imagen);
  40. }
  41. //$fechasArr[] ["busca"=>CODIGO, "reemplaza"=>fecha ]
  42. function cambiaFechas($texto, $fechasArr){
  43. $buscaArr = array();
  44. $reemplazaArr = array();
  45. foreach($fechasArr as $opt){
  46. $buscaArr[] = $opt["busca"];
  47. $reemplazaArr[] = $opt["reemplaza"];
  48. }
  49. return str_replace ($buscaArr, $reemplazaArr, $texto);
  50. }
  51. function directorioArea($texto){
  52. if($texto == "")
  53. return "";
  54. return "/".$texto;
  55. }
  56. $pag = "../nombramientos.php";
  57. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  58. $objSesion = new ValidaSesion($pdo, 54, APSA);
  59. if(!$objSesion->tieneAcceso()){
  60. header("Location: ".$pag."?error=3");
  61. exit();
  62. }
  63. unset($objValida);
  64. if(!isset($_POST["texto"]) || !isset($_POST["fecha_carta"]) /*|| !isset($_POST["fecha_inicial"]) || !isset($_POST["fecha_final"]) || !isset($_POST["fecha_inicial_extras"]) || !isset($_POST["fecha_final_extras"])*/){
  65. header("Location: ".$pag."?error=0");
  66. exit();
  67. }
  68. $texto = $_POST["texto"];
  69. $fecha_carta = fechaGuion(trim(filter_input(INPUT_POST, "fecha_carta", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  70. if(isset($_POST["profesor"]))
  71. $profesor = filter_input(INPUT_POST, "profesor", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  72. if(isset($_POST["categoria"]) && $_POST["categoria"]==1)
  73. $has_categoria = true;
  74. else
  75. $has_categoria = false;
  76. if(isset($_POST["pdf"]) && $_POST["pdf"] == 1){
  77. $pdf = true;
  78. }else{
  79. $pdf = false;
  80. }
  81. if(isset($_POST["split"]) && $_POST["split"] == 1){
  82. $split = true;
  83. }else{
  84. $split = false;
  85. }
  86. //----
  87. $stmt = $pdo->prepare('Select * from fs_director()');
  88. if(!$stmt->execute()){
  89. header("Location:".$pag."?error=1");
  90. //print_r($stmt->errorInfo());
  91. exit();
  92. }
  93. $director_rs = $stmt->fetch();
  94. $stmt->closeCursor();
  95. $stmt = null;
  96. $stmt = $pdo->prepare('Select * from fs_constanciafirma(NULL, NULL) where "Usuario_id" = :usr');
  97. $stmt->bindParam(":usr", $director_rs["Usuario_id"]);
  98. if(!$stmt->execute()){
  99. header("Location:".$pag."?error=1");
  100. //print_r($stmt->errorInfo());
  101. exit();
  102. }
  103. $firma_director = $stmt->fetch();
  104. $stmt->closeCursor();
  105. //-----
  106. $stmt = $pdo->prepare('Select * from fs_puesto(2)');//Secretario académico
  107. if(!$stmt->execute()){
  108. header("Location:".$pag."?error=1");
  109. //print_r($stmt->errorInfo());
  110. exit();
  111. }
  112. $secretario_rs = $stmt->fetch();
  113. $stmt->closeCursor();
  114. $stmt = null;
  115. $stmt = $pdo->prepare('Select * from fs_constanciafirma(NULL, NULL) where "Usuario_id" = :usr');
  116. $stmt->bindParam(":usr", $secretario_rs["Usuario_id"]);
  117. if(!$stmt->execute()){
  118. header("Location:".$pag."?error=1");
  119. //print_r($stmt->errorInfo());
  120. exit();
  121. }
  122. $firma_secretario = $stmt->fetch();
  123. $stmt->closeCursor();
  124. unset($tmp_rs);
  125. //Obtiene fechas de periodo
  126. $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)');
  127. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  128. if(!$stmt->execute()){
  129. header("Location:".$pag."?error=1");
  130. //print_r($stmt->errorInfo());
  131. exit();
  132. }
  133. $periodo_rs = $stmt->fetch();
  134. $nivel = $periodo_rs["Nivel_id"];
  135. $stmt->closeCursor();
  136. //---Inserta/Actualiza fechas importantes nuevas
  137. $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 4, :fechai, :fechaf )');//fecha de la carta
  138. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  139. $stmt->bindParam(":fechai", $fecha_carta);
  140. $stmt->bindParam(":fechaf", $fecha_carta);
  141. if(!$stmt->execute()){
  142. //echo "4";print_r($stmt->errorInfo());exit();
  143. header("Location:".$pag."?error=4");
  144. exit();
  145. }
  146. $stmt->closeCursor();
  147. $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 3 )');//fechas profesores
  148. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  149. if(!$stmt->execute()){
  150. //echo "4";print_r($stmt->errorInfo());exit();
  151. header("Location:".$pag."?error=4");
  152. exit();
  153. }
  154. $rs = $stmt->fetch();
  155. $stmt->closeCursor();
  156. $fecha_inicial = $rs["FechaImportante_inicial"];
  157. $fecha_final = $rs["FechaImportante_final"];
  158. $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 2 )');//fecha de extraordinarios
  159. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  160. if(!$stmt->execute()){
  161. //echo "4";print_r($stmt->errorInfo());exit();
  162. header("Location:".$pag."?error=4");
  163. exit();
  164. }
  165. $rs = $stmt->fetch();
  166. $stmt->closeCursor();
  167. if(!empty($rs["FechaImportante_inicial"])){
  168. $fecha_inicial_extras = $rs["FechaImportante_inicial"];
  169. $fecha_final_extras = $rs["FechaImportante_final"];
  170. }
  171. //Guarda nuevo texto de carta
  172. $stmt = $pdo->prepare('Select * from fi_cartanombramiento(:periodo, :text, :firmaD, :firmaS)');
  173. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  174. $stmt->bindParam(":text", $texto);
  175. $stmt->bindParam(":firmaD", $firma_director["ConstanciaFirma_id"]);
  176. $stmt->bindParam(":firmaS", $firma_secretario["ConstanciaFirma_id"]);
  177. if(!$stmt->execute()){
  178. //print_r($stmt->errorInfo());
  179. header("Location:".$pag."?error=5");
  180. exit();
  181. }
  182. $stmt->closeCursor();
  183. $stmt = null;
  184. //----
  185. $fechasArr = array();
  186. //Periodo tiene fechas de ciclo
  187. $fechasArr[] = array("busca"=>PR_INI, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_inicial"], false));
  188. $fechasArr[] = array("busca"=>PR_INI_Y, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_inicial"], true));
  189. $fechasArr[] = array("busca"=>PR_FIN, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_final"], false));
  190. $fechasArr[] = array("busca"=>PR_FIN_Y, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_final"], true));
  191. //forma tiene fechas periodo completo
  192. $fechasArr[] = array("busca"=>PE_INI, "reemplaza"=>fechaTexto($fecha_inicial, false));
  193. $fechasArr[] = array("busca"=>PE_INI_Y, "reemplaza"=>fechaTexto($fecha_inicial, true));
  194. $fechasArr[] = array("busca"=>PE_FIN, "reemplaza"=>fechaTexto($fecha_final, false));
  195. $fechasArr[] = array("busca"=>PE_FIN_Y, "reemplaza"=>fechaTexto($fecha_final, true));
  196. if($nivel == 1){
  197. //forma tiene fechas extraordinarios
  198. $fechasArr[] = array("busca"=>EX_INI, "reemplaza"=>fechaTexto($fecha_inicial_extras, false));
  199. $fechasArr[] = array("busca"=>EX_INI_Y, "reemplaza"=>fechaTexto($fecha_inicial_extras, true));
  200. $fechasArr[] = array("busca"=>EX_FIN, "reemplaza"=>fechaTexto($fecha_final_extras, false));
  201. $fechasArr[] = array("busca"=>EX_FIN_Y, "reemplaza"=>fechaTexto($fecha_final_extras, true));
  202. }
  203. $texto = cambiaFechas($texto, $fechasArr);
  204. if($nivel == 1){
  205. if($profesor == 0)
  206. if(!$split)
  207. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, NULL, 0, NULL)');
  208. else
  209. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_area(:periodo, NULL, 0, NULL)');
  210. else{
  211. if(!$split)
  212. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, :prof, 0, NULL)');
  213. else
  214. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_area(:periodo, :prof, 0, NULL)');
  215. $stmt->bindParam(":prof", $profesor);
  216. }
  217. }else{
  218. if($profesor == 0)
  219. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_carrera(:periodo, NULL)');
  220. else{
  221. $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_carrera(:periodo, :prof)');
  222. $stmt->bindParam(":prof", $profesor);
  223. }
  224. }
  225. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  226. if(!$stmt->execute()){
  227. header("Location:".$pag."?error=1");
  228. //print_r($stmt->errorInfo());
  229. exit();
  230. }
  231. $rs_usr = $stmt->fetchAll();
  232. $stmt->closeCursor();
  233. $stmt = null;
  234. if($nivel == 1){
  235. $xtpl = new XTemplate('../tpl/nombramiento.tpl.html');
  236. }else{
  237. $xtpl = new XTemplate('../tpl/nombramiento_pos.tpl.html');
  238. }
  239. $xtpl->assign("FECHA_HOY", fechaTexto($fecha_carta, true));
  240. $xtpl->assign("FACULTAD", FACULTAD);
  241. if($has_categoria){
  242. $stmt = $pdo->prepare('Select * from fi_profesorperiodo_categoria(:periodo, :prof )');
  243. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  244. foreach($rs_usr as $prof){
  245. if(strtoupper($prof["Usuario_nombre"]) != "VACANTE"){//no vacante
  246. $stmt->bindParam(":prof", $prof["Usuario_id"]);
  247. if(!$stmt->execute()){
  248. //echo "4";print_r($stmt->errorInfo());exit();
  249. header("Location:".$pag."?error=4");
  250. exit();
  251. }
  252. }
  253. }
  254. $stmt->closeCursor();
  255. }
  256. //-----
  257. if($pdf){
  258. $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
  259. $fontDirs = $defaultConfig['fontDir'];
  260. $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
  261. $fontData = $defaultFontConfig['fontdata'];
  262. $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
  263. $fontDirs = $defaultConfig['fontDir'];
  264. $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
  265. $fontData = $defaultFontConfig['fontdata'];
  266. $stylesheet = "<style>";
  267. $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
  268. $stylesheet .= file_get_contents('../css/carta.css'); // external css
  269. $stylesheet .= "</style>";
  270. if($split){
  271. //----------- Archivos y zip ---
  272. $fecha = date("Ymd_His");
  273. $tmp_folder = "./zip/pdf_".$fecha;
  274. if (!file_exists($tmp_folder)) {
  275. mkdir($tmp_folder, 0777, true);
  276. }
  277. $zip = new ZipArchive();
  278. $zip_filename = "zip/nombramientos_".$fecha.".zip";
  279. if ($zip->open($zip_filename, ZipArchive::CREATE)!==TRUE) {
  280. exit("cannot open <$zip_filename>\n");
  281. }
  282. }else{
  283. $mpdf = new \Mpdf\Mpdf([
  284. 'mode' => 'utf-8',
  285. 'format' => [215, 279],
  286. 'orientation' => 'P',
  287. 'margin_left' => 14,
  288. 'margin_right' => 14,
  289. 'margin_top' => 7,
  290. 'margin_bottom' => 7,
  291. 'fontDir' => array_merge($fontDirs, [
  292. __DIR__ . '/../../fonts/indivisaFont/ttf',
  293. ]),
  294. 'fontdata' => $fontData + [
  295. 'indivisa-display' => [
  296. 'R' => 'IndivisaDisplaySans-Regular.ttf',
  297. ],
  298. 'indivisa-title' => [
  299. 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
  300. ],
  301. 'indivisa-text' => [
  302. 'R' => 'IndivisaTextSans-Regular.ttf',
  303. ]
  304. ],
  305. 'default_font' => 'indivisa-text'
  306. ]);
  307. }
  308. //$hoy = strftime("%e de %B de %Y");
  309. $xtpl->assign("TEXTO_CARTA", $texto);
  310. $cuenta = count($rs_usr);//Cuenta total de usuarios para saber si hay salto de pagina o no
  311. //Marca de agua
  312. if (!file_exists($_SERVER['DOCUMENT_ROOT']. '/apsa/export/zip/marca.png')) {
  313. $marca = mb_strtoupper("Nombramiento",'UTF-8') . ' ' . fechaGuion($fecha_carta) . ' | '; //No acepta caracteres especiales
  314. generaMarcaDeAgua($marca, "./zip/");
  315. }
  316. foreach($rs_usr as $profesor){
  317. if(strtoupper($profesor["Usuario_nombre"]) != "VACANTE"){//no vacante
  318. if($split){
  319. $mpdf = new \Mpdf\Mpdf([
  320. 'mode' => 'utf-8',
  321. 'format' => [215, 279],
  322. 'orientation' => 'P',
  323. 'margin_left' => 14,
  324. 'margin_right' => 14,
  325. 'margin_top' => 7,
  326. 'margin_bottom' => 7,
  327. 'fontDir' => array_merge($fontDirs, [
  328. __DIR__ . '/../../fonts/indivisaFont/ttf',
  329. ]),
  330. 'fontdata' => $fontData + [
  331. 'indivisa-display' => [
  332. 'R' => 'IndivisaDisplaySans-Regular.ttf',
  333. ],
  334. 'indivisa-title' => [
  335. 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
  336. ],
  337. 'indivisa-text' => [
  338. 'R' => 'IndivisaTextSans-Regular.ttf',
  339. ]
  340. ],
  341. 'default_font' => 'indivisa-text'
  342. ]);
  343. if($nivel == 1){
  344. $xtpl = new XTemplate('../tpl/nombramiento.tpl.html');
  345. }else{
  346. $xtpl = new XTemplate('../tpl/nombramiento_pos.tpl.html');
  347. }
  348. $xtpl->assign("FECHA_HOY", fechaTexto($fecha_carta, true));
  349. $xtpl->assign("FACULTAD", FACULTAD);
  350. //$titulo = "Ing."; //Título del director
  351. $xtpl->assign("TEXTO_CARTA", $texto);
  352. }
  353. $stmt = $pdo->prepare('Select * from fs_categoriaperiodo(:periodo, :prof )');//categoría correspondiente al periodo
  354. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  355. $stmt->bindParam(":prof", $profesor["Usuario_id"]);
  356. if(!$stmt->execute()){
  357. $pdo->rollBack();
  358. header("Location:".$pag."?error=2");
  359. //print_r($stmt->errorInfo());
  360. exit();
  361. }
  362. $cat_rs = $stmt->fetch();
  363. $stmt->closeCursor();
  364. $nombre = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  365. $xtpl->assign("PROFESOR", $nombre);
  366. if(!empty($cat_rs["Categoria_desc"]))
  367. $xtpl->assign("CATEGORIA", $cat_rs["Categoria_desc"]);
  368. else
  369. $xtpl->assign("CATEGORIA", "");
  370. //$xtpl->assign("CATEGORIA", $profesor["Profesor_categoria"]);
  371. if($nivel != 1){
  372. $xtpl->assign("PLAN", $profesor["Carrera_desc"]);
  373. $stmt = $pdo->prepare('Select * from fs_horariogrupoprofesor(:prof, :periodo, :carr)');
  374. $stmt->bindParam(":carr", $profesor["Carrera_id"]);
  375. }else
  376. $stmt = $pdo->prepare('Select * from fs_horariogrupoprofesor(:prof, :periodo, NULL)');
  377. $stmt->bindParam(":prof", $profesor["Usuario_id"]);
  378. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  379. if(!$stmt->execute()){
  380. header("Location:".$pag."?error=2");
  381. //print_r($stmt->errorInfo());
  382. exit();
  383. }
  384. $asignatura_rs = $stmt->fetchAll();
  385. $stmt->closeCursor();
  386. $grupo_last = $asignatura_rs[0]["Grupo_id"].$asignatura_rs[0]["Materia_id"];
  387. foreach($asignatura_rs as $asignatura){
  388. if($grupo_last != $asignatura["Grupo_id"].$asignatura["Materia_id"]){
  389. $grupo_last = $asignatura["Grupo_id"].$asignatura["Materia_id"];
  390. $xtpl->parse("main.renglon");
  391. }
  392. $xtpl->assign("ASIGNATURA", $asignatura["Materia_desc"]);
  393. if($nivel == 1)
  394. $xtpl->assign("GRUPO", $asignatura["Grupo_desc"]." ".$asignatura["Carrera_prefijo"]);
  395. else
  396. $xtpl->assign("GRUPO", $asignatura["Materia_grupo_posgrado"]);
  397. if($asignatura["Salon_desc"] != "")
  398. $xtpl->assign("SALON", $asignatura["Salon_desc"]);
  399. else
  400. $xtpl->assign("SALON", "&nbsp;");
  401. $xtpl->assign("DIA", diaNombre($asignatura["Dia_id"]));
  402. //$hora_fin = date('H:i', strtotime('+'.$asignatura["Horario_duracion"].' minutes', strtotime('2019-01-01 '.$asignatura["Horario_hora"])));
  403. $xtpl->assign("HORARIO", substr($asignatura["Horario_hora"], 0, 5)." - ".substr($asignatura["Horario_hora_final"],0, 5));
  404. $xtpl->parse("main.renglon.detalle");
  405. }
  406. $xtpl->parse("main.renglon");
  407. $cuenta--;
  408. $xtpl->assign('MARCA', './zip/marca.png');
  409. if($profesor["Usuario_id"] != $director_rs["Usuario_id"]){
  410. $xtpl->assign('FIRMA', $firma_director["ConstanciaFirma_imagen"]);
  411. $director = $firma_director["ConstanciaFirma_grado"]." ".$director_rs["Usuario_nombre"]." ".$director_rs["Usuario_apellidos"];
  412. $xtpl->assign("NOMBRE_FIRMA", $director);
  413. $xtpl->assign("PUESTO_FIRMA", $director_rs["Puesto_desc"]);
  414. }else{
  415. $xtpl->assign('FIRMA', $firma_secretario["ConstanciaFirma_imagen"]);
  416. $secretario = $firma_secretario["ConstanciaFirma_grado"]." ".$secretario_rs["Usuario_nombre"]." ".$secretario_rs["Usuario_apellidos"];
  417. $xtpl->assign("NOMBRE_FIRMA", $secretario);
  418. $xtpl->assign("PUESTO_FIRMA", $secretario_rs["Puesto_desc"]);
  419. }
  420. if($split){
  421. $xtpl->parse("main");
  422. $mpdf->WriteHTML($stylesheet);
  423. $mpdf->WriteHTML($xtpl->text("main"));
  424. $mpdf->SetProtection(array('print', 'print-highres'), '', md5(time()));
  425. $mpdf->Output($tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf", 'F');
  426. if(isset($profesor["Area_desc"])){
  427. $zip->addFile(
  428. $tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf",
  429. "nombramientos_".$fecha.directorioArea($profesor["Area_desc"])."/nombramiento_".sprintf("%06d", $profesor["Usuario_claveULSA"]).".pdf"
  430. );
  431. }else{
  432. $zip->addFile(
  433. $tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf",
  434. "nombramientos_".$fecha."/nombramiento_".sprintf("%06d", $profesor["Usuario_claveULSA"]).".pdf"
  435. );
  436. }
  437. if($cuenta > 0){
  438. $num++;
  439. }
  440. }else{
  441. if($cuenta > 0) $xtpl->parse("main.pagebreak");
  442. $xtpl->parse("main");
  443. }
  444. }//fin vacante
  445. }//for profesor
  446. /*echo $stylesheet;
  447. $xtpl->out("main");exit();*/
  448. if(!$split){
  449. $mpdf->WriteHTML($stylesheet);
  450. $mpdf->WriteHTML($xtpl->text("main"));
  451. $mpdf->Output("nombramientos.pdf", 'I');
  452. }else{
  453. if($zip->numFiles<=0){
  454. echo "Error al guardar en el zip";
  455. $zip->close();
  456. unlink($zip_filename);
  457. exit();
  458. }
  459. $zip->close();
  460. removeFolder($tmp_folder);
  461. header("Content-Type: application/zip");
  462. header("Content-Disposition: attachment; filename=".basename($zip_filename));
  463. header("Pragma: no-cache");
  464. header("Expires: 0");
  465. ob_end_clean();
  466. flush();
  467. readfile($zip_filename);
  468. unlink($zip_filename);
  469. }
  470. }else{
  471. header("Location: ../nombramientos.php?ok=0");
  472. }
  473. function removeFolder($folderName) {
  474. if (is_dir($folderName))
  475. $folderHandle = opendir($folderName);
  476. if (!$folderHandle)
  477. return false;
  478. while($file = readdir($folderHandle)) {
  479. if ($file != "." && $file != "..") {
  480. if (!is_dir($folderName."/".$file))
  481. unlink($folderName."/".$file);
  482. else
  483. removeFolder($folderName.'/'.$file);
  484. }
  485. }
  486. closedir($folderHandle);
  487. rmdir($folderName);
  488. return true;
  489. }