]> git.plutz.net Git - confetti/blob - cards/cards.html.sh
common functions for pdi (vcf/ics) parsing
[confetti] / cards / cards.html.sh
1 # Copyright 2014 - 2017 Paul Hänsch
2 #
3 # This file is part of Confetti.
4
5 # Confetti is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9
10 # Confetti is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Affero General Public License for more details.
14
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
17
18 setchecked() {
19   printf 'checked="checked"'
20 }
21 check_type(){
22   [ "${_GET[filter]%%:*}" = "$1" ] && setchecked
23 }
24 check_order(){
25   [ "${_GET[order]}" = "$1" ] && setchecked
26 }
27
28 filter_item() {
29 cat <<EOF
30   <fieldset class="item">
31     <legend>$(l10n filter_item):</legend>
32     <input type="hidden" name="filter${n}" value="^"/>
33
34     <input  id="any$n" type="radio" name="filter$((n + 1))" value="any:" $([ "$1" = any ] && setchecked)>
35     <label for="any$n" >$(l10n filter_all)</label>
36
37     <input  id="name$n" type="radio" name="filter$((n + 1))" value="name:" $([ "$1" = name ] && setchecked)>
38     <label for="name$n">$(l10n filter_name)</label>
39
40     <!--
41     <input  id="adr$n" type="radio" name="filter$((n + 1))" value="ADR:" $([ "$1" = ADR ] && setchecked)>
42     <label for="adr$n">$(l10n ADR)</label>
43     -->
44
45     <input  id="street$n" type="radio" name="filter$((n + 1))" value="street:" $([ "$1" = street ] && setchecked)>
46     <label for="street$n">$(l10n filter_street)</label>
47
48     <input  id="zip$n" type="radio" name="filter$((n + 1))" value="zip:" $([ "$1" = zip ] && setchecked)>
49     <label for="zip$n">$(l10n filter_zip)</label>
50
51     <input  id="telephone$n" type="radio" name="filter$((n + 1))" value="TEL:" $([ "$1" = TEL ] && setchecked)>
52     <label for="telephone$n">$(l10n filter_phone)</label>
53
54     <input  id="birth$n" type="radio" name="filter$((n + 1))" value="BDAY:" $([ "$1" = BDAY ] && setchecked)>
55     <label for="birth$n">$(l10n filter_birthyear)</label>
56
57     <input  id="cat$n" type="radio" name="filter$((n + 1))" value="CATEGORIES:" $([ "$1" = CATEGORIES ] && setchecked)>
58     <label for="cat$n">$(l10n CATEGORIES)</label>
59     <input type="text" name="filter$((n + 2))" value="$([ "$1" = CATEGORIES ] || attribsafe "$2")" placeholder="$(l10n filter_placeholder)"/>
60     <fieldset class="categories">
61       $(m=3
62         list_categories \
63         | while read cat; do
64           printf '<label><input type="checkbox" name="filter%i" value="|%s" %s/>%s</label>' \
65                  "$((n + m))" "$(attribsafe "$cat")" "$(printf %s "$cat" |grep -qEx "$2" && setchecked)" "$(htmlsafe "$cat")"
66           m=$((m + 1))
67         done
68       )
69       <a href="?p=categories">$(l10n edit_categories)</a>
70     </fieldset>
71
72     <!--
73     ${profile_circus:+
74     <input  id="course" type="radio" name="filtertype" value="course" $(check_type course)>
75     <label for="course">$(l10n filter_course)</label>
76     }
77     -->
78   </fieldset>
79 EOF
80 }
81
82 cat <<EOF
83 <form class="filter" action="?action=filter_card" method="POST">
84   <h1>$(l10n filter_label)</h1>
85   <input type="hidden" name="page" value="cards"/>
86
87   $(
88   n=0; m="$(list_categories |wc -l)"
89   printf '%s\n' "${_GET[filter]}" |tr '^' '\n' \
90   | while read filter; do
91     [ -n "$filter" ] && filter_item "${filter%%:*}" "${filter#*:}" "$n"
92     n=$((n + 3 + m))
93   done
94   filter_item any '' "$n"
95   )
96
97   <fieldset class="order">
98     <legend>$(l10n filter_order):</legend>
99     <label><input type="radio" name="order" value="firstname" $(check_order firstname)>$(l10n filter_firstname)</label>
100     <label><input type="radio" name="order" value="lastname"  $(check_order lastname) >$(l10n filter_lastname)</label>
101     <label><input type="radio" name="order" value="bdate"     $(check_order bdate)    >$(l10n filter_bdate)</label>
102   </fieldset>
103   <button type="submit" name="choice" value="new_filter">$(l10n filter_apply)</button>
104   <button type="submit" name="choice" value="del_filter">$(l10n filter_cancel)</button>
105 </form>
106
107 <form class="newcard" action="?action=new_card" method="POST">
108   <button type="submit">$(l10n newcard)</button>
109 </form>
110
111 ${edit:+$(edit_card "$edit")}
112 EOF
113
114 listcards |grep ${edit:+-v} "$edit" \
115 | while read card; do
116   cat <<-ENDCARD
117         <div id="${card}" class="card">
118           $(view_card "$card")<!--
119           --><div class="control">
120             <a class="item" href="?action=edit_card&card=${card}">$(l10n edit)</a>
121             <a class="item" href="?action=export_vcard&card=${card}">$(l10n vcf_export)</a>
122             ${profile_medical:+
123             <a class="item" href="?action=new_prescription&client=${card}">$(l10n new_prescription)</a>
124             }
125           </div>
126         </div>
127         ENDCARD
128 done
129
130 # vi:set filetype=html: