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 if ( 0 >= $user->points
) {
22 $page->errorfooter('points');
25 $user->userlinks
['Theme Settings'] = 'theme';
28 // AAAAAAAAAAAAAAAAAAAAAAAAAGH
29 $tmp = $DB->query('SELECT `COLUMN_NAME` , `CHARACTER_MAXIMUM_LENGTH`
30 FROM `information_schema`.`COLUMNS`
31 WHERE `TABLE_SCHEMA` = "'.DATABASE_NAME
.'"
32 AND `TABLE_NAME` = "users"
33 AND `CHARACTER_MAXIMUM_LENGTH` IS NOT NULL');
34 while ( $row = $tmp->fetch_row() ) {
35 $limits[$row[0]] = $row[1];
40 $timezone = new HTML_Select('timezone', 2, $user->timezone
);
41 for ($i = -12; $i <= 12; $i++
) {
42 $timezone->add_item($i);
45 // function to make the $user->options checkboxes
46 function makeoptbox($name)
48 return '<input type="checkbox" name="options['.$name.']" id="'.$name.'"'.
49 ( strpos($GLOBALS['user']->options
, $name) !== false ?
' checked="checked"' : '' ).'/>';
52 // make the {topic,message,board}list selectboxes
54 'Messagelist' => 'msglist_layout',
55 'Messagestyle' => 'msglist_style',
56 'Topiclist' => 'topiclist_layout',
57 'Boardlist' => 'boardlist_layout'
60 foreach ( $selects as $class => $field ) {
61 $
{$field} = new HTML_Select($field, 2, $user->$field);
63 foreach ( glob('lib/class.'.$class.'_*.php') as $filename ) {
66 $tmp = explode('.', $filename);
67 $
{$field}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
73 if ( isset($_POST['submit']) ) {
75 function rangecheck($varname, $min, $max, $errormsg)
77 if ( !isset($_POST[$varname]) ||
!is_numeric($_POST[$varname]) ||
78 $_POST[$varname] < $min ||
$_POST[$varname] > $max ) {
79 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
83 function lengthcheck($varname, $errormsg)
86 if ( !isset($_POST[$varname]) ||
strlen($_POST[$varname]) > $limits[$varname] ) {
87 throw new LengthException(sprintf($errormsg, $limits[$varname]));
91 $timezone->check_value($_POST['timezone']);
92 foreach ( $selects as $field ) {
93 $
{$field}->check_value($_POST[$field]);
96 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
97 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
100 $valid_options = array('namelinks', 'translucent', 'javascript', 'cache', 'quickpost');
102 if ( empty($_POST['options']) ) {
103 $_POST['options'] = array();
106 foreach ( $_POST['options'] as $name => $value ) {
107 if ( in_array($name, $valid_options) ) {
113 'date_format' => 'The custom date format can not be longer than %d characters.',
114 'sig' => 'Your user signature can not be longer than %d characters.',
115 'quote' => 'Your quote can not be longer than %d characters.',
116 'public_contact' => 'Your public contact address can not be longer than %d characters.',
117 'private_contact' => 'Your private contact address can not be longer than %d characters.'
119 foreach ( $tmp as $varname => $errormsg ) {
120 lengthcheck($varname, $errormsg);
123 $DB->autocommit(false);
125 foreach ( $selects as $field ) {
126 $
{$field}->default = $user->$field = intval($_POST[$field]);
129 $timezone->default = $user->timezone
= $_POST['timezone'];
131 $user->sig
= $_POST['sig'];
132 $user->quote
= $_POST['quote'];
134 $user->msgs_page
= $_POST['msgs_page'];
135 $user->topics_page
= $_POST['topics_page'];
136 $user->options
= $uoptions;
138 $user->date_format
= empty($_POST['date_format']) ?
'Y-m-d H:i:s' : $_POST['date_format'];
140 $user->public_contact
= htmlentities($_POST['public_contact']);
141 $user->private_contact
= htmlentities($_POST['private_contact']);
146 echo '<p class="notice">Settings have been saved.</p>';
147 } catch ( Exception
$e ) {
149 echo '<p class="error">',$e->getMessage(),'</p>';
156 <form method
="post" action
="<?php echo $_SERVER['PHP_SELF'] ?>">
158 $options['Display Settings'] = array(
159 'Message list layout<br/>
160 <small>(Threaded view disables messages per page setting)</small>'
161 => $msglist_layout->display().$msglist_style->display(),
162 'Topic list layout' => $topiclist_layout->display(),
163 'Board list layout' => $boardlist_layout->display(),
165 'Messages per page<br/>
166 <small>(Between 5-100)</small>'
167 => '<input type="text" name="msgs_page" value="'.$user->msgs_page
.'" maxlength="3" size="3"/>',
168 'Topics per page<br/>
169 <small>(Between 5-100)</small>'
170 => '<input type="text" name="topics_page" value="'.$user->topics_page
.'" maxlength="3" size="3"/>',
171 'Timezone offset<br/>
172 <small>(Relative to UTC: '.htmlentities(gmdate($user->date_format
)).')</small>'
173 => '±'.$timezone->display().': '.htmlentities(strip_tags($user->fdate(time()))),
175 <small>(See PHP strftime documentation)</small>'
176 => '<input type="text" name="date_format" value="'.htmlentities($user->date_format
).'" maxlength="'.$limits['date_format'].'"/>',
177 '<label for="namelinks">Link repeated usernames on page<br/>
178 <small>(Turn off to save bandwidth/load faster)</small></label>'
179 => makeoptbox('namelinks'),
180 '<label for="translucent">Partial Invisibility<br/>
181 <small>(Turning this on makes you show up online only when you press form submit buttons)</small></label>'
182 => makeoptbox('translucent'),
183 '<label for="javascript">Enable Javascript<br/>
184 <small>(Enables optional functionality such as auto-refreshing on the board list)</small></label>'
185 => makeoptbox('javascript'),
186 '<label for="cache">Enable page caching<br/>
187 <small>(Leave on to speed up page loads, turn off to make theme editing easier)</small></label>'
188 => makeoptbox('cache'),
189 '<label for="quickpost">Use quickpost box<br/>
190 <small>(Puts a thing at the bottom of the message list)</small></label>'
191 => makeoptbox('quickpost')
194 $options['User Settings'] = array(
196 <small>(The bit that gets put at the bottom of your posts)</small>'
197 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig
).'</textarea>',
199 <small>(Some HTML allowed, same as for posts)</small>'
200 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote
).'</textarea>',
201 'Public contact address<br/>
202 <small>(Only visible to logged in users; can be a mailto/http/etc.)</small>'
203 => '<input type="text" name="public_contact" value="'.$user->public_contact
.'" maxlength="'.$limits['public_contact'].'" size="30"/>',
204 'Private contact address<br/>
205 <small>(Only visible to you and admins)</small>'
206 => '<input type="text" name="private_contact" value="'.$user->private_contact
.'" maxlength="'.$limits['private_contact'].'" size="30"/>'
209 foreach ( $options as $title => $array ) {
211 '<table id="',strtr(strtolower($title), ' ', '_'),'">
214 <tr><th scope="rowgroup" colspan="2">',$title,'</th></tr>
215 <tr><th scope="col">Option</th><th scope="col">Value</th></tr>
221 foreach ( $array as $name => $value ) {
222 echo ' <tr class="content c',(++
$a&1),"\">\n",
223 ' <td>',$name,"</td>\n",
224 ' <td>',$value,"</td>\n",
228 echo "</tbody>\n</table>\n";
232 <p
><button type
="submit" name
="submit" accesskey
="s">Save
Settings (S
)</button
></p
>