5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://COPYING
11 '`boardlist_layout`', '`topiclist_layout`', '`msglist_layout`',
12 '`msgs_page`', '`topics_page`', '`sig`', '`quote`',
13 '`public_contact`', '`private_contact`'
16 $page->title
= 'Options Screen';
18 if ( ! ($user instanceof User_Authenticated
) ) {
19 $page->errorfooter('login');
21 $user->userlinks
['Theme Settings'] = 'theme';
24 // AAAAAAAAAAAAAAAAAAAAAAAAAGH
25 $tmp = $DB->query('SELECT `COLUMN_NAME` , `CHARACTER_MAXIMUM_LENGTH`
26 FROM `information_schema`.`COLUMNS`
27 WHERE `TABLE_SCHEMA` = "'.DATABASE_NAME
.'"
28 AND `TABLE_NAME` = "users"
29 AND `CHARACTER_MAXIMUM_LENGTH` IS NOT NULL');
30 while ( $row = $tmp->fetch_row() ) {
31 $limits[$row[0]] = $row[1];
36 $timezone = new HTML_Select('timezone', 2, $user->timezone
);
37 for ($i = -12; $i <= 12; $i++
) {
38 $timezone->add_item($i);
41 // function to make the $user->options checkboxes
42 function makeoptbox($name)
44 return '<input type="checkbox" name="options['.$name.']" id="'.$name.'"'.
45 ( strpos($GLOBALS['user']->options
, $name) !== false ?
' checked="checked"' : '' ).'/>';
48 // make the {topic,message,board}list selectboxes
50 'Messagelist' => 'msglist_layout',
51 'Messagestyle' => 'msglist_style',
52 'Topiclist' => 'topiclist_layout',
53 'Boardlist' => 'boardlist_layout'
56 foreach ( $selects as $class => $field ) {
57 $
{$field} = new HTML_Select($field, 2, $user->$field);
59 foreach ( glob('lib/class.'.$class.'_*.php') as $filename ) {
62 $tmp = explode('.', $filename);
63 $
{$field}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
69 if ( isset($_POST['submit']) ) {
71 function rangecheck($varname, $min, $max, $errormsg)
73 if ( !isset($_POST[$varname]) ||
!is_numeric($_POST[$varname]) ||
74 $_POST[$varname] < $min ||
$_POST[$varname] > $max ) {
75 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
79 function lengthcheck($varname, $errormsg)
82 if ( !isset($_POST[$varname]) ||
strlen($_POST[$varname]) > $limits[$varname] ) {
83 throw new LengthException(sprintf($errormsg, $limits[$varname]));
87 $timezone->check_value($_POST['timezone']);
88 foreach ( $selects as $field ) {
89 $
{$field}->check_value($_POST[$field]);
92 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
93 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
96 $valid_options = array('namelinks', 'alwaysonline', 'javascript', 'cache');
98 if ( empty($_POST['options']) ) {
99 $_POST['options'] = array();
102 foreach ( $_POST['options'] as $name => $value ) {
103 if ( in_array($name, $valid_options) ) {
109 'date_format' => 'The custom date format can not be longer than %d characters.',
110 'sig' => 'Your user signature can not be longer than %d characters.',
111 'quote' => 'Your quote can not be longer than %d characters.',
112 'public_contact' => 'Your public contact address can not be longer than %d characters.',
113 'private_contact' => 'Your private contact address can not be longer than %d characters.'
115 foreach ( $tmp as $varname => $errormsg ) {
116 lengthcheck($varname, $errormsg);
119 $DB->autocommit(false);
121 foreach ( $selects as $field ) {
122 $
{$field}->default = $user->$field = intval($_POST[$field]);
125 $timezone->default = $user->timezone
= $_POST['timezone'];
127 $user->sig
= $_POST['sig'];
128 $user->quote
= $_POST['quote'];
130 $user->msgs_page
= $_POST['msgs_page'];
131 $user->topics_page
= $_POST['topics_page'];
132 $user->options
= $uoptions;
134 $user->date_format
= empty($_POST['date_format']) ?
'Y-m-d H:i:s' : $_POST['date_format'];
136 $user->public_contact
= htmlentities($_POST['public_contact']);
137 $user->private_contact
= htmlentities($_POST['private_contact']);
142 echo '<p class="notice">Settings have been saved.</p>';
143 } catch ( Exception
$e ) {
145 echo '<p class="error">',$e->getMessage(),'</p>';
152 <form method
="post" action
="<?php echo $_SERVER['PHP_SELF'] ?>">
154 $options['Display Settings'] = array(
155 'Message list layout<br/>
156 <small>(Threaded view doesn\'t work with messages per page setting)</small>'
157 => $msglist_layout->display().$msglist_style->display(),
158 'Topic list layout' => $topiclist_layout->display(),
159 'Board list layout' => $boardlist_layout->display(),
161 'Messages per page<br/>
162 <small>(Valid range 5-100)</small>'
163 => '<input type="text" name="msgs_page" value="'.$user->msgs_page
.'" maxlength="3" size="3"/>',
164 'Topics per page<br/>
165 <small>(5-100)</small>'
166 => '<input type="text" name="topics_page" value="'.$user->topics_page
.'" maxlength="3" size="3"/>',
167 'Timezone offset<br/>
168 <small>(Relative to UTC: '.htmlentities(gmdate($user->date_format
)).')</small>'
169 => '±'.$timezone->display().': '.htmlentities(strip_tags($user->fdate(time()))),
171 <small>(Don\'t use HTML)</small>'
172 => '<input type="text" name="date_format" value="'.htmlentities($user->date_format
).'" maxlength="'.$limits['date_format'].'"/>',
173 '<label for="namelinks">Link repeated usernames on page<br/>
174 <small>(Turn off to save bandwidth/load faster)</small></label>'
175 => makeoptbox('namelinks'),
176 '<label for="alwaysonline">Old-style active time updating<br/>
177 <small>(Turning this off only updates your last active time when you submit forms)</small></label>'
178 => makeoptbox('alwaysonline'),
179 '<label for="javascript">Enable Javascript<br/>
180 <small>(Enables optional functionality such as auto-refreshing on the board list)</small></label>'
181 => makeoptbox('javascript')
183 if ( 'HTTP/1.1' == $_SERVER['SERVER_PROTOCOL'] ) {
184 $options['Display Settings']['<label for="cache">Enable page caching<br/>
185 <small>(Leave on to speed up page loads, turn off to make theme editing easier)</small></label>'] = makeoptbox('cache');
187 $options['Display Settings']['Enable HTTP/1.1 page caching'] = '<input type="checkbox" disabled="disabled"/>';
190 $options['User Settings'] = array(
192 <small>(The bit that gets put at the bottom of your posts)</small>'
193 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig
).'</textarea>',
195 <small>(Some HTML allowed, same as for posts)</small>'
196 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote
).'</textarea>',
197 'Public contact address<br/>
198 <small>(Only visible to logged in users; can be a mailto/http/etc.)</small>'
199 => '<input type="text" name="public_contact" value="'.$user->public_contact
.'" maxlength="'.$limits['public_contact'].'" size="30"/>',
200 'Private contact address<br/>
201 <small>(Only visible to you and admins)</small>'
202 => '<input type="text" name="private_contact" value="'.$user->private_contact
.'" maxlength="'.$limits['private_contact'].'" size="30"/>'
205 foreach ( $options as $title => $array ) {
207 '<table id="',strtr(strtolower($title), ' ', '_'),'">
210 <tr><th scope="rowgroup" colspan="2">',$title,'</th></tr>
211 <tr><th scope="col">Option</th><th scope="col">Value</th></tr>
217 foreach ( $array as $name => $value ) {
218 echo ' <tr class="content c',(++
$a&1),"\">\n",
219 ' <td>',$name,"</td>\n",
220 ' <td>',$value,"</td>\n",
224 echo "</tbody>\n</table>\n";
228 <p
><button type
="submit" name
="submit" accesskey
="s">Save
Settings (S
)</button
></p
>