]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_identity.inc
Imported Upstream version 0.2~alpha
[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-2007, 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 1407 2008-05-19 17:47:45Z thomasb $
19
20 */
21
22 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
23 $a_html_cols = array('signature');
24 $a_boolean_cols = array('standard', 'html_signature');
25 $updated = $default_id = false;
26
27 // check input
28 if (empty($_POST['_name']) || empty($_POST['_email']))
29   {
30   $OUTPUT->show_message('formincomplete', 'warning');
31   rcmail_overwrite_action('edit-identitiy');
32   return;
33   }
34
35
36 $save_data = array();
37 foreach ($a_save_cols as $col)
38 {
39   $fname = '_'.$col;
40   if (isset($_POST[$fname]))
41     $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols));
42 }
43
44 // set "off" values for checkboxes that were not checked, and therefore
45 // not included in the POST body.
46 foreach ($a_boolean_cols as $col)
47 {
48   $fname = '_' . $col;
49   if (!isset($_POST[$fname]))
50     $save_data[$col] = 0;
51 }
52
53
54 // update an existing contact
55 if ($_POST['_iid'])
56 {
57   if ($updated = $USER->update_identity(get_input_value('_iid', RCUBE_INPUT_POST), $save_data))
58   {
59     $OUTPUT->show_message('successfullysaved', 'confirmation');
60     
61     if (!empty($_POST['_standard']))
62       $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
63     
64     if ($_POST['_framed'])
65     {
66       // update the changed col in list
67       // ...      
68     }
69   }
70   else if ($DB->is_error())
71   {
72     // show error message
73     $OUTPUT->show_message('errorsaving', 'error');
74     rcmail_overwrite_action('edit-identitiy');
75     return;
76   }
77 }
78
79 // insert a new identity record
80 else
81 {
82   if ($insert_id = $USER->insert_identity($save_data))
83   {
84     $OUTPUT->show_message('successfullysaved', 'confirmation');
85     
86     $_GET['_iid'] = $insert_id;
87
88     if (!empty($_POST['_standard']))
89       $default_id = $insert_id;
90   }
91   else
92   {
93     // show error message
94     $OUTPUT->show_message('errorsaving', 'error');
95     rcmail_overwrite_action('edit-identity');
96     return;
97   }
98 }
99
100
101 // mark all other identities as 'not-default'
102 if ($default_id)
103   $USER->set_default($default_id);
104
105 // go to next step
106 rcmail_overwrite_action('identities');
107
108 ?>