From db165536e1363f6dc4c5510090128e0ea29a3b56 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 5 Mar 2008 10:31:26 +0000 Subject: [PATCH] configurable fields belonging to our (virtual) organisations, patch from Stefan Becker --- addressbook/inc/class.bocontacts.inc.php | 35 +++++++++++++++++++----- addressbook/inc/hook_config.inc.php | 33 +++++++++++++++++++++- addressbook/setup/egw_de.lang | 1 + addressbook/setup/egw_en.lang | 1 + addressbook/templates/default/config.tpl | 6 ++++ 5 files changed, 68 insertions(+), 8 deletions(-) diff --git a/addressbook/inc/class.bocontacts.inc.php b/addressbook/inc/class.bocontacts.inc.php index cc5f806e7b..89176c0bb1 100755 --- a/addressbook/inc/class.bocontacts.inc.php +++ b/addressbook/inc/class.bocontacts.inc.php @@ -246,8 +246,12 @@ class bocontacts extends socontacts { $this->own_account_acl = array_merge($this->own_account_acl,array('n_prefix','n_given','n_middle','n_family','n_suffix')); } + if ($GLOBALS['egw_info']['server']['org_fileds_to_update']) + { + $this->org_fields = unserialize($GLOBALS['egw_info']['server']['org_fileds_to_update']); + } } - + /** * calculate the file_as string from the contact and the file_as type * @@ -615,8 +619,8 @@ class bocontacts extends socontacts list($name,$value) = explode(':',$part); $org[$name] = $value; } + $contacts = parent::search('',$this->org_fields,'','','',false,'AND',false,$org); - if (!$contacts) return false; // create a statistic about the commonness of each fields values @@ -625,7 +629,12 @@ class bocontacts extends socontacts { foreach($contact as $name => $value) { - $fields[$name][$value]++; + if ($name != 'cat_id') $fields[$name][$value]++; + } + foreach(explode(',',$contact['cat_id']) as $part) + { + list($name) = explode(',',$part); + $fields['cat_id'][$name]++; } } foreach($fields as $name => $values) @@ -633,16 +642,28 @@ class bocontacts extends socontacts if (!in_array($name,$this->org_fields)) continue; arsort($values,SORT_NUMERIC); - list($value,$num) = each($values); //echo "

$name: '$value' $num/".count($contacts)."=".($num / (double) count($contacts))." >= $this->org_common_factor = ".($num / (double) count($contacts) >= $this->org_common_factor ? 'true' : 'false')."

\n"; if ($value && $num / (double) count($contacts) >= $this->org_common_factor) { - $org[$name] = $value; + if ($name != 'cat_id') + { + $org[$name] = $value; + } + else + { + $org[$name] = array(); + foreach ($values as $catid => $catvalue) + { + if ($catid && $catvalue / (double) count($values) >= $this->org_common_factor) + { + $org[$name][] = $catid; + } + } + $org[$name] = implode(',',$org[$name]); + } } } - //echo $org_id; _debug_array($org); - return $org; } diff --git a/addressbook/inc/hook_config.inc.php b/addressbook/inc/hook_config.inc.php index 70db80a412..fac74b3bba 100644 --- a/addressbook/inc/hook_config.inc.php +++ b/addressbook/inc/hook_config.inc.php @@ -55,5 +55,36 @@ function own_account_acl($config) { $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); } - return $GLOBALS['egw']->html->checkbox_multiselect('newsettings[own_account_acl]',$config['own_account_acl'],$fields,true,'',8); + return $GLOBALS['egw']->html->checkbox_multiselect('newsettings[own_account_acl]',$config['own_account_acl'],$fields,true,'',4); +} + +function org_fileds_to_update($config) +{ + $bocontacts =& CreateObject('addressbook.bocontacts'); + $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) + // get the list of account fields + $fields = array(); + foreach($bocontacts->contact_fields as $field => $label) + { + // some fields never making sense for an organisation + if (!in_array($field,array('id','tid','owner','created','creator','modified','modifier','private','n_prefix','n_given','n_middle','n_family','n_suffix','n_fn'))) + { + $fields[$field] = $label; + } + } + + if ($config['account_repository'] != 'ldap') // no custom-fields in ldap + { + $custom =& CreateObject('admin.customfields','addressbook'); + foreach($custom->get_customfields() as $name => $data) + { + $fields['#'.$name] = $data['label']; + } + } + if (!is_object($GLOBALS['egw']->html)) + { + $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); + } + return $GLOBALS['egw']->html->checkbox_multiselect('newsettings[org_fileds_to_update]', + $config['org_fileds_to_update'] ? $config['org_fileds_to_update'] : $bocontacts->org_fields,$fields,true,'',4); } diff --git a/addressbook/setup/egw_de.lang b/addressbook/setup/egw_de.lang index 9774a63f4a..2aec0b6a59 100644 --- a/addressbook/setup/egw_de.lang +++ b/addressbook/setup/egw_de.lang @@ -343,6 +343,7 @@ tomorrow is %1's birthday. common de Morgen ist der Geburtstag von %1. translation addressbook de Übersetzung type addressbook de Typ update a single entry by passing the fields. addressbook de Aktualisiert einen einzelnen Eintrag durch Übergabe seiner Felder. +update fields by edited organisations? admin de Welche Felder sollen beim Bearbeiten von Organisationen aktualisiert werden? updated addressbook de Aktualisiert upload or delete the photo addressbook de Foto hochladen oder löschen url to link telephone numbers to (use %1 = number to call, %u = account name, %t = account phone) admin de URL mit denen Telefonnummern verlinkt werden sollen (verwenden Sie %1 = anzurufende Nummer, %u = Benutzernamen, %t = Telefon des Benutzers) diff --git a/addressbook/setup/egw_en.lang b/addressbook/setup/egw_en.lang index b3e10f99d9..b9e7812340 100644 --- a/addressbook/setup/egw_en.lang +++ b/addressbook/setup/egw_en.lang @@ -343,6 +343,7 @@ tomorrow is %1's birthday. common en Tomorrow is %1's birthday. translation addressbook en Translation type addressbook en Type update a single entry by passing the fields. addressbook en Update a single entry by passing the fields. +update fields by edited organisations? admin en Update Fields by edited organisations? updated addressbook en Updated upload or delete the photo addressbook en Upload or delete the photo url to link telephone numbers to (use %1 = number to call, %u = account name, %t = account phone) admin en URL to link telephone numbers to (use %1 = number to call, %u = account name, %t = account phone) diff --git a/addressbook/templates/default/config.tpl b/addressbook/templates/default/config.tpl index cf46068c5d..5e9d54b10a 100644 --- a/addressbook/templates/default/config.tpl +++ b/addressbook/templates/default/config.tpl @@ -48,6 +48,12 @@ +  {lang_Update_Fields_by_edited_organisations?} + + {hook_org_fileds_to_update} + + +  {lang_Use_an_extra_tab_for_private_custom_fields?}