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 ++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 74 deletions(-) (limited to 'classes/pref/prefs.php') 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) { -- cgit v1.2.3