Reduced the gfh2 background image contrast a bit since it was hard to read text with it.
[specialops2.git] / options.php
blob350f12d403f335e60bc1756cf06e6bb9fd928df4
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 $varnames = array('messagelist' => 'msglist_layout', 'topiclist' => 'topiclist_layout', 'boardlist' => 'boardlist_layout');
33 ${$listname} = new form_select($listname, 2, $user->$varnames[$listname]);
34 foreach ( glob('lib/class.'.$listname.'_*.php') as $filename ) {
35 include($filename);
36 $tmp = explode('.', $filename);
37 ${$listname}->add_item(constant($tmp[1].'::ID'), constant($tmp[1].'::Name'));
41 array_map('makeoptlists', array('messagelist', 'topiclist', 'boardlist'));
43 // Form submittal
44 if ( isset($_POST['submit']) ) {
45 try {
46 function rangecheck($varname, $min, $max, $errormsg)
48 if (
49 !isset($_POST[$varname]) ||
50 !is_numeric($_POST[$varname]) ||
51 $_POST[$varname] < $min ||
52 $_POST[$varname] > $max
54 throw new OutOfBoundsException(sprintf($errormsg, $min, $max));
57 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 $messagelist->check_value($_POST['messagelist']);
66 $topiclist->check_value($_POST['topiclist']);
67 $boardlist->check_value($_POST['boardlist']);
69 rangecheck('msgs_page', 5, 100, 'Messages per page must be a number between %d and %d.');
70 rangecheck('topics_page', 5, 100, 'Topics per page must be a number between %d and %d.');
72 $tmp = array(
73 'date_format' => 'The custom date format can not be longer than %d characters.',
74 'sig' => 'Your user signature can not be longer than %d characters.',
75 'quote' => 'Your quote can not be longer than %d characters.',
76 'public_email' => 'Your public contact address can not be longer than %d characters.',
77 'private_email' => 'Your private contact address can not be longer than %d characters.'
79 foreach ( $tmp as $varname => $errormsg )
80 lengthcheck($varname, $errormsg);
82 $DB->query('START TRANSACTION');
83 $messagelist->default = $user->msglist_layout = intval($_POST['messagelist']);
84 $topiclist->default = $user->topiclist_layout = intval($_POST['topiclist']);
85 $boardlist->default = $user->boardlist_layout = intval($_POST['boardlist']);
87 $timezone->default = $user->timezone = $_POST['timezone'];
89 $user->date_format = $_POST['date_format'];
90 $user->sig = $_POST['sig'];
91 $user->quote = $_POST['quote'];
92 $user->msgs_page = $_POST['msgs_page'];
93 $user->topics_page = $_POST['topics_page'];
94 $user->always_namelink = intval(isset($_POST['namelink']));
96 $user->public_email = htmlentities($_POST['public_email']);
97 $user->private_email = htmlentities($_POST['private_email']);
98 $DB->commit();
100 $user->userheader();
101 echo '<p class="notice">Settings have been saved.</p>';
102 } catch ( Exception $e ) {
103 $user->userheader();
104 echo '<p class="error">',$e->getMessage(),'</p>';
106 } else
107 $user->userheader();
109 $a = 1;
111 echo '
112 <form method="post" action="',$_SERVER['PHP_SELF'],'">
113 <table id="options">
114 <col/><col/>
115 <thead>
116 <tr>
117 <th scope="col">Option</th>
118 <th scope="col">Value</th>
119 </tr>
120 </thead>';
122 $options['Display Settings'] = array(
123 'Message list layout' => $messagelist->display(),
124 'Topic list layout' => $topiclist->display(),
125 'Board list layout' => $boardlist->display(),
126 'Messages per page' => '<input type="text" name="msgs_page" value="'.$user->msgs_page.
127 '" maxlength="3"/>',
128 'Topics per page' => '<input type="text" name="topics_page" value="'.$user->topics_page.
129 '" maxlength="3"/>',
130 'Timezone offset' => gmdate($user->date_format).' &#xb1; '.$timezone->display().': '.
131 $user->fdate(time()),
132 'Time format' => '<input type="text" name="date_format" value="'.$user->date_format.
133 '" maxlength="'.$limits['date_format'].'"/>',
134 '<label for="namelink">Hyperlink repeated usernames on page</label>'
135 => '<input type="checkbox" name="namelink" id="namelink"'.
136 ($user->always_namelink ? ' checked="checked"' : '').'/>'
139 $options['User Settings'] = array(
140 'Signature' => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars($user->sig).'</textarea>',
141 'Quote' => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars($user->quote).'</textarea>',
142 'Public contact address (E-Mail or IM)'
143 => '<input type="text" name="public_email" value="'.$user->public_email.
144 '" maxlength="'.$limits['public_email'].'"/>',
145 'Private contact address'
146 => '<input type="text" name="private_email" value="'.$user->private_email.
147 '" maxlength="'.$limits['private_email'].'"/>'
150 foreach ( $options as $title => $array ) {
151 echo '<tbody id="',strtr(strtolower($title), ' ', '_'),"\">\n",
152 ' <tr><th scope="rowgroup" colspan="2">',$title,"</th></tr>\n";
154 foreach ( $array as $name => $value )
155 echo
156 ' <tr class="content c',(++$a&1),"\">\n",
157 ' <td>',$name,"</td>\n",
158 ' <td>',$value,"</td>\n",
159 " </tr>\n";
161 echo "</tbody>\n";
165 </table>
167 <p><button type="submit" name="submit" value="save" accesskey="s">Save Settings (S)</button></p>
168 </form>
170 <?php
171 $page->pagefooter();