+++ /dev/null
-#!/bin/zsh
-
-# Copyright 2014 - 2017 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/>.
-
-BR='
-'
-
-force_items(){
- for each in "$@"; do
- [ -z "${values[$each]+x}" ] && values[${each}]=''
- done
-}
-
-case $PROFILE in
-medical)
- SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL)
- FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL)
- _GET[order]="${_GET[order]:-lastname}"
- _GET[filtertype]="${_GET[filtertype]:-name}"
- profile_medical=x
-;;
-circus)
- SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE)
- FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE)
- _GET[order]="${_GET[order]:-firstname}"
- _GET[filtertype]="${_GET[filtertype]:-any}"
- profile_circus=x
-;;
-esac
-
-edit="${_GET[edit]}"
-[ \! -f "vcard/$edit" -a \! -f "temp/$edit" ] && edit=''
-
-listcourses() {
- ls -1 ${_DATA}/ical/*ics |while read file; do
- icstime="$(sed -rn 's:^DTSTART\:(TZID=.*\:)?([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z?\r$:\2-\3-\4 \5\:\6\:\7:p' "$file")"
- echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
- done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
-}
-
-list_hi_companies(){
- sed -rn 's;^X-HEALTH-INSURANCE:([^\;]+)\;.*$;\1;p' ${_DATA}/vcard/*vcf \
- | sort -u
-}
-
-list_categories() {
- catfile="${_DATA}/mappings/categories"
- sort -u "$catfile" \
- | sed -r '/^[\t ]*$/d'
-}
-
-listcards() {
- filterex='s;^([^\n]+)\n.*$;\1;p'
- printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \
- | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \
- | while read each; do
- case $each in
- name:*) expr='(FN|NICKNAME|N)(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
- street:*) expr='ADR(\;[^\n]+)*:([^\;]*;){2}[^\;\n]*'"(${each#*:})";;
- zip:*) expr='ADR(\;[^\n]+)*:([^\;]*;){5}[^\;\n]*'"(${each#*:})";;
- any:*|:*) expr="[^\n]*"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
- *:*) expr="${each%%:*}"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
- *) expr="(${each})";;
- esac
- filterex='/(^|\n)'"${expr}"'/I{'"${filterex}"'}'
- done
-
- for file in "${_DATA}/vcard/"*.vcf; do
- case "${_GET[order]}" in
- firstname)
- printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" "$file"
- ;;
- lastname)
- printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")" "$file"
- ;;
- bdate)
- printf '%s\t%s\n' "$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")" "$file"
- ;;
- *) printf 'x\t%s\n' "$file"
- ;;
- esac
- done \
- | sort -u |sed -r 's;^.*\t;;' \
- | while read n; do
- { printf '%s\n' "$n"; cat "$n"; } \
- | sed -rn ':X;N;$!bX; {'"$filterex"'}'
- done \
- | sed -r 's;^(.*/)*;;;'
-}
-
-view_card() { #Parameter: Cardfile
- id="$1"
- cardfile="$_DATA/vcard/${id}"
- cachefile="$_DATA/cache/${id}.cache"
- if [ "$cachefile" -nt "$cardfile" ]; then
- cat "$cachefile"
- else
- declare -A values
- vcf_parse "$cardfile"
- . "$_EXEC/templates/view_card.sh" |tee "$cachefile"
- fi
-}
-
-edit_card() { #Parameter: Cardfile
- id="$1"
- cardfile="$_DATA/vcard/$id"
- tempfile="$_DATA/temp/$id"
- [ -f "$tempfile" ] && cardfile="$tempfile"
-
- declare -A values
- vcf_parse "$cardfile"
- force_items $FORCE_ITEMS
- . "$_EXEC/templates/edit_card.sh"
-}
+++ /dev/null
-# Copyright 2014 - 2017 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
-}
-check_c() {
- for n in CATEGORIES CATEGORIES{0..100}; do
- if [ -n "${values[$n]+x}" ]; then
- [ "${values[$n]}" = "$1" ] && setchecked && break
- else
- break
- fi
- done
-}
-
-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
-}
-
-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+0]}"
- hi_number="${values[X-HEALTH-INSURANCE+1]}"
- hi_status="${values[X-HEALTH-INSURANCE+2]}"
-
-[ -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)
- <h3>$(l10n CATEGORIES)</h3>
- $(list_categories |while read each; do
- printf '<label><input type="checkbox" name="CATEGORIES" value="%s" %s/>%s</label>' \
- "$(attribsafe "$each")" "$(check_c "$each")" "$(htmlsafe "$each")"
- 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