3 . "${_EXEC}/comments.sh"
5 id="$(checkid "${PATH_INFO#/}")"
8 #cancel if poll is invalid
9 if [ ! "$id" -o ! -f "$file" ]; then
14 if expr match "$bookmarks" ".*${id}.*" >/dev/null; then
16 elif [ "$bookmarks" ]; then
17 SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}" Path="${_BASE}/"
20 admin="$(expr match "$bookmarks" ".*$id/\([a-zA-Z0-9:=]\{16\}\).*")"
21 admin="$(DBM "$file" get adminkey |grep -xF "$admin")"
24 # convert time stamps for use in POST keys
29 *) out="${out}${str%"${str#?}"}";;
37 local dates todall splittimes
38 local date tod todsplit
40 if [ "$splittimes" = no -a "$dates" -a "$todall" ]; then
41 for date in $dates; do for tod in $todall; do
42 printf %s\\n "${date}_${tod%-}"
45 elif [ "$splittimes" = no -a "$dates" ]; then
46 for date in $dates; do
47 printf %s\\n "${date}"
50 elif [ "$splittimes" = no -a "$todall" ]; then
51 for tod in $todall; do
52 printf %s\\n "${tod%-}"
55 elif [ "$splittimes" = yes ]; then
56 for date in $dates; do
57 todsplit="$(DBM "$file" get "tod_$date")"
59 && for tod in $todsplit; do printf %s\\n "${date}_${tod%-}"; done \
60 || printf %s\\n "${date}"
70 local splittimes="$(DBM "$file" get splittimes || printf no)"
71 local dates="$(DBM "$file" get dates)"
72 local todall="$(DBM "$file" get todall)"
73 local timelist="$(timelist)"
74 local edit="$(GET edit)"
75 local time date span name yes no maybe yc nc mc
77 [ "$timelist" ] || return 1
79 printf '[table .poll [thead\n'
82 printf '[tr .dates [th]'
83 for date in $dates; do
84 span=0; for time in $timelist; do case $time in
85 ${date}*) span=$((span + 1));;
87 date -d "$date" +"[th colspan=\"${span}\" . %A <br/> %B %_d, %Y]";
93 if [ "$splittimes" = yes -o "$todall" ]; then
94 printf '[tr .tod [th]'
95 for time in $timelist; do
97 *-*-*_*:*) time="${time#*_}";;
99 *:*);; # time="${time}"
101 printf '[th . %s]' "${time}"
109 { DBM "$file" get participants; printf \\n; } |while read -r name; do
110 [ "$name" = "$edit" ] && continue
111 maybe="$(DBM "$file" get "reply_maybe_${name}")"
112 yes="$(DBM "$file" get "reply_yes_${name}")"
113 no="$(DBM "$file" get "reply_no_${name}")"
115 printf '[tr [th .name . %s]' "$(HTML "$name")"
116 for time in $timelist; do
117 printf %s "$yes" |grep -qwF "$time" && printf '[td .yes Yes]' && continue
118 printf %s "$no" |grep -qwF "$time" && printf '[td .no No]' && continue
119 printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
120 printf '[td .missing . ?]'
122 printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")"
126 maybe="$(DBM "$file" get "reply_maybe_${edit}")"
127 yes="$(DBM "$file" get "reply_yes_${edit}")"
128 no="$(DBM "$file" get "reply_no_${edit}")"
130 printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")"
131 for time in $timelist; do
132 ktime="$(tkey "$time")"
133 printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes]
134 [radio "%s" "no" #no_%s %s][label for="no_%s" No]
135 [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe]
136 ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \
137 "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \
138 "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}"
140 printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")"
144 printf '[tr .votecount [td]'
145 for time in $timelist; do
147 { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do
148 [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break;
149 yes="$(DBM "$file" get "reply_yes_${name}")"
150 no="$(DBM "$file" get "reply_no_${name}")"
151 maybe="$(DBM "$file" get "reply_maybe_${name}")"
153 printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue
154 printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue
160 printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
161 for time in $timelist; do
162 time="$(tkey "$time")"
163 printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
164 [radio "%s" "no" #no_%s][label for="no_%s" No]
165 [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
166 ]' "${time}" "${time}" "${time}" \
167 "${time}" "${time}" "${time}" \
168 "${time}" "${time}" "${time}"
170 printf '[td [submit "new" "new" Submit]]]\n'
176 if [ "$REQUEST_METHOD" = POST ]; then
177 local update="$(POST update)" delete="$(POST delete)"
178 local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
179 local splittimes="$(DBM "$file" get splittimes || printf no)"
180 local dates="$(DBM "$file" get dates)"
181 local todall="$(DBM "$file" get todall)"
182 local timelist="$(timelist)"
183 local time yes no maybe reply
185 if [ "$(POST new)" = new -o "$update" ]; then
186 [ "$update" ] && name="$update"
188 if [ ! "$name" ]; then
189 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
190 elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then
191 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
192 elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then
193 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
195 if [ ! "$update" ]; then
196 DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
197 || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
200 for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
201 yes) yes="${yes}${yes:+ }${time}";;
202 no) no="${no}${no:+ }${time}";;
203 maybe) maybe="${maybe}${maybe:+ }${time}";;
205 DBM "$file" set "reply_yes_${name}" "$yes"
206 DBM "$file" set "reply_no_${name}" "$no"
207 DBM "$file" set "reply_maybe_${name}" "$maybe"
209 elif [ "$delete" ]; then
210 if ! DBM "$file" get participants |grep -qxF "$delete"; then
211 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
213 DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")"
214 DBM "$file" delete "reply_yes_${delete}"
215 DBM "$file" delete "reply_no_${delete}"
216 DBM "$file" delete "reply_maybe_${delete}"
218 elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then
219 SET_COOKIE +$((182 * 86400)) bookmarks="${id}" Path="${_BASE}/"
222 REDIRECT "${_BASE}${PATH_INFO}"
225 pagename="$(pagename "$id")"
227 yield_page "$pagename" poll <<-EOF
229 [section .description
230 [h1 .title $(HTML "$pagename")]
231 $(DBM "$file" get description |markdown)
234 $(table_poll || printf '[p Poll parameters are invalid]')
236 $(if [ "$admin" ]; then
237 printf '[section .bookmark You have bookmarked the admin page of this poll: [a href="./%s" modify poll]]' "$(URL ${id}/${admin})"
238 elif [ "$bookmarks" ]; then
239 printf '[section .bookmark This poll has been bookmarked and is accessible via a link on the front page.]'
241 printf '[section .bookmark Polls are accessible only via their URL. You can set a Cookie to bookmark all polls you visit. Bookmarked polls will be listed on the frontpage.<br/> [submit "bookmark" "add" Set Cookie]]'