From: paul Date: Wed, 27 Nov 2013 14:15:45 +0000 (+0000) Subject: basic update functions for vcards X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;ds=inline;h=9da739230659371a860e93dcaf3765b977e30de7;hp=9917259ba7ae33000a3aeb892f392ed71ad0377d;p=confetti basic update functions for vcards svn path=/trunk/; revision=19 --- diff --git a/actions/update_attendee.sh b/actions/update_attendee.sh index 3c6ad55..10eb82c 100644 --- a/actions/update_attendee.sh +++ b/actions/update_attendee.sh @@ -2,6 +2,35 @@ cgi_post -debug $_POST +card="$_POST[\"card\"]" +tempfile="temp/$card" +cardfile="vcard/$card" -echo -n "Location: http://$HTTP_HOST/?page=attendees\n\n" +echo "BEGIN:VCARD\r" >"$tempfile" +echo "VERSION:4.0\r" >>"$tempfile" +for field in $VCF_FIELDS; do + value="$_POST[\"$field\"]" + n=0 + while [ -n "$value" ]; do + echo "${field}:${value}\r" + value="$_POST[\"$field$n\"]" + n=$(($n + 1)) + done +done >>"$tempfile" + +case "$_POST[\"action\"]" in + addfield) + echo "$_POST[\"newfield\"]:\r" >>"$tempfile" + echo "END:VCARD\r" >>"$tempfile" + echo -n "Location: http://$HTTP_HOST/?page=attendees&edit=$card#$card\n\n" + ;; + update) + echo "END:VCARD\r" >>"$tempfile" + mv "$tempfile" "$cardfile" + echo -n "Location: http://$HTTP_HOST/?page=attendees#$card\n\n" + ;; + cancel) + rm "$tempfile" + echo -n "Location: http://$HTTP_HOST/?page=attendees#$card\n\n" + ;; +esac diff --git a/cgi.sh b/cgi.sh index cf0023c..676dbc5 100755 --- a/cgi.sh +++ b/cgi.sh @@ -3,7 +3,6 @@ declare -A _GET declare -A _POST - cgi_get() { # parse HTTP GET string echo "$QUERY_STRING" |tr '&' '\n' |while read query; do key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')" @@ -17,7 +16,15 @@ cgi_post() { # parse HTTP POST string sed -u 1q |tr '&' '\n' |while read query; do key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')" val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')" - _POST["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")" + value="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")" + if [ -n "$_POST[\"$key\"]" ]; then + n=0 + while [ -n "$_POST[\"$key$n\"]" ]; do n=$(($n + 1)); done + _POST["$key$n"]="$value" + else + _POST["$key"]="$value" + fi + debug "post($key$n) => $value" done debug "$_POST" } diff --git a/constants.sh b/constants.sh new file mode 100644 index 0000000..dee33a9 --- /dev/null +++ b/constants.sh @@ -0,0 +1,3 @@ +#!/bin/zsh + +VCF_FIELDS=(PHOTO LOGO FN NICKNAME SOUND GENDER KIND TITLE ROLE ORG MEMBER CATEGORIES ANNIVERSARY BDAY EMAIL TEL IMPP ADR URL LANG NOTE RELATED) diff --git a/index.cgi b/index.cgi index 92310fd..681c436 100755 --- a/index.cgi +++ b/index.cgi @@ -48,4 +48,6 @@ EOF cgi_get debug "$_GET" +. "$_EXEC/constants.sh" + [ -n "$_GET[\"action\"]" ] && . "$_EXEC/action.sh" || . "$_EXEC/page.sh" diff --git a/pages/attendees.sh b/pages/attendees.sh index 2d06f6b..9ea073e 100755 --- a/pages/attendees.sh +++ b/pages/attendees.sh @@ -28,8 +28,6 @@ listcards() { esac } -FIELDLIST="$(echo PHOTO LOGO FN NICKNAME SOUND GENDER KIND TITLE ROLE ORG MEMBER CATEGORIES ANNIVERSARY BDAY EMAIL TEL IMPP ADR URL LANG NOTE RELATED |tr ' ' '\n')" - vcf_parse() { tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' \ | sed -rn ' diff --git a/templates/attendees.html.sh b/templates/attendees.html.sh index 92e4d91..3847b71 100644 --- a/templates/attendees.html.sh +++ b/templates/attendees.html.sh @@ -37,15 +37,15 @@ cat < $(listcards |while read card; do - id="vcf_$card" + id="$(basename "$card")" if [ "$_GET[\"edit\"]" = "$id" ]; then cat <
- $(edit_attendee "$card") + $(edit_attendee "$id")

@@ -57,7 +57,7 @@ x_EOF else cat <

$(l10n edit)

- $(view_attendee "$card") + $(view_attendee "$id") x_EOF fi diff --git a/templates/edit_attendee.sh b/templates/edit_attendee.sh index fe33c18..d79553f 100755 --- a/templates/edit_attendee.sh +++ b/templates/edit_attendee.sh @@ -17,11 +17,12 @@ edit_card_item() { } edit_attendee() { - cardfile="$1" - tempfile="temp/$_GET[\"edit\"].vcf" - [ -x "$tempfile" ] && cardfile="$tempfile" + cardfile="vcard/$1" + tempfile="temp/$1" + [ -f "$tempfile" ] && cardfile="$tempfile" + debug Using card: $cardfile unset key - vcf_parse "$cardfile" |while read -r line; do + vcf_parse "$cardfile" |debug |while read -r line; do declare -A tag case "$line" in value*) eval "$line";; diff --git a/templates/view_attendee.sh b/templates/view_attendee.sh index 5b7c772..86dad68 100755 --- a/templates/view_attendee.sh +++ b/templates/view_attendee.sh @@ -25,7 +25,7 @@ view_card_item() { } view_attendee() { #Parameter: Cardfile - cardfile="$1" + cardfile="vcard/$1" cachefile="cache/vcf_$(basename "$cardfile").cache" unset key [ "$cachefile" -nt "$cardfile" ] && cat "$cachefile" \