diff --git a/include/Webservices/DataTransform.php b/include/Webservices/DataTransform.php
index 6111ce62cdeccefd57a31ef61a8e5433e1601d5f..e2fd9d1f6c1e1e89bedb3ff519aa65df90e4a15b 100644
--- a/include/Webservices/DataTransform.php
+++ b/include/Webservices/DataTransform.php
@@ -156,7 +156,7 @@
 			$allFields = $meta->getFieldColumnMapping();
 			$newRow = array();
 			foreach($allFields as $field=>$col){
-				$newRow[$field] = $row[$field];
+				$newRow[$field] = isset($row[$field]) ? $row[$field] : null;
 			}
 			if(isset($row[$recordString])){
 				$newRow[$recordString] = $row[$recordString];
@@ -215,7 +215,7 @@
 						list($row['parent_id'], $fieldId) = explode('@', $row['parent_id']);
 					}
 				}
-				if($row[$field]){
+				if(isset($row[$field]) && $row[$field]){
 					$found = false;
 					foreach ($typeList as $entity) {
 						$webserviceObject = VtigerWebserviceObject::fromName($adb,$entity);
diff --git a/include/Webservices/Utils.php b/include/Webservices/Utils.php
index 2c3c6871de1fa02c95ccc25d3f4365ffd2c3fca7..165527d2d6c32f4774a9ecf2ce52c40ce53f7d23 100644
--- a/include/Webservices/Utils.php
+++ b/include/Webservices/Utils.php
@@ -1272,7 +1272,7 @@ function vtws_getCompanyId() {
 
 function vtws_recordExists($recordId) {
 	$ids = vtws_getIdComponents($recordId);
-	return !Vtiger_Util_Helper::CheckRecordExistance($ids[1]);
+	return isset($ids[1]) ? !Vtiger_Util_Helper::CheckRecordExistance($ids[1]) : null;
 }
 
 function vtws_isDuplicatesAllowed($webserviceObject){
diff --git a/include/Webservices/VTQL_Parser.php b/include/Webservices/VTQL_Parser.php
index 223fc1a8cf6029d577b3d14ce56b8d0ac91d3cf0..be89405e0108ff9d68993552cb88f661a0b7a3d8 100644
--- a/include/Webservices/VTQL_Parser.php
+++ b/include/Webservices/VTQL_Parser.php
@@ -1241,6 +1241,7 @@ $this->out['where_condition']['column_values'][php7_sizeof($this->out['where_con
 #line 1240 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
 #line 82 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
     function yy_r17(){
+        $this->out['where_condition']['column_values'] = isset($this->out['where_condition']['column_values']) ? $this->out['where_condition']['column_values'] : array();
 $length = ($this->out['where_condition']['column_values'])? php7_sizeof($this->out['where_condition']['column_values']):0;
 $pos = $length - 1;
 if($pos < 0){
diff --git a/include/Webservices/VtigerModuleOperation.php b/include/Webservices/VtigerModuleOperation.php
index 03351a117a1139ed9f78d64a2fee7fb040c91103..89dd5671f2c9fd0565ca5b3592d7b29f0ef1c19f 100644
--- a/include/Webservices/VtigerModuleOperation.php
+++ b/include/Webservices/VtigerModuleOperation.php
@@ -16,6 +16,7 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
 	public function __construct($webserviceObject,$user,$adb,$log)
 	{
 		parent::__construct($webserviceObject,$user,$adb,$log);
+		
 		$this->meta = $this->getMetaInstance();
 		$this->tabId = $this->meta->getTabId();
 	}
@@ -80,6 +81,7 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
 	}
 	
     public function relatedIds($id, $relatedModule, $relatedLabel, $relatedHandler=null) {
+		global $adb;
 		$ids = vtws_getIdComponents($id);
         $sourceModule = $this->webserviceObject->getEntityName();		
         global $currentModule;
@@ -195,7 +197,7 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
 		$output = array();
 		for($i=0; $i<$noofrows; $i++){
 			$row = $this->pearDB->fetchByAssoc($result,$i);
-			if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row[$tableIdColumn])){
+			if(!isset($row[$tableIdColumn]) || !$meta->hasPermission(EntityMeta::$RETRIEVE,$row[$tableIdColumn])){
 				continue;
 			}
 			$output[$row[$tableIdColumn]] = DataTransform::sanitizeDataWithColumn($row,$meta);
diff --git a/layouts/v7/modules/HelpDesk/DetailViewHeaderTitle.tpl b/layouts/v7/modules/HelpDesk/DetailViewHeaderTitle.tpl
index 188008a7696c6b7f2a0302a22c6a854e36cf8b24..3515cacc44bb87edbe1bf39c3acbd69e997c0e86 100644
--- a/layouts/v7/modules/HelpDesk/DetailViewHeaderTitle.tpl
+++ b/layouts/v7/modules/HelpDesk/DetailViewHeaderTitle.tpl
@@ -12,7 +12,7 @@
 {strip}
     <div class="col-sm-6 col-lg-6 col-md-6">
         <div class="record-header clearfix">
-            <div class="recordImage bghelpdesk app-{$SELECTED_MENU_CATEGORY}">
+            <div class="recordImage bghelpdesk app-{(isset($SELECTED_MENU_CATEGORY)) ? $SELECTED_MENU_CATEGORY : ''}">
 				<div class="name"><span><strong>{$MODULE_MODEL->getModuleIcon()}</strong></span></div>
             </div>
             <div class="recordBasicInfo">
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/ExportRecords.php b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/ExportRecords.php
index 0a6721e8161e49eaea1afad20ce3da3a6a75d197..bbcd95bdc2d945af5b6d5f48400e2c5ef6181590 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/ExportRecords.php
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/ExportRecords.php
@@ -32,6 +32,7 @@ class CustomerPortal_ExportRecords extends CustomerPortal_API_Abstract {
 			//validate filter fields with portal settings
 			$activeFields = CustomerPortal_Utils::getActiveFields($module);
 			if ($fieldsArray !== null) {
+				if(!is_array($fieldsArray))$fieldsArray=array();
 				foreach ($fieldsArray as $key => $value) {
 					if (!in_array($key, $activeFields)) {
 						throw new Exception($key." is not accessible.", 1412);
@@ -78,7 +79,7 @@ class CustomerPortal_ExportRecords extends CustomerPortal_API_Abstract {
 				}
 				$moduleLabel = CustomerPortal_Utils::getRelatedModuleLabel($module);
 				$countResult = vtws_query_related($countSql, $parentId, $moduleLabel, $current_user);
-				$count = $countResult[0]['count'];
+				$count = isset($countResult[0]) ? $countResult[0]['count'] : 0;
 			}
 			//vtws_query gives max of 100 records per request.loop for records if more than 100
 			$pageLimit = 100;
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchProfile.php b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchProfile.php
index d9535a12228bd017d2fe99f1f98b30bfd78c1d2b..0f3e05bd7e3ac282e364ca83ac4ba466f5874cd7 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchProfile.php
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchProfile.php
@@ -21,8 +21,8 @@ class CustomerPortal_FetchProfile extends CustomerPortal_API_Abstract {
 
 			$contact = vtws_retrieve($contactId, $current_user);
 			$contact = CustomerPortal_Utils::resolveRecordValues($contact);
-			$contact['imagedata'] = $encodedContactImage['imagedata'];
-			$contact['imagetype'] = $encodedContactImage['imagetype'];
+			$contact['imagedata'] = isset($encodedContactImage['imagedata']) ? $encodedContactImage['imagedata'] : '';
+			$contact['imagetype'] = isset($encodedContactImage['imagetype']) ? $encodedContactImage['imagetype'] : '';
 			$response->addToResult('customer_details', $contact);
 
 			if (!empty($accountId)) {
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRecords.php b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRecords.php
index 931c68d56638faa5991bb6b7e5d299ee033f9cd4..de20de4f60366c0ba7a67fc7b9c24dc300d9b7b2 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRecords.php
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRecords.php
@@ -68,12 +68,15 @@ class CustomerPortal_FetchRecords extends CustomerPortal_API_Abstract {
 			$count = null;
 
 			if ($fieldsArray !== null) {
-				foreach ($fieldsArray as $key => $value) {
-					if (!in_array($key, $activeFields)) {
-						throw new Exception($key." is not accessible.", 1412);
-						exit;
+				if(is_iterable($fieldsArray)){
+					foreach ($fieldsArray as $key => $value) {
+						if (!in_array($key, $activeFields)) {
+							throw new Exception($key." is not accessible.", 1412);
+							exit;
+						}
 					}
 				}
+				
 			}
 			$fields = implode(',', $activeFields);
 
@@ -93,7 +96,7 @@ class CustomerPortal_FetchRecords extends CustomerPortal_API_Abstract {
 					$sql = sprintf('SELECT %s FROM Faq WHERE faqstatus=\'Published\'', $fields);
 				}
 				$countResult = vtws_query($countSql, $current_user);
-				$count = $countResult[0]['count'];
+				$count = isset($countResult[0]['count']) ? $countResult[0]['count'] : '';
 
 				$sql = sprintf('%s ORDER BY %s %s LIMIT %s,%s ;', $sql, $orderBy, $order, ($page * $pageLimit), $pageLimit);
 				$result = vtws_query($sql, $current_user);
@@ -123,7 +126,7 @@ class CustomerPortal_FetchRecords extends CustomerPortal_API_Abstract {
 				if ($mode == 'mine') {
 					$relatedId = $contactWebserviceId;
 					$countResult = vtws_query_related($countSql, $relatedId, $moduleLabel, $current_user);
-					$count = $countResult[0]['count'];
+					$count = isset($countResult[0]['count']) ? $countResult[0]['count'] : '';
 
 					$limitClause = sprintf('ORDER BY %s %s LIMIT %s,%s', $orderBy, $order, ($page * $pageLimit), $pageLimit);
 					$result = vtws_query_related($sql, $relatedId, $moduleLabel, $current_user, $limitClause);
@@ -135,7 +138,7 @@ class CustomerPortal_FetchRecords extends CustomerPortal_API_Abstract {
 						$sql = $sql.' '.$limitClause;
 						$result = vtws_query($sql, $current_user);
 						$countResult = vtws_query($countSql, $current_user);
-						$count = $countResult[0]['count'];
+						$count = isset($countResult[0]['count']) ? $countResult[0]['count'] : '';
 					} else {
 						if (!empty($accountId)) {
 							if ($defaultMode == 'all')
@@ -148,7 +151,7 @@ class CustomerPortal_FetchRecords extends CustomerPortal_API_Abstract {
 						}
 
 						$countResult = vtws_query_related($countSql, $relatedId, $moduleLabel, $current_user);
-						$count = $countResult[0]['count'];
+						$count = isset($countResult[0]['count']) ? $countResult[0]['count'] : '';
 
 						$limitClause = sprintf('ORDER BY %s %s LIMIT %s,%s', $orderBy, $order, ($page * $pageLimit), $pageLimit);
 						$result = vtws_query_related($sql, $relatedId, $moduleLabel, $current_user, $limitClause);
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRelatedRecords.php b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRelatedRecords.php
index 3043d9cc21ccfda72329b21ab064e5127f3c103b..01b8dec673bb6a9dc1ddebf6d1649002e02951a3 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRelatedRecords.php
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/apis/FetchRelatedRecords.php
@@ -72,7 +72,7 @@ class CustomerPortal_FetchRelatedRecords extends CustomerPortal_API_Abstract {
 				$result = vtws_query(sprintf("SELECT * FROM ModComments WHERE related_to = '%s' AND is_private='%s' ORDER BY %s DESC LIMIT %s,%s;", $recordId, 0, 'modifiedtime', ($page * $pageLimit), $pageLimit), $current_user);
 
 				$fileIds = array();
-				$$relatedEmailIds = array();
+				$relatedEmailIds = array();
 				if (is_array($result)) {
 					foreach ($result as $index => $value) {
 						$fileId = $value['filename'];
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/helpers/Utils.php b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/helpers/Utils.php
index 2a9d9631dbadacaff630641cc4224a02305658d9..f2f3b5d1b2fbc081a2dfe77e532bc3edbc90fa15 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/helpers/Utils.php
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/helpers/Utils.php
@@ -23,14 +23,14 @@ class CustomerPortal_Utils {
 		$imagePath = $adb->query_result($result, 0, 'path');
 		$imageName = $adb->query_result($result, 0, 'name');
 		$imageType = $adb->query_result($result, 0, 'type');
-		$imageOriginalName = urlencode(decode_html($imageName));
+		$imageOriginalName = isset($imageName) ? urlencode(decode_html($imageName)) : '';
 
 		if (!empty($imageName)) {
 			$imageDetails[] = array(
-				'id' => $imageId,
-				'orgname' => $imageOriginalName,
+				'id' => isset($imageId) ? $imageId : '',
+				'orgname' => isset($imageOriginalName) ? $imageOriginalName : '',
 				'path' => $imagePath.$imageId,
-				'name' => $imageName,
+				'name' => isset($imageName) ? $imageName : '',
 				'type' => $imageType
 			);
 		}
@@ -62,6 +62,7 @@ class CustomerPortal_Utils {
 			$sqlResult = $adb->pquery($sql, array(0, 1));
 
 			for ($i = 0; $i < $adb->num_rows($sqlResult); $i++) {
+				if(!is_array($activeModules))$activeModules = array();
 				$activeModules[] = $adb->query_result($sqlResult, $i, 'name');
 			}
 			//Checking if module is active at Module Manager 
@@ -91,7 +92,7 @@ class CustomerPortal_Utils {
 	static function resolveRecordValues(&$record, $user = null, $ignoreUnsetFields = false) {
 		$userTypeFields = array('assigned_user_id', 'creator', 'userid', 'created_user_id', 'modifiedby', 'folderid');
 
-		if (empty($record))
+		if (empty($record) || empty($user))
 			return $record;
 
 		$module = Vtiger_Util_Helper::detectModulenameFromRecordId($record['id']);
@@ -158,12 +159,13 @@ class CustomerPortal_Utils {
 			for ($i = 0; $i < $num_rows; $i++) {
 				$retrievedModule = $adb->query_result($sqlResult, $i, 'name');
 				$fieldInfo = $adb->query_result($sqlResult, $i, 'fieldinfo');
+				if(!is_array($activeFields))$activeFields = array();
 				$activeFields[$retrievedModule] = $fieldInfo;
 			}
 			Vtiger_Cache::set('CustomerPortal', 'activeFields', $activeFields);
 		}
 
-		$fieldsJSON = $activeFields[$module];
+		$fieldsJSON = isset($activeFields[$module]) ? $activeFields[$module] : '';
 		$data = Zend_Json::decode(decode_html($fieldsJSON));
 		$fields = array();
 
diff --git a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/include.inc b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/include.inc
index cca76ea5521c2d2b5f8dc1b070ba423f9371481b..883550a17848a0424acfb224e43dbccb1691a5d2 100644
--- a/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/include.inc
+++ b/pkg/vtiger/modules/CustomerPortal/modules/CustomerPortal/include.inc
@@ -41,7 +41,6 @@ require_once 'vtlib/Vtiger/Runtime.php';
 include_once 'includes/runtime/Viewer.php';
 include_once 'includes/runtime/Theme.php';
 include_once 'includes/http/Request.php';
-include_once 'libraries/Smarty/libs/sysplugins/smarty_security.php';
 include_once dirname(__FILE__).'/helpers/Request.php';
 include_once dirname(__FILE__).'/helpers/Response.php';
 include_once dirname(__FILE__).'/helpers/Utils.php';