X-Git-Url: https://git.plutz.net/?p=confetti;a=blobdiff_plain;f=cards%2Fupdate_card.sh;h=d942e9abdbc527aa5ff803bc8c0b4dd501355778;hp=7896beb5011d3cee5892b9d6c099a8693d34caa3;hb=30eeafefe167140350ecd4034c9689ab4dd9857d;hpb=203fc5d63ba59a30688bac00c98d199cb08a8f30 diff --git a/cards/update_card.sh b/cards/update_card.sh index 7896beb..d942e9a 100755 --- a/cards/update_card.sh +++ b/cards/update_card.sh @@ -1,6 +1,6 @@ -#!/bin/zsh +#!/bin/sh -# Copyright 2014, 2016, 2019, 2020 Paul Hänsch +# Copyright 2014, 2016, 2019, 2020, 2021 Paul Hänsch # # This file is part of Confetti. # @@ -62,9 +62,15 @@ vcf_escape(){ # [ -n "${_POST[hi_company]}${_POST[hi_number]}${_POST[hi_status]}" ] \ # && _POST[X-HEALTH-INSURANCE]="$(vcf_escape "${_POST[hi_company]}" "${_POST[hi_number]}" "${_POST[hi_status]}")" -vcf="$(pdi_load "$cardfile")" +vcf="$(pdi_load "$tempfile")" -vcf="$(pdi_update_value "$vcf" N 1 "$(vcf_escape "$(POST 1N)" "$(POST 2N)" "$(POST 3N)" "$(POST 4N)" "$(POST 5N)")")" +n1="$(POST 1N)" n2="$(POST 2N)" n3="$(POST 3N)" n4="$(POST 4N)" n5="$(POST 5N)" +# 3N (Middle Names) is not actually used +n3="${n2#${n2%% *}}" + +vcf="$(pdi_update_value "$vcf" N 1 "$(vcf_escape "$n1" "${n2%% *}" "${n3# }" "$n4" "$n5")")" +vcf="$(pdi_update_value "$vcf" FN 1 "$(vcf_escape "$n4 $n2 $n1 $n5" |sed -E 's;(^ +| +$);;g; s; +; ;g;')")" +vcf="$(printf '%s\n' "$vcf" |sed -E "/^CATEGORIES;[^:]*:.*$/d")" for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do for cnt in $(seq 1 $(POST_COUNT "$field")); do @@ -104,14 +110,14 @@ case "$action" in update) if LOCK "$attfile"; then grep -F " ${card}" "$attfile" |while read course junk; do - touch "$_DATA/courses/${course}" + touch "$_DATA/ical/${course}" done - sed -i -r "/^.+ ${card}\$/d" "$attfile" + sed -i -E "/^.+ ${card}\$/d" "$attfile" seq 1 $(POST_COUNT attendance) |while read n; do printf '%s %s\n' "$(POST attendance $n)" "$card" done >>"$attfile" grep -F " ${card}" "$attfile" |while read course junk; do - touch "$_DATA/courses/${course}" + touch "$_DATA/ical/${course}" done RELEASE "$attfile" else @@ -131,6 +137,15 @@ case "$action" in delete) rm "$cardfile" RELEASE_SLOCK "$cardfile" + if LOCK "$attfile"; then + grep -F " ${card}" "$attfile" |while read course junk; do + touch "$_DATA/ical/${course}" + done + sed -i -E "/^.+ ${card}\$/d" "$attfile" + RELEASE "$attfile" + else + SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS" + fi REDIRECT "/cards/?o=${order}&f=${filter}" ;; esac