diff --git a/a.out b/a.out deleted file mode 100644 index e69de29bb..000000000 diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php index b6240fe4c..141335e9f 100644 --- a/endpoints/subscriptions/get.php +++ b/endpoints/subscriptions/get.php @@ -24,10 +24,14 @@ $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 @@ $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 ($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.php index 817bea736..27ea997c2 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -41,6 +41,7 @@ '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.php index abd018cf9..4a8218b65 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -41,6 +41,7 @@ 'new_subscription' => "Νέα συνδρομή", 'search' => "Αναζήτηση", 'state' => "Κατάσταση", + 'alphanumeric' => "Αλφαριθμητική", 'sort' => "Ταξινόμηση", 'name' => "Όνομα", 'last_added' => "Τελευταία προσθήκη", diff --git a/includes/i18n/en.php b/includes/i18n/en.php index c29a2f8e4..de5a754e8 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -41,6 +41,7 @@ '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.php index 558fef803..a86803095 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -41,6 +41,7 @@ '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.php index 99fcf0a80..c691f9c34 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -41,6 +41,7 @@ '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.php index bc3f20616..06979ed20 100644 --- a/includes/i18n/it.php +++ b/includes/i18n/it.php @@ -45,6 +45,7 @@ '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.php index 3aad65fc4..b55c9dfe1 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -41,6 +41,7 @@ 'new_subscription' => "新しい定期購入", 'search' => "検索", 'state' => "状態", + 'alphanumeric' => "アルファベット順", 'sort' => "並べ替え", 'name' => "名前", 'last_added' => "最終追加日", diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php index 36764c21c..a73db4a7b 100644 --- a/includes/i18n/ko.php +++ b/includes/i18n/ko.php @@ -41,6 +41,7 @@ 'new_subscription' => "새 구독", 'search' => "검색", 'state' => "상태", + 'alphanumeric' => "알파벳순", 'sort' => "정렬", 'name' => "이름", 'last_added' => "최근 등록", diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php index 57ebfb297..8fbe1568e 100644 --- a/includes/i18n/pl.php +++ b/includes/i18n/pl.php @@ -41,6 +41,7 @@ '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.php index 1074cb359..048e9f4c3 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -41,6 +41,7 @@ '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.php index 6bcd5e648..bc6d9ef8f 100644 --- a/includes/i18n/pt_br.php +++ b/includes/i18n/pt_br.php @@ -41,6 +41,7 @@ '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.php index 99a7e61ee..b8615f771 100644 --- a/includes/i18n/ru.php +++ b/includes/i18n/ru.php @@ -41,6 +41,7 @@ 'new_subscription' => "Новая подписка", 'search' => "Поиск", 'state' => "Состояние", + 'alphanumeric' => "Алфавитный порядок", 'sort' => "Сортировка", 'name' => "Имя", 'last_added' => "Дата создания", diff --git a/includes/i18n/sl.php b/includes/i18n/sl.php index 6989cff87..e14a0a703 100644 --- a/includes/i18n/sl.php +++ b/includes/i18n/sl.php @@ -41,6 +41,7 @@ '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.php index c051a8987..4f2d4df14 100644 --- a/includes/i18n/sr.php +++ b/includes/i18n/sr.php @@ -41,6 +41,7 @@ 'new_subscription' => "Нова претплата", 'search' => "Претрага", 'state' => "Статус", + 'alphanumeric' => "Алфанумерички", 'sort' => "Сортирај", 'name' => "Назив", 'last_added' => "Последње додато", diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php index 0ec72440f..3a17c2b34 100644 --- a/includes/i18n/sr_lat.php +++ b/includes/i18n/sr_lat.php @@ -41,6 +41,7 @@ '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.php index 959ec790d..d3ec94e24 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -41,6 +41,7 @@ '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.php index e3bd8ac94..3acae3ad3 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -45,6 +45,7 @@ 'new_subscription' => "新订阅", 'search' => "搜索", 'state' => "状态", + 'alphanumeric' => "名称", 'sort' => "排序", 'name' => "名称", 'last_added' => "创建时间", diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php index 9a88dfef9..014c815c0 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -41,6 +41,7 @@ 'new_subscription' => "新訂閱", 'search' => "搜尋", 'state' => "狀態", + 'alphanumeric' => "字母數字", 'sort' => "排序", 'name' => "名稱", 'last_added' => "建立時間", diff --git a/includes/version.php b/includes/version.php index 7f8a24fb4..9c7e85925 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/index.php b/index.php index 1948e7864..f3fb68d39 100644 --- a/index.php +++ b/index.php @@ -8,17 +8,21 @@ $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 @@
@@ -233,6 +238,12 @@ } } + 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, ""); }