4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/save.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, 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 543 2007-04-28 18:07:12Z thomasb $
23 if ($CONTACTS->readonly)
25 $OUTPUT->show_message('contactreadonly', 'error');
26 rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
31 if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)) && $_framed)
33 $OUTPUT->show_message('formincomplete', 'warning');
34 rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show');
39 // setup some vars we need
40 $a_save_cols = array('name', 'firstname', 'surname', 'email');
42 $cid = get_input_value('_cid', RCUBE_INPUT_POST);
44 // read POST values into hash array
45 foreach ($a_save_cols as $col)
48 if (isset($_POST[$fname]))
49 $a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST);
52 // update an existing contact
55 if ($CONTACTS->update($cid, $a_record))
59 // define list of cols to be displayed
61 $record = $CONTACTS->get_record($cid, true);
63 foreach (array('name', 'email') as $col)
64 $a_js_cols[] = (string)$record[$col];
66 // update the changed col in list
67 $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols);
71 $OUTPUT->show_message('successfullysaved', 'confirmation');
72 rcmail_overwrite_action('show');
77 $OUTPUT->show_message('errorsaving', 'error');
78 rcmail_overwrite_action('show');
82 // insert a new contact
85 // check for existing contacts
86 $existing = $CONTACTS->search('email', $a_record['email'], false);
88 // show warning message
91 $OUTPUT->show_message('contactexists', 'warning');
92 rcmail_overwrite_action('add');
96 // insert record and send response
97 if ($insert_id = $CONTACTS->insert($a_record))
101 // add contact row or jump to the page where it should appear
103 $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
105 rcmail_js_contacts_list($result, 'parent.');
106 $OUTPUT->command('parent.contact_list.select', $insert_id);
108 // update record count display
110 $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
114 $OUTPUT->show_message('successfullysaved', 'confirmation');
115 rcmail_overwrite_action('show');
116 $_GET['_cid'] = $insert_id;
120 // show error message
121 $OUTPUT->show_message('errorsaving', 'error');
122 rcmail_overwrite_action('add');