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 "
";
+ // 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"]);
+
+ 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["title"]);
+
+ 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;
+ }
+ }
+
+ // TODO: this maybe needs to be unified with Public::getProfiles()
+ function getProfiles() {
+ $rv = [];
$sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles
WHERE owner_uid = ? ORDER BY title");
$sth->execute([$_SESSION['uid']]);
- print "