Example #1
0
 /**
  * A safe empowered glob().
  *
  * Function glob() is prohibited on some server (probably in safe mode)
  * (Message "Warning: glob() has been disabled for security reasons in
  * (script) on line (line)") for security reasons as stated on:
  * http://seclists.org/fulldisclosure/2005/Sep/0001.html
  *
  * safe_glob() intends to replace glob() using readdir() & fnmatch() instead.
  * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR
  * Additional flags: GLOB_NODIR, GLOB_PATH, GLOB_NODOTS, GLOB_RECURSE
  * (not original glob() flags)
  *
  * @author BigueNique AT yahoo DOT ca
  * @updates
  * - 080324 Added support for additional flags: GLOB_NODIR, GLOB_PATH,
  *   GLOB_NODOTS, GLOB_RECURSE
  */
 function safe_glob($pattern, $flags = 0)
 {
     $split = explode('/', str_replace('\\', '/', $pattern));
     $mask = array_pop($split);
     $path = implode('/', $split);
     if (($dir = @opendir($path)) !== false) {
         $glob = array();
         while (($file = readdir($dir)) !== false) {
             // Recurse subdirectories (GLOB_RECURSE); speedup: no need to sort the intermediate results
             if ($flags & GLOB_RECURSE && is_dir($file) && !in_array($file, array('.', '..'))) {
                 $glob = array_merge($glob, array_prepend(safe_glob($path . '/' . $file . '/' . $mask, $flags | GLOB_NOSORT), $flags & GLOB_PATH ? '' : $file . '/'));
             }
             // Match file mask
             if (fnmatch($mask, $file)) {
                 if ((!($flags & GLOB_ONLYDIR) || is_dir($path . '/' . $file)) && (!($flags & GLOB_NODIR) || !is_dir($path . '/' . $file)) && (!($flags & GLOB_NODOTS) || !in_array($file, array('.', '..')))) {
                     $glob[] = ($flags & GLOB_PATH ? $path . '/' : '') . $file . ($flags & GLOB_MARK && is_dir($path . '/' . $file) ? '/' : '');
                 }
             }
         }
         closedir($dir);
         if (!($flags & GLOB_NOSORT)) {
             sort($glob);
         }
         return $glob;
     } else {
         return false;
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = \Auth::user();
     $userRole = $user->hasRole('user');
     $editorRole = $user->hasRole('editor');
     $adminRole = $user->hasRole('administrator');
     if ($userRole) {
         $access = 'User';
     } elseif ($editorRole) {
         $access = 'Editor';
     } elseif ($adminRole) {
         $access = 'Administrator';
     }
     $today = Carbon::today();
     $año = $today->year;
     // int(2012)
     $mes = $today->month;
     $Activos = Employees::Activos()->count();
     $Bajas = EstadosRevista::BajasDelMes($año, $mes)->count();
     $AltasNuevas = Employees::Activos()->get()->sortBy('Fecha_Ingreso')->forPage(1, 8);
     $Liquidaciones = Liquidacion::where('año', $año)->where('mes', '<=', 12)->whereNull('deleted_at')->orderBy('mes')->get();
     $UltimaLiquidacion = Liquidacion::where('año', $año)->where('mes', '<=', 12)->whereNull('deleted_at')->orderBy('mes', 'desc')->first();
     $AnteUltimaLiquidacion = Liquidacion::where('año', $año)->where('mes', '<=', $UltimaLiquidacion->mes)->whereNull('deleted_at')->orderBy('mes', 'desc')->first();
     $Meses = $Liquidaciones->sortByDesc('mes')->lists('mes');
     $Reten = $Liquidaciones->sortByDesc('mes')->lists('total_retenciones')->toArray();
     $Debes = $Liquidaciones->sortByDesc('mes')->lists('total_debes')->toArray();
     setlocale(LC_TIME, 'Spanish');
     $MesesEsp = [];
     foreach ($Meses as $MesEsp) {
         $MesesEsp = array_prepend($MesesEsp, '"' . Carbon::createFromDate($año, $MesEsp, 1)->formatLocalized('%B') . '"');
     }
     return view('admin.pages.user-home', compact('Activos', 'Bajas', 'AltasNuevas', 'Liquidaciones', 'UltimaLiquidacion', 'AnteUltimaLiquidacion', 'MesesEsp', 'Debes', 'Reten'))->withUser($user)->withAccess($access);
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     // Instead of using the 'exists' validation rule, we opt to use
     // the 'in' rule. We do this because we want to add '0' as a valid
     // value, which will signal a wild card for either all characters
     // or all corporations.
     $character_ids = implode(',', array_prepend(ApiKeyInfoCharacters::pluck('characterID')->toArray(), 0));
     $corporation_ids = implode(',', array_prepend(CorporationSheet::pluck('corporationID')->toArray(), 0));
     return ['id' => 'required|numeric|exists:notification_groups,id', 'characters' => 'required_without_all:corporations', 'corporations' => 'required_without_all:characters', 'characters.*' => 'in:' . $character_ids, 'corporations.*' => 'in:' . $corporation_ids];
 }
 public function view($id)
 {
     $store = Store::findOrFail($id);
     $ids = [];
     foreach ($store->products()->get() as $medicine) {
         $ids = array_prepend($ids, $medicine->id);
     }
     $medicines = Product::whereNotIn('id', $ids)->get();
     return view('store.view', compact('store', 'medicines'));
 }
 function array_prepend($array, $string, $deep = false)
 {
     if (empty($array) || empty($string)) {
         return $array;
     }
     foreach ($array as $key => $element) {
         if (is_array($element)) {
             if ($deep) {
                 $array[$key] = array_prepend($element, $string, $deep);
             } else {
                 trigger_error('array_prepend: array element', E_USER_WARNING);
             }
         } else {
             $array[$key] = $string . $element;
         }
     }
     return $array;
 }
Example #6
0
 /**
  * Adds a child to the front of the child list.
  *
  * @param MenuPresenceInterface $presence
  * @return mixed
  */
 public function shiftChild(MenuPresenceInterface $presence)
 {
     $children = $this->children ?: [];
     if ($children instanceof Collection) {
         $children->prepend($presence);
     } else {
         $children = array_prepend($children, $presence);
     }
     $this->children = $children;
 }
 /**
  * A safe empowered glob().
  *
  * Function glob() is prohibited on some server (probably in safe mode)
  * (Message "Warning: glob() has been disabled for security reasons in
  * (script) on line (line)") for security reasons as stated on:
  * http://seclists.org/fulldisclosure/2005/Sep/0001.html
  *
  * safe_glob() intends to replace glob() using readdir() & fnmatch() instead.
  * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR
  * Additional flags: GLOB_NODIR, GLOB_PATH, GLOB_NODOTS, GLOB_RECURSE, GLOB_NOHIDDEN
  * (not original glob() flags)
  *
  * @author BigueNique AT yahoo DOT ca
  * @updates
  * - 080324 Added support for additional flags: GLOB_NODIR, GLOB_PATH,
  *   GLOB_NODOTS, GLOB_RECURSE
  * - [i_a] Added support for GLOB_NOHIDDEN, split output in directories and files subarrays
  */
 function safe_glob($pattern, $flags = 0)
 {
     $split = explode('/', strtr($pattern, '\\', '/'));
     $mask = array_pop($split);
     $path = implode('/', $split);
     if (($dir = @opendir($path)) !== false) {
         $dirs = array();
         $files = array();
         while (($file = readdir($dir)) !== false) {
             // HACK/TWEAK: PHP5 and below are completely b0rked when it comes to international filenames   :-(
             //             --> do not show such files/directories in the list as they won't be accessible anyway!
             //
             // The regex charset is limited even within the ASCII range, due to    http://en.wikipedia.org/wiki/Filename#Comparison%5Fof%5Ffile%5Fname%5Flimitations
             // Although the filtered characters here are _possible_ on UNIX file systems, they're severely frowned upon.
             if (preg_match('/[^ -)+-.0-;=@-\\[\\]-{}~]/', $file)) {
                 // simply do NOT list anything that we cannot cope with.
                 // That includes clearly inaccessible files (and paths) with non-ASCII characters:
                 // PHP5 and below are a real mess when it comes to handling Unicode filesystems
                 // (see the php.net site too: readdir / glob / etc. user comments and the official
                 // notice that PHP will support filesystem UTF-8/Unicode only when PHP6 is released.
                 //
                 // Big, fat bummer!
                 continue;
             }
             //$temp = unpack("H*",$file);
             //echo 'hexdump of filename = ' . $temp[1] . ' for filename = ' . $file . "<br>\n";
             $filepath = $path . '/' . $file;
             $isdir = is_dir($filepath);
             // Recurse subdirectories (GLOB_RECURSE); speedup: no need to sort the intermediate results
             if ($flags & GLOB_RECURSE && $isdir && !($file == '.' || $file == '..')) {
                 $subsect = safe_glob($filepath . '/' . $mask, $flags | GLOB_NOSORT);
                 if (is_array($subsect)) {
                     if (!($flags & GLOB_PATH)) {
                         $dirs = array_merge($dirs, array_prepend($subject['dirs'], $file . '/'));
                         $files = array_merge($files, array_prepend($subject['files'], $file . '/'));
                     }
                 }
             }
             // Match file mask
             if (fnmatch($mask, $file)) {
                 if ((!($flags & GLOB_ONLYDIR) || $isdir) && (!($flags & GLOB_NODIR) || !$isdir) && (!($flags & GLOB_NODOTS) || !($file == '.' || $file == '..')) && (!($flags & GLOB_NOHIDDEN) || ($file[0] != '.' || $file == '..'))) {
                     if ($isdir) {
                         $dirs[] = ($flags & GLOB_PATH ? $path . '/' : '') . $file . ($flags & GLOB_MARK ? '/' : '');
                     } else {
                         $files[] = ($flags & GLOB_PATH ? $path . '/' : '') . $file;
                     }
                 }
             }
         }
         closedir($dir);
         if (!($flags & GLOB_NOSORT)) {
             sort($dirs);
             sort($files);
         }
         return array('dirs' => $dirs, 'files' => $files);
     } else {
         return false;
     }
 }
Example #8
0
 public function appendLabel($text, $class = null)
 {
     $this->removeClass('labeled')->addClass('right labeled');
     $this->controlsRight = array_prepend($this->controlsRight, (new UiLabel($text))->addClass($class));
     return $this;
 }
    public function definition()
    {
        global $DB;
        $mform =& $this->_form;
        switch ($_SESSION['report_type']) {
            case 'custom_user':
                $table_columns = get_columns(report::$valid_tables['user']);
                $table_columns['user']['user.position'] = 'Position';
                $calc_type = array('total' => 'Total number of users', 'dept' => 'Total number of users per department', 'city' => 'Total number of users per city', 'min_dept' => 'Department with fewest users');
                break;
            case 'custom_course':
                $table_columns = get_columns(report::$valid_tables['course']);
                $table_columns = array_merge($table_columns, get_columns('course_categories'));
                $calc_type = array('total' => 'Total number of courses', 'min_num' => 'Category with fewest courses', 'max_num' => 'Category with the most courses');
                break;
            case 'custom_completions':
                $table_columns = get_columns(report::$valid_tables['course']);
                $table_columns = array_merge($table_columns, get_columns(report::$valid_tables['user']));
                $table_columns = array_merge($table_columns, get_columns(report::$valid_tables['course_completions']));
                $table_columns['course_completions']['course_completions.total_minutes'] = 'training time (Minutes)';
                $table_columns['user']['user.position'] = 'Position';
                $calc_type = array('total' => 'Total Sum of training minutes', 'category' => 'Sum of training minutes per category', 'user' => 'Sum of training minutes per user', 'min_time' => 'shortest completion time', 'max_time' => 'Longest completion time');
                break;
            default:
                break;
        }
        $calc_type = array_prepend($calc_type, '-', '-');
        // functionality: user selects columns to include -> generator joins
        // tables as necessary. Conditions are implied based on the tables
        // involved (i.e. User.first name, course_completions.* -> join on
        // userid)
        $all_cols = array();
        foreach ($table_columns as $table => $columns) {
            $count = count($columns);
            if ($count > 10) {
                $count = $count / 2;
            }
            asort($columns);
            $select_col = $mform->addElement('select', $table . '_columns', 'Select ' . $table . ' columns:', $columns, array('size' => $count));
            $select_col->setMultiple(true);
            $all_cols = array_merge($all_cols, $columns);
        }
        $tab_cols = array_prepend($all_cols, '-', '-');
        $ops = report::$operators;
        $ops = array_prepend($ops, '-', '-');
        $calcs = report::$calculations;
        $calcs = array_prepend($calcs, '-', '-');
        $calc_items = array();
        $calc_items[] = $mform->createElement('select', 'calc_type', 'Select
			Calculation: ', $calc_type);
        $calcnum = 1;
        $calcoptions = array();
        $calcoptions[] = array();
        $calcoptions[] = array();
        $calcoptions[] = array();
        $this->repeat_elements($calc_items, $calcnum, $calcoptions, 'calc_num', 'calc_add', $calcnum, 'Add Calculation');
        $where_items = array();
        $where_items[] = $mform->createElement('select', 'where_col', 'Select
			column to filter on: ', $tab_cols);
        $where_items[] = $mform->createElement('select', 'where_op', 'Select
			filter operation: ', $ops);
        $where_items[] = $mform->createElement('text', 'where_filter', 'Enter
			a value by: ');
        $mform->setType('where_filter', PARAM_NOTAGS);
        $where_items[] =& $mform->createElement('static', 'where_example', '', '<b>e.g. DD-MM-YYYY, trainee3, Business Writing: Email<b><br>');
        $wherenum = 1;
        $whereoptions = array();
        $whereoptions[] = array();
        $whereoptions[] = array();
        $whereoptions[] = array();
        $this->repeat_elements($where_items, $wherenum, $whereoptions, 'where_num', 'where_add', $wherenum, 'Add Filter');
        $select_order = $mform->addElement('select', 'order_by', get_string('select_order_by', 'block_dial_reports'), $tab_cols);
        $this->add_action_buttons(true, get_string('generate_report', 'block_dial_reports'));
    }