3 # Copyright 2014, 2016, 2017 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")"
89 sed -r ':X;N;$!bX; s;\r\n[ \t];;g; s;\r\n;\n;g;' "$1" \
91 # === turn property names to upper case, strip group names ===
93 x; s;^([^;:\.]+\.)?([^;:]+).*$;\2;;
94 y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ;
97 /^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$/{
99 s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):(.*)$;key='\''\1'\'';;
102 s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\2;;
103 s;'\'';'\'\\\\\'\'';g
104 s;\;([A-Z0-9-]+)(=|=(([^\;,:"]+|"[^"]+")(,[^\;,:"]+|,"[^"]+")*))?;\ntag[\1]='\''\3'\'';g
108 s;^([A-Z0-9-]+)((\;[A-z0-9-]+=?|\;[A-z0-9-]+=([^;,:"]+|"[^"]+")(,[^;,:"]+|,"[^"]+")*)*):([^\n]*)\n.*$;\6;;
109 # :X s;((^|[^\\])(\\\\)*)[;,];\1\n;g; s;((^|[^\\])(\\\\)*)\\([;,]);\4;g; tX;
110 s;'\'';'\'\\\\\'\'';g
111 s;^.*$;value='\''&'\'';
120 | while read -r line; do
123 value*) eval "$line";;
126 if [ -z "$key" ]; then
129 values[$key]="$value"
130 for t in ${(k)tag}; do
131 values[${key}_$t]="$tag[$t]"
134 if [ -n "$values[$key]" ]; then
136 while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
147 view_course() { #Parameter: Calendarfile
149 calendarfile="$_DATA/ical/${id}"
150 cachefile="$_DATA/cache/${id}.cache"
152 if [ "$cachefile" -nt "$calendarfile" ]; then
156 ics_parse "$calendarfile"
157 . ${_EXEC}/templates/view_course.sh |tee "$cachefile"
161 edit_course() { #Parameter: Calendarfile
163 calendarfile="$_DATA/ical/$id"
164 tempfile="$_DATA/temp/$id"
165 [ -f "$tempfile" ] && calendarfile="$tempfile"
169 ics_parse "$calendarfile"
170 . ${_EXEC}/templates/edit_course.sh