Database rewrite, first half
[specialops2.git] / options.php
blob6c2a91a532de37920975c427d514dc68ede4182e
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 $language = new form_select('language', 2, $user->language, ( defined('NO_GETTEXT') ? array('readonly' => 'readonly') : array() ));
27 preg_match_all('#(.*)\: (.*)#', file_get_contents('lang/LINGUAS'), $matches, PREG_SET_ORDER);
28 foreach ( $matches as $lingua )
29 $language->add_item($lingua[1], $lingua[2]);
31 $messagelist = new form_select('messagelist', 2, $user->msglist_layout);
32 foreach ( glob('lib/class.messagelist_*') as $classname )
33 include($classname);
34 foreach ( $classes['messagelist'] as $name => $info )
35 $messagelist->add_item($info['ID'], $info['name']);
37 $topiclist = new form_select('topiclist', 2, $user->topiclist_layout);
38 foreach ( glob('lib/class.topiclist_*') as $classname )
39 include($classname);
40 foreach ( $classes['topiclist'] as $name => $info )
41 $topiclist->add_item($info['ID'], $info['name']);
43 $boardlist = new form_select('boardlist', 2, $user->boardlist_layout);
44 foreach ( glob('lib/class.boardlist_*') as $classname )
45 include($classname);
46 foreach ( $classes['boardlist'] as $name => $info )
47 $boardlist->add_item($info['ID'], $info['name']);
50 // Form submittal
51 if ( isset($_POST['submit']) ) {
52 try {
53 function rangecheck($varname, $min, $max, $errormsg) {
54 if ( !isset($_POST[$varname]) || !is_numeric($_POST[$varname]) || $_POST[$varname] < $min || $_POST[$varname] > $max )
55 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
58 function lengthcheck($varname, $errormsg) {
59 global $limits;
60 if ( !isset($_POST[$varname]) || strlen($_POST[$varname]) > $limits[$varname] )
61 throw new LengthException(sprintf($errormsg, $limits[$varname]));
64 $timezone->check_value($_POST['timezone']);
65 $language->check_value($_POST['language']);
66 $messagelist->check_value($_POST['messagelist']);
67 $topiclist->check_value($_POST['topiclist']);
68 $boardlist->check_value($_POST['boardlist']);
70 rangecheck('msgs_page', 5, 100, _('Messages per page must be a number between %d and %d.'));
71 rangecheck('topics_page', 5, 100, _('Topics per page must be a number between %d and %d.'));
73 $tmp = array(
74 'date_format' => _('The custom date format can not be longer than %d characters.'),
75 'sig' => _('Your user signature can not be longer than %d characters.'),
76 'quote' => _('Your quote can not be longer than %d characters.'),
77 'public_email' => _('Your public contact address can not be longer than %d characters.'),
78 'private_email' => _('Your private contact address can not be longer than %d characters.')
80 foreach ( $tmp as $varname => $errormsg )
81 lengthcheck($varname, $errormsg);
83 $DB->query('START TRANSACTION');
84 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
85 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
86 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
88 $timezone->default = $user->timezone = $_POST['timezone'];
89 $language->default = $user->language = $_POST['language'];
91 $user->date_format = $_POST['date_format'];
92 $user->sig = $_POST['sig'];
93 $user->quote = $_POST['quote'];
95 $user->public_email = htmlentities($_POST['public_email']);
96 $user->private_email = htmlentities($_POST['private_email']);
97 $DB->commit();
99 $user->userheader();
100 echo '<div class="notice">',_('Settings have been saved.'),'</div>';
101 } catch ( Exception $e ) {
102 $user->userheader();
103 echo '<div class="error">',$e->getMessage(),'</div>';
105 } else
106 $user->userheader();
108 $a = 1;
110 echo '<form method="post" action="',$_SERVER['PHP_SELF'],'">
111 <table id="options">
112 <thead>
113 <tr>
114 <th scope="col">Option</th>
115 <th scope="col">Value</th>
116 </tr>
117 </thead>
119 <tbody id="display_settings">
120 <tr><th scope="rowgroup" colspan="2">',_('Display Settings'),'</th></tr>
121 <tr class="content c',(++$a&1),'">
122 <td>',_('Message list view:'),'</td>
123 <td>',
124 $messagelist->display(),
125 ' </td>
126 </tr>
127 <tr class="content c',(++$a&1),'">
128 <td>',_('Topic list view:'),'</td>
129 <td>',
130 $topiclist->display(),
131 ' </td>
132 </tr>
133 <tr class="content c',(++$a&1),'">
134 <td>',_('Board list view:'),'</td>
135 <td>',
136 $boardlist->display(),
137 ' </td>
138 </tr>
139 <tr class="content c',(++$a&1),'">
140 <td>',_('Messages per page:'),'</td>
141 <td><input type="text" name="msgs_page" value="',$user->msgs_page,'" maxlength="',$limits['msgs_page'],'" readonly="readonly"/></td>
142 </tr>
143 <tr class="content c',(++$a&1),'">
144 <td>',_('Topics per page:'),'</td>
145 <td><input type="text" name="topics_page" value="',$user->topics_page,'" maxlength="',$limits['topics_page'],'" readonly="readonly"/></td>
146 </tr>
147 <tr class="content c',(++$a&1),'">
148 <td>',_('Timezone offset:'),'</td>
149 <td>',gmdate($user->date_format),' &#xb1; ',
150 $timezone->display(),
151 ' </td>
152 </tr>
153 <tr class="content c',(++$a&1),'">
154 <td>',_('Time format:'),'</td>
155 <td><input type="text" name="date_format" value="',$user->date_format,'" maxlength="',$limits['date_format'],'"/></td>
156 </tr>
157 <tr class="content c',(++$a&1),'">
158 <td>',_('Language:'),'</td>
159 <td>',
160 $language->display(),
161 ' </td>
162 </tr>
163 </tbody>
165 <tbody id="user_settings">
166 <tr><th scope="rowgroup" colspan="2">',_('User Settings'),'</th></tr>
167 <tr class="content c',(++$a&1),'">
168 <td>',_('Signature:'),'<br/>
169 <small>',_('Put your own separator in.'),'</small></td>
170 <td><textarea rows="4" cols="60" name="sig">',htmlspecialchars($user->sig),'</textarea></td>
171 </tr>
172 <tr class="content c',(++$a&1),'">
173 <td>',_('Quote:'),'</td>
174 <td><textarea rows="4" cols="60" name="quote">',htmlspecialchars($user->quote),'</textarea></td>
175 </tr>
176 <tr class="content c',(++$a&1),'">
177 <td>',_('Public e-mail address:'),'<br/>
178 <small>',_('This address will be visible only to registered users.'),'</small></td>
179 <td><input type="text" name="public_email" value="',$user->public_email,'" maxlength="',$limits['public_email'],'"/></td>
180 </tr>
181 <tr class="content c',(++$a&1),'">
182 <td>',_('Private e-mail address:'),'<br/>
183 <small>',_('This address will not be displayed in public.'),'</small></td>
184 <td><input type="text" name="private_email" value="',$user->private_email,'" maxlength="',$limits['private_email'],'"/></td>
185 </tr>
186 </tbody>
187 </table>
189 <div><button type="submit" name="submit" value="save" accesskey="s">',_('Save Settings'),' (S)</button></div>
190 </form>';
192 $page->pagefooter();