Skip to content

Commit

Permalink
feat: add option to list disabled subscriptions at the bottom
Browse files Browse the repository at this point in the history
feat: notification for wallos version updates
  • Loading branch information
ellite authored Aug 6, 2024
1 parent 1767709 commit 3281f0c
Show file tree
Hide file tree
Showing 34 changed files with 670 additions and 207 deletions.
43 changes: 43 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ class="one-third" value="<?= $settings['smtp_port'] ?>" />
</section>

<?php
// Get latest version from admin table
$latestVersion = $settings['latest_version'];
$hasUpdate = version_compare($version, $latestVersion) == -1;

// find unused upload logos

// Get all logos in the subscriptions table
Expand Down Expand Up @@ -298,6 +302,45 @@ class="one-third" value="<?= $settings['smtp_port'] ?>" />
</h2>
</header>
<div class="maintenance-tasks">
<h3><?= translate('update', $i18n) ?></h3>
<div class="form-group">
<?php
if ($hasUpdate) {
?>
<div class="updates-list">
<p><?= translate('new_version_available', $i18n) ?>.</p>
<p>
<?= translate('current_version', $i18n) ?>:
<span>
<?= $version ?>
<a href="https://github.com/ellite/Wallos/releases/tag/<?= $version ?>" target="_blank">
<i class="fa-solid fa-external-link"></i>
</a>
</span>
</p>
<p>
<?= translate('latest_version', $i18n) ?>:
<span>
<?= $latestVersion ?>
<a href="https://github.com/ellite/Wallos/releases/tag/<?= $latestVersion ?>"
target="_blank">
<i class="fa-solid fa-external-link"></i>
</a>
</span>
</p>
</div>
<?php
} else {
?>
<?= translate('on_current_version', $i18n) ?>
<?php
}
?>
</div>
<div class="form-group-inline">
<input type="checkbox" id="updateNotification" <?= $settings['update_notification'] ? 'checked' : '' ?> onchange="toggleUpdateNotification()"/>
<label for="updateNotification"><?= translate('show_update_notification', $i18n) ?></label>
</div>
<h3><?= translate('orphaned_logos', $i18n) ?></h3>
<div class="form-group-inline">
<input type="button" class="button thin mobile-grow" value="<?= translate('delete', $i18n) ?>"
Expand Down
1 change: 1 addition & 0 deletions cronjobs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
0 9 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/sendnotifications.php >> /var/log/cron/sendnotifications.log 2>&1
*/2 * * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/sendverificationemails.php >> /var/log/cron/sendverificationemails.log 2>&1
*/2 * * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/sendresetpasswordemails.php >> /var/log/cron/sendresetpasswordemails.log 2>&1
0 */6 * * * /usr/local/bin/php /var/www/html/endpoints/cronjobs/checkforupdates.php >> /var/log/cron/checkforupdates.log 2>&1
46 changes: 46 additions & 0 deletions endpoints/admin/updatenotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

