3 . "${_EXEC}/comments.sh"
4 . "${_EXEC}/languages.sh"
6 id="$(checkid "${PATH_INFO#/}")"
9 #cancel if poll is invalid
10 if [ ! "$id" -o ! -f "$file" ]; then
15 if expr match "$bookmarks" ".*${id}.*" >/dev/null; then
17 elif [ "$bookmarks" ]; then
18 SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}" Path="${_BASE}/"
21 admin="$(expr match "$bookmarks" ".*$id/\([a-zA-Z0-9:=]\{16\}\).*")"
22 admin="$(DBM "$file" get adminkey |grep -xF "$admin")"
25 # convert time stamps for use in POST keys
30 *) out="${out}${str%"${str#?}"}";;
38 local dates todall splittimes
39 local date tod todsplit
41 if [ "$splittimes" = no -a "$dates" -a "$todall" ]; then
42 for date in $dates; do for tod in $todall; do
43 printf %s\\n "${date}_${tod%-}"
46 elif [ "$splittimes" = no -a "$dates" ]; then
47 for date in $dates; do
48 printf %s\\n "${date}"
51 elif [ "$splittimes" = no -a "$todall" ]; then
52 for tod in $todall; do
53 printf %s\\n "${tod%-}"
56 elif [ "$splittimes" = yes ]; then
57 for date in $dates; do
58 todsplit="$(DBM "$file" get "tod_$date")"
60 && for tod in $todsplit; do printf %s\\n "${date}_${tod%-}"; done \
61 || printf %s\\n "${date}"
71 local splittimes="$(DBM "$file" get splittimes || printf no)"
72 local dates="$(DBM "$file" get dates)"
73 local todall="$(DBM "$file" get todall)"
74 local timelist="$(timelist)"
75 local edit="$(GET edit)"
76 local time date span name yes no maybe yc nc mc
78 table_date="${table_date:-"%A <br/> %B %_d, %Y"}"
80 [ "$timelist" ] || return 1
82 printf '[table .poll [thead\n'
85 printf '[tr .dates [th]'
86 for date in $dates; do
87 span=0; for time in $timelist; do case $time in
88 ${date}*) span=$((span + 1));;
90 date -d "$date" +"[th colspan=\"${span}\" . ${table_date}]";
96 if [ "$splittimes" = yes -o "$todall" ]; then
97 printf '[tr .tod [th]'
98 for time in $timelist; do
100 *-*-*_*:*) time="${time#*_}";;
102 *:*);; # time="${time}"
104 printf '[th . %s]' "${time}"
112 { DBM "$file" get participants; printf \\n; } |while read -r name; do
113 [ "$name" = "$edit" ] && continue
114 maybe="$(DBM "$file" get "reply_maybe_${name}")"
115 yes="$(DBM "$file" get "reply_yes_${name}")"
116 no="$(DBM "$file" get "reply_no_${name}")"
118 printf '[tr [th .name . %s]' "$(HTML "$name")"
119 for time in $timelist; do
120 printf %s "$yes" |grep -qwF "$time" && printf '[td .yes Yes]' && continue
121 printf %s "$no" |grep -qwF "$time" && printf '[td .no No]' && continue
122 printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
123 printf '[td .missing . ?]'
125 printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")"
129 maybe="$(DBM "$file" get "reply_maybe_${edit}")"
130 yes="$(DBM "$file" get "reply_yes_${edit}")"
131 no="$(DBM "$file" get "reply_no_${edit}")"
133 printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")"
134 for time in $timelist; do
135 ktime="$(tkey "$time")"
136 printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes]
137 [radio "%s" "no" #no_%s %s][label for="no_%s" No]
138 [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe]
139 ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \
140 "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \
141 "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}"
143 printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")"
147 printf '[tr .votecount [td]'
148 for time in $timelist; do
150 { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do
151 [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break;
152 yes="$(DBM "$file" get "reply_yes_${name}")"
153 no="$(DBM "$file" get "reply_no_${name}")"
154 maybe="$(DBM "$file" get "reply_maybe_${name}")"
156 printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue
157 printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue
163 printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
164 for time in $timelist; do
165 time="$(tkey "$time")"
166 printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
167 [radio "%s" "no" #no_%s][label for="no_%s" No]
168 [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
169 ]' "${time}" "${time}" "${time}" \
170 "${time}" "${time}" "${time}" \
171 "${time}" "${time}" "${time}"
173 printf '[td [submit "new" "new" Submit]]]\n'
179 if [ "$REQUEST_METHOD" = POST ]; then
180 local update="$(POST update)" delete="$(POST delete)"
181 local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
182 local splittimes="$(DBM "$file" get splittimes || printf no)"
183 local dates="$(DBM "$file" get dates)"
184 local todall="$(DBM "$file" get todall)"
185 local timelist="$(timelist)"
186 local time yes no maybe reply
188 if [ "$(POST new)" = new -o "$update" ]; then
189 [ "$update" ] && name="$update"
191 if [ ! "$name" ]; then
192 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
193 elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then
194 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
195 elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then
196 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
198 if [ ! "$update" ]; then
199 DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
200 || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
203 for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
204 yes) yes="${yes}${yes:+ }${time}";;
205 no) no="${no}${no:+ }${time}";;
206 maybe) maybe="${maybe}${maybe:+ }${time}";;
208 DBM "$file" set "reply_yes_${name}" "$yes"
209 DBM "$file" set "reply_no_${name}" "$no"
210 DBM "$file" set "reply_maybe_${name}" "$maybe"
212 elif [ "$delete" ]; then
213 if ! DBM "$file" get participants |grep -qxF "$delete"; then
214 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
216 DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")"
217 DBM "$file" delete "reply_yes_${delete}"
218 DBM "$file" delete "reply_no_${delete}"
219 DBM "$file" delete "reply_maybe_${delete}"
221 elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then
222 SET_COOKIE +$((182 * 86400)) bookmarks="${id}" Path="${_BASE}/"
225 REDIRECT "${_BASE}${PATH_INFO}"
228 pagename="$(pagename "$id")"
230 yield_page "$pagename" poll <<-EOF
232 [section .description
233 [h1 .title $(HTML "$pagename")]
234 $(DBM "$file" get description |markdown)
237 $(table_poll || printf '[p Poll parameters are invalid]')
239 $(if [ "$admin" ]; then
240 printf '[section .bookmark You have bookmarked the admin page of this poll: [a href="./%s" modify poll]]' "$(URL ${id}/${admin})"
241 elif [ "$bookmarks" ]; then
242 printf '[section .bookmark This poll has been bookmarked and is accessible via a link on the front page.]'
244 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]]'