]> git.wh0rd.org - tt-rss.git/blob - modules/pref-prefs.php
update_daemon2: enable stampfiles
[tt-rss.git] / modules / pref-prefs.php
1 <?php
2 function prefs_js_redirect() {
3 print "<html><body>
4 <script type=\"text/javascript\">
5 window.location = 'prefs.php';
6 </script>
7 </body></html>";
8 }
9
10 function module_pref_prefs($link) {
11 $subop = $_REQUEST["subop"];
12
13 if ($subop == "change-password") {
14
15 $old_pw = $_POST["OLD_PASSWORD"];
16 $new_pw = $_POST["NEW_PASSWORD"];
17 $con_pw = $_POST["CONFIRM_PASSWORD"];
18
19 if ($old_pw == "") {
20 print "ERROR: ".__("Old password cannot be blank.");
21 return;
22 }
23
24 if ($new_pw == "") {
25 print "ERROR: ".__("New password cannot be blank.");
26 return;
27 }
28
29 if ($new_pw != $con_pw) {
30 print "ERROR: ".__("Entered passwords do not match.");
31 return;
32 }
33
34 $old_pw_hash1 = encrypt_password($_POST["OLD_PASSWORD"]);
35 $old_pw_hash2 = encrypt_password($_POST["OLD_PASSWORD"],
36 $_SESSION["name"]);
37
38 $new_pw_hash = encrypt_password($_POST["NEW_PASSWORD"],
39 $_SESSION["name"]);
40
41 $active_uid = $_SESSION["uid"];
42
43 if ($old_pw && $new_pw) {
44
45 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
46
47 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
48 id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR
49 pwd_hash = '$old_pw_hash2')");
50
51 if (db_num_rows($result) == 1) {
52 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
53 WHERE id = '$active_uid'");
54
55 print __("Password has been changed.");
56 } else {
57 print "ERROR: ".__('Old password is incorrect.');
58 }
59 }
60
61 return;
62
63 } else if ($subop == "save-config") {
64
65 # $_SESSION["prefs_op_result"] = "save-config";
66
67 $_SESSION["prefs_cache"] = false;
68
69 // print_r($_POST);
70
71 foreach (array_keys($_POST) as $pref_name) {
72
73 $pref_name = db_escape_string($pref_name);
74 $value = db_escape_string($_POST[$pref_name]);
75
76 $result = db_query($link, "SELECT type_name
77 FROM ttrss_prefs,ttrss_prefs_types
78 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
79
80 if (db_num_rows($result) > 0) {
81
82 $type_name = db_fetch_result($result, 0, "type_name");
83
84 // print "$pref_name : $type_name : $value<br>";
85
86 if ($type_name == "bool") {
87 if ($value == "1") {
88 $value = "true";
89 } else {
90 $value = "false";
91 }
92 } else if ($type_name == "integer") {
93 $value = sprintf("%d", $value);
94 }
95
96 // print "$pref_name : $type_name : $value<br>";
97
98 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
99 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
100
101 }
102
103 }
104
105 #return prefs_js_redirect();
106
107 print __("The configuration was saved.");
108
109 return;
110
111 } else if ($subop == "getHelp") {
112
113 $pref_name = db_escape_string($_GET["pn"]);
114
115 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
116 WHERE pref_name = '$pref_name'");
117
118 if (db_num_rows($result) > 0) {
119 $help_text = db_fetch_result($result, 0, "help_text");
120 print $help_text;
121 } else {
122 print "Unknown option: $pref_name";
123 }
124
125 } else if ($subop == "change-email") {
126
127 $email = db_escape_string($_POST["email"]);
128 $active_uid = $_SESSION["uid"];
129
130 db_query($link, "UPDATE ttrss_users SET email = '$email'
131 WHERE id = '$active_uid'");
132
133 print __("E-mail has been changed.");
134
135 return;
136
137 } else if ($subop == "reset-config") {
138
139 $_SESSION["prefs_op_result"] = "reset-to-defaults";
140
141 db_query($link, "DELETE FROM ttrss_user_prefs
142 WHERE owner_uid = ".$_SESSION["uid"]);
143 initialize_user_prefs($link, $_SESSION["uid"]);
144
145 print __("The configuration was reset to defaults.");
146
147 return;
148
149 } else if ($subop == __("Change theme")) {
150
151 $theme = db_escape_string($_POST["theme"]);
152
153 if ($theme == "Default") {
154 $theme_qpart = 'NULL';
155 } else {
156 $theme_qpart = "'$theme'";
157 }
158
159 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
160 WHERE theme_name = '$theme'");
161
162 if (db_num_rows($result) == 1) {
163 $theme_id = db_fetch_result($result, 0, "id");
164 $theme_path = db_fetch_result($result, 0, "theme_path");
165 } else {
166 $theme_id = "NULL";
167 $theme_path = "";
168 }
169
170 db_query($link, "UPDATE ttrss_users SET
171 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
172
173 $_SESSION["theme"] = $theme_path;
174
175 return prefs_js_redirect();
176
177 } else {
178
179 // print check_for_update($link);
180
181 set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
182
183 if (!SINGLE_USER_MODE) {
184
185 $result = db_query($link, "SELECT id FROM ttrss_users
186 WHERE id = ".$_SESSION["uid"]." AND pwd_hash
187 = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
188
189 if (db_num_rows($result) != 0) {
190 print format_warning(__("Your password is at default value,
191 please change it."), "default_pass_warning");
192 }
193
194 /* if ($_SESSION["pwd_change_result"] == "failed") {
195 print format_warning("Could not change the password.");
196 }
197
198 if ($_SESSION["pwd_change_result"] == "ok") {
199 print format_notice("Password was changed.");
200 }
201
202 $_SESSION["pwd_change_result"] = ""; */
203
204 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
205 print format_notice(__("The configuration was reset to defaults."));
206 }
207
208 # if ($_SESSION["prefs_op_result"] == "save-config") {
209 # print format_notice(__("The configuration was saved."));
210 # }
211
212 $_SESSION["prefs_op_result"] = "";
213
214 print "<form onsubmit='return false' id='change_email_form'>";
215
216 print "<table width=\"100%\" class=\"prefPrefsList\">";
217 print "<tr><td colspan='3'><h3>".__("Personal data")."</h3></tr></td>";
218
219 $result = db_query($link, "SELECT email FROM ttrss_users
220 WHERE id = ".$_SESSION["uid"]);
221
222 $email = db_fetch_result($result, 0, "email");
223
224 print "<tr><td width=\"40%\">".__('E-mail')."</td>";
225 print "<td><input class=\"editbox\" name=\"email\"
226 onkeypress=\"return filterCR(event, changeUserEmail)\"
227 value=\"$email\"></td></tr>";
228
229 print "</table>";
230
231 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
232 print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
233
234 print "</form>";
235
236 print "<p><input class=\"button\" type=\"submit\"
237 onclick=\"return changeUserEmail()\" value=\"".__("Change e-mail")."\">";
238
239 print "<form onsubmit=\"return false\"
240 name=\"change_pass_form\" id=\"change_pass_form\">";
241
242 print "<table width=\"100%\" class=\"prefPrefsList\">";
243 print "<tr><td colspan='3'><h3>".__("Authentication")."</h3></tr></td>";
244
245 print "<tr><td width=\"40%\">".__("Old password")."</td>";
246 print "<td><input class=\"editbox\" type=\"password\"
247 onkeypress=\"return filterCR(event, changeUserPassword)\"
248 name=\"OLD_PASSWORD\"></td></tr>";
249
250 print "<tr><td width=\"40%\">".__("New password")."</td>";
251
252 print "<td><input class=\"editbox\" type=\"password\"
253 onkeypress=\"return filterCR(event, changeUserPassword)\"
254 name=\"NEW_PASSWORD\"></td></tr>";
255
256 print "<tr><td width=\"40%\">".__("Confirm password")."</td>";
257
258 print "<td><input class=\"editbox\" type=\"password\"
259 onkeypress=\"return filterCR(event, changeUserPassword)\"
260 name=\"CONFIRM_PASSWORD\"></td></tr>";
261
262 print "</table>";
263
264 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
265 print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
266
267 print "</form>";
268
269 print "<p><input class=\"button\" type=\"submit\"
270 onclick=\"return changeUserPassword()\"
271 value=\"".__("Change password")."\">";
272
273 }
274
275 $result = db_query($link, "SELECT
276 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
277
278 $user_theme_id = db_fetch_result($result, 0, "theme_id");
279
280 $result = db_query($link, "SELECT
281 id,theme_name FROM ttrss_themes ORDER BY theme_name");
282
283 if (db_num_rows($result) > 0) {
284
285 print "<form action=\"backend.php\" method=\"POST\">";
286 print "<table width=\"100%\" class=\"prefPrefsList\">";
287 print "<tr><td colspan='3'><h3>".__("Themes")."</h3></tr></td>";
288 print "<tr><td width=\"40%\">".__("Select theme")."</td>";
289 print "<td><select name=\"theme\">";
290 print "<option value='Default'>".__('Default')."</option>";
291 print "<option disabled>--------</option>";
292
293 while ($line = db_fetch_assoc($result)) {
294 if ($line["id"] == $user_theme_id) {
295 $selected = "selected";
296 } else {
297 $selected = "";
298 }
299 print "<option $selected>" . $line["theme_name"] . "</option>";
300 }
301 print "</select></td></tr>";
302 print "</table>";
303 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
304 print "<input type=\"hidden\" name=\"subop\" value=\"Change theme\">";
305 print "<p><input class=\"button\" type=\"submit\"
306 value=\"".__('Change theme')."\">";
307 print "</form>";
308 }
309
310 initialize_user_prefs($link, $_SESSION["uid"]);
311
312 $result = db_query($link, "SELECT
313 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
314 section_name,def_value
315 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
316 WHERE type_id = ttrss_prefs_types.id AND
317 section_id = ttrss_prefs_sections.id AND
318 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
319 short_desc != '' AND
320 owner_uid = ".$_SESSION["uid"]."
321 ORDER BY section_id,short_desc");
322
323 print "<form onsubmit='return false' action=\"backend.php\"
324 method=\"POST\" id=\"pref_prefs_form\">";
325
326 $lnum = 0;
327
328 $active_section = "";
329
330 while ($line = db_fetch_assoc($result)) {
331
332 if ($active_section != $line["section_name"]) {
333
334 if ($active_section != "") {
335 print "</table>";
336 }
337
338 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
339
340 $active_section = $line["section_name"];
341
342 print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>";
343 // print "<tr class=\"title\">
344 // <td width=\"25%\">Option</td><td>Value</td></tr>";
345
346 $lnum = 0;
347 }
348
349 // $class = ($lnum % 2) ? "even" : "odd";
350
351 print "<tr>";
352
353 $type_name = $line["type_name"];
354 $pref_name = $line["pref_name"];
355 $value = $line["value"];
356 $def_value = $line["def_value"];
357 $help_text = $line["help_text"];
358
359 print "<td width=\"40%\" id=\"$pref_name\">" . __($line["short_desc"]);
360
361 if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>";
362
363 print "</td>";
364
365 print "<td>";
366
367 if ($type_name == "bool") {
368 // print_select($pref_name, $value, array("true", "false"));
369
370 if ($value == "true") {
371 $value = __("Yes");
372 } else {
373 $value = __("No");
374 }
375
376 print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
377
378 } else {
379 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
380 }
381
382 print "</td>";
383
384 print "</tr>";
385
386 $lnum++;
387 }
388
389 print "</table>";
390
391 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
392
393 print "<p><input class=\"button\" type=\"submit\"
394 onclick=\"return validatePrefsSave()\"
395 value=\"".__('Save configuration')."\">";
396
397 print "&nbsp;<input class=\"button\" type=\"submit\"
398 onclick=\"return validatePrefsReset()\"
399 value=\"".__('Reset to defaults')."\"></p>";
400
401 print "</form>";
402
403 }
404 }
405 ?>