Add export subscriptions to JSON button
This commit is contained in:
parent
c9135e1dc8
commit
f2ed357f60
41
endpoints/subscriptions/export.php
Normal file
41
endpoints/subscriptions/export.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once '../../includes/connect_endpoint.php';
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once '../../includes/getdbkeys.php';
|
||||||
|
|
||||||
|
$query = "SELECT * FROM subscriptions";
|
||||||
|
|
||||||
|
$result = $db->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.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Test",
|
"test" => "Test",
|
||||||
"add" => "Hinzufügen",
|
"add" => "Hinzufügen",
|
||||||
"save" => "Speichern",
|
"save" => "Speichern",
|
||||||
|
"export_subscriptions" => "Abonnements exportieren",
|
||||||
|
"export_to_json" => "Nach JSON exportieren",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Erfolgreich",
|
"success" => "Erfolgreich",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Δοκιμή",
|
"test" => "Δοκιμή",
|
||||||
"add" => "Προσθήκη",
|
"add" => "Προσθήκη",
|
||||||
"save" => "Αποθήκευση",
|
"save" => "Αποθήκευση",
|
||||||
|
"export_subscriptions" => "Εξαγωγή συνδρομών",
|
||||||
|
"export_to_json" => "Εξαγωγή σε JSON",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Επιτυχία",
|
"success" => "Επιτυχία",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Test",
|
"test" => "Test",
|
||||||
"add" => "Add",
|
"add" => "Add",
|
||||||
"save" => "Save",
|
"save" => "Save",
|
||||||
|
"export_subscriptions" => "Export Subscriptions",
|
||||||
|
"export_to_json" => "Export to JSON",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Success",
|
"success" => "Success",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Probar",
|
"test" => "Probar",
|
||||||
"add" => "Agregar",
|
"add" => "Agregar",
|
||||||
"save" => "Guardar",
|
"save" => "Guardar",
|
||||||
|
"export_subscriptions" => "Exportar suscripciones",
|
||||||
|
"export_to_json" => "Exportar a JSON",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Éxito",
|
"success" => "Éxito",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Test",
|
"test" => "Test",
|
||||||
"add" => "Ajouter",
|
"add" => "Ajouter",
|
||||||
"save" => "Enregistrer",
|
"save" => "Enregistrer",
|
||||||
|
"export_subscriptions" => "Exporter les abonnements",
|
||||||
|
"export_to_json" => "Exporter en JSON",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Succès",
|
"success" => "Succès",
|
||||||
// Réponses de l'API
|
// Réponses de l'API
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "テスト",
|
"test" => "テスト",
|
||||||
"add" => "追加",
|
"add" => "追加",
|
||||||
"save" => "保存",
|
"save" => "保存",
|
||||||
|
"export_subscriptions" => "購読をエクスポート",
|
||||||
|
"export_to_json" => "JSONにエクスポート",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "成功",
|
"success" => "成功",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Testar",
|
"test" => "Testar",
|
||||||
"add" => "Adicionar",
|
"add" => "Adicionar",
|
||||||
"save" => "Guardar",
|
"save" => "Guardar",
|
||||||
|
"export_subscriptions" => "Exportar Subscrições",
|
||||||
|
"export_to_json" => "Exportar para JSON",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Sucesso",
|
"success" => "Sucesso",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -134,6 +134,8 @@ $i18n = [
|
|||||||
"test" => "Test Et",
|
"test" => "Test Et",
|
||||||
"add" => "Ekle",
|
"add" => "Ekle",
|
||||||
"save" => "Kaydet",
|
"save" => "Kaydet",
|
||||||
|
"export_subscriptions" => "Abonelikleri Dışa Aktar",
|
||||||
|
"export_to_json" => "JSON'a dışa aktar",
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "Başarılı",
|
"success" => "Başarılı",
|
||||||
// Endpoint responses
|
// Endpoint responses
|
||||||
|
|||||||
@ -141,6 +141,8 @@ $i18n = [
|
|||||||
"test" => "测试",
|
"test" => "测试",
|
||||||
"add" => "添加",
|
"add" => "添加",
|
||||||
"save" => "保存",
|
"save" => "保存",
|
||||||
|
"export_subscriptions" => "导出订阅",
|
||||||
|
"export_to_json" => "导出为 JSON",
|
||||||
|
|
||||||
// Toast
|
// Toast
|
||||||
"success" => "成功",
|
"success" => "成功",
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$version = "v1.2.3";
|
$version = "v1.2.4";
|
||||||
?>
|
?>
|
||||||
@ -608,4 +608,8 @@ function setRemoveBackgroundCookie() {
|
|||||||
const removeBackgroundCheckbox = document.querySelector("#removebackground");
|
const removeBackgroundCheckbox = document.querySelector("#removebackground");
|
||||||
const value = removeBackgroundCheckbox.checked;
|
const value = removeBackgroundCheckbox.checked;
|
||||||
document.cookie = `removeBackground=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
|
document.cookie = `removeBackground=${value}; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportToJson() {
|
||||||
|
window.location.href = "endpoints/subscriptions/export.php";
|
||||||
}
|
}
|
||||||
@ -526,6 +526,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="account-section">
|
||||||
|
<header>
|
||||||
|
<h2><?= translate('export_subscriptions', $i18n) ?></h2>
|
||||||
|
</header>
|
||||||
|
<div>
|
||||||
|
<input type="button" class="button" value="<?= translate('export_to_json', $i18n) ?>" id="exportToJson" onClick="exportToJson()"/>
|
||||||
|
<div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
<script src="scripts/settings.js?<?= $version ?>"></script>
|
<script src="scripts/settings.js?<?= $version ?>"></script>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user