Added a bit of useful info to last active times
[specialops2.git] / options.php
blobe0e07b2858d1fe1c38fea9b8cfeddaf8dd23a58d
1 <?php
2 // $Id$
4 $prefetch = array('`boardlist_layout`', '`topiclist_layout`', '`msglist_layout`',
5 '`msgs_page`', '`topics_page`', '`sig`', '`quote`',
6 '`public_email`', '`private_email`');
7 require 'con.php';
8 $page->title = 'Options Screen';
10 if ( ! ($user instanceof authuser) )
11 $page->errorfooter('login');
13 // AAAAAAAAAAAAAAAAAAAAAAAAAGH
14 $tmp = $DB->query('SELECT `COLUMN_NAME` , `CHARACTER_MAXIMUM_LENGTH`
15 FROM `information_schema`.`COLUMNS`
16 WHERE `TABLE_SCHEMA` = \''.DATABASE_NAME.'\'
17 AND `TABLE_NAME` = \'users\'
18 AND `CHARACTER_MAXIMUM_LENGTH` IS NOT NULL');
19 while ( $row = $tmp->fetch_row() )
20 $limits[$row[0]] = $row[1];
21 unset($tmp);
23 // Timezone selectbox
24 $timezone = new form_select('timezone', 2, $user->timezone);
25 for ($i = -12; $i <= 12; $i++)
26 $timezone->add_item($i);
28 // *list layout selectboxes
29 function makeoptlists($listname)
31 global $$listname, $user;
32 $$listname = new form_select($listname, 2, $user->msglist_layout);
33 foreach ( glob('lib/class.'.$listname.'_*') as $classname )
34 include($classname);
35 foreach ( $classes[$listname] as $name => $info )
36 $$listname->add_item($info['ID'], $info['name']);
38 array_map('makeoptlists', array('messagelist', 'topiclist', 'boardlist'));
40 // Form submittal
41 if ( isset($_POST['submit']) ) {
42 try {
43 function rangecheck($varname, $min, $max, $errormsg)
45 if (
46 !isset($_POST[$varname]) ||
47 !is_numeric($_POST[$varname]) ||
48 $_POST[$varname] < $min ||
49 $_POST[$varname] > $max
51 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
54 function lengthcheck($varname, $errormsg)
56 global $limits;
57 if ( !isset($_POST[$varname]) || strlen($_POST[$varname]) > $limits[$varname] )
58 throw new LengthException(sprintf($errormsg, $limits[$varname]));
61 $timezone->check_value($_POST['timezone']);
62 $messagelist->check_value($_POST['messagelist']);
63 $topiclist->check_value($_POST['topiclist']);
64 $boardlist->check_value($_POST['boardlist']);
66 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
67 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
69 $tmp = array(
70 'date_format' => 'The custom date format can not be longer than %d characters.',
71 'sig' => 'Your user signature can not be longer than %d characters.',
72 'quote' => 'Your quote can not be longer than %d characters.',
73 'public_email' => 'Your public contact address can not be longer than %d characters.',
74 'private_email' => 'Your private contact address can not be longer than %d characters.'
76 foreach ( $tmp as $varname => $errormsg )
77 lengthcheck($varname, $errormsg);
79 $DB->query('START TRANSACTION');
80 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
81 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
82 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
84 $timezone->default = $user->timezone = $_POST['timezone'];
86 $user->date_format = $_POST['date_format'];
87 $user->sig = $_POST['sig'];
88 $user->quote = $_POST['quote'];
89 $user->msgs_page = $_POST['msgs_page'];
90 $user->topics_page = $_POST['topics_page'];
91 $user->always_namelink = intval(isset($_POST['namelink']));
93 $user->public_email = htmlentities($_POST['public_email']);
94 $user->private_email = htmlentities($_POST['private_email']);
95 $DB->commit();
97 $user->userheader();
98 echo '<p class="notice">Settings have been saved.</p>';
99 } catch ( Exception $e ) {
100 $user->userheader();
101 echo '<p class="error">',$e->getMessage(),'</p>';
103 } else
104 $user->userheader();
106 $a = 1;
108 echo '
109 <form method="post" action="',$_SERVER['PHP_SELF'],'">
110 <table id="options">
111 <col/><col/>
112 <thead>
113 <tr>
114 <th scope="col">Option</th>
115 <th scope="col">Value</th>
116 </tr>
117 </thead>';
119 $options['Display Settings'] = array(
120 'Message list layout' => $messagelist->display(),
121 'Topic list layout' => $topiclist->display(),
122 'Board list layout' => $boardlist->display(),
123 'Messages per page' => '<input type="text" name="msgs_page" value="'.$user->msgs_page.
124 '" maxlength="3"/>',
125 'Topics per page' => '<input type="text" name="topics_page" value="'.$user->topics_page.
126 '" maxlength="3"/>',
127 'Timezone offset' => gmdate($user->date_format).' &#xb1; '.$timezone->display().': '.
128 $user->fdate(time()),
129 'Time format' => '<input type="text" name="date_format" value="'.$user->date_format.
130 '" maxlength="'.$limits['date_format'].'"/>',
131 '<label for="namelink">Hyperlink repeated usernames on page</label>'
132 => '<input type="checkbox" name="namelink" id="namelink"'.
133 ($user->always_namelink ? ' checked="checked"' : '').'/>'
136 $options['User Settings'] = array(
137 'Signature' => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
138 'Quote' => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
139 'Public e-mail address' => '<input type="text" name="public_email" value="'.$user->public_email.
140 '" maxlength="'.$limits['public_email'].'"/>',
141 'Private e-mail address'=> '<input type="text" name="private_email" value="'.$user->private_email.
142 '" maxlength="'.$limits['private_email'].'"/>'
145 foreach ( $options as $title => $array ) {
146 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
147 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
149 foreach ( $array as $name => $value )
150 echo
151 ' <tr class="content c',(++$a&1),"\">\n",
152 ' <td>',$name,"</td>\n",
153 ' <td>',$value,"</td>\n",
154 " </tr>\n";
156 echo "</tbody>\n";
160 </table>
162 <p><button type="submit" name="submit" value="save" accesskey="s">Save Settings (S)</button></p>
163 </form>
165 <?php
166 $page->pagefooter();