funciones_helper.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. gc_collect_cycles();
  60. /*$query = $this->db->query($sql);
  61. $result = $query->result();
  62. $query->free_result();*/
  63. return count($conjunto);
  64. }
  65. }
  66. if (!function_exists("insertBucleDuplicateOnKey")) {
  67. function insertBucleDuplicateOnKey($fila_archivo, $nombreTabla, $nombreLog)
  68. {
  69. $contador = 1;
  70. $conjunto = array();
  71. $CI = &get_instance();
  72. foreach ($fila_archivo as $row) {
  73. if ($nombreTabla == "bruto_datos_iniciales" || $nombreTabla == "maestro_datos_iniciales_licitacion") {
  74. if (is_array($row)) {
  75. guardar_log($nombreLog, "ID_licitacion-" . $row['id_licitacion']);
  76. } else {
  77. guardar_log($nombreLog, "ID_licitacion-" . $row->id_licitacion);
  78. }
  79. }
  80. $conjunto[] = $row;
  81. $contador++;
  82. if ($contador % 5000 == 0) {
  83. guardar_log($nombreLog, "Insertados - " . count($conjunto));
  84. //$CI->db->insert_batch($nombreTabla, $conjunto);
  85. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
  86. $conjunto = array();
  87. }
  88. }
  89. if (count($conjunto) > 0) {
  90. guardar_log($nombreLog, "Insertados - " . count($conjunto));
  91. //$CI->db->insert_batch($nombreTabla, $conjunto);
  92. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
  93. }
  94. unset($conjunto);
  95. gc_collect_cycles();
  96. return $CI->db->insert_id();
  97. }
  98. }
  99. if (!function_exists(("check_permisos_template"))) {
  100. function check_permisos_template($view_file_name, $data_array = array(), $vista_permiso = "home")
  101. {
  102. $CI = &get_instance();
  103. if ($CI->session->zonas != "") {
  104. $CI->load->model("Home_model");
  105. $vistas = $CI->Home_model->getPermisosVistaUsuario($CI->session->tipo_usuario);
  106. if ($CI->session->tipo_usuario == 1) {
  107. $CI->template_dashboard->load_template($view_file_name, $data_array);
  108. } else {
  109. if (in_array($vista_permiso, $vistas)) {
  110. $CI->template_dashboard->load_template($view_file_name, $data_array);
  111. } else {
  112. redirect("home");
  113. }
  114. }
  115. } else {
  116. redirect("login", "refresh");
  117. }
  118. }
  119. }
  120. if (!function_exists("pretty_dump")) {
  121. function pretty_dump($data)
  122. {
  123. echo '<pre>' . var_export($data, true) . '</pre>';
  124. }
  125. }
  126. if (!function_exists("enviarEmail")) {
  127. function enviarEmail($asunto, $body, $email_envio, $adjuntos = array(), $print_result = true)
  128. {
  129. print_r($body);
  130. $CI = &get_instance();
  131. $CI->load->library('email');
  132. $config['protocol'] = 'smtp';
  133. $config['smtp_host'] = 'smtp.gmail.com';
  134. $config['smtp_user'] = 'chcalvoleon@mindden.com';
  135. $config['smtp_pass'] = '4lb1R2014';
  136. $config['smtp_crypto'] = 'ssl';
  137. $config['smtp_port'] = 465;
  138. $config['mailtype'] = 'html';
  139. $config['wordwrap'] = 'TRUE';
  140. $config['newline'] = "\r\n";
  141. $config['priority'] = 5;
  142. $config['crlf'] = "\r\n";
  143. $CI->email->initialize($config);
  144. $CI->email->clear(true);
  145. $CI->email->from('chcalvoleon@mindden.com');
  146. $CI->email->to($email_envio);
  147. $CI->email->bcc("chcalvoleon@mindden.com");
  148. $CI->email->subject($asunto);
  149. $CI->email->message($body);
  150. foreach ($adjuntos as $row) {
  151. $CI->email->attach($row);
  152. }
  153. if ($print_result) {
  154. $CI->email->send(false);
  155. $CI->email->print_debugger();
  156. } else {
  157. $CI->email->send(false);
  158. }
  159. }
  160. }
  161. // ------------------------------------------------------------------------
  162. /* End of file Funciones_helper.php */
  163. /* Location: ./application/helpers/Funciones_helper.php */