Typo
[squirrelmail.git] / src / options_identities.php
CommitLineData
aaf9abef 1<?php
895905c0 2
35586184 3/**
4 * options_identities.php
5 *
35586184 6 * Display Identities Options
7 *
79ba18dc 8 * @copyright 1999-2013 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
ca479ad1 12 * @subpackage prefs
0f01b5d7 13 * @since 1.1.3
35586184 14 */
15
ebd2391c 16/** This is the options_identities page */
17define('PAGE_NAME', 'options_identities');
18
30967a1e 19/**
202bcbcc 20 * Include the SquirrelMail initialization file.
30967a1e 21 */
202bcbcc 22require('../include/init.php');
86725763 23
24/* SquirrelMail required files. */
202bcbcc 25require_once(SM_PATH . 'functions/identity.php');
199a9ab8 26require_once(SM_PATH . 'functions/forms.php');
aaf9abef 27
bf02c883 28/* make sure that page is not available when $edit_identity is false */
29if (!$edit_identity) {
30 error_box(_("Editing identities is disabled."));
31 $oTemplate->display('footer.tpl');
32 die();
33}
34
e7f9c987 35if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) {
36 $identities = get_identities();
fe369c70 37}
e7f9c987 38sqgetGlobalVar('newidentities', $newidentities, SQ_POST);
39sqgetGlobalVar('smaction', $smaction, SQ_POST);
40sqgetGlobalVar('return', $return, SQ_POST);
199a9ab8 41sqgetGlobalVar('smtoken', $submitted_token, SQ_POST, '');
fe369c70 42
e7f9c987 43// First lets see if there are any actions to perform //
44if (!empty($smaction) && is_array($smaction)) {
91e0dccc 45
199a9ab8 46 // first do a security check
2cefa62a 47 sm_validate_security_token($submitted_token, -1, TRUE);
199a9ab8 48
e7f9c987 49 $doaction = '';
50 $identid = 0;
91e0dccc 51
e7f9c987 52 foreach($smaction as $action=>$row) {
53 // we only need to extract the action and the identity we are
54 // altering
91e0dccc 55
bb51bc8b 56 foreach($row as $iKey=>$data) {
57 $identid = $iKey;
e7f9c987 58 }
59
60 $doaction = $action;
32f4e318 61 }
91e0dccc 62
e7f9c987 63 $identities = sqfixidentities( $newidentities , $identid , $action );
64 save_identities($identities);
65}
e697b6cc 66
e7f9c987 67if (!empty($return)) {
68 header('Location: ' . get_location() . '/options_personal.php');
69 exit;
70}
e697b6cc 71
876fdb60 72displayPageHeader($color);
e697b6cc 73
0f01b5d7 74/* since 1.1.3 */
6e515418 75do_hook('options_identities_top', $null);
91e0dccc 76
26aefb60 77$i = array();
78foreach ($identities as $key=>$ident) {
79 $a = array();
80 $a['Title'] = $key==0 ? _("Default Identity") : sprintf(_("Alternate Identity %d"), $key);
81 $a['New'] = false;
82 $a['Default'] = $key==0;
3047e291 83 $a['FullName'] = sm_encode_html_special_chars($ident['full_name']);
84 $a['Email'] = sm_encode_html_special_chars($ident['email_address']);
85 $a['ReplyTo'] = sm_encode_html_special_chars($ident['reply_to']);
86 $a['Signature'] = sm_encode_html_special_chars($ident['signature']);
26aefb60 87 $i[$key] = $a;
88}
e697b6cc 89
26aefb60 90$a = array();
91$a['Title'] = _("Add New Identity");
92$a['New'] = true;
93$a['Default'] = false;
94$a['FullName'] = '';
95$a['Email'] = '';
96$a['ReplyTo'] = '';
97$a['Signature'] = '';
98$i[count($i)] = $a;
e697b6cc 99
99b1692b 100//FIXME: NO HTML IN THE CORE
199a9ab8 101echo '<form name="f" action="options_identities.php" method="post">' . "\n"
102 . addHidden('smtoken', sm_generate_security_token()) . "\n";
26aefb60 103
104$oTemplate->assign('identities', $i);
105$oTemplate->display('options_advidentity_list.tpl');
e7f9c987 106
99b1692b 107//FIXME: NO HTML IN THE CORE
26aefb60 108echo "</form>\n";
109
110$oTemplate->display('footer.tpl');
111
112/**
113 * The functions below should not be needed with the additions of templates,
114 * however they will remain in case plugins use them.
115 */
bb51bc8b 116
0f01b5d7 117/**
118 * Returns html formated identity form fields
bb51bc8b 119 *
6cb3431f 120 * Contains options_identities_buttons and options_identities_table hooks.
bb51bc8b 121 * Before 1.4.5/1.5.1 hooks were placed in ShowTableInfo() function.
122 * In 1.1.3-1.4.1 they were called in do_hook function with two or
0f01b5d7 123 * three arguments. Since 1.4.1 hooks are called in concat_hook_function.
124 * Arguments are moved to array.
125 *
126 * options_identities_buttons hook uses array with two keys. First array key is
bb51bc8b 127 * boolean variable used to indicate empty identity field. Second array key
0f01b5d7 128 * is integer variable used to indicate identity number
129 *
130 * options_identities_table hook uses array with three keys. First array key is
bb51bc8b 131 * a string containing background color style CSS (1.4.1-1.4.4/1.5.0 uses only
132 * html color code). Second array key is boolean variable used to indicate empty
133 * identity field. Third array key is integer variable used to indicate identity
0f01b5d7 134 * number
135 * @param string $title Name displayed in header row
136 * @param array $identity Identity information
137 * @param integer $id identity ID
138 * @return string html formatted table rows with form fields for identity management
139 * @since 1.5.1 and 1.4.5 (was called ShowTableInfo() in 1.1.3-1.4.4 and 1.5.0)
140 */
e7f9c987 141function ShowIdentityInfo($title, $identity, $id ) {
142 global $color;
143
144 if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) {
145 $bg = '';
146 $empty = true;
147 } else {
148 $bg = ' style="background-color:' . $color[0] . ';"';
f9632976 149 $empty = false;
e697b6cc 150 }
151
e7f9c987 152 $name = 'newidentities[%d][%s]';
153
e697b6cc 154
e7f9c987 155 $return_str = '';
156
99b1692b 157//FIXME: NO HTML IN THE CORE
e7f9c987 158 $return_str .= '<tr>' . "\n";
159 $return_str .= ' <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n";
160 $return_str .= '</tr>' . "\n";
161 $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg);
162 $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg);
163 $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg);
164 $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg);
ddbd13db 165 $temp = array(&$bg, &$empty, &$id);
166 $return_str .= concat_hook_function('options_identities_table', $temp);
e7f9c987 167 $return_str .= '<tr' . $bg . '> ' . "\n";
168 $return_str .= ' <td> &nbsp; </td>' . "\n";
169 $return_str .= ' <td>' . "\n";
170 $return_str .= ' <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n";
171
172 if (!$empty && $id > 0) {
173 $return_str .= ' <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n";
174 $return_str .= ' <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n";
175
176 if ($id > 1) {
177 $return_str .= ' <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n";
178 }
e697b6cc 179
e697b6cc 180 }
181
ddbd13db 182 $temp = array(&$empty, &$id);
183 $return_str .= concat_hook_function('options_identities_buttons', $temp);
e7f9c987 184 $return_str .= ' </td>' . "\n";
185 $return_str .= '</tr>' . "\n";
186 $return_str .= '<tr>' . "\n";
187 $return_str .= ' <td colspan="2"> &nbsp; </td>' . "\n";
188 $return_str .= '</tr>';
189
190 return $return_str;
aaf9abef 191
01265fba 192}
193
0f01b5d7 194/**
195 * Creates html formated table row with input field
196 * @param string $title Name displayed next to input field
197 * @param string $name Name of input field
3047e291 198 * @param string $data Default value of input field (data is sanitized with sm_encode_html_special_chars)
0f01b5d7 199 * @param string $bgcolor html attributes added to row element (tr)
200 * @return string html formated table row with text input field
201 * @since 1.2.0 (arguments differ since 1.4.5/1.5.1)
202 * @todo check right-to-left language issues
203 * @access private
204 */
e7f9c987 205function sti_input( $title, $name, $data, $bgcolor ) {
99b1692b 206//FIXME: NO HTML IN THE CORE
e7f9c987 207 $str = '';
208 $str .= '<tr' . $bgcolor . ">\n";
209 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
3047e291 210 $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. sm_encode_html_special_chars($data) . '" /> </td>' . "\n";
e7f9c987 211 $str .= '</tr>';
bb51bc8b 212
e7f9c987 213 return $str;
aaf9abef 214
e7f9c987 215}
216
0f01b5d7 217/**
218 * Creates html formated table row with textarea field
219 * @param string $title Name displayed next to textarea field
220 * @param string $name Name of textarea field
3047e291 221 * @param string $data Default value of textarea field (data is sanitized with sm_encode_html_special_chars)
0f01b5d7 222 * @param string $bgcolor html attributes added to row element (tr)
223 * @return string html formated table row with textarea
224 * @since 1.2.5 (arguments differ since 1.4.5/1.5.1)
225 * @todo check right-to-left language issues
226 * @access private
227 */
e7f9c987 228function sti_textarea( $title, $name, $data, $bgcolor ) {
99b1692b 229//FIXME: NO HTML IN THE CORE
e7f9c987 230 $str = '';
231 $str .= '<tr' . $bgcolor . ">\n";
232 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
3047e291 233 $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. sm_encode_html_special_chars($data) . '</textarea> </td>' . "\n";
e7f9c987 234 $str .= '</tr>';
bb51bc8b 235
e7f9c987 236 return $str;
545238b1 237
aaf9abef 238}
a2b193bc 239