From df73036d2b201d166df2ebefa0f7492c016a1780 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 5 Jun 2007 23:22:24 +0000 Subject: [PATCH] sitemgr contact-form that stores direct into the addressbook --- .../inc/class.addressbook_contactform.inc.php | 115 ++++++++++++ addressbook/setup/phpgw_de.lang | 13 ++ addressbook/setup/phpgw_en.lang | 12 ++ ...ass.module_addressbook_contactform.inc.php | 99 ++++++++++ addressbook/templates/default/contactform.xet | 177 ++++++++++++++++++ 5 files changed, 416 insertions(+) create mode 100644 addressbook/inc/class.addressbook_contactform.inc.php create mode 100644 addressbook/sitemgr/class.module_addressbook_contactform.inc.php create mode 100644 addressbook/templates/default/contactform.xet diff --git a/addressbook/inc/class.addressbook_contactform.inc.php b/addressbook/inc/class.addressbook_contactform.inc.php new file mode 100644 index 0000000000..b903a83ed8 --- /dev/null +++ b/addressbook/inc/class.addressbook_contactform.inc.php @@ -0,0 +1,115 @@ + + * @package addressbook + * @copyright (c) 2007 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +require_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.uietemplate.inc.php'); + +/** + * SiteMgr contact form for the addressbook + * + */ +class addressbook_contactform +{ + /** + * Shows the contactform and stores the submitted data + * + * @param array $content=null submitted eTemplate content + * @param int $addressbook + * @param array $fields + * @param string $msg + * @return string html content + */ + function display($content=null,$addressbook=null,$fields=null,$msg=null) + { + //echo "

addressbook_contactform::display($content,$addressbook,".print_r($fields,true).",$msg)

\n"; + $tpl = new etemplate('addressbook.contactform'); + + if (is_array($content)) + { + if ($content['captcha'] != $content['captcha_result']) + { + $tpl->set_validation_error('captcha',lang('Wrong - try again ...')); + } + elseif ($content['submitit']) + { + if ($content['owner']) // save the contact in the addressbook + { + $content['addressbook'] = $addressbook; + require_once(EGW_INCLUDE_ROOT.'/addressbook/inc/class.bocontacts.inc.php'); + $contact = new bocontacts(); + if ($contact->save($content)) + { + return '

'.$content['msg'].'

'; + } + else + { + return '

