#! /bin/bash
if [ -f /tmp/pschedule-loading ] && [ "$1" = "-a" ]; then exit; fi #pSchedule calls this at <action> in tables, which means it would check 5 times during startup if we hadn't prevented it with the -a switch. See xml code in func_new

if [ "$MINUTE" = "$(gettext 'any')" ] || [ ! "$MINUTE" ] ; then MINUTE="*"; fi
if [ "$HOUR" = "$(gettext 'any')" ] || [ ! "$HOUR" ] ; then HOUR="*"; fi
if [ "$DAY" = "$(gettext 'any')" ] || [ ! "$DAY" ] ; then DAY="*"; else DAY=`echo "$DAY" | tr -d .`; fi

case "$MONTH" in
	"$(gettext 'January')")		MONTH="1";;
	"$(gettext 'February')")	MONTH="2";;
	"$(gettext 'March')")		MONTH="3";;
	"$(gettext 'April')")		MONTH="4";;
	"$(gettext 'May')" )		MONTH="5";;
	"$(gettext 'June')")		MONTH="6";;
	"$(gettext 'July')")		MONTH="7";;
	"$(gettext 'August')")		MONTH="8";;
	"$(gettext 'September')")	MONTH="9";;
	"$(gettext 'October')")		MONTH="10";;
	"$(gettext 'November')")	MONTH="11";;
	"$(gettext 'December')")	MONTH="12";;
	*)							MONTH="*";;
esac
case "$WEEKDAY" in
	"$(gettext 'Mondays')")		WEEKDAY="1";;
	"$(gettext 'Tuesdays')")	WEEKDAY="2";;
	"$(gettext 'Wednesdays')")	WEEKDAY="3";;
	"$(gettext 'Thursdays')")	WEEKDAY="4";;
	"$(gettext 'Fridays')")		WEEKDAY="5";;
	"$(gettext 'Saturdays')")	WEEKDAY="6";;
	"$(gettext 'Sundays')")		WEEKDAY="0";;
	*)							WEEKDAY="*";;
esac

echo "$MINUTE"	> /tmp/pschedule-cronminute
echo "$HOUR"	> /tmp/pschedule-cronhour
echo "$DAY"		> /tmp/pschedule-cronday
echo "$MONTH"	> /tmp/pschedule-cronmonth
echo "$WEEKDAY"	> /tmp/pschedule-cronweekday
echo "$MINUTE $HOUR $DAY $MONTH $WEEKDAY  " > /tmp/pschedule-cron
