From 1adb9bb6b643736706b746629b849df9cdf45e50 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Feb 2021 11:54:22 +0300 Subject: profiles: use client dialog; move related methods to pref-prefs --- classes/pref/prefs.php | 143 ++++++++++++++++++++++++------------------------- classes/rpc.php | 75 +------------------------- 2 files changed, 70 insertions(+), 148 deletions(-) (limited to 'classes') diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 3bc8a9a9c..4a4aa45d6 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1219,102 +1219,97 @@ class Pref_Prefs extends Handler_Protected { print json_encode(["value" => $value]); } - function editPrefProfiles() { - print "
"; + function activateprofile() { + $_SESSION["profile"] = (int) clean($_REQUEST["id"]); - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print "
"; - - print " -
"; - - print "
"; - - $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles - WHERE owner_uid = ? ORDER BY title"); - $sth->execute([$_SESSION['uid']]); + // default value + if (!$_SESSION["profile"]) $_SESSION["profile"] = null; + } - print "
"; + function remprofiles() { + $ids = explode(",", clean($_REQUEST["ids"])); - print "
"; + foreach ($ids as $id) { + if ($_SESSION["profile"] != $id) { + $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND + owner_uid = ?"); + $sth->execute([$id, $_SESSION['uid']]); + } + } + } - print ""; + function addprofile() { + $title = clean($_REQUEST["title"]); - print ""; # data-row-id='0' <-- no point, shouldn't be removed + if ($title) { + $this->pdo->beginTransaction(); - print ""; + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles + WHERE title = ? AND owner_uid = ?"); + $sth->execute([$title, $_SESSION['uid']]); - if (!isset($_SESSION["profile"])) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } + if (!$sth->fetch()) { - print ""; + $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) + VALUES (?, ?)"); - print ""; + $sth->execute([$title, $_SESSION['uid']]); - while ($line = $sth->fetch()) { + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE + title = ? AND owner_uid = ?"); + $sth->execute([$title, $_SESSION['uid']]); - $profile_id = $line["id"]; + if ($row = $sth->fetch()) { + $profile_id = $row['id']; - print ""; + if ($profile_id) { + Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id); + } + } + } - $edit_title = htmlspecialchars($line["title"]); + $this->pdo->commit(); + } + } - print ""; + function saveprofile() { + $id = clean($_REQUEST["id"]); + $title = clean($_REQUEST["title"]); - if (isset($_SESSION["profile"]) && $_SESSION["profile"] == $line["id"]) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } + if ($id == 0) { + print __("Default profile"); + return; + } - print ""; + if ($title) { + $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles + SET title = ? WHERE id = ? AND + owner_uid = ?"); - print ""; + $sth->execute([$title, $id, $_SESSION['uid']]); + print $title; } + } + + // TODO: this maybe needs to be unified with Public::getProfiles() + function getProfiles() { + $rv = []; - print "
" . __("Default profile") . " $is_active
" . $edit_title . - " - $is_active
"; - print "
"; + $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles + WHERE owner_uid = ? ORDER BY title"); + $sth->execute([$_SESSION['uid']]); - print ""; + array_push($rv, ["title" => __("Default profile"), + "id" => 0, + "active" => empty($_SESSION["profile"]) + ]); - print "
"; + while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + $row["active"] = isset($_SESSION["profile"]) && $_SESSION["profile"] == $row["id"]; + array_push($rv, $row); + }; + print json_encode($rv); } private function _get_short_desc($pref_name) { diff --git a/classes/rpc.php b/classes/rpc.php index 6831d5667..0fd06da4d 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -2,84 +2,11 @@ class RPC extends Handler_Protected { function csrf_ignore($method) { - $csrf_ignored = array("completelabels", "saveprofile"); + $csrf_ignored = array("completelabels"); return array_search($method, $csrf_ignored) !== false; } - function setprofile() { - $_SESSION["profile"] = (int) clean($_REQUEST["id"]); - - // default value - if (!$_SESSION["profile"]) $_SESSION["profile"] = null; - } - - function remprofiles() { - $ids = explode(",", clean($_REQUEST["ids"])); - - foreach ($ids as $id) { - if ($_SESSION["profile"] != $id) { - $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND - owner_uid = ?"); - $sth->execute([$id, $_SESSION['uid']]); - } - } - } - - // Silent - function addprofile() { - $title = clean($_REQUEST["title"]); - - if ($title) { - $this->pdo->beginTransaction(); - - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles - WHERE title = ? AND owner_uid = ?"); - $sth->execute([$title, $_SESSION['uid']]); - - if (!$sth->fetch()) { - - $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) - VALUES (?, ?)"); - - $sth->execute([$title, $_SESSION['uid']]); - - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE - title = ? AND owner_uid = ?"); - $sth->execute([$title, $_SESSION['uid']]); - - if ($row = $sth->fetch()) { - $profile_id = $row['id']; - - if ($profile_id) { - Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id); - } - } - } - - $this->pdo->commit(); - } - } - - function saveprofile() { - $id = clean($_REQUEST["id"]); - $title = clean($_REQUEST["value"]); - - if ($id == 0) { - print __("Default profile"); - return; - } - - if ($title) { - $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles - SET title = ? WHERE id = ? AND - owner_uid = ?"); - - $sth->execute([$title, $id, $_SESSION['uid']]); - print $title; - } - } - function togglepref() { $key = clean($_REQUEST["key"]); set_pref($key, !get_pref($key)); -- cgit v1.2.3-54-g00ecf