Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- if (!function_exists('option_access')) {
- function option_access($a = array())
- {
- foreach ($a as $str) {
- if (in_array($str, $_SESSION['permisos']))
- return true;
- }
- return false;
- }
- }
- if (!function_exists('check_access')) {
- function check_access($a = array(), $redirect = false)
- {
- if (isset($_SESSION['permisos'])) {
- // array_push($a, 'PASAJES_ADMINISTRADOR');
- if (!option_access($a)) {
- if ($redirect) {
- echo 'Usted no tiene acceso a esta opción, contacte con el administrador.';
- redirect('http://' . $_SERVER['SERVER_ADDR'] . '/error_acceso.php');
- die;
- } else
- return false;
- } else
- return true;
- } else {
- if ($redirect) {
- echo 'Usted no tiene acceso a esta opción, contacte con el administrador.';
- redirect('http://' . $_SERVER['SERVER_ADDR'] . '/error_acceso.php');
- die;
- } else
- return false;
- }
- }
- }
- //recibe la fecha en format d.m.Y y devuelve Ymd
- if (!function_exists('convertir_fecha_formato_sql')) {
- function convertir_fecha_formato_sql($sFecha, $sufijo=''){
- // echo $sFecha . '---' . gettype($sFecha) . '<br>';
- $sFecha = gettype($sFecha)=='string' ? trim($sFecha) : (gettype($sFecha)=='object' && $sFecha instanceof DateTime ? $sFecha->format('d.m.Y') : '');
- if( $sFecha!='' ){
- $sFecha = explode(' ', $sFecha); //para deshacernos de la parte de la hora en caso que tuviera
- $sFecha = explode('.', $sFecha[0]);
- if( is_numeric($sFecha[0]) && is_numeric($sFecha[1]) && is_numeric($sFecha[2]) )
- return "'" . $sFecha[2] . '' . $sFecha[1] . '' . $sFecha[0] . ($sufijo==''?'':' ' . $sufijo) . "'";
- else
- return 'null';
- }
- else
- return 'null';
- }
- }
- //D=Días, DH=Días habiles, M=Meses, W=Semanas
- if (!function_exists('codigo_plazo')) {
- function codigo_plazo($codigo_plazo)
- {
- $plazo = '';
- if ($codigo_plazo == 'D')
- $plazo = 'Días';
- elseif ($codigo_plazo == 'DH')
- $plazo = 'Días hábiles';
- elseif ($codigo_plazo == 'W')
- $plazo = 'Semanas';
- elseif ($codigo_plazo == 'M')
- $plazo = 'Meses';
- return $plazo;
- }
- }
- if (!function_exists('subir_archivo')) {
- function subir_archivo($t, $input, $ruta = '',$tipo_archivo = '')
- {
- $config['upload_path'] = './uploads/' . $ruta;
- if ($tipo_archivo != '') {
- $config['allowed_types'] =$tipo_archivo;
- }else{
- $config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx|xls|xlsx|msg|zip';
- }
- $config['max_size'] = 1024 * 30;
- $config['overwrite'] = true;
- $t->load->library('upload', $config);
- if (!$t->upload->do_upload($input)) {
- $data = array('error' => $t->upload->display_errors(), 'File type:' => $t->upload->file_type);
- } else {
- $data = array('upload_data' => $t->upload->data());
- }
- // print_r($data);
- $t->upload->initialize_error();
- return $data;
- }
- }
- if (!function_exists('renombrar_archivo')) {
- function renombrar_archivo($data, $nuevo_nombre)
- {
- $ruta = $data['upload_data']['file_path'];
- $Documento_nuevo = $nuevo_nombre . $data['upload_data']['file_ext'];
- $Documento = $data['upload_data']['file_name'];
- rename($ruta . $Documento, $ruta . $Documento_nuevo);
- return $Documento_nuevo;
- }
- }
- //--modificanfo helpers
- if (!function_exists('eliminar_archivo_servidor')) {
- function eliminar_archivo_servidor($nombre_archivo, $ubicacion = '')
- {
- if ($nombre_archivo != '') {
- if (file_exists('./uploads/' . $ubicacion . $nombre_archivo)) {
- unlink('./uploads/' . $ubicacion . $nombre_archivo);
- }
- }
- }
- }
- //debugging de arrays con javascript
- if (!function_exists('console_log_php')){
- function console_log_php($data)
- {
- echo '<script>';
- echo 'console.log(' . json_encode($data) . ')';
- echo '</script>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement