]> git.plutz.net Git - lobster/commitdiff
basic update functions for vcards
authorpaul <paul@plutz.net>
Wed, 27 Nov 2013 14:15:45 +0000 (14:15 +0000)
committerpaul <paul@plutz.net>
Wed, 27 Nov 2013 14:15:45 +0000 (14:15 +0000)
svn path=/trunk/; revision=19

actions/update_attendee.sh
cgi.sh
constants.sh [new file with mode: 0644]
index.cgi
pages/attendees.sh
templates/attendees.html.sh
templates/edit_attendee.sh
templates/view_attendee.sh

index 3c6ad55c4ee530048033adf7289528321545b274..10eb82c419b7716856c7c121b9d7ba7a4998cdb1 100644 (file)
@@ -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 cf0023c3c90949f7677bb72b0b2c108e7dac1220..676dbc581abcccf9a4da74c979b227e176fd5624 100755 (executable)
--- 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 (file)
index 0000000..dee33a9
--- /dev/null
@@ -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)
index 92310fd95cb10b877f25fe2b4a5a56e7588f7449..681c436b867e164fb48cd0017eb94464e6b2215a 100755 (executable)
--- 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"
index 2d06f6b9561ca6e5d6189a98d3888534ce14b122..9ea073e6a1c2b5e965c13af98207c4e423538970 100755 (executable)
@@ -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 '
index 92e4d91ab4d053fbc94c9368f5db3a7d6e69bce8..3847b71a8089e6283d83a9b5ee167b838bce7765 100644 (file)
@@ -37,15 +37,15 @@ cat <<EOF
 
 <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>
@@ -57,7 +57,7 @@ x_EOF
   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
index fe33c18e33ee2d26f414600a24bf9021f4880e2a..d79553f284cc7576bd3adb4317375b419a149326 100755 (executable)
@@ -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";;
index 5b7c77237bcf1a41e99725fd861c29ef7d4ef63d..86dad68ea13ec06ea65678460b75e9dbb06a98ab 100755 (executable)
@@ -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" \