Apparently not.
[specialops2.git] / options.php
blob7078b7534676e930fced964d8644ddf8a5360434
1 <?php
2 /**
3 * User Settings Editor
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://COPYING
7 * @version $Id$
8 */
10 $prefetch = array(
11 '`boardlist_layout`', '`topiclist_layout`', '`msglist_layout`',
12 '`msgs_page`', '`topics_page`', '`sig`', '`quote`',
13 '`public_email`', '`private_email`'
15 require 'conf.php';
16 $page->title = 'Options Screen';
18 if ( ! ($user instanceof authuser) ) {
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];
35 // Timezone selectbox
36 $timezone = new form_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 // function to make the {topic,message,board}list selectboxes
49 function makeoptlists($listname)
51 global ${$listname}, $user;
53 $varnames = array('messagelist' => 'msglist_layout', 'topiclist' => 'topiclist_layout', 'boardlist' => 'boardlist_layout');
55 ${$listname} = new form_select($listname, 2, $user->$varnames[$listname]);
57 foreach ( glob('lib/class.'.$listname.'_*.php') as $filename ) {
58 include($filename);
60 $tmp = explode('.', $filename);
61 ${$listname}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
65 array_map('makeoptlists', array('messagelist', 'topiclist', 'boardlist'));
67 // Form submittal
68 if ( isset($_POST['submit']) ) {
69 try {
70 function rangecheck($varname, $min, $max, $errormsg)
72 if ( !isset($_POST[$varname]) || !is_numeric($_POST[$varname]) ||
73 $_POST[$varname] < $min || $_POST[$varname] > $max ) {
74 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
78 function lengthcheck($varname, $errormsg)
80 global $limits;
81 if ( !isset($_POST[$varname]) || strlen($_POST[$varname]) > $limits[$varname] ) {
82 throw new LengthException(sprintf($errormsg, $limits[$varname]));
86 $timezone->check_value($_POST['timezone']);
87 $messagelist->check_value($_POST['messagelist']);
88 $topiclist->check_value($_POST['topiclist']);
89 $boardlist->check_value($_POST['boardlist']);
91 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
92 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
94 $uoptions = array();
95 $valid_options = array('namelinks', 'alwaysonline');
97 if ( empty($_POST['options']) ) {
98 $_POST['options'] = array();
101 foreach ( $_POST['options'] as $name => $value ) {
102 if ( in_array($name, $valid_options) ) {
103 $uoptions[] = $name;
107 $tmp = array(
108 'date_format' => 'The custom date format can not be longer than %d characters.',
109 'sig' => 'Your user signature can not be longer than %d characters.',
110 'quote' => 'Your quote can not be longer than %d characters.',
111 'public_email' => 'Your public contact address can not be longer than %d characters.',
112 'private_email' => 'Your private contact address can not be longer than %d characters.'
114 foreach ( $tmp as $varname => $errormsg ) {
115 lengthcheck($varname, $errormsg);
118 $DB->autocommit(false);
120 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
121 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
122 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
124 $timezone->default = $user->timezone = $_POST['timezone'];
126 $user->sig = $_POST['sig'];
127 $user->quote = $_POST['quote'];
129 $user->msgs_page = $_POST['msgs_page'];
130 $user->topics_page = $_POST['topics_page'];
131 $user->options = $uoptions;
133 $user->date_format = empty($_POST['date_format']) ? 'Y-m-d H:i:s' : $_POST['date_format'];
135 $user->public_email = htmlentities($_POST['public_email']);
136 $user->private_email = htmlentities($_POST['private_email']);
138 $DB->commit();
140 $user->userheader();
141 echo '<p class="notice">Settings have been saved.</p>';
142 } catch ( Exception $e ) {
143 $user->userheader();
144 echo '<p class="error">',$e->getMessage(),'</p>';
146 } else {
147 $user->userheader();
151 <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
152 <table id="options">
153 <col/><col/>
154 <thead>
155 <tr>
156 <th scope="col">Option</th>
157 <th scope="col">Value</th>
158 </tr>
159 </thead>
161 <?php
162 $options['Display Settings'] = array(
163 'Message list layout' => $messagelist->display(),
164 'Topic list layout' => $topiclist->display(),
165 'Board list layout' => $boardlist->display(),
167 'Messages per page <small>(Valid range 5-100)</small>'
168 => '<input type="text" name="msgs_page" value="'.$user->msgs_page.'" maxlength="3" size="3"/>',
169 'Topics per page <small>(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, doesn\'t auto-change for DST/BST)</small>'
173 => htmlentities(gmdate($user->date_format)).' &#xb1; '.$timezone->display().': '.htmlentities($user->fdate(time())),
174 'Time format<br/>
175 <small>(Don\'t use HTML)</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="alwaysonline">Old-style active time updating<br/>
181 <small>(Turning this off only updates your last active time on form posts, which makes you partially invisible)</small></label>'
182 => makeoptbox('alwaysonline')
185 $options['User Settings'] = array(
186 'Signature<br/>
187 <small>(Separator not included, add your own)</small>'
188 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
189 'Quote<br/>
190 <small>(HTML rules are the same as for posts)</small>'
191 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
192 'Public contact address<br/>
193 <small>(E-Mail or IM is acceptable; this is only visible to logged in users)</small>'
194 => '<input type="text" name="public_email" value="'.$user->public_email.'" maxlength="'.$limits['public_email'].'" size="30"/>',
195 'Private contact address<br/>
196 <small>(Not visible to any users other than admin)</small>'
197 => '<input type="text" name="private_email" value="'.$user->private_email.'" maxlength="'.$limits['private_email'].'" size="30"/>'
200 foreach ( $options as $title => $array ) {
201 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
202 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
204 $a = 1;
205 foreach ( $array as $name => $value ) {
206 echo ' <tr class="content c',(++$a&1),"\">\n",
207 ' <td>',$name,"</td>\n",
208 ' <td>',$value,"</td>\n",
209 " </tr>\n";
212 echo "</tbody>\n";
216 </table>
218 <p><button type="submit" name="submit" accesskey="s">Save Settings (S)</button></p>
219 </form>
221 <?php
222 $page->pagefooter();