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 1407 2008-05-19 17:47:45Z 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)))
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))
57 // define list of cols to be displayed
59 $record = $CONTACTS->get_record($cid, true);
61 foreach (array('name', 'email') as $col)
62 $a_js_cols[] = (string)$record[$col];
64 // update the changed col in list
65 $OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols);
68 $OUTPUT->show_message('successfullysaved', 'confirmation');
69 rcmail_overwrite_action('show');
74 $OUTPUT->show_message('errorsaving', 'error');
75 rcmail_overwrite_action('show');
79 // insert a new contact
82 // check for existing contacts
83 $existing = $CONTACTS->search('email', $a_record['email'], true, false);
85 // show warning message
88 $OUTPUT->show_message('contactexists', 'warning');
89 rcmail_overwrite_action('add');
93 // insert record and send response
94 if ($insert_id = $CONTACTS->insert($a_record))
96 // add contact row or jump to the page where it should appear
98 $result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
100 rcmail_js_contacts_list($result, 'parent.');
101 $OUTPUT->command('parent.contact_list.select', $insert_id);
103 // update record count display
105 $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
108 $OUTPUT->show_message('successfullysaved', 'confirmation');
109 rcmail_overwrite_action('show');
110 $_GET['_cid'] = $insert_id;
114 // show error message
115 $OUTPUT->show_message('errorsaving', 'error');
116 rcmail_overwrite_action('add');