3 id="${PATH_INFO%/*}"; id="${id#/}"
7 if [ "$(DBM "$file" get adminkey)" != "$admin" ]; then
10 # REDIRECT "$_BASE/#ERRO_INVALIDKEY"
11 elif expr match "$bookmarks" ".*${id}/${admin}.*" >/dev/null; then
13 elif expr match "$bookmarks" ".*${id}.*" >/dev/null; then
14 bookmarks="$(printf %s "$bookmarks" |tr \ \\n |grep -vxF "${id}")"
15 bookmarks="$(printf %s "$bookmarks" |tr \\n \ )"
16 SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks}${bookmarks:+ }${id}/${admin}" Path="${_BASE}/"
17 elif [ "$bookmarks" ]; then
18 SET_COOKIE +$((182 * 86400)) bookmarks="${bookmarks} ${id}/${admin}" Path="${_BASE}/"
22 local todall="$(DBM "$file" get todall)" time c=0
25 [label .todstart Start Time (optional):
27 [label .todend End Time (optional):
29 $(for time in ${todall:--}; do
32 <input name="todstart" value="%s" placeholder="HH:MM" list="dlist_timeofday"
33 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
34 <input name="todend" value="%s" placeholder="HH:MM" list="dlist_timeofday"
35 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
36 [submit "todremove" "%i" -]
37 ' "${time%-*}" "${time#*-}" "${c}"
39 [submit "addtime" "global" + Add Time Option]
40 [checkbox "none" "none" .splittimes disabled=disabled] [submit "splittimes" "yes" Separate Time Options per Day]
46 local days day times time c
47 days="$(DBM "$file" get dates)"
50 [checkbox "none" "none" .splittimes checked disabled=disabled] [submit "splittimes" "no" Separate Time Options per Day]
51 $([ ! "$days" ] && printf '[p You have not selected any days yet.]\n')
52 $(for day in $days; do
53 date -d $day +"[h2 . %A - %B %_d, %Y]"
54 times=$(DBM "$file" get "tod_$day")
55 for time in ${times:--}; do
58 <input name="todstart_%s" value="%s" placeholder="HH:MM" list="dlist_timeofday"
59 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
60 <input name="todend_%s" value="%s" placeholder="HH:MM" list="dlist_timeofday"
61 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
62 [submit "todremove_%s" "%i" -]
63 ' "$day" "${time%-*}" "$day" "${time#*-}" "$day" "${c}"
65 printf '[submit "addtime" "%s" + Add Time Option]' "$day"
71 if [ "$REQUEST_METHOD" = POST ]; then
72 month="$(POST month |grep -m 1 -xE '[0-9]{4}-(0[1-9]|1[012])')"
73 todremove="$(POST todremove |grep -m 1 -xE '[0-9]+')"
74 splittimes="$(POST splittimes |grep -m 1 -xE 'yes|no')"
75 addtime="$(POST addtime)"
77 if [ "$splittimes" = yes ]; then
78 DBM "$file" set splittimes "$splittimes"
79 splittimes="no" # receive remainder of todall form
80 elif [ "$splittimes" = no ]; then
81 DBM "$file" set splittimes "$splittimes"
82 splittimes="yes" # receive remainder of splittimes form
84 splittimes="$(DBM "$file" get splittimes || printf no)"
87 DBM "$file" set title "$(POST title)"
88 DBM "$file" set description "$(POST description)"
89 # Store common time options "todall"
90 [ "$splittimes" = no ] && DBM "$file" set todall "$(
91 for todcount in $(seq 1 $(POST_COUNT todstart)); do
92 [ "$todremove" -eq "$todcount" ] 2>&- && continue;
93 todstart="$(POST todstart "$todcount")"
94 todend="$(POST todend "$todcount")"
95 [ "${todstart%:??}" -lt "${todend%:??}" -o "${todstart%:??}" -eq "${todend%:??}" -a "${todstart#*:}" -lt "${todend#*:}" ] \
97 && { printf '%02i:%02i-%02i:%02i\n' "${todstart%:??}" "${todstart#*:}" "${todend%:??}" "${todend#*:}"; }\
98 || { [ "${todstart%:??}" -ge 0 -a "${todstart#*:}" -ge 0 ] 2>&- && printf '%02i:%02i-\n' "${todstart%:??}" "${todstart#*:}"; }
99 done |grep -xE '^([01][0-9]|2[0-3]):([0-5][0-9])-(([01][0-9]|2[0-3]):([0-5][0-9]))?$' |sort -u
101 [ "$addtime" = global ] && DBM "$file" append todall "${BR}-"
103 # Store per-date time options "tod_YYYY-mm-dd"
104 [ "$splittimes" = yes ] && for date in $(DBM "$file" get dates); do
105 todremove="$(POST todremove_$date |grep -m 1 -xE '[0-9]+')"
106 DBM "$file" set "tod_$date" "$(
107 for todcount in $(seq 1 $(POST_COUNT "todstart_${date}")); do
108 [ "$todremove" -eq "$todcount" ] 2>&- && continue;
109 todstart="$(POST "todstart_${date}" "$todcount")"
110 todend="$(POST "todend_${date}" "$todcount")"
111 [ "${todstart%:??}" -lt "${todend%:??}" -o "${todstart%:??}" -eq "${todend%:??}" -a "${todstart#*:}" -lt "${todend#*:}" ] \
113 && { printf '%02i:%02i-%02i:%02i\n' "${todstart%:??}" "${todstart#*:}" "${todend%:??}" "${todend#*:}"; }\
114 || { [ "${todstart%:??}" -ge 0 -a "${todstart#*:}" -ge 0 ] 2>&- && printf '%02i:%02i-\n' $(dec ${todstart%:??} ${todstart#*:}); }
115 done |grep -xE '^([01][0-9]|2[0-3]):([0-5][0-9])-(([01][0-9]|2[0-3]):([0-5][0-9]))?$' |sort -u
117 [ "$addtime" = "$date" ] && DBM "$file" append "tod_${date}" "${BR}-"
120 DBM "$file" set dates "$(
121 for date in $(seq 0 $(POST_COUNT date)); do
127 | grep -vxF "$(POST date_remove)" \
128 | grep -xE '^[0-9]{4}-((01|03|05|07|08|10|12)-([012][0-9]|3[01])|(04|06|09|11)-([012][0-9]|30)|02-[012][0-9])$' \
132 if [ "$(POST delete)" = delete ]; then
133 if [ "$(POST delconfirm)" -o ! "$(DBM "$file" get participants)" ]; then
137 REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}#ERROR_NEEDCONFIRM"
139 elif [ "$(POST post)" = post ]; then
140 REDIRECT "$_BASE${PATH_INFO%/*}"
141 elif [ "$(POST bookmark)" -a ! "$bookmarks" ]; then
142 SET_COOKIE +$((182 * 86400)) bookmarks="${id}/${admin}" Path="${_BASE}/"
143 REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}"
145 REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}"
148 month="$(GET month |grep -m1 -xE '[0-9]{4}-(0[1-9]|1[012])' || date +%Y-%m)"
149 Y="${month%-*}"; m="${month#*-}"; Y=${Y#0}; m=${m#0};
150 [ "$m" = 1 ] && prev=$(printf '%04i-%02i' $((Y - 1)) 12) || prev=$(printf '%04i-%02i' $Y $((m - 1)))
151 [ "$m" = 12 ] && next=$(printf '%04i-%02i' $((Y + 1)) 01) || next=$(printf '%04i-%02i' $Y $((m + 1)))
152 dates="$(DBM "$file" get dates)"
153 days="$(printf %s "$dates" |sed -E "/^${month}-/!d; s;^.*-([0-9]{2})$;\1;g")"
154 additional="$(printf %s "$dates" |sed -E "/^${month}-/d;")"
155 splittimes="$(DBM "$file" get splittimes || printf no)"
157 yield_page "$(pagename "$id")" "newdate" <<-EOF
160 [input name=title value="$(DBM "$file" get title |HTML)" placeholder="Title"]
161 [textarea name=description placeholder="Description" . $(DBM "$file" get description |HTML)]
163 $(printf '[hidden "date" "%s"]' $additional)
164 [submit "month" "$prev" Previous Month]
165 $([ "$splittimes" = yes ] && w_month submit date "$month" $days || w_month multiple date "$month" $days)
166 [submit "month" "$next" Next Month]
167 [hidden "month" "$month"]
169 $([ "$splittimes" = "yes" ] && fs_splittimes || fs_timeofday )
170 $(if [ "$(DBM "$file" get participants)" ]; then
171 printf '[checkbox "delconfirm" "confirm" id="delconfirm"][label for=delconfirm Delete Poll]
172 [submit "delete" "delete" Delete Poll] [submit "post" "post" Poll page]'
174 printf '[submit "delete" "delete" Cancel] [submit "post" "post" Post Event]'
176 $(if [ "$bookmarks" ]; then
177 printf '[section .bookmark This admin page is accessible via the link [a href="%s" . %s]. You must copy this link and keep it safe, so you can modify this poll later! The poll has also been bookmarked and will be listed on the front page.' \
178 "$(URL "//$(HEADER Host)/${_BASE}/${id}/${admin}")" \
179 "$(HTML "${HTTPS:+https:}${HTTPS:-http:}//$(HEADER Host)$(PATH "/${_BASE}/${id}/${admin}")")"
181 printf '[section .bookmark This admin page is accessible via the link [a href="%s" . %s]. You must copy this link and keep it safe, so you can modify this poll later! You can also set a Cookie to bookmark all polls you visit, including this admin page. Bookmarked polls will be listed on the frontpage.<br/> [submit "bookmark" "add" Set Cookie]]' \
182 "$(URL "//$(HEADER Host)/${_BASE}/${id}/${admin}")" \
183 "$(HTML "${HTTPS:+https:}${HTTPS:-http:}//$(HEADER Host)$(PATH "/${_BASE}/${id}/${admin}")")"