File: /var/www/proveedores.bradford/application/helpers/utilities_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function limpiacaracteres($str){
$res = str_replace('ñ', 'n', $str);
$res = str_replace('/', ' ', $str);
$res = str_replace('á', 'a', $res);
$res = str_replace('é', 'e', $res);
$res = str_replace('í', 'i', $res);
$res = str_replace('ó', 'o', $res);
$res = str_replace('ú', 'u', $res);
$res = preg_replace('([^A-Za-z0-9 ])', '', $res);
return $res;
}
function format_price($price, $prefix = "$")
{
if (!empty($price)) {
$price = $prefix . number_format($price, 0, ',', '.');
} else {
$price = $prefix . "0";
}
return $price;
}
function format_miles($price)
{
if (!empty($price)) {
$price = number_format($price, 0, ',', '.');
} else {
$price = "0";
}
return $price;
}
function rut($rut)
{
return number_format(substr($rut, 0, -1), 0, "", ".") . '-' . substr($rut, strlen($rut) - 1, 1);
}
function enviar_correo($data_mail, $debug = FALSE)
{
//$data_mail['para'] = '';
//$data_mail['remitente'] = "";
//$data_mail['usuario'] = "";
$CI =& get_instance();
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$CI->load->library('email', $config);
$config = array(
'mailtype' => 'html', // Establece el tipo de correo a HTML
'charset' => 'utf-8',
'priority' => '1'
);
$CI->email->initialize($config);
if(!empty($data_mail['attach']))
{
$CI->email->clear(TRUE);
foreach ($data_mail['attach'] as $key => $value)
{
$CI->email->attach($value['path'], 'attachment', $value['file_name']);
}
}
$CI->email->to($data_mail['para']);
$CI->email->from($data_mail['remitente'], $data_mail['usuario']);
if(!empty($data_mail['bcc_remitente']))
{
$CI->email->bcc($data_mail['bcc_remitente']);
}
$CI->email->subject($data_mail['asunto']);
$CI->email->message($data_mail['mensaje']);
$CI->email->send();
if($debug)
{
echo $CI->email->print_debugger();
}
}
function reportExcel($data, $filename, $url = '')
{
$CI = &get_instance();
$CI->load->library('spreadsheets');
#GENERA ARCHIVO PARA EXPORTAR LA DATA A EXCEL
$path = $CI->spreadsheets->export($data);
#SE VALIDA SI EXISTE ARCHIVO TEMPORAL
if (file_exists($path)) {
$CI->load->helper('download');
force_download($filename . '.xlsx', file_get_contents($path));
} else {
$CI->session->set_flashdata("error_title", "Error Interno");
$CI->session->set_flashdata("error", "Error al exportar los datos. Intente nuevamente si problema persiste contacte a soporte");
redirect(base_url($url));
}
}