funciones_helper.php 5.7KB

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. $CI->db->insert_batch($nombreTabla, $conjunto);
  57. }
  58. return $CI->db->insert_id();
  59. }
  60. }
  61. if (!function_exists("insertBucleDuplicateOnKey")) {
  62. function insertBucleDuplicateOnKey($fila_archivo, $nombreTabla, $nombreLog)
  63. {
  64. $contador = 1;
  65. $conjunto = array();
  66. $CI = &get_instance();
  67. foreach ($fila_archivo as $row) {
  68. $conjunto[] = $row;
  69. $contador++;
  70. if ($contador % 5000 == 0) {
  71. guardar_log($nombreLog, count($conjunto));
  72. //$CI->db->insert_batch($nombreTabla, $conjunto);
  73. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
  74. $conjunto = array();
  75. }
  76. }
  77. if (count($conjunto) > 0) {
  78. //$CI->db->insert_batch($nombreTabla, $conjunto);
  79. $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto);
  80. }
  81. return $CI->db->insert_id();
  82. }
  83. }
  84. if (!function_exists(("check_permisos_template"))) {
  85. function check_permisos_template($view_file_name, $data_array = array(), $vista_permiso = "home")
  86. {
  87. $CI = &get_instance();
  88. if ($CI->session->zonas != "") {
  89. $CI->load->model("Home_model");
  90. $vistas = $CI->Home_model->getPermisosVistaUsuario($CI->session->tipo_usuario);
  91. if ($CI->session->tipo_usuario == 1) {
  92. $CI->template_dashboard->load_template($view_file_name, $data_array);
  93. } else {
  94. if (in_array($vista_permiso, $vistas)) {
  95. $CI->template_dashboard->load_template($view_file_name, $data_array);
  96. } else {
  97. redirect("home");
  98. }
  99. }
  100. } else {
  101. redirect("login", "refresh");
  102. }
  103. }
  104. }
  105. if (!function_exists("pretty_dump")) {
  106. function pretty_dump($data)
  107. {
  108. echo '<pre>' . var_export($data, true) . '</pre>';
  109. }
  110. }
  111. if (!function_exists("enviarEmail")) {
  112. function enviarEmail($asunto, $body, $email_envio, $adjuntos = array(), $print_result = true)
  113. {
  114. print_r($body);
  115. $CI = &get_instance();
  116. $CI->load->library('email');
  117. $config = array();
  118. if ($_SERVER["SERVER_NAME"] == "rielchyc.test") {
  119. $config['protocol'] = 'smtp';
  120. $config['smtp_host'] = 'smtp.gmail.com';
  121. $config['smtp_user'] = 'chcalvoleon@mindden.com';
  122. $config['smtp_pass'] = '';
  123. $config['smtp_crypto'] = 'ssl';
  124. $config['smtp_port'] = 465;
  125. $config['mailtype'] = 'html';
  126. $config['wordwrap'] = 'TRUE';
  127. $config['newline'] = "\r\n";
  128. $config['priority'] = 5;
  129. $config['crlf'] = "\r\n";
  130. } else {
  131. $config['protocol'] = 'smtp';
  132. $config['smtp_host'] = 'b2b.rielchyc.es';
  133. $config['smtp_user'] = 'webmaster@b2b.rielchyc.es';
  134. $config['smtp_pass'] = 'Mindden2021!';
  135. $config['smtp_crypto'] = 'ssl';
  136. $config['smtp_port'] = 465;
  137. $config['mailtype'] = 'html';
  138. $config['wordwrap'] = 'TRUE';
  139. $config['newline'] = "\r\n";
  140. $config['priority'] = 5;
  141. $config['crlf'] = "\r\n";
  142. }
  143. $CI->email->initialize($config);
  144. $CI->email->clear(true);
  145. $CI->email->from('webmaster@b2b.rielchyc.es');
  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. echo $CI->email->send(false);
  155. echo $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 */