#!/bin/zsh
-# Copyright 2014, 2017 Paul Hänsch
+# Copyright 2014, 2017, 2019 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/>.
-cgi_post
-
-if [ "${_POST[choice]}" = new_filter ]; then
+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;\^[^:]*:$;;;'
+ seq 0 100 |while read n; do
+ filter_type="$(POST "filter_type${n}")"
+ filter_text="$(POST "filter_text${n}")"
+ [ ! "$filter_type" -a ! "$filter_text" ] && break
+ if [ "$filter_type" = CATEGORIES ]; then
+ printf '^CATEGORIES:'
+ seq 0 $(POST_COUNT filter_cat$n) |while read m; do
+ printf '|%s' "$(POST filter_cat$n $m)"
+ done
+ else
+ printf '^%s:%s' "$filter_type" "$filter_text"
+ fi
+ 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"
+ REDIRECT "/cards/?o=$(POST order)&f=${filter}"
else
- printf 'Location: ?p=cards\n\n'
+ REDIRECT '/cards/'
fi