diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 33ff58a4a4a96c4214ba31e72ff57648ecfc4300..3407cb024b7bdd8e60edc01d793d1a879284d45a 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -269,6 +269,7 @@ class CRMEntity {
 
 		$ownerid = $this->column_fields['assigned_user_id'];
 		$groupid = $this->column_fields['group_id'];
+		$insertion_mode = $this->mode;
 
 		if (empty($groupid))
 			$groupid = 0;
@@ -298,7 +299,6 @@ class CRMEntity {
         $label = decode_html($record_label);
         $this->column_fields['label'] = $label;
 
-		$insertion_mode = '';
 		if ($this->mode == 'edit') {
 			$description_val = from_html($this->column_fields['description'], ($insertion_mode == 'edit') ? true : false);
 
@@ -649,7 +649,7 @@ class CRMEntity {
 							foreach($IMG_FILES as $fileIndex => $file) {
 								if($file['error'] == 0 && $file['name'] != '' && $file['size'] > 0) {
 									if($_REQUEST[$fileIndex.'_hidden'] != '')
-										$file['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']);
+										$file['original_name'] = vtlib_purify($_REQUEST[$fileIndex.'_hidden']);
 									else {
 										$file['original_name'] = stripslashes($file['name']);
 									}
@@ -687,8 +687,8 @@ class CRMEntity {
 						$uploadedFileNames = array();
 						foreach($UPLOADED_FILES as $fileIndex => $file) {
 							if($file['error'] == 0 && $file['name'] != '' && $file['size'] > 0) {
-								if($_REQUEST[$fileindex.'_hidden'] != '') {
-									$file['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']);
+								if(isset($_REQUEST[$fileIndex.'_hidden']) && $_REQUEST[$fileIndex.'_hidden'] != '') {
+									$file['original_name'] = vtlib_purify($_REQUEST[$fileIndex.'_hidden']);
 								} else {
 									$file['original_name'] = stripslashes($file['name']);
 								}
@@ -746,8 +746,12 @@ class CRMEntity {
 				$update = array();
 				$update_params = array();
 				foreach($changedFields as $field) {
-					$fieldColumn = isset($updateFieldNameColumnNameMap[$field]);
-					if(@array_key_exists($fieldColumn, $updateFieldValues)) {
+					if (!array_key_exists($field, $updateFieldNameColumnNameMap)) {
+						continue;
+					}
+
+					$fieldColumn = $updateFieldNameColumnNameMap[$field];
+					if(array_key_exists($fieldColumn, $updateFieldValues)) {
 						array_push($update, $fieldColumn.'=?');
 						array_push($update_params, $updateFieldValues[$fieldColumn]);
 					}
@@ -3135,7 +3139,7 @@ class TrackableObject implements ArrayAccess, IteratorAggregate {
 
 	#[\ReturnTypeWillChange]
 	function offsetSet($key, $value) {
-            if(is_array($value)) $value = !empty($value) && isset($value[0]) ? $value[0] : "" ;
+		if(is_array($value)) $value = empty($value) ? "" : (array_key_exists(0, $value) ? $value[0] : ""); //it is an associative (if array without a key 0) modified to prevent warning of Undefined array key 0 .
 		if($this->tracking && $this->trackingEnabled) {
 			$olderValue = $this->offsetGet($key);
 			// decode_html only expects string
diff --git a/data/VTEntityDelta.php b/data/VTEntityDelta.php
index 11653756f41e2f0ea1a693282c6e855edaf7efa0..305d3ed29454d8d22383261b7724a68d5686c1b7 100644
--- a/data/VTEntityDelta.php
+++ b/data/VTEntityDelta.php
@@ -113,7 +113,10 @@ class VTEntityDelta extends VTEventHandler {
 		if(empty(self::$oldEntity[$moduleName][$recordId])) {
 			return false;
 		}
-		$fieldDelta = isset(self::$entityDelta[$moduleName][$recordId][$fieldName]) ? self::$entityDelta[$moduleName][$recordId][$fieldName] : false;
+		if (!array_key_exists($fieldName, self::$entityDelta[$moduleName][$recordId])) {
+			return false;
+		}
+		$fieldDelta = self::$entityDelta[$moduleName][$recordId][$fieldName];
 		if(is_array($fieldDelta)) {
 			$fieldDelta = array_map('decode_html', $fieldDelta);
 		}
@@ -124,7 +127,7 @@ class VTEntityDelta extends VTEventHandler {
 			$result = $result && ($fieldDelta['currentValue'] === $fieldValue);
 		}
 		return $result;
+		}
+	
 	}
-
-}
-?>
\ No newline at end of file
+?>
diff --git a/include/ListView/ListViewSession.php b/include/ListView/ListViewSession.php
index 7653e3ec63950907d09ca2a9b700342090aa47b7..790aab9424c8c73ab322a76ea79456dd431546aa 100644
--- a/include/ListView/ListViewSession.php
+++ b/include/ListView/ListViewSession.php
@@ -75,6 +75,7 @@ class ListViewSession {
 		}
 		$cv = new CustomView();
 		$viewId = $cv->getViewId($currentModule);
+		$recordNavigationInfo = array();
 		if(!empty($_SESSION[$currentModule.'_DetailView_Navigation'.$viewId])){
 			$recordNavigationInfo = Zend_Json::decode($_SESSION[$currentModule.'_DetailView_Navigation'.$viewId]);
 			$pageNumber =0;
@@ -103,7 +104,7 @@ class ListViewSession {
 			}
 		}
 
-		$list_query = $_SESSION[$currentModule.'_listquery'];
+		$list_query = isset($_SESSION[$currentModule.'_listquery'])?$_SESSION[$currentModule.'_listquery']:'';
 
 		if($reUseData === false && !empty($list_query)){
 			$recordNavigationInfo = array();
diff --git a/include/QueryGenerator/EnhancedQueryGenerator.php b/include/QueryGenerator/EnhancedQueryGenerator.php
index 4d2f44d30fe359c503bc42f401d3954ec4f4184d..74ef79dbaeb87dee4a5a748d34b65a7fc960afe3 100644
--- a/include/QueryGenerator/EnhancedQueryGenerator.php
+++ b/include/QueryGenerator/EnhancedQueryGenerator.php
@@ -578,7 +578,7 @@ class EnhancedQueryGenerator extends QueryGenerator {
 
 		foreach ($tableJoinCondition as $fieldName => $conditionInfo) {
 			foreach ($conditionInfo as $tableName => $condition) {
-				if (!empty($tableList[$tableName])) {
+				if (isset($tableList[$tableName])) {
 					$tableNameAlias = $tableName.'2';
 					$condition = str_replace($tableName, $tableNameAlias, $condition);
 				} else {
diff --git a/include/Webservices/Create.php b/include/Webservices/Create.php
index 369180dc60db9d5858e86185f6376b84e7513bcc..7f5ae9b3e5ac51fd8bfdc82dd3acea48562e60c7 100644
--- a/include/Webservices/Create.php
+++ b/include/Webservices/Create.php
@@ -64,7 +64,7 @@ function vtws_create($elementType, $element, $user) {
 				throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,
 						"Permission to access reference type is denied" . $referenceObject->getEntityName());
 			}
-		} else if ($element[$fieldName] !== NULL) {
+		} else if (array_key_exists($fieldName, $element) && $element[$fieldName] !== NULL) {
 			unset($element[$fieldName]);
 		}
 	}
@@ -88,4 +88,4 @@ function vtws_create($elementType, $element, $user) {
 		return null;
 	}
 }
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/DataTransform.php b/include/Webservices/DataTransform.php
index 7ac0ba0819014d8ec876d4e80777c8c00857df52..06239fa86ec28572f469f7541ea81c1cdaf37ce8 100644
--- a/include/Webservices/DataTransform.php
+++ b/include/Webservices/DataTransform.php
@@ -130,7 +130,7 @@
 					}
 				}
 			}
-			if(isset($row["id"])){
+			if(isset($row["id"]) && $row["id"]){
 				unset($row["id"]);
 			}
 			if(isset($row[$meta->getObectIndexColumn()])){
diff --git a/include/Webservices/EntityMeta.php b/include/Webservices/EntityMeta.php
index 831eb69b533edd238ec5947c7fd4f5ae52ca4ccc..f449054664f0d3f798e89dc7e6f06fc42af0f3b7 100644
--- a/include/Webservices/EntityMeta.php
+++ b/include/Webservices/EntityMeta.php
@@ -8,6 +8,7 @@
  * All Rights Reserved.
  *************************************************************************************/
 
+#[\AllowDynamicProperties]
 abstract class EntityMeta{
 	
 	public static $RETRIEVE = "DetailView";
@@ -276,4 +277,4 @@ abstract class EntityMeta{
 	abstract public function getName($webserviceId);
 	abstract public function isModuleEntity();
 }
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/LineItem/VtigerLineItemMeta.php b/include/Webservices/LineItem/VtigerLineItemMeta.php
index 60cda71cac0c412f8ba8b6b3be372fe91154c063..efc67cd4af5d3a8293c1cc5a8227e7747fcfe744 100644
--- a/include/Webservices/LineItem/VtigerLineItemMeta.php
+++ b/include/Webservices/LineItem/VtigerLineItemMeta.php
@@ -92,7 +92,7 @@ class VtigerLineItemMeta extends VtigerCRMActorMeta {
 		if(in_array($fieldName,$mandatoryFieldList)){
 			$typeOfData = $fieldType.'~M';
 		}else if(($dbField->not_null == 1 && $fieldName != 'incrementondel' 
-				&& $dbField->primary_key != 1) || $dbField->unique_key == 1){
+				&& $dbField->primary_key != 1) || (property_exists($dbField, 'unique_key') && $dbField->unique_key == 1)) {
 			$typeOfData = $fieldType.'~M';
 		}else{
 			$typeOfData = $fieldType.'~O';
@@ -105,4 +105,4 @@ class VtigerLineItemMeta extends VtigerCRMActorMeta {
 	}
 
 }
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/OperationManager.php b/include/Webservices/OperationManager.php
index 949ab248a4951bbc784c03130c3993145b1f3887..d381b48ebe5311022498118dfbf6873fccfe1d50 100644
--- a/include/Webservices/OperationManager.php
+++ b/include/Webservices/OperationManager.php
@@ -9,7 +9,7 @@
  *************************************************************************************/
 	
 	function setBuiltIn($json){
-		$json->useBuiltinEncoderDecoder = true;
+		Zend_Json::$useBuiltinEncoderDecoder = true;
 	}
 	
 	class OperationManager{
@@ -132,10 +132,10 @@
 		}
 		
 		function handleType($type,$value){
-			$result;
-			$value = stripslashes($value);
+			$result = null;
+			$value = $value ? stripslashes($value) : "";
 			$type = strtolower($type);
-			if($this->inParamProcess[$type]){
+			if(isset($this->inParamProcess[$type]) && $this->inParamProcess[$type]){
 				$result = call_user_func($this->inParamProcess[$type],$value);
 			}else{
 				$result = $value;
@@ -210,4 +210,4 @@
 		
 	}
 	
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/Update.php b/include/Webservices/Update.php
index ce008d80a4cfd36bb5692e51df181381af9d3a2f..76d8b85925c63474daff33b553f3fec7cf9726de 100644
--- a/include/Webservices/Update.php
+++ b/include/Webservices/Update.php
@@ -71,7 +71,7 @@
 					throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,
 						"Permission to access reference type is denied ".$referenceObject->getEntityName());
 				}
-			}else if($element[$fieldName] !== NULL){
+			}else if(array_key_exists($fieldName, $element) && $element[$fieldName] !== NULL){
 				unset($element[$fieldName]);
 			}
 		}
@@ -93,4 +93,4 @@
 		return $entity;
 	}
 	
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/Utils.php b/include/Webservices/Utils.php
index 2b0a1f529b2fb7a7817e063f01b78b40a159adbd..08f3ecbb6767230266229012a4166e71ab4ffd01 100644
--- a/include/Webservices/Utils.php
+++ b/include/Webservices/Utils.php
@@ -139,9 +139,10 @@ function getEmailFieldId($meta, $entityId){
 function vtws_getParameter($parameterArray, $paramName,$default=null){
 
 	if (!get_magic_quotes_gpc()) {
-		if(is_array($parameterArray[$paramName])) {
+		$param = null;
+		if(isset($parameterArray[$paramName]) && is_array($parameterArray[$paramName])) {
 			$param = array_map('addslashes', $parameterArray[$paramName]);
-		} else {
+		} else if (isset($parameterArray[$paramName]) && $parameterArray[$paramName]) {
 			$param = addslashes($parameterArray[$paramName]);
 		}
 	} else {
diff --git a/include/Webservices/VTQL_Parser.php b/include/Webservices/VTQL_Parser.php
index e970ebccecc261f7f953a47a56a4e8bad7cdea6d..223fc1a8cf6029d577b3d14ce56b8d0ac91d3cf0 100644
--- a/include/Webservices/VTQL_Parser.php
+++ b/include/Webservices/VTQL_Parser.php
@@ -208,7 +208,7 @@ function buildSelectStmt($sqlDump){
 	$deletedQuery = $meta->getEntityDeletedQuery();
 	$accessControlQuery = $meta->getEntityAccessControlQuery();
 	$this->query = $this->query.' '.$accessControlQuery;
-	if($sqlDump['where_condition']){
+	if(isset($sqlDump['where_condition'])){
 		// ensure init before use
 		if(!isset($sqlDump['where_condition']['operators'])) $sqlDump['where_condition']['operators'] = array();
 
@@ -287,7 +287,7 @@ function buildSelectStmt($sqlDump){
 	
 	$this->query = $this->query.' '.$deletedQuery;
 	
-	if($sqlDump['orderby']){
+	if(isset($sqlDump['orderby'])){
 		$i=0;
 		$this->query = $this->query.' ORDER BY ';
 		foreach($sqlDump['orderby'] as $ind=>$field){
@@ -302,7 +302,7 @@ function buildSelectStmt($sqlDump){
 			$this->query .= ' '.$sqlDump['sortOrder'];
 		}
 	}
-	if($sqlDump['limit']){
+	if(isset($sqlDump['limit'])){
 		$i=0;
 		$offset =false;
 		if(php7_sizeof($sqlDump['limit'])>1){
@@ -1329,7 +1329,7 @@ $this->out['limit'][] = $this->yystack[$this->yyidx + 0]->minor;
 #line 151 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
     function yy_r41(){
 global $adb;
-if(!$this->out['meta']){
+if(!isset($this->out['meta'])){
 $module = $this->out['moduleName'];
 $handler = vtws_getModuleHandlerFromName($module,$this->user);
 $objectMeta = $handler->getMeta();
@@ -1344,7 +1344,7 @@ foreach($this->out['column_list'] as $ind=>$field){
 $columns[] = $fieldcol[$field];
 }
 }
-if($this->out['where_condition']){
+if(isset($this->out['where_condition']) && isset($this->out['where_condition']['column_names'])){
 foreach($this->out['where_condition']['column_names'] as $ind=>$field){
 $columns[] = $fieldcol[$field];
 }
@@ -1362,6 +1362,7 @@ array_push($tables,$tableName);
 $firstTable = $objectMeta->getEntityBaseTable();
 $tabNameIndex = $objectMeta->getEntityTableIndexList();
 $firstIndex = $tabNameIndex[$firstTable];
+if (!isset($this->out['defaultJoinConditons'])) $this->out['defaultJoinConditions'] = '';
 foreach($tables as $ind=>$table){
 if($firstTable!=$table){
 	if(!isset($tabNameIndex[$table]) && $table == "vtiger_crmentity"){
diff --git a/include/Webservices/VtigerActorOperation.php b/include/Webservices/VtigerActorOperation.php
index 6b26288df78cc051439f65722f146535a33f903d..eea1a69f00290caa14fe99eb76b341bb5d91782d 100644
--- a/include/Webservices/VtigerActorOperation.php
+++ b/include/Webservices/VtigerActorOperation.php
@@ -263,7 +263,7 @@ class VtigerActorOperation extends WebserviceEntityOperation {
 			foreach ($moduleFields as $fieldName=>$webserviceField) {
 				array_push($fields,$this->getDescribeFieldArray($webserviceField));
 			}
-			$label = ($app_strings[$this->meta->getObectIndexColumn()])? $app_strings[$this->meta->getObectIndexColumn()]:
+			$label = isset($app_strings[$this->meta->getObectIndexColumn()])? $app_strings[$this->meta->getObectIndexColumn()]:
 				$this->meta->getObectIndexColumn();
 			$this->moduleFields = $fields;
 		}
@@ -276,7 +276,9 @@ class VtigerActorOperation extends WebserviceEntityOperation {
 		if(isset($app_strings[$fieldLabel])){
 			$fieldLabel = $app_strings[$fieldLabel];
 		}
-		if(strcasecmp($webserviceField->getFieldName(),$this->meta->getObectIndexColumn()) === 0){
+		$fieldName = $webserviceField->getFieldName();
+		$fieldColumn = $this->meta->getObectIndexColumn();
+		if($fieldColumn && strcasecmp($fieldName, $fieldColumn) === 0){
 			return $this->getIdField($fieldLabel);
 		}
 		
@@ -334,4 +336,4 @@ class VtigerActorOperation extends WebserviceEntityOperation {
 	}
 
 }
-?>
\ No newline at end of file
+?>
diff --git a/include/Webservices/VtigerCRMObject.php b/include/Webservices/VtigerCRMObject.php
index 45f472ca0812f228239619f40c41cba2274aa98c..e759f429d6046e90e2b81562dd601f171fc14cdc 100644
--- a/include/Webservices/VtigerCRMObject.php
+++ b/include/Webservices/VtigerCRMObject.php
@@ -185,7 +185,7 @@ class VtigerCRMObject{
 		global $adb;
 		$error = false;
 		$adb->startTransaction();
-		DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id,$returnid);
+		DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id,"");
 		$error = $adb->hasFailedTransaction();
 		$adb->completeTransaction();
 		return !$error;
diff --git a/include/Webservices/VtigerCRMObjectMeta.php b/include/Webservices/VtigerCRMObjectMeta.php
index b583b2876d71599d749595ace0da51c548e341b4..09e12f98f3562debc250ad9e4a3aff3ee4ebc16e 100644
--- a/include/Webservices/VtigerCRMObjectMeta.php
+++ b/include/Webservices/VtigerCRMObjectMeta.php
@@ -223,11 +223,12 @@ class VtigerCRMObjectMeta extends EntityMeta {
 	function hasPermission($operation,$webserviceId){
 		
 		$idComponents = vtws_getIdComponents($webserviceId);
-		$id=$idComponents[1];
-		
-		$permitted = isPermitted($this->getTabName(),$operation,$id);
-		if(strcmp($permitted,"yes")===0){
-			return true;
+		$id=$idComponents ? array_pop($idComponents):null;
+		if ($id) {
+			$permitted = isPermitted($this->getTabName(),$operation,$id);
+			if(strcmp($permitted,"yes")===0){
+				return true;
+			}
 		}
 		return false;
 	}
diff --git a/include/Webservices/WebserviceEntityOperation.php b/include/Webservices/WebserviceEntityOperation.php
index 876d2d45d8e158ddf39baeb0995b047aab1dc0f8..89f9f6a3a6c0eb3048f19e432de6c87fba3a0836 100644
--- a/include/Webservices/WebserviceEntityOperation.php
+++ b/include/Webservices/WebserviceEntityOperation.php
@@ -83,7 +83,7 @@ abstract class WebserviceEntityOperation{
 				break;
 			case 'multipicklist':
 			case 'picklist': $typeDetails["picklistValues"] = $webserviceField->getPicklistDetails($webserviceField);
-				$typeDetails['defaultValue'] = $typeDetails["picklistValues"][0]['value'];
+				$typeDetails['defaultValue'] = !empty($typeDetails["picklistValues"]) ? $typeDetails["picklistValues"][0]['value'] : null;
 				break;
 			case 'file': $maxUploadSize = 0;
 				$maxUploadSize = ini_get('upload_max_filesize');
@@ -131,4 +131,4 @@ abstract class WebserviceEntityOperation{
 	
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/include/database/PearDatabase.php b/include/database/PearDatabase.php
index dee0f71f797f8ab0029cc8eae040841c5a4215ea..ea06f9500399e6dc912b3f5ef9494677db0a40df 100644
--- a/include/database/PearDatabase.php
+++ b/include/database/PearDatabase.php
@@ -21,6 +21,7 @@ $logsqltm = Logger::getLogger('SQLTIME');
 
 // Callback class useful to convert PreparedStatement Question Marks to SQL value
 // See function convertPS2Sql in PearDatabase below
+#[\AllowDynamicProperties]
 class PreparedQMark2SqlValue {
 	// Constructor
 	function __construct($vals){
diff --git a/include/events/VTEntityData.inc b/include/events/VTEntityData.inc
index 8a87e4e0f0f1200c77550f3e57996229db00fe5e..d53c8f31a41643bc4a897f1fd780a592ed72aedc 100644
--- a/include/events/VTEntityData.inc
+++ b/include/events/VTEntityData.inc
@@ -112,7 +112,7 @@ class VTEntityData{
 	 * @return The entity id.
 	 */
 	function getId(){
-		return $this->focus->id;
+		return property_exists($this->focus, "id") ? $this->focus->id : null;
 	}
 
 	/**
diff --git a/include/fields/DateTimeField.php b/include/fields/DateTimeField.php
index 21f4d2de793e43b0c9b2a75911e16c9c27b9dbd3..1bfd3f4e08c88675918318333e8622590551ee5e 100644
--- a/include/fields/DateTimeField.php
+++ b/include/fields/DateTimeField.php
@@ -192,7 +192,10 @@ class DateTimeField {
     public static function __convertToUserFormat($date, $format)
     {
         $date = self::convertToInternalFormat($date);
-        list($y, $m, $d) = explode('-', $date[0]);
+		$dates=explode('-', $date[0]);
+		$y=isset($dates[0])?$dates[0]:'';
+		$m=isset($dates[1])?$dates[1]:'';
+		$d=isset($dates[2])?$dates[2]:'';
 
         switch ($format) {
             case 'dd.mm.yyyy':
@@ -278,7 +281,7 @@ class DateTimeField {
 			// create datetime object for given time in source timezone
 			$sourceTimeZone = new DateTimeZone($sourceTimeZoneName);
 			if($time == '24:00') $time = '00:00';
-			$myDateTime = new DateTime($time, $sourceTimeZone);
+			$myDateTime = new DateTime(isset($time) ? $time : '', $sourceTimeZone);
 
 			// convert this to target timezone using the DateTimeZone object
 			$targetTimeZone = new DateTimeZone($targetTimeZoneName);
diff --git a/include/utils/InventoryUtils.php b/include/utils/InventoryUtils.php
index 223bce80a16dacb34084327d793646265c846fcc..2c949c58885ca57a8851199818d9d01ab879e711 100644
--- a/include/utils/InventoryUtils.php
+++ b/include/utils/InventoryUtils.php
@@ -200,7 +200,8 @@ function getProductTaxPercentage($type,$productid,$default='')
 	if($current_user->truncate_trailing_zeros == true) {
 		$taxpercentage = decimalFormat($taxpercentage);
 	}
-	return array('percentage' => $taxpercentage, 'regions' => Zend_Json::decode(html_entity_decode($adb->query_result($res, $i, 'regions'))));
+	$regions=$adb->query_result($res,0, 'regions');
+	return array('percentage' => $taxpercentage, 'regions' => Zend_Json::decode(html_entity_decode(!empty($regions) ? $regions : '')));
 }
 
 /**	Function used to add the history entry in the relevant tables for PO, SO, Quotes and Invoice modules
@@ -383,7 +384,8 @@ function getTaxDetailsForProduct($productid, $available='all')
 			$tax_details[$i]['type']		= $adb->query_result($res, $i, 'type');
 			$tax_details[$i]['regions']		= Zend_Json::decode(html_entity_decode($adb->query_result($res, $i, 'taxregions')));
 			$tax_details[$i]['compoundon']	= Zend_Json::decode(html_entity_decode($adb->query_result($res, $i, 'compoundon')));
-			$tax_details[$i]['productregions']= Zend_Json::decode(html_entity_decode($adb->query_result($res, $i, 'productregions')));
+			$productregions=$adb->query_result($res, $i, 'productregions');
+			$tax_details[$i]['productregions']= Zend_Json::decode(html_entity_decode(!empty($productregions) ? $productregions : ''));
 		}
 	}
 	else
diff --git a/include/utils/ListViewUtils.php b/include/utils/ListViewUtils.php
index 3fb50b958117f3a2afaba49657697d5a2a0bcf2d..9410005905262a1c5d702402e4b5c8cd73549cb6 100755
--- a/include/utils/ListViewUtils.php
+++ b/include/utils/ListViewUtils.php
@@ -674,6 +674,9 @@ function decode_emptyspace_html($str){
 }
 
 function decode_html($str) {
+	// null or blank
+	if (!$str) return $str;
+
 	global $default_charset;
 	// Direct Popup action or Ajax Popup action should be treated the same.
 	if ((isset($_REQUEST['action']) && $_REQUEST['action'] == 'Popup') || (isset($_REQUEST['file']) && $_REQUEST['file'] == 'Popup'))
diff --git a/include/utils/VtlibUtils.php b/include/utils/VtlibUtils.php
index 06e20bfd7f3cb323625a51db7dd988e76c295fc5..24352abb1c1d0268e28d521776d3712e32b76fc9 100644
--- a/include/utils/VtlibUtils.php
+++ b/include/utils/VtlibUtils.php
@@ -815,6 +815,7 @@ function strcasecmp_accents_callback() {
  * @return <String>
  */
 function purifyHtmlEventAttributes($value,$replaceAll = false){
+	if (!$value) return $value;
 	
 	$tmp_markers = $office365ImageMarkers =  array();
 	$value = Vtiger_Functions::strip_base64_data($value,true,$tmp_markers);	
diff --git a/include/utils/utils.php b/include/utils/utils.php
index f4a48468b9a7b2fc7a1541de179f6429606d9f70..f6385811d4c10bf5e3ef026579797ad69764e888 100755
--- a/include/utils/utils.php
+++ b/include/utils/utils.php
@@ -2439,13 +2439,14 @@ function getRecordGroupId($record) {
  * Function to delete record from $_SESSION[$moduleName.'_DetailView_Navigation'.$cvId]
  */
 function deleteRecordFromDetailViewNavigationRecords($recordId, $cvId, $moduleName) {
-	$recordNavigationInfo = Zend_Json::decode(isset($_SESSION[$moduleName . '_DetailView_Navigation' . $cvId]));
-	if (!empty($recordNavigationInfo) && (php7_count($recordNavigationInfo) != 0)) {
+	$cachekey = ($moduleName . '_DetailView_Navigation' . $cvId);
+	$recordNavigationInfo = isset($_SESSION[$cachekey]) ? Zend_Json::decode($_SESSION[$cachekey]) : null;
+	if ($recordNavigationInfo && (php7_count($recordNavigationInfo) != 0)) {
 		foreach ($recordNavigationInfo as $key => $recordIdList) {
 			$recordIdList = array_diff($recordIdList, array($recordId));
 			$recordNavigationInfo[$key] = $recordIdList;
 		}
-		$_SESSION[$moduleName . '_DetailView_Navigation' . $cvId] = Zend_Json::encode($recordNavigationInfo);
+		$_SESSION[$cachekey] = Zend_Json::encode($recordNavigationInfo);
 	}
 }
 
diff --git a/includes/runtime/Viewer.php b/includes/runtime/Viewer.php
index 023499373c9b1f55ec581e040ee2b81ba55dc37d..da4837c96b063646c047fad3306ada6920e86588 100644
--- a/includes/runtime/Viewer.php
+++ b/includes/runtime/Viewer.php
@@ -75,7 +75,7 @@ class Vtiger_Viewer extends Smarty {
 		$classes = array('Vtiger_MenuStructure_Model', 'Users_Privileges_Model', 
 			'Vtiger_Module_Model', 'Settings_MenuEditor_Module_Model', 'Vtiger_Util_Helper', 
 			'ZEND_JSON', 'Zend_Json', 'Zend_JSON', 'ZEND_json',
-			'Vtiger_Theme', 'Users_Record_Model', 'Vtiger_Module_Model', 'Vtiger_Field_Model', 
+			'Vtiger_Theme', 'Users_Record_Model', 'Vtiger_Module_Model', 'Vtiger_Field_Model', 'Vtiger_Record_Model',
 			'Settings_Picklist_Module_Model', 'CustomView_Record_Model', 'Vtiger_Extension_View',
 			'Vtiger_Tag_Model', 'Settings_Vtiger_Module_Model', 'PBXManager_Server_Model',
 			'Vtiger_Functions', 'Users', 'CurrencyField');
@@ -87,7 +87,7 @@ class Vtiger_Viewer extends Smarty {
 
 		$modifiers = array('vtranslate', 'vtlib_isModuleActive', 'vimage_path', 'strstr', 'stripos', 'strpos', 'date', 'vtemplate_path', 'vresource_url', 
 			'decode_html', 'vtlib_purify', 'php7_count', 'getUserFullName', 'array_flip', 'explode', 'trim', 'array_push',
-			'array_map', 'array_key_exists', 'get_class', 'vtlib_array', 'getDuplicatesPreventionMessage', 'htmlentities',
+			'array_map', 'array_key_exists', 'get_class', 'vtlib_array', 'getDuplicatesPreventionMessage', 'htmlentities', 'purifyHtmlEventAttributes',
 			'getCurrencySymbolandCRate', 'mb_substr', 'isPermitted', 'getEntityName', 'function_exists', 'php7_trim', 'php7_htmlentities',
 			'strtolower', 'strtoupper', 'str_replace', 'urlencode', 'getTranslatedCurrencyString', 'getTranslatedString', 'is_object', 'is_numeric',
 			'php7_sizeof', 'method_exists');
diff --git a/layouts/v7/modules/Calendar/uitypes/DateTime.tpl b/layouts/v7/modules/Calendar/uitypes/DateTime.tpl
index 42f245c96013777da976a3b68c2a85e9ca81989a..e4a7d436c43bde4506de229356e07b42556ff17a 100644
--- a/layouts/v7/modules/Calendar/uitypes/DateTime.tpl
+++ b/layouts/v7/modules/Calendar/uitypes/DateTime.tpl
@@ -20,8 +20,10 @@
 {/if}
 
 {assign var=DATE_TIME_VALUE value=$FIELD_MODEL->get('fieldvalue')}
-{assign var=DATE_TIME_COMPONENTS value=explode(' ' ,$DATE_TIME_VALUE)}
-{if !empty($TIME_FIELD)}
+{if isset($DATE_TIME_VALUE)}
+    {assign var=DATE_TIME_COMPONENTS value=explode(' ', $DATE_TIME_VALUE)}
+{/if}
+{if !empty($TIME_FIELD) && isset($DATE_TIME_COMPONENTS)}
 	{assign var=TIME_FIELD value=$TIME_FIELD->set('fieldvalue',$DATE_TIME_COMPONENTS[1])}
 {/if}
 {if $TIME_FIELD}
@@ -30,6 +32,7 @@
 {assign var=DATE_TIME_COMPONENTS value=explode(' ' ,$DATE_TIME_CONVERTED_VALUE)}
 {assign var=DATE_FIELD value=$DATE_FIELD->set('fieldvalue',$DATE_TIME_COMPONENTS[0])}
 {/if}
+
 <div>
 	{include file=vtemplate_path('uitypes/Date.tpl',$MODULE) BLOCK_FIELDS=$BLOCK_FIELDS FIELD_MODEL=$DATE_FIELD}
 </div>
diff --git a/layouts/v7/modules/Documents/CreateDocument.tpl b/layouts/v7/modules/Documents/CreateDocument.tpl
index c865415b90025be5c23f11c803dee230a9d547e4..8f505629f8477b289472a927add31eed13806012 100644
--- a/layouts/v7/modules/Documents/CreateDocument.tpl
+++ b/layouts/v7/modules/Documents/CreateDocument.tpl
@@ -22,9 +22,9 @@
 					<input type="hidden" name="module" value="{$MODULE}" />
 					<input type="hidden" name="action" value="SaveAjax" />
 					<input type="hidden" name="document_source" value="Vtiger" />
-					<input type="hidden" name='service' value="{$STORAGE_SERVICE}" />
+				<input type="hidden" name='service' value="{if isset($STORAGE_SERVICE)}{$STORAGE_SERVICE}{/if}" />
 					<input type="hidden" name='type' value="{$FILE_LOCATION_TYPE}" />
-					{if $RELATION_OPERATOR eq 'true'}
+					{if isset($RELATION_OPERATOR) && $RELATION_OPERATOR eq 'true'}
 						<input type="hidden" name="relationOperation" value="{$RELATION_OPERATOR}" />
 						<input type="hidden" name="sourceModule" value="{$PARENT_MODULE}" />
 						<input type="hidden" name="sourceRecord" value="{$PARENT_ID}" />
diff --git a/layouts/v7/modules/Documents/ModuleHeader.tpl b/layouts/v7/modules/Documents/ModuleHeader.tpl
index 2c3db7718c038360cd4db45c2d3ce908e231ce5c..92ebd4333e60f1c0e56fa73c544bf099a2d91964 100644
--- a/layouts/v7/modules/Documents/ModuleHeader.tpl
+++ b/layouts/v7/modules/Documents/ModuleHeader.tpl
@@ -41,7 +41,7 @@
 					<p  class="current-filter-name filter-name pull-left cursorPointer" title="{$CVNAME}">&nbsp;<span class="fa fa-angle-right pull-left" aria-hidden="true"></span><a  href='{$MODULE_MODEL->getListViewUrl()}&viewname={$VIEWID}'>&nbsp;{$CVNAME}&nbsp;</a> </p>
 				{/if}
 				{assign var=SINGLE_MODULE_NAME value='SINGLE_'|cat:$MODULE}
-				{if $RECORD and $REQ->get('view') eq 'Edit'}
+				{if isset($RECORD) and $REQ->get('view') eq 'Edit'}
 					<p class="current-filter-name filter-name pull-left "><span class="fa fa-angle-right pull-left" aria-hidden="true"></span><a title="{$RECORD->get('label')}">&nbsp;{vtranslate('LBL_EDITING', $MODULE)} : {$RECORD->get('label')}&nbsp;</a></p>
 				{else if $REQ->get('view') eq 'Edit'}
 					<p class="current-filter-name filter-name pull-left "><span class="fa fa-angle-right pull-left" aria-hidden="true"></span><a>&nbsp;{vtranslate('LBL_ADDING_NEW', $MODULE)}&nbsp;</a></p>
diff --git a/layouts/v7/modules/Documents/UploadDocument.tpl b/layouts/v7/modules/Documents/UploadDocument.tpl
index ffd5b66fbd1ece61e4c426571f658593fbfdaae5..15d42c0e99972df64bf420b1f65ea0317e5ec737 100644
--- a/layouts/v7/modules/Documents/UploadDocument.tpl
+++ b/layouts/v7/modules/Documents/UploadDocument.tpl
@@ -23,11 +23,11 @@
 								<input type="hidden" name="module" value="{$MODULE}" />
 								<input type="hidden" name="action" value="SaveAjax" />
 								<input type="hidden" name="document_source" value="Vtiger" />
-								{if $RELATION_OPERATOR eq 'true'}
+								{if isset($RELATION_OPERATOR) && $RELATION_OPERATOR eq 'true'}
 									<input type="hidden" name="relationOperation" value="{$RELATION_OPERATOR}" />
 									<input type="hidden" name="sourceModule" value="{$PARENT_MODULE}" />
 									<input type="hidden" name="sourceRecord" value="{$PARENT_ID}" />
-									{if $RELATION_FIELD_NAME}
+									{if isset($RELATION_FIELD_NAME)}
 										<input type="hidden" name="{$RELATION_FIELD_NAME}" value="{$PARENT_ID}" /> 
 									{/if}
 								{/if}
@@ -47,7 +47,7 @@
 										<div class="fileUploadBtn btn btn-primary">
 											<span><i class="fa fa-laptop"></i> {vtranslate('LBL_SELECT_FILE_FROM_COMPUTER', $MODULE)}</span>
 											{assign var=FIELD_MODEL value=$FIELD_MODELS['filename']}
-											<input type="file" name="{$FIELD_MODEL->getFieldName()}" value="{$FIELD_VALUE}" data-rule-required="true" />
+							<input type="file" name="{$FIELD_MODEL->getFieldName()}" value="{if isset($FIELD_VALUE)}{$FIELD_VALUE}{/if}" data-rule-required="true" />
 										</div>
 										&nbsp;&nbsp;&nbsp;<i class="fa fa-info-circle cursorPointer" data-toggle="tooltip" title="{vtranslate('LBL_MAX_UPLOAD_SIZE', $MODULE)} {$MAX_UPLOAD_LIMIT_MB}{vtranslate('MB', $MODULE)}"></i>
 									</div>
diff --git a/layouts/v7/modules/Documents/partials/SidebarEssentials.tpl b/layouts/v7/modules/Documents/partials/SidebarEssentials.tpl
index 24889f237872717f78dd1c3866180258793cbdb6..29fda74cdb9b329f40cc8abf9da28283c949c7c2 100644
--- a/layouts/v7/modules/Documents/partials/SidebarEssentials.tpl
+++ b/layouts/v7/modules/Documents/partials/SidebarEssentials.tpl
@@ -152,7 +152,7 @@
             <div class="menu-scroller scrollContainer" style="position:relative; top:0; left:0;">
                         <div class="list-menu-content">
                             <div id="listViewTagContainer" class="multiLevelTagList" 
-                            {if $ALL_CUSTOMVIEW_MODEL} data-view-id="{$ALL_CUSTOMVIEW_MODEL->getId()}" {/if}
+                            {if isset($ALL_CUSTOMVIEW_MODEL)} data-view-id="{$ALL_CUSTOMVIEW_MODEL->getId()}" {/if}
                             data-list-tag-count="{Vtiger_Tag_Model::NUM_OF_TAGS_LIST}">
                                 {foreach item=TAG_MODEL from=$TAGS name=tagCounter}
                                     {assign var=TAG_LABEL value=$TAG_MODEL->getName()}
diff --git a/layouts/v7/modules/Events/uitypes/DateTime.tpl b/layouts/v7/modules/Events/uitypes/DateTime.tpl
index 16648420cd248b14687ad4d9f2a80ca329a6db7f..1c766bbe1b7553659a45fb2c77c76c47a836e8f2 100644
--- a/layouts/v7/modules/Events/uitypes/DateTime.tpl
+++ b/layouts/v7/modules/Events/uitypes/DateTime.tpl
@@ -21,13 +21,16 @@
 {/if}
 
 {assign var=DATE_TIME_VALUE value=$FIELD_MODEL->get('fieldvalue')}
+{if isset($DATE_TIME_VALUE)}
 {assign var=DATE_TIME_COMPONENTS value=explode(' ' ,$DATE_TIME_VALUE)}
 {assign var=TIME_FIELD value=$TIME_FIELD->set('fieldvalue',$DATE_TIME_COMPONENTS[1])}
-
+{/if}
 {* Set the date after converting with repsect to timezone *}
 {assign var=DATE_TIME_CONVERTED_VALUE value=DateTimeField::convertToUserTimeZone($DATE_TIME_VALUE)->format('Y-m-d H:i:s')}
+{if isset($DATE_TIME_CONVERTED_VALUE)}
 {assign var=DATE_TIME_COMPONENTS value=explode(' ' ,$DATE_TIME_CONVERTED_VALUE)}
 {assign var=DATE_FIELD value=$DATE_FIELD->set('fieldvalue',$DATE_TIME_COMPONENTS[0])}
+{/if}
 
 <div>
 	{include file=vtemplate_path('uitypes/Date.tpl',$MODULE) BLOCK_FIELDS=$BLOCK_FIELDS FIELD_MODEL=$DATE_FIELD}
diff --git a/layouts/v7/modules/Vtiger/Comment.tpl b/layouts/v7/modules/Vtiger/Comment.tpl
index 56df0f3668a50450c91de5fd1be0ef6ed84cc186..7234907a5b50f1333274d4a7b2fc4a29c62baeb1 100644
--- a/layouts/v7/modules/Vtiger/Comment.tpl
+++ b/layouts/v7/modules/Vtiger/Comment.tpl
@@ -36,7 +36,7 @@
 									<span class="creatorName" style="color:blue">
 										{$CREATOR_NAME}
 									</span>&nbsp;&nbsp;
-									{if $ROLLUP_STATUS and $COMMENT->get('module') ne $MODULE_NAME}
+									{if isset ($ROLLUP_STATUS) && $ROLLUP_STATUS and $COMMENT->get('module') ne $MODULE_NAME}
 										{assign var=SINGULR_MODULE value='SINGLE_'|cat:$COMMENT->get('module')}
 										{assign var=ENTITY_NAME value=getEntityName($COMMENT->get('module'), array($COMMENT->get('related_to')))}
 										<span class="text-muted">
@@ -69,12 +69,12 @@
 									<br>
 									<div class="commentActionsContainer">
 										<span class="commentActions">
-											{if $CHILDS_ROOT_PARENT_MODEL}
+											{if isset ($CHILDS_ROOT_PARENT_MODEL) && $CHILDS_ROOT_PARENT_MODEL}
 												{assign var=CHILDS_ROOT_PARENT_ID value=$CHILDS_ROOT_PARENT_MODEL->getId()}
 											{/if}
 
 											{if $COMMENTS_MODULE_MODEL->isPermitted('EditView')}
-												{if $CHILDS_ROOT_PARENT_MODEL}
+												{if isset ($CHILDS_ROOT_PARENT_MODEL) && $CHILDS_ROOT_PARENT_MODEL}
 													{assign var=CHILDS_ROOT_PARENT_ID value=$CHILDS_ROOT_PARENT_MODEL->getId()}
 												{/if}
 												<a href="javascript:void(0);" class="cursorPointer replyComment feedback" style="color: blue;">
@@ -89,7 +89,7 @@
 											{/if}
 
 											{assign var=CHILD_COMMENTS_COUNT value=$COMMENT->getChildCommentsCount()}
-											{if $CHILD_COMMENTS_MODEL neq null and ($CHILDS_ROOT_PARENT_ID neq $PARENT_COMMENT_ID)}
+											{if $CHILD_COMMENTS_MODEL neq null and (isset($CHILDS_ROOT_PARENT_ID)&& $CHILDS_ROOT_PARENT_ID neq $PARENT_COMMENT_ID)}
 												{if $COMMENTS_MODULE_MODEL->isPermitted('EditView')}&nbsp;&nbsp;&nbsp;{/if}
 												<span class="viewThreadBlock" data-child-comments-count="{$CHILD_COMMENTS_COUNT}">
 													<a href="javascript:void(0)" class="cursorPointer viewThread" style="color: blue;">
@@ -101,7 +101,7 @@
 														<span class="childCommentsCount">{$CHILD_COMMENTS_COUNT}</span>&nbsp;{if $CHILD_COMMENTS_COUNT eq 1}{vtranslate('LBL_REPLY',$MODULE_NAME)}{else}{vtranslate('LBL_REPLIES',$MODULE_NAME)}{/if}&nbsp;
 													</a>
 												</span>
-											{elseif $CHILD_COMMENTS_MODEL neq null and ($CHILDS_ROOT_PARENT_ID eq $PARENT_COMMENT_ID)}
+											{elseif $CHILD_COMMENTS_MODEL neq null and (isset($CHILDS_ROOT_PARENT_ID)&& $CHILDS_ROOT_PARENT_ID eq $PARENT_COMMENT_ID)}
 												{if $COMMENTS_MODULE_MODEL->isPermitted('EditView')}&nbsp;&nbsp;&nbsp;{/if}
 												<span class="viewThreadBlock" data-child-comments-count="{$CHILD_COMMENTS_COUNT}" style="display:none;">
 													<a href="javascript:void(0)" class="cursorPointer viewThread" style="color: blue;">
diff --git a/layouts/v7/modules/Vtiger/CommentsList.tpl b/layouts/v7/modules/Vtiger/CommentsList.tpl
index 2d7764f9d2c10ef0cd010f86c5feca7fd8aa86b7..25bb39f92e8c10394bc1405ea8d3452047027c8d 100644
--- a/layouts/v7/modules/Vtiger/CommentsList.tpl
+++ b/layouts/v7/modules/Vtiger/CommentsList.tpl
@@ -13,7 +13,7 @@
 
 {if !empty($PARENT_COMMENTS)}
 	<ul class="unstyled">
-		{if $CURRENT_COMMENT}
+		{if isset($CURRENT_COMMENT) && $CURRENT_COMMENT}
 			{assign var=CHILDS_ROOT_PARENT_MODEL value=$CURRENT_COMMENT}
 			{assign var=CURRENT_COMMENT_PARENT_MODEL value=$CURRENT_COMMENT->getParentCommentModel()}
 			{while $CURRENT_COMMENT_PARENT_MODEL neq false}
@@ -30,7 +30,7 @@
 				<li class="commentDetails">
 					{include file='Comment.tpl'|@vtemplate_path COMMENT=$COMMENT COMMENT_MODULE_MODEL=$COMMENTS_MODULE_MODEL}
 
-					{if $CHILDS_ROOT_PARENT_MODEL}
+					{if isset($CHILDS_ROOT_PARENT_MODEL) && $CHILDS_ROOT_PARENT_MODEL}
 						{if $CHILDS_ROOT_PARENT_MODEL->getId() eq $PARENT_COMMENT_ID}		
 							{assign var=CHILD_COMMENTS_MODEL value=$CHILDS_ROOT_PARENT_MODEL->getChildComments()}
 							{include file='CommentsListIteration.tpl'|@vtemplate_path CHILD_COMMENTS_MODEL=$CHILD_COMMENTS_MODEL}
diff --git a/layouts/v7/modules/Vtiger/DetailViewBlockView.tpl b/layouts/v7/modules/Vtiger/DetailViewBlockView.tpl
index 5d439bb7384f957744f3f13496110ac76d347726..0c2673d2662a245aa3ae0f683cc13ee8993452ae 100644
--- a/layouts/v7/modules/Vtiger/DetailViewBlockView.tpl
+++ b/layouts/v7/modules/Vtiger/DetailViewBlockView.tpl
@@ -18,9 +18,7 @@
 		<div class="block block_{$BLOCK_LABEL_KEY}" data-block="{$BLOCK_LABEL_KEY}" data-blockid="{$BLOCK_LIST[$BLOCK_LABEL_KEY]->get('id')}">
 			{assign var=IS_HIDDEN value=$BLOCK->isHidden()}
 			{assign var=WIDTHTYPE value=$USER_MODEL->get('rowheight')}
-			{if !empty($DAY_STARTS)}
-				<input type=hidden name="timeFormatOptions" data-value='{$DAY_STARTS}' />
-			{/if}
+		<input type=hidden name="timeFormatOptions" data-value='{if isset($DAY_STARTS)}{$DAY_STARTS}{else}""{/if}' />
 			<div>
 				<h4 class="textOverflowEllipsis maxWidth50">
 					<img class="cursorPointer alignMiddle blockToggle {if !($IS_HIDDEN)} hide {/if}" src="{vimage_path('arrowRight.png')}" data-mode="hide" data-id={$BLOCK_LIST[$BLOCK_LABEL_KEY]->get('id')}>
diff --git a/layouts/v7/modules/Vtiger/ListViewActions.tpl b/layouts/v7/modules/Vtiger/ListViewActions.tpl
index 3dc128c91b0ee8954f90e1567d9117eb5cfd269f..17a4d2330aae7ac915b01bad2197ff28725f5002 100644
--- a/layouts/v7/modules/Vtiger/ListViewActions.tpl
+++ b/layouts/v7/modules/Vtiger/ListViewActions.tpl
@@ -39,7 +39,7 @@
                         <i class="fa fa-trash"></i>
                     </button>
                 {/if}
-                {if $commentAction}
+                {if isset($commentAction)}
                     <button type="button" class="btn btn-default" id="{$MODULE}_listView_massAction_{$commentAction->getLabel()}" 
                             onclick="Vtiger_List_Js.triggerMassAction('{$commentAction->getUrl()}')" title="{vtranslate('LBL_COMMENT', $MODULE)}" disabled="disabled">
                         <i class="fa fa-comment"></i>
@@ -98,7 +98,7 @@
                             {if $PRINT_TEMPLATE}
                                 <li class="hide"><a id="{$MODULE}_listView_advancedAction_{Vtiger_Util_Helper::replaceSpaceWithUnderScores($PRINT_TEMPLATE->getLabel())}" {if stripos($PRINT_TEMPLATE->getUrl(), 'javascript:')===0} href="javascript:void(0);" onclick='{$PRINT_TEMPLATE->getUrl()|substr:strlen("javascript:")};'{else} href='{$PRINT_TEMPLATE->getUrl()}' {/if}>{vtranslate($PRINT_TEMPLATE->getLabel(), $MODULE)}</a></li>
                             {/if}
-                            {if $FIND_DUPLICATES_EXISTS}
+                            {if isset($FIND_DUPLICATES_EXISTS)}
                                 <li class="hide"><a id="{$MODULE}_listView_advancedAction_MERGE_RECORD"  href="javascript:void(0);" onclick='Vtiger_List_Js.triggerMergeRecord()'>{vtranslate('LBL_MERGE_SELECTED_RECORDS', $MODULE)}</a></li>
                             {/if}
                             {foreach item=LISTVIEW_ADVANCEDACTIONS from=$LISTVIEW_LINKS['LISTVIEW']}
diff --git a/layouts/v7/modules/Vtiger/ListViewContents.tpl b/layouts/v7/modules/Vtiger/ListViewContents.tpl
index dba24cbb1f69ad44baecbfa359326f4f2046d843..2cea24ff8c318058e8254e16e21c942cbedac575 100644
--- a/layouts/v7/modules/Vtiger/ListViewContents.tpl
+++ b/layouts/v7/modules/Vtiger/ListViewContents.tpl
@@ -11,6 +11,10 @@
 {* START YOUR IMPLEMENTATION FROM BELOW. Use {debug} for information *}
 {include file="PicklistColorMap.tpl"|vtemplate_path:$MODULE}
 
+{if !isset($SELECTED_MENU_CATEGORY)}
+	{assign var=SELECTED_MENU_CATEGORY value=""}
+{/if}
+
 <div class="col-sm-12 col-xs-12 ">
 	{if $MODULE neq 'EmailTemplates' && $SEARCH_MODE_RESULTS neq true}
 		{assign var=LEFTPANELHIDE value=$CURRENT_USER_MODEL->get('leftpanelhide')}
diff --git a/layouts/v7/modules/Vtiger/OverlayDetailView.tpl b/layouts/v7/modules/Vtiger/OverlayDetailView.tpl
index 1bd8d59879cfc2c5517cd8e2d82334929615b744..26add60a04b2130f36116fecd4ecc82a93e3c629 100644
--- a/layouts/v7/modules/Vtiger/OverlayDetailView.tpl
+++ b/layouts/v7/modules/Vtiger/OverlayDetailView.tpl
@@ -54,11 +54,13 @@
                 <div class="clearfix">
                     <div class = "btn-group">
                         <button class="btn btn-default fullDetailsButton" onclick="window.location.href = '{$RECORD->getFullDetailViewUrl()}&app={$SELECTED_MENU_CATEGORY}'">{vtranslate('LBL_DETAILS',$MODULE_NAME)}</button>
-						{foreach item=DETAIL_VIEW_BASIC_LINK from=$DETAILVIEW_LINKS['DETAILVIEWBASIC']}
-							{if $DETAIL_VIEW_BASIC_LINK && $DETAIL_VIEW_BASIC_LINK->getLabel() == 'LBL_EDIT'}
-								<button class="btn btn-default editRelatedRecord" value = "{$RECORD->getEditViewUrl()}">{vtranslate('LBL_EDIT',$MODULE_NAME)}</button>
-							{/if}
-						{/foreach}
+                        {if isset($DETAILVIEW_LINKS)}
+                            {foreach item=DETAIL_VIEW_BASIC_LINK from=$DETAILVIEW_LINKS['DETAILVIEWBASIC']}
+                                {if $DETAIL_VIEW_BASIC_LINK && $DETAIL_VIEW_BASIC_LINK->getLabel() == 'LBL_EDIT'}
+                                    <button class="btn btn-default editRelatedRecord" value = "{$RECORD->getEditViewUrl()}">{vtranslate('LBL_EDIT',$MODULE_NAME)}</button>
+                                {/if}
+                            {/foreach}  
+                        {/if}	
                     </div> 
                     <div class="pull-right " >
                         <button type="button" class="close" aria-label="Close" data-dismiss="modal">
diff --git a/layouts/v7/modules/Vtiger/OverlayEditView.tpl b/layouts/v7/modules/Vtiger/OverlayEditView.tpl
index 66c58bdf9ae297d8d5d72671695e90f43da33ddf..e7790c9f4e2524857858ba5ebce467601ce6b506 100644
--- a/layouts/v7/modules/Vtiger/OverlayEditView.tpl
+++ b/layouts/v7/modules/Vtiger/OverlayEditView.tpl
@@ -13,7 +13,12 @@
 
 <div class='fc-overlay-modal modal-content overlayEdit'>
     <div class="overlayHeader">
-        {assign var=TITLE value="{vtranslate('LBL_EDITING', $MODULE)} {vtranslate($SINGLE_MODULE_NAME, $MODULE)} - {$RECORD_STRUCTURE_MODEL->getRecordName()}"} 
+    {if isset($SINGLE_MODULE_NAME)}
+        {assign var="singleModuleName" value=$SINGLE_MODULE_NAME}
+      {else}
+        {assign var="singleModuleName" value=""}
+      {/if}
+          {assign var=TITLE value="{vtranslate('LBL_EDITING', $MODULE)} {vtranslate($singleModuleName, $MODULE)} - {$RECORD_STRUCTURE_MODEL->getRecordName()}"}  
         {include file="ModalHeader.tpl"|vtemplate_path:$MODULE}
     </div>
     <form class="form-horizontal recordEditView" id="EditView" name="edit" method="post" action="index.php" enctype="multipart/form-data">
diff --git a/layouts/v7/modules/Vtiger/RecentActivities.tpl b/layouts/v7/modules/Vtiger/RecentActivities.tpl
index a3351c2a4aa28627f90ea0c8b97b8f23d82aea45..7b29b717cb57aaf8d89ceb79fd0e4de90c17fa69 100644
--- a/layouts/v7/modules/Vtiger/RecentActivities.tpl
+++ b/layouts/v7/modules/Vtiger/RecentActivities.tpl
@@ -94,8 +94,13 @@
                                                 {assign var=PRE_DISPLAY_VALUE value=$TIME_PRE_DISPLAY_VALUE}
                                                 {assign var=POST_DISPLAY_VALUE value=$TIME_POST_DISPLAY_VALUE}
                                             {/if}
+                                            {if isset($TIME_PRE_DISPLAY_VALUE)}
+                                                {assign var=PRE_DISPLAY_TITLE value=$TIME_PRE_DISPLAY_VALUE}
+
+                                            {else}
+                                                {assign var=PRE_DISPLAY_TITLE value=''}
+                                            {/if}
                                             
-                                            {assign var=PRE_DISPLAY_TITLE value=$TIME_PRE_DISPLAY_VALUE}
                                             
                                             
                                             {if $FIELDMODEL && $FIELDMODEL->getFieldInstance() && $FIELDMODEL->getFieldInstance()->isViewable() && $FIELDMODEL->getFieldInstance()->getDisplayType() neq '5'}
diff --git a/layouts/v7/modules/Vtiger/partials/EditViewContents.tpl b/layouts/v7/modules/Vtiger/partials/EditViewContents.tpl
index 004763b240c58dd0b8dd146172bed0aa0d35c759..106011ffc94504b8abd9752caed8d2b284d22eec 100644
--- a/layouts/v7/modules/Vtiger/partials/EditViewContents.tpl
+++ b/layouts/v7/modules/Vtiger/partials/EditViewContents.tpl
@@ -14,7 +14,7 @@
 	{/if}
 
 	<div name='editContent'>
-		{if $DUPLICATE_RECORDS}
+		{if isset($DUPLICATE_RECORDS) && $DUPLICATE_RECORDS}
 			<div class="fieldBlockContainer duplicationMessageContainer">
 				<div class="duplicationMessageHeader"><b>{vtranslate('LBL_DUPLICATES_DETECTED', $MODULE)}</b></div>
 				<div>{getDuplicatesPreventionMessage($MODULE, $DUPLICATE_RECORDS)}</div>
diff --git a/layouts/v7/modules/Vtiger/partials/RelatedListHeader.tpl b/layouts/v7/modules/Vtiger/partials/RelatedListHeader.tpl
index 36b24a959db984e895baa56c66266f889420bd6e..3cef97ed0fbdcf3b969d89d887f91f87b25c290b 100644
--- a/layouts/v7/modules/Vtiger/partials/RelatedListHeader.tpl
+++ b/layouts/v7/modules/Vtiger/partials/RelatedListHeader.tpl
@@ -38,7 +38,7 @@
 									{if $IS_SELECT_BUTTON eq true} data-moduleName="{$RELATED_LINK->get('_module')->get('name')}" {/if}
 									{if ($RELATED_LINK->isPageLoadLink())}
 										{if $RELATION_FIELD} data-name="{$RELATION_FIELD->getName()}" {/if}
-										data-url="{$RELATED_LINK->getUrl()}{if $SELECTED_MENU_CATEGORY}&app={$SELECTED_MENU_CATEGORY}{/if}"
+										data-url="{$RELATED_LINK->getUrl()}{if isset($SELECTED_MENU_CATEGORY)}&app={$SELECTED_MENU_CATEGORY}{/if}"
 									{/if}
 									>{if $IS_SELECT_BUTTON eq false}<i class="fa fa-plus"></i>&nbsp;{/if}&nbsp;{$RELATED_LINK->getLabel()}</button>
 							{/if}
diff --git a/layouts/v7/modules/Vtiger/uitypes/Date.tpl b/layouts/v7/modules/Vtiger/uitypes/Date.tpl
index 3d0f6c9ae3ea5ad84db66e8f59834801c323cc29..3aadfbdda43ccd9c0cd7dac134ed8952239c27c3 100644
--- a/layouts/v7/modules/Vtiger/uitypes/Date.tpl
+++ b/layouts/v7/modules/Vtiger/uitypes/Date.tpl
@@ -13,7 +13,7 @@
 {assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()}
 {assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
 {assign var="dateFormat" value=$USER_MODEL->get('date_format')}
-{if (!$FIELD_NAME)}
+{if (!isset($FIELD_NAME))}
   {assign var="FIELD_NAME" value=$FIELD_MODEL->getFieldName()}
 {/if}
 <div class="input-group inputElement" style="margin-bottom: 3px">
diff --git a/layouts/v7/modules/Vtiger/uitypes/ProductTax.tpl b/layouts/v7/modules/Vtiger/uitypes/ProductTax.tpl
index ff8f81c875685b5dbbf5543788e568079b4f468a..5c69cf1271450ef8c0beb0585e7be7fb2260e090 100644
--- a/layouts/v7/modules/Vtiger/uitypes/ProductTax.tpl
+++ b/layouts/v7/modules/Vtiger/uitypes/ProductTax.tpl
@@ -21,7 +21,7 @@
 		{/if}
 
 		{if $tax_count gt 1}
-			<td class="fieldLabel alignMiddle{if $PULL_RIGHT} pull-right{/if}">{*pull-right required in Quick create only*}
+			<td class="fieldLabel alignMiddle{if isset($PULL_RIGHT) && $PULL_RIGHT} pull-right{/if}">{*pull-right required in Quick create only*}
 				<label class="">
 				{/if}
 				<span class="taxLabel alignBottom">{vtranslate($tax.taxlabel, $MODULE)}<span class="paddingLeft10px">(%)</span></span>
diff --git a/layouts/v7/modules/Vtiger/uitypes/String.tpl b/layouts/v7/modules/Vtiger/uitypes/String.tpl
index 9ec1f6bea6865e942c03a9f0b8f7f2d158dac0b3..f5facd92be175a7245a05dea9a610297c5de44a3 100644
--- a/layouts/v7/modules/Vtiger/uitypes/String.tpl
+++ b/layouts/v7/modules/Vtiger/uitypes/String.tpl
@@ -13,7 +13,7 @@
 	{assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()}
 	{assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
 
-	{if (!$FIELD_NAME)}
+	{if !isset($FIELD_NAME)}
 		{assign var="FIELD_NAME" value=$FIELD_MODEL->getFieldName()}
 	{/if}
 	<input id="{$MODULE}_editView_fieldName_{$FIELD_NAME}" type="text" data-fieldname="{$FIELD_NAME}" data-fieldtype="string" class="inputElement {if $FIELD_MODEL->isNameField()}nameField{/if}" name="{$FIELD_NAME}" value="{decode_html($FIELD_MODEL->get('fieldvalue'))|php7_htmlentities}"
diff --git a/layouts/v7/modules/Vtiger/uitypes/Text.tpl b/layouts/v7/modules/Vtiger/uitypes/Text.tpl
index 9e051d16228add86bde4eacaccd1b17588bd6884..63ce500cf0980aaf1bbe61a6ba68f32141c1ab4c 100644
--- a/layouts/v7/modules/Vtiger/uitypes/Text.tpl
+++ b/layouts/v7/modules/Vtiger/uitypes/Text.tpl
@@ -12,7 +12,7 @@
 {strip}
 {assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()}
 {assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
-{if (!$FIELD_NAME)}
+{if !isset($FIELD_NAME)}
   {assign var="FIELD_NAME" value=$FIELD_MODEL->getFieldName()}
 {/if}
 {if $FIELD_MODEL->get('uitype') eq '19' || $FIELD_MODEL->get('uitype') eq '20'}
diff --git a/layouts/vlayout/modules/Vtiger/uitypes/Date.tpl b/layouts/vlayout/modules/Vtiger/uitypes/Date.tpl
index 50fa8504be4220a2bce435ae461656bcb893d4ad..7e75b6d1a2602c27e6dff3dcb2faff3c3db53e36 100644
--- a/layouts/vlayout/modules/Vtiger/uitypes/Date.tpl
+++ b/layouts/vlayout/modules/Vtiger/uitypes/Date.tpl
@@ -17,7 +17,7 @@
 	<div class="span12 row-fluid date">
 		{assign var=FIELD_NAME value=$FIELD_MODEL->get('name')}
 		<input id="{$MODULE}_editView_fieldName_{$FIELD_NAME}" type="text" class="dateField" name="{$FIELD_MODEL->getFieldName()}" data-date-format="{$dateFormat}"
-			type="text" value="{$FIELD_MODEL->getEditViewDisplayValue($FIELD_MODEL->get('fieldvalue'))}" data-validation-engine="validate[{if $FIELD_MODEL->isMandatory() eq true} required,{/if}funcCall[Vtiger_Base_Validator_Js.invokeValidation]]"   {if !empty($SPECIAL_VALIDATOR)}data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}'{/if} data-fieldinfo='{$FIELD_INFO}' 
+			type="text"  data-validation-engine="validate[{if $FIELD_MODEL->isMandatory() eq true} required,{/if}funcCall[Vtiger_Base_Validator_Js.invokeValidation]]"   {if !empty($SPECIAL_VALIDATOR)}data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}'{/if} data-fieldinfo='{$FIELD_INFO}' 
              {if $MODE eq 'edit' && $FIELD_NAME eq 'due_date'} data-user-changed-time="true" {/if} />
 		<span class="add-on"><i class="icon-calendar"></i></span>
 	</div>
diff --git a/modules/Calendar/Activity.php b/modules/Calendar/Activity.php
index d92db4f65f1b9c58e185afb82a9375e1708efed2..ad8608b928393047f663e3109fded1ef76d0b804 100644
--- a/modules/Calendar/Activity.php
+++ b/modules/Calendar/Activity.php
@@ -145,7 +145,7 @@ class Activity extends CRMEntity {
 				}
 			}
 			$adb->pquery($sql, $params);
-		} else if ($_REQUEST['contactidlist'] == '' && $insertion_mode == "edit") {
+		} else if (isset($_REQUEST['contactidlist'] ) && $_REQUEST['contactidlist'] == '' && $insertion_mode == "edit") {
 			$adb->pquery('DELETE FROM vtiger_cntactivityrel WHERE activityid = ?', array($recordId));
 		}
 
@@ -180,7 +180,7 @@ class Activity extends CRMEntity {
 			$this->insertIntoReminderTable('vtiger_activity_reminder',$module,"");
 
 		//Handling for invitees
-			$selected_users_string =  $_REQUEST['inviteesid'];
+			$selected_users_string = isset($_REQUEST['inviteesid'])?$_REQUEST['inviteesid']:'';
 			$invitees_array = explode(';',$selected_users_string);
 			$this->insertIntoInviteeTable($module,$invitees_array);
 
@@ -242,7 +242,7 @@ class Activity extends CRMEntity {
 			} else {
 				$status = 1;
 			}
-
+			$callback_query='';
 			if(isset($reminderid)) {
 				$callback_query = "UPDATE vtiger_activity_reminder_popup set status = ?, date_start = ?, time_start = ? WHERE reminderid = ?";
 				$callback_params = array($status, $cbdate, $cbtime, $reminderid);
@@ -386,7 +386,7 @@ function insertIntoRecurringTable(& $recurObj)
 	function insertIntoInviteeTable($module,$invitees_array)
 	{
 		global $log,$adb;
-		$log->debug("Entering insertIntoInviteeTable(".$module.",".$invitees_array.") method ...");
+		$log->debug("Entering insertIntoInviteeTable(".$module.",".implode(',',$invitees_array).") method ...");
 		if($this->mode == 'edit'){
 			$sql = "DELETE FROM vtiger_invitees WHERE activityid=?";
 			$adb->pquery($sql, array($this->id));
diff --git a/modules/Calendar/RepeatEvents.php b/modules/Calendar/RepeatEvents.php
index 4219cc9a4edba0b6f078d864a33476a3edaf0d55..d2d6409e8071adf49e1c48981d61cdfa474abc9b 100644
--- a/modules/Calendar/RepeatEvents.php
+++ b/modules/Calendar/RepeatEvents.php
@@ -394,7 +394,7 @@ class Calendar_RepeatEvents {
 	}
 	
     static function checkRecurringDataChanged($recurObjRequest, $recurObjDb) {
-        if(($recurObjRequest->recur_type == $recurObjDb->recur_type) && ($recurObjRequest->recur_freq == $recurObjDb->recur_freq)
+        if(($recurObjRequest && $recurObjDb) && ($recurObjRequest->recur_type == $recurObjDb->recur_type) && ($recurObjRequest->recur_freq == $recurObjDb->recur_freq)
                 && ($recurObjRequest->recurringdates[0] == $recurObjDb->recurringdates[0]) && ($recurObjRequest->recurringenddate == $recurObjDb->recurringenddate)
                 && ($recurObjRequest->dayofweek_to_rpt == $recurObjDb->dayofweek_to_rpt) && ($recurObjRequest->repeat_monthby == $recurObjDb->repeat_monthby)
                 && ($recurObjRequest->rptmonth_datevalue == $recurObjDb->rptmonth_datevalue) && ($recurObjRequest->rptmonth_daytype == $recurObjDb->rptmonth_daytype)) {
diff --git a/modules/Calendar/models/Field.php b/modules/Calendar/models/Field.php
index cb81df21944800b02ad1010760b1f81a211bc105..880f40678e7d4415c54fbe8cc234efcc07d22427 100644
--- a/modules/Calendar/models/Field.php
+++ b/modules/Calendar/models/Field.php
@@ -80,6 +80,7 @@ class Calendar_Field_Model extends Vtiger_Field_Model {
 			} else if ($this->getName() == 'due_date') {
 				$dateTimeValue = $value . ' '. $recordInstance->get('time_end');
 				$value = $this->getUITypeModel()->getDisplayValue($dateTimeValue);
+				if (substr_count($value, ' ') == 0) $value .= ' '; // if $startTime is missing then added a space to it to avoid undefined array key warning.
 				list($startDate, $startTime) = explode(' ', $value);
 
 				$currentUser = Users_Record_Model::getCurrentUserModel();
diff --git a/modules/Calendar/models/Record.php b/modules/Calendar/models/Record.php
index d13c3c4ba7320c12ca4e9cd774b9d005efdb8937..d58e2fa7fbf06ca8ee1520650265b50bb19fcebc 100644
--- a/modules/Calendar/models/Record.php
+++ b/modules/Calendar/models/Record.php
@@ -99,7 +99,7 @@ class Calendar_Record_Model extends Vtiger_Record_Model {
 	function save() {
 		//Time should changed to 24hrs format
 		$_REQUEST['time_start'] = Vtiger_Time_UIType::getTimeValueWithSeconds($_REQUEST['time_start']);
-		$_REQUEST['time_end'] = Vtiger_Time_UIType::getTimeValueWithSeconds($_REQUEST['time_end']);
+		$_REQUEST['time_end'] = isset($_REQUEST['time_end']) ? Vtiger_Time_UIType::getTimeValueWithSeconds($_REQUEST['time_end']): '';
 		parent::save();
 	}
 	
diff --git a/modules/Calendar/uitypes/Time.php b/modules/Calendar/uitypes/Time.php
index afd349279abeefb3e597e7d9ee1d354f061a88da..04f337da83affa7b71ca36c4124432178bfce174 100644
--- a/modules/Calendar/uitypes/Time.php
+++ b/modules/Calendar/uitypes/Time.php
@@ -36,8 +36,8 @@ class Calendar_Time_UIType extends Vtiger_Time_UIType {
 	 * @return <Vtiger_Time_UIType> - getTimeValue 
 	 */
 	public function getDisplayTimeDifferenceValue($fieldName, $value){
-		$userModel = Users_Privileges_Model::getCurrentUserModel();
-		$date = new DateTime($value);
+		$userModel = Users_Privileges_Model::getCurrentUserModel();	
+		$date = new DateTime(isset($value) ? $value: '');
 		
 		//No need to set the time zone as DateTimeField::getDisplayTime API is already doing this
 		/*if(empty($value)) {
diff --git a/modules/Calendar/views/Detail.php b/modules/Calendar/views/Detail.php
index 186583fb7e952add457393681224bf2da3f65b07..d55a45ada04289ca2b61bac6c964923562098a4e 100644
--- a/modules/Calendar/views/Detail.php
+++ b/modules/Calendar/views/Detail.php
@@ -144,7 +144,6 @@ class Calendar_Detail_View extends Vtiger_Detail_View {
 			$relatedContacts = array();
 		}
 
-
 		$viewer = $this->getViewer($request);
 		$viewer->assign('RECORD', $recordModel);
 		$viewer->assign('RECORD_STRUCTURE', $structuredValues);
@@ -152,10 +151,13 @@ class Calendar_Detail_View extends Vtiger_Detail_View {
 		$viewer->assign('RECORD_STRUCTURE_MODEL', $recordStrucure);
 		$viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
 		$viewer->assign('MODULE_NAME', $moduleName);
+		$viewer->assign('DAY_STARTS','');
 		$viewer->assign('RELATED_CONTACTS', $relatedContacts);
 		$viewer->assign('IS_AJAX_ENABLED', $this->isAjaxEnabled($recordModel));
 		$viewer->assign('RECURRING_INFORMATION', $recordModel->getRecurringDetails());
 
+		$appName = !empty($request->get('app'))?$request->get('app'):'';
+		$viewer->assign('SELECTED_MENU_CATEGORY',$appName);
 		$picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName);
 		$viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Vtiger_Functions::jsonEncode($picklistDependencyDatasource));
 
diff --git a/modules/Documents/Documents.php b/modules/Documents/Documents.php
index d5ddd791404caaca700feaaa58c2249c27cd04b3..93f0adcb81baeddf9740206440b98b2aa3cc4442 100644
--- a/modules/Documents/Documents.php
+++ b/modules/Documents/Documents.php
@@ -95,8 +95,10 @@ class Documents extends CRMEntity {
 		}
 		$filetype_fieldname = $this->getFileTypeFieldName();
 		$filename_fieldname = $this->getFile_FieldName();
+		$filedownloadcount = null;
+		$filename = null;
 		if($this->column_fields[$filetype_fieldname] == 'I' ){
-			if($_FILES[$filename_fieldname]['name'] != ''){
+			if(isset($_FILES[$filename_fieldname]) && $_FILES[$filename_fieldname]['name'] != ''){
 				$errCode=$_FILES[$filename_fieldname]['error'];
 					if($errCode == 0){
 						foreach($_FILES as $fileindex => $files)
@@ -178,7 +180,7 @@ class Documents extends CRMEntity {
 
 		foreach($_FILES as $fileindex => $files)
 		{
-			if($files['name'] != '' && $files['size'] > 0)
+			if($files['name'] != '' && $files['size'] > 0 && isset($_REQUEST[$fileindex.'_hidden']))
 			{
 				$files['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']);
 				$file_saved = $this->uploadAndSaveFile($id,$module,$files);
@@ -550,6 +552,7 @@ class Documents extends CRMEntity {
 	function get_related_list($id, $cur_tab_id, $rel_tab_id,$actions = false) {
 		$related_module = vtlib_getModuleNameById($rel_tab_id);
 		$other = CRMEntity::getInstance($related_module);
+		$more_relation='';
 		vtlib_setup_modulevars('Documents', $this);
 		vtlib_setup_modulevars($related_module, $other);
 
@@ -585,4 +588,4 @@ class Documents extends CRMEntity {
 		return $return_value;
 	}
 }
-?>
\ No newline at end of file
+?>
diff --git a/modules/Documents/models/Record.php b/modules/Documents/models/Record.php
index 58080280cce843502823b933b21cac4f1c6d32af..411f134379320942a793089b9f99d733d4593303 100644
--- a/modules/Documents/models/Record.php
+++ b/modules/Documents/models/Record.php
@@ -21,6 +21,7 @@ class Documents_Record_Model extends Vtiger_Record_Model {
 	function getDownloadFileURL($attachmentId = false) {
 		if ($this->get('filelocationtype') == 'I') {
 			$fileDetails = $this->getFileDetails();
+			if (!isset($fileDetails['attachmentsid'])) $fileDetails['attachmentsid'] = '';
 			return 'index.php?module='. $this->getModuleName() .'&action=DownloadFile&record='. $this->getId() .'&fileid='. $fileDetails['attachmentsid'];
 		} else {
 			return $this->get('filename');
@@ -133,4 +134,4 @@ class Documents_Record_Model extends Vtiger_Record_Model {
 		return $value;
 	}
     
-}
\ No newline at end of file
+}
diff --git a/modules/Documents/views/List.php b/modules/Documents/views/List.php
index d61c444ee23808f6ca306a63326b7e21f4c432fa..ea7387a26f041a08c4089e5c84a0b951c238612a 100644
--- a/modules/Documents/views/List.php
+++ b/modules/Documents/views/List.php
@@ -93,7 +93,7 @@ class Documents_List_View extends Vtiger_List_View {
 			$orderBy = '';
 			$sortOrder = '';
 		}
-		if(empty($listHeaders)) {
+		if(empty($listHeaders) && $orderParams && isset($orderParams['list_headers'])) {
 			$listHeaders = $orderParams['list_headers'];
 		}
 		if(empty($orderBy) && empty($searchValue) && empty($pageNumber)) {
@@ -233,16 +233,16 @@ class Documents_List_View extends Vtiger_List_View {
 		}
 		$viewer->assign('PAGE_NUMBER',$pageNumber);
 
-		if(!$this->moduleFieldStructure) {
+		if(!isset($this->moduleFieldStructure)) {
 			$recordStructure = Vtiger_RecordStructure_Model::getInstanceForModule($listViewModel->getModule(), Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_FILTER);
 			$this->moduleFieldStructure = $recordStructure->getStructure();   
 		}
 
 		$currentUser = Users_Record_Model::getCurrentUserModel();
-		if(!$this->tags) {
+		if(!isset($this->tags)) {
 			$this->tags = Vtiger_Tag_Model::getAllAccessible($currentUser->id, $moduleName);
 		}
-		if(!$this->allUserTags) {
+		if(!isset($this->allUserTags)) {
 			$this->allUserTags = Vtiger_Tag_Model::getAllUserTags($currentUser->getId());
 		}
 
diff --git a/modules/Documents/views/QuickCreateAjax.php b/modules/Documents/views/QuickCreateAjax.php
index 856e0c5458f0c68930c47b3233753171376d49c8..b2f0f81fceb7c8cb19ef68f43108eb7ce72b9204 100644
--- a/modules/Documents/views/QuickCreateAjax.php
+++ b/modules/Documents/views/QuickCreateAjax.php
@@ -81,7 +81,7 @@ class Documents_QuickCreateAjax_View extends Vtiger_IndexAjax_View {
 			$viewer->assign('RELATION_OPERATOR', $relationOperation);
 			$viewer->assign('PARENT_MODULE', $request->get('sourceModule'));
 			$viewer->assign('PARENT_ID', $request->get('sourceRecord'));
-			if ($relationFieldName) {
+			if (isset($relationFieldName)) {
 				$viewer->assign('RELATION_FIELD_NAME', $relationFieldName);
 			}
 		}
@@ -118,4 +118,4 @@ class Documents_QuickCreateAjax_View extends Vtiger_IndexAjax_View {
 		return $jsScriptInstances;
 	}
 
-}
\ No newline at end of file
+}
diff --git a/modules/Events/actions/Save.php b/modules/Events/actions/Save.php
index 9113275cef57ff994311469149f223ae6d26dae5..bc095debfeaf38a9f2e8b84c1611f565da4d7a29 100644
--- a/modules/Events/actions/Save.php
+++ b/modules/Events/actions/Save.php
@@ -80,7 +80,7 @@ class Events_Save_Action extends Calendar_Save_Action {
 		$recurObj = getrecurringObjValue();
 		$recurringDataChanged = Calendar_RepeatEvents::checkRecurringDataChanged($recurObj, $recurObjDb);
 		//TODO: remove the dependency on $_REQUEST
-		if(($_REQUEST['recurringtype'] != '' && $_REQUEST['recurringtype'] != '--None--' && $recurringEditMode != 'current') || ($recurringDataChanged && empty($recurObj))) {
+		if((isset($_REQUEST['recurringtype']))&&($_REQUEST['recurringtype'] != '' && $_REQUEST['recurringtype'] != '--None--' && $recurringEditMode != 'current') || ($recurringDataChanged && empty($recurObj))) {
 			$focus =  CRMEntity::getInstance('Events');
 			//get all the stored data to this object
 			$focus->column_fields = new TrackableObject($recordModel->getData());
diff --git a/modules/Products/models/Record.php b/modules/Products/models/Record.php
index 967f4eaac4dfa80c7ded039ae0d249717ca35196..8659fecc8afd68462483b06f058eb94b55ef5756 100644
--- a/modules/Products/models/Record.php
+++ b/modules/Products/models/Record.php
@@ -370,7 +370,7 @@ class Products_Record_Model extends Vtiger_Record_Model {
 				$imageNamesList[] = $imageName;
                 $imageUrlsList[] = $url;
 			}
-
+			$imageOriginalNamesList=array();
 			if(is_array($imageOriginalNamesList)) {
 				$countOfImages = php7_count($imageOriginalNamesList);
 				for($j=0; $j<$countOfImages; $j++) {
diff --git a/modules/Vtiger/actions/MentionedUsers.php b/modules/Vtiger/actions/MentionedUsers.php
index d6bd2cba374f675d978cc4ec6e32e840f160d38c..31fcb6b876b3ddaccd73964770845f6b2cbd3562 100644
--- a/modules/Vtiger/actions/MentionedUsers.php
+++ b/modules/Vtiger/actions/MentionedUsers.php
@@ -37,7 +37,7 @@ class Vtiger_MentionedUsers_Action extends Vtiger_Action_Controller {
         if(($key = array_search(strtolower($currentUserName), $mentionedUsers)) !== false) {
             unset($mentionedUsers[$key]);
         }
-        
+        $mentionedUsersData=array();
         if(!empty($mentionedUsers)){
             $usersString = '@'.implode(' @', $mentionedUsers);
             $mentionedUsersData['usersString'] = $usersString.' ';
diff --git a/modules/Vtiger/helpers/Util.php b/modules/Vtiger/helpers/Util.php
index 0dc1862dc3240d140066b9316f9678191882cdc8..17731db7e721528ace6ee6cb9d833f9241d18a98 100644
--- a/modules/Vtiger/helpers/Util.php
+++ b/modules/Vtiger/helpers/Util.php
@@ -105,7 +105,7 @@ class Vtiger_Util_Helper {
 	 */
 	public static function toSafeHTML($input) {
 		global $default_charset;
-		return htmlentities($input, ENT_QUOTES, $default_charset);
+		return $input ? htmlentities($input, ENT_QUOTES, $default_charset) : $input;
 	}
 
 	/**
diff --git a/modules/Vtiger/models/Field.php b/modules/Vtiger/models/Field.php
index a13e2ec4ec6d15bdb0b54a3b2dda8344d962e4be..ab3a9af5209ae83018d225a9c80ed475970ea2c1 100644
--- a/modules/Vtiger/models/Field.php
+++ b/modules/Vtiger/models/Field.php
@@ -1347,8 +1347,7 @@ class Vtiger_Field_Model extends Vtiger_Field {
 	}
 
 	public function hasDefaultValue() {
-		$value = $this->defaultvalue !== null ? $this->defaultvalue : '';
-		return trim($value) == '' ? false : true;
+		return !$this->defaultvalue || trim($this->defaultvalue) == '' ? false : true;
 	}
 
 	public function isActiveField() {
diff --git a/modules/Vtiger/models/RelationListView.php b/modules/Vtiger/models/RelationListView.php
index 2a32d8a3fcb1d8ee7ff5a0f4397b08a8b9896176..054045afa4cad9789d776f35c486858402a0f229 100644
--- a/modules/Vtiger/models/RelationListView.php
+++ b/modules/Vtiger/models/RelationListView.php
@@ -281,7 +281,7 @@ class Vtiger_RelationListView_Model extends Vtiger_Base_Model {
 				if (is_array($fieldValue)) {
 					$comparator = $fieldValue[1];
 					$searchValue = $fieldValue[2];
-					$type = $fieldValue[3];
+					$type = isset($fieldValue[3])?$fieldValue[3]:'';
 					if ($type == 'time') {
 						$searchValue = Vtiger_Time_UIType::getTimeValueWithSeconds($searchValue);
 					}
@@ -350,8 +350,10 @@ class Vtiger_RelationListView_Model extends Vtiger_Base_Model {
 				}
 			}
 			//To show the value of "Assigned to"
+			if(isset($row['smownerid'])){
 			$ownerId = $row['smownerid'];
 			$newRow['assigned_user_id'] = $row['smownerid'];
+			}
 			if($relationModuleName == 'Calendar') {
 				$visibleFields = array('activitytype','date_start','time_start','due_date','time_end','assigned_user_id','visibility','smownerid','parent_id');
 				$visibility = true;
diff --git a/modules/Vtiger/uitypes/Time.php b/modules/Vtiger/uitypes/Time.php
index 4ee1b37e0efbef87245f4d8120cfc3b1349d872c..868152acfcb1ed28a3f69fd7bdb62af6fe7c2e22 100644
--- a/modules/Vtiger/uitypes/Time.php
+++ b/modules/Vtiger/uitypes/Time.php
@@ -64,15 +64,16 @@ class Vtiger_Time_UIType extends Vtiger_Base_UIType {
 	 */
 	public static function getTimeValueWithSeconds($time) {
 		if($time){
+			if (substr_count($time, ':') < 2) $time .= ':'; // adding : if seconds value is missing to avoid undefined array key error
 			$timeDetails = explode(' ', $time);
 			list($hours, $minutes, $seconds) = explode(':', $timeDetails[0]);
 
 			//If pm exists and if it not 12 then we need to make it to 24 hour format
-			if ($timeDetails[1] === 'PM' && $hours != '12') {
+			if (isset($timeDetails[1]) && $timeDetails[1] === 'PM' && $hours != '12') {
 				$hours = $hours+12;
 			}
 
-			if($timeDetails[1] === 'AM' && $hours == '12'){
+			if(isset($timeDetails[1]) && $timeDetails[1] === 'AM' && $hours == '12'){
 				$hours = '00';
 			}
 
diff --git a/modules/Vtiger/views/Detail.php b/modules/Vtiger/views/Detail.php
index 6248b3d4173c9d31359ea230a9a70e0f3ca0f265..ff6a69a4ab7611a22bfc54f1ffd21f07ca189dd1 100644
--- a/modules/Vtiger/views/Detail.php
+++ b/modules/Vtiger/views/Detail.php
@@ -319,7 +319,7 @@ class Vtiger_Detail_View extends Vtiger_Index_View {
 		$viewer->assign('MODULE_NAME', $moduleName);
 		$viewer->assign('IS_AJAX_ENABLED', $this->isAjaxEnabled($recordModel));
 		$viewer->assign('MODULE', $moduleName);
-
+		$viewer->assign('DAY_STARTS','');
 		$picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName);
 		$viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Vtiger_Functions::jsonEncode($picklistDependencyDatasource));
 
@@ -579,7 +579,6 @@ class Vtiger_Detail_View extends Vtiger_Index_View {
 		$currentUserModel = Users_Record_Model::getCurrentUserModel();
 		$modCommentsModel = Vtiger_Module_Model::getInstance('ModComments');
 		$moduleName = $parentCommentModel->getParentRecordModel()->getModuleName();
-
 		$viewer = $this->getViewer($request);
 		$viewer->assign('PARENT_COMMENTS', $childComments);
 		$viewer->assign('CURRENTUSER', $currentUserModel);
diff --git a/modules/Vtiger/views/MassActionAjax.php b/modules/Vtiger/views/MassActionAjax.php
index 303468c4a2fd302794ac7f6a20f8fada54b7dbf4..d8eb6a4e7f92aaf8a54a7bce995b153bd9b01844 100644
--- a/modules/Vtiger/views/MassActionAjax.php
+++ b/modules/Vtiger/views/MassActionAjax.php
@@ -210,11 +210,15 @@ class Vtiger_MassActionAjax_View extends Vtiger_IndexAjax_View {
 			$viewer->assign('ALPHABET_VALUE',$searchValue);
             $viewer->assign('SEARCH_KEY',$searchKey);
 		}
+		else{
+			$viewer->assign('OPERATOR','');
+			$viewer->assign('ALPHABET_VALUE','');
+            $viewer->assign('SEARCH_KEY','');
+		}
+        
+        $searchParams = !empty($request->get('search_params'))?$request->get('search_params'):' ';
+		$viewer->assign('SEARCH_PARAMS',$searchParams);
         
-        $searchParams = $request->get('search_params');
-        if(!empty($searchParams)) {
-            $viewer->assign('SEARCH_PARAMS',$searchParams);
-        }
 
 		$to = $request->get('to');
 		if (!$to) {
diff --git a/pkg/vtiger/modules/ModComments/modules/ModComments/views/InRelation.php b/pkg/vtiger/modules/ModComments/modules/ModComments/views/InRelation.php
index 3f46bfb8762e05bf44ecd46642097ddc7cd678e0..07bcd349d87e486f764e0c5a5a930028b69e92da 100644
--- a/pkg/vtiger/modules/ModComments/modules/ModComments/views/InRelation.php
+++ b/pkg/vtiger/modules/ModComments/modules/ModComments/views/InRelation.php
@@ -27,6 +27,8 @@ class ModComments_InRelation_View extends Vtiger_RelatedList_View {
 			$startindex = $startindex + 10;
 		} else {
 			$parentCommentModels = ModComments_Record_Model::getAllParentComments($parentRecordId);
+
+		
 		}
 
 		$currentCommentModel = null;
@@ -45,7 +47,6 @@ class ModComments_InRelation_View extends Vtiger_RelatedList_View {
 		$viewer->assign('FIELD_MODEL', $fileFieldModel);
 		$viewer->assign('MAX_UPLOAD_LIMIT_MB', Vtiger_Util_Helper::getMaxUploadSize());
 		$viewer->assign('MAX_UPLOAD_LIMIT_BYTES', Vtiger_Util_Helper::getMaxUploadSizeInBytes());
-
 		$viewer->assign('MODULE_NAME', $request->getModule());
 		$viewer->assign('MODULE_RECORD', $parentRecordId);
 		$viewer->assign('ROLLUP_STATUS', $rollupStatus);
diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php
index 106558c75197775a5d833b834a983f05bb1f2b85..7fc4fd1072adad35b84bd91498d74006d64ca453 100644
--- a/vtlib/Vtiger/Functions.php
+++ b/vtlib/Vtiger/Functions.php
@@ -519,10 +519,12 @@ class Vtiger_Functions {
 	// Utility
 	static function formatDecimal($value){
 		$fld_value = $value;
-		if(strpos($value, '.')) {
-			$fld_value = rtrim($value, '0');
-		}
-		$value = rtrim($fld_value, '.');
+		if(!$value)return $value;
+			if(strpos($value, '.')) {
+				$fld_value = rtrim($value, '0');
+			}
+			$value = rtrim($fld_value, '.');
+		
 		return $value;
 	}
 
@@ -1691,6 +1693,7 @@ class Vtiger_Functions {
             $result = $adb->pquery($query, array($crmid));
             $noofrows = $adb->num_rows($result);
             if ($noofrows) {
+                $attachmentIds = array();
                 for ($i = 0; $i < $noofrows; $i++) {
                     $attachmentIds[] = vtws_getId($WsEntityId,$adb->query_result($result, $i, 'attachmentsid'));
                 }
@@ -1715,6 +1718,9 @@ class Vtiger_Functions {
 	 * if mark will be true, then we are keeping the strip details in the $markers variable
 	 */
 	public static function strip_base64_data ($input, $mark = false, &$markers = null) {
+		if (!$input) {
+			return $input;
+		}
 		if ($markers === null) {
 			$markers = array();
 		}
@@ -1739,17 +1745,17 @@ class Vtiger_Functions {
 			$endchar = "";
 
 			// HTML embed in attributes (eg. img src="...").
-			$startidx = strpos($input, '"data:', $offset);
+			$startidx = strpos(isset($input) ? $input: '', '"data:', $offset);
 			if ($startidx !== false) {
 				$endchar = '"';
 			} else {
 				// HTML embed in attributes (eg. img src='...').
-				$startidx = strpos($input, "'data:", $offset);
+				$startidx = strpos(isset($input) ? $input: '', "'data:", $offset);
 				if ($startidx !== false) {
 					$endchar = "'";
 				} else {
 					// TEXT embed with wrap [eg. (data...)]
-					$startidx = strpos($input, "(data:", $offset);
+					$startidx = strpos(isset($input) ? $input : '', "(data:", $offset);
 					if ($startidx !== false) {
 						$endchar = ")";
 					} else {
@@ -1778,7 +1784,7 @@ class Vtiger_Functions {
 			$offset = $endidx + 1;
 		} while (true);
 
-		if ($offset < strlen($input)) {
+		if ($offset < strlen(isset($input) ? $input: '')) {
 			$parts[] = substr($input, $offset);
 		}
 				return implode("", $parts);
@@ -1789,6 +1795,9 @@ class Vtiger_Functions {
 	 * if mark will be true, then we are keeping the strip details in the $markers variable
 	 */
 	public static function stripInlineOffice365Image ($input, $mark = false, &$markers = null) {
+		if (!$input) {
+			return $input;
+		}
 		if ($markers === null) {
 			$markers = array();
 		}