summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/addressbook/edit.inc36
-rw-r--r--program/steps/addressbook/func.inc8
-rw-r--r--program/steps/addressbook/save.inc6
3 files changed, 41 insertions, 9 deletions
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 39161127c..f9d74e4fb 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -55,6 +55,7 @@ else {
$SOURCE_ID = $source;
+
function rcmail_get_edit_record()
{
global $RCMAIL, $CONTACTS;
@@ -105,7 +106,6 @@ function rcmail_contact_edithead($attrib)
return $form_start . $out . $form_end;
}
-
function rcmail_contact_editform($attrib)
{
global $RCMAIL, $CONTACT_COLTYPES;
@@ -167,7 +167,6 @@ function rcmail_contact_editform($attrib)
return $form_start . $out . $form_end;
}
-
function rcmail_upload_photo_form($attrib)
{
global $OUTPUT;
@@ -204,17 +203,18 @@ function rcmail_upload_photo_form($attrib)
return $out;
}
-
// similar function as in /steps/settings/edit_identity.inc
function get_form_tags($attrib)
{
- global $CONTACTS, $EDIT_FORM, $RCMAIL;
+ global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID;
$form_start = $form_end = '';
if (empty($EDIT_FORM)) {
- $hiddenfields = new html_hiddenfield(array(
- 'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
+ $hiddenfields = new html_hiddenfield();
+
+ if ($RCMAIL->action == 'edit')
+ $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID));
$hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
@@ -234,12 +234,36 @@ function get_form_tags($attrib)
return array($form_start, $form_end);
}
+function rcmail_source_selector($attrib)
+{
+ global $RCMAIL, $SOURCE_ID;
+
+ $sources_list = $RCMAIL->get_address_sources(true);
+
+ if (count($sources_list) < 2) {
+ $source = $sources_list[$SOURCE_ID];
+ $hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID));
+ return html::span($attrib, Q($source['name']) . $hiddenfield->show());
+ }
+
+ $attrib['name'] = '_source';
+ $attrib['onchange'] = JS_OBJECT_NAME . ".command('save', 'reload', this.form)";
+
+ $select = new html_select($attrib);
+
+ foreach ($sources_list as $source)
+ $select->add($source['name'], $source['id']);
+
+ return $select->show($SOURCE_ID);
+}
+
$OUTPUT->add_handlers(array(
'contactedithead' => 'rcmail_contact_edithead',
'contacteditform' => 'rcmail_contact_editform',
'contactphoto' => 'rcmail_contact_photo',
'photouploadform' => 'rcmail_upload_photo_form',
+ 'sourceselector' => 'rcmail_source_selector',
));
if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd'))
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index d0be00dbb..4c930c80b 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -68,20 +68,22 @@ if (!$RCMAIL->action && !$OUTPUT->ajax_call) {
if (!strlen($source) || !isset($js_list[$source]))
$source = $js_list[key($js_list)]['id'];
- // find writeable source
+ // count writeable sources
+ $writeable = 0;
foreach ($js_list as $s) {
if (!$s['readonly']) {
- $OUTPUT->set_env('writable_source', $s['id']);
- break;
+ $writeable++;
}
}
$search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
$OUTPUT->set_env('search_mods', $search_mods);
$OUTPUT->set_env('address_sources', $js_list);
+ $OUTPUT->set_env('writable_source', $writeable);
$OUTPUT->set_pagetitle(rcube_label('addressbook'));
$_SESSION['addressbooks_count'] = count($js_list);
+ $_SESSION['addressbooks_count_writeable'] = $writeable;
$CONTACTS = rcmail_contact_source($source, true);
}
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index 19d8f8c7d..e1986efeb 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -24,6 +24,12 @@ $cid = get_input_value('_cid', RCUBE_INPUT_POST);
$return_action = empty($cid) ? 'add' : 'edit';
+// Source changed, display the form again
+if (!empty($_GET['_reload'])) {
+ rcmail_overwrite_action($return_action);
+ return;
+}
+
// cannot edit record
if ($CONTACTS->readonly) {
$OUTPUT->show_message('contactreadonly', 'error');