From 1791ab3a05520fc9aa370a2175c07e1f6012ec51 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 15 Nov 2010 16:29:31 +0000 Subject: [PATCH] Fix for blank country in history --- addressbook/inc/class.addressbook_bo.inc.php | 5 ++- .../inc/class.addressbook_tracking.inc.php | 40 +++++++++++++++++++ addressbook/inc/class.addressbook_ui.inc.php | 2 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 2a0d7d614e..9a74245ab3 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -203,6 +203,7 @@ class addressbook_bo extends addressbook_so 'adr_one_region' => lang('state').' ('.lang('business').')', 'adr_one_postalcode' => lang('zip code').' ('.lang('business').')', 'adr_one_countryname' => lang('country').' ('.lang('business').')', + 'adr_one_countrycode' => lang('country').' ('.lang('business').')', 'label' => lang('label'), 'adr_two_street' => lang('street').' ('.lang('private').')', 'adr_two_street2' => lang('address line 2').' ('.lang('private').')', @@ -210,6 +211,7 @@ class addressbook_bo extends addressbook_so 'adr_two_region' => lang('state').' ('.lang('private').')', 'adr_two_postalcode' => lang('zip code').' ('.lang('private').')', 'adr_two_countryname' => lang('country').' ('.lang('private').')', + 'adr_two_countrycode' => lang('country').' ('.lang('private').')', 'tel_work' => lang('work phone'), 'tel_cell' => lang('mobile phone'), 'tel_fax' => lang('fax').' ('.lang('business').')', @@ -816,7 +818,8 @@ class addressbook_bo extends addressbook_so // Update country codes foreach(array('adr_one_', 'adr_two_') as $c_prefix) { - if($contact[$c_prefix.'countryname'] && $code = $GLOBALS['egw']->country->country_code($contact[$c_prefix.'countryname'])) + if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] && + $code = $GLOBALS['egw']->country->country_code($contact[$c_prefix.'countryname'])) { if(strlen($code) == 2) { diff --git a/addressbook/inc/class.addressbook_tracking.inc.php b/addressbook/inc/class.addressbook_tracking.inc.php index a1dcb5e900..67b65cd30c 100644 --- a/addressbook/inc/class.addressbook_tracking.inc.php +++ b/addressbook/inc/class.addressbook_tracking.inc.php @@ -133,6 +133,46 @@ class addressbook_tracking extends bo_tracking return null; } + /** + * Override changes to do some special handling of the text country field vs the country code + * + * If the country name was changed at all, use the translated name from the country code as the other value. + * Otherwise, use country code. + * + * @internal use only track($data,$old) + * @param array $data current entry + * @param array $old=null old/last state of the entry or null for a new entry + * @param boolean $deleted=null can be set to true to let the tracking know the item got deleted or undelted + * @param array $changed_fields=null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again + * @return int number of log-entries made + */ + protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null) + { + if (is_null($changed_fields)) + { + $changed_fields = self::changed_fields($data,$old); + } + if (!$changed_fields) return 0; + foreach(array('adr_one_countryname' => 'adr_one_countrycode', 'adr_two_countryname' => 'adr_two_countrycode') as $name => $code) + { + // Only codes involved, but old text name is automatically added when loaded + if($old[$code] && $data[$code]) { + unset($changed_fields[array_search($name, $changed_fields)]); + continue; + } + + // Code and a text name + if(in_array($name, $changed_fields) && in_array($code, $changed_fields)) + { + if($data[$code]) { + $data[$name] = $GLOBALS['egw']->country->get_full_name($data[$code], true); + } + unset($changed_fields[array_search($code, $changed_fields)]); + } + } + parent::save_history($data,$old,$deleted,$changed_fields); + } + /** * Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented * diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 21a4ccf56d..13593c6afb 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -2237,6 +2237,8 @@ class addressbook_ui extends addressbook_bo 'status-widgets' => array( 'owner' => 'select-account', 'cat_id' => 'select-cat', + 'adr_one_countrycode' => 'select-country', + 'adr_two_countrycode' => 'select-country', ), );