.
[specialops2.git] / options.php
blob80c2583e74bce1366729d93c73339fba9c98b1db
1 <?php
2 // $Id$
4 $prefetch = array('`boardlist_layout`', '`topiclist_layout`', '`msglist_layout`', '`msgs_page`', '`topics_page`', '`sig`', '`quote`');
5 require 'con.php';
6 $page->title = 'Options Screen';
8 if ( ! ($user instanceof authuser) ) {
9 $page->errorfooter('login');
12 // leet hax
13 $tmp = $DB->query('DESCRIBE `users`');
14 while ( $row = $tmp->fetch_assoc() ) {
15 preg_match('#\(([0-9]+)\)#', $row['Type'], $limits[$row['Field']]);
16 $limits[$row['Field']] = $limits[$row['Field']][1];
18 unset($tmp);
21 // Make selectboxes, throw exceptions
22 $timezone = new form_select('timezone', 2, $user->timezone);
23 for ($i = -12; $i <= 12; $i++)
24 $timezone->add_item($i);
26 $messagelist = new form_select('messagelist', 2, $user->msglist_layout);
27 foreach ( glob('lib/class.messagelist_*') as $classname )
28 include($classname);
29 foreach ( $classes['messagelist'] as $name => $info )
30 $messagelist->add_item($info['ID'], $info['name']);
32 $topiclist = new form_select('topiclist', 2, $user->topiclist_layout);
33 foreach ( glob('lib/class.topiclist_*') as $classname )
34 include($classname);
35 foreach ( $classes['topiclist'] as $name => $info )
36 $topiclist->add_item($info['ID'], $info['name']);
38 $boardlist = new form_select('boardlist', 2, $user->boardlist_layout);
39 foreach ( glob('lib/class.boardlist_*') as $classname )
40 include($classname);
41 foreach ( $classes['boardlist'] as $name => $info )
42 $boardlist->add_item($info['ID'], $info['name']);
45 // Form submittal
46 if ( isset($_POST['submit']) ) {
47 try {
48 function rangecheck($varname, $min, $max, $errormsg) {
49 if ( !isset($_POST[$varname]) || !is_numeric($_POST[$varname]) || $_POST[$varname] < $min || $_POST[$varname] > $max )
50 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
53 function lengthcheck($varname, $errormsg) {
54 global $limits;
55 if ( !isset($_POST[$varname]) || strlen($_POST[$varname]) > $limits[$varname] )
56 throw new LengthException(sprintf($errormsg, $limits[$varname]));
59 $timezone->check_value($_POST['timezone']);
60 $messagelist->check_value($_POST['messagelist']);
61 $topiclist->check_value($_POST['topiclist']);
62 $boardlist->check_value($_POST['boardlist']);
64 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
65 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
67 $tmp = array(
68 'date_format' => 'The custom date format can not be longer than %d characters.',
69 'sig' => 'Your user signature can not be longer than %d characters.',
70 'quote' => 'Your quote can not be longer than %d characters.',
71 'public_email' => 'Your public contact address can not be longer than %d characters.',
72 'private_email' => 'Your private contact address can not be longer than %d characters.'
74 foreach ( $tmp as $varname => $errormsg )
75 lengthcheck($varname, $errormsg);
77 $DB->query('START TRANSACTION');
78 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
79 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
80 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
82 $timezone->default = $user->timezone = $_POST['timezone'];
84 $user->date_format = $_POST['date_format'];
85 $user->sig = $_POST['sig'];
86 $user->quote = $_POST['quote'];
87 $user->msgs_page = $_POST['msgs_page'];
89 $user->public_email = htmlentities($_POST['public_email']);
90 $user->private_email = htmlentities($_POST['private_email']);
91 $DB->commit();
93 $user->userheader();
94 echo '<div class="notice">Settings have been saved.</div>';
95 } catch ( Exception $e ) {
96 $user->userheader();
97 echo '<div class="error">',$e->getMessage(),'</div>';
99 } else
100 $user->userheader();
102 $a = 1;
104 echo '<form method="post" action="',$_SERVER['PHP_SELF'],'">
105 <table id="options">
106 <thead>
107 <tr>
108 <th scope="col">Option</th>
109 <th scope="col">Value</th>
110 </tr>
111 </thead>',"\n";
113 $options['Display Settings'] = array(
114 'Message list view' => $messagelist->display(),
115 'Topic list view' => $topiclist->display(),
116 'Board list view' => $boardlist->display(),
117 'Messages per page' => '<input type="text" name="msgs_page" value="'.$user->msgs_page.
118 '" maxlength="'.$limits['msgs_page'].'"/>',
119 'Topics per page' => '<input type="text" name="topics_page" value="'.$user->topics_page.
120 '" maxlength="'.$limits['topics_page'].'" readonly="readonly"/>',
121 'Timezone offset' => gmdate($user->date_format).' &#xb1; '.$timezone->display(),
122 'Time format' => '<input type="text" name="date_format" value="'.$user->date_format.
123 '" maxlength="'.$limits['date_format'].'"/>'
126 $options['User Settings'] = array(
127 'Signature' => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
128 'Quote' => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
129 'Public e-mail address' => '<input type="text" name="public_email" value="'.$user->public_email.
130 '" maxlength="'.$limits['public_email'].'"/>',
131 'Private e-mail address'=> '<input type="text" name="private_email" value="'.$user->private_email.
132 '" maxlength="'.$limits['private_email'].'"/>'
135 foreach ( $options as $title => $array ) {
136 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),'">',"\n",
137 '<tr><th scope="rowgroup" colspan="2">',$title,'</th></tr>';
139 foreach ( $array as $name => $value )
140 echo '<tr class="content c',(++$a&1),'">',"\n",
141 "\t<td>",$name,":</td>\n",
142 "\t<td>",$value,"</td>\n",
143 "</tr>\n";
145 echo "</tbody>\n";
148 echo '</table>
150 <div><button type="submit" name="submit" value="save" accesskey="s">Save Settings (S)</button></div>
151 </form>';
153 $page->pagefooter();