3 require('includes/header.php');
5 update_activity('dashboard');
6 $page_title = 'Dashboard';
11 'memorable_name' => '',
12 'memorable_password' => '',
17 'snippet_length' => 80
19 $user_config = $defaults;
21 // These inputs have no simple valid settings.
30 $valid_settings = array
32 'topics_mode' => array('0', '1'),
33 'spoiler_mode' => array('0', '1'),
34 'ostrich_mode' => array('0', '1'),
35 'snippet_length' => array('80', '100', '120', '140', '160')
38 // Get our user's settings from the database.
39 $stmt = $link->prepare('SELECT memorable_name, memorable_password, email, spoiler_mode, topics_mode, ostrich_mode, snippet_length FROM user_settings WHERE uid = ?');
40 $stmt->bind_param('s', $_SESSION['UID']);
42 $stmt->bind_result($user_config_db['memorable_name'], $user_config_db['memorable_password'], $user_config_db['email'], $user_config_db['spoiler_mode'], $user_config_db['topics_mode'], $user_config_db['ostrich_mode'], $user_config_db['snippet_length']);
46 // If the values were set in the database, overwrite the defaults.
47 foreach($user_config_db as $key => $value)
51 $user_config[$key] = $value;
55 if($_POST['form_sent'])
57 // Unticked checkboxes are not sent by the client, so we need to set them ourselves.
58 foreach($defaults as $option => $setting)
60 if( ! array_key_exists($option, $_POST['form']))
62 $_POST['form'][$option] = $setting;
66 // Make some specific validations ...
67 if( ! empty($_POST['form']['memorable_name']) && $_POST['form']['memorable_name'] != $user_config['memorable_name'])
69 // Check if the name is already being used.
70 $check_name = $link->prepare('SELECT 1 FROM user_settings WHERE LOWER(memorable_name) = LOWER(?)');
71 $check_name->bind_param('s', $_POST['form']['memorable_name']);
72 $check_name->execute();
74 $check_name->store_result();
75 if($check_name->num_rows
> 0)
77 add_error('The memorable name "' . htmlspecialchars($_POST['form']['memorable_name']) . '" is already being used.');
85 //Iterate over every sent form[] value.
86 foreach($_POST['form'] as $key => $value)
88 // Check if the settings are valid ...
89 if( ! in_array($key, $text_inputs) && ( ! array_key_exists($key, $defaults) ||
! in_array($value, $valid_settings[$key]) ) )
93 if(strlen($value) > 100)
98 // If the submitted setting differs from the current setting, update it.
99 if($user_config[$key] != $value)
102 $link->query('INSERT INTO user_settings (uid, ' . $link->real_escape_string($key). ') VALUES (\'' . $link->real_escape_string($_SESSION['UID']). '\', \'' . $link->real_escape_string($value) . '\') ON DUPLICATE KEY UPDATE ' . $link->real_escape_string($key). ' = \'' . $link->real_escape_string($value) . '\'');
104 // Reset the value so it displays correctly on this page load.
105 $user_config[$key] = $value;
107 // Text inputs never need to be set as cookies.
108 if(!in_array($key, $text_inputs))
110 setcookie($key, $value, $_SERVER['REQUEST_TIME'] +
315569260);
116 $_SESSION['notice'] = 'Settings updated.';
123 <form action
="" method
="post">
125 <label
class="common" for="memorable_name">Memorable name
</label
>
126 <input type
="text" id
="memorable_name" name
="form[memorable_name]" class="inline" value
="<?php echo htmlspecialchars($user_config['memorable_name']) ?>" maxlength
="100" />
129 <label
class="common" for="memorable_password">Memorable password
</label
>
130 <input type
="text" class="inline" id
="memorable_password" name
="form[memorable_password]" value
="<?php echo htmlspecialchars($user_config['memorable_password']) ?>" maxlength
="100" />
132 <p
class="caption">This information can be used to more easily
<a href
="/restore_ID">restore your ID
</a
>. Password is optional
, but recommended
.</p
>
136 <label
class="common" for="e-mail">E
-mail address
</label
>
137 <input type
="text" id
="e-mail" name
="form[email]" class="inline" value
="<?php echo htmlspecialchars($user_config['email']) ?>" size
="35" maxlength
="100" />
139 <p
class="caption">Used to recover your internal ID
<a href
="/recover_ID_by_email">via e
-mail
</a
>.</p
>
143 <label
class="common" for="topics_mode" class="inline">Sort topics by
:</label
>
144 <select id
="topics_mode" name
="form[topics_mode]" class="inline">
145 <option value
="0"<?php
if($user_config['topics_mode'] == 0) echo ' selected' ?
>>Last
post (default)</option
>
146 <option value
="1"<?php
if($user_config['topics_mode'] == 1) echo ' selected' ?
>>Date created
</option
>
151 <label
class="common" for="snippet_length" class="inline">Snippet length in characters
</label
>
152 <select id
="snippet_length" name
="form[snippet_length]" class="inline">
153 <option value
="80"<?php
if($user_config['snippet_length'] == 0) echo ' selected' ?
>>80 (default)</option
>
154 <option value
="100"<?php
if($user_config['snippet_length'] == 100) echo ' selected' ?
>>100</option
>
155 <option value
="120"<?php
if($user_config['snippet_length'] == 120) echo ' selected' ?
>>120</option
>
156 <option value
="140"<?php
if($user_config['snippet_length'] == 140) echo ' selected' ?
>>140</option
>
157 <option value
="160"<?php
if($user_config['snippet_length'] == 160) echo ' selected' ?
>>160</option
>
160 <p
class="caption"></p
>
164 <label
class="common" for="spoiler_mode">Spoiler mode
</label
>
165 <input type
="checkbox" id
="spoiler_mode" name
="form[spoiler_mode]" value
="1" class="inline"<?php
if($user_config['spoiler_mode'] == 1) echo ' checked="checked"' ?
> />
167 <p
class="caption">When enabled
, snippets of the bodies will show in the topic
list. Not recommended unless you have a very high
-resolution screen
.</p
>
171 <label
class="common" for="ostrich_mode">Ostrich mode
</label
>
172 <input type
="checkbox" id
="ostrich_mode" name
="form[ostrich_mode]" value
="1" class="inline"<?php
if($user_config['ostrich_mode'] == 1) echo ' checked="checked"' ?
> />
174 <p
class="caption">When enabled
, any topic
or reply that contains a phrase from your
<a href
="/edit_ignore_list">ignore
list</a
> will be hidden
.</p
>
178 <input type
="submit" name
="form_sent" value
="Save settings" />
185 require('includes/footer.php');