pref-users: fix sorting the table

master
Andrew Dolgov 7 years ago
parent 3eecebc34f
commit 2cf93c046c

@ -376,7 +376,10 @@ class Pref_Users extends Handler_Protected {
print "</div>"; #pane print "</div>"; #pane
print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; print "<div id=\"pref-user-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
print "<div id=\"sticky-status-msg\"></div>"; $sort = validate_field($sort,
["login", "access_level", "created", "num_feeds", "created", "last_login"], "login");
if ($sort != "login") $sort = "$sort DESC";
$sth = $this->pdo->prepare("SELECT $sth = $this->pdo->prepare("SELECT
tu.id, tu.id,
@ -388,8 +391,8 @@ class Pref_Users extends Handler_Protected {
ttrss_users tu ttrss_users tu
WHERE WHERE
(:search = '' OR login LIKE :search) AND tu.id > 0 (:search = '' OR login LIKE :search) AND tu.id > 0
ORDER BY :sort"); ORDER BY $sort");
$sth->execute([":search" => $user_search ? "%$user_search%" : "", ":sort" => $sort]); $sth->execute([":search" => $user_search ? "%$user_search%" : ""]);
print "<p><table width=\"100%\" cellspacing=\"0\" print "<p><table width=\"100%\" cellspacing=\"0\"
class=\"prefUserList\" id=\"prefUserList\">"; class=\"prefUserList\" id=\"prefUserList\">";

@ -2548,6 +2548,13 @@
return $bad_tables; return $bad_tables;
} }
function validate_field($string, $allowed, $default = "") {
if (in_array($string, $allowed))
return $string;
else
return $default;
}
function arr_qmarks($arr) { function arr_qmarks($arr) {
return str_repeat('?,', count($arr) - 1) . '?'; return str_repeat('?,', count($arr) - 1) . '?';
} }

Loading…
Cancel
Save