]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/save_identity.inc
Imported Upstream version 0.3
[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-2009, 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 2778 2009-07-21 16:02:33Z thomasb $
19
20 */
21
22 define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
23
24 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
25 $a_html_cols = array('signature');
26 $a_boolean_cols = array('standard', 'html_signature');
27 $updated = $default_id = false;
28
29 // check input
30 if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3))
31   {
32   $OUTPUT->show_message('formincomplete', 'warning');
33   rcmail_overwrite_action('edit-identity');
34   return;
35   }
36
37
38 $save_data = array();
39 foreach ($a_save_cols as $col)
40 {
41   $fname = '_'.$col;
42   if (isset($_POST[$fname]))
43     $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols));
44 }
45
46 // set "off" values for checkboxes that were not checked, and therefore
47 // not included in the POST body.
48 foreach ($a_boolean_cols as $col)
49 {
50   $fname = '_' . $col;
51   if (!isset($_POST[$fname]))
52     $save_data[$col] = 0;
53 }
54
55 // unset email address if user has no rights to change it
56 if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3)
57   unset($save_data['email']);
58
59
60 // update an existing contact
61 if ($_POST['_iid'])
62 {
63   $iid = get_input_value('_iid', RCUBE_INPUT_POST);
64   $plugin = $RCMAIL->plugins->exec_hook('save_identity', array('id' => $iid, 'record' => $save_data));
65   $save_data = $plugin['record'];
66
67   if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data)))
68   {
69     $OUTPUT->show_message('successfullysaved', 'confirmation');
70     
71     if (!empty($_POST['_standard']))
72       $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
73     
74     if ($_POST['_framed'])
75     {
76       // update the changed col in list
77       // ...      
78     }
79   }
80   else if ($plugin['abort'] || $DB->is_error())
81   {
82     // show error message
83     $OUTPUT->show_message('errorsaving', 'error', null, false);
84     rcmail_overwrite_action('edit-identity');
85     return;
86   }
87 }
88
89 // insert a new identity record
90 else if (IDENTITIES_LEVEL < 2)
91 {
92   if (IDENTITIES_LEVEL == 1)
93     $save_data['email'] = $RCMAIL->user->get_username();
94
95   $plugin = $RCMAIL->plugins->exec_hook('create_identity', array('record' => $save_data));
96   $save_data = $plugin['record'];
97
98   if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data)))
99   {
100     $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
101     
102     $_GET['_iid'] = $insert_id;
103
104     if (!empty($_POST['_standard']))
105       $default_id = $insert_id;
106   }
107   else
108   {
109     // show error message
110     $OUTPUT->show_message('errorsaving', 'error', null, false);
111     rcmail_overwrite_action('edit-identity');
112     return;
113   }
114 }
115 else
116   $OUTPUT->show_message('opnotpermitted', 'error');
117
118
119 // mark all other identities as 'not-default'
120 if ($default_id)
121   $USER->set_default($default_id);
122
123 // go to next step
124 rcmail_overwrite_action('identities');
125
126 ?>