}
w_month() {
- local month="$1" selected="$2"
+ # Arguments:
+ # 1. (optional) Name of select box, default "date"
+ # 2. (optional) Month to display in format: YYYY-MM, default current month
+ # 3. (optional) Day to preselect in format: DD, default none
+
+ local input="${1:-date}" month="$2" selected="$3"
local dow dom days n=1 Y m d V w B
if [ $month ]; then
read Y m d V w B<<-EOF
dow=$(( (w - d + 35 + dom ) % 7))
[ $dow = 1 -o $dom = 1 ] && printf '[tr [th .weekno . %i]' $V
[ $dom = 1 ] && while [ $n -lt $(( ($dow + 6) % 7 + 1)) ]; do printf '[td ]'; n=$((n + 1)); done
- printf '[td [label [input type=radio name=date value="%04i-%02i-%02i" %s] %i]]' $Y $m $dom "$(checked $dom $selected)" $dom
+ date="$(printf "%04i-%02i-%02i" $Y $m $dom)"
+ printf '[td [input type=radio id="%s_%s" name="%s" value="%s" %s][label for="%s_%s" . %i]]' \
+ "$input" "$date" "$input" "$date" "$(checked $dom $selected)" "$input" "$date" "$dom"
[ $dow = 0 ] && printf ']\n'
[ $dow = 0 ] && V=$(( V % 53 + 1))
done
+ if [ $dow -le 6 ]; then
+ while [ $dow -le 6 ]; do printf '[td ]'; dow=$((dow + 1)) ; done
+ printf ']\n'
+ fi
printf ']]'
}