'.lang('There was an error saving your data :-(').'
'. + lang('The anonymous user has probably no add rights for this addressbook.').'

'; + } + } + else // todo email + { + return 'email not yet implemented!'; + } + } + } + else + { + $preserv['owner'] = $addressbook; + $preserv['msg'] = $msg; + if (!$fields) $fields = array('org_name','n_fn','email','tel_work','url','note','captcha'); + $custom = 1; + foreach($fields as $name) + { + if ($name{0} == '#') // custom field + { + static $contact; + if (is_null($contact)) + { + require_once(EGW_INCLUDE_ROOT.'/addressbook/inc/class.bocontacts.inc.php'); + $contact = new bocontacts(); + } + $content['show']['custom'.$custom] = true; + $content['customfield'][$custom] = $name; + $content['customlabel'][$custom] = $contact->customfields[substr($name,1)]['label']; + ++$custom; + } + elseif($name == 'adr_one_locality') + { + if (!($content['show'][$name] = $GLOBALS['egw_info']['user']['preferences']['addressbook']['addr_format'])) + { + $content['show'][$name] = 'postcode_city'; + } + } + else + { + $content['show'][$name] = true; + } + } + } + $content['addr_format'] = $GLOBALS['egw_info']['user']['preferences']['addressbook']['addr_format']; + + if ($addressbook) $preserv['owner'] = $addressbook; + if ($msg) $preserv['msg'] = $msg; + + // a simple calculation captcha + $num1 = rand(1,99); + $num2 = rand(1,99); + if ($num2 > $num1) // keep the result positive + { + $n = $num1; $num1 = $num2; $num2 = $n; + } + $content['captcha_task'] = sprintf('%d - %d =',$num1,$num2); + $preserv['captcha_result'] = $num1-$num2; + + return $tpl->exec('addressbook.addressbook_contactform.display',$content,$sel_options,$readonlys,$preserv); + } +} diff --git a/addressbook/setup/phpgw_de.lang b/addressbook/setup/phpgw_de.lang index 28477e10a2..9b3f327b8f 100644 --- a/addressbook/setup/phpgw_de.lang +++ b/addressbook/setup/phpgw_de.lang @@ -5,6 +5,7 @@ %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) %1 starts with '%2' addressbook de %1 beginnt mit '%2' +%s please calculate the result addressbook de %s Bitte berechnen Sie das Ergebnis (e.g. 1969) addressbook de (z.B. 1966) no conversion type <none> could be located. please choose a conversion type from the list addressbook de Kein Übersetzungstyp konnte gefunden werden. Bitte wählen Sie einen Übersetzungstyp aus der Liste @-eval() is only availible to admins!!! addressbook de @-eval() ist nur verfügbar für Administratoren!!! @@ -77,10 +78,12 @@ contact common de Kontakt contact application admin de Kontakt Anwendung contact copied addressbook de Kontakt kopiert contact deleted addressbook de Kontakt gelöscht +contact fields to show addressbook de Kontaktfelder die angezeigt werden sollen contact id addressbook de Kontakt ID contact repository admin de Speicherort Kontakte contact saved addressbook de Kontakt gespeichert contact settings admin de Kontakt Einstellungen +contactform addressbook de Kontaktformular contacts and account contact-data to ldap admin de Kontakte und Kontaktdaten der Benutzer nach LDAP contacts to ldap admin de Kontakte nach LDAP contacts to ldap, account contact-data to sql admin de Kontakte nach LDAP, Kontaktdaten der Benutzer nach SQL @@ -197,6 +200,7 @@ link title for contacts show addressbook de Titel der Verkn links addressbook de Verknüpfungen list all categories addressbook de Liste alle Kategorien list all customfields addressbook de Liste alle benutzerdefinierten Felder +list already exists! addressbook de Die Liste existiert bereits! list created addressbook de Verteiler erzeugt list creation failed, no rights! addressbook de Verteiler erzeugen fehlgeschlagen, keine Rechte! load vcard addressbook de VCard laden @@ -204,6 +208,7 @@ locations addressbook de Standorte mark records as private addressbook de Eintrag als Privat kennzeichnen merge into first or account, deletes all other! addressbook de Vereinige im ersten oder Benutzerkonto, löscht alle anderen! merged addressbook de vereinigt +message after submitting the form addressbook de Nachricht nach dem Abschicken des Formulars message phone addressbook de Anrufbeantworter middle name addressbook de Zweiter Vorname migration finished addressbook de Migration beendet @@ -250,6 +255,7 @@ record access addressbook de Zugriffsrechte record owner addressbook de Datensatzeigentümer remove selected contacts from distribution list addressbook de Ausgewählte Kontakte vom Verteiler löschen removed from distribution list addressbook de vom Verteiler gelöscht +required fields * addressbook de unbedingt auszufüllende Felder * role addressbook de Funktion room addressbook de Raum search for '%1' addressbook de Suche nach '%1' @@ -280,7 +286,12 @@ suffix addressbook de Zusatz tel home addressbook de Telefon privat telephony integration admin de Telefonie Integration test import (show importable records only in browser) addressbook de Test-Import (zeigt importierbare Datensätze nur im Browser an) +thank you for contacting us. addressbook de Danke das Sie uns kontaktierten. that field name has been used already ! addressbook de Dieser Feldname wird bereits benutzt! +the anonymous user has probably no add rights for this addressbook. addressbook de Der anonyme Benutzer hat vermutlich keine Hinzufügen Rechte für diese Adressbuch. +the anonymous user needs add rights for it! addressbook de Der anonyme Benutzer benötigt Hinzufügen Rechte dafür! +there was an error saving your data :-( addressbook de Beim Speichern ihrer Daten ist ein Fehler aufgetreten :-( +this module displays a contactform, that stores direct into the addressbook. addressbook de Diese Module ist ein Kontaktformular, das direkt in das Adressbuch speichert. this person's first name was not in the address book. addressbook de Der Vorname dieser Person ist nicht im Adressbuch. this person's last name was not in the address book. addressbook de Der Nachname dieser Person ist nicht im Adressbuch. timezone addressbook de Zeitzone @@ -299,6 +310,7 @@ used for links and for the own sorting of the list addressbook de wird f vcard common de VCard vcards require a first name entry. addressbook de VCards benötigen einen Vornamen. vcards require a last name entry. addressbook de VCards benötigen einen Nachnamen. +verification addressbook de Verifikation view linked infolog entries addressbook de Verknüpfte InfoLog Einträge anzeigen warning!! ldap is valid only if you are not using contacts for accounts storage! admin de WARNUNG!! LDAP darf nur verwendet werden, wenn sie die Benutzerkonten nicht im Adressbuch speichern! warning: all contacts found will be deleted! addressbook de WARNUNG: Alle gefundenen Kontakte werden gelöscht! @@ -310,6 +322,7 @@ which fields should be exported. all means every field stored in the addressbook whole query addressbook de gesamte Abfrage work phone addressbook de Tel dienstl. write (update or add) a single entry by passing the fields. addressbook de Schreibt (aktualiseren oder zufügen) eines einzelnen Eintrags durch Übergabe der Felder +wrong - try again ... addressbook de Falsch - nochmal versuchen ... yes, for the next three days addressbook de Ja, für die nächsten drei Tage yes, for the next two weeks addressbook de Ja, für die nächsten zwei Wochen yes, for the next week addressbook de Ja, für die nächste Woche diff --git a/addressbook/setup/phpgw_en.lang b/addressbook/setup/phpgw_en.lang index 032c2f25be..5742ee089b 100644 --- a/addressbook/setup/phpgw_en.lang +++ b/addressbook/setup/phpgw_en.lang @@ -5,6 +5,7 @@ %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) %1 starts with '%2' addressbook en %1 starts with '%2' +%s please calculate the result addressbook en %s please calculate the result (e.g. 1969) addressbook en (e.g. 1969) no conversion type <none> could be located. please choose a conversion type from the list addressbook en No conversion type <none> could be located. Please choose a conversion type from the list @-eval() is only availible to admins!!! addressbook en @-eval() is only availible to admins!!! @@ -77,10 +78,12 @@ contact common en Contact contact application admin en Contact application contact copied addressbook en Contact copied contact deleted addressbook en Contact deleted +contact fields to show addressbook en Contact fields to show contact id addressbook en Contact ID contact repository admin en Contact repository contact saved addressbook en Contact saved contact settings admin en Contact Settings +contactform addressbook en Contactform contacts and account contact-data to ldap admin en contacts and account contact-data to LDAP contacts to ldap admin en contacts to LDAP contacts to ldap, account contact-data to sql admin en contacts to LDAP, account contact-data to SQL @@ -205,6 +208,7 @@ locations addressbook en locations mark records as private addressbook en Mark records as private merge into first or account, deletes all other! addressbook en Merge into first or account, deletes all other! merged addressbook en merged +message after submitting the form addressbook en Message after submitting the form message phone addressbook en Message Phone middle name addressbook en Middle Name migration finished addressbook en Migration finished @@ -251,6 +255,7 @@ record access addressbook en Record Access record owner addressbook en Record owner remove selected contacts from distribution list addressbook en Remove selected contacts from distribution list removed from distribution list addressbook en removed from distribution list +required fields * addressbook en required fields * role addressbook en Role room addressbook en Room search for '%1' addressbook en Search for '%1' @@ -281,7 +286,12 @@ suffix addressbook en Suffix tel home addressbook en tel home telephony integration admin en Telephony integration test import (show importable records only in browser) addressbook en Test Import (show importable records only in browser) +thank you for contacting us. addressbook en Thank you for contacting us. that field name has been used already ! addressbook en That field name has been used already ! +the anonymous user has probably no add rights for this addressbook. addressbook en The anonymous user has probably no add rights for this addressbook. +the anonymous user needs add rights for it! addressbook en The anonymous user needs add rights for it! +there was an error saving your data :-( addressbook en There was an error saving your data :-( +this module displays a contactform, that stores direct into the addressbook. addressbook en This module displays a contactform, that stores direct into the addressbook. this person's first name was not in the address book. addressbook en This person's first name was not in the address book. this person's last name was not in the address book. addressbook en This person's last name was not in the address book. timezone addressbook en Timezone @@ -300,6 +310,7 @@ used for links and for the own sorting of the list addressbook en used for links vcard common en VCard vcards require a first name entry. addressbook en VCards require a first name entry. vcards require a last name entry. addressbook en Vcards require a last name entry. +verification addressbook en Verification view linked infolog entries addressbook en View linked InfoLog entries warning!! ldap is valid only if you are not using contacts for accounts storage! admin en WARNING!! LDAP is valid only if you are NOT using contacts for accounts storage! warning: all contacts found will be deleted! addressbook en WARNING: All contacts found will be deleted! @@ -311,6 +322,7 @@ which fields should be exported. all means every field stored in the addressbook whole query addressbook en whole query work phone addressbook en Work Phone write (update or add) a single entry by passing the fields. addressbook en Write (update or add) a single entry by passing the fields. +wrong - try again ... addressbook en Wrong - try again ... yes, for the next three days addressbook en Yes, for the next three days yes, for the next two weeks addressbook en Yes, for the next two weeks yes, for the next week addressbook en Yes, for the next week diff --git a/addressbook/sitemgr/class.module_addressbook_contactform.inc.php b/addressbook/sitemgr/class.module_addressbook_contactform.inc.php new file mode 100644 index 0000000000..89ec10b928 --- /dev/null +++ b/addressbook/sitemgr/class.module_addressbook_contactform.inc.php @@ -0,0 +1,99 @@ + + * @package addressbook + * @copyright (c) 2007 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +require_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.sitemgr_module.inc.php'); + +/** + * SiteMgr contact form for the addressbook + * + */ +class module_addressbook_contactform extends sitemgr_module +{ + /** + * Constructor + * + * @return module_addressbook_contactform + */ + function module_addressbook_contactform() + { + $this->arguments = array(); // get's set in get_user_interface + $this->title = lang('Contactform'); + $this->description = lang('This module displays a contactform, that stores direct into the addressbook.'); + + $this->etemplate_method = 'addressbook.addressbook_contactform.display'; + } + + /** + * Reimplemented to add the addressbook translations and fetch the addressbooks only if needed for the user-interface + * + * @return array + */ + function get_user_interface() + { + $GLOBALS['egw']->translation->add_app('addressbook'); + + require_once(EGW_INCLUDE_ROOT.'/addressbook/inc/class.uicontacts.inc.php'); + $uicontacts = new uicontacts(); + + $default = $fields = array( + 'org_name' => lang('Company'), + 'org_unit' => lang('Department'), + 'n_fn' => lang('Prefix').', '.lang('Firstname').' + '.lang('Lastname'), + 'sep1' => '----------------------------', + 'email' => lang('email'), + 'tel_work' => lang('work phone'), + 'tel_cell' => lang('mobile phone'), + 'tel_fax' => lang('fax'), + 'tel_home' => lang('home phone'), + 'url' => lang('url'), + 'sep2' => '----------------------------', + 'adr_one_street' => lang('street'), + 'adr_one_street2' => lang('address line 2'), + 'adr_one_locality' => lang('city').' + '.lang('zip code'), + 'sep3' => '----------------------------', + ); + foreach($uicontacts->customfields as $name => $data) + { + $fields['#'.$name] = $data['label']; + } + $fields += array( + 'sep4' => '----------------------------', + 'note' => lang('message'), + 'sep5' => '----------------------------', + 'captcha' => lang('Verification'), + ); + $this->arguments = array( + 'arg1' => array( + 'type' => 'select', + 'label' => lang('Addressbook the contact should be saved to').' ('.lang('The anonymous user needs add rights for it!').')', + 'options' => array( + '' => lang('None'), + )+$uicontacts->get_addressbooks(EGW_ACL_ADD) // add to not show the accounts! + ), + 'arg2' => array( + 'type' => 'select', + 'label' => lang('Contact fields to show'), + 'multiple' => true, + 'options' => $fields, + 'default' => $default, + 'params' => array('size' => 15), + ), + 'arg3' => array( + 'type' => 'textfield', + 'label' => lang('Message after submitting the form'), + 'params' => array('size' => 80), + 'default' => lang('Thank you for contacting us.'), + ), + ); + return parent::get_user_interface(); + } +} diff --git a/addressbook/templates/default/contactform.xet b/addressbook/templates/default/contactform.xet new file mode 100644 index 0000000000..7e87711c58 --- /dev/null +++ b/addressbook/templates/default/contactform.xet @@ -0,0 +1,177 @@ + + + + + \ No newline at end of file