]> git.plutz.net Git - confetti/blob - categories/index.cgi
Merge commit 'c0dcd45c3ecac33376e06b7ca470ae56f2ed5e19' into cgilite
[confetti] / categories / index.cgi
1 #!/bin/sh
2 # Copyright 2015, 2017, 2018, 2021 Paul Hänsch
3 #
4 # This file is part of Confetti.
5
6 # Confetti is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # Confetti is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
18
19 . $_EXEC/pdiread.sh
20 . $_EXEC/categories/l10n.sh
21
22 catfile="${_DATA}/mappings/categories"
23
24 list_categories() {
25   grep -vxE '[   ]*' "$catfile" |sort -u
26 }
27
28 list_catsel(){
29   local vcf="$1" card="$2" n=1 cats="${BR}"
30   while cats="${cats}${BR}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n + 1)); done
31
32   list_categories |while read cat; do
33     printf '[li [label [input %s type="checkbox" name="%s" value="%s"] %s]]' \
34            "$([ "${cats%*${BR}${cat}${BR}*}" != "$cats" ] && printf checked=checked)" \
35            "$(HTML "$card")" "$(HTML "$cat")" "$(HTML "$cat")" 
36   done
37 }
38
39 cat <<EOF |yield_page categories
40 [form .categories action="edit_categories.sh" method="POST"
41   [h1 $(l10n categories_label)]
42   [input type="hidden" name="page" value="categories"]
43   [ul
44     $(list_categories | while read cat; do
45       printf '[li . %s [button type="submit" name="remove" value="%s" . %s]]\n' \
46              "$(HTML "$cat")" "$(HTML "$cat")" "$(l10n cat_remove)"
47     done)
48     [li
49       [input type="text" name="newcat" placeholder="$(l10n cat_newlabel)"]
50       [button type="submit" name="add" value="add" . $(l10n cat_add)]
51     ]
52   ]
53 ]
54
55 [form .namelist action="update_categories.sh" method="POST"
56   [fieldset
57     [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
58   ]
59   [ul .namelist
60   $(for vcffile in "$_DATA"/vcard/*vcf; do
61     vcf="$(pdi_load "$vcffile")"
62     printf '    [li [h2 . %s][ul ' "$(pdi_value "$vcf" FN)"
63     list_catsel "$vcf" "${vcffile##*/}"
64     printf ']]\n'
65   done |sort)
66   ]
67   [fieldset
68     [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
69   ]
70 ]
71 EOF