diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php index b9e1547..984a377 100644 --- a/endpoints/cronjobs/sendnotifications.php +++ b/endpoints/cronjobs/sendnotifications.php @@ -134,15 +134,21 @@ $notify = []; $i = 0; $currentDate = new DateTime('now'); while ($rowSubscription = $resultSubscriptions->fetchArray(SQLITE3_ASSOC)) { + if ($rowSubscription['notify_days_before'] !== 0) { + $daysToCompare = $rowSubscription['notify_days_before']; + } else { + $daysToCompare = $days; + } $nextPaymentDate = new DateTime($rowSubscription['next_payment']); $difference = $currentDate->diff($nextPaymentDate)->days + 1; - if ($difference === $days) { + if ($difference === $daysToCompare) { $notify[$rowSubscription['payer_user_id']][$i]['name'] = $rowSubscription['name']; $notify[$rowSubscription['payer_user_id']][$i]['price'] = $rowSubscription['price'] . $currencies[$rowSubscription['currency_id']]['symbol']; $notify[$rowSubscription['payer_user_id']][$i]['currency'] = $currencies[$rowSubscription['currency_id']]['name']; $notify[$rowSubscription['payer_user_id']][$i]['category'] = $categories[$rowSubscription['category_id']]['name']; $notify[$rowSubscription['payer_user_id']][$i]['payer'] = $household[$rowSubscription['payer_user_id']]['name']; $notify[$rowSubscription['payer_user_id']][$i]['date'] = $rowSubscription['next_payment']; + $notify[$rowSubscription['payer_user_id']][$i]['days'] = $daysToCompare; $i++; } } @@ -163,11 +169,11 @@ $defaultName = $defaultUser['username']; foreach ($notify as $userId => $perUser) { - $dayText = $days == 1 ? "tomorrow" : "in " . $days . " days"; - $message = "The following subscriptions are up for renewal " . $dayText . ":\n"; + $message = "The following subscriptions are up for renewal:\n"; foreach ($perUser as $subscription) { - $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; + $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days"; + $message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n"; } $mail = new PHPMailer(true); @@ -214,15 +220,15 @@ $title = translate('wallos_notification', $i18n); - $dayText = $days == 1 ? "tomorrow" : "in " . $days . " days"; if ($user['name']) { - $message = $user['name'] . ", the following subscriptions are up for renewal " . $dayText . ":\n"; + $message = $user['name'] . ", the following subscriptions are up for renewal:\n"; } else { - $message = "The following subscriptions are up for renewal " . $dayText . ":\n"; + $message = "The following subscriptions are up for renewal:\n"; } foreach ($perUser as $subscription) { - $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; + $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days"; + $message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n"; } $postfields = [ @@ -267,15 +273,15 @@ $result = $stmt->execute(); $user = $result->fetchArray(SQLITE3_ASSOC); - $dayText = $days == 1 ? "tomorrow" : "in " . $days . " days"; if ($user['name']) { - $message = $user['name'] . ", the following subscriptions are up for renewal " . $dayText . ":\n"; + $message = $user['name'] . ", the following subscriptions are up for renewal:\n"; } else { - $message = "The following subscriptions are up for renewal " . $dayText . ":\n"; + $message = "The following subscriptions are up for renewal:\n"; } foreach ($perUser as $subscription) { - $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; + $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days"; + $message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n"; } $data = array( @@ -312,15 +318,15 @@ $result = $stmt->execute(); $user = $result->fetchArray(SQLITE3_ASSOC); - $dayText = $days == 1 ? "tomorrow" : "in " . $days . " days"; if ($user['name']) { - $message = $user['name'] . ", the following subscriptions are up for renewal " . $dayText . ":\n"; + $message = $user['name'] . ", the following subscriptions are up for renewal:\n"; } else { - $message = "The following subscriptions are up for renewal " . $dayText . ":\n"; + $message = "The following subscriptions are up for renewal:\n"; } foreach ($perUser as $subscription) { - $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; + $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days"; + $message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n"; } $data = array( @@ -357,15 +363,15 @@ $result = $stmt->execute(); $user = $result->fetchArray(SQLITE3_ASSOC); - $dayText = $days == 1 ? "tomorrow" : "in " . $days . " days"; if ($user['name']) { - $message = $user['name'] . ", the following subscriptions are up for renewal " . $dayText . ":\n"; + $message = $user['name'] . ", the following subscriptions are up for renewal:\n"; } else { - $message = "The following subscriptions are up for renewal " . $dayText . ":\n"; + $message = "The following subscriptions are up for renewal:\n"; } foreach ($perUser as $subscription) { - $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; + $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days"; + $message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n"; } $ch = curl_init(); @@ -394,7 +400,7 @@ if ($webhookNotificationsEnabled) { // Get webhook payload and turn it into a json object - $payload = str_replace("{{days_until}}", $days, $webhook['payload']); + $payload = str_replace("{{days_until}}", $days, $webhook['payload']); // The default value for all subscriptions $payload_json = json_decode($payload, true); $subscription_template = $payload_json["{{subscriptions}}"]; @@ -422,6 +428,7 @@ $temp_subscription[$key] = str_replace("{{subscription_category}}", $subscription['category'], $temp_subscription[$key]); $temp_subscription[$key] = str_replace("{{subscription_payer}}", $subscription['payer'], $temp_subscription[$key]); $temp_subscription[$key] = str_replace("{{subscription_date}}", $subscription['date'], $temp_subscription[$key]); + $temp_subscription[$key] = str_replace("{{subscription_days_until_payment}}", $subscription['days'], $temp_subscription[$key]); // The de facto value for this subscription } } $subscriptions[] = $temp_subscription; diff --git a/endpoints/subscription/add.php b/endpoints/subscription/add.php index ad3cb3d..bb8f649 100644 --- a/endpoints/subscription/add.php +++ b/endpoints/subscription/add.php @@ -166,6 +166,7 @@ $logoUrl = validate($_POST['logo-url']); $logo = ""; $notify = isset($_POST['notifications']) ? true : false; + $notifyDaysBefore = $_POST['notify_days_before']; $inactive = isset($_POST['inactive']) ? true : false; if($logoUrl !== "") { @@ -183,15 +184,20 @@ 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, inactive, url) + payment_method_id, payer_user_id, category_id, notify, inactive, url, notify_days_before) VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes, - :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url)"; + :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url, :notifyDaysBefore)"; } 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, inactive = :inactive, 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, notify_days_before = :notifyDaysBefore 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, inactive = :inactive, 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,notify_days_before = :notifyDaysBefore WHERE id = :id"; } } @@ -215,6 +221,7 @@ $stmt->bindParam(':notify', $notify, SQLITE3_INTEGER); $stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER); $stmt->bindParam(':url', $url, SQLITE3_TEXT); + $stmt->bindParam(':notifyDaysBefore', $notifyDaysBefore, SQLITE3_INTEGER); if ($stmt->execute()) { $success['status'] = "Success"; diff --git a/endpoints/subscription/get.php b/endpoints/subscription/get.php index 7e8f680..2bb31b5 100644 --- a/endpoints/subscription/get.php +++ b/endpoints/subscription/get.php @@ -27,6 +27,7 @@ $subscriptionData['notify'] = $row['notify']; $subscriptionData['inactive'] = $row['inactive']; $subscriptionData['url'] = htmlspecialchars_decode($row['url']); + $subscriptionData['notify_days_before'] = $row['notify_days_before']; $subscriptionJson = json_encode($subscriptionData); header('Content-Type: application/json'); diff --git a/includes/i18n/de.php b/includes/i18n/de.php index 80312b5..5e8818f 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notizen", "enable_notifications" => "Benachrichtigungen für dieses Abonnement aktivieren", + "default_value_from_settings" => "Standardwert aus den Einstellungen", "delete" => "Löschen", "cancel" => "Abbrechen", "upload_logo" => "Logo hochladen", diff --git a/includes/i18n/el.php b/includes/i18n/el.php index 23a301c..709b365 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Σημειώσεις", "enable_notifications" => "Ενεργοποίηση ειδοποιήσεων για αυτή τη συνδρομή", + "default_value_from_settings" => "Προεπιλεγμένη τιμή από τις ρυθμίσεις", "delete" => "Διαγραφή", "cancel" => "Ακύρωση", "upload_logo" => "Φόρτωση λογότυπου", diff --git a/includes/i18n/en.php b/includes/i18n/en.php index 0cb324e..004870d 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notes", "enable_notifications" => "Enable Notifications for this subscription", + "default_value_from_settings" => "Default value from settings", "delete" => "Delete", "cancel" => "Cancel", "upload_logo" => "Upload Logo", diff --git a/includes/i18n/es.php b/includes/i18n/es.php index 4d76faa..6531b3d 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notas", "enable_notifications" => "Habilitar notificaciones para esta suscripción", + "default_value_from_settings" => "Valor predeterminado de la configuración", "delete" => "Eliminar", "cancel" => "Cancelar", "upload_logo" => "Cargar Logotipo", diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index e8bd441..39b5653 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notes", "enable_notifications" => "Activer les notifications pour cet abonnement", + "default_value_from_settings" => "Valeur par défaut des paramètres", "delete" => "Supprimer", "cancel" => "Annuler", "upload_logo" => "Télécharger le logo", diff --git a/includes/i18n/it.php b/includes/i18n/it.php index f19269d..13fe25e 100644 --- a/includes/i18n/it.php +++ b/includes/i18n/it.php @@ -76,6 +76,7 @@ $i18n = [ 'url' => 'URL', 'notes' => 'Note', 'enable_notifications' => 'Abilita notifiche per questo abbonamento', + 'default_value_from_settings' => 'Valore predefinito dalle impostazioni', 'delete' => 'Cancella', 'cancel' => 'Annulla', 'upload_logo' => 'Carica logo', diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index f72d3c2..2f9da67 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "注釈", "enable_notifications" => "この定期購入の通知を有効にする", + "default_value_from_settings" => "設定からデフォルト値を使用", "delete" => "削除", "cancel" => "キャンセル", "upload_logo" => "ロゴのアップロード", diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php index d37e945..d1c9f7b 100644 --- a/includes/i18n/ko.php +++ b/includes/i18n/ko.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "메모", "enable_notifications" => "이 구독에 대한 알림을 활성화합니다.", + "default_value_from_settings" => "설정에서 기본값 사용", "delete" => "삭제", "cancel" => "취소", "upload_logo" => "로고 업로드", diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php index c69467f..3b1047c 100644 --- a/includes/i18n/pl.php +++ b/includes/i18n/pl.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notatki", "enable_notifications" => "Włącz powiadomienia dla tej subskrypcji", + "default_value_from_settings" => "Wartość domyślna z ustawień", "delete" => "Usuń", "cancel" => "Anuluj", "upload_logo" => "Prześlij logo", diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index 5376f1e..a93a01c 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notas", "enable_notifications" => "Activar notificações para esta subscrição", + "default_value_from_settings" => "Valor por defeito das definições", "delete" => "Remover", "cancel" => "Cancelar", "upload_logo" => "Enviar Logo", diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php index f9c6d5d..10f3cdf 100644 --- a/includes/i18n/pt_br.php +++ b/includes/i18n/pt_br.php @@ -72,6 +72,7 @@ $i18n = [ "url" => "URL", "notes" => "Anotações", "enable_notifications" => "Ativar notificações para essa assinatura", + "default_value_from_settings" => "Valor padrão das configurações", "delete" => "Excluir", "cancel" => "Cancelar", "upload_logo" => "Enviar Logo", diff --git a/includes/i18n/ru.php b/includes/i18n/ru.php index 134583d..02059ad 100644 --- a/includes/i18n/ru.php +++ b/includes/i18n/ru.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Примечания", "enable_notifications" => "Включить уведомления для этой подписки", + "default_value_from_settings" => "Значение по умолчанию из настроек", "delete" => "Удалить", "cancel" => "Отмена", "upload_logo" => "Загрузить логотип", diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php index 8d2bd23..f989c5b 100644 --- a/includes/i18n/sr_lat.php +++ b/includes/i18n/sr_lat.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Beleške", "enable_notifications" => "Omogući obaveštenja za ovu pretplatu", + "default_value_from_settings" => "Podrazumevana vrednost iz podešavanja", "delete" => "Izbriši", "cancel" => "Otkaži", "upload_logo" => "Učitaj logo", diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php index 76e82d3..7f8fd4d 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "URL", "notes" => "Notlar", "enable_notifications" => "Bu abonelik için bildirimleri etkinleştir", + "default_value_from_settings" => "Ayarlar'dan varsayılan değeri al", "delete" => "Sil", "cancel" => "İptal", "upload_logo" => "Logo Yükle", diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index ea0ffcb..963b2f5 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -78,6 +78,7 @@ $i18n = [ "url" => "链接", "notes" => "备注", "enable_notifications" => "为此订阅启用通知", + "default_value_from_settings" => "默认值从设置中获取", "delete" => "删除", "cancel" => "取消", "upload_logo" => "上传 Logo", diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php index a6d759c..3d39cdd 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -74,6 +74,7 @@ $i18n = [ "url" => "連結", "notes" => "備註", "enable_notifications" => "為該訂閱開啟通知", + "default_value_from_settings" => "從設定中取得預設值", "delete" => "刪除", "cancel" => "取消", "upload_logo" => "上傳圖示", diff --git a/includes/version.php b/includes/version.php index c9063c1..2262924 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ diff --git a/index.php b/index.php index 15311f8..758c16a 100644 --- a/index.php +++ b/index.php @@ -276,10 +276,25 @@
- = translate('variables_available', $i18n) ?>: {{days_until}}, {{subscription_name}}, {{subscription_price}}, {{subscription_currency}}, {{subscription_category}}, {{subscription_date}}, {{subscription_payer}}
+ = translate('variables_available', $i18n) ?>: {{days_until}}, {{subscription_name}}, {{subscription_price}}, {{subscription_currency}}, {{subscription_category}}, {{subscription_date}}, {{subscription_payer}}, {{subscription_days_until_payment}}