Advertisement
yacel100

function_helper.php

Sep 1st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.43 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. if (!function_exists('option_access')) {
  4.     function option_access($a = array())
  5.     {
  6.         foreach ($a as $str) {
  7.             if (in_array($str, $_SESSION['permisos']))
  8.                 return true;
  9.         }
  10.         return false;
  11.     }
  12. }
  13. if (!function_exists('check_access')) {
  14.     function check_access($a = array(), $redirect = false)
  15.     {
  16.         if (isset($_SESSION['permisos'])) {
  17.             // array_push($a, 'PASAJES_ADMINISTRADOR');
  18.             if (!option_access($a)) {
  19.                 if ($redirect) {
  20.                     echo 'Usted no tiene acceso a esta opción, contacte con el administrador.';
  21.                     redirect('http://' . $_SERVER['SERVER_ADDR'] . '/error_acceso.php');
  22.                     die;
  23.                 } else
  24.                     return false;
  25.             } else
  26.                 return true;
  27.         } else {
  28.             if ($redirect) {
  29.                 echo 'Usted no tiene acceso a esta opción, contacte con el administrador.';
  30.                 redirect('http://' . $_SERVER['SERVER_ADDR'] . '/error_acceso.php');
  31.                 die;
  32.             } else
  33.                 return false;
  34.         }
  35.     }
  36. }
  37.  
  38. //recibe la fecha en format d.m.Y y devuelve Ymd
  39. if (!function_exists('convertir_fecha_formato_sql')) {
  40.     function convertir_fecha_formato_sql($sFecha, $sufijo=''){
  41.         // echo $sFecha . '---' . gettype($sFecha) . '<br>';
  42.         $sFecha = gettype($sFecha)=='string' ? trim($sFecha) : (gettype($sFecha)=='object' && $sFecha instanceof DateTime ? $sFecha->format('d.m.Y') : '');
  43.         if( $sFecha!='' ){
  44.             $sFecha = explode(' ', $sFecha); //para deshacernos de la parte de la hora en caso que tuviera
  45.             $sFecha = explode('.', $sFecha[0]);
  46.             if( is_numeric($sFecha[0]) && is_numeric($sFecha[1]) && is_numeric($sFecha[2]) )
  47.                 return "'" . $sFecha[2] . '' . $sFecha[1] . '' . $sFecha[0] . ($sufijo==''?'':' ' . $sufijo) . "'";
  48.             else
  49.                 return 'null';
  50.         }
  51.         else
  52.             return 'null';
  53.     }
  54. }
  55.  
  56. //D=Días, DH=Días habiles, M=Meses, W=Semanas
  57. if (!function_exists('codigo_plazo')) {
  58.     function codigo_plazo($codigo_plazo)
  59.     {
  60.         $plazo = '';
  61.         if ($codigo_plazo == 'D')
  62.             $plazo = 'Días';
  63.         elseif ($codigo_plazo == 'DH')
  64.             $plazo = 'Días hábiles';
  65.         elseif ($codigo_plazo == 'W')
  66.             $plazo = 'Semanas';
  67.         elseif ($codigo_plazo == 'M')
  68.             $plazo = 'Meses';
  69.         return $plazo;
  70.     }
  71. }
  72.  
  73.  
  74. if (!function_exists('subir_archivo')) {
  75.     function subir_archivo($t, $input, $ruta = '',$tipo_archivo = '')
  76.     {
  77.         $config['upload_path'] = './uploads/' . $ruta;
  78.         if ($tipo_archivo != '') {
  79.             $config['allowed_types'] =$tipo_archivo;
  80.         }else{
  81.             $config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx|xls|xlsx|msg|zip';
  82.         }
  83.         $config['max_size'] = 1024 * 30;
  84.         $config['overwrite'] = true;
  85.         $t->load->library('upload', $config);
  86.         if (!$t->upload->do_upload($input)) {
  87.             $data = array('error' => $t->upload->display_errors(), 'File type:' => $t->upload->file_type);
  88.         } else {
  89.             $data = array('upload_data' => $t->upload->data());
  90.         }
  91.         // print_r($data);
  92.         $t->upload->initialize_error();
  93.         return $data;
  94.     }
  95. }
  96. if (!function_exists('renombrar_archivo')) {
  97.     function renombrar_archivo($data, $nuevo_nombre)
  98.     {
  99.         $ruta = $data['upload_data']['file_path'];
  100.         $Documento_nuevo = $nuevo_nombre . $data['upload_data']['file_ext'];
  101.         $Documento = $data['upload_data']['file_name'];
  102.         rename($ruta . $Documento, $ruta . $Documento_nuevo);
  103.         return $Documento_nuevo;
  104.     }
  105. }
  106. //--modificanfo helpers
  107. if (!function_exists('eliminar_archivo_servidor')) {
  108.     function eliminar_archivo_servidor($nombre_archivo, $ubicacion = '')
  109.     {
  110.         if ($nombre_archivo != '') {
  111.             if (file_exists('./uploads/' . $ubicacion . $nombre_archivo)) {
  112.                 unlink('./uploads/' . $ubicacion . $nombre_archivo);
  113.             }
  114.         }
  115.     }
  116. }
  117.  
  118.  
  119. //debugging de arrays con javascript
  120. if (!function_exists('console_log_php')){
  121.  
  122.     function console_log_php($data)
  123.     {
  124.         echo '<script>';
  125.         echo 'console.log(' . json_encode($data) . ')';
  126.         echo '</script>';
  127.     }
  128. }
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement