4 local todall="$(DBM "$file" get todall)" time c=0
7 [label .todstart Start Time (optional):
9 [label .todend End Time (optional):
11 $(for time in ${todall:--}; do
14 <input name="todstart" value="%s" placeholder="HH:MM" list="dlist_timeofday"
15 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
16 <input name="todend" value="%s" placeholder="HH:MM" list="dlist_timeofday"
17 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
18 [submit "todremove" "%i" -]
19 ' "${time%-*}" "${time#*-}" "${c}"
21 [submit "addtime" "global" + Add Time Option]
22 [checkbox "none" "none" .splittimes disabled=disabled] [submit "splittimes" "yes" Separate Time Options per Day]
28 local days day times time c
29 days="$(DBM "$file" get dates)"
32 [checkbox "none" "none" .splittimes checked disabled=disabled] [submit "splittimes" "no" Separate Time Options per Day]
33 $([ ! "$days" ] && printf '[p You have not selected any days yet.]\n')
34 $(for day in $days; do
35 date -d $day +"[h2 . %A - %B %_d, %Y]"
36 times=$(DBM "$file" get "tod_$day")
37 for time in ${times:--}; do
40 <input name="todstart_%s" value="%s" placeholder="HH:MM" list="dlist_timeofday"
41 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
42 <input name="todend_%s" value="%s" placeholder="HH:MM" list="dlist_timeofday"
43 pattern="^(0?\[0-9\]|1\[0-9\]|2\[0-3\]):(\[0-5\]\[0-9\])$"/>
44 [submit "todremove" "%i" -]
45 ' "$day" "${time%-*}" "$day" "${time#*-}" "${c}"
47 printf '[submit "addtime" "%s" + Add Time Option]' "$day"
53 if [ "$REQUEST_METHOD" = POST ]; then
54 id="${PATH_INFO%/newdate}"; id="${id#/}"
56 month="$(POST month |grep -m 1 -xE '[0-9]{4}-(0[1-9]|1[012])')"
57 todremove="$(POST todremove |grep -m 1 -xE '[0-9]+')"
58 splittimes="$(POST splittimes |grep -m 1 -xE 'yes|no')"
59 addtime="$(POST addtime)"
61 if [ "$splittimes" = yes ]; then
62 DBM "$file" set splittimes "$splittimes"
63 splittimes="no" # receive remainder of todall form
64 elif [ "$splittimes" = no ]; then
65 DBM "$file" set splittimes "$splittimes"
66 splittimes="yes" # receive remainder of splittimes form
68 splittimes="$(DBM "$file" get splittimes || printf no)"
71 DBM "$file" set title "$(POST title)"
72 DBM "$file" set description "$(POST description)"
73 # Store common time options "todall"
74 [ "$splittimes" = no ] && DBM "$file" set todall "$(
75 for todcount in $(seq 1 $(POST_COUNT todstart)); do
76 [ "$todremove" -eq "$todcount" ] 2>&- && continue;
77 todstart="$(POST todstart "$todcount")"
78 todend="$(POST todend "$todcount")"
79 [ "${todstart%:??}" -lt "${todend%:??}" -o "${todstart%:??}" -eq "${todend%:??}" -a "${todstart#*:}" -lt "${todend#*:}" ] \
81 && { printf '%02i:%02i-%02i:%02i\n' "${todstart%:??}" "${todstart#*:}" "${todend%:??}" "${todend#*:}"; }\
82 || { [ "${todstart%:??}" -ge 0 -a "${todstart#*:}" -ge 0 ] 2>&- && printf '%02i:%02i-\n' "${todstart%:??}" "${todstart#*:}"; }
83 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
85 [ "$addtime" = global ] && DBM "$file" append todall "${BR}-"
87 # Store per-date time options "tod_YYYY-mm-dd"
88 [ "$splittimes" = yes ] && for date in $(DBM "$file" get dates); do
89 todremove="$(POST todremove_$date |grep -m 1 -xE '[0-9]+')"
90 DBM "$file" set "tod_$date" "$(
91 for todcount in $(seq 1 $(POST_COUNT "todstart_${date}")); do
92 [ "$todremove" -eq "$todcount" ] 2>&- && continue;
93 todstart="$(POST "todstart_${date}" "$todcount")"
94 todend="$(POST "todend_${date}" "$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" = "$date" ] && DBM "$file" append "tod_${date}" "${BR}-"
104 DBM "$file" set dates "$(
105 for date in $(seq 0 $(POST_COUNT date)); do
111 | grep -vxF "$(POST date_remove)" \
112 | 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])$' \
116 if [ "$(POST cancel)" = cancel ]; then
119 elif [ "$(POST post)" = post ]; then
120 REDIRECT "$_BASE${PATH_INFO%/*}"
122 REDIRECT "$_BASE$PATH_INFO${month:+?month=}${month}"
125 id="${PATH_INFO%/newdate}"; id="${id#/}"
127 month="$(GET month |grep -m1 -xE '[0-9]{4}-(0[1-9]|1[012])' || date +%Y-%m)"
128 Y="${month%-*}"; m="${month#*-}"; Y=${Y#0}; m=${m#0};
129 [ "$m" = 1 ] && prev=$(printf '%04i-%02i' $((Y - 1)) 12) || prev=$(printf '%04i-%02i' $Y $((m - 1)))
130 [ "$m" = 12 ] && next=$(printf '%04i-%02i' $((Y + 1)) 01) || next=$(printf '%04i-%02i' $Y $((m + 1)))
131 dates="$(DBM "$file" get dates)"
132 days="$(printf %s "$dates" |sed -E "/^${month}-/!d; s;^.*-([0-9]{2})$;\1;g")"
133 additional="$(printf %s "$dates" |sed -E "/^${month}-/d;")"
134 splittimes="$(DBM "$file" get splittimes || printf no)"
136 yield_page "$(pagename "$id")" "newdate" <<-EOF
139 [input name=title value="$(DBM "$file" get title |HTML)" placeholder="Title"]
140 [textarea name=description placeholder="Description" . $(DBM "$file" get description |HTML)]
142 $(printf '[hidden "date" "%s"]' $additional)
143 [submit "month" "$prev" Previous Month]
144 $([ "$splittimes" = yes ] && w_month submit date "$month" $days || w_month multiple date "$month" $days)
145 [submit "month" "$next" Next Month]
146 [hidden "month" "$month"]
148 $([ "$splittimes" = "yes" ] && fs_splittimes || fs_timeofday )
149 [submit "cancel" "cancel" Cancel]
150 [submit "post" "post" Post Event]