renamed stuff, nothing will work
[specialops2.git] / options.php
blob85ecc4a97ad3bc89deb0b7d64b06449fe021f326
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 'con.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', 'messageoutput' => 'msglist_style',
54 'topiclist' => 'topiclist_layout', 'boardlist' => 'boardlist_layout');
56 ${$listname} = new form_select($listname, 2, $user->$varnames[$listname]);
58 foreach ( glob('lib/class.'.$listname.'_*.php') as $filename ) {
59 include($filename);
61 $tmp = explode('.', $filename);
62 ${$listname}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
66 array_map('makeoptlists', array('messagelist', 'messageoutput', 'topiclist', 'boardlist'));
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 $messagelist->check_value($_POST['messagelist']);
89 $messageoutput->check_value($_POST['messageoutput']);
90 $topiclist->check_value($_POST['topiclist']);
91 $boardlist->check_value($_POST['boardlist']);
93 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
94 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
96 $uoptions = array();
97 $valid_options = array('namelinks', 'alwaysonline', 'javascript');
99 if ( empty($_POST['options']) ) {
100 $_POST['options'] = array();
103 foreach ( $_POST['options'] as $name => $value ) {
104 if ( in_array($name, $valid_options) ) {
105 $uoptions[] = $name;
109 $tmp = array(
110 'date_format' => 'The custom date format can not be longer than %d characters.',
111 'sig' => 'Your user signature can not be longer than %d characters.',
112 'quote' => 'Your quote can not be longer than %d characters.',
113 'public_email' => 'Your public contact address can not be longer than %d characters.',
114 'private_email' => 'Your private contact address can not be longer than %d characters.'
116 foreach ( $tmp as $varname => $errormsg ) {
117 lengthcheck($varname, $errormsg);
120 $DB->autocommit(false);
122 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
123 $messageoutput->default = $user->msglist_style = intval($_POST['messageoutput']);
124 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
125 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
127 $timezone->default = $user->timezone = $_POST['timezone'];
129 $user->sig = $_POST['sig'];
130 $user->quote = $_POST['quote'];
132 $user->msgs_page = $_POST['msgs_page'];
133 $user->topics_page = $_POST['topics_page'];
134 $user->options = $uoptions;
136 $user->date_format = empty($_POST['date_format']) ? 'Y-m-d H:i:s' : $_POST['date_format'];
138 $user->public_email = htmlentities($_POST['public_email']);
139 $user->private_email = htmlentities($_POST['private_email']);
141 $DB->commit();
143 $user->userheader();
144 echo '<p class="notice">Settings have been saved.</p>';
145 } catch ( Exception $e ) {
146 $user->userheader();
147 echo '<p class="error">',$e->getMessage(),'</p>';
149 } else {
150 $user->userheader();
154 <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
155 <table id="options">
156 <col/><col/>
157 <thead>
158 <tr>
159 <th scope="col">Option</th>
160 <th scope="col">Value</th>
161 </tr>
162 </thead>
164 <?php
165 $options['Display Settings'] = array(
166 'Message list layout' => $messagelist->display().$messageoutput->display(),
167 'Topic list layout' => $topiclist->display(),
168 'Board list layout' => $boardlist->display(),
170 'Messages per page <small>(Valid range 5-100)</small>'
171 => '<input type="text" name="msgs_page" value="'.$user->msgs_page.'" maxlength="3" size="3"/>',
172 'Topics per page <small>(5-100)</small>'
173 => '<input type="text" name="topics_page" value="'.$user->topics_page.'" maxlength="3" size="3"/>',
174 'Timezone offset<br/>
175 <small>(Relative to UTC, doesn\'t auto-change for DST/BST)</small>'
176 => htmlentities(gmdate($user->date_format)).' &#xb1; '.$timezone->display().': '.htmlentities($user->fdate(time())),
177 'Time format<br/>
178 <small>(Don\'t use HTML)</small>'
179 => '<input type="text" name="date_format" value="'.htmlentities($user->date_format).'" maxlength="'.$limits['date_format'].'"/>',
180 '<label for="namelinks">Link repeated usernames on page<br/>
181 <small>(Turn off to save bandwidth/load faster)</small></label>'
182 => makeoptbox('namelinks'),
183 '<label for="alwaysonline">Old-style active time updating<br/>
184 <small>(Turning this off only updates your last active time on form posts, which makes you partially invisible)</small></label>'
185 => makeoptbox('alwaysonline'),
186 '<label for="javascript">Enable Javascript<br/>
187 <small>(Bad idea.)</small></label>'
188 => makeoptbox('javascript')
191 $options['User Settings'] = array(
192 'Signature<br/>
193 <small>(Separator not included, add your own)</small>'
194 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
195 'Quote<br/>
196 <small>(HTML rules are the same as for posts)</small>'
197 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
198 'Public contact address<br/>
199 <small>(E-Mail or IM is acceptable; this is only visible to logged in users)</small>'
200 => '<input type="text" name="public_email" value="'.$user->public_email.'" maxlength="'.$limits['public_email'].'" size="30"/>',
201 'Private contact address<br/>
202 <small>(Not visible to any users other than admin)</small>'
203 => '<input type="text" name="private_email" value="'.$user->private_email.'" maxlength="'.$limits['private_email'].'" size="30"/>'
206 foreach ( $options as $title => $array ) {
207 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
208 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
210 $a = 1;
211 foreach ( $array as $name => $value ) {
212 echo ' <tr class="content c',(++$a&1),"\">\n",
213 ' <td>',$name,"</td>\n",
214 ' <td>',$value,"</td>\n",
215 " </tr>\n";
218 echo "</tbody>\n";
222 </table>
224 <p><button type="submit" name="submit" accesskey="s">Save Settings (S)</button></p>
225 </form>
227 <?php
228 $page->pagefooter();