]> git.plutz.net Git - confetti/blob - courses/view_course.sh
path handling and helper functions
[confetti] / courses / view_course.sh
1 # Copyright 2014 Paul Hänsch
2 #
3 # This file is part of Confetti.
4
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
10 # Confetti is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
17
18 dtstart="$values[DTSTART]"
19 [ -z "$dtstart" ] && dtstart=$(date +%Y%m%dT%H%M%S)
20
21 echo "$dtstart" |case "$dtstart" in
22   *Z)
23     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'
24     ;;
25   TZID*)
26     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'
27     ;;
28   *)
29     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'
30     ;;
31 esac |read dts_date
32
33 dts_year=$(date -d "$dts_date" +%Y)
34 dts_month=$(date -d "$dts_date" +%m)
35 dts_dom=$(date -d "$dts_date" +%d)
36 dts_dow=$(date -d "$dts_date" +%u)
37 dts_weekday=$(date -d "$dts_date" +%A)
38 dts_hour=$(date -d "$dts_date" +%H)
39 dts_min=$(date -d "$dts_date" +%M)
40 dts_sec=$(date -d "$dts_date" +%S)
41
42 rrule="$values[RRULE]"
43 rr_int="$(echo $rrule |sed -rn 's:^.*INTERVAL=([0-9]+)(;.*)?$:\1:p')"
44 rr_count="$(echo $rrule |sed -rn 's:^.*COUNT=([0-9]+)(;.*)?$:\1:p')"
45 rr_freq="$(echo $rrule |sed -rn 's:^.*FREQ=(YEARLY|MONTHLY|WEEKLY|DAILY)(;.*)?$:\1:p')"
46 rr_uyear="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\1:p')"
47 rr_umonth="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\2:p')"
48 rr_uday="$(echo $rrule |sed -rn 's:^.*UNTIL=([0-9]{4})([0-9]{2})([0-9]{2})T[0-9]{6}Z(;.*)?$:\3:p')"
49 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')"
50 if [ -n "$rr_count" ]; then
51   rr_limit=COUNT
52 elif [ -n "$rr_uyear" ]; then
53   rr_limit=UNTIL
54 else
55   rr_limit=ETERN
56 fi
57
58 coursemail=""
59
60 echo '<div id="'${id}'" class="course">'
61 echo '<form action="?action=update_course" method="POST">'
62 echo '<input type="hidden" name="course" value="'${id}'"/>'
63 echo '  <div class="section basic">'
64 echo '    <h2>'$values[SUMMARY]'</h2>'
65 echo '    <span class="text">'$(date -d "$dts_date" "+%A %B %d, %Y - %H:%M") $(l10n t_oclock)'</span>'
66 [ "$rr_int" -eq 1 ] \
67 && echo '<span class="text">'$(l10n s$rr_freq)'</span>' \
68 || echo '<span class="text">'$(l10n t_every) ${rr_int} $(l10n $rr_freq)'</span>'
69 case "$rr_limit" in
70   COUNT)
71     m1=$(echo $rr_freq |sed -r "s:DAILY:day:g;s:WEEKLY:week:g;s:MONTHLY:month:g;s:YEARLY:year:g;")
72     m2=$(($rr_int * $rr_count))
73     echo '<span class="text">'$(l10n t_until) $(date -d "$dts_date + $m2 $m1" "+%A %B %d, %Y - %H:%M")'</span>'
74     ;;
75   UNTIL)
76     echo '<span class="text">'$(l10n t_until) $(date -d "$rr_udate" "+%A %B %d, %Y - %H:%M")'</span>'
77     ;;
78 esac
79 echo '  </div>'
80
81 echo '  <div class="section COMMENT">'
82 echo '    <h3>'$(l10n COMMENT)'</h3>'
83 for n in COMMENT COMMENT{0..10}; do [ -n "$values[$n]" ] &&\
84   echo '    <p class="item COMMENT">'$(echo "$values[$n]" |sed -r "s:$:<br/>:g" )'</p>'
85 done
86 echo '  </div>'
87
88 echo '  <div class="section attendance">'
89 echo '    <h3>'$(l10n course_attendance)'</h3>'
90 list_attendance "$id" |sort -k 2 |sed -r 's:^([^ ]+) (.*)$:<a class="attendance" href="?p=cards#\1">\2</a>:'
91 echo '  </div>'
92
93 echo '  <div class="control">'
94 echo '    <a class="item" href="?action=edit_course&course='${id}'">'$(l10n edit)'</a>'
95 echo '    <a class="item" href="?action=generate_courselist&course='${id}'" target="_blank">'$(l10n courselist)'</a>'
96 echo '    <a class="item" href="?action=export_ical&course='${id}'">'$(l10n ics_export)'</a>'
97 echo '    <a class="item" href="mailto:zack@vuesch.org?bcc='$(course_mail "$id")'">'$(l10n course_mail)'</a>'
98 echo '  </div>'
99 echo '<input type="hidden" name="UID" value="'$values["UID"]'"/>'
100 echo '</form>'
101 echo '</div>'
102