funciones_helper.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. /**
  4. *
  5. * Helpers Funciones_helper
  6. *
  7. * This Helpers for ...
  8. *
  9. * @package CodeIgniter
  10. * @category Helpers
  11. * @author Setiawan Jodi <jodisetiawan@fisip-untirta.ac.id>
  12. * @link https://github.com/setdjod/myci-extension/
  13. *
  14. */
  15. // ------------------------------------------------------------------------
  16. if (!function_exists('guardar_log')) {
  17. function guardar_log($nombre_archivo = "", $texto = "", $echo = false, $tipo = 1)
  18. {
  19. $textoTipoLogico = "";
  20. if ($tipo == 1) {
  21. $textoTipoLogico = "INFO";
  22. } else if ($tipo == 2) {
  23. $textoTipoLogico = "ERROR";
  24. }
  25. //CREAMOS EL REGISTRO PARA EL LOG
  26. $registro = date('d-m-Y H:i:s') . ' - ' . $textoTipoLogico . " - " . $texto;
  27. //FICHERO DE LOG
  28. $file_name = APPPATH . 'logs/' . $nombre_archivo . '.txt';
  29. //GUARDAMOS EL REGISTRO EN EL FICHERO DE LOG
  30. $f = fopen($file_name, "a");
  31. fwrite($f, $registro . PHP_EOL);
  32. fclose($f);
  33. //SI ES NECESARIO SE MUESTRA POR PANTALLA
  34. if ($echo == true) {
  35. echo $registro . '<br>';
  36. }
  37. return $texto . '<br>';
  38. }
  39. }
  40. if (!function_exists("insertBucle")) {
  41. function insertBucle($fila_archivo, $nombreTabla, $nombreLog): int
  42. {
  43. $contador = 1;
  44. $conjunto = array();
  45. $CI = &get_instance();
  46. foreach ($fila_archivo as $row) {
  47. $conjunto[] = $row;
  48. $contador++;
  49. if ($contador % 5000 == 0) {
  50. guardar_log($nombreLog, count($conjunto));
  51. $CI->db->insert_batch($nombreTabla, $conjunto);
  52. $conjunto = array();
  53. }
  54. }
  55. if (count($conjunto) > 0) {
  56. guardar_log($nombreLog, count($conjunto));
  57. $CI->db->insert_batch($nombreTabla, $conjunto);
  58. }
  59. return $CI->db->insert_id();
  60. }
  61. }
  62. if (!function_exists("insertBucleDuplicateOnKey")) {
  63. function insertBucleDuplicateOnKey($fila_archivo, $nombreTabla, $nombreLog)
  64. {
  65. $contador = 1;
  66. $conjunto = array();
  67. $CI = &get_instance();
  68. foreach ($fila_archivo as $row) {
  69. $conjunto[] = $row;
  70. $contador++;
  71. if ($contador % 5000 == 0) {
  72. guardar_log($nombreLog, count($conjunto));
  73. //$CI->db->insert_batch($nombreTabla, $conjunto);
  74. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
  75. $conjunto = array();
  76. }
  77. }
  78. if (count($conjunto) > 0) {
  79. //$CI->db->insert_batch($nombreTabla, $conjunto);
  80. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
  81. }
  82. return $CI->db->insert_id();
  83. }
  84. }
  85. if (!function_exists(("check_permisos_template"))) {
  86. function check_permisos_template($view_file_name, $data_array = array(), $vista_permiso = "home")
  87. {
  88. $CI = &get_instance();
  89. if ($CI->session->zonas != "") {
  90. $CI->load->model("Home_model");
  91. $vistas = $CI->Home_model->getPermisosVistaUsuario($CI->session->tipo_usuario);
  92. if ($CI->session->tipo_usuario == 1) {
  93. $CI->template_dashboard->load_template($view_file_name, $data_array);
  94. } else {
  95. if (in_array($vista_permiso, $vistas)) {
  96. $CI->template_dashboard->load_template($view_file_name, $data_array);
  97. } else {
  98. redirect("home");
  99. }
  100. }
  101. } else {
  102. redirect("login", "refresh");
  103. }
  104. }
  105. }
  106. if (!function_exists("pretty_dump")) {
  107. function pretty_dump($data)
  108. {
  109. echo '<pre>' . var_export($data, true) . '</pre>';
  110. }
  111. }
  112. if (!function_exists("enviarEmail")) {
  113. function enviarEmail($asunto, $body, $email_envio, $adjuntos = array(), $print_result = true)
  114. {
  115. print_r($body);
  116. $CI = &get_instance();
  117. $CI->load->library('email');
  118. $config['protocol'] = 'smtp';
  119. $config['smtp_host'] = 'smtp.gmail.com';
  120. $config['smtp_user'] = 'chcalvoleon@mindden.com';
  121. $config['smtp_pass'] = '';
  122. $config['smtp_crypto'] = 'ssl';
  123. $config['smtp_port'] = 465;
  124. $config['mailtype'] = 'html';
  125. $config['wordwrap'] = 'TRUE';
  126. $config['newline'] = "\r\n";
  127. $config['priority'] = 5;
  128. $config['crlf'] = "\r\n";
  129. $CI->email->initialize($config);
  130. $CI->email->clear(true);
  131. $CI->email->from('chcalvoleon@mindden.com');
  132. $CI->email->to($email_envio);
  133. $CI->email->bcc("chcalvoleon@mindden.com");
  134. $CI->email->subject($asunto);
  135. $CI->email->message($body);
  136. foreach ($adjuntos as $row) {
  137. $CI->email->attach($row);
  138. }
  139. if ($print_result) {
  140. echo $CI->email->send(false);
  141. echo $CI->email->print_debugger();
  142. } else {
  143. $CI->email->send(false);
  144. }
  145. }
  146. }
  147. // ------------------------------------------------------------------------
  148. /* End of file Funciones_helper.php */
  149. /* Location: ./application/helpers/Funciones_helper.php */