]> git.plutz.net Git - confetti/commitdiff
separate pages in ledger section, stubs for account page
authorPaul Hänsch <paul@plutz.net>
Mon, 13 May 2024 21:19:41 +0000 (23:19 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 13 May 2024 21:19:41 +0000 (23:19 +0200)
ledgers/account.sh [new file with mode: 0755]
ledgers/iban_assign.sh
ledgers/index.cgi
ledgers/set_iban.sh [new file with mode: 0755]

diff --git a/ledgers/account.sh b/ledgers/account.sh
new file mode 100755 (executable)
index 0000000..2cc279b
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+if [ "$REQUEST_METHOD" = POST ]; then
+  uid="$(POST uid)"
+  cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)"
+  REDIRECT "${_BASE}/ledgers/account.sh?card=${cfile##*/}"
+fi
+
+. "${_EXEC}/pdiread.sh"
+. "${_EXEC}/cards/l10n.sh"
+. "${_EXEC}/cards/widgets.sh"
+
+cardfile="${_DATA}/vcard/$(GET card |PATH)"
+if [ ! -f "$cardfile" ]; then
+  SET_COOKIE 0 message="Invalid account: $cardfile"
+  REDIRECT "${_BASE}/ledgers/"
+fi
+
+{
+  card="$(pdi_load "$cardfile")"
+  cat <<-EOF
+       [div .card #${cardfile##*/}
+         [div .section .basic . $(
+           card_item "$card" FN GENDER NICKNAME BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE SOUND PHOTO LOGO
+         )]
+         [div .section .phone   . $(card_item "$card" TEL)]
+         [div .section .message . $(card_item "$card" EMAIL IMPP URL)]
+         [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="%s/courses#%s" . %s]]' \
+                    "${_BASE}" "$each" \
+                    "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)" |unescape |HTML)"
+           done |sort -k7)]
+           $(card_item "$card" CATEGORIES)
+         ]
+       ]
+       EOF
+} \
+| yield_page ledgers
index 8d9ae99d0ec52585965f64baa7b679b2d0af2c42..778d279aebe83152f08bc33b80296189b1677a18 100755 (executable)
@@ -1,51 +1,81 @@
 #!/bin/sh
 
-. "$_EXEC/pdiread.sh"
-. "$_EXEC/session_lock.sh"
+credit() {
+  printf '%03i\n' "$1" \
+  | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
+}
 
