Example #1
0
 function __construct($table, $joins = false)
 {
     global $option;
     global $view;
     $this->table = $table;
     $this->friendlytable = ucfirst(str_replace(TABLEPREFIX, '', $table));
     $this->option = $option;
     $this->view = $view;
     $this->frm_name = "{$table}_filter_form";
     $this->joins = $joins;
     // Are we actively performing a filter
     $this->apply = req::_('frm_name') == $this->frm_name ? true : false;
     if ($this->apply) {
         // actively applying this filter to the current table
         // Filter Params
         $filter = req::_('filter', -1);
         $this->filter = is_array($filter) ? implode(',', $filter) : $filter;
         // Build Pagination params
         $_SESSION['rows_per_page'] = req::_('rows_per_page', ROWS_PER_PAGE, '_SESSION');
         $rows_per_page = $_SESSION['rows_per_page'] = req::_('rows_per_page', $_SESSION['rows_per_page']);
         $first_record = req::_chk('page') ? (req::_('page') - 1) * $rows_per_page + 1 : 1;
         $last_record = $first_record + $rows_per_page - 1;
         // Build where statement
         $search_criteria = req::_('search_criteria', '');
         if (!empty($search_criteria)) {
             $search_criteria = urldecode($search_criteria);
             $pairs = explode('&', $search_criteria);
             $this->search_criteria = array();
             foreach ($pairs as $pair) {
                 $p = explode('=', $pair);
                 $this->search_criteria[$p[0]] = $p[1];
             }
         }
         $this->where = !empty($this->search_criteria) ? dbfn::_buildwhere2($this->search_criteria) : 1;
         // Build order criteria
         $this->order = req::_('order', dbfn::_getPrimary($table));
         $this->dir = req::_('dir', 'ASC');
     } else {
         // not actively applying any filters to this table
         $this->filter = -1;
         $rows_per_page = $_SESSION['rows_per_page'];
         $first_record = 1;
         $last_record = $first_record + $rows_per_page - 1;
         $this->where = 1;
         $this->order = dbfn::_getPrimary($table);
         $this->dir = 'ASC';
     }
     $this->limit = $first_record - 1 . "," . $rows_per_page;
     $this->page = req::_('page', 1);
     $this->rows_per_page = $rows_per_page;
     // Find total records
     $select2 = "SELECT count(*) AS `c` FROM `{$table}` {$joins} WHERE {$this->where}";
     $oTemp = new db($select2);
     $this->total_rows = $oTemp->_getResult();
     $this->first_record = $this->rows_per_page < $this->total_rows ? $first_record : 1;
     $this->last_record = $this->total_rows <= $last_record ? $this->total_rows : $last_record;
     $this->total_pages = ceil($this->total_rows / $this->rows_per_page);
     // Update limit and page number if necessary
     $this->limit = $this->first_record - 1 . "," . $rows_per_page;
     $this->page = $this->rows_per_page < $this->total_rows ? $this->page : 1;
     // Row message: Displaying x - y of z records...
     $this->row_message = $this->total_rows > 0 ? "Showing " . $this->first_record . " - " . $this->last_record . " of " . $this->total_rows . " rows." : "<font style='color:red'>No records found.</font>";
     $this->row_message_class = $this->total_rows > 0 ? "ui-state-success" : "ui-state-error";
 }