case "${_POST[choice]}"; in
new_filter)
- filter="${_POST[filter]}"
- filtertype="${_POST[filtertype]}"
+ for n in '' {0..100}; do
+ debug "N: $n; ${_POST[filter$n]}"
+ [ -z "${_POST[filter$n]+x}" ] && break
+ filterval="${_POST[filter$n]}"
+ filtertype="${_POST[filtertype$n]}"
+ filter="${filtertype}:${filterval}${filter+^${filter}}"
+ done
order="${_POST[order]}"
- echo -n "Location: ?p=cards&filter=$filter&filtertype=$filtertype&order=$order\n\n"
+ echo -n "Location: ?p=cards&filter=$filter&filtertype=advanced&order=$order\n\n"
;;
+ #new_filter)
+ # filter="${_POST[filter]}"
+ # filtertype="${_POST[filtertype]}"
+ # order="${_POST[order]}"
+ # echo -n "Location: ?p=cards&filter=$filter&filtertype=$filtertype&order=$order\n\n"
+ # ;;
*)
echo -n "Location: ?p=cards\n\n"
;;
}
listcards() {
- case "${_GET[filtertype]}" in
- any)
- grep -il "${_GET[filter]}" ${_DATA}/vcard/*vcf
- ;;
- name)
- egrep -xil "(FN|NICKNAME|N)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
- ;;
- street)
- egrep -xil "(ADR)(;.+)*:([^;]*;){2}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
- ;;
- zip)
- egrep -xil "(ADR)(;.+)*:([^;]*;){5}${_GET[filter]}.*" ${_DATA}/vcard/*vcf
- ;;
- telephone)
- egrep -xil "(TEL)(;.+)*:.*${_GET[filter]}.*" ${_DATA}/vcard/*vcf
- ;;
- birth)
- egrep -xil "(BDAY)(;.+)*:${_GET[filter]}.*" ${_DATA}/vcard/*vcf
- ;;
- course)
- ;;
- *) ls -1 ${_DATA}/vcard/*vcf 2>/dev/null
- ;;
- esac |case "${_GET[order]}" in
- firstname)
- while read file; do
- fn=$(sed -rn 's:^N(;.+)*\:([^;]*;){1} *([^;]*).*$:\3:p' "$file")
- echo "$fn\t$file"
- done
- ;;
- lastname)
- while read file; do
- ln=$(sed -rn 's:^N(;.+)*\:([^;]*;){0} *([^;]*).*$:\3:p' "$file")
- echo "$ln\t$file"
- done
- ;;
- bdate)
- while read file; do
- bd=$(sed -rn 's:^BDAY(;.+)*\:(.*)$:\2:p' "$file")
- echo "$bd\t$file"
- done
- ;;
- *)
- sed -r 's:^.*$:x\t&:'
- ;;
- esac |sort |sed -r 's:^.*\t(.*/)([^/]+)$:\2:'
+ 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}"'/{'"${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;^(.*/)*;;;'
}
vcf_parse() {
# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
check_type(){
- [ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"'
+ #[ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"'
+ [ "${_GET[filter]%%:*}" = "$1" ] && echo 'checked="checked"'
}
check_order(){
[ "${_GET[order]}" = "$1" ] && echo 'checked="checked"'
<input id="zip" type="radio" name="filtertype" value="zip" $(check_type zip)>
<label for="zip">$(l10n filter_zip)</label>
- <input id="telephone" type="radio" name="filtertype" value="telephone" $(check_type telephone)>
+ <input id="telephone" type="radio" name="filtertype" value="TEL" $(check_type TEL)>
<label for="telephone">$(l10n filter_phone)</label>
- <input id="birth" type="radio" name="filtertype" value="birth" $(check_type birth)>
+ <input id="birth" type="radio" name="filtertype" value="BDAY" $(check_type BDAY)>
<label for="birth">$(l10n filter_birthyear)</label>
+<!--
${profile_circus:+
<input id="course" type="radio" name="filtertype" value="course" $(check_type course)>
<label for="course">$(l10n filter_course)</label>
}
+-->
- <input type="text" name="filter" value="${_GET[filter]}" placeholder="$(l10n filter_placeholder)"/>
+ <input type="text" name="filter" value="${_GET[filter]#*:}" placeholder="$(l10n filter_placeholder)"/>
</fieldset>
<fieldset class="order">