// Check that user is an admin
if ($userId !== 1) {
die(json_encode([
"success" => false,
"message" => translate('error', $i18n)
]));
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {

$postData = file_get_contents("php://input");
$data = json_decode($postData, true);

$updateNotification = $data['notificationEnabled'];

// Save settings
$stmt = $db->prepare('UPDATE admin SET update_notification = :update_notification');
$stmt->bindValue(':update_notification', $updateNotification, SQLITE3_INTEGER);
$result = $stmt->execute();

if ($result) {
die(json_encode([
"success" => true,
"message" => translate('success', $i18n)
]));
} else {
die(json_encode([
"success" => false,
"message" => translate('error', $i18n)
]));
}

}

?>
30 changes: 30 additions & 0 deletions endpoints/cronjobs/checkforupdates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';

$options = [
'http' => [
'header' => "User-Agent: MyApp\r\n"
]
];

$repository = 'ellite/Wallos'; // Change this to your repository if you fork Wallos
$url = "https://api.github.com/repos/$repository/releases/latest";

$context = stream_context_create($options);
$fetch = file_get_contents($url, false, $context);

if ($fetch === false) {
die('Error fetching data from GitHub API');
}

$latestVersion = json_decode($fetch, true)['tag_name'];

// Check that $latestVersion is a valid version number
if (!preg_match('/^v\d+\.\d+\.\d+$/', $latestVersion)) {
die('Error: Invalid version number from GitHub API');
}

$db->exec("UPDATE admin SET latest_version = '$latestVersion'");

?>
34 changes: 34 additions & 0 deletions endpoints/settings/disabled_to_bottom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {
$postData = file_get_contents("php://input");
$data = json_decode($postData, true);

$disabled_to_bottom = $data['value'];

$stmt = $db->prepare('UPDATE settings SET disabled_to_bottom = :disabled_to_bottom WHERE user_id = :userId');
$stmt->bindParam(':disabled_to_bottom', $disabled_to_bottom, SQLITE3_INTEGER);
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);

if ($stmt->execute()) {
die(json_encode([
"success" => true,
"message" => translate("success", $i18n)
]));
} else {
die(json_encode([
"success" => false,
"message" => translate("error", $i18n)
]));
}
}

?>
74 changes: 53 additions & 21 deletions endpoints/subscriptions/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,11 @@
}

if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {


$sort = "next_payment";
$sortOrder = $sort;
$order = "ASC";
$sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC, inactive ASC";
if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") {
$sort = $_COOKIE['sortOrder'];
$sortOrder = $sort;
$allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive', 'alphanumeric'];
if ($sort == "price" || $sort == "id") {
$order = "DESC";
}
if ($sort == "alphanumeric") {
$sort = "name";
}
if (!in_array($sort, $allowedSortCriteria)) {
$sort = "next_payment";
}
}

$params = array();
$sql = "SELECT * FROM subscriptions WHERE user_id = :userId";
Expand All @@ -61,12 +48,41 @@
$params[':inactive'] = $_GET['state'];
}

$sql .= " ORDER BY LOWER($sort) $order";
if ($sort != "next_payment") {
$sql .= ", next_payment ASC";
}
if ($sort != "state") {
$sql .= ", inactive ASC";
if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") {
$sort = $_COOKIE['sortOrder'];
$allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive', 'alphanumeric'];
$order = ($sort == "price" || $sort == "id") ? "DESC" : "ASC";

if ($sort == "alphanumeric") {
$sort = "name";
}

if (!in_array($sort, $allowedSortCriteria)) {
$sort = "next_payment";
}

$orderByClauses = [];

if ($settings['disabledToBottom'] === 'true') {
if (in_array($sort, ["payer_user_id", "category_id", "payment_method_id"])) {
$orderByClauses[] = "$sort $order";
$orderByClauses[] = "inactive ASC";
} else {
$orderByClauses[] = "inactive ASC";
$orderByClauses[] = "$sort $order";
}
} else {
$orderByClauses[] = "$sort $order";
if ($sort != "inactive") {
$orderByClauses[] = "inactive ASC";
}
}

if ($sort != "next_payment") {
$orderByClauses[] = "next_payment ASC";
}

$sql .= " ORDER BY " . implode(", ", $orderByClauses);
}

$stmt = $db->prepare($sql);
Expand Down Expand Up @@ -123,6 +139,22 @@
usort($print, function ($a, $b) {
return strnatcmp(strtolower($a['name']), strtolower($b['name']));
});
if ($settings['disabledToBottom'] === 'true') {
usort($print, function ($a, $b) {
return $a['inactive'] - $b['inactive'];
});
}
}

if ($sort === "price") {
usort($subscriptions, function ($a, $b) {
return $a['price'] < $b['price'] ? 1 : -1;
});
if ($settings['disabledToBottom'] === 'true') {
usort($print, function ($a, $b) {
return $a['inactive'] - $b['inactive'];
});
}
}

