From: paul Date: Sun, 1 Dec 2013 00:26:33 +0000 (+0000) Subject: updated manipulation and view functions for attendee X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=19a85441a8f173c3d2cd3d29fd7d95d2b471bb3c;p=lobster updated manipulation and view functions for attendee svn path=/trunk/; revision=26 --- diff --git a/actions/new_attendee.sh b/actions/new_attendee.sh new file mode 100644 index 0000000..d209191 --- /dev/null +++ b/actions/new_attendee.sh @@ -0,0 +1,26 @@ +#!/bin/zsh + +cgi_post + +uid=$(dbus-uuidgen) +card="${uid}.vcf" + +cardfile="vcard/$card" +tempfile="temp/$card" + +touch "$cardfile" + +cat >"$tempfile" <>"$tempfile" echo "END:VCARD\r" >>"$tempfile" - echo -n "Location: http://$HTTP_HOST/?page=attendees&edit=$card#$card\n\n" + echo -n "Location: http://$HTTP_HOST/?page=attendees&edit=$card\n\n" ;; update) echo "END:VCARD\r" >>"$tempfile" @@ -35,4 +35,8 @@ case "$_POST[\"action\"]" in rm "$tempfile" echo -n "Location: http://$HTTP_HOST/?page=attendees#$card\n\n" ;; + delete) + rm "$tempfile" "$cardfile" + echo -n "Location: http://$HTTP_HOST/?page=attendees\n\n" + ;; esac diff --git a/pages/attendees.sh b/pages/attendees.sh index 4a352ca..35e790e 100755 --- a/pages/attendees.sh +++ b/pages/attendees.sh @@ -1,6 +1,6 @@ #!/bin/sh -[ "$_GET[\"action\"]" = "del_filter" ] && _GET["filter"]="" && _GET["filtertype"]="" +[ "$_GET[\"choice\"]" = "del_filter" ] && _GET["filter"]="" && _GET["filtertype"]="" listcards() { case "$_GET["filtertype"]" in any) @@ -25,7 +25,7 @@ listcards() { ;; *) ls -1 ${_DATA}/vcard/*vcf ;; - esac + esac |sed -r 's:^(.*/)([^/]+)$:\2:' } vcf_parse() { @@ -67,6 +67,7 @@ vcf_parse() { s:^X-EVOLUTION-BLOG-URL:021 URL:p; s:^LANG:022 LANG:p; s:^NOTE:023 NOTE:p; + s:^UID:026 UID:p; s:^RELATED:025 RELATED:p; s:^AGENT:025 RELATED\;TYPE=agent:p; @@ -96,7 +97,6 @@ vcf_parse() { s:^SORT-STRING.*$::; s:^SOURCE.*$::; s:^TZ.*$::; - s:^UID.*$::; s:^VERSION.*$:000 VERSION\:4.0:p; s:^XML.*$::; @@ -156,6 +156,82 @@ vcf_parse() { done } +view_attendee() { #Parameter: Cardfile + id="$1" + cardfile="$_DATA/vcard/${id}" + cachefile="$_DATA/cache/${id}.cache" + unset key + if [ "$cachefile" -nt "$cardfile" ]; then + cat "$cachefile" + else + declare -A tags + declare -A values + vcf_parse "$cardfile" |while read -r line; do + declare -A tag + case "$line" in + value*) eval "$line";; + tag*) eval "$line";; + key*) + if [ -z "$key" ]; then + eval "$line" + else + values[$key]="$value" + for t in ${(k)tag}; do + tags[${key}_$t]="$tag[$t]" + done + eval "$line" + if [ -n "$values[$key]" ]; then + n=0 + while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done + key=$key$n + fi + unset value + unset tag + fi + ;; + esac + done + . ${_EXEC}/templates/view_attendee.sh |tee "$cachefile" + fi +} + +edit_attendee() { #Parameter: Cardfile + id="$1" + cardfile="$_DATA/vcard/$id" + tempfile="$_DATA/temp/$id" + [ -f "$tempfile" ] && cardfile="$tempfile" + unset key + + declare -A tags + declare -A values + vcf_parse "$cardfile" |while read -r line; do + declare -A tag + case "$line" in + value*) eval "$line";; + tag*) eval "$line";; + key*) + if [ -z "$key" ]; then + eval "$line" + else + [ -n "$value" ] && values[$key]="$value" || values[$key]='\r' + for t in ${(k)tag}; do + tags[${key}_$t]="$tag[$t]" + done + eval "$line" + if [ -n "$values[$key]" ]; then + n=0 + while [ -n "$values[${key}${n}]" ]; do n=$(($n + 1)); done + key=$key$n + fi + unset value + unset tag + fi + ;; + esac + done + . ${_EXEC}/templates/edit_attendee.sh +} + case "$1" in title) echo "Teilnehmende" @@ -164,6 +240,7 @@ case "$1" in . ${_EXEC}/templates/attendees.css.sh ;; body) + . ${_EXEC}/templates/text_attendee.sh . ${_EXEC}/templates/attendees.html.sh ;; esac diff --git a/templates/attendees.html.sh b/templates/attendees.html.sh index a237d3e..86605d2 100644 --- a/templates/attendees.html.sh +++ b/templates/attendees.html.sh @@ -1,11 +1,10 @@ -. ${_EXEC}/templates/text_attendee.sh -. ${_EXEC}/templates/view_attendee.sh -. ${_EXEC}/templates/edit_attendee.sh - check(){ [ "$_GET[\"filtertype\"]" = "$1" ] && echo 'checked="checked"' } +edit="$_GET[\"edit\"]" +[ -z "$_GET[\"filtertype\"]" ] && _GET[filtertype]="any" + cat <
@@ -20,41 +19,30 @@ cat <$(l10n filter_phone) $(l10n filter_birthyear) $(l10n filter_course)
- - + +
-

