From c195881a2389862d4bfcd2fd55ca868f7a20b8e8 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 2 Dec 2013 05:46:18 +0000 Subject: [PATCH] implemented course section svn path=/trunk/; revision=30 --- actions/edit_attendee.sh | 1 - actions/edit_course.sh | 5 ++ actions/new_course.sh | 29 ++++++++ actions/update_attendee.sh | 1 + actions/update_course.sh | 97 ++++++++++++++++++++++++ cgi.sh | 1 + export.sh | 5 ++ index.cgi | 2 +- pages/attendees.sh | 2 +- pages/courses.sh | 116 +++++++++++++++++++++++++++++ templates/courses.css.sh | 127 +++++++++++++++++++++++++++++++ templates/courses.html.sh | 25 +++++++ templates/edit_attendee.sh | 1 - templates/edit_course.sh | 148 +++++++++++++++++++++++++++++++++++++ templates/text_courses.sh | 36 +++++++++ templates/view_course.sh | 77 +++++++++++++++++++ 16 files changed, 669 insertions(+), 4 deletions(-) create mode 100644 actions/edit_course.sh create mode 100644 actions/new_course.sh create mode 100644 actions/update_course.sh create mode 100644 templates/courses.css.sh create mode 100644 templates/courses.html.sh create mode 100755 templates/edit_course.sh create mode 100755 templates/text_courses.sh diff --git a/actions/edit_attendee.sh b/actions/edit_attendee.sh index 9a5bcb4..4e42014 100644 --- a/actions/edit_attendee.sh +++ b/actions/edit_attendee.sh @@ -3,7 +3,6 @@ cgi_refdata card="$_GET[\"card\"]" -debug card: $card filter="&filter=$_REF[\"filter\"]" filtertype="&filtertype=$_REF[\"filtertype\"]" order="&order=$_REF[\"order\"]" diff --git a/actions/edit_course.sh b/actions/edit_course.sh new file mode 100644 index 0000000..df07c32 --- /dev/null +++ b/actions/edit_course.sh @@ -0,0 +1,5 @@ +#!/bin/zsh + +course="$_GET[\"course\"]" + +echo -n "Location: http://$HTTP_HOST/?page=courses&edit=$course\n\n" diff --git a/actions/new_course.sh b/actions/new_course.sh new file mode 100644 index 0000000..7be0f26 --- /dev/null +++ b/actions/new_course.sh @@ -0,0 +1,29 @@ +#!/bin/zsh + +cgi_post + +uid=$(dbus-uuidgen) +course="${uid}.ics" + +tzid=$(cat /etc/timezone) +tstamp=$(TZ="$tzid" date +%Y%m%dT%H%M%S) + +tempfile="$_DATA/temp/$course" + +cat >"$tempfile" </dev/null 2>/dev/null || dts_day="01" +[ -z $dts_hour ] && dts_hour=$(date +%H) +[ -z $dts_minute ] && dts_minute=$(date +%M) + +dtstart="TZID=${tzid}:${dts_year}${dts_month}${dts_day}T${dts_hour}${dts_minute}00" + +rr_int="$_POST[\"RRULE_INTERVAL\"]" +rr_freq="$_POST[\"RRULE_FREQ\"]" +rr_limit="$_POST[\"RRULE_LIMIT\"]" +case "$rr_limit" in + ETERN) + rrule="FREQ=$rr_freq;INTERVAL=$rr_int" + ;; + COUNT) + t="$_POST[\"RRULE_COUNT\"]" + rrule="FREQ=$rr_freq;INTERVAL=$rr_int;COUNT=$t" + ;; + UNTIL) + uy="$_POST[\"RRULE_UYEAR\"]" + um="$_POST[\"RRULE_UMONTH\"]" + ud="$_POST[\"RRULE_UDAY\"]" + rrule="FREQ=$rr_freq;INTERVAL=$rr_int;UNTIL=${uy}${um}${ud}T000000Z" + ;; +esac + +echo "BEGIN:VCALENDAR\r" >"$tempfile" +echo "VERSION:2.0\r" >>"$tempfile" +echo "PRODID:Berlin RAW Confetti\r" >>"$tempfile" +echo "BEGIN:VEVENT\r" >>"$tempfile" +echo "UID:$uid\r" >>"$tempfile" +echo "DTSTAMP:TZID=${tzid}:${tstamp}\r" >>"$tempfile" +echo "DTSTART:${dtstart}\r" >>"$tempfile" +echo "RRULE:${rrule}\r" >>"$tempfile" +for field in SUMMARY COMMENT; do + value="$_POST[\"$field\"]" + n=0 + while [ -n "$value" ]; do + value="$(echo "$value" |sed -r ':a;N;$!ba;s:\n:\\\\n:g;s:\r:\\\\r:g')" + 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:VEVENT\r" >>"$tempfile" + echo "END:VCALENDAR\r" >>"$tempfile" + echo -n "Location: http://$HTTP_HOST/?page=courses&edit=$course\n\n" + ;; + update) + echo "END:VEVENT\r" >>"$tempfile" + echo "END:VCALENDAR\r" >>"$tempfile" + mv "$tempfile" "$coursefile" + echo -n "Location: http://$HTTP_HOST/?page=courses#$course\n\n" + ;; + cancel) + rm "$tempfile" + [ -f "$coursefile" ] \ + && echo -n "Location: http://$HTTP_HOST/?page=courses#$course\n\n" \ + || echo -n "Location: http://$HTTP_HOST/?page=courses\n\n" + ;; + delete) + rm "$tempfile" "$coursefile" + echo -n "Location: http://$HTTP_HOST/?page=courses\n\n" + ;; + *) + echo "END:VEVENT\r" >>"$tempfile" + echo "END:VCALENDAR\r" >>"$tempfile" + echo -n "Location: http://$HTTP_HOST/?page=courses&edit=$course\n\n" + ;; +esac diff --git a/cgi.sh b/cgi.sh index 39172ba..803c2bb 100755 --- a/cgi.sh +++ b/cgi.sh @@ -24,6 +24,7 @@ cgi_post() { # parse HTTP POST string else _POST["$key"]="$value" fi + #debug "_POST[$key] => $value" done } diff --git a/export.sh b/export.sh index aa8570a..29ddf6e 100755 --- a/export.sh +++ b/export.sh @@ -6,4 +6,9 @@ case "$_GET[\"export\"]" in card="$_GET[\"card\"]" cat "$_DATA/vcard/$card" ;; + ical) + echo -n "Content-Type: text/calendar;charset=utf-8\n\n" + course="$_GET[\"course\"]" + cat "$_DATA/ical/$course" + ;; esac diff --git a/index.cgi b/index.cgi index 1721280..c052787 100755 --- a/index.cgi +++ b/index.cgi @@ -23,7 +23,7 @@ _DATA="$(dirname "$call")" #storage directory [ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" # create directories for object storage -for each in "$_DATA"/{vcard,mappings,courses,cache,temp}; do +for each in "$_DATA"/{vcard,ical,cache,temp}; do [ ! -e "$each" ] && mkdir "$each" [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory" done diff --git a/pages/attendees.sh b/pages/attendees.sh index dfa7dfb..32f651b 100755 --- a/pages/attendees.sh +++ b/pages/attendees.sh @@ -22,7 +22,7 @@ listcards() { ;; course) ;; - *) ls -1 ${_DATA}/vcard/*vcf + *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null ;; esac |case "$_GET[\"order\"]" in firstname) diff --git a/pages/courses.sh b/pages/courses.sh index 1c69c66..9610ec2 100755 --- a/pages/courses.sh +++ b/pages/courses.sh @@ -1,12 +1,128 @@ #!/bin/sh +listcourses() { + case "$_GET[\"filtertype\"]" in + *) ls -1 ${_DATA}/ical/*ics 2>/dev/null + ;; + esac |case "$_GET[\"order\"]" in + *) + sed -r 's:^.*$:x\t&:' + ;; + esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:' +} + +ics_parse() { + tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' |tr -d '\r' \ + | sed -r 's:^([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key="\1"\nvalue="\3"\ntag=\2:g' \ + | while read -r line; do + case "$line" in + key=*) echo -E "$line" + ;; + value=*) echo -E "$line" + ;; + tag=*) ot='' + echo -E "$line" \ + | sed -r 's:^tag=::;s:\;([A-Z+_-]+="[^"]+"|[A-Z+_-]+=[^\;]+):\n\1:g;' \ + | sed -r 's:([A-Z+_-]+)="?(.*)"?:tag\[\1\]="\2":g' \ + | sed -r '/^ *$/d' \ + | sort |while read -r tag; do + nt="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\1:')" + nv="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\2:')" + [ "$nt" = "$ot" ] && vl="$nv,$vl" || vl="$nv" + echo -E "tag[$nt]=\"$vl\"" + ot="$nt" + done + ;; + esac + done +} + +view_course() { #Parameter: Calendarfile + id="$1" + calendarfile="$_DATA/ical/${id}" + cachefile="$_DATA/cache/${id}.cache" + unset key + if [ "$cachefile" -nt "$calendarfile" ]; then + cat "$cachefile" + else + declare -A tags + declare -A values + ics_parse "$calendarfile" |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_course.sh |tee "$cachefile" + fi +} + +edit_course() { #Parameter: Calendarfile + id="$1" + calendarfile="$_DATA/ical/$id" + tempfile="$_DATA/temp/$id" + [ -f "$tempfile" ] && calendarfile="$tempfile" + unset key + + declare -A tags + declare -A values + ics_parse "$calendarfile" |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_course.sh +} + case "$1" in title) echo "Kurse" ;; css) + . ${_EXEC}/templates/courses.css.sh ;; body) + . ${_EXEC}/templates/text_courses.sh + . ${_EXEC}/templates/courses.html.sh ;; esac diff --git a/templates/courses.css.sh b/templates/courses.css.sh new file mode 100644 index 0000000..a0fdb03 --- /dev/null +++ b/templates/courses.css.sh @@ -0,0 +1,127 @@ +cat < +
+ +
+ + +
+$( +[ -f "ical/$edit" -o -f "temp/$edit" ] && edit_course "$edit" +if [ "$?" = 0 ]; then + listcourses |grep -v "$edit" +else + listcourses +fi |while read card; do + view_course "$card" +done +) +
+EOF + +# vi:set filetype=html: diff --git a/templates/edit_attendee.sh b/templates/edit_attendee.sh index 5013c88..004f690 100755 --- a/templates/edit_attendee.sh +++ b/templates/edit_attendee.sh @@ -8,7 +8,6 @@ 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')" -declare -A SUP_FIELDS SUP_FIELDS=(N NICKNAME GENDER BDAY EMAIL TEL IMPP ADR URL NOTE) [ -z "$values[UID]" ] && values[UID]="$(dbus-uuidgen)" diff --git a/templates/edit_course.sh b/templates/edit_course.sh new file mode 100755 index 0000000..cab3213 --- /dev/null +++ b/templates/edit_course.sh @@ -0,0 +1,148 @@ + +SUP_FIELDS=(SUMMARY COMMENT) +[ -z "$values[UID]" ] && values[UID]="$(dbus-uuidgen)" + +dtstart="$values[DTSTART]" +[ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S) + +echo "$dtstart" |case "$dtstart" in + *Z) + sed -rn 's:^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$:\1-\2-\3 \4\:\5\:\6 UTC:p' + ;; + TZID*) + sed -rn 's:^TZID=(.+)\:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$:TZ="\1" \2-\3-\4 \5\:\6\:\7:p' + ;; + *) + sed -rn 's:^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$:\1-\2-\3 \4\:\5\:\6:p' + ;; +esac |read dts_date + +dts_year=$(date -d "$dts_date" +%Y) +dts_month=$(date -d "$dts_date" +%m) +dts_dom=$(date -d "$dts_date" +%d) +dts_dow=$(date -d "$dts_date" +%u) +dts_weekday=$(date -d "$dts_date" +%A) +dts_hour=$(date -d "$dts_date" +%H) +dts_min=$(date -d "$dts_date" +%M) +dts_sec=$(date -d "$dts_date" +%S) + +rrule="$values[RRULE]" +rr_int="$(echo $rrule |sed -rn 's:^.*INTERVAL=([0-9]+)(;.*)?$:\1:p')" +rr_count="$(echo $rrule |sed -rn 's:^.*COUNT=([0-9]+)(;.*)?$:\1:p')" +rr_freq="$(echo $rrule |sed -rn 's:^.*FREQ=(YEARLY|MONTHLY|WEEKLY|DAILY)(;.*)?$:\1:p')" +rr_uyear="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\1:p')" +rr_umonth="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\2:p')" +rr_uday="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\3:p')" +if [ -n "$rr_count" ]; then + rr_limit=COUNT +elif [ -n "$rr_uyear" ]; then + rr_limit=UNTIL +else + rr_limit=ETERN +fi + +echo '
' +echo '
' +echo '' +echo '
' +echo ' '$(l10n SUMMARY)'' +echo ' ' +echo ' '$(l10n COMMENT)'' +for n in COMMENT COMMENT{0..10}; do [ -n "$values[$n]" ] &&\ + echo ' ' +done +echo '
' + +echo '
' +echo ' '$(l10n DTSTART)'' +echo ' ' +echo ' ' +echo ' ' +for wd in mon tue wed thu fri sat sun; do + echo ' '$(date -d $wd +%a)'' +done +fdom=$(date -d ${dts_year}-${dts_month}-1 +%u) +while [ "$fdom" -gt 1 ]; do + echo ' ' + fdom=$(($fdom - 1)) +done +echo '' +cnt=$(date -d ${dts_year}-${dts_month}-1 +%s) +while [ "$(date -d @$cnt +%m)" = "$dts_month" ]; do + dn=$(date -d @$cnt +%d) + echo ' ' + cnt=$(($cnt + 86400)) +done +echo '
' +echo ' '$(l10n time)':' +echo ' :' +echo '
' + +echo '
' +echo ' '$(l10n RRULE)'' +echo ' '$(l10n t_every)'' +echo ' ' +echo '
' +echo ' '$(l10n t_eternal)'
' +echo ' ' +echo ' '$(l10n t_times)'
' +echo ' '$(l10n t_until)'' +echo ' ' +echo ' ' +echo ' ' +echo '
' + +echo '
' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +echo ' ' +echo '
' +echo '' +echo '
' +echo '
' + diff --git a/templates/text_courses.sh b/templates/text_courses.sh new file mode 100755 index 0000000..31cf89c --- /dev/null +++ b/templates/text_courses.sh @@ -0,0 +1,36 @@ +declare -A item_name + +item_name[SUMMARY]="Bezeichnung" +item_name[COMMENT]="Kommentar" +item_name[DTSTART]="Beginn" +item_name[DURATION]="Dauer" +item_name[RRULE]="Regelmäßigkeit" + +item_name[DAILY]="Tage" +item_name[WEEKLY]="Wochen" +item_name[MONTHLY]="Monate" +item_name[YEARLY]="Jahre" + +item_name[sDAILY]="Täglich" +item_name[sWEEKLY]="Wöchentlich" +item_name[sMONTHLY]="Monatlich" +item_name[sYEARLY]="Jährlich" + +item_name[newcourse]="Neuen Eintrag anlegen" +item_name[time]="Uhrzeit" +item_name[edit_update]="Daten übernehmen" +item_name[edit_cancel]="Abbrechen" +item_name[edit_delete]="Eintrag löschen" +item_name[edit_addfieldtext]="Neues Feld" +item_name[edit_addfield]="+" +item_name[edit_dtscal]="✓" + +item_name[t_every]="Alle" +item_name[t_eternal]="ewig" +item_name[t_times]="mal" +item_name[t_until]="Bis" +item_name[t_oclock]="Uhr" + +l10n() { + [ -n "$item_name[$1]" ] && echo -n "$item_name[$1]" || echo -n "$1" +} diff --git a/templates/view_course.sh b/templates/view_course.sh index e69de29..ea48afe 100755 --- a/templates/view_course.sh +++ b/templates/view_course.sh @@ -0,0 +1,77 @@ + +dtstart="$values[DTSTART]" +[ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S) + +echo "$dtstart" |case "$dtstart" in + *Z) + sed -rn 's:^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$:\1-\2-\3 \4\:\5\:\6 UTC:p' + ;; + TZID*) + sed -rn 's:^TZID=(.+)\:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$:TZ="\1" \2-\3-\4 \5\:\6\:\7:p' + ;; + *) + sed -rn 's:^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$:\1-\2-\3 \4\:\5\:\6:p' + ;; +esac |read dts_date + +dts_year=$(date -d "$dts_date" +%Y) +dts_month=$(date -d "$dts_date" +%m) +dts_dom=$(date -d "$dts_date" +%d) +dts_dow=$(date -d "$dts_date" +%u) +dts_weekday=$(date -d "$dts_date" +%A) +dts_hour=$(date -d "$dts_date" +%H) +dts_min=$(date -d "$dts_date" +%M) +dts_sec=$(date -d "$dts_date" +%S) + +rrule="$values[RRULE]" +rr_int="$(echo $rrule |sed -rn 's:^.*INTERVAL=([0-9]+)(;.*)?$:\1:p')" +rr_count="$(echo $rrule |sed -rn 's:^.*COUNT=([0-9]+)(;.*)?$:\1:p')" +rr_freq="$(echo $rrule |sed -rn 's:^.*FREQ=(YEARLY|MONTHLY|WEEKLY|DAILY)(;.*)?$:\1:p')" +rr_uyear="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\1:p')" +rr_umonth="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\2:p')" +rr_uday="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\3:p')" +rr_udate="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z(;.*)?$:\1-\2-\3 \4\:\5\:\6:p')" +if [ -n "$rr_count" ]; then + rr_limit=COUNT +elif [ -n "$rr_uyear" ]; then + rr_limit=UNTIL +else + rr_limit=ETERN +fi + +echo '
' +echo '
' +echo '' +echo '
' +echo ' '$values[SUMMARY]'' +echo ' '$(date -d "$dts_date" "+%A %B %d, %Y - %H:%M") $(l10n t_oclock)'' +[ "$rr_int" -eq 1 ] \ +&& echo ''$(l10n s$rr_freq)'' \ +|| echo ''$(l10n t_every) ${rr_int} $(l10n $rr_freq)'' +case "$rr_limit" in + COUNT) + m1=$(echo $rr_freq |sed -r "s:DAILY:day:g;s:WEEKLY:week:g;s:MONTHLY:month:g;s:YEARLY:year:g;") + m2=$(($rr_int * $rr_count)) + echo ''$(l10n t_until) $(date -d "$dts_date + $m2 $m1" "+%A %B %d, %Y - %H:%M")'' + ;; + UNTIL) + echo ''$(l10n t_until) $(date -d "$rr_udate" "+%A %B %d, %Y - %H:%M")'' + ;; +esac +echo '
' + +echo '
' +echo ' '$(l10n COMMENT)'' +for n in COMMENT COMMENT{0..10}; do [ -n "$values[$n]" ] &&\ + echo '

'$values[$n]'

' +done +echo '
' + +echo '
' +echo ' '$(l10n edit)'' +echo ' '$(l10n vcf_export)'' +echo '
' +echo '' +echo '
' +echo '
' + -- 2.39.2