Hi there,
I currently have a page that contains three select boxes.
The first select box contains the week end date
The second select box contains the month
The third select box, the year.
Depending on what month or year is selected, the week end dates are calculated.
What i want to do now is add two buttons.
A button to get the previous week end and a button for the next week end.
This is so I don't have to always use the select boxes.
With the code I am supplying below, how would I make this possible?
I call the function like this
create_header_dates("$selYear", "$selMonth", "$selWeek", "$hdnTspage");
if ($selYear && $selWeek) {
$iMth = $selMonth + 1;
if ($iMth!='11' && $iMth!='12') {
$iMth = "0".$iMth;
}
$week_end_date = "$selYear-$iMth-$selWeek";
}
here is the function:
function create_header_dates($selYear, $selMonth, $selWeek, $hdnTspage) {
$CONST_WEEK_END = 0;
$curr_week_end = -1;
$previous_week;
$previous_month;
$previous_year;
// if the selected values are unknown then set the default to today
if ($selYear && $selWeek) {
$yr = $selYear;
$mth = $selMonth;
$day = $selWeek;
}
// if no available date, use the current date
else {
$day = date("d");
$mth = date("m");
$yr = date("Y");
$mth = $mth-1;
}
$daysInMth = cal_days_in_month (CAL_GREGORIAN, $mth+1, $yr);
$daysInMthPrev = cal_days_in_month (CAL_GREGORIAN, $mth, $yr);
/********* Calculate the value of the week pager *********/
// Set Current Week End Date
// iterate through the 7 days following today until you get
// to the last day of the week
for ($i=0; $i<= 7; $i++) {
$calc_day = $day+$i;
// if it is the last day of the month and it is not a Sunday
// then the curr_week_end is set to -1 b/c the next week end
// is not in this month
$julianDay = gregoriantojd ($mth+1, $calc_day, $yr);
$dayOfWeek = jddayofweek ($julianDay, 0);
if ($calc_day == $daysInMth && $dayOfWeek != $CONST_WEEK_END)
{
$curr_week_end = -1;
break;
}
// else if we have retrieved the next week-ending day
// set this as the week value
else if ($dayOfWeek == $CONST_WEEK_END)
{
$curr_week_end=$calc_day;
break;
}
}
// Run out of Week Ends. Need to default to start of next month
if ($curr_week_end == -1)
{
$mth++;
if ($mth==11) {
$mth=0;
$yr++;
}
$calc_day = 1;
// set week ending day as the first one in that month
for ($i=0; $i<= 7; $i++) {
$calc_day = $calc_day+$i;
$julianDay = gregoriantojd ($mth+1, $calc_day, $yr);
$dayOfWeek = jddayofweek ($julianDay, 0);
// if we have retrieved the next week-ending day
// set this as the week value
if ($dayOfWeek == $CONST_WEEK_END)
{
$curr_week_end=$calc_day;
break;
}
}
}
print "<select id='selWeekHeader' Size=1 Onchange=\"goto_url('$hdnTspage','headerDatesChanged=changed');\"> \n";
for ($i=1; $i<=$daysInMth; $i++) {
$calc_day = $i;
$julianDay = gregoriantojd ($mth+1, $calc_day, $yr);
$dayOfWeek = jddayofweek ($julianDay, 0);
if ($dayOfWeek == $CONST_WEEK_END) {
if ($curr_week_end == $calc_day) {
print "<option selected value='$calc_day'>$calc_day\n";
} else {
print "<option value='$calc_day'>$calc_day\n";
}
}
}
print "</select>\n";
/********* Calculate the value of the month pager *********/
$moy = array();
$moy[0] = "January";
$moy[1] = "February";
$moy[2] = "March";
$moy[3] = "April";
$moy[4] = "May";
$moy[5] = "June";
$moy[6] = "July";
$moy[7] = "August";
$moy[8] = "September";
$moy[9] = "October";
$moy[10] = "November";
$moy[11] = "December";
print "<select id='selMonthHeader' Size=1 onChange=\"goto_url('$hdnTspage','headerDatesChanged=changed');\"> \n";
for ($i=0; $i < count($moy); $i++) {
if ($mth == $i) {
print "<option selected value='$i'>".$moy[$i]."\n";
} else {
print "<option value='$i'>".$moy[$i]."\n";
}
}
print "</select>";
/********* Calculate the value of the year pager *********/
$locYear = date("Y");
$daysInMth = cal_days_in_month (CAL_GREGORIAN, $mth+1, $yr);
for ($i=0; $i<= 7; $i++) {
$calc_day = $day + $i;
$julianDay = gregoriantojd ($mth+1, $calc_day, $yr);
$dayOfWeek = jddayofweek ($julianDay, 0);
if ($calc_day == $daysInMth && $dayOfWeek != $CONST_WEEK_END && $mth == 11)
{
$yr++;
break;
}
else if ($dayOfWeek == $CONST_WEEK_END)
{
break;
}
}
print "<select id='selYearHeader' Size=1 onChange=\"goto_url('$hdnTspage','headerDatesChanged=changed');\">";
for ($i=$locYear-2; $i <= $locYear+1; $i++) {
if ($yr == $i ) {
print "<option selected value='$i'>$i";
} else {
print "<option value='$i'>$i";
}
}
print "</select>";