diff --git a/endpoints/settings/convert_currency.php b/endpoints/settings/convert_currency.php new file mode 100644 index 000000000..86c1b3897 --- /dev/null +++ b/endpoints/settings/convert_currency.php @@ -0,0 +1,33 @@ + false, + "message" => translate('session_expired', $i18n) + ])); +} + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + $postData = file_get_contents("php://input"); + $data = json_decode($postData, true); + + $convert_currency = $data['value']; + + $stmt = $db->prepare('UPDATE settings SET convert_currency = :convert_currency'); + $stmt->bindParam(':convert_currency', $convert_currency, SQLITE3_INTEGER); + + if ($stmt->execute()) { + die(json_encode([ + "success" => true, + "message" => translate("success", $i18n) + ])); + } else { + die(json_encode([ + "success" => false, + "message" => translate("error", $i18n) + ])); + } +} + +?> \ No newline at end of file diff --git a/endpoints/settings/monthly_price.php b/endpoints/settings/monthly_price.php new file mode 100644 index 000000000..f6dc17285 --- /dev/null +++ b/endpoints/settings/monthly_price.php @@ -0,0 +1,33 @@ + false, + "message" => translate('session_expired', $i18n) + ])); +} + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + $postData = file_get_contents("php://input"); + $data = json_decode($postData, true); + + $monthly_price = $data['value']; + + $stmt = $db->prepare('UPDATE settings SET monthly_price = :monthly_price'); + $stmt->bindParam(':monthly_price', $monthly_price, SQLITE3_INTEGER); + + if ($stmt->execute()) { + die(json_encode([ + "success" => true, + "message" => translate("success", $i18n) + ])); + } else { + die(json_encode([ + "success" => false, + "message" => translate("error", $i18n) + ])); + } +} + +?> \ No newline at end of file diff --git a/endpoints/settings/remove_background.php b/endpoints/settings/remove_background.php new file mode 100644 index 000000000..6eecbcffc --- /dev/null +++ b/endpoints/settings/remove_background.php @@ -0,0 +1,33 @@ + false, + "message" => translate('session_expired', $i18n) + ])); +} + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + $postData = file_get_contents("php://input"); + $data = json_decode($postData, true); + + $remove_background = $data['value']; + + $stmt = $db->prepare('UPDATE settings SET remove_background = :remove_background'); + $stmt->bindParam(':remove_background', $remove_background, SQLITE3_INTEGER); + + if ($stmt->execute()) { + die(json_encode([ + "success" => true, + "message" => translate("success", $i18n) + ])); + } else { + die(json_encode([ + "success" => false, + "message" => translate("error", $i18n) + ])); + } +} + +?> \ No newline at end of file diff --git a/endpoints/settings/theme.php b/endpoints/settings/theme.php new file mode 100644 index 000000000..48a867c2b --- /dev/null +++ b/endpoints/settings/theme.php @@ -0,0 +1,33 @@ + false, + "message" => translate('session_expired', $i18n) + ])); +} + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + $postData = file_get_contents("php://input"); + $data = json_decode($postData, true); + + $theme = $data['theme']; + + $stmt = $db->prepare('UPDATE settings SET dark_theme = :theme'); + $stmt->bindParam(':theme', $theme, SQLITE3_INTEGER); + + if ($stmt->execute()) { + die(json_encode([ + "success" => true, + "message" => translate("success", $i18n) + ])); + } else { + die(json_encode([ + "success" => false, + "message" => translate("error", $i18n) + ])); + } +} + +?> \ No newline at end of file diff --git a/endpoints/subscription/add.php b/endpoints/subscription/add.php index 9baa47e81..8ab257dcc 100644 --- a/endpoints/subscription/add.php +++ b/endpoints/subscription/add.php @@ -2,6 +2,7 @@ error_reporting(E_ERROR | E_PARSE); require_once '../../includes/connect_endpoint.php'; require_once '../../includes/inputvalidation.php'; + require_once '../../includes/getsettings.php'; session_start(); @@ -40,7 +41,7 @@ function getLogoFromUrl($url, $uploadDir, $name) { function saveLogo($imageData, $uploadFile, $name) { $image = imagecreatefromstring($imageData); - $removeBackground = isset($_COOKIE['removeBackground']) && $_COOKIE['removeBackground'] === 'true'; + $removeBackground = isset($settings['removeBackground']) && $settings['removeBackground'] === 'true'; if ($image !== false) { $tempFile = tempnam(sys_get_temp_dir(), 'logo'); imagepng($image, $tempFile); diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php index 660d97368..67a51de74 100644 --- a/endpoints/subscriptions/get.php +++ b/endpoints/subscriptions/get.php @@ -7,9 +7,11 @@ include_once '../../includes/list_subscriptions.php'; + require_once '../../includes/getsettings.php'; + $theme = "light"; - if (isset($_COOKIE['theme'])) { - $theme = $_COOKIE['theme']; + if (isset($settings['theme'])) { + $theme = $settings['theme']; } if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) { @@ -57,11 +59,11 @@ $print[$id]['url'] = $subscription['url']; $print[$id]['notes'] = $subscription['notes']; - if (isset($_COOKIE['convertCurrency']) && $_COOKIE['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) { + if (isset($settings['convertCurrency']) && $settings['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) { $print[$id]['price'] = getPriceConverted($print[$id]['price'], $currencyId, $db); $print[$id]['currency_code'] = $currencies[$mainCurrencyId]['code']; } - if (isset($_COOKIE['showMonthlyPrice']) && $_COOKIE['showMonthlyPrice'] === 'true') { + if (isset($settings['showMonthlyPrice']) && $settings['showMonthlyPrice'] === 'true') { $print[$id]['price'] = getPricePerMonth($cycle, $frequency, $print[$id]['price']); } } diff --git a/includes/getsettings.php b/includes/getsettings.php new file mode 100644 index 000000000..421df17ed --- /dev/null +++ b/includes/getsettings.php @@ -0,0 +1,15 @@ +query($query); +$settings = $result->fetchArray(SQLITE3_ASSOC); +if ($settings) { + $cookieExpire = time() + (30 * 24 * 60 * 60); + setcookie('theme', $settings['dark_theme'] ? 'dark': 'light', $cookieExpire); + $settings['theme'] = $settings['dark_theme'] ? 'dark': 'light'; + $settings['showMonthlyPrice'] = $settings['monthly_price'] ? 'true': 'false'; + $settings['convertCurrency'] = $settings['convert_currency'] ? 'true': 'false'; + $settings['removeBackground'] = $settings['remove_background'] ? 'true': 'false'; +} + +?> \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index 0a9f7e5ea..35f33592e 100644 --- a/includes/header.php +++ b/includes/header.php @@ -8,6 +8,8 @@ require_once 'i18n/getlang.php'; require_once 'i18n/' . $lang . '.php'; + require_once 'getsettings.php'; + require_once 'version.php'; if ($userCount == 0) { @@ -17,8 +19,8 @@ } $theme = "light"; - if (isset($_COOKIE['theme'])) { - $theme = $_COOKIE['theme']; + if (isset($settings['theme'])) { + $theme = $settings['theme']; } ?> @@ -47,7 +49,7 @@
@@ -58,7 +60,7 @@