commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/save.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
f11541
|
8 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Save a contact entry or to add a new one | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
f11541
|
22 |
// cannot edit record |
T |
23 |
if ($CONTACTS->readonly) |
|
24 |
{ |
|
25 |
$OUTPUT->show_message('contactreadonly', 'error'); |
ea7c46
|
26 |
rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show'); |
10a699
|
27 |
return; |
f11541
|
28 |
} |
T |
29 |
|
|
30 |
// check input |
c1b3c4
|
31 |
if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST))) |
f11541
|
32 |
{ |
T |
33 |
$OUTPUT->show_message('formincomplete', 'warning'); |
|
34 |
rcmail_overwrite_action(empty($_POST['_cid']) ? 'add' : 'show'); |
|
35 |
return; |
|
36 |
} |
|
37 |
|
10a699
|
38 |
|
d1d2c4
|
39 |
// setup some vars we need |
64009e
|
40 |
$a_save_cols = array('name', 'firstname', 'surname', 'email'); |
f11541
|
41 |
$a_record = array(); |
T |
42 |
$cid = get_input_value('_cid', RCUBE_INPUT_POST); |
|
43 |
|
|
44 |
// read POST values into hash array |
|
45 |
foreach ($a_save_cols as $col) |
|
46 |
{ |
|
47 |
$fname = '_'.$col; |
|
48 |
if (isset($_POST[$fname])) |
|
49 |
$a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST); |
|
50 |
} |
10a699
|
51 |
|
4e17e6
|
52 |
// update an existing contact |
f11541
|
53 |
if (!empty($cid)) |
T |
54 |
{ |
|
55 |
if ($CONTACTS->update($cid, $a_record)) |
4e17e6
|
56 |
{ |
c1b3c4
|
57 |
// define list of cols to be displayed |
T |
58 |
$a_js_cols = array(); |
|
59 |
$record = $CONTACTS->get_record($cid, true); |
f11541
|
60 |
|
c1b3c4
|
61 |
foreach (array('name', 'email') as $col) |
T |
62 |
$a_js_cols[] = (string)$record[$col]; |
4e17e6
|
63 |
|
c1b3c4
|
64 |
// update the changed col in list |
T |
65 |
$OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols); |
6b47de
|
66 |
|
T |
67 |
// show confirmation |
f11541
|
68 |
$OUTPUT->show_message('successfullysaved', 'confirmation'); |
6b47de
|
69 |
rcmail_overwrite_action('show'); |
4e17e6
|
70 |
} |
f11541
|
71 |
else |
T |
72 |
{ |
|
73 |
// show error message |
|
74 |
$OUTPUT->show_message('errorsaving', 'error'); |
|
75 |
rcmail_overwrite_action('show'); |
|
76 |
} |
|
77 |
} |
4e17e6
|
78 |
|
T |
79 |
// insert a new contact |
|
80 |
else |
f11541
|
81 |
{ |
10a699
|
82 |
// check for existing contacts |
3fc00e
|
83 |
$existing = $CONTACTS->search('email', $a_record['email'], true, false); |
f11541
|
84 |
|
10a699
|
85 |
// show warning message |
f11541
|
86 |
if ($existing->count) |
T |
87 |
{ |
|
88 |
$OUTPUT->show_message('contactexists', 'warning'); |
|
89 |
rcmail_overwrite_action('add'); |
10a699
|
90 |
return; |
f11541
|
91 |
} |
4e17e6
|
92 |
|
f11541
|
93 |
// insert record and send response |
T |
94 |
if ($insert_id = $CONTACTS->insert($a_record)) |
|
95 |
{ |
c1b3c4
|
96 |
// add contact row or jump to the page where it should appear |
T |
97 |
$CONTACTS->reset(); |
|
98 |
$result = $CONTACTS->search($CONTACTS->primary_key, $insert_id); |
4e17e6
|
99 |
|
c1b3c4
|
100 |
rcmail_js_contacts_list($result, 'parent.'); |
T |
101 |
$OUTPUT->command('parent.contact_list.select', $insert_id); |
d1d2c4
|
102 |
|
c1b3c4
|
103 |
// update record count display |
T |
104 |
$CONTACTS->reset(); |
|
105 |
$OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text()); |
d1d2c4
|
106 |
|
S |
107 |
// show confirmation |
f11541
|
108 |
$OUTPUT->show_message('successfullysaved', 'confirmation'); |
6b47de
|
109 |
rcmail_overwrite_action('show'); |
f11541
|
110 |
$_GET['_cid'] = $insert_id; |
4e17e6
|
111 |
} |
f11541
|
112 |
else |
T |
113 |
{ |
|
114 |
// show error message |
|
115 |
$OUTPUT->show_message('errorsaving', 'error'); |
|
116 |
rcmail_overwrite_action('add'); |
|
117 |
} |
|
118 |
} |
4e17e6
|
119 |
|
d1d2c4
|
120 |
?> |