Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
feat: add alphanumeric sort order for subscriptions (#449)
Miguel Ribeiro775e6ee39457
diff --git a/a.out b/a.outdeleted file mode 100644index e69de29..0000000diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.phpindex b6240fe..141335e 100644--- a/endpoints/subscriptions/get.php+++ b/endpoints/subscriptions/get.php@@ -24,10 +24,14 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {$sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC, 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'];+ $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";}@@ -56,7 +60,7 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {$params[':inactive'] = $_GET['state'];}- $sql .= " ORDER BY $sort $order";+ $sql .= " ORDER BY LOWER($sort) $order";if ($sort != "next_payment") {$sql .= ", next_payment ASC";}@@ -114,6 +118,12 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {}}+ if ($sortOrder == "alphanumeric") {+ usort($print, function ($a, $b) {+ return strnatcmp(strtolower($a['name']), strtolower($b['name']));+ });+ }+if (isset($print)) {printSubscriptions($print, $sort, $categories, $members, $i18n, $colorTheme, "../../");}diff --git a/includes/i18n/de.php b/includes/i18n/de.phpindex 817bea7..27ea997 100644--- a/includes/i18n/de.php+++ b/includes/i18n/de.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Neues Abonnement",'search' => "Suche",'state' => "Status",+ 'alphanumeric' => "Alphanumerisch",'sort' => "Sortieren",'name' => "Bezeichnung",'last_added' => "Zuletzt hinzugefügt",diff --git a/includes/i18n/el.php b/includes/i18n/el.phpindex abd018c..4a8218b 100644--- a/includes/i18n/el.php+++ b/includes/i18n/el.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Νέα συνδρομή",'search' => "Αναζήτηση",'state' => "Κατάσταση",+ 'alphanumeric' => "Αλφαριθμητική",'sort' => "Ταξινόμηση",'name' => "Όνομα",'last_added' => "Τελευταία προσθήκη",diff --git a/includes/i18n/en.php b/includes/i18n/en.phpindex c29a2f8..de5a754 100644--- a/includes/i18n/en.php+++ b/includes/i18n/en.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "New Subscription",'search' => "Search",'state' => "State",+ 'alphanumeric' => "Alphanumeric",'sort' => "Sort",'name' => "Name",'last_added' => "Last Added",diff --git a/includes/i18n/es.php b/includes/i18n/es.phpindex 558fef8..a868030 100644--- a/includes/i18n/es.php+++ b/includes/i18n/es.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nueva Suscripción",'search' => "Buscar",'state' => "Estado",+ 'alphanumeric' => "Alfanumérico",'sort' => "Ordenar",'name' => "Nombre",'last_added' => "Última Añadida",diff --git a/includes/i18n/fr.php b/includes/i18n/fr.phpindex 99fcf0a..c691f9c 100644--- a/includes/i18n/fr.php+++ b/includes/i18n/fr.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nouvel abonnement",'search' => "Rechercher",'state' => "État",+ 'alphanumeric' => "Alphanumérique",'sort' => "Trier",'name' => "Nom",'last_added' => "Dernier ajouté",diff --git a/includes/i18n/it.php b/includes/i18n/it.phpindex bc3f206..06979ed 100644--- a/includes/i18n/it.php+++ b/includes/i18n/it.php@@ -45,6 +45,7 @@ $i18n = ['new_subscription' => 'Nuovo abbonamento','search' => 'Cerca','state' => "Stato",+ 'alphanumeric' => 'Alfanumerico','sort' => 'Ordina','name' => 'Nome','last_added' => 'Ultimo aggiunto',diff --git a/includes/i18n/jp.php b/includes/i18n/jp.phpindex 3aad65f..b55c9df 100644--- a/includes/i18n/jp.php+++ b/includes/i18n/jp.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "新しい定期購入",'search' => "検索",'state' => "状態",+ 'alphanumeric' => "アルファベット順",'sort' => "並べ替え",'name' => "名前",'last_added' => "最終追加日",diff --git a/includes/i18n/ko.php b/includes/i18n/ko.phpindex 36764c2..a73db4a 100644--- a/includes/i18n/ko.php+++ b/includes/i18n/ko.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "새 구독",'search' => "검색",'state' => "상태",+ 'alphanumeric' => "알파벳순",'sort' => "정렬",'name' => "이름",'last_added' => "최근 등록",diff --git a/includes/i18n/pl.php b/includes/i18n/pl.phpindex 57ebfb2..8fbe156 100644--- a/includes/i18n/pl.php+++ b/includes/i18n/pl.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nowa subskrypcja",'search' => "Szukaj",'state' => "Stan",+ 'alphanumeric' => "Alfanumeryczny",'sort' => "Sortuj",'name' => "Nazwa",'last_added' => "Ostatnio dodane",diff --git a/includes/i18n/pt.php b/includes/i18n/pt.phpindex 1074cb3..048e9f4 100644--- a/includes/i18n/pt.php+++ b/includes/i18n/pt.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nova Subscrição",'search' => "Pesquisar",'state' => "Estado",+ 'alphanumeric' => "Alfanumérico",'sort' => "Ordenar",'name' => "Nome",'last_added' => "Última Adicionada",diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.phpindex 6bcd5e6..bc6d9ef 100644--- a/includes/i18n/pt_br.php+++ b/includes/i18n/pt_br.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nova assinatura",'search' => "Pesquisar",'state' => "Estado",+ 'alphanumeric' => "Alfanumérico",'sort' => "Ordenar",'name' => "Nome",'last_added' => "Última adicionada",diff --git a/includes/i18n/ru.php b/includes/i18n/ru.phpindex 99a7e61..b8615f7 100644--- a/includes/i18n/ru.php+++ b/includes/i18n/ru.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Новая подписка",'search' => "Поиск",'state' => "Состояние",+ 'alphanumeric' => "Алфавитный порядок",'sort' => "Сортировка",'name' => "Имя",'last_added' => "Дата создания",diff --git a/includes/i18n/sl.php b/includes/i18n/sl.phpindex 6989cff..e14a0a7 100644--- a/includes/i18n/sl.php+++ b/includes/i18n/sl.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nova naročnina",'search' => "Iskanje",'state' => "Stanje",+ 'alphanumeric' => "Abecedno",'sort' => "Razvrsti",'name' => "Ime",'last_added' => "Zadnje dodano",diff --git a/includes/i18n/sr.php b/includes/i18n/sr.phpindex c051a89..4f2d4df 100644--- a/includes/i18n/sr.php+++ b/includes/i18n/sr.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Нова претплата",'search' => "Претрага",'state' => "Статус",+ 'alphanumeric' => "Алфанумерички",'sort' => "Сортирај",'name' => "Назив",'last_added' => "Последње додато",diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.phpindex 0ec7244..3a17c2b 100644--- a/includes/i18n/sr_lat.php+++ b/includes/i18n/sr_lat.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Nova pretplata",'search' => "Pretraga",'state' => "Stanje",+ 'alphanumeric' => "Alfanumerički",'sort' => "Sortiraj",'name' => "Naziv",'last_added' => "Poslednje dodato",diff --git a/includes/i18n/tr.php b/includes/i18n/tr.phpindex 959ec79..d3ec94e 100644--- a/includes/i18n/tr.php+++ b/includes/i18n/tr.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "Yeni Abonelik",'search' => "Ara",'state' => "Durum",+ 'alphanumeric' => "Alfanümerik",'sort' => "Sırala",'name' => "İsim",'last_added' => "Son Eklenen",diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.phpindex e3bd8ac..3acae3a 100644--- a/includes/i18n/zh_cn.php+++ b/includes/i18n/zh_cn.php@@ -45,6 +45,7 @@ $i18n = ['new_subscription' => "新订阅",'search' => "搜索",'state' => "状态",+ 'alphanumeric' => "名称",'sort' => "排序",'name' => "名称",'last_added' => "创建时间",diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.phpindex 9a88dfe..014c815 100644--- a/includes/i18n/zh_tw.php+++ b/includes/i18n/zh_tw.php@@ -41,6 +41,7 @@ $i18n = ['new_subscription' => "新訂閱",'search' => "搜尋",'state' => "狀態",+ 'alphanumeric' => "字母數字",'sort' => "排序",'name' => "名稱",'last_added' => "建立時間",diff --git a/includes/version.php b/includes/version.phpindex 7f8a24f..9c7e859 100644--- a/includes/version.php+++ b/includes/version.php@@ -1,3 +1,3 @@<?php-$version = "v2.18.0";+$version = "v2.19.0";?>\ No newline at end of filediff --git a/index.php b/index.phpindex 1948e78..f3fb68d 100644--- a/index.php+++ b/index.php@@ -8,17 +8,21 @@ $sort = "next_payment";$sql = "SELECT * FROM subscriptions WHERE user_id = :userId ORDER BY next_payment ASC, 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'];+ $sortOrder = $sort;+ $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive', 'alphanumeric'];$order = "ASC";if ($sort == "price" || $sort == "id") {$order = "DESC";}+ if ($sort == "alphanumeric") {+ $sort = "name";+ }if (!in_array($sort, $allowedSortCriteria)) {$sort = "next_payment";}$sql = "SELECT * FROM subscriptions WHERE user_id = :userId";- $sql .= " ORDER BY $sort $order";+ $sql .= " ORDER BY LOWER($sort) $order";if ($sort != "next_payment") {$sql .= ", next_payment ASC";}@@ -165,32 +169,33 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden</button><div class="sort-options" id="sort-options"><ul>- <li <?= $sort == "name" ? 'class="selected"' : "" ?> onClick="setSortOption('name')" id="sort-name">+ <li <?= $sortOrder == "name" ? 'class="selected"' : "" ?> onClick="setSortOption('name')" id="sort-name"><?= translate('name', $i18n) ?></li>- <li <?= $sort == "id" ? 'class="selected"' : "" ?> onClick="setSortOption('id')" id="sort-id">+ <li <?= $sortOrder == "id" ? 'class="selected"' : "" ?> onClick="setSortOption('id')" id="sort-id"><?= translate('last_added', $i18n) ?></li>- <li <?= $sort == "price" ? 'class="selected"' : "" ?> onClick="setSortOption('price')" id="sort-price">+ <li <?= $sortOrder == "price" ? 'class="selected"' : "" ?> onClick="setSortOption('price')" id="sort-price"><?= translate('price', $i18n) ?></li>- <li <?= $sort == "next_payment" ? 'class="selected"' : "" ?> onClick="setSortOption('next_payment')"+ <li <?= $sortOrder == "next_payment" ? 'class="selected"' : "" ?> onClick="setSortOption('next_payment')"id="sort-next_payment"><?= translate('next_payment', $i18n) ?></li>- <li <?= $sort == "payer_user_id" ? 'class="selected"' : "" ?> onClick="setSortOption('payer_user_id')"+ <li <?= $sortOrder == "payer_user_id" ? 'class="selected"' : "" ?> onClick="setSortOption('payer_user_id')"id="sort-payer_user_id"><?= translate('member', $i18n) ?></li>- <li <?= $sort == "category_id" ? 'class="selected"' : "" ?> onClick="setSortOption('category_id')"+ <li <?= $sortOrder == "category_id" ? 'class="selected"' : "" ?> onClick="setSortOption('category_id')"id="sort-category_id"><?= translate('category', $i18n) ?></li>- <li <?= $sort == "payment_method_id" ? 'class="selected"' : "" ?> onClick="setSortOption('payment_method_id')"+ <li <?= $sortOrder == "payment_method_id" ? 'class="selected"' : "" ?> onClick="setSortOption('payment_method_id')"id="sort-payment_method_id"><?= translate('payment_method', $i18n) ?></li><?phpif (!isset($settings['hideDisabledSubscriptions']) || $settings['hideDisabledSubscriptions'] !== 'true') {?>- <li <?= $sort == "inactive" ? 'class="selected"' : "" ?> onClick="setSortOption('inactive')"+ <li <?= $sortOrder == "inactive" ? 'class="selected"' : "" ?> onClick="setSortOption('inactive')"id="sort-inactive"><?= translate('state', $i18n) ?></li><?php}?>-+ <li <?= $sortOrder == "alphanumeric" ? 'class="selected"' : "" ?> onClick="setSortOption('alphanumeric')"+ id="sort-alphanumeric"><?= translate('alphanumeric', $i18n) ?></li></ul></div></div>@@ -233,6 +238,12 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden}}+ if ($sortOrder == "alphanumeric") {+ usort($print, function ($a, $b) {+ return strnatcmp(strtolower($a['name']), strtolower($b['name']));+ });+ }+if (isset($print)) {printSubscriptions($print, $sort, $categories, $members, $i18n, $colorTheme, "");}