]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_identity.inc
Imported Upstream version 0.1~beta2.2~dfsg
[roundcube.git] / program / steps / settings / save_identity.inc
1 <?php
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                      |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
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: save_identity.inc 430 2006-12-22 22:31:38Z thomasb $
19
20 */
21
22 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature');
23 $a_html_cols = array('signature');
24
25
26 // check input
27 if (empty($_POST['_name']) || empty($_POST['_email']))
28   {
29   show_message('formincomplete', 'warning');
30   rcmail_overwrite_action('edit-identitiy');
31   return;
32   }
33
34
35 // update an existing contact
36 if ($_POST['_iid'])
37   {
38   $a_write_sql = array();
39
40   foreach ($a_save_cols as $col)
41     {
42     $fname = '_'.$col;
43     if (!isset($_POST[$fname]))
44       continue;
45
46     $a_write_sql[] = sprintf("%s=%s",
47                              $DB->quoteIdentifier($col),
48                              $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))));
49     }
50
51   if (sizeof($a_write_sql))
52     {
53     $DB->query("UPDATE ".get_table_name('identities')."
54                 SET ".join(', ', $a_write_sql)."
55                 WHERE  identity_id=?
56                 AND    user_id=?
57                 AND    del<>1",
58                 $_POST['_iid'],
59                 $_SESSION['user_id']);
60                        
61     $updated = $DB->affected_rows();
62     }
63        
64   if ($updated && !empty($_POST['_standard']))
65     {
66     show_message('successfullysaved', 'confirmation');
67
68     // mark all other identities as 'not-default'
69     $DB->query("UPDATE ".get_table_name('identities')."
70                 SET ".$DB->quoteIdentifier('standard')."='0'
71                 WHERE  user_id=?
72                 AND    identity_id<>?
73                 AND    del<>1",
74                 $_SESSION['user_id'],
75                 $_POST['_iid']);
76     
77     if ($_POST['_framed'])
78       {
79       // update the changed col in list
80       // ...      
81       }
82     }
83   else if ($DB->is_error())
84     {
85     // show error message
86     show_message('errorsaving', 'error');
87     rcmail_overwrite_action('edit-identitiy');
88     }
89   }
90
91 // insert a new contact
92 else
93   {
94   $a_insert_cols = $a_insert_values = array();
95
96   foreach ($a_save_cols as $col)
97     {
98     $fname = '_'.$col;
99     if (!isset($_POST[$fname]))
100       continue;
101     
102     $a_insert_cols[] = $DB->quoteIdentifier($col);
103     $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
104     }
105     
106   if (sizeof($a_insert_cols))
107     {
108     $DB->query("INSERT INTO ".get_table_name('identities')."
109                 (user_id, ".join(', ', $a_insert_cols).")
110                 VALUES (?, ".join(', ', $a_insert_values).")",
111                 $_SESSION['user_id']);
112
113     $insert_id = $DB->insert_id(get_sequence_name('identities'));
114     }
115     
116   if ($insert_id)
117     {
118     $_GET['_iid'] = $insert_id;
119
120     if ($_POST['_framed'])
121       {
122       // add contact row or jump to the page where it should appear
123       // ....
124       }
125     }
126   else
127     {
128     // show error message
129     show_message('errorsaving', 'error');
130     rcmail_overwrite_action('edit-identity');
131     }
132   }
133
134
135 // go to next step
136 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identity' : 'identities');
137
138 ?>