X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb_pager.inc;h=ff31c1df97ab4960b8945fa460ea58eedb9a5d15;hb=af9e628479b38b0cd7972044ab02902b020211e9;hp=6ad1755a752ff707d7e6b2218d5256383649bf7c;hpb=e8ebca8f2b08eeb3bfd3da04ca946dfa8cc1fb3f;p=fa-stable.git diff --git a/includes/db_pager.inc b/includes/db_pager.inc index 6ad1755a..ff31c1df 100644 --- a/includes/db_pager.inc +++ b/includes/db_pager.inc @@ -77,6 +77,8 @@ class db_pager { // function set_sql($sql) { + global $SysPrefs; + if ($sql != $this->sql) { $this->sql = $sql; $this->ready = false; @@ -94,7 +96,7 @@ class db_pager { $this->select = $parts[0]; $sql = $parts[1]; } else { - if ($go_debug) + if ($SysPrefs->go_debug) display_error("Invalid sql input for db_pager"); } @@ -186,53 +188,53 @@ 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; - } + } // // Calculates page numbers for html controls. // 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 @@ -245,8 +247,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 = ''; @@ -257,10 +259,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': @@ -293,24 +295,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'])) { @@ -319,10 +318,9 @@ class db_pager { } } } - + if (count($ord)) { - $ord = array_map(function_exists('mysql_real_escape_string') ? - 'mysql_real_escape_string': 'mysql_escape_string', $ord); + $ord = array_map('db_escape_function', $ord); $sql .= " ORDER BY " . implode(',', $ord); } else { if($order) @@ -342,7 +340,7 @@ class db_pager { // function _init() { - global $go_debug; + global $SysPrefs; if ($this->ready == false ) { $sql = $this->_sql_gen(true); @@ -354,7 +352,7 @@ class db_pager { $this->max_page = $this->page_len ? ceil($this->rec_count/$this->page_len) : 0; - if ($go_debug) { // FIX - need column name parsing, but for now: + if ($SysPrefs->go_debug) { // FIX - need column name parsing, but for now: // check if field names are set explicite in col def // for all initially ordered columns foreach ($this->columns as $col) { @@ -432,9 +430,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; @@ -510,4 +505,3 @@ function refresh_pager($name) if (isset($_SESSION[$name])) $_SESSION[$name]->ready = false; } -?>