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 | |
|
8 |
| Copyright (C) 2005, 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 |
|
|
22 |
|
|
23 |
$a_save_cols = array('name', 'firstname', 'surname', 'email'); |
|
24 |
|
|
25 |
|
|
26 |
// update an existing contact |
|
27 |
if ($_POST['_cid']) |
|
28 |
{ |
|
29 |
$a_write_sql = array(); |
|
30 |
|
|
31 |
foreach ($a_save_cols as $col) |
|
32 |
{ |
|
33 |
$fname = '_'.$col; |
|
34 |
if (!isset($_POST[$fname])) |
|
35 |
continue; |
|
36 |
|
|
37 |
$a_write_sql[] = sprintf("%s='%s'", $col, addslashes($_POST[$fname])); |
|
38 |
} |
|
39 |
|
|
40 |
if (sizeof($a_write_sql)) |
|
41 |
{ |
d7cb77
|
42 |
$DB->query("UPDATE ".get_table_name('contacts')." |
S |
43 |
SET ".join(', ', $a_write_sql)." |
|
44 |
WHERE contact_id=? |
|
45 |
AND user_id=? |
|
46 |
AND del<>'1'", |
|
47 |
$_POST['_cid'], |
|
48 |
$_SESSION['user_id']); |
4e17e6
|
49 |
|
T |
50 |
$updated = $DB->affected_rows(); |
|
51 |
} |
|
52 |
|
|
53 |
if ($updated) |
|
54 |
{ |
|
55 |
$_action = 'show'; |
|
56 |
show_message('successfullysaved', 'confirmation'); |
|
57 |
|
|
58 |
if ($_POST['_framed']) |
|
59 |
{ |
|
60 |
// define list of cols to be displayed |
|
61 |
$a_show_cols = array('name', 'email'); |
|
62 |
$a_js_cols = array(); |
|
63 |
|
d7cb77
|
64 |
$sql_result = $DB->query("SELECT * FROM ".get_table_name('contacts')." |
S |
65 |
WHERE contact_id=? |
|
66 |
AND user_id=? |
|
67 |
AND del<>'1'", |
4e17e6
|
68 |
$_POST['_cid'], |
d7cb77
|
69 |
$_SESSION['user_id']); |
4e17e6
|
70 |
|
T |
71 |
$sql_arr = $DB->fetch_assoc($sql_result); |
|
72 |
foreach ($a_show_cols as $col) |
|
73 |
$a_js_cols[] = (string)$sql_arr[$col]; |
|
74 |
|
|
75 |
// update the changed col in list |
|
76 |
$OUTPUT->add_script(sprintf("if(parent.%s)parent.%s.update_contact_row('%d', %s);", |
|
77 |
$JS_OBJECT_NAME, |
|
78 |
$JS_OBJECT_NAME, |
|
79 |
$_POST['_cid'], |
|
80 |
array2js($a_js_cols))); |
|
81 |
|
|
82 |
// show confirmation |
|
83 |
show_message('successfullysaved', 'confirmation'); |
|
84 |
} |
|
85 |
} |
|
86 |
else |
|
87 |
{ |
|
88 |
// show error message |
|
89 |
show_message('errorsaving', 'error'); |
|
90 |
$_action = 'show'; |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
// insert a new contact |
|
95 |
else |
|
96 |
{ |
|
97 |
$a_insert_cols = $a_insert_values = array(); |
|
98 |
|
|
99 |
foreach ($a_save_cols as $col) |
|
100 |
{ |
|
101 |
$fname = '_'.$col; |
|
102 |
if (!isset($_POST[$fname])) |
|
103 |
continue; |
|
104 |
|
|
105 |
$a_insert_cols[] = $col; |
|
106 |
$a_insert_values[] = sprintf("'%s'", addslashes($_POST[$fname])); |
|
107 |
} |
|
108 |
|
|
109 |
if (sizeof($a_insert_cols)) |
|
110 |
{ |
d7cb77
|
111 |
$DB->query("INSERT INTO ".get_table_name('contacts')." |
S |
112 |
(user_id, ".join(', ', $a_insert_cols).") |
|
113 |
VALUES (?, ".join(', ', $a_insert_values).")", |
|
114 |
$_SESSION['user_id']); |
4e17e6
|
115 |
|
T |
116 |
$insert_id = $DB->insert_id(); |
|
117 |
} |
|
118 |
|
|
119 |
if ($insert_id) |
|
120 |
{ |
|
121 |
$_action = 'show'; |
|
122 |
$_GET['_cid'] = $insert_id; |
|
123 |
|
|
124 |
if ($_POST['_framed']) |
|
125 |
{ |
|
126 |
// add contact row or jump to the page where it should appear |
|
127 |
$commands = sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME); |
d7cb77
|
128 |
$sql_result = $DB->query("SELECT * FROM ".get_table_name('contacts')." |
S |
129 |
WHERE contact_id=? |
|
130 |
AND user_id=?", |
|
131 |
$insert_id, |
|
132 |
$_SESSION['user_id']); |
4e17e6
|
133 |
$commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME); |
T |
134 |
|
|
135 |
$commands .= sprintf("if(parent.%s)parent.%s.select('%d');\n", |
|
136 |
$JS_OBJECT_NAME, |
|
137 |
$JS_OBJECT_NAME, |
|
138 |
$insert_id); |
|
139 |
|
|
140 |
// update record count display |
|
141 |
$commands .= sprintf("if(parent.%s)parent.%s.set_rowcount('%s');\n", |
|
142 |
$JS_OBJECT_NAME, |
|
143 |
$JS_OBJECT_NAME, |
|
144 |
rcmail_get_rowcount_text()); |
|
145 |
|
|
146 |
$OUTPUT->add_script($commands); |
|
147 |
|
|
148 |
// show confirmation |
|
149 |
show_message('successfullysaved', 'confirmation'); |
|
150 |
} |
|
151 |
} |
|
152 |
else |
|
153 |
{ |
|
154 |
// show error message |
|
155 |
show_message('errorsaving', 'error'); |
|
156 |
$_action = 'add'; |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
|
|
161 |
?> |