From fc841ff9cf23bee4f6731bf4ffc3e7067af92596 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 28 Jun 2010 14:05:33 +0000 Subject: [PATCH] - Fix save so fileas gets updated even if n_fn is set (normal edit) - Add isUpdate parameter to fill in any not set fields from DB when updating fileas --- addressbook/inc/class.addressbook_bo.inc.php | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 81f7e40ef2..f11753404d 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -341,15 +341,31 @@ class addressbook_bo extends addressbook_so * * @param array $contact * @param string $type=null file_as type, default null to read it from the contact, unknown/not set type default to the first one + * @param boolean $update=false If true, reads the old record for any not set fields * @return string */ - function fileas($contact,$type=null) + function fileas($contact,$type=null, $isUpdate=false) { if (is_null($type)) $type = $contact['fileas_type']; if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact); + if($isUpdate) + { + $fileas_fields = array('n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','org_name','org_unit','adr_one_locality'); + $old = null; + foreach($fileas_fields as $field) + { + if(!isset($contact[$field])) + { + if(is_null($old)) $old = $this->read($contact['id']); + $contact[$field] = $old[$field]; + } + } + unset($old); + } + $fileas = str_replace(array('n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','org_name','org_unit','adr_one_locality'), array($contact['n_prefix'],$contact['n_given'],$contact['n_middle'],$contact['n_family'],$contact['n_suffix'], $contact['n_fn'],$contact['org_name'],$contact['org_unit'],$contact['adr_one_locality']),$type); @@ -787,8 +803,9 @@ class addressbook_bo extends addressbook_so if (!isset($contact['n_fn'])) { $contact['n_fn'] = $this->fullname($contact); - if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact); } + if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact, null, false); + $to_write = $contact; // (non-admin) user editing his own account, make sure he does not change fields he is not allowed to (eg. via SyncML or xmlrpc) if (!$ignore_acl && !$contact['owner'] && !$this->is_admin($contact))