X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=cards%2Flist.sh;h=2f2e767a9dad082aed283da405e01c1eda6bf8fb;hp=421ff3a4a51d3eaef3577a36e9eb7f1c82ba73b7;hb=HEAD;hpb=8e0acb145101c4cb570e5c8bfb9ffe18a9b393a0 diff --git a/cards/list.sh b/cards/list.sh index 421ff3a..e12d760 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -13,7 +13,7 @@ edit_card(){ else card="$(pdi_load "$tempfile")" cat <<-EOF - [form .card #${cardfile##*/} action="/cards/update_card.sh" method="POST" + [form .card #${cardfile##*/} action="${_BASE}/cards/update_card.sh" method="POST" [input type="hidden" name="tid" value="$(transid ${tempfile})"] [div .section .basic $( edit_item "$card" N GENDER @@ -31,28 +31,33 @@ edit_card(){ [ $(pdi_count "$card" IMPP) -gt 0 ] && edit_item "$card" IMPP [ $(pdi_count "$card" URL ) -gt 0 ] && edit_item "$card" URL )] - [div .section .address $(edit_item "$card" ADR)] + [div .section .address $( + edit_item "$card" ADR + [ $(pdi_count "$card" X-IBAN) -gt 0 ] && edit_item "$card" X-IBAN + )] [div .section .note $(edit_item "$card" NOTE)] [div .section .attendance - [h3 $(l10n course_attendance) ] $( - for course in "$_DATA"/ical/*.ics; do - printf '[label [input type="checkbox" name="attendance" value="%s" %s] %s]' \ - "${course##*/}" \ - "$(grep -qF "${course##*/} ${cardfile##*/}" "$_DATA/mappings/attendance" \ + [h3 $(l10n course_attendance) ] [div .attendance $( + list_courses |while IFS=/ read course coursename; do + courseH="$(HTML "$course")" + printf '[input type="checkbox" id="cour%s" name="attendance" value="%s" %s][label for="cour%s" . %s]' \ + "$courseH" "$courseH" \ + "$(grep -qF "${course} ${cardfile##*/}" "$_DATA/mappings/attendance" \ && printf 'checked="checked"' )" \ - "$(pdi_value "$(pdi_load "$course")" SUMMARY || l10n "(unnamed course)" |unescape |HTML)" - done) - [h3 $(l10n CATEGORIES) ] $( + "$courseH" "$coursename" + done)] + [h3 $(l10n CATEGORIES) ] [div .categories $( grep -xE '[^ ]+' "$_DATA"/mappings/categories |while read -r cat; do - printf '[label [input type="checkbox" name="CATEGORIES" value="%s" %s] %s]' \ - "$(HTML "$cat")" \ + catH="$(HTML "$cat")" + printf '[input type="checkbox" id="cat%s" name="CATEGORIES" value="%s" %s][label for="cat%s" . %s]' \ + "$catH" "$catH" \ "$(seq 1 $(pdi_count "$card" CATEGORIES) |while read c; do pdi_value "$card" CATEGORIES $c |grep -qxF "$cat" \ && printf 'checked="checked"' && break done)" \ - "$(HTML "$cat")" - done) + "$catH" "$catH" + done)] ] [div .control [div .item .delete label="$(l10n edit_delete)" @@ -63,7 +68,7 @@ edit_card(){ [div .item .newfield [select name="newfield" [option value="" disabled="disabled" selected="selected" $(l10n edit_addfieldtext)] - $(for f in NICKNAME EMAIL TEL IMPP ADR URL NOTE; do + $(for f in NICKNAME EMAIL TEL IMPP ADR URL NOTE X-ZACK-LEAVEDATE X-IBAN; do printf '[option value="%s" %s] ' "$f" "$(l10n "$f")" done) ][button type="submit" name="action" value="addfield" $(l10n edit_addfield)] @@ -88,19 +93,20 @@ print_card(){ )] [div .section .phone . $(card_item "$card" TEL)] [div .section .message . $(card_item "$card" EMAIL IMPP URL)] - [div .section .address . $(card_item "$card" ADR)] + [div .section .address . $(card_item "$card" ADR X-IBAN)] [div .section .note . $(card_item "$card" NOTE)] [div .section .attendance [h3 $(l10n course_attendance) ] [ul $(grep -F " ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do - printf '[li [a .item .attendance href="/courses#%s" . %s]]' \ - "$each" \ + printf '[li [a .item .attendance href="%s/courses#%s" . %s]]' \ + "${_BASE}" "$each" \ "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)" |unescape |HTML)" - done)] + done |sort -k7)] $(card_item "$card" CATEGORIES) ] [div .control - [a .item href="/cards/edit_card.sh?card=${cardfile##*/}" $(l10n edit)] - [a .item href="/cards/export_card.sh?card=${cardfile##*/}" $(l10n vcf_export)] + [a .button .item href="${_BASE}/ledgers/account.sh?card=${cardfile##*/}" $(l10n ledger)] + [a .button .item href="${_BASE}/cards/edit_card.sh?card=${cardfile##*/}" $(l10n edit)] + [a .button .item href="${_BASE}/cards/export_card.sh?card=${cardfile##*/}" $(l10n vcf_export)] ] ] EOF @@ -111,21 +117,45 @@ print_cards(){ while read cardfile; do cachefile="${_DATA}/cache/${cardfile##*/}.cache" - # if [ -s "$cachefile" -a "$cachefile" -nt "$cardfile" \ - # -a "$cachefile" -nt "${_EXEC}/cards" ]; then if [ -s "$cachefile" -a "$cachefile" -nt "$cardfile" ]; then cat "$cachefile" - else + elif [ -s "$cardfile" ]; then print_card "$cardfile" |tee "$cachefile" fi done } +filter_attendance(){ + fatt="$1" + attfile="$_DATA/mappings/attendance" + + if [ ! "$fatt" ]; then + # debug 'list all' + printf '%s\n' "$_DATA/vcard"/*.vcf + elif [ "${fatt#* }" = "${fatt}" ]; then + # debug "list $fatt" + grep -xiE "(${fatt}) .+vcf" "$attfile" \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + else + # debug "filter ${fatt%% *}" + filter_attendance "${fatt#* }" \ + | while read vcf; do + grep -xiE "(${fatt%% *}) ${vcf##*/}" "$attfile" + done \ + | while read vcf; do + printf '%s/vcard/%s\n' "$_DATA" "${vcf##* }" + done + fi +} + filter_cards(){ local filter f fex='x;p;' + local upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; ' filter="$(printf %s "${filter}" \ - | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\\\&;g; + | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\&;g; '"$upcase" )^" @@ -134,6 +164,8 @@ filter_cards(){ case $f in '') break ;; + COURSE:*) fatt="${fatt}${fatt:+ }${f#*:}" + ;; ANY:*) fex="/\n.*(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" ;; NAME:*) fex="/\n(N|FN|NICKNAME)(\;[^:]*)?:[^\n]*(${f#*:})[^\n]*\r?\n/{${fex}}" @@ -145,11 +177,12 @@ filter_cards(){ esac done - for cardfile in "${_DATA}"/vcard/*.vcf; do + # for cardfile in "${_DATA}"/vcard/*.vcf; do + filter_attendance "$fatt" |while read cardfile; do printf '%s\n' "$cardfile" cat "$cardfile" done \ - | sed -En ':X; /\nEND:VCARD\r?$/!{ N; bX; }; h; s;\n.*$;;; x; s;^[^\n]+\n;;; + | sed -nE ':X; /\nEND\;?:VCARD\r?$/!{ N; bX; }; h; s;\n.*$;;; x; s;^[^\n]+\n;;; '"$upcase""$fex" }