]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_identity.inc
Imported Upstream version 0.1
[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 938 2007-12-10 15:27:19Z 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 contact
80 else
81 {
82   if ($insert_id = $USER->insert_identity($save_data))
83   {
84     $_GET['_iid'] = $insert_id;
85
86     if (!empty($_POST['_standard']))
87       $default_id = $insert_id;
88
89     if ($_POST['_framed'])
90     {
91       // add contact row or jump to the page where it should appear
92       // ....
93     }
94   }
95   else
96   {
97     // show error message
98     $OUTPUT->show_message('errorsaving', 'error');
99     rcmail_overwrite_action('edit-identity');
100     return;
101   }
102 }
103
104
105 // mark all other identities as 'not-default'
106 if ($default_id)
107   $USER->set_default($default_id);
108
109 // go to next step
110 rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities');
111
112 ?>