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_email`', '`private_email`'
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');
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_email' => 'Your public contact address can not be longer than %d characters.',
113 'private_email' => '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_email
= htmlentities($_POST['public_email']);
137 $user->private_email
= htmlentities($_POST['private_email']);
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'] ?>">
157 <th scope
="col">Option
</th
>
158 <th scope
="col">Value
</th
>
163 $options['Display Settings'] = array(
164 'Message list layout' => $msglist_layout->display().$msglist_style->display(),
165 'Topic list layout' => $topiclist_layout->display(),
166 'Board list layout' => $boardlist_layout->display(),
168 'Messages per page <small>(Valid range 5-100)</small>'
169 => '<input type="text" name="msgs_page" value="'.$user->msgs_page
.'" maxlength="3" size="3"/>',
170 'Topics per page <small>(5-100)</small>'
171 => '<input type="text" name="topics_page" value="'.$user->topics_page
.'" maxlength="3" size="3"/>',
172 'Timezone offset<br/>
173 <small>(Relative to UTC)</small>'
174 => htmlentities(gmdate($user->date_format
)).' ± '.$timezone->display().': '.htmlentities(strip_tags($user->fdate(time()))),
176 <small>(Don\'t use HTML)</small>'
177 => '<input type="text" name="date_format" value="'.htmlentities($user->date_format
).'" maxlength="'.$limits['date_format'].'"/>',
178 '<label for="namelinks">Link repeated usernames on page<br/>
179 <small>(Turn off to save bandwidth/load faster)</small></label>'
180 => makeoptbox('namelinks'),
181 '<label for="alwaysonline">Old-style active time updating<br/>
182 <small>(Turning this off only updates your last active time on form posts, which makes you partially invisible)</small></label>'
183 => makeoptbox('alwaysonline'),
184 '<label for="javascript">Enable Javascript<br/>
185 <small>(Bad idea.)</small></label>'
186 => makeoptbox('javascript')
189 $options['User Settings'] = array(
191 <small>(Separator not included, add your own)</small>'
192 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig
).'</textarea>',
194 <small>(HTML rules are the same as for posts)</small>'
195 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote
).'</textarea>',
196 'Public contact address<br/>
197 <small>(E-Mail or IM is acceptable; this is only visible to logged in users)</small>'
198 => '<input type="text" name="public_email" value="'.$user->public_email
.'" maxlength="'.$limits['public_email'].'" size="30"/>',
199 'Private contact address<br/>
200 <small>(Not visible to any users other than admin)</small>'
201 => '<input type="text" name="private_email" value="'.$user->private_email
.'" maxlength="'.$limits['private_email'].'" size="30"/>'
204 foreach ( $options as $title => $array ) {
205 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
206 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
209 foreach ( $array as $name => $value ) {
210 echo ' <tr class="content c',(++
$a&1),"\">\n",
211 ' <td>',$name,"</td>\n",
212 ' <td>',$value,"</td>\n",
222 <p
><button type
="submit" name
="submit" accesskey
="s">Save
Settings (S
)</button
></p
>