+++ /dev/null
-/*
-# Copyright 2014, 2015, 2018 Paul Hänsch
-#
-# This file is part of Confetti.
-#
-# Confetti is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Confetti is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-form.categories {
- display: block;
- border: solid 1px;
- border-radius: 4px 4px 0 0;
- margin: .5em 2em .25em 2em;
- padding: 0 2ex .5em 2ex;
- background: #EFF;
-}
-
-form.categories h1 {
- display: block;
- font-weight: bold;
- font-size: 1.25em;
- border-style: none none solid none;
- border-radius: 4px 4px 0 0;
- border-width: 1px;
- margin: 0 -1.625ex .5em -1.625ex;
- padding: .125em 1ex;
- background: #EEF;
-}
-
-form.categories ul { margin: 0; padding: 0; }
-form.categories ul li {
- display: inline-block;
- margin: 0 .25ex;
- padding: .125em .25ex .125em 1ex;
- border: 1px solid black;
- background-color: #EEF;
-}
-form.categories ul li button {
- margin: 0 0 0 1ex;
- background-color: #FCC;
- border: 1px solid black;
- min-width: 3ex;
- text-align: center;
-}
-form.categories ul li:last-of-type { padding: .125em .25ex .125em .25ex; }
-form.categories ul li:last-of-type button { background-color: #FFF; }
-
-form.namelist {
- display: block;
- margin: 1em 2em;
- padding: 0;
-}
-form.namelist > fieldset {
- display: block;
- border: solid 1px;
- border-radius: 4px 4px 0 0;
- margin: 0; padding: .25em 2ex;
- background: #EFF;
- text-align: right;
-}
-form.namelist > fieldset:last-of-type {
- border-radius: 0 0 4px 4px;
-}
-ul.namelist { margin: 0; padding: 0;}
-ul.namelist > li {
- display: block;
- border: solid 1px;
- margin: -1px 0;
- background: #FFF;
-}
-ul.namelist > li:nth-of-type(2n){ background: #EEE;}
-
-ul.namelist h2 {
- font-size: 1em;
- display: inline-block;
- margin: 0;
- padding: 0 1ex;
- min-width: 30ex;
-}
-ul.namelist ul { margin: 0; padding: 0; display: inline-block;}
-ul.namelist ul li {
- display: inline-block;
- margin: 0 1ex 0 0;
-}
-
-.fakeorder {
- position: absolute;
- width: 0; height: 0;
- left: -100%;
-}
+++ /dev/null
-# Copyright 2015, 2017, 2018 Paul Hänsch
-#
-# This file is part of Confetti.
-#
-# Confetti is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Confetti is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-
-cat_listing(){
- list_categories | while read cat; do
- printf '<li>%s<button type="submit" name="remove" value="%s">%s</button></li>\n' \
- "$(htmlsafe "$cat")" "$(attribsafe "$cat")" "$(l10n cat_remove)"
- done
-}
-
-list_catsel(){
- card="$1"
- cats="$(get_categories "$card")"
-
- list_categories |while read cat; do
- printf '<li><label><input %s type="checkbox" name="%s" value="%s">%s</label></li>' \
- "$(printf %s "$cats" |grep -qF "$cat" && printf 'checked="checked"')" \
- "$(attribsafe "$card")" "$(attribsafe "$cat")" "$(htmlsafe "$cat")"
- done
-}
-
-display_catsel(){
- card="$1"
- printf '<li><h2>%s</h2><ul>' "$(htmlsafe "$(get_name "$card")")"
- list_catsel "$card"
- printf '</ul></li>'
-}
-
-cat <<EOF
-<form class="categories" action="?action=edit_categories" method="POST">
- <input type="submit" class="fakeorder" name="add" value="add" />
- <h1>$(l10n categories_label)</h1>
- <input type="hidden" name="page" value="categories"/>
- <ul>
- $(cat_listing)
- <li>
- <input type="text" name="newcat" placeholder="$(l10n cat_newlabel)">
- <button type="submit" name="add" value="add">$(l10n cat_add)</button>
- </li>
- </ul>
-</form>
-
-<form class="namelist" action="?action=update_categories" method="POST">
- <fieldset>
- <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
- </fieldset>
- <ul class="namelist">
-EOF
-listcards \
-| while read card; do
- display_catsel "$card"
-done
-cat <<EOF
- </ul>
- <fieldset>
- <button type="submit" name="submit" value="submit">$(l10n cat_update)</button>
- </fieldset>
-</form>
-EOF
-
+++ /dev/null
-#!/bin/zsh
-
-# Copyright 2015, 2017 Paul Hänsch
-#
-# This file is part of Confetti.
-#
-# Confetti is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Confetti is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-
-catfile="${_DATA}/mappings/categories"
-
-listcards() {
- for file in "${_DATA}/vcard/"*.vcf; do
- printf '%s\t%s\n' \
- "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" \
- "$file"
- done \
- | sort \
- | sed -r 's;^.*\t(.*/)([^/]+)$;\2;'
-}
-
-get_name() {
- cfile="${_DATA}/vcard/$1"
- sed -rn 's;^N(\;[^":]+|\;"[^"]+")*:([^\;]*)(\;[^\;]*)(\;[^\;]*)?(\;[^\;]*)?(\;[^\;]*)?\r?$;\5 \3 \4 \2 \6;;
- tX; b; :X s;[,\; ]+; ;g; p;' "$cfile"
-}
-
-get_categories(){
- cfile="${_DATA}/vcard/$1"
- sed -rn 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:(.+)\r?$;\2;;
- tX; b; :X
- s;(^|[^\\]+)((\\\\)+),;\1\2\n;g;
- s;(^|[^\\]),;\1\n;g; s;(^|[^\\]+)((\\\\)+),;\1\2\n;g;
- s;(^|[^\\]),;\1\n;g; s;\\,;,;g; p;' "$cfile" \
- | sort -u
-}
-
-list_categories() {
- sort -u "$catfile" \
- | sed -r '/^[\t ]*$/d'
-}
"$(printf %s "$cat" |grep -qxEe "$2" && printf checked )" \
"$(HTML "$cat")"
done)
- [a href="/cards/categories.sh" $(l10n edit_categories)]
+ [a href="/categories/" $(l10n edit_categories)]
]
]
EOF
catfile="${_DATA}/mappings/categories"
-remove="${_POST[remove]}"
-newcat="${_POST[newcat]}"
+remove="$(POST remove)"
+newcat="$(POST newcat)"
-if [ "${_POST[add]}" = "add" ]; then
+if [ "$(POST add)" = "add" ]; then
printf %s\\n "$newcat" >>"$catfile"
-elif [ -n "$remove" ]; then
- sed -ri '/^'"${remove}"'$/d' $catfile
+elif [ "$remove" ]; then
+ sed -Ei '/^'"${remove}"'$/d' "$catfile"
fi
-redirect "?p=categories"
+REDIRECT "/categories/"
--- /dev/null
+#!/bin/sh
+# Copyright 2015, 2017, 2018, 2021 Paul Hänsch
+#
+# This file is part of Confetti.
+#
+# Confetti is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Confetti is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
+
+. $_EXEC/pdiread.sh
+. $_EXEC/categories/l10n.sh
+
+catfile="${_DATA}/mappings/categories"
+
+list_categories() {
+ grep -vxE '[ ]*' "$catfile" |sort -u
+}
+
+list_catsel(){
+ local vcf="$1" card="$2" n=1 cats="${BR}"
+ while cats="${cats}${BR}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n + 1)); done
+
+ list_categories |while read cat; do
+ printf '[li [label [input %s type="checkbox" name="%s" value="%s"] %s]]' \
+ "$([ "${cats%*${BR}${cat}${BR}*}" != "$cats" ] && printf checked=checked)" \
+ "$(HTML "$card")" "$(HTML "$cat")" "$(HTML "$cat")"
+ done
+}
+
+cat <<EOF |yield_page categories
+[form .categories action="edit_categories.sh" method="POST"
+ [h1 $(l10n categories_label)]
+ [input type="hidden" name="page" value="categories"]
+ [ul
+ $(list_categories | while read cat; do
+ printf '[li . %s [button type="submit" name="remove" value="%s" . %s]]\n' \
+ "$(HTML "$cat")" "$(HTML "$cat")" "$(l10n cat_remove)"
+ done)
+ [li
+ [input type="text" name="newcat" placeholder="$(l10n cat_newlabel)"]
+ [button type="submit" name="add" value="add" . $(l10n cat_add)]
+ ]
+ ]
+]
+
+[form .namelist action="update_categories.sh" method="POST"
+ [fieldset
+ [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
+ ]
+ [ul .namelist
+ $(for vcffile in "$_DATA"/vcard/*vcf; do
+ vcf="$(pdi_load "$vcffile")"
+ printf ' [li [h2 . %s][ul ' "$(pdi_value "$vcf" FN)"
+ list_catsel "$vcf" "${vcffile##*/}"
+ printf ']]\n'
+ done |sort)
+ ]
+ [fieldset
+ [button type="submit" name="submit" value="submit" . $(l10n cat_update)]
+ ]
+]
+EOF
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014, 2015, 2016, 2019, 2021 Paul Hänsch
#
# This file is part of Confetti.
#
# You should have received a copy of the GNU Affero General Public License
# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-item_name[cat_remove]="-"
-item_name[cat_add]="+"
-item_name[cat_newlabel]="neue Kategorie"
-item_name[cat_update]="Zuweisungen übernehmen"
-item_name[categories_label]="Kategorien"
+l10n(){
+ local word
+ [ $# -eq 0 ] && read -r word || word="$*"
+ case $word in
+ cat_remove) printf %s "-";;
+ cat_add) printf %s "+";;
+ cat_newlabel) printf %s "neue Kategorie";;
+ cat_update) printf %s "Zuweisungen übernehmen";;
+ categories_label) printf %s "Kategorien";;
+
+ *) l10n_global "$word";;
+ esac
+}
-#!/bin/zsh
+#!/bin/sh
-# Copyright 2016 Paul Hänsch
+# Copyright 2016, 2021 Paul Hänsch
#
# This file is part of Confetti.
#
# You should have received a copy of the GNU Affero General Public License
# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-. "$_EXEC"/pages/categories.sh
+. "$_EXEC"/cgilite/storage.sh
+. "$_EXEC"/pdiread.sh
catfile="${_DATA}/mappings/categories"
-set_categories(){
- card="${_DATA}/vcard/$1"
- cats="$2"
- cardcats="$(sed -nr 's;^CATEGORIES(\;[^":]+|\;"[^"]+")*:([^\r]+)\r?$;\2;p' "$card")"
+for card in "${_DATA}"/vcard/*.vcf; do
+ n='' postcats='' cardcats=''
+ vcf="$(pdi_load "$card")"
- debug "CARD: $card"
- debug "CATS: $cardcats"
- debug "NEW: $cats"
- if [ "$cats" != "$cardcats" ]; then
+ n=1; while postcats="${postcats}${postcats:+,}$(POST "${card##*/}" $n)"; do n=$((n+1)); done
+ n=1; while cardcats="${cardcats}${cardcats:+,}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n+1)); done
+
+ if [ "${postcats}" != "${cardcats}" ] && LOCK "$card"; then
sed -ri '
/^CATEGORIES[;:]/d
- /^END:VCARD *\r?$/iCATEGORIES:'"$cats"'\r
+ /^END;?:VCARD *\r?$/iCATEGORIES:'"${postcats%,}"'\r
' "${card}"
+ RELEASE "$card"
fi
-}
-
-listcards |while read card; do
- cardcats=''
- for n in "$card" "$card"{0..100}; do
- if [ -z "${_POST[$n]}" ]; then
- set_categories "$card" "$cardcats"
- break
- fi
- cardcats="${cardcats}${cardcats:+,}${_POST[$n]}"
- done
done
-redirect "?p=categories"
+REDIRECT /categories/
* {
position: relative;
box-sizing: border-box;
+ max-width: 100%;
font-family: sans-serif;
font-weight: normal;
font-size: initial;
/* =========== FILTER AND SEARCH Headers ========= */
+form.categories,
form.search, form.sort, form.filter, form.newcard, form.newcourses {
margin-top: 1em; padding: 0 1em;
z-index: 1;
background-color: #EEE;
border-style: solid;
border-width: .5pt .25pt 0 .25pt;
+ white-space: normal;
}
form.filter fieldset.item input[type=radio] + label:first-of-type {
border-left: 1pt solid;
margin-bottom: 0;
}
form.course .attendance input { margin-top: .375em; }
+
+/* ======== Categories Page ======== */
+
+body.categories form ul { list-style: none; margin: 0; }
+
+form.categories li {
+ display: inline-block;
+ background-color: #EEE;
+ margin-right: .5em; margin-bottom: .5em;
+ padding-left: .5em;
+ box-shadow: .125em .125em .25em;
+}
+form.categories li button[name=remove] {
+ font-size: .75em;
+ width: 2.5em;
+ background-color: #FBB;
+ overflow: hidden;
+ white-space: pre;
+}
+form.categories li button[name=remove]:before {
+ content: '\274C ';
+ margin-right: 3em;
+}
+
+form.categories li:last-child { padding-left: 0 }
+
+body.categories form.namelist ul.namelist > li:nth-of-type(2n + 1) { background-color: #EEE; }
+body.categories form.namelist ul.namelist > li h2,
+body.categories form.namelist ul.namelist > li ul {
+ display: inline-block;
+}
+body.categories form.namelist ul.namelist > li h2 {
+ width: 20%;
+ min-width: 10em;
+}
+body.categories form.namelist ul.namelist > li ul li {
+ display: inline-block;
+}