From e9818989ac8514b3e98740d286b91f94eaa36650 Mon Sep 17 00:00:00 2001
From: "yogeshwar.g" <yogeshwar.g@vtigersolutions.com>
Date: Fri, 19 Jan 2024 10:28:08 +0530
Subject: [PATCH] #Fixes::157703673::Re-fixed;

---
 kcfinder/lib/class_gd.php                     | 13 +++++++----
 .../modules/Settings/Groups/resources/Edit.js |  2 +-
 modules/Calendar/actions/Save.php             |  1 +
 modules/Calendar/views/TaskManagement.php     | 23 +++++++++++--------
 modules/SalesOrder/actions/SaveAjax.php       |  5 ++--
 .../Settings/LayoutEditor/actions/Field.php   |  4 ----
 .../Settings/Vtiger/models/ConfigModule.php   |  4 +---
 modules/Vtiger/actions/ExportData.php         |  8 ++++++-
 modules/Vtiger/actions/Save.php               |  1 +
 modules/Vtiger/actions/SaveAjax.php           | 10 ++++----
 modules/Vtiger/helpers/Util.php               |  2 +-
 11 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/kcfinder/lib/class_gd.php b/kcfinder/lib/class_gd.php
index adfc89784..0ac2aaea9 100644
--- a/kcfinder/lib/class_gd.php
+++ b/kcfinder/lib/class_gd.php
@@ -52,8 +52,13 @@ class gd {
             $height = @imagesy($image);
 
         } elseif (is_array($image)) {
-            list($key, $width) = each($image);
-            list($key, $height) = each($image);
+            $key = key($image);
+            $width = current($image);
+            next($image);
+
+            $key = key($image);
+            $height = current($image);
+            next($image);
             $image = imagecreatetruecolor($width, $height);
 
         } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
