From 2d2fd172e1548dd24e1719accd0b856cff6a31a0 Mon Sep 17 00:00:00 2001
From: Falko Timme <ft@falkotimme.com>
Date: Fri, 18 Oct 2013 12:20:13 -0400
Subject: [PATCH] - Added funtion to convert currency formatted numbers back to floating numbers. - Improved getSearchSQL() function so that users can use their native date format so search for dates in lists.

---
 interface/lib/classes/tform.inc.php |  131 ++++++++++++++-----------------------------
 1 files changed, 42 insertions(+), 89 deletions(-)

diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index bd28db4..7cefb22 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -553,7 +553,8 @@
                                         break;
 
                                 case 'PASSWORD':
-                                        $new_record[$key] = '';
+                                        //$new_record[$key] = '';
+										$new_record[$key] = htmlspecialchars($field['default']);
                                 break;
 
                                 case 'CHECKBOX':
@@ -887,6 +888,7 @@
 										  }
                                         }
                                 break;
+				/*
 				case 'ISV6PREFIX':
 					$v6_prefix_ok = 0;
 					$explode_field_value = explode(':',$field_value);
@@ -917,7 +919,8 @@
 					if($v6_prefix_ok <> 1){
 						$this->errorMessage .= $errmsg."<br />\r\n"; 
 					}
-				break;
+				break;
+				*/
 								case 'ISIPV4':
 								$vip=1;
 								if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){
@@ -937,31 +940,45 @@
 										}
                                 break;
 								case 'ISIP':
-								//* Check if its a IPv4 or IPv6 address
-								if(function_exists('filter_var')) {
-									if(!filter_var($field_value,FILTER_VALIDATE_IP)) {
-										$errmsg = $validator['errmsg'];
-										if(isset($this->wordbook[$errmsg])) {
-											$this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n";
-										} else {
-											$this->errorMessage .= $errmsg."<br />\r\n";
-										}
-									}
+								if($validator['allowempty'] != 'y') $validator['allowempty'] = 'n';
+								if($validator['allowempty'] == 'y' && $field_value == '') {
+									//* Do nothing
 								} else {
-									//* Check content with regex, if we use php < 5.2
-									$ip_ok = 0;
-									if(preg_match("/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i", $field_value)){
-										$ip_ok = 1;
+								//* Check if its a IPv4 or IPv6 address
+									if(isset($validator['separator']) && $validator['separator'] != '') {
+										//* When the field may contain several IP addresses, split them by the char defined as separator
+										$field_value_array = explode($validator['separator'],$field_value);
+									} else {
+										$field_value_array[] = $field_value;
 									}
-									if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){
-										$ip_ok = 1;
-									}
-									if($ip_ok == 0) {
-										$errmsg = $validator['errmsg'];
-										if(isset($this->wordbook[$errmsg])) {
-											$this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n";
+									foreach($field_value_array as $field_value) {
+										$field_value = trim($field_value);
+										if(function_exists('filter_var')) {
+											if(!filter_var($field_value,FILTER_VALIDATE_IP)) {
+												$errmsg = $validator['errmsg'];
+												if(isset($this->wordbook[$errmsg])) {
+													$this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n";
+												} else {
+													$this->errorMessage .= $errmsg."<br />\r\n";
+												}
+											}
 										} else {
-											$this->errorMessage .= $errmsg."<br />\r\n";
+											//* Check content with regex, if we use php < 5.2
+											$ip_ok = 0;
+											if(preg_match("/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i", $field_value)){
+												$ip_ok = 1;
+											}
+											if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){
+												$ip_ok = 1;
+											}
+											if($ip_ok == 0) {
+												$errmsg = $validator['errmsg'];
+												if(isset($this->wordbook[$errmsg])) {
+													$this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n";
+												} else {
+													$this->errorMessage .= $errmsg."<br />\r\n";
+												}
+											}
 										}
 									}
 								}
@@ -1243,7 +1260,7 @@
 		function getDataRecord($primary_id) {
 			global $app;
 			$escape = '`';
-			$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
+			$sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id." AND ".$this->getAuthSQL('r',$this->formDef['db_table']);
             return $app->db->queryOneRecord($sql);
 		}
 		
@@ -1253,70 +1270,6 @@
 				
 				$app->db->datalogSave($this->formDef['db_table'], $action, $this->formDef['db_table_idx'], $primary_id, $record_old, $record_new);
 				return true;
-				
-				/*
-                // Add backticks for incomplete table names.
-                if(stristr($this->formDef['db_table'],'.')) {
-                        $escape = '';
-                } else {
-                        $escape = '`';
-                }
-
-                $this->diffrec = array();
-				
-				// Full diff records for ISPConfig, they have a different format then the simple diffrec
-				$diffrec_full = array();
-
-                if(is_array($record_old) && count($record_old) > 0) {
-                        foreach($record_old as $key => $val) {
-                                //if(isset($record_new[$key]) && $record_new[$key] != $val) {
-								if(!isset($record_new[$key]) || $record_new[$key] != $val) {
-                                    // Record has changed
-									$diffrec_full['old'][$key] = $val;
-									$diffrec_full['new'][$key] = $record_new[$key];
-									$this->diffrec[$key] = array(	'new' => $record_new[$key],
-                                                               		'old' => $val);
-                                } else {
-									$diffrec_full['old'][$key] = $val;
-									$diffrec_full['new'][$key] = $val;
-								}
-                        }
-                } elseif(is_array($record_new)) {
-                        foreach($record_new as $key => $val) {
-                                if(isset($record_new[$key]) && $record_old[$key] != $val) {
-                                    // Record has changed
-									$diffrec_full['new'][$key] = $val;
-									$diffrec_full['old'][$key] = $record_old[$key];
-									$this->diffrec[$key] = array(	'old' => @$record_old[$key],
-                                                               		'new' => $val);
-                                } else {
-									$diffrec_full['new'][$key] = $val;
-									$diffrec_full['old'][$key] = $val;
-								}
-                        }
-                }
-				
-				//$this->diffrec = $diffrec;
-				// Insert the server_id, if the record has a server_id
-				$server_id = (isset($record_old["server_id"]) && $record_old["server_id"] > 0)?$record_old["server_id"]:0;
-				if(isset($record_new["server_id"])) $server_id = $record_new["server_id"];
-
-                if(count($this->diffrec) > 0) {
-						$diffstr = addslashes(serialize($diffrec_full));
-                        $username = $app->db->quote($_SESSION["s"]["user"]["username"]);
-                        $dbidx = $this->formDef['db_table_idx'].":".$primary_id;
-                        // $action = ($action == 'INSERT')?'i':'u';
-						
-						if($action == 'INSERT') $action = 'i';
-						if($action == 'UPDATE') $action = 'u';
-						if($action == 'DELETE') $action = 'd';
-                        $sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$this->formDef['db_table']."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')";
-						$app->db->query($sql);
-                }
-
-                return true;
-				*/
-
         }
 
         function getAuthSQL($perm, $table = '') {

--
Gitblit v1.9.1