| 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$ |
|---|
| 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 | } |
|---|
| 31 | // add-identity |
|---|
| 32 | else { |
|---|
| 33 | if (IDENTITIES_LEVEL > 1) { |
|---|
| 34 | $OUTPUT->show_message('opnotpermitted', 'error'); |
|---|
| 35 | // go to identities page |
|---|
| 36 | rcmail_overwrite_action('identities'); |
|---|
| 37 | return; |
|---|
| 38 | } |
|---|
| 39 | else if (IDENTITIES_LEVEL == 1) |
|---|
| 40 | $IDENTITY_RECORD['email'] = rcmail_get_email(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | function rcube_identity_form($attrib) |
|---|
| 45 | { |
|---|
| 46 | global $IDENTITY_RECORD, $RCMAIL, $OUTPUT; |
|---|
| 47 | |
|---|
| 48 | $tinylang = substr($_SESSION['language'], 0, 2); |
|---|
| 49 | if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js')) |
|---|
| 50 | { |
|---|
| 51 | $tinylang = 'en'; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | $OUTPUT->include_script('tiny_mce/tiny_mce.js'); |
|---|
| 55 | $OUTPUT->add_script("tinyMCE.init({ mode : 'textareas'," . |
|---|
| 56 | "editor_selector : 'mce_editor'," . |
|---|
| 57 | "apply_source_formatting : true," . |
|---|
| 58 | "language : '$tinylang'," . |
|---|
| 59 | "content_css : '\$__skin_path' + '/editor_content.css'," . |
|---|
| 60 | "theme : 'advanced'," . |
|---|
| 61 | "theme_advanced_toolbar_location : 'top'," . |
|---|
| 62 | "theme_advanced_toolbar_align : 'left'," . |
|---|
| 63 | "theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor'," . |
|---|
| 64 | "theme_advanced_buttons2 : ',fontselect,fontsizeselect'," . |
|---|
| 65 | "theme_advanced_buttons3 : '',". |
|---|
| 66 | "gecko_spellcheck : true });"); |
|---|
| 67 | |
|---|
| 68 | if (!$IDENTITY_RECORD && $RCMAIL->action != 'add-identity') |
|---|
| 69 | return rcube_label('notfound'); |
|---|
| 70 | |
|---|
| 71 | // add some labels to client |
|---|
| 72 | $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting'); |
|---|
| 73 | |
|---|
| 74 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 75 | $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; |
|---|
| 76 | $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; |
|---|
| 77 | |
|---|
| 78 | list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id'])); |
|---|
| 79 | unset($attrib['form']); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | // list of available cols |
|---|
| 83 | $a_show_cols = array('name' => array('type' => 'text', 'size' => $i_size), |
|---|
| 84 | 'email' => array('type' => 'text', 'size' => $i_size), |
|---|
| 85 | 'organization' => array('type' => 'text', 'size' => $i_size), |
|---|
| 86 | 'reply-to' => array('type' => 'text', 'label' => 'reply-to', 'size' => $i_size), |
|---|
| 87 | 'bcc' => array('type' => 'text', 'size' => $i_size), |
|---|
| 88 | 'signature' => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows), |
|---|
| 89 | 'html_signature'=>array('type' => 'checkbox', 'label' => 'htmlsignature', 'onclick' => 'return rcmail.toggle_editor(this, \'rcmfd_signature\');'), |
|---|
| 90 | 'standard' => array('type' => 'checkbox', 'label' => 'setdefault')); |
|---|
| 91 | |
|---|
| 92 | // disable some field according to access level |
|---|
| 93 | if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) { |
|---|
| 94 | $a_show_cols['email']['disabled'] = true; |
|---|
| 95 | $a_show_cols['email']['class'] = 'disabled'; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | // a specific part is requested |
|---|
| 99 | if ($attrib['part']) |
|---|
| 100 | { |
|---|
| 101 | $colprop = $a_show_cols[$attrib['part']]; |
|---|
| 102 | if (is_array($colprop)) |
|---|
| 103 | { |
|---|
| 104 | $out = $form_start; |
|---|
| 105 | $out .= rcmail_get_edit_field($attrib['part'], $IDENTITY_RECORD[$attrib['part']], $attrib, $colprop['type']); |
|---|
| 106 | return $out; |
|---|
| 107 | } |
|---|
| 108 | else |
|---|
| 109 | return ''; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | // return the complete edit form as table |
|---|
| 114 | $out = "$form_start<table>\n\n"; |
|---|
| 115 | |
|---|
| 116 | foreach ($a_show_cols as $col => $colprop) |
|---|
| 117 | { |
|---|
| 118 | $colprop['id'] = 'rcmfd_'.$col; |
|---|
| 119 | |
|---|
| 120 | if ($col == 'signature') |
|---|
| 121 | { |
|---|
| 122 | $colprop['spellcheck'] = true; |
|---|
| 123 | if ($IDENTITY_RECORD['html_signature']) |
|---|
| 124 | { |
|---|
| 125 | $colprop['class'] = 'mce_editor'; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | $label = strlen($colprop['label']) ? $colprop['label'] : $col; |
|---|
| 130 | $value = rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']); |
|---|
| 131 | |
|---|
| 132 | $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n", |
|---|
| 133 | $colprop['id'], |
|---|
| 134 | Q(rcube_label($label)), |
|---|
| 135 | $value); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | $out .= "\n</table>$form_end"; |
|---|
| 139 | |
|---|
| 140 | return $out; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | $OUTPUT->include_script('list.js'); |
|---|
| 144 | $OUTPUT->add_handler('identityform', 'rcube_identity_form'); |
|---|
| 145 | $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL); |
|---|
| 146 | |
|---|
| 147 | $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem'))); |
|---|
| 148 | |
|---|
| 149 | if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('addidentity')) |
|---|
| 150 | $OUTPUT->send('addidentity'); |
|---|
| 151 | |
|---|
| 152 | $OUTPUT->send('editidentity'); |
|---|
| 153 | |
|---|
| 154 | ?> |
|---|