-UIDLIST="$(
-  pdi_load "$_DATA/vcard/"*.vcf \
-  | sed -Ez '
-    s/\nBEGIN;:VCARD\n([^\n]+\n)*FN;:([^\n]+)\n([^\n]+\n)*UID;:([^\n]+)\n([^\n]+\n)*END;:VCARD\n/UID:\4 FN:\2/g
-  '
-  echo
-)"
-
-# printf '%s\r\n' "Content-Type: text/plain" ""
-
-for key in $(POST_KEYS); do case $key in
-  use_*)
-    use_iban="${use_iban} ${key#use_} "
-    ;;
-esac; done
-
-[ "$use_iban" ] && for key in $(POST_KEYS); do case $key in
-  check_*_*)
-    iban="${key#check_}" iban="${iban%_*}"
-    [ ! "${use_iban##* "${iban}" *}" ] && check="${check} ${key#check_} "
-    ;;
-esac; done
-
-{ printf '[ul .results'
-  for use in $check; do
-    iban="${use%_*}"
-    fn="$(POST "fn_${use}")"
-    uid="${UIDLIST%% FN:"$fn"${BR}*}" uid="${uid##*${BR}UID:}"
-  
-    # cfile="${_DATA}/vcard/${uid}.vcf"
-    cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)"
-    if SLOCK "$cfile" >/dev/null; then
-      card="$(pdi_load "$cfile")"
-      cnum="$(pdi_count "$card" X-IBAN)"
-      pdi_update_value "$card" X-IBAN "$((cnum + 1))" "$iban" >"$cfile"
-      printf '[li .success . [span .name . %s] [span .uid . (UID: %s)] assigned IBAN [span .iban . %s]]' \
-             "$(HTML "$fn")" "$(HTML "$uid")" "$(HTML "$iban")"
-      RELEASE_SLOCK "$cfile"
-    else
-      printf '[li .error . [span .name . %s] [span .uid . (UID: %s)] is being edited elsewhere]'
-             "$(HTML "$fn")" "$(HTML "$uid")"
-    fi
+{ printf '
+  [h1 . %s]
+  [form .ibanassign action="%s/ledgers/set_iban.sh" method=POST
+    [input type=hidden name=session_id value="%s"]
+  ' "$(l10n "IBAN Assignments")" "${_BASE}" "$SESSION_ID"
+  printf '[datalist id=lattendants .'
+  pdi_load "${_DATA}"/vcard/*.vcf |sed -n '/^FN\;:/!b; s;^FN\;:;;; p;' \
+  | while read name; do
+    printf '[option value="%s"]' "$(HTML "$name")"
   done
   printf ']'
-  printf '[a .button href=/ledgers/ . %s]' "$(l10n Back)"
-} | yield_page ledgers_assign
+  l10n_attendant="$(l10n attendant)"
+  printf %s\\n "$IBAN_ASSIGN" \
+  | while read -r state iban data; do
+    iban="$(UNSTRING "$iban")"
+    [ ! "$iban" ] && iban="??????????"
+    printf '[input type=checkbox id="use_%s" name="use_%s" value=true]' "$iban" "$iban"
+    printf '[fieldset .iban .%s [legend . %s ]' \
+           "$state" "$iban"
+    if   [ $state = sure ]; then
+      for card in $data; do
+        uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
+        printf '[span .card . %s]' "$(HTML "${name}")"
+      done
+      :
+    elif [ $state = guess ]; then
+      record="$(UNSTRING "${data%%     *}")"
+      cards="${data#*  }"
+      date="${record%% *}"
+      principal="${record#*    *       *       }" principal="${principal%%     *}"
+      subject="${record#*      *       *       *       }" subject="${subject%% *}"
+      amount="${record#*       *       *       *       *       }" amount="${amount%%   *}"
+      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
+             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
+      n=0; for card in $cards; do
+        n=$((n+1)); uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$n" name="check_${iban}_$n" value=true checked=checked]
+         [input .card name="fn_${iban}_$n" value="$(HTML "$name")" .disabled tabindex="-1"]
+         [label .del for="check_${iban}_$n" . -]
+       EOF
+      done
+      for m in 1 2 3 4 5 6 7 8; do
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=true]
+         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
+         [label .add for="check_${iban}_$((n+m))" . +]
+       EOF
+      done
+      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
+      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
+    elif [ $state = unknown ]; then
+      date="${data%%   *}"
+      principal="${data#*      *       *       }" principal="${principal%%     *}"
+      subject="${data#*        *       *       *       }" subject="${subject%% *}"
+      amount="${data#* *       *       *       *       }" amount="${amount%%   *}"
+      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
+             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
+      printf '[input name="check_" type=hidden][input type=hidden][label .del]'
+      n=0; for m in 1 2 3 4 5 6 7 8; do
+        cat <<-EOF
+         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
+         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
+         [label .add for="check_${iban}_$((n+m))" . +]
+       EOF
+      done
+      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
+      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
+    fi
+  printf ']'
+  done
+  printf '[button type=submit . %s]' "$(l10n Submit Changes)"
+  printf '  ]'
+} | yield_page ledgers
index f2c2bf0d0da40d929e2befa2c32a12a2b3ee91fa..f5ac6b5b3c9a8f6f6a3d1128e34ccbe5e92fc259 100755 (executable)
@@ -3,11 +3,31 @@
 . "$_EXEC/cgilite/storage.sh"
 . "$_EXEC/pdiread.sh"
 
+if [ "$(POST show_account)" ]; then
+  uid="$(POST show_account)"
+  cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)"
+  REDIRECT "${_BASE}/ledgers/account.sh?card=${cfile##*/}"
+  exit 0;
+fi
+
 credit() {
   printf '%03i\n' "$1" \
   | sed -E 's;[0-9]{2}$;d&;; :0 s;([0-9])([0-9]{3}[dm]);\1m\2;; t0; y;dm;,.;'
 }
 
+IBAN_ASSIGN="$(
+  { pdi_load "${_DATA}"/vcard/*.vcf
+    printf 'BEGIN:LEDGERS\n'
+    cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
+  } | "${_EXEC}"/ledgers/iban_assign.awk
+  printf '\n'
+)"
+
+if [ "${PATH_INFO%/iban_assign/}" != "${PATH_INFO}" ]; then
+  . "${_EXEC}/ledgers/iban_assign.sh"
+  exit 0
+fi
+
 { printf '
   [form .upload action="%s/ledgers/csv_upload.sh" method="POST" enctype="multipart/form-data"
     [label for=ledger_upload . %s:]
@@ -28,80 +48,29 @@ credit() {
            "$(HTML "${ledger% - ????.tbl}")" "$(HTML "$ledger")" "$(l10n delete)"
   done
   printf '  ]'
-  printf '
-  [form .ibanassign action="%s/ledgers/iban_assign.sh" method=POST
-    [input type=hidden name=session_id value="%s"]
-    [h3 . %s]
-  ' "${_BASE}" "$SESSION_ID" "$(l10n "IBAN Assignments")"
-  printf '[datalist id=lattendants .'
-  pdi_load "${_DATA}"/vcard/*.vcf |sed -n '/^FN\;:/!b; s;^FN\;:;;; p;' \
-  | while read name; do
-    printf '[option value="%s"]' "$(HTML "$name")"
-  done
-  printf ']'
-  l10n_attendant="$(l10n attendant)"
-  { pdi_load "${_DATA}"/vcard/*.vcf
-    printf 'BEGIN:LEDGERS\n'
-    cat "${_DATA}"/ledgers/????-??-??\ -\ ????-??-??\ -\ ????.tbl
-  } | "${_EXEC}"/ledgers/iban_assign.awk \
-  | while read -r state iban data; do
-    iban="$(UNSTRING "$iban")"
-    [ ! "$iban" ] && iban="??????????"
-    printf '[input type=checkbox id="use_%s" name="use_%s" value=true]' "$iban" "$iban"
-    printf '[fieldset .iban .%s [legend . %s ]' \
-           "$state" "$iban"
-    if   [ $state = sure ]; then
-      for card in $data; do
-        uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
-        printf '[span .card . %s]' "$(HTML "${name}")"
-      done
-      :
-    elif [ $state = guess ]; then
-      record="$(UNSTRING "${data%%     *}")"
-      cards="${data#*  }"
-      date="${record%% *}"
-      principal="${record#*    *       *       }" principal="${principal%%     *}"
-      subject="${record#*      *       *       *       }" subject="${subject%% *}"
-      amount="${record#*       *       *       *       *       }" amount="${amount%%   *}"
-      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
-             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
-      n=0; for card in $cards; do
-        n=$((n+1)); uid="${card%%/*}" name="$(UNSTRING "${card#*/}")"
-        cat <<-EOF
-         [input type=checkbox id="check_${iban}_$n" name="check_${iban}_$n" value=true checked=checked]
-         [input .card name="fn_${iban}_$n" value="$(HTML "$name")" .disabled tabindex="-1"]
-         [label .del for="check_${iban}_$n" . -]
+  unassigned="$(printf %s\\n "$IBAN_ASSIGN" |grep -E '^guess|^unknown' |wc -l)"
+  cat <<-EOF
+       [div
+         [h1 . $(l10n IBAN Assignments)]
+         $(printf "$(l10n "%i IBANs are unassigned")" "$unassigned")
+         [a href="${_BASE}/ledgers/iban_assign/" . $(l10n Assign IBANs)]
+       ]
+       [form action="${_BASE}/ledgers/account.sh" method=POST
+         [select name=uid
+         $(printf %s\\n "$IBAN_ASSIGN" \
+           | sed -E '
+             /^sure    /!d;
+             s;^sure   [^\t]+;;;
+             s;([^\t]+)/([^\t]+);\1    \2\n;g;
+             s;\n$;;
+           ' \
+           | while read uid fn; do
+             uid="$(HTML "$uid")"
+             fn="$(UNSTRING "$fn" |HTML)"
+             printf '[option value="%s" . %s]' "$uid" "$fn"
+           done)
+         ]
+         [button type="submit" . $(l10n Account)]
+       ]
        EOF
-      done
-      for m in 1 2 3 4 5 6 7 8; do
-        cat <<-EOF
-         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=true]
-         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
-         [label .add for="check_${iban}_$((n+m))" . +]
-       EOF
-      done
-      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
-      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
-    elif [ $state = unknown ]; then
-      date="${data%%   *}"
-      principal="${data#*      *       *       }" principal="${principal%%     *}"
-      subject="${data#*        *       *       *       }" subject="${subject%% *}"
-      amount="${data#* *       *       *       *       }" amount="${amount%%   *}"
-      printf '[p .principal . %s][p .date %s][p .amount %s][p .subject . %s]' \
-             "$(UNSTRING "$principal" |HTML)" "$date" "$(credit "$amount")" "$(UNSTRING "$subject" |HTML)"
-      printf '[input name="check_" type=hidden][input type=hidden][label .del]'
-      n=0; for m in 1 2 3 4 5 6 7 8; do
-        cat <<-EOF
-         [input type=checkbox id="check_${iban}_$((n+m))" name="check_${iban}_$((n+m))" value=false]
-         [input .card name="fn_${iban}_$((n+m))" value="" placeholder="${l10n_attendant}" list="lattendants"]
-         [label .add for="check_${iban}_$((n+m))" . +]
-       EOF
-      done
-      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Accept Suggestions)"
-      printf '[label .button for="use_%s" . %s]' "$iban" "$(l10n Ignore Suggestions)"
-    fi
-  printf ']'
-  done
-  printf '[button type=submit . %s]' "$(l10n Submit Changes)"
-  printf '  ]'
 } | yield_page ledgers
