Improved userlist.php from O(n^2) to O(n)
[specialops2.git] / options.php
blob53027067dd4f54c3ba96bb6a7e8af9a11dd26028
1 <?php
2 // $Id$
4 require 'con.php';
5 $page->title = _('Options and Settings');
7 if ( ! ($user instanceof authuser) ) {
8 $page->errorfooter('login');
11 if ( isset($_POST['submit']) ) {
12 try {
15 * var: variable to check
16 * min: minimum allowed value
17 * max: maximum allowed value
18 * errormsg: message to give in thrown exception if variable doesn't pass checks
20 function rangecheck(&$var, $min, $max, $errormsg) {
21 if ( !isset($var) || !is_numeric($var) || $var < $min || $var > $max )
22 throw new invalidInputException($errormsg);
25 rangecheck($_POST['tz'], -12, 12, _('"Timezone" must be an integer between -12 and 12.'));
26 $user->u_timezone = $_POST['tz'];
27 $user->u_language = $_POST['lng'];
29 if ( !isset($_POST['mlist_layout'], $_POST['tlist_layout'], $_POST['sig'], $_POST['quote']) )
30 throw new invalidInputException(_('One or more form field values is missing.'));
31 $user->u_mlist_view = intval($_POST['mlist_layout']);
32 $user->u_tlist_view = intval($_POST['tlist_layout']);
34 if ( strlen($_POST['sig']) > 255 )
35 throw new invalidInputException(_('Your user signature can not be longer than 255 bytes.'));
36 if ( strlen($_POST['quote']) > 255 )
37 throw new invalidInputException(_('Your quote can not be longer than 255 bytes.'));
38 $user->u_sig = $_POST['sig'];
39 $user->u_quote = $_POST['quote'];
40 $user->userheader();
41 echo '<div class="notice">',_('Settings have been saved.'),'</div>';
42 } catch (invalidInputException $e) {
43 $user->userheader();
44 echo '<div class="error">',$e->getMessage(),'</div>';
46 } else {
47 $user->userheader();
50 $tz_selectbox = '<select name="tz" id="tz">'."\n\t\t";
51 for ($i = -12; $i <= 12; $i++)
52 $tz_selectbox .= '<option value="'.$i.'"'.( $user->u_timezone == $i ? ' selected="selected"' : '' ).'>'.$i."</option>\n\t\t";
53 $tz_selectbox .= '</select>';
55 preg_match_all('#(.*)\: (.*)#', file_get_contents('lang/LINGUAS'), $matches, PREG_SET_ORDER);
56 $lng_selectbox = '<select name="lng" id="lng"'.( defined('NO_GETTEXT') ? ' disabled="disabled"' : '' ).'>'."\n\t\t";
57 foreach($matches as $lingua) {
58 $lng_selectbox .= '<option value="'.$lingua[1].'"'.( $user->u_language == $lingua[1] ? ' selected="selected"' : '' ).'>'.$lingua[2].'</option>'."\n\t\t";
60 $lng_selectbox .= '</select>';
62 echo '<form id="prefs" method="post" action="',$_SERVER['PHP_SELF'],'">
63 <fieldset id="display_settings">
64 <legend>',_('Display Settings'),'</legend>
65 <ul class="formlist">
66 <li>
67 <label for="mlist">',_('Message list view:'),'</label>
68 <select name="mlist_layout" id="mlist">
69 <option value="0"',( 0 == $user->u_mlist_view ? ' selected="selected"' : '' ),'>',_('Flat'),'</option>
70 <option value="1"',( 1 == $user->u_mlist_view ? ' selected="selected"' : '' ),'>',_('Threaded'),'</option>
71 <option value="3"',( 3 == $user->u_mlist_view ? ' selected="selected"' : '' ),'>',_('IRC'),'</option>
72 </select>
73 </li>
74 <li>
75 <label for="tlist">',_('Topic list view:'),'</label>
76 <select name="tlist_layout" id="tlist">
77 <option value="0"',( 0 == $user->u_tlist_view ? ' selected="selected"' : '' ),'>',_('SO2'),'</option>
78 <option value="1"',( 1 == $user->u_tlist_view ? ' selected="selected"' : '' ),'>',_('Twisted Legacy'),'</option>
79 </select>
80 </li>
81 <li>
82 <label for="blist">',_('Board list view:'),'</label>
83 <select name="blist_layout" id="blist" disabled="disabled">
84 <option value="0"',( 0 == $user->u_blist_view ? ' selected="selected"' : '' ),'>',_('SO2'),'</option>
85 </select>
86 </li>
87 <li>
88 <label for="mpp">',_('Messages per page:'),'</label>
89 <input type="text" name="mpp" id="mpp" value="',$user->u_msgs_page,'" disabled="disabled"/>
90 </li>
91 <li>
92 <label for="tpp">',_('Topics per page:'),'</label>
93 <input type="text" name="tpp" id="tpp" value="',$user->u_topics_page,'" disabled="disabled"/>
94 </li>
95 <li>
96 <label for="tz">',_('Timezone offset:'),'</label> ',gmdate('Y-m-d H:i:s'),' &#xb1; ',$tz_selectbox,'
97 </li>
98 <li>
99 <label for="lng">',_('Language:'),'</label> ',$lng_selectbox,'
100 </li>
101 </ul>
102 </fieldset>
104 <fieldset id="user_settings">
105 <legend>',_('User Settings'),'</legend>
106 <ul class="formlist">
107 <li>
108 <label for="sig">',_('Signature:'),'<br/>
109 <small>',_('Put your own separator in.'),'</small></label>
110 <textarea rows="4" cols="60" name="sig" id="sig">',htmlspecialchars($user->u_sig),'</textarea>
111 </li>
112 <li>
113 <label for="quote">',_('Quote:'),'</label>
114 <textarea rows="4" cols="60" name="quote" id="quote">',htmlspecialchars($user->u_quote),'</textarea>
115 </li>
116 </ul>
118 </fieldset>
120 <div><button type="submit" name="submit" value="save" accesskey="s">',_('Save Settings'),' (S)</button></div>
121 </form>';
123 $page->pagefooter();