-edit_card_item() {
- case "$key" in
- BEGIN|VERSION|END);;
- PHOTO)
- echo "<img class=\"PHOTO\" src=\"data:image/$tag[TYPE];base64,$value\"/>"
- ;;
- *)
- echo -n "<span class=\"item\"><span class=\"KEY\">$(l10n "$key")"
- [ -n "$tag[TYPE]" ] && echo -n "($tag[TYPE])"
- echo ":</span>"
- ;|
- *)
- echo "<input class=\"VALUE\" name=\"$key\" value=\"$value\" /></item>"
- ;;
- esac
+# Copyright 2014 - 2016 Paul Hänsch
+#
+# This file is part of Confetti.
+#
+# Confetti is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Confetti is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
+
+setchecked() {
+ printf 'checked="checked"'
+}
+setselected() {
+ printf 'selected="selected"'
+}
+check_gen() {
+ [ "$values[GENDER]" = "$1" ] && setselected
+}
+check_a() {
+ egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && setchecked
+}
+teltype() {
+ cat <<-EOF
+ <select class="item phonetype" name="phonetype">
+ <option value="" disabled="disabled" $([ -z "$1" ] && setselected )>$(l10n phone_typeselect)</option>
+ <option value=""></option>
+ <option value="HOME" $([ "$1" = HOME ] && setselected)>$(l10n phone_home)</option>
+ <option value="CELL" $([ "$1" = CELL ] && setselected)>$(l10n phone_cell)</option>
+ <option value="WORK" $([ "$1" = WORK ] && setselected)>$(l10n phone_work)</option>
+ <option value="FAX" $([ "$1" = FAX ] && setselected)>$(l10n phone_fax )</option>
+ </select>
+ EOF
}
-edit_attendee() {
- cardfile="$1"
- unset key
- vcf_parse "$cardfile" |while read -r line; do
- declare -A tag
- case "$line" in
- value*) eval "$line";;
- tag*) eval "$line";;
- key*)
- if [ -z "$key" ]; then
- eval "$line"
- else
- edit_card_item
- eval "$line"
- unset value
- unset tag
- fi
- ;;
- esac
+list_items(){
+ item="$1"
+ placeholder="$2"
+ [ -n "${values[$item]+x}" ] && printf '<h3>%s</h3>\n' "$(l10n $item)"
+ for n in "$item" "$item"{0..100}; do
+ if [ -n "${values[$n]+x}" ]; then
+ case "$item" in
+ (ADR|NOTE)
+ printf '<textarea class="item %s" name="%s">%s</textarea>\n' \
+ "$item" "$item" "$(htmlsafe ${values[$n]})"
+ ;;
+ (TEL)
+ teltype "${values[${n}_TYPE]}"
+ printf '<input class="item %s" name="%s" value="%s" />\n' \
+ "$item" "$item" "$(attribsafe ${values[$n]})"
+ ;;
+ (*)
+ printf '<input class="item %s" name="%s" value="%s" placeholder="%s"/>\n' \
+ "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder"
+ ;;
+ esac
+ else
+ break
+ fi
done
}
+
+list_section(){
+ printf '<div class="section %s">' "$1"
+ shift 1
+ for each in $@; do
+ list_items "$each"
+ done
+ printf '</div>'
+}
+
+hi_company="${values[X-HEALTH-INSURANCE+1]}"
+ hi_number="${values[X-HEALTH-INSURANCE+2]}"
+ hi_status="${values[X-HEALTH-INSURANCE+3]}"
+
+[ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
+
+cat <<END_HTML
+<form id="$id" class="card" action="?action=update_card" method="POST">
+ <input type="hidden" name="card" value="${id}"/>
+ <div class="section basic">
+ <h3>$(l10n N)</h3>
+ <input class="item N" name="3N" placeholder="$(l10n n_pre)" value="$values[N+3]" />
+ <input class="item N" name="1N" placeholder="$(l10n n_first)" value="$values[N+1]" />
+ <input class="item N" name="2N" placeholder="$(l10n n_middle)" value="$values[N+2]" />
+ <input class="item N" name="0N" placeholder="$(l10n n_last)" value="$values[N+0]" />
+ <input class="item N" name="4N" placeholder="$(l10n n_post)" value="$values[N+4]" />
+
+ <select class="item GENDER" name="GENDER">
+ <option value="" disabled="disabled">$(l10n GENDER)</option>
+ <option value="female" $(check_gen female)>$(l10n gender_female)</option>
+ <option value="male" $(check_gen male)>$(l10n gender_male)</option>
+ <option value="other" $(check_gen other)>$(l10n gender_other)</option>
+ <option value="none" $(check_gen none)>$(l10n gender_none)</option>
+ </select>
+END_HTML
+
+ for n in NICKNAME NICKNAME{0..100}; do
+ [ -z "${values[$n]+x}" ] && break \
+ || printf '
+ <input class="item NICKNAME" name="NICKNAME" value="%s" placeholder="%s"/>
+ ' "$(attribsafe ${values[$n]})" "$(l10n NICKNAME)"
+ done
+
+ list_items BDAY YYYY-MM-DD
+ list_items X-ZACK-JOINDATE YYYY-MM-DD
+ list_items X-ZACK-LEAVEDATE YYYY-MM-DD
+
+ [ -n "$values[SOUND]" ] && printf '
+ <audio controls="controls" class="item SOUND">
+ <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
+ </audio>' "$values[SOUND]"
+
+ [ -n "$values[PHOTO]" ] && printf '
+ <img class="item PHOTO" src="data:image/%s;base64,%s" />
+ ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
+
+ [ -n "$values[LOGO]" ] && printf '
+ <img class="item PHOTO" src="data:image/%s;base64,%s" />
+ ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
+
+printf '</div>'
+
+if [ "$PROFILE" = circus ]; then
+ list_section phone TEL
+ list_section message EMAIL IMPP URL
+ list_section address ADR
+ list_section note NOTE X-CLIENT-REFERRAL
+ cat <<-END_HTML
+ <div class="section attendance">
+ <h3>$(l10n course_attendance)</h3>
+ $(listcourses |while read each; do
+ cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
+ printf '<label><input type="checkbox" name="attendance" value="%s" %s/>%s</label>' \
+ "$(attribsafe "$each")" "$(check_a "$each")" "$(htmlsafe "$cname")"
+ done)
+ </div>
+ END_HTML
+elif [ "$PROFILE" = medical ]; then
+ list_section address ADR
+ list_section phone TEL EMAIL IMPP URL
+ cat <<-END_HTML
+ <div class="section insurance">
+ <h3>$(l10n X-HEALTH-INSURANCE)</h3>
+ <input type="radio" name="hi_select" value="list" id="hi_select_list" checked /><label for="hi_select_list">$(l10n hi_from_list)</label
+ ><input type="radio" name="hi_select" value="other" id="hi_other"><label for="hi_other">$(l10n hi_other)</label>
+ <select class="item" name="hi_company">
+ <option value="" disabled="disabled" ${hi_company:-selected}>$(l10n hi_company)</option>
+ $(list_hi_companies |while read -r f; do
+ printf '<option value="%s" %s>%s</option>
+ ' "$(attribsafe "$f")" "$([ "$f" = "$hi_company" ] && setselected )" "$(htmlsafe "$f")"
+ done)
+ </select>
+ <input type="text" name="hi_other" value="$hi_company" placeholder="$(l10n hi_company)" />
+ <input name="hi_number" value="$hi_number" placeholder="$(l10n hi_number)" />
+ <input name="hi_status" value="$hi_status" placeholder="$(l10n hi_status)" />
+ </div>
+ END_HTML
+ list_section note NOTE X-CLIENT-REFERRAL
+fi
+
+
+cat <<END_HTML
+ <div class="control">
+ <select class="item" name="newfield">
+ <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
+ $(for f in $SUP_FIELDS; do printf '<option value="%s">%s</option>\n' "$f" "$(l10n "$f")"; done)
+ </select
+ ><button class="item" type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
+ <button class="item" type="submit" name="action" value="update">$(l10n edit_update)</button>
+ <input type="checkbox" id="delete"><label class="item" for="delete">$(l10n edit_delete)</label>
+ <button class="item" type="submit" name="action" value="delete">$(l10n edit_delete)</button>
+ <button class="item" type="submit" name="action" value="cancel">$(l10n edit_cancel)</button>
+ </div>
+ <input type="hidden" name="UID" value="$values[UID]"/>
+</form>
+END_HTML