diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 70feb278484ce4b4b63784e4ae2b86668bcf724c..5e7569897f001830e91b59bafdac687762ae3f68 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -159,7 +159,7 @@ class CRMEntity {
 	 */
 	function uploadAndSaveFile($id, $module, $file_details, $attachmentType='Attachment') {
 		global $log;
-		$log->debug("Entering into uploadAndSaveFile($id,$module,$file_details) method.");
+		$log->debug("Entering into uploadAndSaveFile($id,$module) method.");
 
 		global $adb, $current_user;
 		global $upload_badext;
diff --git a/include/QueryGenerator/EnhancedQueryGenerator.php b/include/QueryGenerator/EnhancedQueryGenerator.php
index d842693a30531488b41278f05f83a2770cc33418..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 ($tableList[$tableName]) {
+				if (isset($tableList[$tableName])) {
 					$tableNameAlias = $tableName.'2';
 					$condition = str_replace($tableName, $tableNameAlias, $condition);
 				} 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 c7e28588e12599457d08ee9ca672dcb68a2d6023..ca897998b55be668bc52dd8554c2dbcf7ac4ce4e 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($_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/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..10ac0db6a61f748d19811a473428c6ee6247d473 100644
--- a/layouts/v7/modules/Documents/UploadDocument.tpl
+++ b/layouts/v7/modules/Documents/UploadDocument.tpl
@@ -23,7 +23,7 @@
 								<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}" />
@@ -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/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/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/modules/Documents/Documents.php b/modules/Documents/Documents.php
index d5ddd791404caaca700feaaa58c2249c27cd04b3..b34a3fd32daf0032af78d0d23e6a817d00d12ca9 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);
@@ -585,4 +587,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/Vtiger/helpers/Util.php b/modules/Vtiger/helpers/Util.php
index f793b582a8da26151e4f1b4b239943921d711d4d..57b862f53c3b65675e6382bbfe7a857feb3a63de 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 8fe19db1b3e1b66540df101519b2a0a72b528281..ab3a9af5209ae83018d225a9c80ed475970ea2c1 100644
--- a/modules/Vtiger/models/Field.php
+++ b/modules/Vtiger/models/Field.php
@@ -1347,7 +1347,7 @@ class Vtiger_Field_Model extends Vtiger_Field {
 	}
 
 	public function hasDefaultValue() {
-		return trim($this->defaultvalue) == '' ? false : true;
+		return !$this->defaultvalue || trim($this->defaultvalue) == '' ? false : true;
 	}
 
 	public function isActiveField() {
diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php
index 106558c75197775a5d833b834a983f05bb1f2b85..3037eca76daa9c75bb09fac744d06bbb7cc257c1 100644
--- a/vtlib/Vtiger/Functions.php
+++ b/vtlib/Vtiger/Functions.php
@@ -1691,6 +1691,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 +1716,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();
 		}
@@ -1789,6 +1793,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();
 		}