local dates="$(DBM "$file" get dates)"
local todall="$(DBM "$file" get todall)"
local timelist="$(timelist)"
- local time date span name
+ local edit="$(GET edit)"
+ local time date span name yes no maybe yc nc mc
[ "$timelist" ] || return 1
printf '][tbody\n'
+ # Vote displays
{ DBM "$file" get participants; printf \\n; } |while read -r name; do
+ [ "$name" = "$edit" ] && continue
+ maybe="$(DBM "$file" get "reply_maybe_${name}")"
yes="$(DBM "$file" get "reply_yes_${name}")"
no="$(DBM "$file" get "reply_no_${name}")"
- maybe="$(DBM "$file" get "reply_maybe_${name}")"
printf '[tr [th .name . %s]' "$(HTML "$name")"
for time in $timelist; do
printf %s "$maybe" |grep -qwF "$time" && printf '[td .maybe Maybe]' && continue
printf '[td .missing . ?]'
done
- printf '[td]]'
+ printf '[td .edit [a href="?edit=%s" Edit]]]\n' "$(URL "$name")"
done
- # Submit line
- printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
- for time in $timelist; do
- time="$(tkey "$time")"
- printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
- [radio "%s" "no" #no_%s][label for="no_%s" No]
- [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
- ]' "${time}" "${time}" "${time}" \
- "${time}" "${time}" "${time}" \
- "${time}" "${time}" "${time}"
- done
- printf '[td [submit "new" "new" Submit]]]\n'
+ if [ "$edit" ]; then
+ maybe="$(DBM "$file" get "reply_maybe_${edit}")"
+ yes="$(DBM "$file" get "reply_yes_${edit}")"
+ no="$(DBM "$file" get "reply_no_${edit}")"
+
+ printf '[tr .new [th .name [submit "delete" "%s" -] %s]' "$(HTML "$edit")" "$(HTML "$edit")"
+ for time in $timelist; do
+ ktime="$(tkey "$time")"
+ printf '[td [radio "%s" "yes" #yes_%s %s][label for="yes_%s" Yes]
+ [radio "%s" "no" #no_%s %s][label for="no_%s" No]
+ [radio "%s" "maybe" #maybe_%s %s][label for="maybe_%s" Maybe]
+ ]' "${ktime}" "${time}" "$(checked "$time" $yes)" "${time}" \
+ "${ktime}" "${time}" "$(checked "$time" $no)" "${time}" \
+ "${ktime}" "${time}" "$(checked "$time" $maybe)" "${time}"
+ done
+ printf '[td [submit "update" "%s" Update]]]\n' "$(HTML "$edit")"
+ else
+
+ # Vote counts
+ printf '[tr .votecount [td]'
+ for time in $timelist; do
+ yc=0 nc=0 mc=0
+ { DBM "$file" get participants; printf \\n\\n; } |while read -r name; do
+ [ ! "$name" ] && printf '[td %i (%i)]' "$yc" "$((yc + mc))" && break;
+ yes="$(DBM "$file" get "reply_yes_${name}")"
+ no="$(DBM "$file" get "reply_no_${name}")"
+ maybe="$(DBM "$file" get "reply_maybe_${name}")"
+
+ printf %s "$yes" |grep -qwF "$time" && yc=$((yc + 1)) && continue
+ printf %s "$maybe" |grep -qwF "$time" && mc=$((mc + 1)) && continue
+ done
+ done
+ printf '[td]]\n'
+
+ # Submit line
+ printf '[tr .new [td [input name="name" value="" placeholder="Your Name" autocomplete=off]]'
+ for time in $timelist; do
+ time="$(tkey "$time")"
+ printf '[td [radio "%s" "yes" #yes_%s][label for="yes_%s" Yes]
+ [radio "%s" "no" #no_%s][label for="no_%s" No]
+ [radio "%s" "maybe" #maybe_%s][label for="maybe_%s" Maybe]
+ ]' "${time}" "${time}" "${time}" \
+ "${time}" "${time}" "${time}" \
+ "${time}" "${time}" "${time}"
+ done
+ printf '[td [submit "new" "new" Submit]]]\n'
+ fi
printf ']]'
}
if [ "$REQUEST_METHOD" = POST ]; then
+ local update="$(POST update)" delete="$(POST delete)"
local name="$(POST name |grep -m 1 -xE '.*[^ ].*')"
local splittimes="$(DBM "$file" get splittimes || printf no)"
local dates="$(DBM "$file" get dates)"
local timelist="$(timelist)"
local time yes no maybe reply
- if [ "$(POST new)" = new ]; then
+ if [ "$(POST new)" = new -o "$update" ]; then
+ [ "$update" ] && name="$update"
+
if [ ! "$name" ]; then
REDIRECT "${_BASE}${PATH_INFO}#ERROR_NONAME"
- elif DBM "$file" get participants |grep -qxF "$name"; then
+ elif [ ! "$update" ] && DBM "$file" get participants |grep -qxF "$name"; then
REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMEEXISTS"
+ elif [ "$update" ] && ! DBM "$file" get participants |grep -qxF "$name"; then
+ REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
+ fi
+ if [ ! "$update" ]; then
+ DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
+ || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
fi
- DBM "$file" append participants "${BR}${name}" || DBM "$file" insert participants "${name}" \
- || REDIRECT "${_BASE}${PATH_INFO}#ERROR_DBACCESS"
for time in $timelist; do reply="$(POST "$(tkey "$time")")"; case $reply in
yes) yes="${yes}${yes:+ }${time}";;
DBM "$file" set "reply_yes_${name}" "$yes"
DBM "$file" set "reply_no_${name}" "$no"
DBM "$file" set "reply_maybe_${name}" "$maybe"
- REDIRECT "${_BASE}${PATH_INFO}"
+
+ elif [ "$delete" ]; then
+ if ! DBM "$file" get participants |grep -qxF "$delete"; then
+ REDIRECT "${_BASE}${PATH_INFO}#ERROR_NAMENONEXIST"
+ fi
+ DBM "$file" set participants "$(DBM "$file" get participants |grep -vxF "$delete")"
+ DBM "$file" delete "reply_yes_${delete}"
+ DBM "$file" delete "reply_no_${delete}"
+ DBM "$file" delete "reply_maybe_${delete}"
fi
+ REDIRECT "${_BASE}${PATH_INFO}"
else
pagename="$(pagename "$id")"
background-color: rgba(255,255,255,.5);
border-collapse: collapse;
margin: auto;
- -border: .5pt solid;
box-shadow: #000 .25em .25em .5em;
border-radius: 2pt;
}
text-align: center;
border: .5pt solid;
padding: 0 .25em;
+ background-clip: padding-box;
}
body.poll table tbody tr td:first-child,
body.poll table tbody tr td:last-child,
body.poll table tbody tr td.yes { background-color: #AFA; }
body.poll table tbody tr td.no { background-color: #FAA; }
body.poll table tbody tr td.maybe { background-color: #FFA; }
+body.poll table tbody tr td.edit { text-align: left; font-size: .875em; }
+
+body.poll table tbody tr.votecount td { padding: .375em .25em;}
+body.poll table tbody tr th.name button[name=delete] { font-size: .625em; line-height: 1.5em; background-color: #FAA; }
+
+body.poll table tbody tr.new td:first-child { text-align: right; }
+body.poll table tbody tr.new td input[name=name] { min-width: 100%; width: 4em; }
body.poll table td input[type=radio] { display: none; }
body.poll table td input[type=radio] + label {