3 # Copyright 2014 - 2017 Paul Hänsch
5 # This file is part of Confetti.
7 # Confetti is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Confetti is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with Confetti. If not, see <http://www.gnu.org/licenses/>.
25 [ -z "${values[$each]+x}" ] && values[${each}]=''
31 SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL)
32 FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL)
33 _GET[order]="${_GET[order]:-lastname}"
34 _GET[filtertype]="${_GET[filtertype]:-name}"
38 SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE)
39 FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE)
40 _GET[order]="${_GET[order]:-firstname}"
41 _GET[filtertype]="${_GET[filtertype]:-any}"
47 [ \! -f "vcard/$edit" -a \! -f "temp/$edit" ] && edit=''
50 ls -1 ${_DATA}/ical/*ics |while read file; do
51 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")"
52 echo "$(date -d "$icstime" "+%u %H%M%S")\t$file"
53 done |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
57 sed -rn 's;^X-HEALTH-INSURANCE:([^\;]+)\;.*$;\1;p' ${_DATA}/vcard/*vcf \
62 catfile="${_DATA}/mappings/categories"
64 | sed -r '/^[\t ]*$/d'
68 filterex='s;^([^\n]+)\n.*$;\1;p'
69 printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \
70 | sed -r 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g' \
73 name:*) expr='(FN|NICKNAME|N)(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
74 street:*) expr='ADR(\;[^\n]+)*:([^\;]*;){2}[^\;\n]*'"(${each#*:})";;
75 zip:*) expr='ADR(\;[^\n]+)*:([^\;]*;){5}[^\;\n]*'"(${each#*:})";;
76 any:*|:*) expr="[^\n]*"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
77 *:*) expr="${each%%:*}"'(\;[^\n]+)*:[^\n]*'"(${each#*:})";;
80 filterex='/(^|\n)'"${expr}"'/I{'"${filterex}"'}'
83 for file in "${_DATA}/vcard/"*.vcf; do
84 case "${_GET[order]}" in
86 printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")" "$file"
89 printf '%s\t%s\n' "$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")" "$file"
92 printf '%s\t%s\n' "$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")" "$file"
94 *) printf 'x\t%s\n' "$file"
98 | sort -u |sed -r 's;^.*\t;;' \
100 { printf '%s\n' "$n"; cat "$n"; } \
101 | sed -rn ':X;N;$!bX; {'"$filterex"'}'
103 | sed -r 's;^(.*/)*;;;'
106 view_card() { #Parameter: Cardfile
108 cardfile="$_DATA/vcard/${id}"
109 cachefile="$_DATA/cache/${id}.cache"
110 if [ "$cachefile" -nt "$cardfile" ]; then
114 vcf_parse "$cardfile"
115 . "$_EXEC/templates/view_card.sh" |tee "$cachefile"
119 edit_card() { #Parameter: Cardfile
121 cardfile="$_DATA/vcard/$id"
122 tempfile="$_DATA/temp/$id"
123 [ -f "$tempfile" ] && cardfile="$tempfile"
126 vcf_parse "$cardfile"
127 force_items $FORCE_ITEMS
128 . "$_EXEC/templates/edit_card.sh"