From e94a9fb5e4b6a2bc07e0bb4cf8ea35fc70c4bbf0 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 10 May 2012 12:31:27 -0400
Subject: [PATCH] Merged revisions 3049-3051,3053-3054,3058,3070,3074-3077,3082,3086-3088,3091-3092,3094-3095 from stable branch.
---
interface/lib/classes/listform.inc.php | 162 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 110 insertions(+), 52 deletions(-)
diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php
index a3946eb..b17eb0e 100644
--- a/interface/lib/classes/listform.inc.php
+++ b/interface/lib/classes/listform.inc.php
@@ -38,7 +38,6 @@
private $pagingValues;
private $searchChanged = 0;
private $module;
- private $dateformat = 'Y-m-d H:i';
public $wordbook;
public function loadListDef($file, $module = '')
@@ -52,12 +51,14 @@
$this->module = $module;
//* Fill datasources
- foreach($this->listDef['item'] as $key => $field) {
- if(@is_array($field['datasource'])) {
- $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
- }
+ if(@is_array($this->listDef['item'])) {
+ foreach($this->listDef['item'] as $key => $field) {
+ if(@is_array($field['datasource'])) {
+ $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
+ }
+ }
}
-
+
//* Set local Language File
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng';
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng';
@@ -92,6 +93,8 @@
//$querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring);
$app->uses('tform');
$querystring = str_replace("{AUTHSQL}",$app->tform->getAuthSQL('r'),$querystring);
+ $querystring = str_replace("{AUTHSQL-A}",$app->tform->getAuthSQL('r','a'),$querystring);
+ $querystring = str_replace("{AUTHSQL-B}",$app->tform->getAuthSQL('r','b'),$querystring);
//* Getting the records
$tmp_records = $app->db->queryAllRecords($querystring);
@@ -128,61 +131,76 @@
//* Get config variable
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
+
+ if(isset($_REQUEST['Filter']) && !isset($_SESSION['search'][$list_name])) {
+ //* Jump back to page 1 of the list when a new search gets started.
+ $_SESSION['search'][$list_name]['page'] = 0;
+ }
//* store retrieval query
- foreach($this->listDef['item'] as $i) {
- $field = $i['field'];
+ if(@is_array($this->listDef['item'])) {
+ foreach($this->listDef['item'] as $i) {
+ $field = $i['field'];
- //*TODO: comment = hat sich die suche ge�ndert
- if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){
- $this->searchChanged = 1;
- }
+ //* The search string has been changed
+ if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){
+ $this->searchChanged = 1;
+
+ //* Jump back to page 1 of the list when search has changed.
+ $_SESSION['search'][$list_name]['page'] = 0;
+ }
- //* Store field in session
- if(isset($_REQUEST[$search_prefix.$field])){
- $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
- }
+ //* Store field in session
+ if(isset($_REQUEST[$search_prefix.$field])){
+ $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
+ }
- if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){
- if(is_array($i['value'])) {
- $out = '<option value=""></option>';
- foreach($i['value'] as $k => $v) {
- // TODO: this could be more elegant
- $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field])
- && $k == $_SESSION['search'][$list_name][$search_prefix.$field]
- && $_SESSION['search'][$list_name][$search_prefix.$field] != '')
- ? ' SELECTED' : '';
- $out .= "<option value='$k'$selected>$v</option>\r\n";
+ if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){
+ if(is_array($i['value'])) {
+ $out = '<option value=""></option>';
+ foreach($i['value'] as $k => $v) {
+ // TODO: this could be more elegant
+ $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field])
+ && $k == $_SESSION['search'][$list_name][$search_prefix.$field]
+ && $_SESSION['search'][$list_name][$search_prefix.$field] != '')
+ ? ' SELECTED' : '';
+ $out .= "<option value='$k'$selected>$v</option>\r\n";
+ }
+ }
+ $this->searchValues[$search_prefix.$field] = $out;
+ } else {
+ if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){
+ $this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]);
}
}
- $this->searchValues[$search_prefix.$field] = $out;
- } else {
- if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){
- $this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]);
+ }
+ }
+ //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name];
+ if(@is_array($this->listDef['item'])) {
+ foreach($this->listDef['item'] as $i) {
+ $field = $i['field'];
+ // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
+ if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){
+ $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and";
}
}
}
-
- //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name];
- foreach($this->listDef['item'] as $i) {
- $field = $i['field'];
- // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
- if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){
- $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and";
- }
- }
-
return ( $sql_where != '' ) ? $sql_where = substr($sql_where,0,-3) : '1';
}
public function getPagingSQL($sql_where = '1')
{
global $app, $conf;
+
+ //* Add Global Limit from selectbox
+ if(!empty($_POST['search_limit']) AND intval($_POST['search_limit'])){
+ $_SESSION['search']['limit'] = $_POST['search_limit'];
+ }
//* Get Config variables
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
- $records_per_page = $this->listDef['records_per_page'];
+ $records_per_page = (empty($_SESSION['search']['limit']) ? $this->listDef['records_per_page'] : $_SESSION['search']['limit']) ;
$table = $this->listDef['table'];
//* set PAGE to zero, if in session not set
@@ -268,8 +286,8 @@
public function decode($record)
{
- global $conf;
- if(is_array($record)) {
+ global $conf, $app;
+ if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $field){
$key = $field['field'];
if(isset($record[$key])) {
@@ -279,8 +297,36 @@
$record[$key] = htmlentities(stripslashes($record[$key]),ENT_QUOTES,$conf["html_content_encoding"]);
break;
- case 'DATE':
- $record[$key] = ($record[$key] > 0) ? date($this->dateformat,$record[$key]) : '';
+ case 'DATETSTAMP':
+ if ($record[$key] > 0) {
+ // is value int?
+ if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
+ $record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
+ } else {
+ $record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
+ }
+ }
+ break;
+ case 'DATE':
+ if ($record[$key] > 0) {
+ // is value int?
+ if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
+ $record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
+ } else {
+ $record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
+ }
+ }
+ break;
+
+ case 'DATETIME':
+ if ($record[$key] > 0) {
+ // is value int?
+ if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
+ $record[$key] = date($this->lng('conf_format_datetime'), $record[$key]);
+ } else {
+ $record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key]));
+ }
+ }
break;
case 'INTEGER':
@@ -292,7 +338,7 @@
break;
case 'CURRENCY':
- $record[$key] = number_format($record[$key], 2, ',', '');
+ $record[$key] = $app->functions->currency_format($record[$key]);
break;
default:
@@ -306,6 +352,7 @@
public function encode($record)
{
+ global $app;
if(is_array($record)) {
foreach($this->listDef['item'] as $field){
$key = $field['field'];
@@ -314,16 +361,27 @@
case 'VARCHAR':
case 'TEXT':
if(!is_array($record[$key])) {
- $record[$key] = mysql_real_escape_string($record[$key]);
+ $record[$key] = $app->db->quote($record[$key]);
} else {
$record[$key] = implode($this->tableDef[$key]['separator'],$record[$key]);
}
break;
- case 'DATE':
+ case 'DATETSTAMP':
if($record[$key] > 0) {
- list($tag,$monat,$jahr) = explode('.',$record[$key]);
- $record[$key] = mktime(0,0,0,$monat,$tag,$jahr);
+ $record[$key] = date('Y-m-d',strtotime($record[$key]));
+ }
+ break;
+
+ case 'DATE':
+ if($record[$key] != '' && $record[$key] != '0000-00-00') {
+ $record[$key] = $record[$key];
+ }
+ break;
+
+ case 'DATETIME':
+ if($record[$key] > 0) {
+ $record[$key] = date('Y-m-d H:i:s',strtotime($record[$key]));
}
break;
@@ -332,7 +390,7 @@
break;
case 'DOUBLE':
- $record[$key] = mysql_real_escape_string($record[$key]);
+ $record[$key] = $app->db->quote($record[$key]);
break;
case 'CURRENCY':
@@ -370,4 +428,4 @@
}
-?>
\ No newline at end of file
+?>
--
Gitblit v1.9.1