/** * Function to get recurring dates depending on the recurring type * return array $recurringDates - Recurring Dates in format * Recurring date will be returned in DB Time Zone, as well as DB format */ function _getRecurringDates() { $startdateObj = $this->startdate; $startdate = $startdateObj->get_DB_formatted_date(); $recurringDates[] = $startdate; $tempdateObj = $startdateObj; $tempdate = $startdate; $enddate = $this->enddate->get_DB_formatted_date(); $dbDateTime = strtotime($startdate); $userDateTime = strtotime($startdateObj->get_userTimezone_formatted_date()); $dateDiff = $dbDateTime - $userDateTime; if ($dateDiff < 0) { $dayDiff = $dateDiff / 3600 / 24; } elseif ($dateDiff > 0) { $dayDiff = $dateDiff / 3600 / 24; } while ($tempdate <= $enddate) { $date = $tempdateObj->get_Date(); $month = $tempdateObj->getMonth(); $year = $tempdateObj->getYear(); if ($this->recur_type == 'Daily') { if (isset($this->recur_freq)) { $index = $date + $this->recur_freq - 1; } else { $index = $date; } $tempdateObj = $this->startdate->getThismonthDaysbyIndex($index, '', $month, $year); $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } elseif ($this->recur_type == 'Weekly') { if (count($this->dayofweek_to_rpt) == 0) { $this->dayofweek_to_rpt[] = $this->startdate->dayofweek; } for ($i = 0; $i < count($this->dayofweek_to_rpt); $i++) { $repeat = $this->dayofweek_to_rpt[$i]; if ($repeat == 0) { $repeat = $repeat + 1; $isSunday = true; } $repeatDay = $tempdateObj->getThisweekDaysbyIndex($repeat); $repeatDate = $repeatDay->get_DB_formatted_date(); if ($dayDiff) { $repeatDate = date('Y-m-d', strtotime($dayDiff . ' day', strtotime($repeatDate))); } if ($isSunday) { $repeatDate = date('Y-m-d', strtotime('-1 day', strtotime($repeatDate))); $isSunday = false; } if ($repeatDate > $startdate && $repeatDate <= $enddate) { $recurringDates[] = $repeatDate; } } if (isset($this->recur_freq)) { $index = $this->recur_freq * 7; } else { $index = 7; } $date_arr = array('day' => $date + $index, 'month' => $month, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); $tempdate = $tempdateObj->get_DB_formatted_date(); } elseif ($this->recur_type == 'Monthly') { if ($this->repeat_monthby == 'date') { if ($this->rptmonth_datevalue <= $date) { $index = $this->rptmonth_datevalue - 1; $day = $this->rptmonth_datevalue; if (isset($this->recur_freq)) { $month = $month + $this->recur_freq; } else { $month = $month + 1; } $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year); } else { $index = $this->rptmonth_datevalue - 1; $day = $this->rptmonth_datevalue; $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year); } } elseif ($this->repeat_monthby == 'day') { if ($this->rptmonth_daytype == 'first') { $date_arr = array('day' => 1, 'month' => $month, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); $firstdayofmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj); if ($firstdayofmonthObj->get_DB_formatted_date() <= $tempdate) { if (isset($this->recur_freq)) { $month = $firstdayofmonthObj->getMonth() + $this->recur_freq; } else { $month = $firstdayofmonthObj->getMonth() + 1; } $dateObj = $firstdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $firstdayofmonthObj->getYear()); $nextmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $dateObj); $tempdateObj = $nextmonthObj; } else { $tempdateObj = $firstdayofmonthObj; } } elseif ($this->rptmonth_daytype == 'last') { $date_arr = array('day' => $tempdateObj->getDaysInMonth(), 'month' => $tempdateObj->getMonth(), 'year' => $tempdateObj->getYear()); $tempdateObj = new vt_DateTime($date_arr, true); $lastdayofmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj); if ($lastdayofmonthObj->get_DB_formatted_date() <= $tempdate) { if (isset($this->recur_freq)) { $month = $lastdayofmonthObj->getMonth() + $this->recur_freq; } else { $month = $lastdayofmonthObj->getMonth() + 1; } $dateObj = $lastdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $lastdayofmonthObj->getYear()); $dateObj = $dateObj->getThismonthDaysbyIndex($dateObj->getDaysInMonth() - 1, $dateObj->getDaysInMonth(), $month, $lastdayofmonthObj->getYear()); $nextmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $dateObj); $tempdateObj = $nextmonthObj; } else { $tempdateObj = $lastdayofmonthObj; } } } else { $date_arr = array('day' => $date, 'month' => $month + 1, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); } $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } elseif ($this->recur_type == 'Yearly') { if (isset($this->recur_freq)) { $index = $year + $this->recur_freq; } else { $index = $year + 1; } if ($index > 2037 || $index < 1970) { print "<font color='red'>" . $app_strings['LBL_CAL_LIMIT_MSG'] . "</font>"; exit; } $date_arr = array('day' => $date, 'month' => $month, 'year' => $index); $tempdateObj = new vt_DateTime($date_arr, true); $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } else { die("Recurring Type " . $this->recur_type . " is not defined"); } } return $recurringDates; }
/** * Function to get recurring dates depending on the recurring type * return array $recurringDates - Recurring Dates in format * Recurring date will be returned in DB Time Zone, as well as DB format */ function _getRecurringDates() { $startdateObj = $this->startdate; $startdate = $startdateObj->get_DB_formatted_date(); $recurringDates[] = $startdate; $tempdateObj = $startdateObj; $tempdate = $startdate; $enddate = $this->enddate->get_DB_formatted_date(); while ($tempdate <= $enddate) { $date = $tempdateObj->get_Date(); $month = $tempdateObj->getMonth(); $year = $tempdateObj->getYear(); if ($this->recur_type == 'Daily') { if (isset($this->recur_freq)) { $index = $date + $this->recur_freq - 1; } else { $index = $date; } $tempdateObj = $this->startdate->getThismonthDaysbyIndex($index, '', $month, $year); $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } elseif ($this->recur_type == 'Weekly') { if (count($this->dayofweek_to_rpt) == 0) { $this->dayofweek_to_rpt[] = $this->startdate->dayofweek; } for ($i = 0; $i < count($this->dayofweek_to_rpt); $i++) { $repeatDay = $tempdateObj->getThisweekDaysbyIndex($this->dayofweek_to_rpt[$i]); $repeatDate = $repeatDay->get_DB_formatted_date(); if ($repeatDate > $startdate && $repeatDate <= $enddate) { $recurringDates[] = $repeatDate; } } if (isset($this->recur_freq)) { $index = $this->recur_freq * 7; } else { $index = 7; } $date_arr = array('day' => $date + $index, 'month' => $month, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); $tempdate = $tempdateObj->get_DB_formatted_date(); } elseif ($this->recur_type == 'Monthly') { if ($this->repeat_monthby == 'date') { if ($this->rptmonth_datevalue <= $date) { $index = $this->rptmonth_datevalue - 1; $day = $this->rptmonth_datevalue; if (isset($this->recur_freq)) { $month = $month + $this->recur_freq; } else { $month = $month + 1; } $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year); } else { $index = $this->rptmonth_datevalue - 1; $day = $this->rptmonth_datevalue; $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year); } } elseif ($this->repeat_monthby == 'day') { if ($this->rptmonth_daytype == 'first') { $date_arr = array('day' => 1, 'month' => $month, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); $firstdayofmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj); if ($firstdayofmonthObj->get_DB_formatted_date() <= $tempdate) { if (isset($this->recur_freq)) { $month = $firstdayofmonthObj->getMonth() + $this->recur_freq; } else { $month = $firstdayofmonthObj->getMonth() + 1; } $dateObj = $firstdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $firstdayofmonthObj->getYear()); $nextmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $dateObj); $tempdateObj = $nextmonthObj; } else { $tempdateObj = $firstdayofmonthObj; } } elseif ($this->rptmonth_daytype == 'second' or $this->rptmonth_daytype == 'third') { $position = $this->rptmonth_daytype == 'second' ? 2 : 3; $date_arr = array('day' => $this->getDayOfWeekPerWeekPositionInMonth($this->dayofweek_to_rpt[0], $year, $month, $position), 'month' => $month, 'year' => $year); $nextdayofmonthObj = new vt_DateTime($date_arr, true); if ($nextdayofmonthObj->get_DB_formatted_date() <= $tempdate) { if (isset($this->recur_freq)) { $month = $nextdayofmonthObj->getMonth() + $this->recur_freq; } else { $month = $nextdayofmonthObj->getMonth() + 1; } $date_arr = array('day' => $this->getDayOfWeekPerWeekPositionInMonth($this->dayofweek_to_rpt[0], $year, $month, $position), 'month' => $month, 'year' => $year); $nextdayofmonthObj = new vt_DateTime($date_arr, true); } $tempdateObj = $nextdayofmonthObj; } elseif ($this->rptmonth_daytype == 'last') { $date_arr = array('day' => $tempdateObj->getDaysInMonth(), 'month' => $tempdateObj->getMonth(), 'year' => $tempdateObj->getYear()); $tempdateObj = new vt_DateTime($date_arr, true); $lastdayofmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj); if ($lastdayofmonthObj->get_DB_formatted_date() <= $tempdate) { if (isset($this->recur_freq)) { $month = $lastdayofmonthObj->getMonth() + $this->recur_freq; } else { $month = $lastdayofmonthObj->getMonth() + 1; } $dateObj = $lastdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $lastdayofmonthObj->getYear()); $dateObj = $dateObj->getThismonthDaysbyIndex($dateObj->getDaysInMonth() - 1, $dateObj->getDaysInMonth(), $month, $lastdayofmonthObj->getYear()); $nextmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $dateObj); $tempdateObj = $nextmonthObj; } else { $tempdateObj = $lastdayofmonthObj; } } } else { $date_arr = array('day' => $date, 'month' => $month + 1, 'year' => $year); $tempdateObj = new vt_DateTime($date_arr, true); } $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } elseif ($this->recur_type == 'Yearly') { if (isset($this->recur_freq)) { $index = $year + $this->recur_freq; } else { $index = $year + 1; } if ($index > 2037 || $index < 1970) { print "<font color='red'>" . $app_strings['LBL_CAL_LIMIT_MSG'] . "</font>"; exit; } $date_arr = array('day' => $date, 'month' => $month, 'year' => $index); $tempdateObj = new vt_DateTime($date_arr, true); $tempdate = $tempdateObj->get_DB_formatted_date(); if ($tempdate <= $enddate) { $recurringDates[] = $tempdate; } } else { die("Recurring Type " . $this->recur_type . " is not defined"); } } return $recurringDates; }