thomascube
2005-11-06 10a699759d4f106f29c077a6d65d3b8d212825e5
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
10a699 25 // check input
T 26 if (empty($_POST['_name']) || empty($_POST['_email']))
27   {
28   show_message('formincomplete', 'warning');
29   rcmail_overwrite_action('edit-identitiy');
30   return;
31   }
32
33
4e17e6 34 // update an existing contact
T 35 if ($_POST['_iid'])
36   {
37   $a_write_sql = array();
38
39   foreach ($a_save_cols as $col)
40     {
41     $fname = '_'.$col;
42     if (!isset($_POST[$fname]))
43       continue;
44
10a699 45     $a_write_sql[] = sprintf("%s=%s", $DB->quoteIdentifier($col), $DB->quote(strip_tags($_POST[$fname])));
4e17e6 46     }
T 47
48   if (sizeof($a_write_sql))
49     {
d7cb77 50     $DB->query("UPDATE ".get_table_name('identities')."
S 51                 SET ".join(', ', $a_write_sql)."
52                 WHERE  identity_id=?
53                 AND    user_id=?
54                 AND    del<>'1'",
55                 $_POST['_iid'],
56                 $_SESSION['user_id']);
4e17e6 57                        
T 58     $updated = $DB->affected_rows();
59     }
60        
61   if ($updated)
62     {
63     show_message('successfullysaved', 'confirmation');
64
65     // mark all other identities as 'not-default'
d7cb77 66     $DB->query("UPDATE ".get_table_name('identities')."
S 67                 SET ".$DB->quoteIdentifier('default')."='0'
10a699 68                 WHERE  user_id=?
T 69                 AND    identity_id<>?
d7cb77 70                 AND    del<>'1'",
10a699 71                 $_SESSION['user_id'],
T 72                 $_POST['_iid']);
4e17e6 73     
T 74     if ($_POST['_framed'])
75       {
76       // update the changed col in list
77       // ...      
78       }
79     }
80   else
81     {
82     // show error message
10a699 83     show_message('errorsaving', 'error');
T 84     rcmail_overwrite_action('edit-identitiy');
4e17e6 85     }
T 86   }
87
88 // insert a new contact
89 else
90   {
91   $a_insert_cols = $a_insert_values = array();
92
93   foreach ($a_save_cols as $col)
94     {
95     $fname = '_'.$col;
96     if (!isset($_POST[$fname]))
97       continue;
98     
d7cb77 99     $a_insert_cols[] = $DB->quoteIdentifier($col);
10a699 100     $a_insert_values[] = $DB->quote(strip_tags($_POST[$fname]));
4e17e6 101     }
T 102     
103   if (sizeof($a_insert_cols))
104     {
d7cb77 105     $DB->query("INSERT INTO ".get_table_name('identities')."
S 106                 (user_id, ".join(', ', $a_insert_cols).")
107                 VALUES (?, ".join(', ', $a_insert_values).")",
108                 $_SESSION['user_id']);
4e17e6 109                        
T 110     $insert_id = $DB->insert_id();
111     }
112     
113   if ($insert_id)
114     {
115     $_GET['_iid'] = $insert_id;
116
117     if ($_POST['_framed'])
118       {
119       // add contact row or jump to the page where it should appear
120       // ....
121       }
122     }
123   else
124     {
125     // show error message
10a699 126     show_message('errorsaving', 'error');
T 127     rcmail_overwrite_action('edit-identitiy');
4e17e6 128     }
T 129   }
130
131
132 // go to next step
10a699 133 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
4e17e6 134
T 135 ?>