diff --git a/ledgers/set_iban.sh b/ledgers/set_iban.sh
new file mode 100755 (executable)
index 0000000..08c9a3b
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+. "$_EXEC/pdiread.sh"
+. "$_EXEC/session_lock.sh"
+
+UIDLIST="$(
+  pdi_load "$_DATA/vcard/"*.vcf \
+  | sed -Ez '
+    s/\nBEGIN;:VCARD\n([^\n]+\n)*FN;:([^\n]+)\n([^\n]+\n)*UID;:([^\n]+)\n([^\n]+\n)*END;:VCARD\n/UID:\4 FN:\2/g
+  '
+  echo
+)"
+
+for key in $(POST_KEYS); do case $key in
+  use_*)
+    use_iban="${use_iban} ${key#use_} "
+    ;;
+esac; done
+
+[ "$use_iban" ] && for key in $(POST_KEYS); do case $key in
+  check_*_*)
+    iban="${key#check_}" iban="${iban%_*}"
+    [ ! "${use_iban##* "${iban}" *}" ] && check="${check} ${key#check_} "
+    ;;
+esac; done
+
+{ printf '[ul .results'
+  for use in $check; do
+    iban="${use%_*}"
+    fn="$(POST "fn_${use}")"
+    uid="${UIDLIST%% FN:"$fn"${BR}*}" uid="${uid##*${BR}UID:}"
+  
+    # cfile="${_DATA}/vcard/${uid}.vcf"
+    cfile="$(grep -lxF "UID;:${uid}" "${_DATA}/vcard/"*.vcf || grep -lxF "UID:${uid}" "${_DATA}/vcard/"*.vcf)"
+    if SLOCK "$cfile" >/dev/null; then
+      card="$(pdi_load "$cfile")"
+      cnum="$(pdi_count "$card" X-IBAN)"
+      pdi_update_value "$card" X-IBAN "$((cnum + 1))" "$iban" >"$cfile"
+      printf '[li .success . [span .name . %s] [span .uid . (UID: %s)] assigned IBAN [span .iban . %s]]' \
+             "$(HTML "$fn")" "$(HTML "$uid")" "$(HTML "$iban")"
+      RELEASE_SLOCK "$cfile"
+    else
+      printf '[li .error . [span .name . %s] [span .uid . (UID: %s)] is being edited elsewhere]'
+             "$(HTML "$fn")" "$(HTML "$uid")"
+    fi
+  done
+  printf ']'
+  printf '[a .button href="%s/ledgers/iban_assign/" . %s]' "${_BASE}" "$(l10n Back)"
+} | yield_page ledgers_assign