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
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:')"
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"
}
--- /dev/null
+#!/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)
cgi_get
debug "$_GET"
+. "$_EXEC/constants.sh"
+
[ -n "$_GET[\"action\"]" ] && . "$_EXEC/action.sh" || . "$_EXEC/page.sh"
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 '
<div class="cardlist">
$(listcards |while read card; do
- id="vcf_$card"
+ id="$(basename "$card")"
if [ "$_GET[\"edit\"]" = "$id" ]; then cat <<x_EOF
<div id="${id}" class="card">
<form action="/?action=update_attendee" method="POST">
<input type="hidden" name="card" value="${id}"/>
- $(edit_attendee "$card")
+ $(edit_attendee "$id")
<br /><select name="newfield">
<option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
- $(echo $FIELDLIST |while read f; do echo "<option value=\"$f\">$(l10n $f)</option>"; done)
+ $(for f in $VCF_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done)
</select>
<button type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
<br /><button type="submit" name="action" value="update">$(l10n edit_update)</button>
else cat <<x_EOF
<div id="${id}" class="card">
<p class="control"><a href="?page=attendees&edit=${id}#${id}">$(l10n edit)</a></p>
- $(view_attendee "$card")
+ $(view_attendee "$id")
</div>
x_EOF
fi
}
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";;
}
view_attendee() { #Parameter: Cardfile
- cardfile="$1"
+ cardfile="vcard/$1"
cachefile="cache/vcf_$(basename "$cardfile").cache"
unset key
[ "$cachefile" -nt "$cardfile" ] && cat "$cachefile" \