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 | |
549933
|
8 |
| Copyright (C) 2005-2009, 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 |
|
57f0c8
|
22 |
$cid = get_input_value('_cid', RCUBE_INPUT_POST); |
T |
23 |
$return_action = empty($cid) ? 'add' : 'show'; |
|
24 |
|
f11541
|
25 |
// cannot edit record |
T |
26 |
if ($CONTACTS->readonly) |
|
27 |
{ |
|
28 |
$OUTPUT->show_message('contactreadonly', 'error'); |
57f0c8
|
29 |
rcmail_overwrite_action($return_action); |
10a699
|
30 |
return; |
f11541
|
31 |
} |
T |
32 |
|
|
33 |
// check input |
c1b3c4
|
34 |
if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST))) |
f11541
|
35 |
{ |
T |
36 |
$OUTPUT->show_message('formincomplete', 'warning'); |
57f0c8
|
37 |
rcmail_overwrite_action($return_action); |
f11541
|
38 |
return; |
T |
39 |
} |
|
40 |
|
10a699
|
41 |
|
d1d2c4
|
42 |
// setup some vars we need |
64009e
|
43 |
$a_save_cols = array('name', 'firstname', 'surname', 'email'); |
f11541
|
44 |
$a_record = array(); |
T |
45 |
|
|
46 |
// read POST values into hash array |
|
47 |
foreach ($a_save_cols as $col) |
|
48 |
{ |
|
49 |
$fname = '_'.$col; |
|
50 |
if (isset($_POST[$fname])) |
|
51 |
$a_record[$col] = get_input_value($fname, RCUBE_INPUT_POST); |
|
52 |
} |
10a699
|
53 |
|
4e17e6
|
54 |
// update an existing contact |
f11541
|
55 |
if (!empty($cid)) |
T |
56 |
{ |
119ad1
|
57 |
$plugin = $RCMAIL->plugins->exec_hook('contact_update', |
A |
58 |
array('id' => $cid, 'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); |
69f18a
|
59 |
$a_record = $plugin['record']; |
T |
60 |
|
e83f03
|
61 |
if (!$plugin['abort'] && ($result = $CONTACTS->update($cid, $a_record))) |
4e17e6
|
62 |
{ |
e83f03
|
63 |
// LDAP DN change |
A |
64 |
if (is_string($result) && strlen($result)>1) { |
|
65 |
$newcid = $result; |
|
66 |
// change cid in POST for 'show' action |
|
67 |
$_POST['_cid'] = $newcid; |
|
68 |
} |
|
69 |
|
c1b3c4
|
70 |
// define list of cols to be displayed |
T |
71 |
$a_js_cols = array(); |
e83f03
|
72 |
$record = $CONTACTS->get_record($newcid ? $newcid : $cid, true); |
f11541
|
73 |
|
c1b3c4
|
74 |
foreach (array('name', 'email') as $col) |
T |
75 |
$a_js_cols[] = (string)$record[$col]; |
4e17e6
|
76 |
|
c1b3c4
|
77 |
// update the changed col in list |
e83f03
|
78 |
$OUTPUT->command('parent.update_contact_row', $cid, $a_js_cols, $newcid); |
6b47de
|
79 |
|
T |
80 |
// show confirmation |
69f18a
|
81 |
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false); |
6b47de
|
82 |
rcmail_overwrite_action('show'); |
4e17e6
|
83 |
} |
f11541
|
84 |
else |
T |
85 |
{ |
|
86 |
// show error message |
69f18a
|
87 |
$OUTPUT->show_message('errorsaving', 'error', null, false); |
f11541
|
88 |
rcmail_overwrite_action('show'); |
T |
89 |
} |
|
90 |
} |
4e17e6
|
91 |
|
T |
92 |
// insert a new contact |
|
93 |
else |
f11541
|
94 |
{ |
10a699
|
95 |
// check for existing contacts |
3fc00e
|
96 |
$existing = $CONTACTS->search('email', $a_record['email'], true, false); |
b80a97
|
97 |
|
10a699
|
98 |
// show warning message |
f11541
|
99 |
if ($existing->count) |
T |
100 |
{ |
69f18a
|
101 |
$OUTPUT->show_message('contactexists', 'warning', null, false); |
f11541
|
102 |
rcmail_overwrite_action('add'); |
10a699
|
103 |
return; |
f11541
|
104 |
} |
4e17e6
|
105 |
|
e6ce00
|
106 |
$plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); |
69f18a
|
107 |
$a_record = $plugin['record']; |
T |
108 |
|
f11541
|
109 |
// insert record and send response |
69f18a
|
110 |
if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record))) |
f11541
|
111 |
{ |
c1b3c4
|
112 |
// add contact row or jump to the page where it should appear |
T |
113 |
$CONTACTS->reset(); |
|
114 |
$result = $CONTACTS->search($CONTACTS->primary_key, $insert_id); |
4e17e6
|
115 |
|
c1b3c4
|
116 |
rcmail_js_contacts_list($result, 'parent.'); |
T |
117 |
$OUTPUT->command('parent.contact_list.select', $insert_id); |
d1d2c4
|
118 |
|
c1b3c4
|
119 |
// update record count display |
T |
120 |
$CONTACTS->reset(); |
|
121 |
$OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text()); |
d1d2c4
|
122 |
|
S |
123 |
// show confirmation |
69f18a
|
124 |
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false); |
b80a97
|
125 |
$OUTPUT->send('iframe'); |
4e17e6
|
126 |
} |
f11541
|
127 |
else |
T |
128 |
{ |
|
129 |
// show error message |
69f18a
|
130 |
$OUTPUT->show_message('errorsaving', 'error', null, false); |
f11541
|
131 |
rcmail_overwrite_action('add'); |
T |
132 |
} |
|
133 |
} |
4e17e6
|
134 |
|
b25dfd
|
135 |
|