From 91e53a48e4b1f51acc9d50b1f91c4b3620b00d62 Mon Sep 17 00:00:00 2001 From: Sokratis <59183311+sokratis1988@users.noreply.github.com> Date: Fri, 23 Feb 2024 15:29:11 +0100 Subject: [PATCH] Allow to disable notifications --- endpoints/cronjobs/sendnotifications.php | 2 +- endpoints/cronjobs/updatenextpayment.php | 2 +- endpoints/subscription/add.php | 10 ++++++---- endpoints/subscription/get.php | 1 + endpoints/subscriptions/get.php | 1 + includes/i18n/de.php | 2 ++ includes/i18n/el.php | 2 ++ includes/i18n/en.php | 2 ++ includes/i18n/es.php | 2 ++ includes/i18n/fr.php | 2 ++ includes/i18n/jp.php | 2 ++ includes/i18n/pt.php | 2 ++ includes/i18n/zh_cn.php | 2 ++ includes/list_subscriptions.php | 9 ++++++++- index.php | 6 ++++++ migrations/000008.php | 11 +++++++++++ scripts/dashboard.js | 2 ++ stats.php | 21 +++++++++++++++++++-- styles/styles.css | 7 +++++++ 19 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 migrations/000008.php diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php index d33a96945..55003538f 100644 --- a/endpoints/cronjobs/sendnotifications.php +++ b/endpoints/cronjobs/sendnotifications.php @@ -30,7 +30,7 @@ $currencies[$currencyId] = $row; } - $querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1"; + $querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1 AND inactive = 0"; $resultSubscriptions = $db->query($querySubscriptions); $notify = []; $i = 0; diff --git a/endpoints/cronjobs/updatenextpayment.php b/endpoints/cronjobs/updatenextpayment.php index 546939ead..e7bf3abc7 100644 --- a/endpoints/cronjobs/updatenextpayment.php +++ b/endpoints/cronjobs/updatenextpayment.php @@ -13,7 +13,7 @@ $cycles[$cycleId] = $row; } - $query = "SELECT id, next_payment, frequency, cycle FROM subscriptions WHERE next_payment < :currentDate"; + $query = "SELECT id, next_payment, frequency, cycle FROM subscriptions WHERE inactive = 0 AND next_payment < :currentDate"; $stmt = $db->prepare($query); $stmt->bindValue(':currentDate', $currentDate->format('Y-m-d')); $result = $stmt->execute(); diff --git a/endpoints/subscription/add.php b/endpoints/subscription/add.php index 8ab257dcc..30df7d371 100644 --- a/endpoints/subscription/add.php +++ b/endpoints/subscription/add.php @@ -151,6 +151,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) { $logoUrl = validate($_POST['logo-url']); $logo = ""; $notify = isset($_POST['notifications']) ? true : false; + $inactive = isset($_POST['inactive']) ? true : false; if($logoUrl !== "") { $logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name); @@ -162,15 +163,15 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) { if (!$isEdit) { $sql = "INSERT INTO subscriptions (name, logo, price, currency_id, next_payment, cycle, frequency, notes, - payment_method_id, payer_user_id, category_id, notify, url) + payment_method_id, payer_user_id, category_id, notify, inactive, url) VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes, - :paymentMethodId, :payerUserId, :categoryId, :notify, :url)"; + :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url)"; } else { $id = $_POST['id']; if ($logo != "") { - $sql = "UPDATE subscriptions SET name = :name, logo = :logo, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, url = :url WHERE id = :id"; + $sql = "UPDATE subscriptions SET name = :name, logo = :logo, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url WHERE id = :id"; } else { - $sql = "UPDATE subscriptions SET name = :name, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, url = :url WHERE id = :id"; + $sql = "UPDATE subscriptions SET name = :name, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url WHERE id = :id"; } } @@ -192,6 +193,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) { $stmt->bindParam(':payerUserId', $payerUserId, SQLITE3_INTEGER); $stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER); $stmt->bindParam(':notify', $notify, SQLITE3_INTEGER); + $stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER); $stmt->bindParam(':url', $url, SQLITE3_TEXT); if ($stmt->execute()) { diff --git a/endpoints/subscription/get.php b/endpoints/subscription/get.php index 38ad3ce27..7063cff60 100644 --- a/endpoints/subscription/get.php +++ b/endpoints/subscription/get.php @@ -25,6 +25,7 @@ $subscriptionData['payer_user_id'] = $row['payer_user_id']; $subscriptionData['category_id'] = $row['category_id']; $subscriptionData['notify'] = $row['notify']; + $subscriptionData['inactive'] = $row['inactive']; $subscriptionData['url'] = $row['url']; $subscriptionJson = json_encode($subscriptionData); diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php index 67a51de74..cb5850508 100644 --- a/endpoints/subscriptions/get.php +++ b/endpoints/subscriptions/get.php @@ -56,6 +56,7 @@ $print[$id]['category_id'] = $subscription['category_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id']; $print[$id]['price'] = floatval($subscription['price']); + $print[$id]['inactive'] = $subscription['inactive']; $print[$id]['url'] = $subscription['url']; $print[$id]['notes'] = $subscription['notes']; diff --git a/includes/i18n/de.php b/includes/i18n/de.php index f3e08e9f2..d2f12a39a 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -33,6 +33,7 @@ 'last_added' => "Zuletzt hinzugefügt", 'price' => "Preis", 'next_payment' => "Nächste Zahlung", + 'inactive' => "Deaktiviertes Abonnement", 'member' => "Mitglied", 'category' => "Kategorie", 'payment_method' => "Zahlungsmethode", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "Allgemeine Statistiken", 'active_subscriptions' => "Aktive Abonnements", + 'inactive_subscriptions' => "Inaktive Abonnements", 'monthly_cost' => "Monatliche Kosten", 'yearly_cost' => "Jährliche Kosten", 'average_monthly' => "Durchschnittliche monatliche Kosten", diff --git a/includes/i18n/el.php b/includes/i18n/el.php index 50afc29c1..247baa686 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -33,6 +33,7 @@ 'last_added' => "Τελευταία προσθήκη", 'price' => "Τιμή", 'next_payment' => "Επόμενη πληρωμή", + 'inactive' => "Ανενεργή συνδρομή", 'member' => "Χρήστης", 'category' => "Κατηγορία", 'payment_method' => "Τρόπος πληρωμής", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "Γενικές στατιστικές", 'active_subscriptions' => "Ενεργές συνδρομές", + 'inactive_subscriptions' => "Ανενεργές συνδρομές", 'monthly_cost' => "Μηνιαίο κόστος", 'yearly_cost' => "Ετήσιο κόστος", 'average_monthly' => "Μέσο μηνιαίο κόστος συνδρομής", diff --git a/includes/i18n/en.php b/includes/i18n/en.php index 5ef6579ed..fdc2c6de3 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -33,6 +33,7 @@ 'last_added' => "Last Added", 'price' => "Price", 'next_payment' => "Next Payment", + 'inactive' => "Disabled Subscription", 'member' => "Member", 'category' => "Category", 'payment_method' => "Payment Method", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "General Statistics", 'active_subscriptions' => "Active Subscriptions", + 'inactive_subscriptions' => "Inactive Subscriptions", 'monthly_cost' => "Monthly Cost", 'yearly_cost' => "Yearly Cost", 'average_monthly' => "Average Monthly Subscription Cost", diff --git a/includes/i18n/es.php b/includes/i18n/es.php index bb3d88998..7823b9714 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -33,6 +33,7 @@ 'last_added' => "Última Añadida", 'price' => "Precio", 'next_payment' => "Próximo Pago", + 'inactive' => "Suscripción desactivada", 'member' => "Miembro", 'category' => "Categoría", 'payment_method' => "Método de Pago", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "Estadísticas Generales", 'active_subscriptions' => "Suscripciones Activas", + 'inactive_subscriptions' => "Suscripciones inactivas", 'monthly_cost' => "Costo Mensual", 'yearly_cost' => "Costo Anual", 'average_monthly' => "Costo Promedio Mensual de Suscripción", diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index 8e67e2804..c1f5c7159 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -33,6 +33,7 @@ 'last_added' => "Dernier ajouté", 'price' => "Prix", 'next_payment' => "Prochain paiement", + 'inactive' => "Abonnement désactivé", 'member' => "Membre", 'category' => "Catégorie", 'payment_method' => "Méthode de paiement", @@ -70,6 +71,7 @@ // Page de statistiques 'general_statistics' => "Statistiques générales", 'active_subscriptions' => "Abonnements actifs", + 'inactive_subscriptions' => "Abonnements inactifs", 'monthly_cost' => "Coût mensuel", 'yearly_cost' => "Coût annuel", 'average_monthly' => "Coût moyen mensuel de l'abonnement", diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index 7fde90af4..327199f91 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -33,6 +33,7 @@ 'last_added' => "最終追加日", 'price' => "金額", 'next_payment' => "次回支払い", + 'inactive' => "無効なサブスクリプション", 'member' => "メンバー", 'category' => "カテゴリ", 'payment_method' => "支払い方法", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "一般統計", 'active_subscriptions' => "アクティブな定期購入", + 'inactive_subscriptions' => "非アクティブなサブスクリプション", 'monthly_cost' => "月間費用", 'yearly_cost' => "年間費用", 'average_monthly' => "月額平均費用", diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index 1192a33e8..266b86e36 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -33,6 +33,7 @@ 'last_added' => "Última Adicionada", 'price' => "Preço", 'next_payment' => "Próximo Pagamento", + 'inactive' => "Subscrição desactivada", 'member' => "Membro", 'category' => "Categoria", 'payment_method' => "Metodo de Pagamento", @@ -70,6 +71,7 @@ // Statistics page 'general_statistics' => "Estatísticas Gerais", 'active_subscriptions' => "Subscrições Activas", + 'inactive_subscriptions' => "Subscrições inactivas", 'monthly_cost' => "Custo Mensal", 'yearly_cost' => "Custo Anual", 'average_monthly' => "Custo Mensal Médio das Subscrições", diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index 9ec01a5f0..1a2b350e7 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -36,6 +36,7 @@ 'last_added' => "创建时间", 'price' => "价格", 'next_payment' => "下次支付时间", + 'inactive' => "禁用订阅", 'member' => "成员", 'category' => "分类", 'payment_method' => "支付方式", @@ -75,6 +76,7 @@ // 统计页面 'general_statistics' => "总体统计", 'active_subscriptions' => "活跃订阅", + 'inactive_subscriptions' => "非活动订阅", 'monthly_cost' => "月费用", 'yearly_cost' => "年费用", 'average_monthly' => "平均每月订阅费用", diff --git a/includes/list_subscriptions.php b/includes/list_subscriptions.php index 3a7aed1b1..2e7045bcd 100644 --- a/includes/list_subscriptions.php +++ b/includes/list_subscriptions.php @@ -63,6 +63,13 @@ function printSubscriptions($subscriptions, $sort, $categories, $members, $i18n) }); } + usort($subscriptions, function ($a, $b) { + if ($a['inactive'] == $b['inactive']) { + return 0; + } + return $a['inactive'] ? 1 : -1; + }); + $currentCategory = 0; $currentPayerUserId = 0; $currentPaymentMethodId = 0; @@ -98,7 +105,7 @@ function printSubscriptions($subscriptions, $sort, $categories, $members, $i18n) $currentPaymentMethodId = $subscription['payment_method_id']; } ?> -
+
diff --git a/index.php b/index.php index 98ff3995a..54a04e7e1 100644 --- a/index.php +++ b/index.php @@ -87,6 +87,7 @@ $print[$id]['category_id'] = $subscription['category_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id']; $print[$id]['price'] = floatval($subscription['price']); + $print[$id]['inactive'] = $subscription['inactive']; $print[$id]['url'] = $subscription['url']; $print[$id]['notes'] = $subscription['notes']; @@ -194,6 +195,11 @@
+
+ + +
+