thomascube
2009-11-02 0207c45c90818e7c7df64ea52c61050850dee13d
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                     |
549933 8  | Copyright (C) 2005-2009, 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
ec0171 22 define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
A 23
a0109c 24 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
ea7c46 25 $a_html_cols = array('signature');
a0109c 26 $a_boolean_cols = array('standard', 'html_signature');
6ec91f 27 $updated = $default_id = false;
4e17e6 28
10a699 29 // check input
ec0171 30 if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3))
10a699 31   {
f11541 32   $OUTPUT->show_message('formincomplete', 'warning');
407dcf 33   rcmail_overwrite_action('edit-identity');
10a699 34   return;
T 35   }
36
37
fba1f5 38 $save_data = array();
T 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 }
ec0171 54
A 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']);
fba1f5 58
T 59
4e17e6 60 // update an existing contact
T 61 if ($_POST['_iid'])
fba1f5 62 {
69f18a 63   $iid = get_input_value('_iid', RCUBE_INPUT_POST);
T 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)))
4e17e6 68   {
f11541 69     $OUTPUT->show_message('successfullysaved', 'confirmation');
6ec91f 70     
ea206d 71     if (!empty($_POST['_standard']))
6ec91f 72       $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
4e17e6 73     
T 74     if ($_POST['_framed'])
fba1f5 75     {
4e17e6 76       // update the changed col in list
T 77       // ...      
78     }
fba1f5 79   }
69f18a 80   else if ($plugin['abort'] || $DB->is_error())
fba1f5 81   {
4e17e6 82     // show error message
69f18a 83     $OUTPUT->show_message('errorsaving', 'error', null, false);
407dcf 84     rcmail_overwrite_action('edit-identity');
6ec91f 85     return;
4e17e6 86   }
fba1f5 87 }
4e17e6 88
c1b3c4 89 // insert a new identity record
ec0171 90 else if (IDENTITIES_LEVEL < 2)
fba1f5 91 {
ec0171 92   if (IDENTITIES_LEVEL == 1)
82c45a 93     $save_data['email'] = $RCMAIL->user->get_username();
ec0171 94
f879f4 95   $plugin = $RCMAIL->plugins->exec_hook('create_identity', array('record' => $save_data));
69f18a 96   $save_data = $plugin['record'];
T 97
98   if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data)))
4e17e6 99   {
69f18a 100     $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
72b280 101     
4e17e6 102     $_GET['_iid'] = $insert_id;
T 103
6ec91f 104     if (!empty($_POST['_standard']))
T 105       $default_id = $insert_id;
fba1f5 106   }
4e17e6 107   else
fba1f5 108   {
4e17e6 109     // show error message
69f18a 110     $OUTPUT->show_message('errorsaving', 'error', null, false);
853b2e 111     rcmail_overwrite_action('edit-identity');
6ec91f 112     return;
4e17e6 113   }
fba1f5 114 }
f645ce 115 else
T 116   $OUTPUT->show_message('opnotpermitted', 'error');
4e17e6 117
T 118
6ec91f 119 // mark all other identities as 'not-default'
T 120 if ($default_id)
fba1f5 121   $USER->set_default($default_id);
6ec91f 122
4e17e6 123 // go to next step
c1b3c4 124 rcmail_overwrite_action('identities');
4e17e6 125
ec0171 126 ?>