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