From 4634465bb8e0bcd826819e8782a5fb378bf6dda7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 9 May 2009 07:58:16 +0000 Subject: [PATCH] addressbook maintenance: set full name and file as in contacts of all users --- addressbook/inc/class.addressbook_bo.inc.php | 64 ++++++++++++++++++++ addressbook/inc/class.addressbook_ui.inc.php | 31 ++++++++++ addressbook/inc/hook_config.inc.php | 34 ++++++++++- addressbook/setup/egw_de.lang | 6 ++ addressbook/setup/egw_en.lang | 5 ++ addressbook/templates/default/config.tpl | 13 +++- 6 files changed, 151 insertions(+), 2 deletions(-) diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 68b88d1517..ed72bbc640 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -369,6 +369,70 @@ class addressbook_bo extends addressbook_so return $options; } + /** + * Set n_fileas (and n_fn) in contacts of all users (called by Admin >> Addressbook >> Site configuration (Admin only) + * + * If $all all fileas fields will be set, if !$all only empty ones + * + * @param string $fileas_type '' or type of $this->fileas_types + * @param int $all=false update all contacts or only ones with empty values + * @param int &$errors=null on return number of errors + * @return int|boolean number of contacts updated, false for wrong fileas type + */ + function set_all_fileas($fileas_type,$all=false,&$errors=null,$ignore_acl=false) + { + if ($type != '' && !in_array($type,$this->fileas_types)) + { + return false; + } + if ($ignore_acl) + { + unset($this->somain->grants); // to NOT limit search to contacts readable by current user + } + // to be able to work on huge contact repositories we read the contacts in chunks of 100 + for($n = $updated = $errors = 0; ($contacts = parent::search($all ? array() : array( + 'n_fileas IS NULL', + "n_fileas=''", + 'n_fn IS NULL', + "n_fn=''", + ),false,'','','',false,'OR',array($n*100,100))); ++$n) + { + foreach($contacts as $contact) + { + $old_fn = $contact['n_fn']; + $old_fileas = $contact['n_fileas']; + $contact['n_fn'] = $this->fullname($contact); + // only update fileas if type is given AND (all should be updated or n_fileas is empty) + if ($fileas_type && ($all || empty($contact['n_fileas']))) + { + $contact['n_fileas'] = $this->fileas($contact,$fileas_type); + } + if ($old_fileas != $contact['n_fileas'] || $old_fn != $contact['n_fn']) + { + //echo "

('$old_fileas' != '{$contact['n_fileas']}' || '$old_fn' != '{$contact['n_fn']}')=".array2string($old_fileas != $contact['n_fileas'] || $old_fn != $contact['n_fn'])."

\n"; + // only specify/write updated fields plus "keys" + $contact = array_intersect_key($contact,array( + 'id' => true, + 'owner' => true, + 'private' => true, + 'account_id' => true, + 'uid' => true, + )+($old_fileas != $contact['n_fileas'] ? array('n_fileas' => true) : array())+($old_fn != $contact['n_fn'] ? array('n_fn' => true) : array())); + if ($this->save($contact,$ignore_acl)) + { + $updated++; + } + else + { + $errors++; + } + } + } + } + return $updated; + } + + /** * get full name from the name-parts * diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 0f03b90f9a..6296783e4e 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -25,6 +25,7 @@ class addressbook_ui extends addressbook_bo 'photo' => True, 'emailpopup'=> True, 'migrate2ldap' => True, + 'admin_set_fileas' => True, 'cat_add' => True, ); /** @@ -1934,6 +1935,10 @@ $readonlys['button[vcard]'] = true; '; } + /** + * Migrate contacts to or from LDAP (called by Admin >> Addressbook >> Site configuration (Admin only) + * + */ function migrate2ldap() { $GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook').' - '.lang('Migration to LDAP'); @@ -1952,6 +1957,32 @@ $readonlys['button[vcard]'] = true; $GLOBALS['egw']->common->egw_footer(); } + /** + * Set n_fileas (and n_fn) in contacts of all users (called by Admin >> Addressbook >> Site configuration (Admin only) + * + * If $_GET[all] all fileas fields will be set, if !$_GET[all] only empty ones + * + */ + function admin_set_fileas() + { + translation::add_app('admin'); + $GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook').' - '.lang('Contact maintenance'); + $GLOBALS['egw']->common->egw_header(); + parse_navbar(); + + // check if user has admin rights AND if a valid fileas type is given (Security) + if (!$this->is_admin() || $_GET['type'] != '' && !in_array($_GET['type'],$this->fileas_types)) + { + echo '

'.lang('Permission denied !!!')."

\n"; + } + else + { + $updated = parent::set_all_fileas($_GET['type'],(boolean)$_GET['all'],$errors,true); // true = ignore acl + echo '

'.lang('%1 contacts updated (%2 errors).',$updated,$errors)."

\n"; + } + $GLOBALS['egw']->common->egw_footer(); + } + /** * Download a document with inserted contact(s) * diff --git a/addressbook/inc/hook_config.inc.php b/addressbook/inc/hook_config.inc.php index 6de0b93df3..f51df0f88b 100644 --- a/addressbook/inc/hook_config.inc.php +++ b/addressbook/inc/hook_config.inc.php @@ -1,6 +1,6 @@ @@ -9,6 +9,12 @@ * @version $Id$ */ +/** + * Hook to query available contact repositories for addressbook config + * + * @param array $config + * @return string with options + */ function contact_repositories($config) { $repositories = array('sql' => 'SQL'); @@ -27,6 +33,26 @@ function contact_repositories($config) return $options; } +/** + * Hook to get available fileas types selectbox for addressbook config + * + * @param array $config + * @return string html + */ +function select_fileas($config) +{ + $bocontacts = new addressbook_bo(); + + return html::select('fileas','',array('' => lang('Set only full name'))+$bocontacts->fileas_options(),true); +} + + +/** + * Hook to get a multiselect box with all fieleds of onw-account-acl for addressbook config + * + * @param array $config + * @return string html + */ function own_account_acl($config) { $bocontacts = new addressbook_bo(); @@ -53,6 +79,12 @@ function own_account_acl($config) return html::checkbox_multiselect('newsettings[own_account_acl]',$config['own_account_acl'],$fields,true,'',4); } +/** + * Hook to get a multiselect box with all fields of org-fields-to-update for addressbook config + * + * @param array $config + * @return string html + */ function org_fileds_to_update($config) { $bocontacts = new addressbook_bo(); diff --git a/addressbook/setup/egw_de.lang b/addressbook/setup/egw_de.lang index c6b5a16323..b1f4d16d51 100644 --- a/addressbook/setup/egw_de.lang +++ b/addressbook/setup/egw_de.lang @@ -1,6 +1,7 @@ %1 added addressbook de %1 hinzugefügt %1 contact(s) %2 addressbook de %1 Kontakt(e) %2 %1 contact(s) %2, %3 failed because of insufficent rights !!! addressbook de %1 Kontakt(e) %2, %3 nicht wegen fehlender Rechte !!! +%1 contacts updated (%2 errors). addressbook de %1 Kontakte aktualisiert (%2 Fehler). %1 fields in %2 other organisation member(s) changed addressbook de %1 Felder in %2 Mitglied(ern) der Organisation geändert %1 records imported addressbook de %1 Datensätze importiert %1 records read (not yet imported, you may go %2back%3 and uncheck test import) addressbook de %1 Datensätze gelesen (noch nicht importiert, sie können %2zurück%3 gehen und Test-Import auschalten) @@ -96,6 +97,7 @@ contact deleted addressbook de Kontakt gelöscht contact fields to show addressbook de Kontaktfelder die angezeigt werden sollen contact fields: addressbook de Kontaktfelder: contact id addressbook de Kontakt ID +contact maintenance admin de Kontakt Wartung contact modified by %1 at %2 addressbook de Kontakt geändert von %1 am %2 contact not found! addressbook de Kontakt nicht gefunden! contact repository admin de Speicherort Kontakte @@ -160,8 +162,10 @@ edit phonenumbers - addressbook de Telefonnummern bearbeiten either the configured email addesses are wrong or the mail configuration. addressbook de Entweder die konfigurierte Email Adresse ist falsch oder die Mail Konfiguration. email & internet addressbook de E-Mail & Internet email addresses (comma separated) to send the contact data addressbook de Email Adressen (Komma getrennt) zum Senden der Kontaktdaten +empty admin de leere empty for all addressbook de leer für alle enable an extra private addressbook addressbook de Privates Adressbuch einschalten +enclosure addressbook de Einschluss end addressbook de Ende enter the path to the exported file here addressbook de Bitte geben Sie den Pfad für die exportierte Datei an error deleting the contact !!! addressbook de Fehler beim Löschen des Kontakts !!! @@ -341,6 +345,8 @@ select the type of conversion: addressbook de Typ der Umwandlung auswählen: select where you want to store / retrieve contacts admin de Auswählen wo Sie Adressen speichern wollen selected contacts addressbook de ausgewählte Kontakte seperator addressbook de Feldtrenner +set full name and file as field in contacts of all users (either all or only empty values) admin de Setzt vollen Namen und eigene Sortierung in Kontakten aller Benutzer (entweder alle oder nur leere Werte) +set only full name addressbook de Nur vollen Namen setzen should the columns photo and home address always be displayed, even if they are empty. addressbook de Sollen die Spalten Foto und Privatadresse immer angezeigt werden, auch wenn sie leer sind. show addressbook de Anzeigen show birthday reminders on main screen addressbook de Geburtstagserinnerungen auf der Startseite anzeigen diff --git a/addressbook/setup/egw_en.lang b/addressbook/setup/egw_en.lang index d151097153..8e021bb0c7 100644 --- a/addressbook/setup/egw_en.lang +++ b/addressbook/setup/egw_en.lang @@ -1,6 +1,7 @@ %1 added addressbook en %1 added %1 contact(s) %2 addressbook en %1 contact(s) %2 %1 contact(s) %2, %3 failed because of insufficent rights !!! addressbook en %1 contact(s) %2, %3 failed because of insufficent rights !!! +%1 contacts updated (%2 errors). addressbook en %1 contacts updated (%2 errors). %1 fields in %2 other organisation member(s) changed addressbook en %1 fields in %2 other organisation member(s) changed %1 records imported addressbook en %1 records imported %1 records read (not yet imported, you may go %2back%3 and uncheck test import) addressbook en %1 records read (not yet imported, you may go %2back%3 and uncheck Test Import) @@ -96,6 +97,7 @@ contact deleted addressbook en Contact deleted contact fields to show addressbook en Contact fields to show contact fields: addressbook en Contact fields: contact id addressbook en Contact ID +contact maintenance admin en Contact maintenance contact modified by %1 at %2 addressbook en Contact modified by %1 at %2 contact not found! addressbook en Contact not found! contact repository admin en Contact repository @@ -160,6 +162,7 @@ edit phonenumbers - addressbook en Edit Phonenumbers - either the configured email addesses are wrong or the mail configuration. addressbook en Either the configured email addesses are wrong or the mail configuration. email & internet addressbook en Email & Internet email addresses (comma separated) to send the contact data addressbook en Email addresses (comma separated) to send the contact data +empty admin en Empty empty for all addressbook en empty for all enable an extra private addressbook addressbook en Enable an extra private addressbook enclosure addressbook en Enclosure @@ -342,6 +345,8 @@ select the type of conversion: addressbook en Select the type of conversion: select where you want to store / retrieve contacts admin en Select where you want to store / retrieve contacts selected contacts addressbook en selected contacts seperator addressbook en Seperator +set full name and file as field in contacts of all users (either all or only empty values) admin en Set full name and file as field in contacts of all users (either all or only empty values) +set only full name addressbook en Set only full name should the columns photo and home address always be displayed, even if they are empty. addressbook en Should the columns photo and home address always be displayed, even if they are empty. show addressbook en Show show birthday reminders on main screen addressbook en Show birthday reminders on main screen diff --git a/addressbook/templates/default/config.tpl b/addressbook/templates/default/config.tpl index f5070d9486..38a7b97db8 100644 --- a/addressbook/templates/default/config.tpl +++ b/addressbook/templates/default/config.tpl @@ -14,7 +14,7 @@  {lang_Telephony_integration} -  {lang_URL_to_link_telephone_numbers_to_(use_%1_=_number_to_call,_%u_=_account_name,_%t_=_account_phone)}: +  {lang_URL_to_link_telephone_numbers_to_(use_%1_=_number_to_call,_%u_=_account_name,_%t_=_account_phone)}: @@ -67,6 +67,17 @@ {lang_(empty_=_use_global_limit,_no_=_no_export_at_all)}: + +  {lang_Contact_maintenance} + + +  {lang_Set_full_name_and_file_as_field_in_contacts_of_all_users_(either_all_or_only_empty_values)}: + + {hook_select_fileas} + + + +  {lang_Contact_repository}