util.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. function fechaConstancia($fechaTxt){
  3. $fechaTxt = trim($fechaTxt);
  4. if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
  5. $fechaArr = explode("/", $fechaTxt);
  6. return mesNombre($fechaArr[1])." ".intval($fechaArr[0])." de ".$fechaArr[2];
  7. }
  8. if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
  9. $fechaArr = explode("-", $fechaTxt);
  10. return mesNombre($fechaArr[1])." ".intval($fechaArr[2])." de ".$fechaArr[0];
  11. }
  12. return "";
  13. }
  14. function generaMarcaDeAgua($marca, $carpeta) {
  15. $imagen = imagecreatetruecolor(344,143); // Crear la imagen de 591x379
  16. $textColor = imagecolorallocate($imagen, 224, 224, 224); //Colores del texto
  17. $transparente = imagecolorallocate ($imagen, 0, 0, 0); //Color que cambiará a transparene
  18. imagecolortransparent($imagen, $transparente); // Hacer el fondo transparente
  19. for ($cont = 0; $cont < 5; $cont++) { $marca .= $marca; }
  20. // Escribirlo
  21. for ($cont=1; $cont <= 50; $cont++){
  22. if ($cont%2 == 0)
  23. $val = -5;
  24. else
  25. $val = 5;
  26. imagestring($imagen,1, $val, 10*$cont, $marca, $textColor); //Escribe el texto
  27. }
  28. header('Content-Type: image/png');
  29. imagepng($imagen, $carpeta.'marca.png'); //Genera la imagen
  30. //imagedestroy($imagen);
  31. }
  32. function creaFolio($pdo, $sist, $pag, $fecha, $participante, $motivo, $tipo, $evento, $desc, $evento_id, $img) {
  33. $folio = '';
  34. //echo 'Select * from fi_constanciaLog(:sist, :evento_id, :part, :motivo, :fecha, :tipo, :evento, :desc, :usr)<br>';
  35. //echo 'Select * from fi_constanciaLog('.$sist.', '.$evento_id.', '.$participante.', '.$motivo.', '.$fecha.', '.$tipo.', '.$evento.', '.htmlentities($desc).', '.$_SESSION["usuario_id"].')<br>';
  36. if($img==NULL)
  37. $stmt = $pdo->prepare('Select * from fi_constanciaLog(:sist, :evento_id, :part, :motivo, :fecha, :tipo, :evento, :desc, NULL, :usr)');//firmas
  38. else{
  39. $stmt = $pdo->prepare('Select * from fi_constanciaLog(:sist, :evento_id, :part, :motivo, :fecha, :tipo, :evento, :desc, :img, :usr)');//firmas
  40. $stmt->bindParam(":img", $img);
  41. }
  42. $stmt->bindParam(":sist", $sist);
  43. $stmt->bindParam(":evento_id", $evento_id);
  44. $stmt->bindParam(":part", $participante);
  45. $stmt->bindParam(":motivo", $motivo);
  46. $stmt->bindParam(":fecha", $fecha);
  47. $stmt->bindParam(":tipo", $tipo);
  48. $stmt->bindParam(":evento", $evento);
  49. $stmt->bindParam(":desc", $desc);
  50. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  51. if(!$stmt->execute()){
  52. $pdo->rollBack();
  53. header("Location:".$pag."?error=3");
  54. //print_r($stmt->errorInfo());
  55. exit();
  56. }
  57. $rs=$stmt->fetch();
  58. $folio = $rs["ConstanciaLog_id"];
  59. if (!empty($folio))
  60. return $folio;
  61. return "";
  62. }
  63. function generaFooter($pdo, $sist, $pag, $fecha, $numFirmas, $firmasArr, $participante, $motivo, $tipo, $evento, $desc, $evento_id, $img=NULL){
  64. //echo "generaFooter: ".$evento_id."<br>";
  65. $folio = creaFolio($pdo, $sist, $pag, $fecha, $participante, $motivo, $tipo, $evento, $desc, $evento_id, $img);
  66. if (!empty($folio)){
  67. $folio_text = 'FI - ';
  68. switch($sist){
  69. case GEMA: $folio_text.='G'; break;
  70. case CIDIT: $folio_text.='C'; break;
  71. case EXPOING: $folio_text.='E'; break;
  72. default: $folio_text.='X'; break;
  73. }
  74. $folio_text .= $evento_id . ' - ' . sprintf("%04d", $folio);
  75. } else{
  76. $pdo->rollBack();
  77. header("Location:".$pag."?error=3");
  78. exit();
  79. }
  80. $xtpl = new XTemplate('../tpl/footer.tpl.html');
  81. $xtpl->assign('FOLIO', $folio_text);
  82. $fechaConst = fechaConstancia($fecha);
  83. $xtpl->assign('FECHA_CARTA', $fechaConst);
  84. if($numFirmas >= 2)
  85. $numFirmas = 2; // 1 -> sólo una firma / 2 -> 2 o más firmas
  86. $orden = 1;
  87. foreach($firmasArr as $firma_pie){
  88. $xtpl->assign('NUM', $numFirmas);
  89. if($firma_pie["lleva_firma"]){
  90. $xtpl->assign('MARCA', './zip/marca.png');
  91. $xtpl->assign('FIRMA', $firma_pie["firma"]);
  92. }else{
  93. $xtpl->assign('MARCA', '../../img/firmas/marca_blanco.png');
  94. $xtpl->assign('FIRMA', "blanco.png");
  95. }
  96. $xtpl->assign('NOMBRE', $firma_pie["grado"]." ".$firma_pie["nombre"]);
  97. $xtpl->assign('PUESTO', $firma_pie["puesto"]);
  98. $xtpl->parse('main.firma');
  99. if($firma_pie["lleva_firma"]){
  100. $stmt = $pdo->prepare('Select * from fi_constancialogfirma(:sist, :evento, :serial, :firma, :orden, :puesto, true)');//firmas
  101. }else{
  102. $stmt = $pdo->prepare('Select * from fi_constancialogfirma(:sist, :evento, :serial, :firma, :orden, :puesto, false)');//firmas
  103. }
  104. $stmt->bindParam(":sist", $sist);
  105. $stmt->bindParam(":evento", $evento_id);
  106. $stmt->bindParam(":serial", $folio);
  107. $stmt->bindParam(":firma", $firma_pie["id"]);
  108. $stmt->bindParam(":orden", $orden);
  109. $stmt->bindParam(":puesto", $firma_pie["puesto"]);
  110. if(!$stmt->execute()){
  111. $pdo->rollBack();
  112. header("Location:".$pag."?error=3");
  113. exit();
  114. }
  115. $orden++;
  116. }
  117. $xtpl->assign('NUM', $numFirmas);
  118. $xtpl->parse('main');
  119. return $xtpl->text('main');
  120. }
  121. // -- Solo CIDIT ---
  122. function cambiaTextos($texto, $codeArr){
  123. $buscaArr = array();
  124. $reemplazaArr = array();
  125. foreach($codeArr as $opt){
  126. $buscaArr[] = $opt["busca"];
  127. $reemplazaArr[] = $opt["reemplaza"];
  128. }
  129. return str_replace ($buscaArr, $reemplazaArr, $texto);
  130. }
  131. function textoLugar($num){
  132. switch($num){
  133. case 1: return $num."er";
  134. case 2: return $num."do";
  135. case 3: return $num."er";
  136. }
  137. return $num."to";
  138. }
  139. // -- Consulta de constancias --
  140. function imprimeFooter($fecha, $numFirmas, $firmasArr, $sistema, $evento_id, $folio){
  141. $folio_text = 'FI - ';
  142. switch($sistema){
  143. case GEMA: $folio_text.='G'; break;
  144. case CIDIT: $folio_text.='C'; break;
  145. default: $folio_text.='X'; break;
  146. }
  147. $folio_text.=$evento_id . ' - ' . sprintf("%04d", $folio);
  148. $xtpl = new XTemplate('../tpl/footer.tpl.html');
  149. $xtpl->assign('FOLIO', $folio_text);
  150. if(empty($fecha))
  151. $fecha = date("Y-m-d");
  152. $fechaConst = fechaConstancia($fecha);
  153. $xtpl->assign('FECHA_CARTA', $fechaConst);
  154. if($numFirmas >= 2)
  155. $numFirmas = 2; // 1 -> sólo una firma / 2 -> 2 o más firmas
  156. foreach($firmasArr as $firma_pie){
  157. $xtpl->assign('NUM', $numFirmas);
  158. if($firma_pie["lleva_firma"]){
  159. $xtpl->assign('MARCA', './zip/marca.png');
  160. $xtpl->assign('FIRMA', $firma_pie["firma"]);
  161. }else{
  162. $xtpl->assign('MARCA', '../../img/firmas/marca_blanco.png');
  163. $xtpl->assign('FIRMA', "blanco.png");
  164. }
  165. $xtpl->assign('NOMBRE', $firma_pie["grado"]." ".$firma_pie["nombre"]);
  166. $xtpl->assign('PUESTO', $firma_pie["puesto"]);
  167. $xtpl->parse('main.firma');
  168. }
  169. $xtpl->assign('NUM', $numFirmas);
  170. $xtpl->parse('main');
  171. return $xtpl->text('main');
  172. }
  173. function supText($texto){
  174. $textoArr = explode(".", $texto);
  175. return $textoArr[0].".<sup>".$textoArr[1]."</sup>";
  176. }
  177. ?>