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 time date span name
62 [ "$timelist" ] || return 1
64 printf '[table .poll [thead\n'
67 printf '[tr .dates [th]'
68 for date in $dates; do
69 span=0; for time in $timelist; do case $time in
70 ${date}*) span=$((span + 1));;
72 date -d "$date" +"[th colspan=\"${span}\" . %A <br/> %B %_d, %Y]";
78 if [ "$splittimes" = yes -o "$todall" ]; then
79 printf '[tr .tod [th]'
80 for time in $timelist; do
81 [ "${time#*_}" = "${time}" ] && time="${time}_"
82 printf '[th . %s]' "${time#*_}"
89 { DBM "$file" get participants; printf \\n; } |while read -r name; do
90 yes="$(DBM "$file" get "reply_yes_${name}")"
91 no="$(DBM "$file" get "reply_no_${name}")"
92 maybe="$(DBM "$file" get "reply_maybe_${name}")"
94 printf '[tr [th .name . %s]' "$(HTML "$name")"
95 for time in $timelist; do
96 printf %s "$yes" |grep -qwF "$time" && printf '[td .yes Yes]' && continue
97 printf %s "$no" |grep -qwF "$time" && printf '[td .no No]' && continue
98 printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
99 printf '[td .missing . ?]'
105 printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
106 for time in $timelist; do
107 time="$(tkey "$time")"
108 printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
109 [radio "%s" "no" #no_%s][label for="no_%s" No]
110 [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
111 ]' "${time}" "${time}" "${time}" \
112 "${time}" "${time}" "${time}" \
113 "${time}" "${time}" "${time}"
115 printf '[td [submit "new" "new" Submit]]]\n'
120 if [ "$REQUEST_METHOD" = POST ]; then
121 local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
122 local splittimes="$(DBM "$file" get splittimes || printf no)"
123 local dates="$(DBM "$file" get dates)"
124 local todall="$(DBM "$file" get todall)"
125 local timelist="$(timelist)"
126 local time yes no maybe reply
128 if [ "$(POST new)" = new ]; then
129 if [ ! "$name" ]; then
130 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
131 elif DBM "$file" get participants |grep -qxF "$name"; then
132 REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
134 DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
135 || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
137 for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
138 yes) yes="${yes}${yes:+ }${time}";;
139 no) no="${no}${no:+ }${time}";;
140 maybe) maybe="${maybe}${maybe:+ }${time}";;
142 DBM "$file" set "reply_yes_${name}" "$yes"
143 DBM "$file" set "reply_no_${name}" "$no"
144 DBM "$file" set "reply_maybe_${name}" "$maybe"
145 REDIRECT "${_BASE}${PATH_INFO}"
149 pagename="$(pagename "$id")"
151 yield_page "$pagename" poll <<-EOF
153 [section .description
154 [h1 .title $(HTML "$pagename")]
155 $(DBM "$file" get description |markdown)
157 $(table_poll || printf '[p Poll parameters are invalid]')