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 2889 2009-08-29 18:41:17Z alec $
22 $cid = get_input_value('_cid', RCUBE_INPUT_POST);
23 $return_action = empty($cid) ? 'add' : 'show';
26 if ($CONTACTS->readonly)
28 $OUTPUT->show_message('contactreadonly', 'error');
29 rcmail_overwrite_action($return_action);
34 if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)))
36 $OUTPUT->show_message('formincomplete', 'warning');
37 rcmail_overwrite_action($return_action);
42 // setup some vars we need
43 $a_save_cols = array('name', 'firstname', 'surname', 'email');
46 // read POST values into hash array
47 foreach ($a_save_cols as $col)
50 if (isset($_POST[$fname]))
51 $a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
54 // update an existing contact
57 $plugin = $RCMAIL->plugins->exec_hook('save_contact', array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
58 $a_record = $plugin['record'];
60 if (!$plugin['abort'] && ($result = $CONTACTS->update($cid, $a_record)))
63 if (is_string($result) && strlen($result)>1) {
65 // change cid in POST for 'show' action
66 $_POST['_cid'] = $newcid;
69 // define list of cols to be displayed
71 $record = $CONTACTS->get_record($newcid ? $newcid : $cid, true);
73 foreach (array('name', 'email') as $col)
74 $a_js_cols[] = (string)$record[$col];
76 // update the changed col in list
77 $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols, $newcid);
80 $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
81 rcmail_overwrite_action('show');
86 $OUTPUT->show_message('errorsaving', 'error', null, false);
87 rcmail_overwrite_action('show');
91 // insert a new contact
94 // check for existing contacts
95 $existing = $CONTACTS->search('email', $a_record['email'], true, false);
97 // show warning message
100 $OUTPUT->show_message('contactexists', 'warning', null, false);
101 rcmail_overwrite_action('add');
105 $plugin = $RCMAIL->plugins->exec_hook('create_contact', array('record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
106 $a_record = $plugin['record'];
108 // insert record and send response
109 if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record)))
111 // add contact row or jump to the page where it should appear
113 $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
115 rcmail_js_contacts_list($result, 'parent.');
116 $OUTPUT->command('parent.contact_list.select', $insert_id);
118 // update record count display
120 $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
123 $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
124 rcmail_overwrite_action('show');
125 $_GET['_cid'] = $insert_id;
129 // show error message
130 $OUTPUT->show_message('errorsaving', 'error', null, false);
131 rcmail_overwrite_action('add');