|
|
|
@ -95,6 +95,11 @@ class SortableTable extends HTML_Table |
|
|
|
|
public $use_jqgrid = false; |
|
|
|
|
public $table_id = null; |
|
|
|
|
public $headers = array(); |
|
|
|
|
/** |
|
|
|
|
* @var array |
|
|
|
|
* Columns to hide |
|
|
|
|
*/ |
|
|
|
|
private $columnsToHide = array(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new SortableTable |
|
|
|
@ -124,7 +129,6 @@ class SortableTable extends HTML_Table |
|
|
|
|
$table_id = $table_name.uniqid(); |
|
|
|
|
} |
|
|
|
|
$this->table_id = $table_id; |
|
|
|
|
|
|
|
|
|
parent::__construct(array('class' => 'data_table', 'id' => $table_id)); |
|
|
|
|
$this->table_name = $table_name; |
|
|
|
|
$this->additional_parameters = array(); |
|
|
|
@ -240,6 +244,7 @@ class SortableTable extends HTML_Table |
|
|
|
|
public function return_table() |
|
|
|
|
{ |
|
|
|
|
$empty_table = false; |
|
|
|
|
$this->processHeaders(); |
|
|
|
|
$content = $this->get_table_html(); |
|
|
|
|
|
|
|
|
|
if ($this->get_total_number_of_items() == 0) { |
|
|
|
@ -293,7 +298,6 @@ class SortableTable extends HTML_Table |
|
|
|
|
$html .= '<td>'; |
|
|
|
|
|
|
|
|
|
if (count($this->form_actions) > 0) { |
|
|
|
|
|
|
|
|
|
$html .= '<div class="btn-toolbar">'; |
|
|
|
|
$html .= '<div class="btn-group">'; |
|
|
|
|
$html .= '<a class="btn" href="?'.$params.'&'.$this->param_prefix.'selectall=1" onclick="javascript: setCheckbox(true, \''.$table_id.'\'); return false;">'.get_lang('SelectAll').'</a>'; |
|
|
|
@ -588,6 +592,7 @@ class SortableTable extends HTML_Table |
|
|
|
|
|
|
|
|
|
foreach ($this->th_attributes as $column => $attributes) { |
|
|
|
|
$this->setCellAttributes(0, $column, $attributes); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
foreach ($this->td_attributes as $column => $attributes) { |
|
|
|
|
$this->setColAttributes($column, $attributes); |
|
|
|
@ -667,6 +672,66 @@ class SortableTable extends HTML_Table |
|
|
|
|
return $showed_items[0].' - '.$showed_items[1].' / '.$this->get_total_number_of_items(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function getHeaders() |
|
|
|
|
{ |
|
|
|
|
return $this->headers; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Process headers |
|
|
|
|
*/ |
|
|
|
|
public function processHeaders() |
|
|
|
|
{ |
|
|
|
|
foreach ($this->headers as $column => $columnInfo) { |
|
|
|
|
$label = $columnInfo['label']; |
|
|
|
|
$sortable = $columnInfo['sortable']; |
|
|
|
|
$th_attributes = $columnInfo['th_attributes']; |
|
|
|
|
$td_attributes = $columnInfo['td_attributes']; |
|
|
|
|
|
|
|
|
|
$param['direction'] = 'ASC'; |
|
|
|
|
if ($this->column == $column && $this->direction == 'ASC') { |
|
|
|
|
$param['direction'] = 'DESC'; |
|
|
|
|
} |
|
|
|
|
$param['page_nr'] = $this->page_nr; |
|
|
|
|
$param['per_page'] = $this->per_page; |
|
|
|
|
$param['column'] = $column; |
|
|
|
|
if ($sortable) { |
|
|
|
|
$link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&'; |
|
|
|
|
foreach ($param as $key => & $value) { |
|
|
|
|
$link .= $this->param_prefix.$key.'='.urlencode($value).'&'; |
|
|
|
|
} |
|
|
|
|
$link .= $this->get_additional_url_paramstring(); |
|
|
|
|
$link .= '">'.$label.'</a>'; |
|
|
|
|
if ($this->column == $column) { |
|
|
|
|
$link .= $this->direction == 'ASC' ? ' ↓' : ' ↑'; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$link = $label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$addHeader = true; |
|
|
|
|
if (!empty($this->columnsToHide)) { |
|
|
|
|
if (isset($this->columnsToHide[$column])) { |
|
|
|
|
$addHeader = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($addHeader) { |
|
|
|
|
$this->setHeaderContents(0, $column, $link); |
|
|
|
|
|
|
|
|
|
if (!is_null($td_attributes)) { |
|
|
|
|
$this->td_attributes[$column] = $td_attributes; |
|
|
|
|
} |
|
|
|
|
if (!is_null($th_attributes)) { |
|
|
|
|
$this->th_attributes[$column] = $th_attributes; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set the header-label |
|
|
|
|
* @param int $column The column number |
|
|
|
@ -680,33 +745,12 @@ class SortableTable extends HTML_Table |
|
|
|
|
*/ |
|
|
|
|
public function set_header($column, $label, $sortable = true, $th_attributes = null, $td_attributes = null) |
|
|
|
|
{ |
|
|
|
|
$param['direction'] = 'ASC'; |
|
|
|
|
if ($this->column == $column && $this->direction == 'ASC') { |
|
|
|
|
$param['direction'] = 'DESC'; |
|
|
|
|
} |
|
|
|
|
$param['page_nr'] = $this->page_nr; |
|
|
|
|
$param['per_page'] = $this->per_page; |
|
|
|
|
$param['column'] = $column; |
|
|
|
|
if ($sortable) { |
|
|
|
|
$link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&'; |
|
|
|
|
foreach ($param as $key => & $value) { |
|
|
|
|
$link .= $this->param_prefix.$key.'='.urlencode($value).'&'; |
|
|
|
|
} |
|
|
|
|
$link .= $this->get_additional_url_paramstring(); |
|
|
|
|
$link .= '">'.$label.'</a>'; |
|
|
|
|
if ($this->column == $column) { |
|
|
|
|
$link .= $this->direction == 'ASC' ? ' ↓' : ' ↑'; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$link = $label; |
|
|
|
|
} |
|
|
|
|
$this->setHeaderContents(0, $column, $link); |
|
|
|
|
if (!is_null($td_attributes)) { |
|
|
|
|
$this->td_attributes[$column] = $td_attributes; |
|
|
|
|
} |
|
|
|
|
if (!is_null($th_attributes)) { |
|
|
|
|
$this->th_attributes[$column] = $th_attributes; |
|
|
|
|
} |
|
|
|
|
$this->headers[$column] = array( |
|
|
|
|
'label' => $label, |
|
|
|
|
'sortable' => $sortable, |
|
|
|
|
'th_attributes' => $th_attributes, |
|
|
|
|
'td_attributes' => $td_attributes, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -782,6 +826,15 @@ class SortableTable extends HTML_Table |
|
|
|
|
$this->column_filters[$column] = $function; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* List of columns to hide |
|
|
|
|
* @param int $column |
|
|
|
|
*/ |
|
|
|
|
public function setHideColumn($column) |
|
|
|
|
{ |
|
|
|
|
$this->columnsToHide[$column] = $column; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Define a list of actions which can be performed on the table-date. |
|
|
|
|
* If you define a list of actions, the first column of the table will be |
|
|
|
@ -832,6 +885,15 @@ class SortableTable extends HTML_Table |
|
|
|
|
foreach ($this->column_filters as $column => & $function) { |
|
|
|
|
$row[$column] = call_user_func($function, $row[$column], $url_params, $row); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($this->columnsToHide)) { |
|
|
|
|
foreach ($this->columnsToHide as $index) { |
|
|
|
|
if (isset($row[$index])) { |
|
|
|
|
unset($row[$index]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (count($this->form_actions) > 0) { |
|
|
|
|
if (strlen($row[0]) > 0) { |
|
|
|
|
$row[0] = '<input type="checkbox" name="'.$this->checkbox_name.'[]" value="'.$row[0].'"'; |
|
|
|
|