From e9a2757a1a9ce6a32711e03f95f0cbb4ac11e9b4 Mon Sep 17 00:00:00 2001
From: Uma S <uma.s@vtiger.com>
Date: Thu, 18 Jul 2019 17:35:58 +0530
Subject: [PATCH] Merge with master

---
 data/CRMEntity.php           | 29 ++++++++++++--------
 include/utils/VtlibUtils.php | 52 ++++++++++++++++++++++++++++++++++++
 languages/en_us/Contacts.php |  1 +
 3 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index ecc1cfe1f..f81a41c2d 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -174,18 +174,25 @@ class CRMEntity {
 			$file_name = $file_details['name'];
 		}
 
-		$save_file = 'true'; 
-		//only images are allowed for Image Attachmenttype 
-		$mimeType = vtlib_mime_content_type($file_details['tmp_name']); 
-		$mimeTypeContents = explode('/', $mimeType); 
-		// For contacts and products we are sending attachmentType as value 
-		if ($attachmentType == 'Image' || ($file_details['size'] && $mimeTypeContents[0] == 'image')) { 
-				$save_file = validateImageFile($file_details); 
-		} 
-		if ($save_file == 'false') { 
-				return false; 
-		} 
+		// Check 1
+		$save_file = 'true';
+		//only images are allowed for Image Attachmenttype
+		$mimeType = vtlib_mime_content_type($file_details['tmp_name']);
+		$mimeTypeContents = explode('/', $mimeType);
+		// For contacts and products we are sending attachmentType as value
+		if ($attachmentType == 'Image' || ($file_details['size'] && $mimeTypeContents[0] == 'image')) {
+			$save_file = validateImageFile($file_details);
+		}
+		if ($save_file == 'false') {
+			return false;
+		}
 
+		// Check 2
+		$save_file = 'true';
+		//only images are allowed for these modules
+		if ($module == 'Contacts' || $module == 'Products') {
+			$save_file = validateImageFile($file_details);
+		}
 		$binFile = sanitizeUploadFileName($file_name, $upload_badext);
 
 		$current_id = $adb->getUniqueID("vtiger_crmentity");
diff --git a/include/utils/VtlibUtils.php b/include/utils/VtlibUtils.php
index 55b571b17..51b35ba0e 100644
--- a/include/utils/VtlibUtils.php
+++ b/include/utils/VtlibUtils.php
@@ -775,4 +775,56 @@ function vtlib_module_icon($modulename){
 function vtlib_mime_content_type($filename) {
 	return Vtiger_Functions::mime_content_type($filename);
 }
+
+/**
+ * Function to add settings entry in CRM settings page
+ * @param string $linkName
+ * @param string $linkURL
+ * @param string $blockName
+ * @return boolean true/false
+ */
+function vtlib_addSettingsLink($linkName, $linkURL, $blockName = false) {
+	$success = true;
+	$db = PearDatabase::getInstance();
+
+	//Check entry name exist in DB or not
+	$result = $db->pquery('SELECT 1 FROM vtiger_settings_field WHERE name=?', array($linkName));
+	if ($result && !$db->num_rows($result)) {
+		$blockId = 0;
+		if ($blockName) {
+			$blockId = getSettingsBlockId($blockName);//Check block name exist in DB or not
+		}
+
+		if (!$blockId) {
+			$blockName = 'LBL_OTHER_SETTINGS';
+			$blockId = getSettingsBlockId($blockName);//Check block name exist in DB or not
+		}
+
+		//Add block in to DB if not exists
+		if (!$blockId) {
+			$blockSeqResult = $db->pquery('SELECT MAX(sequence) AS sequence FROM vtiger_settings_blocks', array());
+			if ($db->num_rows($blockSeqResult)) {
+				$blockId = $db->getUniqueID('vtiger_settings_blocks');
+				$blockSequence = $db->query_result($blockSeqResult, 0, 'sequence');
+				$db->pquery('INSERT INTO vtiger_settings_blocks(blockid, label, sequence) VALUES(?,?,?)', array($blockId, 'LBL_OTHER_SETTINGS', $blockSequence++));
+			}
+		}
+
+		//Add settings field in to DB
+		if ($blockId) {
+			$fieldSeqResult = $db->pquery('SELECT MAX(sequence) AS sequence FROM vtiger_settings_field WHERE blockid=?', array($blockId));
+			if ($db->num_rows($fieldSeqResult)) {
+				$fieldId = $db->getUniqueID('vtiger_settings_field');
+				$linkURL = ($linkURL) ? $linkURL : '';
+				$fieldSequence = $db->query_result($fieldSeqResult, 0, 'sequence');
+
+				$db->pquery('INSERT INTO vtiger_settings_field(fieldid, blockid, name, iconpath, description, linkto, sequence, active, pinned) VALUES(?,?,?,?,?,?,?,?,?)', array($fieldId, $blockId, $entryName, '', $entryName, $linkURL, $fieldSequence++, 0, 0));
+			}
+		} else {
+			$success = false;
+		}
+	}
+	return $success;
+}
+
 ?>
\ No newline at end of file
diff --git a/languages/en_us/Contacts.php b/languages/en_us/Contacts.php
index 73f745093..e012a5993 100644
--- a/languages/en_us/Contacts.php
+++ b/languages/en_us/Contacts.php
@@ -8,6 +8,7 @@
  * All Rights Reserved.
  *************************************************************************************/
 $languageStrings = array(
+	// Basic Strings
 	'Assistant' => 'Assistant',
 	'Assistant Phone' => 'Assistant Phone',
 	'Birthdate' => 'Date of Birth',
-- 
GitLab