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