if (isset($print)) {
Expand Down
3 changes: 3 additions & 0 deletions includes/getsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$settings['convertCurrency'] = $settings['convert_currency'] ? 'true': 'false';
$settings['removeBackground'] = $settings['remove_background'] ? 'true': 'false';
$settings['hideDisabledSubscriptions'] = $settings['hide_disabled'] ? 'true': 'false';
$settings['disabledToBottom'] = $settings['disabled_to_bottom'] ? 'true': 'false';
}

$query = "SELECT * FROM custom_colors WHERE user_id = :userId";
Expand Down Expand Up @@ -54,6 +55,8 @@

if ($adminSettings) {
$settings['disableLogin'] = $adminSettings['login_disabled'];
$settings['update_notification'] = $adminSettings['update_notification'];
$settings['latest_version'] = $adminSettings['latest_version'];
}

?>
7 changes: 7 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"calculate_monthly_price" => "Berechne und zeige monatlichen Preis für alle Abonnements an",
"convert_prices" => "Preise immer in meine Hauptwährung umrechnen und darin anzeigen (langsamer)",
"hide_disabled_subscriptions" => "Deaktivierte Abonnements verstecken",
"show_disabled_subscriptions_at_the_bottom" => "Deaktivierte Abonnements am Ende anzeigen",
"experimental_settings" => "Experimentelle Einstellungen",
"remove_background" => "Versuchen den Hintergrund von Logos aus der Bildersuche zu entfernen (experimentell)",
"experimental_info" => "Experimentelle Einstellungen funktionieren möglicherweise nicht perfekt.",
Expand Down Expand Up @@ -309,6 +310,12 @@
"smtp_usage_info" => "Wird für die Passwortwiederherstellung und andere System-E-Mails verwendet",
"maintenance_tasks" => "Wartungsaufgaben",
"orphaned_logos" => "Verwaiste Logos",
"update" => "Update",
"new_version_available" => "Eine neue Version von Wallos ist verfügbar",
"current_version" => "Aktuelle Version",
"latest_version" => "Neueste Version",
"on_current_version" => "Sie verwenden die neueste Version von Wallos.",
"show_update_notification" => "Benachrichtigung über Updates auf dem Dashboard anzeigen",
// Email Verification
"email_verified" => "E-Mail verifiziert",
"email_verification_failed" => "E-Mail konnte nicht verifiziert werden",
Expand Down
9 changes: 8 additions & 1 deletion includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"theme" => "Θέμα",
"dark_theme" => "Dark Theme",
"light_theme" => "Light Theme",
"automatic"=> "Αυτόματο",
"automatic" => "Αυτόματο",
"main_color" => "Κύριο χρώμα",
"accent_color" => "Χρώμα επισήμανσης",
"hover_color" => "Χρώμα πάνω από",
Expand All @@ -197,6 +197,7 @@
"calculate_monthly_price" => "Υπολογισμός και εμφάνιση της μηνιαίας τιμής για όλες τις συνδρομές",
"convert_prices" => "Πάντα να μετατρέπει και να εμφανίζει τις τιμές στο κύριο νόμισμά μου (πιο αργό)",
"hide_disabled_subscriptions" => "Απόκρυψη απενεργοποιημένων συνδρομών",
"show_disabled_subscriptions_at_the_bottom" => "Εμφάνιση απενεργοποιημένων συνδρομών στο τέλος",
"experimental_settings" => "Πειραματικές ρυθμίσεις",
"remove_background" => "Προσπάθεια αφαίρεσης του φόντου των λογότυπων από την αναζήτηση εικόνας (πειραματικά)",
"experimental_info" => "Οι πειραματικές ρυθμίσεις πιθανότατα δεν θα λειτουργούν τέλεια.",
Expand Down Expand Up @@ -309,6 +310,12 @@
"smtp_usage_info" => "Θα χρησιμοποιηθεί για ανάκτηση κωδικού πρόσβασης και άλλα μηνύματα ηλεκτρονικού ταχυδρομείου συστήματος.",
"maintenance_tasks" => "Εργασίες συντήρησης",
"orphaned_logos" => "Ορφανά λογότυπα",
"update" => "Ενημέρωση",
"new_version_available" => "Μια νέα έκδοση του Wallos είναι διαθέσιμη",
"current_version" => "Τρέχουσα Έκδοση",
"latest_version" => "Τελευταία Έκδοση",
"on_current_version" => "Χρησιμοποιείτε την τελευταία έκδοση του Wallos.",
"show_update_notification" => "Εμφάνιση ειδοποίησης για ενημερώσεις στο dashboard",
// Email Verification
"email_verified" => "Το email επιβεβαιώθηκε",
"email_verification_failed" => "Η επαλήθευση email απέτυχε",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"calculate_monthly_price" => "Calculate and show monthly price for all subscriptions",
"convert_prices" => "Always convert and show prices on my main currency (slower)",
"hide_disabled_subscriptions" => "Hide disabled subscriptions",
"show_disabled_subscriptions_at_the_bottom" => "Show disabled subscriptions at the bottom",
"experimental_settings" => "Experimental Settings",
"remove_background" => "Attempt to remove background of logos from image search (experimental)",
"experimental_info" => "Experimental settings will probably not work perfectly.",
Expand Down Expand Up @@ -309,6 +310,12 @@
"smtp_usage_info" => "Will be used for password recovery and other system emails.",
"maintenance_tasks" => "Maintenance Tasks",
"orphaned_logos" => "Orphaned Logos",
"update" => "Update",
"new_version_available" => "A new version of Wallos is available",
"current_version" => "Current Version",
"latest_version" => "Latest Version",
"on_current_version" => "You're running the latest version of Wallos.",
"show_update_notification" => "Show notification for updates on the dashboard",
// Email Verification
"email_verified" => "Email verified successfully",
"email_verification_failed" => "Email verification failed",
Expand Down
9 changes: 8 additions & 1 deletion includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"theme" => "Tema",
"dark_theme" => "Tema Oscuro",
"light_theme" => "Tema Claro",
"automatic"=> "Automático",
"automatic" => "Automático",
"main_color" => "Color Principal",
"accent_color" => "Color de Acento",
"hover_color" => "Color de Hover",
Expand All @@ -197,6 +197,7 @@
"calculate_monthly_price" => "Calcular y mostrar el precio mensual de todas las suscripciones",
"convert_prices" => "Convertir y mostrar siempre los precios en mi moneda principal (más lento)",
"hide_disabled_subscriptions" => "Ocultar suscripciones desactivadas",
"show_disabled_subscriptions_at_the_bottom" => "Mostrar suscripciones desactivadas al final",
"experimental_settings" => "Configuraciones Experimentales",
"remove_background" => "Intentar quitar el fondo de los logotipos de la búsqueda de imágenes (experimental)",
"experimental_info" => "Las configuraciones experimentales probablemente no funcionarán perfectamente.",
Expand Down Expand Up @@ -309,6 +310,12 @@
"smtp_usage_info" => "Se utilizará para recuperar contraseñas y otros correos electrónicos del sistema.",
"maintenance_tasks" => "Tareas de Mantenimiento",
"orphaned_logos" => "Logotipos huérfanos",
"update" => "Actualizar",
"new_version_available" => "Una nueva versión de Wallos está disponible",
"current_version" => "Versión Actual",
"latest_version" => "Última Versión",
"on_current_version" => "Está utilizando la última versión de Wallos.",
"show_update_notification" => "Mostrar notificación de actualizaciones en el dashboard",
// Email Verification
"email_verified" => "Correo electrónico verificado",
"email_verification_failed" => "Error al verificar el correo electrónico",
Expand Down
Loading

0 comments on commit 3281f0c

Please sign in to comment.