PCHomepage
Programmer
I am creating a calendaring application and need to be able to optionally select a check-box or select-box and have it submit entries the same day of the week throughout the month or even for several months. I already have the values for the beginning and ending of the month in the code but need to know how to get the days required.
Below is the preliminary code that I'm using just to test and for testing, it is using only hard-coded values rather than form submission. This is just a rough draft but what's there is working to repeat an event daily for the whole month or for a specific number of days.
Below is the preliminary code that I'm using just to test and for testing, it is using only hard-coded values rather than form submission. This is just a rough draft but what's there is working to repeat an event daily for the whole month or for a specific number of days.
PHP:
/* Sample form fields shown for reference.
<select name="NoDays">
<option value="">Select Days (optional)</option>
<option value="1">Repeat 1 Day</option>
<option value="2">Repeat 2 Days</option>
<option value="3">Repeat 3 Days</option>
<option value="4">Repeat 4 Days</option>
<option value="5">Repeat 5 Days</option>
<option value="31">Repeat Every Day</option>
</select>
<input type="checkbox" name="RepeatMonthly" value="1">
*/
$RepeatDaily = 1;
$RepType = ($RepeatDaily == 1) ? "days" : "week";
$NumberDays = 4;
$NoDays = ($NumberDays >= 1) ? $NumberDays : "";
$cBegin = strtotime($rowCalendar['Start']);
$cEnd = strtotime($rowCalendar['End']);
$cLast = ($NoDays == 0) ? strtotime('last day of this month', $cEnd) : strtotime('+'.$NoDays.' days', $cEnd);
// Get beginning date/time, otherwise listing starts with the next day
echo $rowCalendar['StaffID'].", ".date("Y-m-d H:i:s",$cBegin).", ".date("Y-m-d H:i:s",$cEnd)."<br>";
while($cBegin <= $cLast) :
echo $rowCalendar['StaffID'].", ".date("Y-m-d H:i:s",$cBegin).", ".date("Y-m-d H:i:s",$cEnd)."<br>";
$cBegin = strtotime('+1 '.$RepType, $cBegin);
$cEnd = strtotime('+1 '.$RepType, $cEnd);
endwhile;