/**
* Standard (imp) contacts display page.
*
+ * URL parameters:
+ * 'formfield' - (string) Overrides the form field to fill on closing the
+ * window.
+ * 'formname' - (string) Name of the calling form (defaults to 'compose').
+ * 'sa' - TODO
+ * 'search' - (string) Search term (defaults to '' which should list
+ * everyone).
+ * 'searched' - TODO
+ * 'source' - TODO
+ * 'to_only' - (boolean) Are we limiting to only the 'To:' field?
+ *
* Copyright 2002-2010 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('imp', array('authentication' => 'horde'));
+$vars = Horde_Variables::getDefaultVariables();
+
/* Get the lists of address books through the API. */
$source_list = $registry->call('contacts/sources');
/* If we self-submitted, use that source. Otherwise, choose a good
* source. */
-$source = Horde_Util::getFormData('source');
-if (empty($source) || !isset($source_list[$source])) {
- /* We don't just pass the second argument to getFormData() because
- * we want to trap for invalid sources, not just no source. */
+if (!isset($vars->source) || !isset($source_list[$vars->source])) {
reset($source_list);
- $source = key($source_list);
+ $vars->source = key($source_list);
}
-/* Get the search as submitted (defaults to '' which should list everyone). */
-$search = Horde_Util::getFormData('search');
-
-/* Get the name of the calling form (Defaults to 'compose'). */
-$formname = Horde_Util::getFormData('formname', 'compose');
-
-/* Are we limiting to only the 'To:' field? */
-$to_only = Horde_Util::getFormData('to_only');
+if (!isset($vars->formname)) {
+ $vars->formname = 'compose';
+}
$search_params = IMP_Compose::getAddressSearchParams();
$apiargs = array(
- 'addresses' => array($search),
- 'addressbooks' => array($source),
+ 'addresses' => array($vars->search),
+ 'addressbooks' => array($vars->source),
'fields' => $search_params['fields']
);
$addresses = array();
-if (Horde_Util::getFormData('searched') || $prefs->getValue('display_contact')) {
+if ($vars->searched || $prefs->getValue('display_contact')) {
$results = $registry->call('contacts/search', $apiargs);
foreach ($results as $r) {
/* The results list returns an array for each source searched. Make
/* If self-submitted, preserve the currently selected users encoded by
* javascript to pass as value|text. */
$selected_addresses = array();
-foreach (explode('|', Horde_Util::getFormData('sa')) as $addr) {
+foreach (explode('|', $vars->sa) as $addr) {
if (strlen(trim($addr))) {
$selected_addresses[] = @htmlspecialchars($addr, ENT_QUOTES, Horde_Nls::getCharset());
}
$template->setOption('gettext', true);
$template->set('action', Horde::applicationUrl('contacts.php')->add(array('uniq' => uniqid(mt_rand()))));
-$template->set('formname', $formname);
+$template->set('formname', $vars->formname);
$template->set('formInput', Horde_Util::formInput());
-$template->set('search', htmlspecialchars($search));
+$template->set('search', htmlspecialchars($vars->search));
if (count($source_list) > 1) {
$template->set('multiple_source', true);
$s_list = array();
foreach ($source_list as $key => $select) {
- $s_list[] = array('val' => $key, 'selected' => ($key == $source), 'label' => htmlspecialchars($select));
+ $s_list[] = array('val' => $key, 'selected' => ($key == $vars->source), 'label' => htmlspecialchars($select));
}
$template->set('source_list', $s_list);
} else {
}
}
$template->set('a_list', $a_list);
-$template->set('cc', !$to_only);
+$template->set('cc', intval(!$vars->to_only));
$template->set('sa', $selected_addresses);
+$js = array(
+ 'ImpContacts.formname = "' . $vars->formname . '"',
+ 'ImpContacts.to_only = ' . intval($vars->to_only)
+);
+if (isset($vars->formfield)) {
+ $js[] = 'ImpContacts.formfield = "' . $vars->formfield . '"';
+}
+
/* Display the form. */
$title = _("Address Book");
Horde::addScriptFile('contacts.js', 'imp');
require IMP_TEMPLATES . '/common-header.inc';
-Horde::addInlineScript(array(
- 'ImpContacts.formname = \'' . $formname . '\'',
- 'ImpContacts.to_only = ' . intval($to_only),
-));
+Horde::addInlineScript($js);
echo $template->fetch(IMP_TEMPLATES . '/imp/contacts/contacts.html');
require $registry->get('templates', 'horde') . '/common-footer.inc';
var ImpContacts = {
// The following variables are defined in contacts.php:
- // formname, to_only
+ // formfield, formname, to_only
_passAddresses: function()
{
$('selected_addresses').childElements().each(function(s) {
var address = s.value, f, field = null, pos, v;
pos = address.indexOf(':');
- f = address.substring(0, pos);
address = address.substring(pos + 2, address.length)
- if (f == 'to') {
- field = parent.opener.document[this.formname].to;
- } else if (!this.to_only && f == 'cc') {
- field = parent.opener.document[this.formname].cc;
- } else if (!this.to_only && f == 'bcc') {
- field = parent.opener.document[this.formname].bcc;
+ if (this.formfield) {
+ field = parent.opener.document[this.formname][this.formfield];
+ } else {
+ f = address.substring(0, pos);
+ if (f == 'to' ||
+ (!this.to_only && (f == 'cc' || f == 'bcc'))) {
+ field = parent.opener.document[this.formname][f];
+ }
}
if (!field) {