123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
-
- /**
- *
- * Helpers Funciones_helper
- *
- * This Helpers for ...
- *
- * @package CodeIgniter
- * @category Helpers
- * @author Setiawan Jodi <jodisetiawan@fisip-untirta.ac.id>
- * @link https://github.com/setdjod/myci-extension/
- *
- */
-
- // ------------------------------------------------------------------------
-
- if (!function_exists('guardar_log')) {
-
- function guardar_log($nombre_archivo = "", $texto = "", $echo = false, $tipo = 1)
- {
- $textoTipoLogico = "";
- if ($tipo == 1) {
- $textoTipoLogico = "INFO";
- } else if ($tipo == 2) {
- $textoTipoLogico = "ERROR";
- }
-
- //CREAMOS EL REGISTRO PARA EL LOG
- $registro = date('d-m-Y H:i:s') . ' - ' . $textoTipoLogico . " - " . $texto;
-
- //FICHERO DE LOG
- $file_name = APPPATH . 'logs/' . $nombre_archivo . '.txt';
-
- //GUARDAMOS EL REGISTRO EN EL FICHERO DE LOG
- $f = fopen($file_name, "a");
- fwrite($f, $registro . PHP_EOL);
- fclose($f);
-
- //SI ES NECESARIO SE MUESTRA POR PANTALLA
- if ($echo == true) {
- //echo $registro . '<br>';
- }
-
- return $texto . '<br>';
- }
- }
-
- if (!function_exists("insertBucle")) {
- function insertBucle($fila_archivo, $nombreTabla, $nombreLog): int
- {
- $contador = 1;
-
- $conjunto = array();
-
- $CI = &get_instance();
-
- foreach ($fila_archivo as $row) {
-
- $conjunto[] = $row;
-
- $contador++;
-
- if ($contador % 5000 == 0) {
- guardar_log($nombreLog, count($conjunto));
- $CI->db->insert_batch($nombreTabla, $conjunto);
-
- $conjunto = array();
- }
- }
-
- if (count($conjunto) > 0) {
- guardar_log($nombreLog, count($conjunto));
- $CI->db->insert_batch($nombreTabla, $conjunto);
-
- }
-
- gc_collect_cycles();
- /*$query = $this->db->query($sql);
- $result = $query->result();
- $query->free_result();*/
-
- return count($conjunto);
- }
- }
-
- if (!function_exists("insertBucleDuplicateOnKey")) {
- function insertBucleDuplicateOnKey($fila_archivo, $nombreTabla, $nombreLog)
- {
- $contador = 1;
-
- $conjunto = array();
-
- $CI = &get_instance();
-
- foreach ($fila_archivo as $row) {
-
- if ($nombreTabla == "bruto_datos_iniciales" || $nombreTabla == "maestro_datos_iniciales_licitacion") {
- if (is_array($row)) {
- guardar_log($nombreLog, "ID_licitacion-" . $row['id_licitacion']);
- } else {
- guardar_log($nombreLog, "ID_licitacion-" . $row->id_licitacion);
- }
- }
-
- $conjunto[] = $row;
-
- $contador++;
-
- if ($contador % 5000 == 0) {
- guardar_log($nombreLog, "Insertados - " . count($conjunto));
- //$CI->db->insert_batch($nombreTabla, $conjunto);
- $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
-
- $conjunto = array();
- }
- }
-
- if (count($conjunto) > 0) {
- guardar_log($nombreLog, "Insertados - " . count($conjunto));
- //$CI->db->insert_batch($nombreTabla, $conjunto);
- $CI->db->insert_on_duplicate_update_batch($nombreTabla, $conjunto, $nombreLog);
- }
- unset($conjunto);
- gc_collect_cycles();
- return $CI->db->insert_id();
- }
- }
-
- if (!function_exists(("check_permisos_template"))) {
- function check_permisos_template($view_file_name, $data_array = array(), $vista_permiso = "home")
- {
-
- $CI = &get_instance();
- if ($CI->session->zonas != "") {
- $CI->load->model("Home_model");
- $vistas = $CI->Home_model->getPermisosVistaUsuario($CI->session->tipo_usuario);
-
- if ($CI->session->tipo_usuario == 1) {
- $CI->template_dashboard->load_template($view_file_name, $data_array);
- } else {
- if (in_array($vista_permiso, $vistas)) {
- $CI->template_dashboard->load_template($view_file_name, $data_array);
- } else {
- redirect("home");
- }
- }
- } else {
- redirect("login", "refresh");
- }
- }
- }
-
- if (!function_exists("pretty_dump")) {
- function pretty_dump($data)
- {
- echo '<pre>' . var_export($data, true) . '</pre>';
- }
- }
-
- if (!function_exists("enviarEmail")) {
- function enviarEmail($asunto, $body, $email_envio, $adjuntos = array(), $print_result = true)
- {
- print_r($body);
- $CI = &get_instance();
-
- $CI->load->library('email');
-
- $config['protocol'] = 'smtp';
- $config['smtp_host'] = 'smtp.gmail.com';
- $config['smtp_user'] = 'chcalvoleon@mindden.com';
- $config['smtp_pass'] = '4lb1R2014';
- $config['smtp_crypto'] = 'ssl';
- $config['smtp_port'] = 465;
- $config['mailtype'] = 'html';
- $config['wordwrap'] = 'TRUE';
- $config['newline'] = "\r\n";
- $config['priority'] = 5;
- $config['crlf'] = "\r\n";
-
- $CI->email->initialize($config);
- $CI->email->clear(true);
-
- $CI->email->from('chcalvoleon@mindden.com');
- $CI->email->to($email_envio);
- $CI->email->bcc("chcalvoleon@mindden.com");
- $CI->email->subject($asunto);
- $CI->email->message($body);
-
- foreach ($adjuntos as $row) {
- $CI->email->attach($row);
- }
-
- if ($print_result) {
- $CI->email->send(false);
- $CI->email->print_debugger();
- } else {
- $CI->email->send(false);
- }
- }
- }
-
- // ------------------------------------------------------------------------
-
- /* End of file Funciones_helper.php */
- /* Location: ./application/helpers/Funciones_helper.php */
|