3 id="$(checkid "${PATH_INFO#/}")"
6 #cancel if poll is invalid
7 [ "$id" -a -f "$file" ] || REDIRECT "$_BASE/"
10 # convert time stamps for use in POST keys
15 *) out="${out}${str%"${str#?}"}";;
23 local dates todall splittimes
24 local date tod todsplit
26 if [ "$splittimes" = no -a "$dates" -a "$todall" ]; then
27 for date in $dates; do for tod in $todall; do
28 printf %s\\n "${date}_${tod%-}"
31 elif [ "$splittimes" = no -a "$dates" ]; then
32 for date in $dates; do
33 printf %s\\n "${date}"
36 elif [ "$splittimes" = no -a "$todall" ]; then
37 for tod in $todall; do
38 printf %s\\n "${tod%-}"
41 elif [ "$splittimes" = yes ]; then
42 for date in $dates; do
43 todsplit="$(DBM "$file" get "tod_$date")"
45 && for tod in $todsplit; do printf %s\\n "${date}_${tod%-}"; done \
46 || printf %s\\n "${date}"
56 local splittimes="$(DBM "$file" get splittimes || printf no)"
57 local dates="$(DBM "$file" get dates)"
58 local todall="$(DBM "$file" get todall)"
59 local timelist="$(timelist)"
60 local edit="$(GET edit)"
61 local time date span name yes no maybe yc nc mc
63 [ "$timelist" ] || return 1
65 printf '[table .poll [thead\n'
68 printf '[tr .dates [th]'
69 for date in $dates; do
70 span=0; for time in $timelist; do case $time in
71 ${date}*) span=$((span + 1));;
73 date -d "$date" +"[th colspan=\"${span}\" . %A <br/> %B %_d, %Y]";
79 if [ "$splittimes" = yes -o "$todall" ]; then
80 printf '[tr .tod [th]'
81 for time in $timelist; do
82 [ "${time#*_}" = "${time}" ] && time="${time}_"
83 printf '[th . %s]' "${time#*_}"
91 { DBM "$file" get participants; printf \\n; } |while read -r name; do
92 [ "$name" = "$edit" ] && continue
93 maybe="$(DBM "$file" get "reply_maybe_${name}")"
94 yes="$(DBM "$file" get "reply_yes_${name}")"
95 no="$(DBM "$file" get "reply_no_${name}")"
97 printf '[tr [th .name . %s]' "$(HTML "$name")"
98 for time in $timelist; do
99 printf %s "$yes" |grep -qwF "$time" && printf '[td .yes Yes]' && continue
100 printf %s "$no" |grep -qwF "$time" && printf '[td .no No]' && continue
101 printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
102 printf '[td .missing . ?]'
104 printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")"
108 maybe="$(DBM "$file" get "reply_maybe_${edit}")"
109 yes="$(DBM "$file" get "reply_yes_${edit}")"
110 no="$(DBM "$file" get "reply_no_${edit}")"
112 printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")"
113 for time in $timelist; do
114 ktime="$(tkey "$time")"
115 printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes]
116 [radio "%s" "no" #no_%s %s][label for="no_%s" No]
117 [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe]
118 ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \
119 "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \
120 "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}"
122 printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")"
126 printf '[tr .votecount [td]'
127 for time in $timelist; do
129 { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do
130 [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break;
131 yes="$(DBM "$file" get "reply_yes_${name}")"
132 no="$(DBM "$file" get "reply_no_${name}")"
133 maybe="$(DBM "$file" get "reply_maybe_${name}")"
135 printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue
136 printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue
142 printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
143 for time in $timelist; do
144 time="$(tkey "$time")"
145 printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
146 [radio "%s" "no" #no_%s][label for="no_%s" No]
147 [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
148 ]' "${time}" "${time}" "${time}" \
149 "${time}" "${time}" "${time}" \
150 "${time}" "${time}" "${time}"
152 printf '[td [submit "new" "new" Submit]]]\n'
158 if [ "$REQUEST_METHOD" = POST ]; then
159 local update="$(POST update)" delete="$(POST delete)"
160 local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
161 local splittimes="$(DBM "$file" get splittimes || printf no)"
162 local dates="$(DBM "$file" get dates)"
163 local todall="$(DBM "$file" get todall)"
164 local timelist="$(timelist)"
165 local time yes no maybe reply
167 if [ "$(POST new)" = new -o "$update" ]; then
168 [ "$update" ] && name="$update"
170 if [ ! "$name" ]; then
171 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
172 elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then
173 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
174 elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then
175 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
177 if [ ! "$update" ]; then
178 DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
179 || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
182 for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
183 yes) yes="${yes}${yes:+ }${time}";;
184 no) no="${no}${no:+ }${time}";;
185 maybe) maybe="${maybe}${maybe:+ }${time}";;
187 DBM "$file" set "reply_yes_${name}" "$yes"
188 DBM "$file" set "reply_no_${name}" "$no"
189 DBM "$file" set "reply_maybe_${name}" "$maybe"
191 elif [ "$delete" ]; then
192 if ! DBM "$file" get participants |grep -qxF "$delete"; then
193 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
195 DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")"
196 DBM "$file" delete "reply_yes_${delete}"
197 DBM "$file" delete "reply_no_${delete}"
198 DBM "$file" delete "reply_maybe_${delete}"
200 REDIRECT "${_BASE}${PATH_INFO}"
203 pagename="$(pagename "$id")"
205 yield_page "$pagename" poll <<-EOF
207 [section .description
208 [h1 .title $(HTML "$pagename")]
209 $(DBM "$file" get description |markdown)
211 $(table_poll || printf '[p Poll parameters are invalid]')