]> git.plutz.net Git - confetti/blob - templates/view_card.sh
Lobster: time sheet on therapy note
[confetti] / templates / view_card.sh
1 # Copyright 2014 - 2017 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 list_items(){
19   item="$1"
20   [ -n "${values[$item]+x}" ] && \
21     printf '<h3>%s</h3>\n' "$(l10n $item)"
22   for n in "$item" "$item"{0..100}; do
23     if [ -z "${values[$n]+x}" ]; then
24       break
25     else case "$item" in
26       EMAIL)
27         printf '<a class="item EMAIL" href="mailto:%s">%s</a>\n' \
28           "$(attribsafe "${values[$n]}")" "$(htmlsafe "${values[$n]}")"
29         ;;
30       *)
31         printf '<span class="item %s">%s</span>\n' \
32           "$item" "$(htmlsafe ${values[$n]})"
33         ;;
34     esac; fi
35   done
36 }
37
38 list_section(){
39   printf '<div class="section %s">' "$1"
40   shift 1
41   for each in $@; do
42     list_items "$each"
43   done
44   printf '</div>'
45 }
46
47 n=$(printf %s "$values[N+3] $values[N+1] $values[N+2] $values[N+0] $values[N+4]" \
48     | sed -r ':X;$!{N;bX}; s;^[\n ]+;;; s;[\n ]+$;;; s;[\r\t\n ]+; ;g;'
49    )
50 fullname="${n:-${values[FN]:-${values[NICKNAME]}}}"
51
52 hi_company="${values[X-HEALTH-INSURANCE+0]}"
53  hi_number="${values[X-HEALTH-INSURANCE+1]}"
54  hi_status="${values[X-HEALTH-INSURANCE+2]}"
55
56 printf '<div class="section basic">
57     <h2 class="item FN">%s</h2>
58 ' "$fullname"
59 [ -n "$values[GENDER]" ] && printf '
60   <span class="item GENDER">%s</span>
61   ' "$(l10n "$values[GENDER]")"
62
63 for n in NICKNAME NICKNAME{0..100}; do
64   [ -z "${values[$n]+x}" ] && break \
65   || printf '
66       <span class="item NICKNAME">aka. %s</span>
67   ' "$(htmlsafe ${values[$n]})"
68 done
69
70 [ -n "$values[BDAY]" ] && printf '
71   <span class="item BDAY"><b>*:</b> %s</span>
72   ' "$(htmlsafe "$values[BDAY]")"
73 [ -n "$values[X-ZACK-JOINDATE]" ] && printf '
74   <span class="item X-ZACK-JOINDATE"><b>%s:</b> %s</span>
75   ' "$(l10n label_join)" "$(htmlsafe "$values[X-ZACK-JOINDATE]")"
76 [ -n "$values[X-ZACK-LEAVEDATE]" ] && printf '
77   <span class="item X-ZACK-LEAVEDATE"><b>%s:</b >%s</span>
78   ' "$(l10n label_leave)" "$(htmlsafe "$values[X-ZACK-LEAVEDATE]")"
79
80 [ -n "$values[SOUND]" ] && printf '
81   <audio controls="controls" class="item SOUND">
82     <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
83   </audio>' "$values[SOUND]"
84
85 [ -n "$values[PHOTO]" ] && printf '
86   <img class="item PHOTO" src="data:image/%s;base64,%s" />
87   ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
88
89 [ -n "$values[LOGO]" ] && printf '
90   <img class="item PHOTO" src="data:image/%s;base64,%s" />
91   ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
92
93 if [ "$PROFILE" = circus ]; then
94   printf '</div>'
95
96   list_section phone TEL
97   list_section message EMAIL IMPP URL
98   list_section address ADR
99   list_section note NOTE
100
101   printf '<div class="section attendance"><h3>%s</h3><ul>' "$(l10n course_attendance)"
102   sed -rn 's:(.*)\t'"$id"'$:\1:p' "$_DATA/mappings/attendance" |while read each; do
103     cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
104     printf '   <li><a class="item attendance" href="?p=courses#%s">%s</a></li>' "$each" "$(htmlsafe $cname)"
105   done
106   printf '</ul>'
107   list_items CATEGORIES
108   printf '</div>'
109
110 elif [ "$PROFILE" = medical ]; then
111   list_items ADR
112   list_items URL
113   printf '</div>'
114
115   list_section phone TEL EMAIL IMPP
116
117   printf '<div class="section insurance"><h3>%s</h3>' "$(l10n X-HEALTH-INSURANCE)"
118   [ -n "$hi_company" ] && printf '<span class="item hi_comapany">%s</span>' \
119     "$(htmlsafe "$hi_company")"
120   [ -n "$hi_number" ] && printf '<span class="item hi_number"><label>%s:</label> %s</span>' \
121     "$(l10n hi_number)" "$(htmlsafe "$hi_number")"
122   [ -n "$hi_status" ] && printf '<span class="item hi_status"><label>%s:</label> %s</span>' \
123     "$(l10n hi_status)" "$(htmlsafe "$hi_status")"
124   printf '</div>'
125
126   list_section note NOTE X-CLIENT-REFERRAL
127
128   printf '<div class="section prescriptions"><h3>%s</h3><ul>' "$(l10n prescriptions)"
129   declare -A mpx
130   find "$_DATA/prescriptions/" -name "${id%.vcf}.*.mpx" \
131   | while read pfile; do
132     mpx=(); cat "$pfile" |while read -r line; do
133       val="${line#*:}"
134       mpx[${line%%:*}]="$(htmlsafe "${val//\\n/$BR}")"
135     done
136     printf '<li><a href="?p=prescriptions&amp;client=%s#%s" >%s: %s - %s</a></li>' \
137       "${id}" "${pfile##*/}" "${mpx[date]}" "${mpx[indicator]}" \
138       "$([ -n "${mpx[remidy]}" ] && printf '%s %s' "${mpx[quantity]}" "${mpx[remidy]}" 
139          for n in {0..10}; do
140            [ -n "${mpx[remidy${n}]}" ] && printf ', %s %s' "${mpx[quantity${n}]}" "${mpx[remidy${n}]}" 
141          done
142        )"
143   done |sort -r
144   printf '</ul></div>'
145 fi