Templates for help section
[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 *
47ccfad4 8 * @copyright &copy; 1999-2006 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
30967a1e 16/**
202bcbcc 17 * Include the SquirrelMail initialization file.
30967a1e 18 */
202bcbcc 19require('../include/init.php');
86725763 20
21/* SquirrelMail required files. */
202bcbcc 22require_once(SM_PATH . 'functions/identity.php');
aaf9abef 23
bf02c883 24/* make sure that page is not available when $edit_identity is false */
25if (!$edit_identity) {
26 error_box(_("Editing identities is disabled."));
27 $oTemplate->display('footer.tpl');
28 die();
29}
30
e7f9c987 31if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) {
32 $identities = get_identities();
fe369c70 33}
e7f9c987 34sqgetGlobalVar('newidentities', $newidentities, SQ_POST);
35sqgetGlobalVar('smaction', $smaction, SQ_POST);
36sqgetGlobalVar('return', $return, SQ_POST);
fe369c70 37
e7f9c987 38// First lets see if there are any actions to perform //
39if (!empty($smaction) && is_array($smaction)) {
91e0dccc 40
e7f9c987 41 $doaction = '';
42 $identid = 0;
91e0dccc 43
e7f9c987 44 foreach($smaction as $action=>$row) {
45 // we only need to extract the action and the identity we are
46 // altering
91e0dccc 47
bb51bc8b 48 foreach($row as $iKey=>$data) {
49 $identid = $iKey;
e7f9c987 50 }
51
52 $doaction = $action;
32f4e318 53 }
91e0dccc 54
e7f9c987 55 $identities = sqfixidentities( $newidentities , $identid , $action );
56 save_identities($identities);
57}
e697b6cc 58
e7f9c987 59if (!empty($return)) {
60 header('Location: ' . get_location() . '/options_personal.php');
61 exit;
62}
e697b6cc 63
e7f9c987 64displayPageHeader($color, 'None');
e697b6cc 65
0f01b5d7 66/* since 1.1.3 */
e7f9c987 67do_hook('options_identities_top');
91e0dccc 68
e7f9c987 69$td_str = '';
70$td_str .= '<form name="f" action="options_identities.php" method="post"><br />' . "\n";
71$td_str .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n";
72$cnt = count($identities);
bb51bc8b 73foreach( $identities as $iKey=>$ident ) {
e697b6cc 74
bb51bc8b 75 if ($iKey == 0) {
e7f9c987 76 $hdr_str = _("Default Identity");
77 } else {
bb51bc8b 78 $hdr_str = sprintf( _("Alternate Identity %d"), $iKey);
e697b6cc 79 }
80
bb51bc8b 81 $td_str .= ShowIdentityInfo( $hdr_str, $ident, $iKey );
e697b6cc 82
e7f9c987 83}
84
85$td_str .= ShowIdentityInfo( _("Add a New Identity"), array('full_name'=>'','email_address'=>'','reply_to'=>'','signature'=>''), $cnt);
86$td_str .= '</table>' . "\n";
87$td_str .= '</form>';
88
89echo '<br /> ' . "\n" .
90 html_tag('table', "\n" .
91 html_tag('tr', "\n" .
bb51bc8b 92 html_tag('td' , "\n" .
e7f9c987 93 '<b>' . _("Options") . ' - ' . _("Advanced Identities") . '</b><br />' .
94 html_tag('table', "\n" .
95 html_tag('tr', "\n" .
96 html_tag('td', "\n" .
97 html_tag('table' , "\n" .
98 html_tag('tr' , "\n" .
99 html_tag('td', "\n" . $td_str ,'','', 'style="text-align:center;"')
100 ),
101 '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
102 'center', $color[4])
103 ),
104 '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' )) ,
105 'center', $color[0]),
106 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . '</body></html>';
bb51bc8b 107
0f01b5d7 108/**
109 * Returns html formated identity form fields
bb51bc8b 110 *
0f01b5d7 111 * Contains options_identities_buttons and option_identities_table hooks.
bb51bc8b 112 * Before 1.4.5/1.5.1 hooks were placed in ShowTableInfo() function.
113 * In 1.1.3-1.4.1 they were called in do_hook function with two or
0f01b5d7 114 * three arguments. Since 1.4.1 hooks are called in concat_hook_function.
115 * Arguments are moved to array.
116 *
117 * options_identities_buttons hook uses array with two keys. First array key is
bb51bc8b 118 * boolean variable used to indicate empty identity field. Second array key
0f01b5d7 119 * is integer variable used to indicate identity number
120 *
121 * options_identities_table hook uses array with three keys. First array key is
bb51bc8b 122 * a string containing background color style CSS (1.4.1-1.4.4/1.5.0 uses only
123 * html color code). Second array key is boolean variable used to indicate empty
124 * identity field. Third array key is integer variable used to indicate identity
0f01b5d7 125 * number
126 * @param string $title Name displayed in header row
127 * @param array $identity Identity information
128 * @param integer $id identity ID
129 * @return string html formatted table rows with form fields for identity management
130 * @since 1.5.1 and 1.4.5 (was called ShowTableInfo() in 1.1.3-1.4.4 and 1.5.0)
131 */
e7f9c987 132function ShowIdentityInfo($title, $identity, $id ) {
133 global $color;
134
135 if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) {
136 $bg = '';
137 $empty = true;
138 } else {
139 $bg = ' style="background-color:' . $color[0] . ';"';
f9632976 140 $empty = false;
e697b6cc 141 }
142
e7f9c987 143 $name = 'newidentities[%d][%s]';
144
e697b6cc 145
e7f9c987 146 $return_str = '';
147
148 $return_str .= '<tr>' . "\n";
149 $return_str .= ' <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n";
150 $return_str .= '</tr>' . "\n";
151 $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg);
152 $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg);
153 $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg);
154 $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg);
155 $return_str .= concat_hook_function('options_identities_table', array($bg, $empty, $id));
156 $return_str .= '<tr' . $bg . '> ' . "\n";
157 $return_str .= ' <td> &nbsp; </td>' . "\n";
158 $return_str .= ' <td>' . "\n";
159 $return_str .= ' <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n";
160
161 if (!$empty && $id > 0) {
162 $return_str .= ' <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n";
163 $return_str .= ' <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n";
164
165 if ($id > 1) {
166 $return_str .= ' <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n";
167 }
e697b6cc 168
e697b6cc 169 }
170
e7f9c987 171 $return_str .= concat_hook_function('options_identities_buttons', array($empty, $id));
172 $return_str .= ' </td>' . "\n";
173 $return_str .= '</tr>' . "\n";
174 $return_str .= '<tr>' . "\n";
175 $return_str .= ' <td colspan="2"> &nbsp; </td>' . "\n";
176 $return_str .= '</tr>';
177
178 return $return_str;
aaf9abef 179
01265fba 180}
181
0f01b5d7 182/**
183 * Creates html formated table row with input field
184 * @param string $title Name displayed next to input field
185 * @param string $name Name of input field
186 * @param string $data Default value of input field (data is sanitized with htmlspecialchars)
187 * @param string $bgcolor html attributes added to row element (tr)
188 * @return string html formated table row with text input field
189 * @since 1.2.0 (arguments differ since 1.4.5/1.5.1)
190 * @todo check right-to-left language issues
191 * @access private
192 */
e7f9c987 193function sti_input( $title, $name, $data, $bgcolor ) {
194 $str = '';
195 $str .= '<tr' . $bgcolor . ">\n";
196 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
197 $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. htmlspecialchars($data) . '"> </td>' . "\n";
198 $str .= '</tr>';
bb51bc8b 199
e7f9c987 200 return $str;
aaf9abef 201
e7f9c987 202}
203
0f01b5d7 204/**
205 * Creates html formated table row with textarea field
206 * @param string $title Name displayed next to textarea field
207 * @param string $name Name of textarea field
208 * @param string $data Default value of textarea field (data is sanitized with htmlspecialchars)
209 * @param string $bgcolor html attributes added to row element (tr)
210 * @return string html formated table row with textarea
211 * @since 1.2.5 (arguments differ since 1.4.5/1.5.1)
212 * @todo check right-to-left language issues
213 * @access private
214 */
e7f9c987 215function sti_textarea( $title, $name, $data, $bgcolor ) {
216 $str = '';
217 $str .= '<tr' . $bgcolor . ">\n";
218 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
219 $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. htmlspecialchars($data) . '</textarea> </td>' . "\n";
220 $str .= '</tr>';
bb51bc8b 221
e7f9c987 222 return $str;
545238b1 223
aaf9abef 224}
a2b193bc 225
0f01b5d7 226?>