예제 #1
0
 /**
  *  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;
 }