Typo
[squirrelmail.git] / src / options_identities.php
1 <?php
2
3 /**
4 * options_identities.php
5 *
6 * Display Identities Options
7 *
8 * @copyright 1999-2013 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 * @subpackage prefs
13 * @since 1.1.3
14 */
15
16 /** This is the options_identities page */
17 define('PAGE_NAME', 'options_identities');
18
19 /**
20 * Include the SquirrelMail initialization file.
21 */
22 require('../include/init.php');
23
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'functions/identity.php');
26 require_once(SM_PATH . 'functions/forms.php');
27
28 /* make sure that page is not available when $edit_identity is false */
29 if (!$edit_identity) {
30 error_box(_("Editing identities is disabled."));
31 $oTemplate->display('footer.tpl');
32 die();
33 }
34
35 if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) {
36 $identities = get_identities();
37 }
38 sqgetGlobalVar('newidentities', $newidentities, SQ_POST);
39 sqgetGlobalVar('smaction', $smaction, SQ_POST);
40 sqgetGlobalVar('return', $return, SQ_POST);
41 sqgetGlobalVar('smtoken', $submitted_token, SQ_POST, '');
42
43 // First lets see if there are any actions to perform //
44 if (!empty($smaction) && is_array($smaction)) {
45
46 // first do a security check
47 sm_validate_security_token($submitted_token, -1, TRUE);
48
49 $doaction = '';
50 $identid = 0;
51
52 foreach($smaction as $action=>$row) {
53 // we only need to extract the action and the identity we are
54 // altering
55
56 foreach($row as $iKey=>$data) {
57 $identid = $iKey;
58 }
59
60 $doaction = $action;
61 }
62
63 $identities = sqfixidentities( $newidentities , $identid , $action );
64 save_identities($identities);
65 }
66
67 if (!empty($return)) {
68 header('Location: ' . get_location() . '/options_personal.php');
69 exit;
70 }
71
72 displayPageHeader($color);
73
74 /* since 1.1.3 */
75 do_hook('options_identities_top', $null);
76
77 $i = array();
78 foreach ($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;
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']);
87 $i[$key] = $a;
88 }
89
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;
99
100 //FIXME: NO HTML IN THE CORE
101 echo '<form name="f" action="options_identities.php" method="post">' . "\n"
102 . addHidden('smtoken', sm_generate_security_token()) . "\n";
103
104 $oTemplate->assign('identities', $i);
105 $oTemplate->display('options_advidentity_list.tpl');
106
107 //FIXME: NO HTML IN THE CORE
108 echo "</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 */
116
117 /**
118 * Returns html formated identity form fields
119 *
120 * Contains options_identities_buttons and options_identities_table hooks.
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
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
127 * boolean variable used to indicate empty identity field. Second array key
128 * is integer variable used to indicate identity number
129 *
130 * options_identities_table hook uses array with three keys. First array key is
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
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 */
141 function 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] . ';"';
149 $empty = false;
150 }
151
152 $name = 'newidentities[%d][%s]';
153
154
155 $return_str = '';
156
157 //FIXME: NO HTML IN THE CORE
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);
165 $temp = array(&$bg, &$empty, &$id);
166 $return_str .= concat_hook_function('options_identities_table', $temp);
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 }
179
180 }
181
182 $temp = array(&$empty, &$id);
183 $return_str .= concat_hook_function('options_identities_buttons', $temp);
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;
191
192 }
193
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
198 * @param string $data Default value of input field (data is sanitized with sm_encode_html_special_chars)
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 */
205 function sti_input( $title, $name, $data, $bgcolor ) {
206 //FIXME: NO HTML IN THE CORE
207 $str = '';
208 $str .= '<tr' . $bgcolor . ">\n";
209 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
210 $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. sm_encode_html_special_chars($data) . '" /> </td>' . "\n";
211 $str .= '</tr>';
212
213 return $str;
214
215 }
216
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
221 * @param string $data Default value of textarea field (data is sanitized with sm_encode_html_special_chars)
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 */
228 function sti_textarea( $title, $name, $data, $bgcolor ) {
229 //FIXME: NO HTML IN THE CORE
230 $str = '';
231 $str .= '<tr' . $bgcolor . ">\n";
232 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
233 $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. sm_encode_html_special_chars($data) . '</textarea> </td>' . "\n";
234 $str .= '</tr>';
235
236 return $str;
237
238 }
239