X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb_pager.inc;h=affb9e09796e9cf046abdb0998817ed533eac076;hb=df660a601cabb0afe7f3246884f16207b9a0c314;hp=f9089e9ee5a0f2ba89f152762f0645f5dab020ad;hpb=5e63c6ace55729bbb5ee3b060035a25a4426eb0a;p=fa-stable.git diff --git a/includes/db_pager.inc b/includes/db_pager.inc index f9089e9e..affb9e09 100644 --- a/includes/db_pager.inc +++ b/includes/db_pager.inc @@ -29,6 +29,7 @@ class db_pager { var $width; // table width (default '95%') var $header_fun; // additional row between title and body var $header_class; + var $row_fun; // Function for row preprocessing var $footer_fun; var $footer_class; var $data = array(); @@ -48,7 +49,7 @@ class db_pager { $from, $group, $order; - var $extra_where; + var $extra_where = array(); var $ready = false; // this var is false after change in sql before first // and before first query. @@ -64,7 +65,7 @@ class db_pager { // array('select' => 'SUM(quantity)', 'from' => TB_PREF."stock_moves", 'group' => 'location') // // $name is base name for pager controls - function db_pager($sql, $name, $table = null, $page_len=0) + function __construct($sql, $name, $table = null, $page_len=0) { $this->width = "95%"; if ($page_len == 0) $page_len = user_query_size(); @@ -119,11 +120,6 @@ class db_pager { } } } - //_vd($this->select); - //_vd($this->from); - //_vd($this->where); - //_vd($this->group); - //_vd($this->order); } // // Set additional constraint on record set @@ -193,22 +189,22 @@ class db_pager { if ($result) { // setting field names for subsequent queries $c = 0; - // add result field names to column defs for - // col value retrieve and sort purposes - $cnt = min(db_num_fields($result), count($this->columns)); + // add result field names to column defs for + // col value retrieve and sort purposes + $cnt = min(db_num_fields($result), count($this->columns)); for ($c = $i = 0; $c < $cnt; $c++) { if (!(isset($this->columns[$c]['insert']) && $this->columns[$c]['insert'])) { // if (!@($this->columns[$c]['type']=='skip')) $this->columns[$c]['name']= db_field_name($result, $i); if (!@($this->columns[$c]['type']=='insert')) - $i++; - } + $i++; + } } while ($row = db_fetch_assoc($result)) { $this->data[] = $row; } } else - return false; + return false; return true; } // @@ -217,29 +213,29 @@ class db_pager { function set_page($to) { switch($to) { - case 'next': - $page = $this->curr_page+1; break; - case 'prev': - $page = $this->curr_page-1; break; - case 'last': - $page = $this->last_page; break; - default: - if (is_numeric($to)) { - $page = $to; break; - } - case 'first': - $page = 1; break; + case 'next': + $page = $this->curr_page+1; break; + case 'prev': + $page = $this->curr_page-1; break; + case 'last': + $page = $this->last_page; break; + default: + if (is_numeric($to)) { + $page = $to; break; + } + case 'first': + $page = 1; break; } - if ($page < 1) - $page = 1; - $max = $this->max_page; - if ($page > $max) - $page = $max; - $this->curr_page = $page; - $this->next_page = ($page < $max) ? $page+1 : null; - $this->prev_page = ($page > 1) ? ($page-1) : null; - $this->last_page = ($page < $max) ? $max : null; - $this->first_page = ($page != 1) ? 1: null; + if ($page < 1) + $page = 1; + $max = $this->max_page; + if ($page > $max) + $page = $max; + $this->curr_page = $page; + $this->next_page = ($page < $max) ? $page+1 : null; + $this->prev_page = ($page > 1) ? ($page-1) : null; + $this->last_page = ($page < $max) ? $max : null; + $this->first_page = ($page != 1) ? 1: null; } // // Set column definitions @@ -252,8 +248,8 @@ class db_pager { } foreach ($flds as $colnum=>$coldef) { if (is_string($colnum)) { // 'colname'=>params - $h = $colnum; - $c = $coldef; + $h = $colnum; + $c = $coldef; } else { // n=>params if (is_array($coldef)) { $h = ''; @@ -264,10 +260,10 @@ class db_pager { } } if (is_string($c)) // params is simple column type - $c = array('type'=>$c); + $c = array('type'=>$c); if (!isset($c['type'])) - $c['type'] = 'text'; + $c['type'] = 'text'; switch($c['type']) { case 'inactive': @@ -300,24 +296,21 @@ class db_pager { } if ($where) $where = " WHERE ($where)"; - if ($count) { - $group = $group == '' ? "*" : "DISTINCT $group"; - - return "SELECT COUNT($group) FROM $from $where"; - } + if ($count) + return "SELECT COUNT(*) FROM ($this->sql) tmp_count"; $sql = "$select FROM $from $where"; if ($group) $sql.= " GROUP BY $group"; $ord = array(); - // sort order column by priority instead of table order. - $columns = array(); + // sort order column by priority instead of table order. + $columns = array(); foreach ($this->columns as $col) { - if(isset($col['ord_priority'])) { - $columns[$col['ord_priority']] = $col; - } + if(isset($col['ord_priority'])) { + $columns[$col['ord_priority']] = $col; } - krsort($columns); + } + krsort($columns); foreach ($columns as $col) { if (isset($col['ord'])) { @@ -326,7 +319,7 @@ class db_pager { } } } - + if (count($ord)) { $ord = array_map('db_escape_function', $ord); $sql .= " ORDER BY " . implode(',', $ord); @@ -438,9 +431,6 @@ class db_pager { function inactive_control_cell(&$row) { if ($this->inactive_ctrl) { -// return inactive_control_cell($row[$this->inactive_ctrl['key']], -// $row['inactive'], $this->inactive_ctrl['table'], -// $this->inactive_ctrl['key']); global $Ajax;