From aa78fde6a92f66b84d626e114d8b54a5fb6ece0c Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Wed, 14 Nov 2012 07:19:43 -0500
Subject: [PATCH] - Added function for IPv6 prefixes in multiserver mirror setups to nginx plugin.

---
 interface/lib/classes/listform.inc.php |  184 +++++++++++++++++++++++++++++++---------------
 1 files changed, 124 insertions(+), 60 deletions(-)

diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php
index 6ce5fee..6128022 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);
@@ -115,7 +118,7 @@
 				$record = array();
                 $values = $app->$datasource_class->$datasource_function($field, $record);
             } else {
-                $this->errorMessage .= "Custom datasource class or function is empty<br>\r\n";
+                $this->errorMessage .= "Custom datasource class or function is empty<br />\r\n";
             }
         }
         return $values;
@@ -123,66 +126,82 @@
 
     public function getSearchSQL($sql_where = '') 
     {
-        global $db;
+        global $app, $db;
 
         //* 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]) && !stristr($_REQUEST[$search_prefix.$field],"'")){
+                    $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
+					if(preg_match("/['\\\\]/", $_SESSION['search'][$list_name][$search_prefix.$field])) $_SESSION['search'][$list_name][$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']." '".$app->db->quote($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 $app->functions->intval($_POST['search_limit'])){
+			$_SESSION['search']['limit'] = $app->functions->intval($_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']) ? $app->functions->intval($this->listDef['records_per_page']) : $app->functions->intval($_SESSION['search']['limit'])) ;
         $table              = $this->listDef['table'];
 
         //* set PAGE to zero, if in session not set
@@ -191,14 +210,14 @@
         }
 
         //* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page"
-        if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $_REQUEST["page"];
+        if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $app->functions->intval($_REQUEST["page"]);
 
         //* PAGE to 0 set, if look for themselves ?  page auf 0 setzen, wenn suche sich ge�ndert hat.
         if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0;
 
-        $sql_von = $_SESSION['search'][$list_name]['page'] * $records_per_page;
+        $sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page);
         $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table WHERE $sql_where");
-        $pages = intval(($record_count['anzahl'] - 1) / $records_per_page);
+        $pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page);
 
 
         $vars['list_file']      = $_SESSION['s']['module']['name'].'/'.$this->listDef['file'];
@@ -229,9 +248,9 @@
         //* Show Back 
         if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){
             $content .= '<a href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params']."');".'">'
-                        .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_180.png"></a> ';
+                        .'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_180.png"></a> &nbsp; ';
         }
-        $content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' ';
+        $content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' &nbsp; ';
         //* Show Next
         if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){
             $content .= '<a href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params']."');".'">'
@@ -268,10 +287,15 @@
 
     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'];
+                //* Apply filter to record value.
+                if(isset($field['filters']) && is_array($field['filters'])) {
+                    $app->uses('tform');
+                    $record[$key] = $app->tform->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW');
+                }
 				if(isset($record[$key])) {
                 	switch ($field['datatype']){
                     case 'VARCHAR':
@@ -279,12 +303,40 @@
                         $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':
-                        $record[$key] = intval($record[$key]);
+                        $record[$key] = $app->functions->intval($record[$key]);
                         break;
 
                     case 'DOUBLE':
@@ -292,7 +344,7 @@
                         break;
 
                     case 'CURRENCY':
-                        $record[$key] = number_format($record[$key], 2, ',', '');
+                        $record[$key] = $app->functions->currency_format($record[$key]);
                         break;
 
                     default:
@@ -306,6 +358,7 @@
 
     public function encode($record)
     {
+	global $app;
         if(is_array($record)) {
             foreach($this->listDef['item'] as $field){
                 $key = $field['field'];
@@ -314,25 +367,36 @@
                     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;
 
                     case 'INTEGER':
-                        $record[$key] = intval($record[$key]);
+                        $record[$key] = $app->functions->intval($record[$key]);
                         break;
 
                     case 'DOUBLE':
-                        $record[$key] = mysql_real_escape_string($record[$key]);
+                        $record[$key] = $app->db->quote($record[$key]);
                         break;
 
                     case 'CURRENCY':

--
Gitblit v1.9.1