// Change sort column direction
// in order asc->desc->none->asc
//
- function sort_table($col=null)
+ function sort_table($col)
{
$ord = $this->columns[$col]['ord'];
$ord = ($ord == '') ? 'asc' : (($ord == 'asc') ? 'desc' : '');
// add result field names to column defs for
// col value retrieve and sort purposes
for ($c = $i = 0; $c < count($this->columns); $c++) {
- if ($this->columns[$c]['type'] != 'insert')
+ if (!(isset($this->columns[$c]['insert']) && $this->columns[$c]['insert']))
$this->columns[$c]['name']= mysql_field_name($result, $i++);
}
$flds = array($flds);
}
foreach ($flds as $colnum=>$coldef) {
- if (!is_numeric($colnum)) { // 'colname'=>params
+ if (is_string($colnum)) { // 'colname'=>params
$h = $colnum;
$c = $coldef;
} else { // n=>params
$h = $coldef;
$c = 'text';
}
- $c = '';
}
- if (!is_array($c)) // params is simple column type
+ if (is_string($c)) // params is simple column type
$c = array('type'=>$c);
if (!isset($c['type']))
return "SELECT COUNT($group) FROM $from $where";
}
- $sql = "$select FROM $from $where GROUP BY $group";
+ $sql = "$select FROM $from $where";
+ if($group) $sql.= " GROUP BY $group";
$ord = array();
foreach( $this->columns as $col) {
global $Ajax;
$page = find_submit($this->name.'_page_', false);
- $sort = find_submit($this->name.'_sort_', false);
+ $sort = find_submit($this->name.'_sort_', true);
if ($page) {
$this->change_page($page);
- } elseif ($sort) {
+ if ($page == 'next' && !$this->next_page ||
+ $page == 'last' && !$this->last_page)
+ set_focus($this->name.'_page_prev');
+ if ($page == 'prev' && !$this->prev_page ||
+ $page == 'first' && !$this->first_page)
+ set_focus($this->name.'_page_next');
+ } elseif ($sort != -1) {
$this->sort_table($sort);
} else
$this->query();
// $sql - base sql for data inquiry. Order of fields implies
// pager columns order.
// $coldef - array of column definitions. Example definitions
-// Text column with title 'User name':
+// Column with title 'User name' and default text format:
// 'User name'
// Skipped field from sql query. Data for the field is not displayed:
// 'dummy' => 'skip'
-// Column without title, formated with function func(). Field value
-// is passed as parameter:
-// array('type'=>'spec', 'fun'=>'func')
-// Inserted column with title 'Some', formated with function rowfun(). Row
-// values are passed as parameter array:
-// 'Some' => array('type'=>'insert', 'fun'=>'rowfun')
+// Column without title, data retrieved form row data with function func():
+// array('fun'=>'func')
+// Inserted column with title 'Some', formated with function rowfun().
+// formated as date:
+// 'Some' => array('type'=>'date, 'insert'=>true, 'fun'=>'rowfun')
// Column with name 'Another', formatted as date,
// sortable with ascending start order (available orders: asc,desc, '').
// 'Another' => array('type'=>'date', 'ord'=>'asc')