3 # Copyright 2014, 2016 Paul Hänsch
5 # This file is part of Confetti.
7 # Confetti is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Confetti is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
20 [ -z "${_GET[order]}" ] && _GET[order]=DOW
23 ls -1 ${_DATA}/vcard/*vcf 2>/dev/null |while read file; do
24 fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")
26 done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
31 case "${_GET[filtertype]}" in
32 *) ls -1 ${_DATA}/ical/*ics 2>/dev/null
34 esac |case "${_GET[order]}" in
37 icstime="$(sed -rn 's:^DTSTART\:(TZID=.*\:)?([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z?\r$:\2-\3-\4 \5\:\6\:\7:p' "$file")"
38 echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
43 icstime="$(sed -rn 's:^DTSTART\:(TZID=.*\:)?([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z?\r$:\2-\3-\4 \5\:\6\:\7:p' "$file")"
44 echo "$(date -d "$icstime" +%H%M%S)\t$file"
50 esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
55 sed -rn 's:'$id'\t(.+)$:\1:p' "$_DATA/mappings/attendance" |while read each; do
56 card="$_DATA/vcard/$each"
57 if [ -r "$card" ]; then
61 s;^N(\;.+)*:([^\;]*\;){3} *([^\;]*).*$;\3;p; g;
62 s;^N(\;.+)*:([^\;]*\;){1} *([^\;]*).*$;\3;p; g;
63 s;^N(\;.+)*:([^\;]*\;){2} *([^\;]*).*$;\3;p; g;
64 s;^N(\;.+)*:([^\;]*\;){0} *([^\;]*).*$;\3;p; g;
65 s;^N(\;.+)*:([^\;]*\;){4} *([^\;]*).*$;\3;p; g;
67 | sed -r ':X;N;$!bX; s;([\;\n\r,]| )+; ;g;; s;^ +| +$;;g;'
69 fname="$(sed -rn 's;^FN(\;.+)*:(.+)\r?$;\2;g; s;([\;\n,]| )+; ;g;; s;^ +| +$;;g;' "$card")"
70 nname="$(sed -rn 's;^NICKNAME(\;.+)*:(.+)\r?$;\2;g; s;([\;\n,]| )+; ;g;; s;^ +| +$;;g;' "$card")"
71 byear="$(sed -rn 's:^BDAY(\;.+)*\:([0-9]{4})(-[0-9][0-9]){2}.*$:\2:p' "$_DATA/vcard/$each")"
73 printf '%s %s (*%04i)\n' "$each" "${aname:-${fname:-${nname}}}" "$byear"
81 sed -rn 's:'$id'\t(.+)$:\1:p' "$_DATA/mappings/attendance" |while read each; do
82 coursemail="$coursemail$(sed -rn 's:^EMAIL(;.+)*\:(.+)\r$:\2,:p' "$_DATA/vcard/$each")"
88 tr -d '\n' <"$1" |sed -r 's:\r ::g;s:\r:\n:g' |tr -d '\r' \
89 | sed -r 's:^([^;\:]+)(;[^"\:]+|;"[^"]+")*\:(.*)$:key="\1"\nvalue="\3"\ntag=\2:g' \
90 | while read -r line; do
92 key=*) echo -E "$line"
94 value=*) echo -E "$line"
98 | sed -r 's:^tag=::;s:\;([A-Z+_-]+="[^"]+"|[A-Z+_-]+=[^\;]+):\n\1:g;' \
99 | sed -r 's:([A-Z+_-]+)="?(.*)"?:tag\[\1\]="\2":g' \
101 | sort |while read -r tag; do
102 nt="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\1:')"
103 nv="$(echo -E "$tag" |sed -r 's:^tag\[([A-Z+_-]+)\]="(.*)"$:\2:')"
104 [ "$nt" = "$ot" ] && vl="$nv,$vl" || vl="$nv"
105 echo -E "tag[$nt]=\"$vl\""
113 view_course() { #Parameter: Calendarfile
115 calendarfile="$_DATA/ical/${id}"
116 cachefile="$_DATA/cache/${id}.cache"
118 if [ "$cachefile" -nt "$calendarfile" ]; then
123 ics_parse "$calendarfile" |while read -r line; do
126 value*) eval "$line";;
129 if [ -z "$key" ]; then
132 values[$key]="$value"
133 for t in ${(k)tag}; do
134 tags[${key}_$t]="$tag[$t]"
137 if [ -n "$values[$key]" ]; then
139 while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
148 . ${_EXEC}/templates/view_course.sh |tee "$cachefile"
152 edit_course() { #Parameter: Calendarfile
154 calendarfile="$_DATA/ical/$id"
155 tempfile="$_DATA/temp/$id"
156 [ -f "$tempfile" ] && calendarfile="$tempfile"
161 ics_parse "$calendarfile" |while read -r line; do
164 value*) eval "$line";;
167 if [ -z "$key" ]; then
170 [ -n "$value" ] && values[$key]="$value" || values[$key]='\r'
171 for t in ${(k)tag}; do
172 tags[${key}_$t]="$tag[$t]"
175 if [ -n "$values[$key]" ]; then
177 while [ -n "$values[${key}${n}]" ]; do n=$(($n + 1)); done
186 . ${_EXEC}/templates/edit_course.sh