Fix for blank country in history

This commit is contained in:
Nathan Gray 2010-11-15 16:29:31 +00:00
parent 76038568fc
commit 1791ab3a05
3 changed files with 46 additions and 1 deletions

View File

@ -203,6 +203,7 @@ class addressbook_bo extends addressbook_so
'adr_one_region' => lang('state').' ('.lang('business').')', 'adr_one_region' => lang('state').' ('.lang('business').')',
'adr_one_postalcode' => lang('zip code').' ('.lang('business').')', 'adr_one_postalcode' => lang('zip code').' ('.lang('business').')',
'adr_one_countryname' => lang('country').' ('.lang('business').')', 'adr_one_countryname' => lang('country').' ('.lang('business').')',
'adr_one_countrycode' => lang('country').' ('.lang('business').')',
'label' => lang('label'), 'label' => lang('label'),
'adr_two_street' => lang('street').' ('.lang('private').')', 'adr_two_street' => lang('street').' ('.lang('private').')',
'adr_two_street2' => lang('address line 2').' ('.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_region' => lang('state').' ('.lang('private').')',
'adr_two_postalcode' => lang('zip code').' ('.lang('private').')', 'adr_two_postalcode' => lang('zip code').' ('.lang('private').')',
'adr_two_countryname' => lang('country').' ('.lang('private').')', 'adr_two_countryname' => lang('country').' ('.lang('private').')',
'adr_two_countrycode' => lang('country').' ('.lang('private').')',
'tel_work' => lang('work phone'), 'tel_work' => lang('work phone'),
'tel_cell' => lang('mobile phone'), 'tel_cell' => lang('mobile phone'),
'tel_fax' => lang('fax').' ('.lang('business').')', 'tel_fax' => lang('fax').' ('.lang('business').')',
@ -816,7 +818,8 @@ class addressbook_bo extends addressbook_so
// Update country codes // Update country codes
foreach(array('adr_one_', 'adr_two_') as $c_prefix) { 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) if(strlen($code) == 2)
{ {

View File

@ -133,6 +133,46 @@ class addressbook_tracking extends bo_tracking
return null; 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 * Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented
* *

View File

@ -2237,6 +2237,8 @@ class addressbook_ui extends addressbook_bo
'status-widgets' => array( 'status-widgets' => array(
'owner' => 'select-account', 'owner' => 'select-account',
'cat_id' => 'select-cat', 'cat_id' => 'select-cat',
'adr_one_countrycode' => 'select-country',
'adr_two_countrycode' => 'select-country',
), ),
); );