]> git.plutz.net Git - confetti/blob - cards/edit_card.template.sh
editing interface
[confetti] / cards / edit_card.template.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 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 check_c() {
31   for n in CATEGORIES CATEGORIES{0..100}; do
32     if [ -n "${values[$n]+x}" ]; then
33       [ "${values[$n]}" = "$1" ] && setchecked && break
34     else
35       break
36     fi
37   done
38 }
39
40 teltype() {
41   cat <<-EOF
42         <select class="item phonetype" name="phonetype">
43           <option value="" disabled="disabled" $([ -z "$1" ] && setselected )>$(l10n phone_typeselect)</option>
44           <option value=""></option>
45           <option value="HOME" $([ "$1" = HOME ] && setselected)>$(l10n phone_home)</option>
46           <option value="CELL" $([ "$1" = CELL ] && setselected)>$(l10n phone_cell)</option>
47           <option value="WORK" $([ "$1" = WORK ] && setselected)>$(l10n phone_work)</option>
48           <option value="FAX"  $([ "$1" = FAX  ] && setselected)>$(l10n phone_fax )</option>
49         </select>
50         EOF
51 }
52
53 list_items(){
54   item="$1"
55   placeholder="$2"
56   [ -n "${values[$item]+x}" ] && printf '<h3>%s</h3>\n' "$(l10n $item)"
57   for n in "$item" "$item"{0..100}; do
58     if [ -n "${values[$n]+x}" ]; then
59       case "$item" in
60         (ADR|NOTE)
61           printf '<textarea class="item %s" name="%s">%s</textarea>\n' \
62             "$item" "$item" "$(htmlsafe ${values[$n]})"
63           ;;
64         (TEL)
65           teltype "${values[${n}_TYPE]}"
66           printf '<input class="item %s" name="%s" value="%s" />\n' \
67             "$item" "$item" "$(attribsafe ${values[$n]})"
68           ;;
69         (*)
70           printf '<input class="item %s" name="%s" value="%s" placeholder="%s"/>\n' \
71             "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder"
72           ;;
73       esac
74     else
75       break
76     fi
77   done
78 }
79
80 list_section(){
81   printf '<div class="section %s">' "$1"
82   shift 1
83   for each in $@; do
84     list_items "$each"
85   done
86   printf '</div>'
87 }
88
89 hi_company="${values[X-HEALTH-INSURANCE+0]}"
90  hi_number="${values[X-HEALTH-INSURANCE+1]}"
91  hi_status="${values[X-HEALTH-INSURANCE+2]}"
92
93 [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
94
95 cat <<END_HTML
96 <form id="$id" class="card" action="?action=update_card" method="POST">
97   <input type="hidden" name="card" value="${id}"/>
98   <div class="section basic">
99     <h3>$(l10n N)</h3>
100     <input class="item N" name="3N" placeholder="$(l10n n_pre)" value="$values[N+3]" />
101     <input class="item N" name="1N" placeholder="$(l10n n_first)" value="$values[N+1]" />
102     <input class="item N" name="2N" placeholder="$(l10n n_middle)" value="$values[N+2]" />
103     <input class="item N" name="0N" placeholder="$(l10n n_last)" value="$values[N+0]" />
104     <input class="item N" name="4N" placeholder="$(l10n n_post)" value="$values[N+4]" />
105
106     <select class="item GENDER" name="GENDER">
107       <option value="" disabled="disabled">$(l10n GENDER)</option>
108       <option value="female" $(check_gen female)>$(l10n gender_female)</option>
109       <option value="male" $(check_gen male)>$(l10n gender_male)</option>
110       <option value="other" $(check_gen other)>$(l10n gender_other)</option>
111       <option value="none" $(check_gen none)>$(l10n gender_none)</option>
112     </select>
113 END_HTML
114
115     for n in NICKNAME NICKNAME{0..100}; do
116       [ -z "${values[$n]+x}" ] && break \
117       || printf '
118           <input class="item NICKNAME" name="NICKNAME" value="%s" placeholder="%s"/>
119       ' "$(attribsafe ${values[$n]})" "$(l10n NICKNAME)"
120     done
121
122     list_items BDAY YYYY-MM-DD
123     list_items X-ZACK-JOINDATE YYYY-MM-DD
124     list_items X-ZACK-LEAVEDATE YYYY-MM-DD
125
126     [ -n "$values[SOUND]" ] && printf '
127       <audio controls="controls" class="item SOUND">
128         <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
129       </audio>' "$values[SOUND]"
130
131     [ -n "$values[PHOTO]" ] && printf '
132       <img class="item PHOTO" src="data:image/%s;base64,%s" />
133       ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
134
135     [ -n "$values[LOGO]" ] && printf '
136       <img class="item PHOTO" src="data:image/%s;base64,%s" />
137       ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
138
139 printf '</div>'
140
141 if [ "$PROFILE" = circus ]; then
142   list_section phone TEL
143   list_section message EMAIL IMPP URL
144   list_section address ADR
145   list_section note NOTE X-CLIENT-REFERRAL
146   cat <<-END_HTML
147         <div class="section attendance">
148           <h3>$(l10n course_attendance)</h3>
149           $(listcourses |while read each; do
150             cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
151             printf '<label><input type="checkbox" name="attendance" value="%s" %s/>%s</label>' \
152               "$(attribsafe "$each")" "$(check_a "$each")" "$(htmlsafe "$cname")"
153           done)
154           <h3>$(l10n CATEGORIES)</h3>
155           $(list_categories |while read each; do
156             printf '<label><input type="checkbox" name="CATEGORIES" value="%s" %s/>%s</label>' \
157               "$(attribsafe "$each")" "$(check_c "$each")" "$(htmlsafe "$each")"
158           done)
159         </div>
160         END_HTML
161 elif [ "$PROFILE" = medical ]; then
162   list_section address ADR
163   list_section phone TEL EMAIL IMPP URL
164   cat <<-END_HTML
165         <div class="section insurance">
166           <h3>$(l10n X-HEALTH-INSURANCE)</h3>
167           <input type="radio" name="hi_select" value="list" id="hi_select_list" checked /><label for="hi_select_list">$(l10n hi_from_list)</label
168           ><input type="radio" name="hi_select" value="other" id="hi_other"><label for="hi_other">$(l10n hi_other)</label>
169           <select class="item" name="hi_company">
170             <option value="" disabled="disabled" ${hi_company:-selected}>$(l10n hi_company)</option>
171             $(list_hi_companies |while read -r f; do
172               printf '<option value="%s" %s>%s</option>
173               '  "$(attribsafe "$f")" "$([ "$f" = "$hi_company" ] && setselected )" "$(htmlsafe "$f")"
174             done)
175           </select>
176           <input type="text" name="hi_other" value="$hi_company" placeholder="$(l10n hi_company)" />
177           <input name="hi_number" value="$hi_number" placeholder="$(l10n hi_number)" />
178           <input name="hi_status" value="$hi_status" placeholder="$(l10n hi_status)" />
179         </div>
180         END_HTML
181   list_section note NOTE X-CLIENT-REFERRAL
182 fi
183
184
185 cat <<END_HTML
186   <div class="control">
187     <select class="item" name="newfield">
188       <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
189       $(for f in $SUP_FIELDS; do printf '<option value="%s">%s</option>\n' "$f" "$(l10n "$f")"; done)
190     </select
191     ><button class="item" type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
192     <button class="item" type="submit" name="action" value="update">$(l10n edit_update)</button>
193     <input type="checkbox" id="delete"><label class="item" for="delete">$(l10n edit_delete)</label>
194       <button class="item" type="submit" name="action" value="delete">$(l10n edit_delete)</button>
195     <button class="item" type="submit" name="action" value="cancel">$(l10n edit_cancel)</button>
196   </div>
197   <input type="hidden" name="UID" value="$values[UID]"/>
198 </form>
199 END_HTML