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