4 * options_identities.php
6 * Display Identities Options
8 * @copyright © 1999-2005 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 include_once(SM_PATH
. 'functions/global.php');
25 include_once(SM_PATH
. 'functions/display_messages.php');
26 include_once(SM_PATH
. 'functions/html.php');
27 include_once(SM_PATH
. 'functions/identity.php');
29 if (!sqgetGlobalVar('identities', $identities, SQ_SESSION
)) {
30 $identities = get_identities();
32 sqgetGlobalVar('newidentities', $newidentities, SQ_POST
);
33 sqgetGlobalVar('smaction', $smaction, SQ_POST
);
34 sqgetGlobalVar('return', $return, SQ_POST
);
36 // First lets see if there are any actions to perform //
37 if (!empty($smaction) && is_array($smaction)) {
42 foreach($smaction as $action=>$row) {
43 // we only need to extract the action and the identity we are
46 foreach($row as $iKey=>$data) {
53 $identities = sqfixidentities( $newidentities , $identid , $action );
54 save_identities($identities);
57 if (!empty($return)) {
58 header('Location: ' . get_location() . '/options_personal.php');
62 displayPageHeader($color, 'None');
65 do_hook('options_identities_top');
68 $td_str .= '<form name="f" action="options_identities.php" method="post"><br />' . "\n";
69 $td_str .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . "\n";
70 $cnt = count($identities);
71 foreach( $identities as $iKey=>$ident ) {
74 $hdr_str = _("Default Identity");
76 $hdr_str = sprintf( _("Alternate Identity %d"), $iKey);
79 $td_str .= ShowIdentityInfo( $hdr_str, $ident, $iKey );
83 $td_str .= ShowIdentityInfo( _("Add a New Identity"), array('full_name'=>'','email_address'=>'','reply_to'=>'','signature'=>''), $cnt);
84 $td_str .= '</table>' . "\n";
87 echo '<br /> ' . "\n" .
88 html_tag('table', "\n" .
90 html_tag('td' , "\n" .
91 '<b>' . _("Options") . ' - ' . _("Advanced Identities") . '</b><br />' .
92 html_tag('table', "\n" .
95 html_tag('table' , "\n" .
96 html_tag('tr' , "\n" .
97 html_tag('td', "\n" . $td_str ,'','', 'style="text-align:center;"')
99 '', '', 'width="80%" cellpadding="2" cellspacing="0" border="0"' ) ,
102 '', '', 'width="100%" border="0" cellpadding="1" cellspacing="1"' )) ,
103 'center', $color[0]),
104 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . '</body></html>';
107 * Returns html formated identity form fields
109 * Contains options_identities_buttons and option_identities_table hooks.
110 * Before 1.4.5/1.5.1 hooks were placed in ShowTableInfo() function.
111 * In 1.1.3-1.4.1 they were called in do_hook function with two or
112 * three arguments. Since 1.4.1 hooks are called in concat_hook_function.
113 * Arguments are moved to array.
115 * options_identities_buttons hook uses array with two keys. First array key is
116 * boolean variable used to indicate empty identity field. Second array key
117 * is integer variable used to indicate identity number
119 * options_identities_table hook uses array with three keys. First array key is
120 * a string containing background color style CSS (1.4.1-1.4.4/1.5.0 uses only
121 * html color code). Second array key is boolean variable used to indicate empty
122 * identity field. Third array key is integer variable used to indicate identity
124 * @param string $title Name displayed in header row
125 * @param array $identity Identity information
126 * @param integer $id identity ID
127 * @return string html formatted table rows with form fields for identity management
128 * @since 1.5.1 and 1.4.5 (was called ShowTableInfo() in 1.1.3-1.4.4 and 1.5.0)
130 function ShowIdentityInfo($title, $identity, $id ) {
133 if (empty($identity['full_name']) && empty($identity['email_address']) && empty($identity['reply_to']) && empty($identity['signature'])) {
137 $bg = ' style="background-color:' . $color[0] . ';"';
141 $name = 'newidentities[%d][%s]';
146 $return_str .= '<tr>' . "\n";
147 $return_str .= ' <th style="text-align:center;background-color:' . $color[9] . ';" colspan="2">' . $title . '</th> '. "\n";
148 $return_str .= '</tr>' . "\n";
149 $return_str .= sti_input( _("Full Name") , sprintf($name, $id, 'full_name'), $identity['full_name'], $bg);
150 $return_str .= sti_input( _("E-Mail Address") , sprintf($name, $id, 'email_address'), $identity['email_address'], $bg);
151 $return_str .= sti_input( _("Reply To"), sprintf($name, $id, 'reply_to'), $identity['reply_to'], $bg);
152 $return_str .= sti_textarea( _("Signature"), sprintf($name, $id, 'signature'), $identity['signature'], $bg);
153 $return_str .= concat_hook_function('options_identities_table', array($bg, $empty, $id));
154 $return_str .= '<tr' . $bg . '> ' . "\n";
155 $return_str .= ' <td> </td>' . "\n";
156 $return_str .= ' <td>' . "\n";
157 $return_str .= ' <input type="submit" name="smaction[save][' . $id . ']" value="' . _("Save / Update") . '" />' . "\n";
159 if (!$empty && $id > 0) {
160 $return_str .= ' <input type="submit" name="smaction[makedefault][' . $id . ']" value="' . _("Make Default") . '" />' . "\n";
161 $return_str .= ' <input type="submit" name="smaction[delete]['.$id.']" value="' . _("Delete") . '" />' . "\n";
164 $return_str .= ' <input type="submit" name="smaction[move]['.$id.']" value="' . _("Move Up") . '" />' . "\n";
169 $return_str .= concat_hook_function('options_identities_buttons', array($empty, $id));
170 $return_str .= ' </td>' . "\n";
171 $return_str .= '</tr>' . "\n";
172 $return_str .= '<tr>' . "\n";
173 $return_str .= ' <td colspan="2"> </td>' . "\n";
174 $return_str .= '</tr>';
181 * Creates html formated table row with input field
182 * @param string $title Name displayed next to input field
183 * @param string $name Name of input field
184 * @param string $data Default value of input field (data is sanitized with htmlspecialchars)
185 * @param string $bgcolor html attributes added to row element (tr)
186 * @return string html formated table row with text input field
187 * @since 1.2.0 (arguments differ since 1.4.5/1.5.1)
188 * @todo check right-to-left language issues
191 function sti_input( $title, $name, $data, $bgcolor ) {
193 $str .= '<tr' . $bgcolor . ">\n";
194 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
195 $str .= ' <td> <input type="text" name="' . $name . '" size="50" value="'. htmlspecialchars($data) . '"> </td>' . "\n";
203 * Creates html formated table row with textarea field
204 * @param string $title Name displayed next to textarea field
205 * @param string $name Name of textarea field
206 * @param string $data Default value of textarea field (data is sanitized with htmlspecialchars)
207 * @param string $bgcolor html attributes added to row element (tr)
208 * @return string html formated table row with textarea
209 * @since 1.2.5 (arguments differ since 1.4.5/1.5.1)
210 * @todo check right-to-left language issues
213 function sti_textarea( $title, $name, $data, $bgcolor ) {
215 $str .= '<tr' . $bgcolor . ">\n";
216 $str .= ' <td style="white-space: nowrap;text-align:right;">' . $title . ' </td>' . "\n";
217 $str .= ' <td> <textarea name="' . $name . '" cols="50" rows="5">'. htmlspecialchars($data) . '</textarea> </td>' . "\n";