Beispiel #1
0
 /**
  *  Function to get recurring dates depending on the recurring type
  *  return  array   $recurringDates     -  Recurring Dates in format
  */
 function getRecurringDates()
 {
     $startdate = $this->startdate->get_formatted_date();
     $recurringDates[] = $startdate;
     $tempdate = $startdate;
     $enddate = $this->enddate->get_formatted_date();
     while ($tempdate <= $enddate) {
         if ($this->recur_type == 'Daily') {
             $st_date = explode("-", $tempdate);
             if (isset($this->recur_freq)) {
                 $index = $st_date[2] + $this->recur_freq - 1;
             } else {
                 $index = $st_date[2];
             }
             $tempdateObj = $this->startdate->getThismonthDaysbyIndex($index, '', $st_date[1], $st_date[0]);
             $tempdate = $tempdateObj->get_formatted_date();
             $recurringDates[] = $tempdate;
         } elseif ($this->recur_type == 'Weekly') {
             $st_date = explode("-", $tempdate);
             $date_arr = array('day' => $st_date[2], 'month' => $st_date[1], 'year' => $st_date[0]);
             $tempdateObj = new vt_DateTime($date_arr, true);
             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_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' => $st_date[2] + $index, 'month' => $st_date[1], 'year' => $st_date[0]);
             $tempdateObj = new vt_DateTime($date_arr, true);
             $tempdate = $tempdateObj->get_formatted_date();
         } elseif ($this->recur_type == 'Monthly') {
             $st_date = explode("-", $tempdate);
             $date_arr = array('day' => $st_date[2], 'month' => $st_date[1], 'year' => $st_date[0]);
             $startdateObj = new vt_DateTime($date_arr, true);
             if ($this->repeat_monthby == 'date') {
                 if ($this->rptmonth_datevalue <= $st_date[2]) {
                     $index = $this->rptmonth_datevalue - 1;
                     $day = $this->rptmonth_datevalue;
                     if (isset($this->recur_freq)) {
                         $month = $st_date[1] + $this->recur_freq;
                     } else {
                         $month = $st_date[1] + 1;
                     }
                     $year = $st_date[0];
                     $tempdateObj = $startdateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
                 } else {
                     $index = $this->rptmonth_datevalue - 1;
                     $day = $this->rptmonth_datevalue;
                     $month = $st_date[1];
                     $year = $st_date[0];
                     $tempdateObj = $startdateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
                 }
             } elseif ($this->repeat_monthby == 'day') {
                 if ($this->rptmonth_daytype == 'first') {
                     $date_arr = array('day' => 1, 'month' => $st_date[1], 'year' => $st_date[0]);
                     $tempdateObj = new vt_DateTime($date_arr, true);
                     $firstdayofmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj);
                     if ($firstdayofmonthObj->get_formatted_date() <= $tempdate) {
                         if (isset($this->recur_freq)) {
                             $month = $firstdayofmonthObj->month + $this->recur_freq;
                         } else {
                             $month = $firstdayofmonthObj->month + 1;
                         }
                         $dateObj = $firstdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $firstdayofmonthObj->year);
                         $nextmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $dateObj);
                         $tempdateObj = $nextmonthObj;
                     } else {
                         $tempdateObj = $firstdayofmonthObj;
                     }
                 } elseif ($this->rptmonth_daytype == 'last') {
                     $date_arr = array('day' => $startdateObj->daysinmonth, 'month' => $startdateObj->month, 'year' => $startdateObj->year);
                     $tempdateObj = new vt_DateTime($date_arr, true);
                     $lastdayofmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj);
                     if ($lastdayofmonthObj->get_formatted_date() <= $tempdate) {
                         if (isset($this->recur_freq)) {
                             $month = $lastdayofmonthObj->month + $this->recur_freq;
                         } else {
                             $month = $lastdayofmonthObj->month + 1;
                         }
                         $dateObj = $lastdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $lastdayofmonthObj->year);
                         $dateObj = $dateObj->getThismonthDaysbyIndex($dateObj->daysinmonth - 1, $dateObj->daysinmonth, $month, $lastdayofmonthObj->year);
                         $nextmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $dateObj);
                         $tempdateObj = $nextmonthObj;
                     } else {
                         $tempdateObj = $lastdayofmonthObj;
                     }
                 }
             } else {
                 $date_arr = array('day' => $st_date[2], 'month' => $st_date[1] + 1, 'year' => $st_date[0]);
                 $tempdateObj = new vt_DateTime($date_arr, true);
             }
             $tempdate = $tempdateObj->get_formatted_date();
             $recurringDates[] = $tempdate;
         } elseif ($this->recur_type == 'Yearly') {
             $st_date = explode("-", $tempdate);
             if (isset($this->recur_freq)) {
                 $index = $st_date[0] + $this->recur_freq;
             } else {
                 $index = $st_date[0] + 1;
             }
             if ($index > 2037 || $index < 1970) {
                 print "<font color='red'>" . $app_strings['LBL_CAL_LIMIT_MSG'] . "</font>";
                 exit;
             }
             $date_arr = array('day' => $st_date[2], 'month' => $st_date[1], 'year' => $index);
             $tempdateObj = new vt_DateTime($date_arr, true);
             $tempdate = $tempdateObj->get_formatted_date();
             $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();
     $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;
 }