Finished options.php stuff, gave everything in ./ the correctness fixes
[specialops2.git] / options.php
blobdda7401d5a042a0beab89c1894f1428c97b376b8
1 <?php
2 // $Id$
4 $prefetch = array(
5 '`boardlist_layout`', '`topiclist_layout`', '`msglist_layout`',
6 '`msgs_page`', '`topics_page`', '`sig`', '`quote`',
7 '`public_email`', '`private_email`'
8 );
9 require 'con.php';
10 $page->title = 'Options Screen';
12 if ( ! ($user instanceof authuser) ) {
13 $page->errorfooter('login');
17 // AAAAAAAAAAAAAAAAAAAAAAAAAGH
18 $tmp = $DB->query('SELECT `COLUMN_NAME` , `CHARACTER_MAXIMUM_LENGTH`
19 FROM `information_schema`.`COLUMNS`
20 WHERE `TABLE_SCHEMA` = \''.DATABASE_NAME.'\'
21 AND `TABLE_NAME` = \'users\'
22 AND `CHARACTER_MAXIMUM_LENGTH` IS NOT NULL');
23 while ( $row = $tmp->fetch_row() ) {
24 $limits[$row[0]] = $row[1];
28 // Timezone selectbox
29 $timezone = new form_select('timezone', 2, $user->timezone);
30 for ($i = -12; $i <= 12; $i++) {
31 $timezone->add_item($i);
35 // function to make the {topic,message,board}list selectboxes
36 function makeoptlists($listname)
38 global ${$listname}, $user;
40 $varnames = array('messagelist' => 'msglist_layout', 'topiclist' => 'topiclist_layout', 'boardlist' => 'boardlist_layout');
42 ${$listname} = new form_select($listname, 2, $user->$varnames[$listname]);
44 foreach ( glob('lib/class.'.$listname.'_*.php') as $filename ) {
45 include($filename);
47 $tmp = explode('.', $filename);
48 ${$listname}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
52 array_map('makeoptlists', array('messagelist', 'topiclist', 'boardlist'));
54 // Form submittal
55 if ( isset($_POST['submit']) ) {
56 try {
57 function rangecheck($varname, $min, $max, $errormsg)
59 if ( !isset($_POST[$varname]) || !is_numeric($_POST[$varname]) ||
60 $_POST[$varname] < $min || $_POST[$varname] > $max ) {
61 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
65 function lengthcheck($varname, $errormsg)
67 global $limits;
68 if ( !isset($_POST[$varname]) || strlen($_POST[$varname]) > $limits[$varname] ) {
69 throw new LengthException(sprintf($errormsg, $limits[$varname]));
73 $timezone->check_value($_POST['timezone']);
74 $messagelist->check_value($_POST['messagelist']);
75 $topiclist->check_value($_POST['topiclist']);
76 $boardlist->check_value($_POST['boardlist']);
78 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
79 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
81 $uoptions = array();
82 $valid_options = array('namelinks');
84 if ( empty($_POST['options']) ) {
85 $_POST['options'] = array();
88 foreach ( $_POST['options'] as $name => $value ) {
89 if ( in_array($name, $valid_options) ) {
90 $uoptions[] = $name;
94 $tmp = array(
95 'date_format' => 'The custom date format can not be longer than %d characters.',
96 'sig' => 'Your user signature can not be longer than %d characters.',
97 'quote' => 'Your quote can not be longer than %d characters.',
98 'public_email' => 'Your public contact address can not be longer than %d characters.',
99 'private_email' => 'Your private contact address can not be longer than %d characters.'
101 foreach ( $tmp as $varname => $errormsg ) {
102 lengthcheck($varname, $errormsg);
105 $DB->autocommit(false);
107 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
108 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
109 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
111 $timezone->default = $user->timezone = $_POST['timezone'];
113 $user->sig = $_POST['sig'];
114 $user->quote = $_POST['quote'];
116 $user->msgs_page = $_POST['msgs_page'];
117 $user->topics_page = $_POST['topics_page'];
118 $user->options = $uoptions;
120 $user->date_format = empty($_POST['date_format']) ? 'Y-m-d H:i:s' : $_POST['date_format'];
122 $user->public_email = htmlentities($_POST['public_email']);
123 $user->private_email = htmlentities($_POST['private_email']);
125 $DB->commit();
127 $user->userheader();
128 echo '<p class="notice">Settings have been saved.</p>';
129 } catch ( Exception $e ) {
130 $user->userheader();
131 echo '<p class="error">',$e->getMessage(),'</p>';
133 } else {
134 $user->userheader();
138 <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
139 <table id="options">
140 <col/><col/>
141 <thead>
142 <tr>
143 <th scope="col">Option</th>
144 <th scope="col">Value</th>
145 </tr>
146 </thead>
148 <?php
149 $options['Display Settings'] = array(
150 'Message list layout' => $messagelist->display(),
151 'Topic list layout' => $topiclist->display(),
152 'Board list layout' => $boardlist->display(),
154 'Messages per page <small>(5-100)</small>'
155 => '<input type="text" name="msgs_page" value="'.$user->msgs_page.'" maxlength="3" size="3"/>',
156 'Topics per page <small>(5-100)</small>'
157 => '<input type="text" name="topics_page" value="'.$user->topics_page.'" maxlength="3" size="3"/>',
158 'Timezone offset <small>(Relative to UTC)</small>'
159 => htmlentities(gmdate($user->date_format)).' &#xb1; '.$timezone->display().': '.htmlentities($user->fdate(time())),
160 'Time format <small>(Don\'t use HTML)</small>'
161 => '<input type="text" name="date_format" value="'.htmlentities($user->date_format).'" maxlength="'.$limits['date_format'].'"/>',
162 '<label for="namelink">Link repeated usernames on page</label>'
163 => '<input type="checkbox" name="options[namelinks]" id="namelink"'.( strpos($user->options, 'namelinks') !== false ? ' checked="checked"' : '' ).'/>'
166 $options['User Settings'] = array(
167 'Signature <small>(Separator not included)</small>'
168 => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
169 'Quote <small>(HTML rules are same as for posts)</small>'
170 => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
171 'Public contact address <small>(E-Mail or IM)</small>'
172 => '<input type="text" name="public_email" value="'.$user->public_email.'" maxlength="'.$limits['public_email'].'"/>',
173 'Private contact address <small>(Not shown to normal users)</small>'
174 => '<input type="text" name="private_email" value="'.$user->private_email.'" maxlength="'.$limits['private_email'].'"/>'
177 foreach ( $options as $title => $array ) {
178 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
179 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
181 $a = 1;
182 foreach ( $array as $name => $value ) {
183 echo ' <tr class="content c',(++$a&1),"\">\n",
184 ' <td>',$name,"</td>\n",
185 ' <td>',$value,"</td>\n",
186 " </tr>\n";
189 echo "</tbody>\n";
193 </table>
195 <p><button type="submit" name="submit" accesskey="s">Save Settings (S)</button></p>
196 </form>
198 <?php
199 $page->pagefooter();