funciones_helper.php 5.6KB

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