]> git.plutz.net Git - confetti/blob - templates/edit_client.sh
fix faulty escaping of line breaks
[confetti] / templates / edit_client.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 setchecked() {
19   printf 'checked="checked"'
20 }
21 setselected() {
22   printf 'selected="selected"'
23 }
24 check_gen() {
25   [ "$values[GENDER]" = "$1" ] && setselected
26 }
27 check_a() {
28   egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && setchecked
29 }
30 teltype() {
31   cat <<-EOF
32         <select class="item phonetype" name="phonetype">
33           <option value="" disabled="disabled" $([ -z "$1" ] && setselected )>$(l10n phone_typeselect)</option>
34           <option value=""></option>
35           <option value="HOME" $([ "$1" = HOME ] && setselected)>$(l10n phone_home)</option>
36           <option value="CELL" $([ "$1" = CELL ] && setselected)>$(l10n phone_cell)</option>
37           <option value="WORK" $([ "$1" = WORK ] && setselected)>$(l10n phone_work)</option>
38           <option value="FAX"  $([ "$1" = FAX  ] && setselected)>$(l10n phone_fax )</option>
39         </select>
40         EOF
41 }
42
43 list_items(){
44   item="$1"
45   placeholder="$2"
46   [ -n "${values[$item]+x}" ] && printf '<h3>%s</h3>\n' "$(l10n $item)"
47   for n in "$item" "$item"{0..100}; do
48     if [ -n "${values[$n]+x}" ]; then
49       case "$item" in
50         (ADR|NOTE)
51           printf '<textarea class="item %s" name="%s">%s</textarea>\n' \
52             "$item" "$item" "$(htmlsafe ${values[$n]})"
53           ;;
54         (TEL)
55           teltype "${values[${n}_TYPE]}"
56           printf '<input class="item %s" name="%s" value="%s" />\n' \
57             "$item" "$item" "$(attribsafe ${values[$n]})"
58           ;;
59         (*)
60           printf '<input class="item %s" name="%s" value="%s" placeholder="%s"/>\n' \
61             "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder"
62           ;;
63       esac
64     else
65       break
66     fi
67   done
68 }
69
70 hi_company="${values[X-HEALTH-INSURANCE+1]}"
71 hi_number= "${values[X-HEALTH-INSURANCE+2]}"
72 hi_status= "${values[X-HEALTH-INSURANCE+3]}"
73
74 [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
75
76 cat <<END_HTML
77 <form id="$id" class="card" action="?action=update_card" method="POST">
78   <input type="hidden" name="card" value="${id}"/>
79   <div class="section basic">
80     <h3>$(l10n N)</h3>
81     <input class="item N" name="3N" placeholder="$(l10n n_pre)" value="$values[N+3]" />
82     <input class="item N" name="1N" placeholder="$(l10n n_first)" value="$values[N+1]" />
83     <input class="item N" name="2N" placeholder="$(l10n n_middle)" value="$values[N+2]" />
84     <input class="item N" name="0N" placeholder="$(l10n n_last)" value="$values[N+0]" />
85     <input class="item N" name="4N" placeholder="$(l10n n_post)" value="$values[N+4]" />
86
87     <select class="item GENDER" name="GENDER">
88       <option value="" disabled="disabled">$(l10n GENDER)</option>
89       <option value="female" $(check_gen female)>$(l10n gender_female)</option>
90       <option value="male" $(check_gen male)>$(l10n gender_male)</option>
91       <option value="other" $(check_gen other)>$(l10n gender_other)</option>
92       <option value="none" $(check_gen none)>$(l10n gender_none)</option>
93     </select>
94
95     $(for n in NICKNAME NICKNAME{0..10}; do
96       printf %s\\n "${values[$n]+<input class="item NICKNAME" name="NICKNAME" placeholder="$(l10n NICKNAME)" value="$values[$n]" />}"
97     done)
98
99     $(list_items BDAY YYYY-MM-DD)
100
101     $(list_items X-ZACK-JOINDATE YYYY-MM-DD)
102     $(list_items X-ZACK-LEAVEDATE YYYY-MM-DD)
103
104     $([ -n "$values[SOUND]" ] && printf '
105       <audio controls="controls" class="item SOUND">
106         <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
107       </audio>' "$values[SOUND]"
108     )
109     ${values[PHOTO]+<img class="item PHOTO" src="data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]" />}
110     ${values[LOGO]+<img class="item LOGO" src="data:image/$values[LOGO_TYPE];base64,$values[LOGO]" />}
111   </div>
112
113   <div class="section address">
114     $(list_items ADR)
115   </div>
116
117   <div class="section phone">
118     $(list_items TEL)
119     $(list_items EMAIL)
120     $(list_items IMPP)
121     $(list_items URL)
122   </div>
123
124   <div class="section insurance">
125     <h3>$(l10n X-HEALTH-INSURANCE)</h3>
126     <input type="radio" name="hi_select" value="list" id="hi_select_list" checked /><label for="hi_select_list">$(l10n hi_from_list)</label><!--
127     --><input type="radio" name="hi_select" value="other" id="hi_other"><label for="hi_other">$(l10n hi_other)</label>
128     <select class="item" name="hi_company">
129       <option value="" disabled="disabled" ${hi_company:-selected}>$(l10n hi_company)</option>
130       $(list_hi_companies |while read f; do
131         [ "$f" = "$hi_company" ] \
132         && printf '<option value="%s" selected>%s</option>' "$f" "$f" \
133         || printf '<option value="%s">%s</option>' "$f" "$f"
134       done)
135     </select>
136     <input type="text" name="hi_other" value="$hi_company" placeholder="$(l10n hi_company)" />
137     <input name="hi_number" value="$hi_number" placeholder="$(l10n hi_number)" />
138     <input name="hi_status" value="$hi_status" placeholder="$(l10n hi_status)" />
139
140   </div>
141
142   <div class="section note">
143     $(list_items NOTE)
144     $(list_items X-CLIENT-REFERRAL)
145   </div>
146
147   <div class="control">
148     <select class="item" name="newfield">
149       <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
150       $(for f in $SUP_FIELDS; do printf %s\\n "<option value=\"$f\">$(l10n $f)</option>"; done)
151     </select
152     ><button class="item" type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
153     <button class="item" type="submit" name="action" value="update">$(l10n edit_update)</button>
154     <input type="checkbox" id="delete"><label class="item" for="delete">$(l10n edit_delete)</label>
155       <button class="item" type="submit" name="action" value="delete">$(l10n edit_delete)</button>
156     <button class="item" type="submit" name="action" value="cancel">$(l10n edit_cancel)</button>
157   </div>
158   <input type="hidden" name="UID" value="$values[UID]"/>
159 </form>
160 END_HTML