[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/utils/ -> RecurringType.php (source)

   1  <?php
   2  
   3  /* * *******************************************************************************
   4   * * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   5   * ("License"); You may not use this file except in compliance with the License
   6   * The Original Code is:  vtiger CRM Open Source
   7   * The Initial Developer of the Original Code is vtiger.
   8   * Portions created by vtiger are Copyright (C) vtiger.
   9   * All Rights Reserved.
  10   *
  11   * ****************************************************************************** */
  12  require_once ('include/utils/utils.php');
  13  require_once ('modules/Calendar/Date.php');
  14  global $app_strings;
  15  
  16  class RecurringType {
  17  
  18      var $recur_type;
  19      var $startdate;
  20      var $enddate;
  21      var $recur_freq;
  22      var $dayofweek_to_rpt = array();
  23      var $repeat_monthby;
  24      var $rptmonth_datevalue;
  25      var $rptmonth_daytype;
  26      var $recurringdates = array();
  27      var $reminder;
  28      var $recurringenddate; 
  29  
  30      /**
  31       * Constructor for class RecurringType
  32       * @param array  $repeat_arr     - array contains recurring info
  33       */
  34  	function RecurringType($repeat_arr) {
  35  
  36          $st_date = explode("-", $repeat_arr["startdate"]);
  37          $st_time = explode(":", $repeat_arr["starttime"]);
  38          $end_date = explode("-", $repeat_arr["enddate"]);
  39          $end_time = explode(":", $repeat_arr['endtime']);
  40          $recurringenddate = explode("-", $repeat_arr["recurringenddate"]); 
  41  
  42          $start_date = Array(
  43              'day' => $st_date[2],
  44              'month' => $st_date[1],
  45              'year' => $st_date[0],
  46              'hour' => $st_time[0],
  47              'min' => $st_time[1]
  48          );
  49          $end_date = Array(
  50              'day' => $end_date[2],
  51              'month' => $end_date[1],
  52              'year' => $end_date[0],
  53              'hour' => $end_time[0],
  54              'min' => $end_time[1]
  55          );
  56          $recurringenddate = Array( 
  57              'day' => $recurringenddate[2], 
  58              'month' => $recurringenddate[1], 
  59              'year' => $recurringenddate[0], 
  60          ); 
  61          $this->startdate = new vt_DateTime($start_date, true);
  62          $this->enddate = new vt_DateTime($end_date, true);
  63          $this->recurringenddate = new vt_DateTime($recurringenddate, true); 
  64  
  65          $this->recur_type = $repeat_arr['type'];
  66          $this->recur_freq = $repeat_arr['repeat_frequency'];
  67          if (empty($this->recur_freq)) {
  68              $this->recur_freq = 1;
  69          }
  70          $this->dayofweek_to_rpt = $repeat_arr['dayofweek_to_repeat'];
  71          $this->repeat_monthby = $repeat_arr['repeatmonth_type'];
  72          if (isset($repeat_arr['repeatmonth_date']))
  73              $this->rptmonth_datevalue = $repeat_arr['repeatmonth_date'];
  74          $this->rptmonth_daytype = $repeat_arr['repeatmonth_daytype'];
  75          
  76          $this->recurringdates = $this->_getRecurringDates();
  77      }
  78  
  79  	public static function fromUserRequest($requestArray) {
  80          // All the information from the user is received in User Time zone
  81          // Convert Start date and Time to DB Time zone
  82          $startDateObj = DateTimeField::convertToDBTimeZone($requestArray["startdate"] . ' ' . $requestArray['starttime']);
  83          $requestArray['startdate'] = $startDate = $startDateObj->format('Y-m-d');
  84          $requestArray['starttime'] = $startTime = $startDateObj->format('H:i');
  85          $endDateObj = DateTimeField::convertToDBTimeZone($requestArray["enddate"] . ' ' . $requestArray['endtime']);
  86          $requestArray['enddate'] = $endDate = $endDateObj->format('Y-m-d');
  87          $requestArray['endtime'] = $endTime = $endDateObj->format('H:i');
  88          if(!empty($requestArray["recurringenddate"])){ 
  89              $reccurringDateObj = DateTimeField::convertToDBTimeZone($requestArray["recurringenddate"] . ' ' . $requestArray['endtime']); 
  90              $requestArray['recurringenddate'] = $reccurringDateObj->format('Y-m-d'); 
  91          } 
  92  
  93          if ($requestArray['sun_flag']) {
  94              $requestArray['dayofweek_to_repeat'][] = 0;
  95          }
  96          if ($requestArray['mon_flag']) {
  97              $requestArray['dayofweek_to_repeat'][] = 1;
  98          }
  99          if ($requestArray['tue_flag']) {
 100              $requestArray['dayofweek_to_repeat'][] = 2;
 101          }
 102          if ($requestArray['wed_flag']) {
 103              $requestArray['dayofweek_to_repeat'][] = 3;
 104          }
 105          if ($requestArray['thu_flag']) {
 106              $requestArray['dayofweek_to_repeat'][] = 4;
 107          }
 108          if ($requestArray['fri_flag']) {
 109              $requestArray['dayofweek_to_repeat'][] = 5;
 110          }
 111          if ($requestArray['sat_flag']) {
 112              $requestArray['dayofweek_to_repeat'][] = 6;
 113          }
 114  
 115          if ($requestArray['type'] == 'Weekly') {
 116              if ($requestArray['dayofweek_to_repeat'] != null) {
 117                  $userStartDateTime = DateTimeField::convertToUserTimeZone($startDate . ' ' . $startTime);
 118                  $dayOfWeek = $requestArray['dayofweek_to_repeat'];
 119                  $dbDaysOfWeek = array();
 120                  for ($i = 0; $i < count($dayOfWeek); ++$i) {
 121                      $selectedDayOfWeek = $dayOfWeek[$i];
 122                      $currentDayOfWeek = $userStartDateTime->format('w');
 123                      $newDate = $userStartDateTime->format('d') + ($selectedDayOfWeek - $currentDayOfWeek);
 124                      $userStartDateTime->setDate($userStartDateTime->format('Y'), $userStartDateTime->format('m'), $newDate);
 125                      $dbDaysOfWeek[] = $userStartDateTime->format('w');
 126                  }
 127                  $requestArray['dayofweek_to_repeat'] = $dbDaysOfWeek;
 128              }
 129          } elseif ($requestArray['type'] == 'Monthly') {
 130              $userStartDateTime = DateTimeField::convertToUserTimeZone($startDate . ' ' . $startTime);
 131              if ($requestArray['repeatmonth_type'] == 'date') {
 132                  $dayOfMonth = $requestArray['repeatmonth_date'];
 133                  $userStartDateTime->setDate($userStartDateTime->format('Y'), $userStartDateTime->format('m'), $dayOfMonth);
 134                  $userStartDateTime->setTimezone(new DateTimeZone(DateTimeField::getDBTimeZone()));
 135                  $requestArray['repeatmonth_date'] = $userStartDateTime->format('d');
 136              } else {
 137                  $dayOfWeek = $requestArray['dayofweek_to_repeat'][0];
 138                  if ($requestArray['repeatmonth_daytype'] == 'first') {
 139                      $userStartDateTime->setDate($userStartDateTime->format('Y'), $userStartDateTime->format('m'), 1);
 140                      $dayOfWeekForFirstDay = $userStartDateTime->format('N');
 141                      if ($dayOfWeekForFirstDay < $dayOfWeek) {
 142                          $date = $dayOfWeek - $dayOfWeekForFirstDay + 1;
 143                      } else {
 144                          $date = (7 - $dayOfWeekForFirstDay) + $dayOfWeek + 1;
 145                      }
 146                  } elseif ($requestArray['repeatmonth_daytype'] == 'last') {
 147                      $daysInMonth = $userStartDateTime->format('t');
 148                      $userStartDateTime->setDate($userStartDateTime->format('Y'), $userStartDateTime->format('m'), $daysInMonth);
 149                      $dayOfWeekForLastDay = $userStartDateTime->format('N');
 150                      if ($dayOfWeekForLastDay < $dayOfWeek) {
 151                          $date = $daysInMonth - 7 + ($dayOfWeek - $dayOfWeekForLastDay);
 152                      } else {
 153                          $date = $daysInMonth - ($dayOfWeekForLastDay - $dayOfWeek);
 154                      }
 155                  }
 156                  $userStartDateTime->setDate($userStartDateTime->format('Y'), $userStartDateTime->format('m'), $date);
 157                  $userStartDateTime->setTimezone(new DateTimeZone(DateTimeField::getDBTimeZone()));
 158                  $requestArray['dayofweek_to_repeat'][0] = (int)$userStartDateTime->format('N')%7;
 159              }
 160          }
 161  
 162          return new RecurringType($requestArray);
 163      }
 164  
 165  	public static function fromDBRequest($resultRow) {
 166          // All the information from the database is received in DB Time zone
 167          
 168          $repeatInfo = array();
 169  
 170          $repeatInfo['startdate'] = $startDate = $resultRow['date_start'];
 171          $repeatInfo['starttime'] = $startTime = $resultRow['time_start'];
 172          $repeatInfo['enddate'] = $endDate = $resultRow['due_date'];
 173          $repeatInfo['endtime'] = $endTime = $resultRow['time_end'];
 174  
 175          $repeatInfo['type'] = $resultRow['recurringtype'];
 176          $repeatInfo['repeat_frequency'] = $resultRow['recurringfreq'];
 177          $repeatInfo['recurringenddate'] = $resultRow['recurringenddate']; 
 178  
 179          $recurringInfoString = $resultRow['recurringinfo'];
 180          $recurringInfo = explode('::', $recurringInfoString);
 181  
 182          if ($repeatInfo['type'] == 'Weekly') {
 183              $startIndex = 1; // 0 is for Recurring Type
 184              $length = count($recurringInfo);
 185              $j = 0;
 186              for ($i = $startIndex; $i < $length; ++$i) {
 187                  $repeatInfo['dayofweek_to_repeat'][$j++] = $recurringInfo[$i];
 188              }
 189          } elseif ($repeatInfo['type'] == 'Monthly') {
 190              $repeatInfo['repeatmonth_type'] = $recurringInfo[1];
 191              if ($repeatInfo['repeatmonth_type'] == 'date') {
 192                  $repeatInfo['repeatmonth_date'] = $recurringInfo[2];
 193              } else {
 194                  $repeatInfo['repeatmonth_daytype'] = $recurringInfo[2];
 195                  $repeatInfo['dayofweek_to_repeat'][0] = $recurringInfo[3];
 196              }
 197          }
 198  
 199          return new RecurringType($repeatInfo);
 200      }
 201  
 202  	function getRecurringType() {
 203          return $this->recur_type;
 204      }
 205  
 206  	function getRecurringFrequency() {
 207          return $this->recur_freq;
 208      }
 209  	function getRecurringEndDate() { 
 210          return $this->recurringenddate; 
 211      } 
 212  
 213  	function getDBRecurringInfoString() {
 214          $recurringType = $this->getRecurringType();
 215          $recurringInfo = '';
 216          if ($recurringType == 'Daily' || $recurringType == 'Yearly') {
 217              $recurringInfo = $recurringType;
 218          } elseif ($recurringType == 'Weekly') {
 219              if ($this->dayofweek_to_rpt != null) {
 220                  $recurringInfo = $recurringType . '::' . implode('::', $this->dayofweek_to_rpt);
 221              } else {
 222                  $recurringInfo = $recurringType;
 223              }
 224          } elseif ($recurringType == 'Monthly') {
 225              $recurringInfo = $recurringType . '::' . $this->repeat_monthby;
 226              if ($this->repeat_monthby == 'date') {
 227                  $recurringInfo = $recurringInfo . '::' . $this->rptmonth_datevalue;
 228              } else {
 229                  $recurringInfo = $recurringInfo . '::' . $this->rptmonth_daytype . '::' . $this->dayofweek_to_rpt[0];
 230              }
 231          }
 232  
 233          return $recurringInfo;
 234      }
 235  
 236  	function getUserRecurringInfo() {
 237          $recurringType = $this->getRecurringType();
 238          $recurringInfo = array();
 239  
 240          if ($recurringType == 'Weekly') {
 241              if ($this->dayofweek_to_rpt != null) {
 242                  $recurringInfo['dayofweek_to_repeat'] = $this->dayofweek_to_rpt;
 243              }
 244          } elseif ($recurringType == 'Monthly') {
 245              $dbStartDateTime = new DateTime($this->startdate->get_DB_formatted_date() . ' ' . $this->startdate->get_formatted_time());
 246              $recurringInfo['repeatmonth_type'] = $this->repeat_monthby;
 247              if ($this->repeat_monthby == 'date') {
 248                  $dayOfMonth = $this->rptmonth_datevalue;
 249                  $dbStartDateTime->setDate($dbStartDateTime->format('Y'), $dbStartDateTime->format('m'), $dayOfMonth);
 250                  $userStartDateTime = DateTimeField::convertToUserTimeZone($dbStartDateTime->format('Y-m-d') . ' ' . $dbStartDateTime->format('H:i'));
 251                  $recurringInfo['repeatmonth_date'] = $userStartDateTime->format('d');
 252              } else {
 253                  $dayOfWeek = $this->dayofweek_to_rpt[0];
 254                  $recurringInfo['repeatmonth_daytype'] = $this->rptmonth_daytype;
 255                  if ($this->rptmonth_daytype == 'first') {
 256                      $dbStartDateTime->setDate($dbStartDateTime->format('Y'), $dbStartDateTime->format('m'), 1);
 257                      $dayOfWeekForFirstDay = $dbStartDateTime->format('N');
 258                      if ($dayOfWeekForFirstDay < $dayOfWeek) {
 259                          $date = $dayOfWeek - $dayOfWeekForFirstDay + 1;
 260                      } else {
 261                          $date = (7 - $dayOfWeekForFirstDay) + $dayOfWeek + 1;
 262                      }
 263                  } elseif ($this->rptmonth_daytype == 'last') {
 264                      $daysInMonth = $dbStartDateTime->format('t');
 265                      $dbStartDateTime->setDate($dbStartDateTime->format('Y'), $dbStartDateTime->format('m'), $daysInMonth);
 266                      $dayOfWeekForLastDay = $dbStartDateTime->format('N');
 267                      if ($dayOfWeekForLastDay < $dayOfWeek) {
 268                          $date = $daysInMonth - 7 + ($dayOfWeek - $dayOfWeekForLastDay);
 269                      } else {
 270                          $date = $daysInMonth - ($dayOfWeekForLastDay - $dayOfWeek);
 271                      }
 272                  }
 273                  $dbStartDateTime->setDate($dbStartDateTime->format('Y'), $dbStartDateTime->format('m'), $date);
 274                  $userStartDateTime = DateTimeField::convertToUserTimeZone($dbStartDateTime->format('Y-m-d') . ' ' . $dbStartDateTime->format('H:i'));
 275                  $recurringInfo['dayofweek_to_repeat'][0] = (int)$userStartDateTime->format('N')%7;
 276              }
 277          }
 278          return $recurringInfo;
 279      }
 280  
 281  	function getDisplayRecurringInfo() {
 282          global $currentModule;
 283  
 284          $displayRecurringData = array();
 285  
 286          $recurringInfo = $this->getUserRecurringInfo();
 287  
 288          $displayRecurringData['recurringcheck'] = getTranslatedString('LBL_YES', $currentModule);
 289          $displayRecurringData['repeat_frequency'] = $this->getRecurringFrequency();
 290          $displayRecurringData['recurringtype'] = $this->getRecurringType();
 291  
 292          if ($this->getRecurringType() == 'Weekly') {
 293              $noOfDays = count($recurringInfo['dayofweek_to_repeat']);
 294              $translatedRepeatDays = array();
 295              for ($i = 0; $i < $noOfDays; ++$i) {
 296                  $translatedRepeatDays[] = getTranslatedString('LBL_DAY' . $recurringInfo['dayofweek_to_repeat'][$i], $currentModule);
 297              }
 298              $displayRecurringData['repeat_str'] = getTranslatedString('On', $currentModule).' '.implode(',', $translatedRepeatDays);
 299          } elseif ($this->getRecurringType() == 'Monthly') {
 300  
 301              $translatedRepeatDays = array();
 302              $displayRecurringData['repeatMonth'] = $recurringInfo['repeatmonth_type'];
 303              if ($recurringInfo['repeatmonth_type'] == 'date') {
 304                  $displayRecurringData['repeatMonth_date'] = $recurringInfo['repeatmonth_date'];
 305                  $displayRecurringData['repeat_str'] = getTranslatedString('on', $currentModule)
 306                          . ' ' . $recurringInfo['repeatmonth_date']
 307                          . ' ' . getTranslatedString('day of the month', $currentModule);
 308              } else {
 309                  $displayRecurringData['repeatMonth_daytype'] = $recurringInfo['repeatmonth_daytype'];
 310                  $displayRecurringData['repeatMonth_day'] = $recurringInfo['dayofweek_to_repeat'][0];
 311                  $translatedRepeatDay = getTranslatedString('LBL_DAY' . $recurringInfo['dayofweek_to_repeat'][0], $currentModule);
 312  
 313                  $displayRecurringData['repeat_str'] = getTranslatedString('On', $currentModule)
 314                          . ' ' . getTranslatedString($recurringInfo['repeatmonth_daytype'], $currentModule)
 315                          . ' ' . $translatedRepeatDay;
 316              }
 317          }
 318  
 319          return $displayRecurringData;
 320      }
 321  
 322      /**
 323       *  Function to get recurring dates depending on the recurring type
 324       *  return  array   $recurringDates     -  Recurring Dates in format
 325       *     Recurring date will be returned in DB Time Zone, as well as DB format
 326       */
 327  	function _getRecurringDates() {
 328          $startdateObj = $this->startdate;
 329          $startdate = $startdateObj->get_DB_formatted_date();
 330          $recurringDates[] = $startdate;
 331          $tempdateObj = $startdateObj;
 332          $tempdate = $startdate;
 333          $enddate = $this->enddate->get_DB_formatted_date();
 334  
 335          $dbDateTime = strtotime($startdate);
 336          $userDateTime = strtotime($startdateObj->get_userTimezone_formatted_date());
 337          $dateDiff = $dbDateTime - $userDateTime;
 338          if ($dateDiff < 0) {
 339              $dayDiff = $dateDiff/3600/24;
 340          } elseif ($dateDiff > 0) {
 341              $dayDiff = $dateDiff/3600/24;
 342          }
 343  
 344          while ($tempdate <= $enddate) {
 345              $date = $tempdateObj->get_Date();
 346              $month = $tempdateObj->getMonth();
 347              $year = $tempdateObj->getYear();
 348  
 349              if ($this->recur_type == 'Daily') {
 350                  if (isset($this->recur_freq)) {
 351                      $index = $date + $this->recur_freq - 1;
 352                  } else {
 353                      $index = $date;
 354                  }
 355                  $tempdateObj = $this->startdate->getThismonthDaysbyIndex($index, '', $month, $year);
 356                  $tempdate = $tempdateObj->get_DB_formatted_date();
 357                  if($tempdate <= $enddate) {
 358                      $recurringDates[] = $tempdate;
 359                  }
 360              } elseif ($this->recur_type == 'Weekly') {
 361                  if (count($this->dayofweek_to_rpt) == 0) {
 362                      $this->dayofweek_to_rpt[] = $this->startdate->dayofweek;
 363                  }
 364  
 365                  for ($i = 0; $i < count($this->dayofweek_to_rpt); $i++) {
 366                      $repeat = $this->dayofweek_to_rpt[$i];
 367                      if ($repeat == 0) {
 368                          $repeat = $repeat+1;
 369                          $isSunday = true;
 370                      }
 371                      $repeatDay = $tempdateObj->getThisweekDaysbyIndex($repeat);
 372                      $repeatDate = $repeatDay->get_DB_formatted_date();
 373                      if ($dayDiff) {
 374                          $repeatDate = date('Y-m-d', strtotime($dayDiff.' day', strtotime($repeatDate)));
 375                      }
 376                      if ($isSunday) {
 377                          $repeatDate = date('Y-m-d', strtotime('-1 day', strtotime($repeatDate)));
 378                          $isSunday = false;
 379                      }
 380                      if ($repeatDate > $startdate && $repeatDate <= $enddate) {
 381                          $recurringDates[] = $repeatDate;
 382                      }
 383                  }
 384  
 385                  if (isset($this->recur_freq)) {
 386                      $index = $this->recur_freq * 7;
 387                  } else {
 388                      $index = 7;
 389                  }
 390                  $date_arr = Array(
 391                      'day' => $date + $index,
 392                      'month' => $month,
 393                      'year' => $year
 394                  );
 395                  $tempdateObj = new vt_DateTime($date_arr, true);
 396                  $tempdate = $tempdateObj->get_DB_formatted_date();
 397              } elseif ($this->recur_type == 'Monthly') {
 398                  if ($this->repeat_monthby == 'date') {
 399                      if ($this->rptmonth_datevalue <= $date) {
 400                          $index = $this->rptmonth_datevalue - 1;
 401                          $day = $this->rptmonth_datevalue;
 402                          if (isset($this->recur_freq))
 403                              $month = $month + $this->recur_freq;
 404                          else
 405                              $month = $month + 1;
 406                          $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
 407                      }
 408                      else {
 409                          $index = $this->rptmonth_datevalue - 1;
 410                          $day = $this->rptmonth_datevalue;
 411                          $tempdateObj = $tempdateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
 412                      }
 413                  } elseif ($this->repeat_monthby == 'day') {
 414                      if ($this->rptmonth_daytype == 'first') {
 415                          $date_arr = Array(
 416                              'day' => 1,
 417                              'month' => $month,
 418                              'year' => $year
 419                          );
 420                          $tempdateObj = new vt_DateTime($date_arr, true);
 421                          $firstdayofmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj);
 422                          if ($firstdayofmonthObj->get_DB_formatted_date() <= $tempdate) {
 423                              if (isset($this->recur_freq))
 424                                  $month = $firstdayofmonthObj->getMonth() + $this->recur_freq;
 425                              else
 426                                  $month = $firstdayofmonthObj->getMonth() + 1;
 427                              $dateObj = $firstdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $firstdayofmonthObj->getYear());
 428                              $nextmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0], $dateObj);
 429                              $tempdateObj = $nextmonthObj;
 430                          } else {
 431                              $tempdateObj = $firstdayofmonthObj;
 432                          }
 433                      } elseif ($this->rptmonth_daytype == 'last') {
 434                          $date_arr = Array(
 435                              'day' => $tempdateObj->getDaysInMonth(),
 436                              'month' => $tempdateObj->getMonth(),
 437                              'year' => $tempdateObj->getYear()
 438                          );
 439                          $tempdateObj = new vt_DateTime($date_arr, true);
 440                          $lastdayofmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $tempdateObj);
 441                          if ($lastdayofmonthObj->get_DB_formatted_date() <= $tempdate) {
 442                              if (isset($this->recur_freq))
 443                                  $month = $lastdayofmonthObj->getMonth() + $this->recur_freq;
 444                              else
 445                                  $month = $lastdayofmonthObj->getMonth() + 1;
 446                              $dateObj = $lastdayofmonthObj->getThismonthDaysbyIndex(0, 1, $month, $lastdayofmonthObj->getYear());
 447                              $dateObj = $dateObj->getThismonthDaysbyIndex($dateObj->getDaysInMonth() - 1,
 448                                              $dateObj->getDaysInMonth(), $month, $lastdayofmonthObj->getYear());
 449                              $nextmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0], $dateObj);
 450                              $tempdateObj = $nextmonthObj;
 451                          }
 452                          else {
 453                              $tempdateObj = $lastdayofmonthObj;
 454                          }
 455                      }
 456                  } else {
 457                      $date_arr = Array(
 458                          'day' => $date,
 459                          'month' => $month + 1,
 460                          'year' => $year
 461                      );
 462                      $tempdateObj = new vt_DateTime($date_arr, true);
 463                  }
 464                  $tempdate = $tempdateObj->get_DB_formatted_date();
 465                  if ($tempdate <= $enddate) {
 466                      $recurringDates[] = $tempdate;
 467                  }
 468              } elseif ($this->recur_type == 'Yearly') {
 469  
 470                  if (isset($this->recur_freq))
 471                      $index = $year + $this->recur_freq;
 472                  else
 473                      $index = $year + 1;
 474                  if ($index > 2037 || $index < 1970) {
 475                      print("<font color='red'>" . $app_strings['LBL_CAL_LIMIT_MSG'] . "</font>");
 476                      exit;
 477                  }
 478                  $date_arr = Array(
 479                      'day' => $date,
 480                      'month' => $month,
 481                      'year' => $index
 482                  );
 483                  $tempdateObj = new vt_DateTime($date_arr, true);
 484                  $tempdate = $tempdateObj->get_DB_formatted_date();
 485                  if ($tempdate <= $enddate) {
 486                      $recurringDates[] = $tempdate;
 487                  }
 488              } else {
 489                  die("Recurring Type " . $this->recur_type . " is not defined");
 490              }
 491          }
 492          return $recurringDates;
 493      }
 494  
 495      /** Function to get first day of the month(like first Monday or Friday and etc.)
 496       *  @param $dayofweek   -- day of the week to repeat the event :: Type string
 497       *  @param $dateObj     -- date object  :: Type vt_DateTime Object
 498       *  return $dateObj -- the date object on which the event repeats :: Type vt_DateTime Object
 499       */
 500  	function getFistdayofmonth($dayofweek, & $dateObj) {
 501          if ($dayofweek < $dateObj->dayofweek) {
 502              $index = (7 - $dateObj->dayofweek) + $dayofweek;
 503              $day = 1 + $index;
 504              $month = $dateObj->month;
 505              $year = $dateObj->year;
 506              $dateObj = $dateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
 507          } else {
 508              $index = $dayofweek - $dateObj->dayofweek;
 509              $day = 1 + $index;
 510              $month = $dateObj->month;
 511              $year = $dateObj->year;
 512              $dateObj = $dateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
 513          }
 514          return $dateObj;
 515      }
 516  
 517      /** Function to get last day of the month(like last Monday or Friday and etc.)
 518       *  @param $dayofweek   -- day of the week to repeat the event :: Type string
 519       *  @param $dateObj     -- date object  :: Type vt_DateTime Object
 520       *  return $dateObj -- the date object on which the event repeats :: Type vt_DateTime Object
 521       */
 522  	function getLastdayofmonth($dayofweek, & $dateObj) {
 523          if ($dayofweek == $dateObj->dayofweek) {
 524              return $dateObj;
 525          } else {
 526              if ($dayofweek > $dateObj->dayofweek)
 527                  $day = $dateObj->day - 7 + ($dayofweek - $dateObj->dayofweek);
 528              else
 529                  $day = $dateObj->day - ($dateObj->dayofweek - $dayofweek);
 530              $index = $day - 1;
 531              $month = $dateObj->month;
 532              $year = $dateObj->year;
 533              $dateObj = $dateObj->getThismonthDaysbyIndex($index, $day, $month, $year);
 534              return $dateObj;
 535          }
 536      }
 537  
 538  }
 539  
 540  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1