3 id="$(checkid "${PATH_INFO#/}")"
6 #cancel if poll is invalid
7 [ "$id" -a -f "$file" ] || REDIRECT "$_BASE/"
9 if expr match "$bookmarks" ".*${id}.*" >/dev/null; then
11 elif [ "$bookmarks" ]; then
12 SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}" Path="${_BASE}/"
15 admin="$(expr match "$bookmarks" ".*$id/\([a-zA-Z0-9:=]\{16\}\).*")"
16 admin="$(DBM "$file" get adminkey |grep -xF "$admin")"
19 # convert time stamps for use in POST keys
24 *) out="${out}${str%"${str#?}"}";;
32 local dates todall splittimes
33 local date tod todsplit
35 if [ "$splittimes" = no -a "$dates" -a "$todall" ]; then
36 for date in $dates; do for tod in $todall; do
37 printf %s\\n "${date}_${tod%-}"
40 elif [ "$splittimes" = no -a "$dates" ]; then
41 for date in $dates; do
42 printf %s\\n "${date}"
45 elif [ "$splittimes" = no -a "$todall" ]; then
46 for tod in $todall; do
47 printf %s\\n "${tod%-}"
50 elif [ "$splittimes" = yes ]; then
51 for date in $dates; do
52 todsplit="$(DBM "$file" get "tod_$date")"
54 && for tod in $todsplit; do printf %s\\n "${date}_${tod%-}"; done \
55 || printf %s\\n "${date}"
65 local splittimes="$(DBM "$file" get splittimes || printf no)"
66 local dates="$(DBM "$file" get dates)"
67 local todall="$(DBM "$file" get todall)"
68 local timelist="$(timelist)"
69 local edit="$(GET edit)"
70 local time date span name yes no maybe yc nc mc
72 [ "$timelist" ] || return 1
74 printf '[table .poll [thead\n'
77 printf '[tr .dates [th]'
78 for date in $dates; do
79 span=0; for time in $timelist; do case $time in
80 ${date}*) span=$((span + 1));;
82 date -d "$date" +"[th colspan=\"${span}\" . %A <br/> %B %_d, %Y]";
88 if [ "$splittimes" = yes -o "$todall" ]; then
89 printf '[tr .tod [th]'
90 for time in $timelist; do
91 [ "${time#*_}" = "${time}" ] && time="_${time}"
92 printf '[th . %s]' "${time#*_}"
100 { DBM "$file" get participants; printf \\n; } |while read -r name; do
101 [ "$name" = "$edit" ] && continue
102 maybe="$(DBM "$file" get "reply_maybe_${name}")"
103 yes="$(DBM "$file" get "reply_yes_${name}")"
104 no="$(DBM "$file" get "reply_no_${name}")"
106 printf '[tr [th .name . %s]' "$(HTML "$name")"
107 for time in $timelist; do
108 printf %s "$yes" |grep -qwF "$time" && printf '[td .yes Yes]' && continue
109 printf %s "$no" |grep -qwF "$time" && printf '[td .no No]' && continue
110 printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
111 printf '[td .missing . ?]'
113 printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")"
117 maybe="$(DBM "$file" get "reply_maybe_${edit}")"
118 yes="$(DBM "$file" get "reply_yes_${edit}")"
119 no="$(DBM "$file" get "reply_no_${edit}")"
121 printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")"
122 for time in $timelist; do
123 ktime="$(tkey "$time")"
124 printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes]
125 [radio "%s" "no" #no_%s %s][label for="no_%s" No]
126 [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe]
127 ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \
128 "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \
129 "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}"
131 printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")"
135 printf '[tr .votecount [td]'
136 for time in $timelist; do
138 { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do
139 [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break;
140 yes="$(DBM "$file" get "reply_yes_${name}")"
141 no="$(DBM "$file" get "reply_no_${name}")"
142 maybe="$(DBM "$file" get "reply_maybe_${name}")"
144 printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue
145 printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue
151 printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
152 for time in $timelist; do
153 time="$(tkey "$time")"
154 printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
155 [radio "%s" "no" #no_%s][label for="no_%s" No]
156 [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
157 ]' "${time}" "${time}" "${time}" \
158 "${time}" "${time}" "${time}" \
159 "${time}" "${time}" "${time}"
161 printf '[td [submit "new" "new" Submit]]]\n'
167 if [ "$REQUEST_METHOD" = POST ]; then
168 local update="$(POST update)" delete="$(POST delete)"
169 local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
170 local splittimes="$(DBM "$file" get splittimes || printf no)"
171 local dates="$(DBM "$file" get dates)"
172 local todall="$(DBM "$file" get todall)"
173 local timelist="$(timelist)"
174 local time yes no maybe reply
176 if [ "$(POST new)" = new -o "$update" ]; then
177 [ "$update" ] && name="$update"
179 if [ ! "$name" ]; then
180 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
181 elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then
182 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
183 elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then
184 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
186 if [ ! "$update" ]; then
187 DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
188 || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
191 for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
192 yes) yes="${yes}${yes:+ }${time}";;
193 no) no="${no}${no:+ }${time}";;
194 maybe) maybe="${maybe}${maybe:+ }${time}";;
196 DBM "$file" set "reply_yes_${name}" "$yes"
197 DBM "$file" set "reply_no_${name}" "$no"
198 DBM "$file" set "reply_maybe_${name}" "$maybe"
200 elif [ "$delete" ]; then
201 if ! DBM "$file" get participants |grep -qxF "$delete"; then
202 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
204 DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")"
205 DBM "$file" delete "reply_yes_${delete}"
206 DBM "$file" delete "reply_no_${delete}"
207 DBM "$file" delete "reply_maybe_${delete}"
209 elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then
210 SET_COOKIE +$((182 * 86400)) bookmarks="${id}" Path="${_BASE}/"
213 REDIRECT "${_BASE}${PATH_INFO}"
216 pagename="$(pagename "$id")"
218 yield_page "$pagename" poll <<-EOF
220 [section .description
221 [h1 .title $(HTML "$pagename")]
222 $(DBM "$file" get description |markdown)
224 $(table_poll || printf '[p Poll parameters are invalid]')
225 $(if [ "$admin" ]; then
226 printf '[section .bookmark You have bookmarked the admin page of this poll: [a href="./%s" modify poll]]' "$(URL ${id}/${admin})"
227 elif [ "$bookmarks" ]; then
228 printf '[section .bookmark This poll has been bookmarked and is accessible via a link on the front page.]'
230 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]]'