From 0a0530fe46efb22ac9123c644cc6afcb3247265b Mon Sep 17 00:00:00 2001
From: nathangray <nathangray.bsc+github@gmail.com>
Date: Thu, 13 Apr 2017 09:25:47 -0600
Subject: [PATCH] * Addressbook - Fix bug where private required custom fields
 could block saving the entry if they were not on their own tab

---
 addressbook/inc/class.addressbook_ui.inc.php | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php
index 71adb6198b..51a9ac8a6b 100644
--- a/addressbook/inc/class.addressbook_ui.inc.php
+++ b/addressbook/inc/class.addressbook_ui.inc.php
@@ -2347,17 +2347,19 @@ window.egw_LAB.wait(function() {
 		$content['cat_id_tree'] = $content['cat_id'];
 
 		// Avoid setting conflicts with private custom fields
-		if ($this->config['private_cf_tab'])
+		$content['private_cfs'] = array();
+		foreach(Api\Storage\Customfields::get('addressbook', true) as $name => $cf)
 		{
-			$content['private_cfs'] = array();
-			foreach(Api\Storage\Customfields::get('addressbook', true) as $name => $cf)
+			if ($this->config['private_cf_tab'] && $cf['private'] && isset($content['#'.$name]))
 			{
-				if ($cf['private'] && isset($content['#'.$name]))
-				{
-					$content['private_cfs']['#'.$name] = $content['#'.$name];
-				}
+				$content['private_cfs']['#'.$name] = $content['#'.$name];
+			}
+			else if ($cf['private'])
+			{
+				$readonlys['private_cfs']['#'.$name] = true;
 			}
 		}
+		
 		// how to display addresses
 		$content['addr_format']  = $this->addr_format_by_country($content['adr_one_countryname']);
 		$content['addr_format2'] = $this->addr_format_by_country($content['adr_two_countryname']);
@@ -2414,7 +2416,7 @@ window.egw_LAB.wait(function() {
 		// disable not needed tabs
 		$readonlys['tabs']['cats'] = !($content['cat_tab'] = $this->config['cat_tab']);
 		$readonlys['tabs']['custom'] = !$this->customfields || $this->get_backend($content['id'],$content['owner']) == $this->so_accounts;
-		$readonlys['tabs']['custom_private'] = $readonlys['tabs']['custom'] || !$this->config['private_cf_tab'];
+		$readonlys['tabs']['custom_private'] = $readonlys['tabs']['custom'] || !$this->config['private_cf_tab'] ? '__ALL__' : false;
 		$readonlys['tabs']['distribution_list'] = !$content['distrib_lists'];#false;
 		$readonlys['tabs']['history'] = $this->contact_repository != 'sql' || !$content['id'] ||
 			$this->account_repository != 'sql' && $content['account_id'];