From f2ed357f6021e78d1e244335040be1976eaa3360 Mon Sep 17 00:00:00 2001 From: Miguel Ribeiro Date: Wed, 14 Feb 2024 01:05:48 +0100 Subject: [PATCH] Add export subscriptions to JSON button --- endpoints/subscriptions/export.php | 41 ++++++++++++++++++++++++++++++ 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/tr.php | 2 ++ includes/i18n/zh_cn.php | 2 ++ includes/version.php | 2 +- scripts/settings.js | 4 +++ settings.php | 9 +++++++ 13 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 endpoints/subscriptions/export.php diff --git a/endpoints/subscriptions/export.php b/endpoints/subscriptions/export.php new file mode 100644 index 0000000..c43275a --- /dev/null +++ b/endpoints/subscriptions/export.php @@ -0,0 +1,41 @@ +query($query); +if ($result) { + $subscriptions = array(); + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + // Map foreign keys to their corresponding values + $row['currency'] = $currencies[$row['currency_id']]; + $row['payment_method'] = $payment_methods[$row['payment_method_id']]; + $row['payer_user'] = $members[$row['payer_user_id']]; + $row['category'] = $categories[$row['category_id']]; + $row['cycle'] = $cycles[$row['cycle']]; + $row['frequency'] = $frequencies[$row['frequency']]; + + $subscriptions[] = $row; + } + + // Output JSON + $json = json_encode($subscriptions, JSON_PRETTY_PRINT); + + // Set headers for file download + header('Content-Type: application/json'); + header('Content-Disposition: attachment; filename="subscriptions.json"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + // Output JSON for download + echo $json; +} else { + echo json_encode(array('error' => 'Failed to fetch subscriptions.')); +} + +?> \ No newline at end of file diff --git a/includes/i18n/de.php b/includes/i18n/de.php index e527308..d0f7e71 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Test", "add" => "Hinzufügen", "save" => "Speichern", + "export_subscriptions" => "Abonnements exportieren", + "export_to_json" => "Nach JSON exportieren", // Toast "success" => "Erfolgreich", // Endpoint responses diff --git a/includes/i18n/el.php b/includes/i18n/el.php index 2bdb565..a956ca3 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Δοκιμή", "add" => "Προσθήκη", "save" => "Αποθήκευση", + "export_subscriptions" => "Εξαγωγή συνδρομών", + "export_to_json" => "Εξαγωγή σε JSON", // Toast "success" => "Επιτυχία", // Endpoint responses diff --git a/includes/i18n/en.php b/includes/i18n/en.php index 42fbf47..29deea1 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Test", "add" => "Add", "save" => "Save", + "export_subscriptions" => "Export Subscriptions", + "export_to_json" => "Export to JSON", // Toast "success" => "Success", // Endpoint responses diff --git a/includes/i18n/es.php b/includes/i18n/es.php index a580600..aa889d4 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Probar", "add" => "Agregar", "save" => "Guardar", + "export_subscriptions" => "Exportar suscripciones", + "export_to_json" => "Exportar a JSON", // Toast "success" => "Éxito", // Endpoint responses diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index 3b4bfe0..efe84aa 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Test", "add" => "Ajouter", "save" => "Enregistrer", + "export_subscriptions" => "Exporter les abonnements", + "export_to_json" => "Exporter en JSON", // Toast "success" => "Succès", // Réponses de l'API diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index e1c6de8..a305ebf 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "テスト", "add" => "追加", "save" => "保存", + "export_subscriptions" => "購読をエクスポート", + "export_to_json" => "JSONにエクスポート", // Toast "success" => "成功", // Endpoint responses diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index 1069fe9..c34b3e0 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Testar", "add" => "Adicionar", "save" => "Guardar", + "export_subscriptions" => "Exportar Subscrições", + "export_to_json" => "Exportar para JSON", // Toast "success" => "Sucesso", // Endpoint responses diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php index c478d9b..018ad1d 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -134,6 +134,8 @@ $i18n = [ "test" => "Test Et", "add" => "Ekle", "save" => "Kaydet", + "export_subscriptions" => "Abonelikleri Dışa Aktar", + "export_to_json" => "JSON'a dışa aktar", // Toast "success" => "Başarılı", // Endpoint responses diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index 6a81c2b..3495f7b 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -141,6 +141,8 @@ $i18n = [ "test" => "测试", "add" => "添加", "save" => "保存", + "export_subscriptions" => "导出订阅", + "export_to_json" => "导出为 JSON", // Toast "success" => "成功", diff --git a/includes/version.php b/includes/version.php index 8aa218c..f464c96 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/scripts/settings.js b/scripts/settings.js index 3e92fbd..c0bc291 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -608,4 +608,8 @@ function setRemoveBackgroundCookie() { const removeBackgroundCheckbox = document.querySelector("#removebackground"); const value = removeBackgroundCheckbox.checked; document.cookie = `removeBackground=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`; +} + +function exportToJson() { + window.location.href = "endpoints/subscriptions/export.php"; } \ No newline at end of file diff --git a/settings.php b/settings.php index e286b1b..a8b1ed8 100644 --- a/settings.php +++ b/settings.php @@ -526,6 +526,15 @@ +
+
+

+
+
+ +
+
+