commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/settings/save_identity.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 an identity record or to add a new one | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
$a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'default'); |
|
23 |
|
|
24 |
|
|
25 |
// update an existing contact |
|
26 |
if ($_POST['_iid']) |
|
27 |
{ |
|
28 |
$a_write_sql = array(); |
|
29 |
|
|
30 |
foreach ($a_save_cols as $col) |
|
31 |
{ |
|
32 |
$fname = '_'.$col; |
|
33 |
if (!isset($_POST[$fname])) |
|
34 |
continue; |
|
35 |
|
|
36 |
$a_write_sql[] = sprintf("`%s`='%s'", $col, addslashes($_POST[$fname])); |
|
37 |
} |
|
38 |
|
|
39 |
if (sizeof($a_write_sql)) |
|
40 |
{ |
d7cb77
|
41 |
$DB->query("UPDATE ".get_table_name('identities')." |
S |
42 |
SET ".join(', ', $a_write_sql)." |
|
43 |
WHERE identity_id=? |
|
44 |
AND user_id=? |
|
45 |
AND del<>'1'", |
|
46 |
$_POST['_iid'], |
|
47 |
$_SESSION['user_id']); |
4e17e6
|
48 |
|
T |
49 |
$updated = $DB->affected_rows(); |
|
50 |
} |
|
51 |
|
|
52 |
if ($updated) |
|
53 |
{ |
|
54 |
show_message('successfullysaved', 'confirmation'); |
|
55 |
|
|
56 |
// mark all other identities as 'not-default' |
d7cb77
|
57 |
$DB->query("UPDATE ".get_table_name('identities')." |
S |
58 |
SET ".$DB->quoteIdentifier('default')."='0' |
|
59 |
WHERE identity_id!=? |
|
60 |
AND user_id=? |
|
61 |
AND del<>'1'", |
|
62 |
$_POST['_iid'], |
|
63 |
$_SESSION['user_id']); |
4e17e6
|
64 |
|
T |
65 |
if ($_POST['_framed']) |
|
66 |
{ |
|
67 |
// update the changed col in list |
|
68 |
// ... |
|
69 |
} |
|
70 |
} |
|
71 |
else |
|
72 |
{ |
|
73 |
// show error message |
|
74 |
|
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
// insert a new contact |
|
79 |
else |
|
80 |
{ |
|
81 |
$a_insert_cols = $a_insert_values = array(); |
|
82 |
|
|
83 |
foreach ($a_save_cols as $col) |
|
84 |
{ |
|
85 |
$fname = '_'.$col; |
|
86 |
if (!isset($_POST[$fname])) |
|
87 |
continue; |
|
88 |
|
d7cb77
|
89 |
$a_insert_cols[] = $DB->quoteIdentifier($col); |
4e17e6
|
90 |
$a_insert_values[] = sprintf("'%s'", addslashes($_POST[$fname])); |
T |
91 |
} |
|
92 |
|
|
93 |
if (sizeof($a_insert_cols)) |
|
94 |
{ |
d7cb77
|
95 |
$DB->query("INSERT INTO ".get_table_name('identities')." |
S |
96 |
(user_id, ".join(', ', $a_insert_cols).") |
|
97 |
VALUES (?, ".join(', ', $a_insert_values).")", |
|
98 |
$_SESSION['user_id']); |
4e17e6
|
99 |
|
T |
100 |
$insert_id = $DB->insert_id(); |
|
101 |
} |
|
102 |
|
|
103 |
if ($insert_id) |
|
104 |
{ |
|
105 |
$_GET['_iid'] = $insert_id; |
|
106 |
|
|
107 |
if ($_POST['_framed']) |
|
108 |
{ |
|
109 |
// add contact row or jump to the page where it should appear |
|
110 |
// .... |
|
111 |
} |
|
112 |
} |
|
113 |
else |
|
114 |
{ |
|
115 |
// show error message |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
// go to next step |
|
121 |
if ($_POST['_framed']) |
|
122 |
$_action = 'edit-identitiy'; |
|
123 |
else |
|
124 |
$_action = 'identities'; |
|
125 |
|
|
126 |
|
|
127 |
// overwrite action variable |
|
128 |
$OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action)); |
|
129 |
|
|
130 |
?> |