Update readme for no reason
[specialops2.git] / options.php
blob7550d8892e16c3e8a4022e6af037cde8f7549436
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_contact`', '`private_contact`'
15 require 'con.php';
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];
35 // Timezone selectbox
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
49 $selects = array(
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 ) {
60 include($filename);
62 $tmp = explode('.', $filename);
63 ${$field}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
68 // Form submittal
69 if ( isset($_POST['submit']) ) {
70 try {
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)
81 global $limits;
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.');
95 $uoptions = array();
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) ) {
104 $uoptions[] = $name;
108 $tmp = array(
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']);
139 $DB->commit();
141 $user->userheader();
142 echo '<p class="notice">Settings have been saved.</p>';
143 } catch ( Exception $e ) {
144 $user->userheader();
145 echo '<p class="error">',$e->getMessage(),'</p>';
147 } else {
148 $user->userheader();
152 <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
153 <?php
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 => '&#xb1;'.$timezone->display().': '.htmlentities(strip_tags($user->fdate(time()))),
170 'Time format<br/>
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');
186 } else {
187 $options['Display Settings']['Enable HTTP/1.1 page caching'] = '<input type="checkbox" disabled="disabled"/>';
190 $options['User Settings'] = array(
191 'Signature<br/>
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>',
194 'Quote<br/>
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 ) {
206 echo
207 '<table id="',strtr(strtolower($title), ' ', '_'),'">
208 <col/><col/>
209 <thead>
210 <tr><th scope="rowgroup" colspan="2">',$title,'</th></tr>
211 <tr><th scope="col">Option</th><th scope="col">Value</th></tr>
212 </thead>
213 <tbody>
216 $a = 1;
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",
221 " </tr>\n";
224 echo "</tbody>\n</table>\n";
228 <p><button type="submit" name="submit" accesskey="s">Save Settings (S)</button></p>
229 </form>
231 <?php
232 $page->pagefooter();