@@ -71,8 +76,8 @@ class gd {
         }
 
         $return = (
-            is_resource($image) &&
-            (get_resource_type($image) == "gd") &&
+            ((is_resource($image) && get_resource_type($image) === 'gd') ||
+            (is_object($image) && $image instanceof \GDImage)) &&
             isset($width) &&
             isset($height) &&
             (preg_match('/^[1-9][0-9]*$/', $width) !== false) &&
diff --git a/layouts/v7/modules/Settings/Groups/resources/Edit.js b/layouts/v7/modules/Settings/Groups/resources/Edit.js
index 1b0a169cd..ea8291c48 100644
--- a/layouts/v7/modules/Settings/Groups/resources/Edit.js
+++ b/layouts/v7/modules/Settings/Groups/resources/Edit.js
@@ -60,7 +60,7 @@ Settings_Vtiger_Edit_Js("Settings_Groups_Edit_Js",{},{
 								form.submit();
 							},
 							function(data, err){
-								app.helper.showErrorNotification({message:app.vtranslate('JS_DUPLICATES_EXIST')});
+								app.helper.showErrorNotification({message:data.message});
 								jQuery('.saveButton').removeAttr('disabled');
 								return false;
 							}
diff --git a/modules/Calendar/actions/Save.php b/modules/Calendar/actions/Save.php
index 0074aa18d..f6b4cf19f 100644
--- a/modules/Calendar/actions/Save.php
+++ b/modules/Calendar/actions/Save.php
@@ -159,6 +159,7 @@ class Calendar_Save_Action extends Vtiger_Save_Action {
 				if(!is_array($fieldValue)) {
 					$fieldValue = trim($fieldValue);
 				}
+                                $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 				$recordModel->set($fieldName, $fieldValue);
 			}
 		}
diff --git a/modules/Calendar/views/TaskManagement.php b/modules/Calendar/views/TaskManagement.php
index 678bdcd13..21b3e1541 100644
--- a/modules/Calendar/views/TaskManagement.php
+++ b/modules/Calendar/views/TaskManagement.php
@@ -99,7 +99,7 @@ class Calendar_TaskManagement_View extends Vtiger_Index_View {
 		if (!$request->get('colors')) {
 			$colors = array();
 			foreach ($priorities as $key => $value) {
-				$colors[$key] = $this->getColor($key);
+				$colors[$key] = $this->getColors($key,$field->getName());
 			}
 		} else {
 			$colors = $request->get('colors');
@@ -107,14 +107,19 @@ class Calendar_TaskManagement_View extends Vtiger_Index_View {
 		return $colors;
 	}
 
-	public function getColor($priority) {
-		$color = '';
-		switch ($priority) {
-			case 'High'		:	$color = '#FF5555';	break;
-			case 'Medium'	:	$color = '#03C04A';	break;
-			case 'Low'		:	$color = '#54A7F5';	break;
-			default			:	$color = '#'.dechex(rand(0x000000, 0xFFFFFF));
-								break;
+	public function getColors($priorities,$fieldname){
+		$db=PearDatabase::getInstance();
+		if(isset($priorities)){
+			$tableName = "vtiger_$fieldname";
+			$result=$db->pquery("SELECT color FROM $tableName WHERE $fieldname=?",array($priorities));
+			$no_of_row=$db->num_rows($result);
+			for($i=0;$i<$no_of_row;$i++){
+				$color = $db->query_result($result,$i,'color');
+			}
+		}
+		if(($color=='#ffffff') || ($color=' '))
+		{
+			$color = '#'.dechex(rand(0x000000, 0xFFFFFF));
 		}
 		return $color;
 	}
diff --git a/modules/SalesOrder/actions/SaveAjax.php b/modules/SalesOrder/actions/SaveAjax.php
index 92d2df700..3a04b4049 100755
--- a/modules/SalesOrder/actions/SaveAjax.php
+++ b/modules/SalesOrder/actions/SaveAjax.php
@@ -66,6 +66,7 @@ class SalesOrder_SaveAjax_Action extends Inventory_SaveAjax_Action {
 					if (!is_array($fieldValue)) {
 						$fieldValue = trim($fieldValue);
 					}
+                                        $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 					$recordModel->set($fieldName, $fieldValue);
 				}
 				$recordModel->set($fieldName, $fieldValue);
@@ -84,9 +85,6 @@ class SalesOrder_SaveAjax_Action extends Inventory_SaveAjax_Action {
 					$fieldValue = $fieldModel->getDefaultFieldValue();
 				}
 				$fieldDataType = $fieldModel->getFieldDataType();
-                if($fieldValue){
-                    $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue,$fieldModel);
-                }
 				if ($fieldDataType == 'time' && $fieldValue !== null) {
 					$fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
 				}
@@ -94,6 +92,7 @@ class SalesOrder_SaveAjax_Action extends Inventory_SaveAjax_Action {
 					if (!is_array($fieldValue)) {
 						$fieldValue = trim($fieldValue);
 					}
+                                        $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 					$recordModel->set($fieldName, $fieldValue);
 				}
 			} 
diff --git a/modules/Settings/LayoutEditor/actions/Field.php b/modules/Settings/LayoutEditor/actions/Field.php
index 2e22908e3..33569309f 100644
--- a/modules/Settings/LayoutEditor/actions/Field.php
+++ b/modules/Settings/LayoutEditor/actions/Field.php
@@ -100,10 +100,6 @@ class Settings_LayoutEditor_Field_Action extends Settings_Vtiger_Index_Action {
 	$defaultValue = $fieldInstance->get('defaultvalue');
         if(!is_null($request->get('fieldDefaultValue', null))) {
             $defaultValue = decode_html($request->get('fieldDefaultValue'));
-            if(preg_match('/AM|PM/',$defaultValue) && ($fieldInstance->get('uitype') =='14'))
-            {
-                $defaultValue=Vtiger_Time_UIType::getTimeValueWithSeconds($defaultValue);
-            }
             $fieldInstance->set('defaultvalue', $defaultValue);
         }
 	$response = new Vtiger_Response();
diff --git a/modules/Settings/Vtiger/models/ConfigModule.php b/modules/Settings/Vtiger/models/ConfigModule.php
index f31648625..09c10b560 100644
--- a/modules/Settings/Vtiger/models/ConfigModule.php
+++ b/modules/Settings/Vtiger/models/ConfigModule.php
@@ -153,9 +153,7 @@ class Settings_Vtiger_ConfigModule_Model extends Settings_Vtiger_Module_Model {
 			return "LBL_INVALID_EMAILID";
 		} else if(array_key_exists('HELPDESK_SUPPORT_NAME',$updatedFields) && preg_match ('/[\'";?><]/', $updatedFields['HELPDESK_SUPPORT_NAME'])) {
 			return "LBL_INVALID_SUPPORT_NAME";
-		} else if((array_key_exists('upload_maxsize',$updatedFields) && !filter_var(ltrim($updatedFields['upload_maxsize'],'0'), FILTER_VALIDATE_INT))
-				|| (array_key_exists('list_max_entries_per_page',$updatedFields) &&  !filter_var(ltrim($updatedFields['list_max_entries_per_page'], '0'), FILTER_VALIDATE_INT))
-				|| (array_key_exists('listview_max_textlength',$updatedFields) && !filter_var(ltrim($updatedFields['listview_max_textlength'], '0'), FILTER_VALIDATE_INT))) {
+                } else if((array_key_exists('upload_maxsize',$updatedFields) && !filter_var(ltrim($updatedFields['upload_maxsize'],'0'), FILTER_VALIDATE_INT)) || (array_key_exists('list_max_entries_per_page',$updatedFields) &&  filter_var(ltrim($updatedFields['list_max_entries_per_page'], '0'), FILTER_VALIDATE_INT, array("options" => array("min_range"=>1, "max_range"=>100))) === false) || (array_key_exists('listview_max_textlength',$updatedFields) && filter_var(ltrim($updatedFields['listview_max_textlength'], '0'), FILTER_VALIDATE_INT , array("options" => array("min_range"=>1, "max_range"=>100))) === false)){
 			return "LBL_INVALID_NUMBER";
 		}
 		return true;
diff --git a/modules/Vtiger/actions/ExportData.php b/modules/Vtiger/actions/ExportData.php
index ef3a7fc83..454b0d234 100644
--- a/modules/Vtiger/actions/ExportData.php
+++ b/modules/Vtiger/actions/ExportData.php
@@ -348,7 +348,13 @@ class Vtiger_ExportData_Action extends Vtiger_Mass_Action {
 				if ($value && $value != '0000-00-00') {
 					$value = DateTimeField::convertToUserFormat($value);
 				}
-			} elseif($type == 'datetime') {
+			} /**
+			*  Handled Conversion of time as per custom field time format in exported file
+			*/
+			elseif($uitype == 14) {
+			   $timeUIObj = new Vtiger_Time_UIType();
+			   $value = $timeUIObj->getDisplayValue($value);
+		   }elseif($type == 'datetime') {
 				if ($moduleName == 'Calendar' && in_array($fieldName, array('date_start', 'due_date'))) {
 					$timeField = 'time_start';
 					if ($fieldName === 'due_date') {
diff --git a/modules/Vtiger/actions/Save.php b/modules/Vtiger/actions/Save.php
index 33a714782..4a9c41dd7 100644
--- a/modules/Vtiger/actions/Save.php
+++ b/modules/Vtiger/actions/Save.php
@@ -170,6 +170,7 @@ class Vtiger_Save_Action extends Vtiger_Action_Controller {
 				if(!is_array($fieldValue) && $fieldDataType != 'currency') {
 					$fieldValue = trim($fieldValue);
 				}
+                                $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 				$recordModel->set($fieldName, $fieldValue);
 			}
 		}
diff --git a/modules/Vtiger/actions/SaveAjax.php b/modules/Vtiger/actions/SaveAjax.php
index e8a8618d8..0c5013d10 100644
--- a/modules/Vtiger/actions/SaveAjax.php
+++ b/modules/Vtiger/actions/SaveAjax.php
@@ -38,9 +38,10 @@ class Vtiger_SaveAjax_Action extends Vtiger_Save_Action {
 						$displayValue = $fieldModel->getDisplayValue($fieldValue, $recordModel->getId()); 
 					}
 					if ($fieldModel->getFieldDataType() == 'currency') {
-						$displayValue = Vtiger_Currency_UIType::transformDisplayValue($fieldValue);
+						$displayValue = Vtiger_Currency_UIType::transformDisplayValue(Vtiger_Currency_UIType::convertToDBFormat($fieldValue));
 					}
-					if(!empty($picklistColorMap)) {
+                                        
+					if(!empty($picklistColorMap) && ($fieldModel->getFieldDataType() == 'picklist' || $fieldModel->getFieldDataType() == 'multipicklist')) {
 						$result[$fieldName] = array('value' => $fieldValue, 'display_value' => $displayValue, 'colormap' => $picklistColorMap);
 					} else {
 						$result[$fieldName] = array('value' => $fieldValue, 'display_value' => $displayValue);
@@ -111,6 +112,7 @@ class Vtiger_SaveAjax_Action extends Vtiger_Save_Action {
 					if (!is_array($fieldValue)) {
 						$fieldValue = trim($fieldValue);
 					}
+                                        $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 					$recordModel->set($fieldName, $fieldValue);
 				}
 				$recordModel->set($fieldName, $fieldValue);
@@ -132,9 +134,6 @@ class Vtiger_SaveAjax_Action extends Vtiger_Save_Action {
 				} else {
 					$fieldValue = $fieldModel->getDefaultFieldValue();
 				}
-                if($fieldValue){
-                    $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue,$fieldModel);
-                }
 				$fieldDataType = $fieldModel->getFieldDataType();
 				if ($fieldDataType == 'time' && $fieldValue !== null) {
 					$fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
@@ -144,6 +143,7 @@ class Vtiger_SaveAjax_Action extends Vtiger_Save_Action {
 					if (!is_array($fieldValue)) {
 						$fieldValue = trim($fieldValue);
 					}
+                                        $fieldValue = Vtiger_Util_Helper::validateFieldValue($fieldValue, $fieldModel);
 					$recordModel->set($fieldName, $fieldValue);
 				}
 			} 
diff --git a/modules/Vtiger/helpers/Util.php b/modules/Vtiger/helpers/Util.php
index dbc43a38e..ee94c7792 100644
--- a/modules/Vtiger/helpers/Util.php
+++ b/modules/Vtiger/helpers/Util.php
@@ -140,7 +140,7 @@ class Vtiger_Util_Helper {
 		global $adb;
 		$query = 'Select deleted from vtiger_crmentity where crmid=?';
 		$result = $adb->pquery($query, array($recordId));
-		return $adb->query_result($result, 'deleted');
+		return $adb->query_result($result, 0, 'deleted');
 	}
 
 	/**
-- 
GitLab