#!/bin/zsh
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2017 Paul Hänsch
#
# This file is part of Confetti.
#
cgi_post
-case "${_POST[choice]}"; in
- new_filter)
- 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=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"
- ;;
-esac
+if [ "${_POST[choice]}" = new_filter ]; then
+ filter="$(
+ for n in filter{0..100}; do
+ # [ -z "${_POST[$n]:+x}" ] && break
+ printf %s "${_POST[$n]}"
+ done \
+ | sed -r 's;\|+;\|;g; s;\^+;\^;g; s;:\|;:;g; :X; s;\^[^:]*:\^;\^;g; /\^[^:]*:\^/bX; s;^\^;;; s;\^[^:]*:$;;;'
+ )"
+ printf 'Location: ?p=cards&order=%s&filter=%s\n\n' "${_POST[order]}" "$filter"
+else
+ printf 'Location: ?p=cards\n\n'
+fi
/*
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
#
# This file is part of Confetti.
#
.filter fieldset.item { padding-left: 0; }
.filter fieldset.item legend { display: none; }
-.filter fieldset.item input[type=text] {
+.filter fieldset.item input[type=text],
+.filter fieldset.item fieldset.categories {
background-color: #FFF;
border: 1px solid #000;
margin-top: -1px;
border: 1px solid #000;
border-bottom-color: #FFF;
}
+.filter fieldset.item input[type=radio][value="CATEGORIES:"]:checked + label + input[type=text],
+.filter fieldset.item input[type=radio][value="CATEGORIES:"] + label + input[type=text] + fieldset.categories {
+ display: none;
+}
+.filter fieldset.item input[type=radio][value="CATEGORIES:"]:checked + label + input[type=text] + fieldset.categories {
+ display: block;
+}
+.filter fieldset.item fieldset.categories a {
+ font-size: .875em;
+ line-height: 1.625em;
+ color: #44C;
+}
.newcard {
display: block;
-# Copyright 2014 - 2016 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
#
# This file is part of Confetti.
#
# 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"'
+}
check_type(){
- #[ "${_GET[filtertype]}" = "$1" ] && echo 'checked="checked"'
- [ "${_GET[filter]%%:*}" = "$1" ] && echo 'checked="checked"'
+ [ "${_GET[filter]%%:*}" = "$1" ] && setchecked
}
check_order(){
- [ "${_GET[order]}" = "$1" ] && echo 'checked="checked"'
+ [ "${_GET[order]}" = "$1" ] && setchecked
}
+filter_item() {
cat <<EOF
-<form class="filter" action="?action=filter_card" method="POST">
- <h1>$(l10n filter_label)</h1>
- <input type="hidden" name="page" value="cards"/>
<fieldset class="item">
- <legend>$(l10n filter_item):</legend>
- <input id="any" type="radio" name="filtertype" value="any" $(check_type any)>
- <label for="any" >$(l10n filter_all)</label>
+ <legend>$(l10n filter_item):</legend>
+ <input type="hidden" name="filter${n}" value="^"/>
- <input id="name" type="radio" name="filtertype" value="name" $(check_type name)>
- <label for="name">$(l10n filter_name)</label>
+ <input id="any$n" type="radio" name="filter$((n + 1))" value="any:" $([ "$1" = any ] && setchecked)>
+ <label for="any$n" >$(l10n filter_all)</label>
- <input id="street" type="radio" name="filtertype" value="street" $(check_type street)>
- <label for="street">$(l10n filter_street)</label>
+ <input id="name$n" type="radio" name="filter$((n + 1))" value="name:" $([ "$1" = name ] && setchecked)>
+ <label for="name$n">$(l10n filter_name)</label>
- <input id="zip" type="radio" name="filtertype" value="zip" $(check_type zip)>
- <label for="zip">$(l10n filter_zip)</label>
+ <!--
+ <input id="adr$n" type="radio" name="filter$((n + 1))" value="ADR:" $([ "$1" = ADR ] && setchecked)>
+ <label for="adr$n">$(l10n ADR)</label>
+ -->
- <input id="telephone" type="radio" name="filtertype" value="TEL" $(check_type TEL)>
- <label for="telephone">$(l10n filter_phone)</label>
+ <input id="street$n" type="radio" name="filter$((n + 1))" value="street:" $([ "$1" = street ] && setchecked)>
+ <label for="street$n">$(l10n filter_street)</label>
- <input id="birth" type="radio" name="filtertype" value="BDAY" $(check_type BDAY)>
- <label for="birth">$(l10n filter_birthyear)</label>
+ <input id="zip$n" type="radio" name="filter$((n + 1))" value="zip:" $([ "$1" = zip ] && setchecked)>
+ <label for="zip$n">$(l10n filter_zip)</label>
-<!--
+ <input id="telephone$n" type="radio" name="filter$((n + 1))" value="TEL:" $([ "$1" = TEL ] && setchecked)>
+ <label for="telephone$n">$(l10n filter_phone)</label>
+
+ <input id="birth$n" type="radio" name="filter$((n + 1))" value="BDAY:" $([ "$1" = BDAY ] && setchecked)>
+ <label for="birth$n">$(l10n filter_birthyear)</label>
+
+ <input id="cat$n" type="radio" name="filter$((n + 1))" value="CATEGORIES:" $([ "$1" = CATEGORIES ] && setchecked)>
+ <label for="cat$n">$(l10n CATEGORIES)</label>
+ <input type="text" name="filter$((n + 2))" value="$([ "$1" = CATEGORIES ] || attribsafe "$2")" placeholder="$(l10n filter_placeholder)"/>
+ <fieldset class="categories">
+ $(m=3
+ list_categories \
+ | while read cat; do
+ printf '<label><input type="checkbox" name="filter%i" value="|%s" %s/>%s</label>' \
+ "$((n + m))" "$(attribsafe "$cat")" "$(printf %s "$cat" |grep -qEx "$2" && setchecked)" "$(htmlsafe "$cat")"
+ m=$((m + 1))
+ done
+ )
+ <a href="?p=categories">$(l10n edit_categories)</a>
+ </fieldset>
+
+ <!--
${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)"/>
+ -->
</fieldset>
+EOF
+}
+
+cat <<EOF
+<form class="filter" action="?action=filter_card" method="POST">
+ <h1>$(l10n filter_label)</h1>
+ <input type="hidden" name="page" value="cards"/>
+
+ $(
+ n=0; m="$(list_categories |wc -l)"
+ printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \
+ | while read filter; do
+ [ -n "$filter" ] && filter_item "${filter%%:*}" "${filter#*:}" "$n"
+ n=$((n + 3 + m))
+ done
+ filter_item any '' "$n"
+ )
<fieldset class="order">
<legend>$(l10n filter_order):</legend>