Neuer Eintrag

-
- Name: - - + +
-$(listcards |while read card; do - id="$(basename "$card")" - if [ "$_GET[\"edit\"]" = "$id" ]; then cat < -
- - $(edit_attendee "$id") -
-
-x_EOF - else cat < - $(view_attendee "$id") - -x_EOF - fi -done) +$( +[ -f "vcard/$edit" -o -f "temp/$edit" ] && edit_attendee "$edit" +if [ "$?" = 0 ]; then + listcards |grep -v "$edit" +else + listcards +fi |while read card; do + view_attendee "$card" +done +) - EOF # vi:set filetype=html: diff --git a/templates/edit_attendee.sh b/templates/edit_attendee.sh index 679a7bd..5013c88 100755 --- a/templates/edit_attendee.sh +++ b/templates/edit_attendee.sh @@ -2,130 +2,103 @@ check_gen() { [ "$value[GENDER]" = "$1" ] && echo 'selected="selected"' } -edit_card() { - n_last="$(echo "$values[N]" |sed -rn 's:^([^;]*;){0} *([^;]*).*$:\2:p')" - n_first="$(echo "$values[N]" |sed -rn 's:^([^;]*;){1} *([^;]*).*$:\2:p')" - n_middle="$(echo "$values[N]" |sed -rn 's:^([^;]*;){2} *([^;]*).*$:\2:p')" - n_pre="$(echo "$values[N]" |sed -rn 's:^([^;]*;){3} *([^;]*).*$:\2:p')" - n_post="$(echo "$values[N]" |sed -rn 's:^([^;]*;){4} *([^;]*)*$:\2:p')" +n_last="$(echo "$values[N]" |sed -rn 's:^([^;]*;){0} *([^;]*).*$:\2:p')" +n_first="$(echo "$values[N]" |sed -rn 's:^([^;]*;){1} *([^;]*).*$:\2:p')" +n_middle="$(echo "$values[N]" |sed -rn 's:^([^;]*;){2} *([^;]*).*$:\2:p')" +n_pre="$(echo "$values[N]" |sed -rn 's:^([^;]*;){3} *([^;]*).*$:\2:p')" +n_post="$(echo "$values[N]" |sed -rn 's:^([^;]*;){4} *([^;]*)*$:\2:p')" - [ -z "$values[UID]" ] && values[UID]="$(dbus-uuidgen)" +declare -A SUP_FIELDS +SUP_FIELDS=(N NICKNAME GENDER BDAY EMAIL TEL IMPP ADR URL NOTE) - echo '
' - echo ' '$(l10n N)'' - echo ' ' - echo ' ' - echo ' ' - echo ' ' - echo ' ' - if [ -n "$value[GENDER]" ]; then - echo '
' - echo ' ' - fi - for n in NICKNAME NICKNAME{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - if [ -n "$values[BDAY]" ]; then - echo ' '$(l10n BDAY)'' - echo ' ' - fi - if [ -n "$values[SOUND]" ]; then - echo ' ' - fi - [ -n "$values[PHOTO]" ] &&\ - echo ' ' - [ -n "$values[LOGO]" ] &&\ - echo ' ' - echo '
' - echo '' - echo '
' - echo ' '$(l10n TEL)'' - print -l ${(k)values} |egrep '^TEL[0-9]*$' |while read n; do - echo ' ' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n EMAIL)'' - for n in EMAIL EMAIL{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - [ -n "$values[IMPP]" ] && \ - echo ' '$(l10n IMPP)'' - for n in IMPP IMPP{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n ADR)'' - for n in ADR ADR{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - [ -n "$values[URL]" ] && \ - echo ' '$(l10n URL)'' - for n in URL URL{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n NOTE)'' - for n in NOTE NOTE{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - echo '
' - echo '' +[ -z "$values[UID]" ] && values[UID]="$(dbus-uuidgen)" + +echo '
' +echo '
' +echo '' +echo '
' +echo ' '$(l10n N)'' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +if [ -n "$value[GENDER]" ]; then echo '
' echo ' ' - echo ' ' - echo ' ' - echo ' ' - echo '
' - echo '' -} +fi +for n in NICKNAME NICKNAME{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +if [ -n "$values[BDAY]" ]; then + echo ' '$(l10n BDAY)'' + echo ' ' +fi +if [ -n "$values[SOUND]" ]; then + echo ' ' +fi +[ -n "$values[PHOTO]" ] &&\ + echo ' ' +[ -n "$values[LOGO]" ] &&\ + echo ' ' +echo '
' +echo '' +echo '
' +echo ' '$(l10n TEL)'' +for n in TEL TEL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n EMAIL)'' +for n in EMAIL EMAIL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +[ -n "$values[IMPP]" ] && \ + echo ' '$(l10n IMPP)'' +for n in IMPP IMPP{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n ADR)'' +for n in ADR ADR{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +[ -n "$values[URL]" ] && \ + echo ' '$(l10n URL)'' +for n in URL URL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n NOTE)'' +for n in NOTE NOTE{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +echo '
' +echo '' +echo '
' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +echo '
' +echo '' +echo '
' +echo '
' -edit_attendee() { #Parameter: Cardfile - id="$1" - cardfile="vcard/$id" - unset key - - declare -A tags - declare -A values - vcf_parse "$cardfile" |while read -r line; do - declare -A tag - case "$line" in - value*) eval "$line";; - tag*) eval "$line";; - key*) - if [ -z "$key" ]; then - eval "$line" - else - [ -n "$value" ] && values[$key]="$value" || values[$key]='\r' - for t in ${(k)tag}; do - tags[${key}_$t]="$tag[$t]" - done - eval "$line" - if [ -n "$values[$key]" ]; then - n=0 - while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done - key=$key$n - fi - unset value - unset tag - fi - ;; - esac - done - edit_card -} diff --git a/templates/text_attendee.sh b/templates/text_attendee.sh index 1942b9f..714ac61 100755 --- a/templates/text_attendee.sh +++ b/templates/text_attendee.sh @@ -53,9 +53,10 @@ item_name[XML]="" item_name[edit]="Bearbeiten" item_name[vcf_export]="Vcard Exportieren" item_name[control]="Aktionen" -item_name[edit_update]="Daten Übernehmen" +item_name[edit_update]="Daten übernehmen" item_name[edit_cancel]="Abbrechen" -item_name[edit_addfieldtext]="Feld hinzufügen" +item_name[edit_delete]="Eintrag löschen" +item_name[edit_addfieldtext]="Neues Feld" item_name[edit_addfield]="+" item_name[edit_deletefield]="X" item_name[filter_all]="Alles" @@ -67,6 +68,7 @@ item_name[filter_birthyear]="Geburtsjahr" item_name[filter_course]="Kurs" item_name[filter_apply]="Filtern" item_name[filter_cancel]="Filter löschen" +item_name[newcard]="Neuen Eintrag anlegen" l10n() { [ -n "$item_name[$1]" ] && echo -n "$item_name[$1]" || echo -n "$1" diff --git a/templates/view_attendee.sh b/templates/view_attendee.sh index 40f0992..1bfccee 100755 --- a/templates/view_attendee.sh +++ b/templates/view_attendee.sh @@ -1,104 +1,65 @@ -print_card() { - echo '
' - echo ' '$values[FN]'' - [ -n "$value[GENDER]" ] && \ - echo ' '$(l10n $values[GENDER])'' - for n in NICKNAME NICKNAME{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' aka. '$values[$n]'' - done - [ -n "$values[BDAY]" ] &&\ - echo ' *: '$values[BDAY]'' - if [ -n "$values[SOUND]" ]; then - echo ' ' - fi - [ -n "$values[PHOTO]" ] &&\ - echo ' ' - [ -n "$values[LOGO]" ] &&\ - echo ' ' - echo '
' - echo '' - echo '
' - echo ' '$(l10n TEL)'' - for n in TEL TEL{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' '$tags[${n}_TYPE]' '$values[$n]'' - done - echo '
' - echo '' - echo '
' - [ -n "$values[EMAIL]" ] && \ - echo ' '$(l10n EMAIL)'' - for n in EMAIL EMAIL{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' ' - done - [ -n "$values[IMPP]" ] && \ - echo ' '$(l10n IMPP)'' - for n in IMPP IMPP{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' '$tags[${n}_TYPE]' '$values[$n]'' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n ADR)'' - for n in ADR ADR{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' '$values[$n]'' - done - [ -n "$values[URL]" ] && \ - echo ' '$(l10n URL)'' - for n in URL URL{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' '$values[$n]'' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n NOTE)'' - for n in NOTE NOTE{0..10}; do [ -n "$values[$n]" ] &&\ - echo ' '$values[$n]'' - done - echo '
' - echo '' - echo '
' - echo ' '$(l10n edit)'' - echo ' '$(l10n vcf_export)'' - echo '
' -} - -view_attendee() { #Parameter: Cardfile - id="$1" - cardfile="vcard/$id" - cachefile="cache/${id}.cache" - unset key - if [ "$cachefile" -nt "$cardfile" ]; then - cat "$cachefile" - else - declare -A tags - declare -A values - vcf_parse "$cardfile" |while read -r line; do - declare -A tag - case "$line" in - value*) eval "$line";; - tag*) eval "$line";; - key*) - if [ -z "$key" ]; then - eval "$line" - else - values[$key]="$value" - for t in ${(k)tag}; do - tags[${key}_$t]="$tag[$t]" - done - eval "$line" - if [ -n "$values[$key]" ]; then - n=0 - while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done - key=$key$n - fi - unset value - unset tag - fi - ;; - esac - done - print_card |tee "$cachefile" - fi -} +echo '
' +echo '
' +echo ' '$values[FN]'' +[ -n "$value[GENDER]" ] && \ + echo ' '$(l10n $values[GENDER])'' +for n in NICKNAME NICKNAME{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' aka. '$values[$n]'' +done +[ -n "$values[BDAY]" ] &&\ + echo ' *: '$values[BDAY]'' +if [ -n "$values[SOUND]" ]; then + echo ' ' +fi +[ -n "$values[PHOTO]" ] &&\ + echo ' ' +[ -n "$values[LOGO]" ] &&\ + echo ' ' +echo '
' +echo '' +echo '
' +echo ' '$(l10n TEL)'' +for n in TEL TEL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' '$tags[${n}_TYPE]' '$values[$n]'' +done +echo '
' +echo '' +echo '
' +[ -n "$values[EMAIL]" ] && \ + echo ' '$(l10n EMAIL)'' +for n in EMAIL EMAIL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +[ -n "$values[IMPP]" ] && \ + echo ' '$(l10n IMPP)'' +for n in IMPP IMPP{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' '$tags[${n}_TYPE]' '$values[$n]'' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n ADR)'' +for n in ADR ADR{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' '$values[$n]'' +done +[ -n "$values[URL]" ] && \ + echo ' '$(l10n URL)'' +for n in URL URL{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' '$values[$n]'' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n NOTE)'' +for n in NOTE NOTE{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' '$values[$n]'' +done +echo '
' +echo '' +echo '
' +echo ' '$(l10n edit)'' +echo ' '$(l10n vcf_export)'' +echo '
' +echo '
'