]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/edit_identity.inc
Imported Upstream version 0.2.2
[roundcube.git] / program / steps / settings / edit_identity.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/edit_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  |   Show edit form for a identity record or to add a new one            |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: edit_identity.inc 2483 2009-05-15 10:22:29Z thomasb $
19
20 */
21
22 define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
23
24 // edit-identity
25 if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') {
26   $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC));
27   
28   if (is_array($IDENTITY_RECORD))
29     $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']);
30   else {
31     $OUTPUT->show_message('opnotpermitted', 'error');
32     // go to identities page
33     rcmail_overwrite_action('identities');
34     return;
35   }
36 }
37 // add-identity
38 else {
39   if (IDENTITIES_LEVEL > 1) {
40     $OUTPUT->show_message('opnotpermitted', 'error');
41     // go to identities page
42     rcmail_overwrite_action('identities');
43     return;
44   }
45   else if (IDENTITIES_LEVEL == 1)
46     $IDENTITY_RECORD['email'] = $RCMAIL->user->get_username();
47 }
48
49
50 function rcube_identity_form($attrib)
51   {
52   global $IDENTITY_RECORD, $RCMAIL, $OUTPUT;
53
54   rcube_html_editor('identity');
55
56   // add some labels to client
57   $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting', 'editorwarning');
58
59   $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
60   $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
61   $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
62
63   list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id']));
64   unset($attrib['form']);
65
66   // list of available cols
67   $a_show_cols = array('name'         => array('type' => 'text', 'size' => $i_size),
68                        'email'        => array('type' => 'text', 'size' => $i_size),
69                        'organization' => array('type' => 'text', 'size' => $i_size),
70                        'reply-to'     => array('type' => 'text', 'label' => 'reply-to', 'size' => $i_size),
71                        'bcc'          => array('type' => 'text', 'size' => $i_size),
72                        'signature'        => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows),
73                        'html_signature'=>array('type' => 'checkbox', 'label' => 'htmlsignature', 'onclick' => 'return rcmail_toggle_editor(this.checked, \'rcmfd_signature\');'),
74                        'standard'     => array('type' => 'checkbox', 'label' => 'setdefault'));
75
76   // disable some field according to access level
77   if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) {
78     $a_show_cols['email']['disabled'] = true;
79     $a_show_cols['email']['class'] = 'disabled';
80   }
81   
82   // a specific part is requested
83   if ($attrib['part'])
84     {
85     $colprop = $a_show_cols[$attrib['part']];
86     if (is_array($colprop))
87       {
88       $out = $form_start;
89       $out .= rcmail_get_edit_field($attrib['part'], $IDENTITY_RECORD[$attrib['part']], $attrib, $colprop['type']); 
90       return $out;
91       }
92     else
93       return '';
94     }
95
96
97   // return the complete edit form as table
98   $out = "$form_start<table>\n\n";
99
100   foreach ($a_show_cols as $col => $colprop)
101     {
102     $colprop['id'] = 'rcmfd_'.$col;
103
104     if ($col == 'signature')
105       {
106       $colprop['spellcheck'] = true;
107       if ($IDENTITY_RECORD['html_signature'])
108         {
109         $colprop['class'] = 'mce_editor';
110         }
111       }
112
113     $label = strlen($colprop['label']) ? $colprop['label'] : $col;
114     $value = rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']);
115
116     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
117                     $colprop['id'],
118                     Q(rcube_label($label)),
119                     $value);
120     }
121
122   $out .= "\n</table>$form_end";
123
124   return $out;  
125   }
126
127 $OUTPUT->include_script('list.js');
128 $OUTPUT->add_handler('identityform', 'rcube_identity_form');
129 $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
130
131 $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem')));
132
133 if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('addidentity'))
134   $OUTPUT->send('addidentity');
135
136 $OUTPUT->send('editidentity');
137
138 ?>