4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/save.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Save a contact entry or to add a new one |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: save.inc 4166 2010-11-02 09:27:03Z alec $
22 $cid = get_input_value('_cid', RCUBE_INPUT_POST);
23 $return_action = empty($cid) ? 'add' : 'edit';
26 if ($CONTACTS->readonly) {
27 $OUTPUT->show_message('contactreadonly', 'error');
28 rcmail_overwrite_action($return_action);
33 if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST))) {
34 $OUTPUT->show_message('formincomplete', 'warning');
35 rcmail_overwrite_action($return_action);
40 // setup some vars we need
41 $a_save_cols = array('name', 'firstname', 'surname', 'email');
44 // read POST values into hash array
45 foreach ($a_save_cols as $col) {
47 if (isset($_POST[$fname]))
48 $a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
52 $_email = idn_to_ascii($a_record['email']);
53 if (!check_email($_email, false)) {
54 $OUTPUT->show_message('emailformaterror', 'warning', array('email' => $_email));
55 rcmail_overwrite_action($return_action);
59 // update an existing contact
62 $plugin = $RCMAIL->plugins->exec_hook('contact_update',
63 array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
64 $a_record = $plugin['record'];
66 if (!$plugin['abort'])
67 $result = $CONTACTS->update($cid, $a_record);
69 $result = $plugin['result'];
73 if (is_string($result) && strlen($result)>1) {
75 // change cid in POST for 'show' action
76 $_POST['_cid'] = $newcid;
79 // define list of cols to be displayed
81 $record = $CONTACTS->get_record($newcid ? $newcid : $cid, true);
83 foreach (array('name', 'email') as $col)
84 $a_js_cols[] = (string)$record[$col];
86 // update the changed col in list
87 $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols, $newcid);
90 $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
91 rcmail_overwrite_action('show');
95 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
96 rcmail_overwrite_action('show');
100 // insert a new contact
102 // check for existing contacts
103 $existing = $CONTACTS->search('email', $a_record['email'], true, false);
105 // show warning message
106 if ($existing->count) {
107 $OUTPUT->show_message('contactexists', 'warning', null, false);
108 rcmail_overwrite_action('add');
112 $plugin = $RCMAIL->plugins->exec_hook('contact_create', array(
113 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
114 $a_record = $plugin['record'];
116 // insert record and send response
117 if (!$plugin['abort'])
118 $insert_id = $CONTACTS->insert($a_record);
120 $insert_id = $plugin['result'];
124 // add contact row or jump to the page where it should appear
126 $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
128 rcmail_js_contacts_list($result, 'parent.');
129 $OUTPUT->command('parent.contact_list.select', $insert_id);
131 // update record count display
133 $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
136 $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
137 $OUTPUT->send('iframe');
140 // show error message
141 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
142 rcmail_overwrite_action('add');