[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 require_once ('include/utils/utils.php'); 12 require_once ('modules/Calendar/Date.php'); 13 class RecurringType 14 { 15 var $recur_type; 16 var $startdate; 17 var $enddate; 18 var $recur_freq; 19 var $dayofweek_to_rpt = array(); 20 var $repeat_monthby; 21 var $rptmonth_datevalue; 22 var $rptmonth_daytype; 23 var $recurringdates = array(); 24 var $reminder; 25 26 /** 27 * Constructor for class RecurringType 28 * @param array $repeat_arr - array contains recurring info 29 */ 30 function RecurringType($repeat_arr) 31 { 32 //to get startdate and enddate in yyyy-mm-dd format 33 $st_date = explode("-",getDBInsertDateValue($repeat_arr["startdate"])); 34 $end_date = explode("-",getDBInsertDateValue($repeat_arr["enddate"])); 35 $start_date = Array( 36 'day' => $st_date[2], 37 'month' => $st_date[1], 38 'year' => $st_date[0] 39 ); 40 $end_date = Array( 41 'day' => $end_date[2], 42 'month' => $end_date[1], 43 'year' => $end_date[0] 44 ); 45 $this->recur_type = $repeat_arr['type']; 46 $this->recur_freq = $repeat_arr['repeat_frequency']; 47 $this->startdate = new DateTime($start_date,true); 48 $this->enddate = new DateTime($end_date,true); 49 if($repeat_arr['sun_flag']) 50 { 51 $this->dayofweek_to_rpt[] = 0; 52 } 53 if($repeat_arr['mon_flag']) 54 { 55 $this->dayofweek_to_rpt[] = 1; 56 } 57 if($repeat_arr['tue_flag']) 58 { 59 $this->dayofweek_to_rpt[] = 2; 60 } 61 if($repeat_arr['wed_flag']) 62 { 63 $this->dayofweek_to_rpt[] = 3; 64 } 65 if($repeat_arr['thu_flag']) 66 { 67 $this->dayofweek_to_rpt[] = 4; 68 } 69 if($repeat_arr['fri_flag']) 70 { 71 $this->dayofweek_to_rpt[] = 5; 72 } 73 if($repeat_arr['sat_flag']) 74 { 75 $this->dayofweek_to_rpt[] = 6; 76 } 77 $this->repeat_monthby = $repeat_arr['repeatmonth_type']; 78 if(isset($repeat_arr['repeatmonth_date'])) 79 $this->rptmonth_datevalue = $repeat_arr['repeatmonth_date']; 80 $this->rptmonth_daytype = $repeat_arr['repeatmonth_daytype']; 81 $this->recurringdates = $this->getRecurringDates(); 82 } 83 84 /** 85 * Function to get recurring dates depending on the recurring type 86 * return array $recurringDates - Recurring Dates in format 87 */ 88 89 function getRecurringDates() 90 { 91 $startdate = $this->startdate->get_formatted_date(); 92 $tempdate = $startdate; 93 $enddate = $this->enddate->get_formatted_date(); 94 while($tempdate <= $enddate) 95 { 96 if($this->recur_type == 'Daily') 97 { 98 $recurringDates[] = $tempdate; 99 $st_date = explode("-",$tempdate); 100 if(isset($this->recur_freq)) 101 $index = $st_date[2] + $this->recur_freq - 1; 102 else 103 $index = $st_date[2]; 104 $tempdateObj = $this->startdate->getThismonthDaysbyIndex($index,'',$st_date[1],$st_date[0]); 105 $tempdate = $tempdateObj->get_formatted_date(); 106 } 107 elseif($this->recur_type == 'Weekly') 108 { 109 $st_date = explode("-",$tempdate); 110 $date_arr = Array( 111 'day' => $st_date[2], 112 'month' => $st_date[1], 113 'year' => $st_date[0] 114 ); 115 $tempdateObj = new DateTime($date_arr,true); 116 if(isset($this->dayofweek_to_rpt) && $this->dayofweek_to_rpt != null) 117 { 118 $weekstartObj = $tempdateObj->getThisweekDaysbyIndex(0); 119 if($weekstartObj->get_formatted_date() >= $this->startdate->get_formatted_date()) 120 { 121 for($i=0;$i<count($this->dayofweek_to_rpt);$i++) 122 { 123 $repeatdateObj = $weekstartObj->getThisweekDaysbyIndex($this->dayofweek_to_rpt[$i]); 124 if($repeatdateObj->get_formatted_date() <= $enddate) 125 $recurringDates[] = $repeatdateObj->get_formatted_date(); 126 } 127 if(isset($this->recur_freq)) 128 $index = $this->recur_freq * 7; 129 else 130 $index = 7; 131 $date_arr = Array( 132 'day' => $st_date[2] + $index, 133 'month' => $st_date[1], 134 'year' => $st_date[0] 135 ); 136 $tempdateObj = new DateTime($date_arr,true); 137 } 138 else 139 { 140 if(isset($this->recur_freq)) 141 $index = $this->recur_freq * 7; 142 else 143 $index = 7; 144 $date_arr = Array( 145 'day' => $st_date[2] + $index, 146 'month' => $st_date[1], 147 'year' => $st_date[0] 148 ); 149 $tempdateObj = new DateTime($date_arr,true); 150 151 } 152 } 153 else 154 { 155 $recurringDates[] = $tempdateObj->get_formatted_date(); 156 if(isset($this->recur_freq)) 157 $index = $this->recur_freq * 7; 158 else 159 $index = 7; 160 $date_arr = Array( 161 'day' => $st_date[2] + $index, 162 'month' => $st_date[1], 163 'year' => $st_date[0] 164 ); 165 $tempdateObj = new DateTime($date_arr,true); 166 } 167 $tempdate = $tempdateObj->get_formatted_date(); 168 } 169 elseif($this->recur_type == 'Monthly') 170 { 171 $st_date = explode("-",$tempdate); 172 $date_arr = Array( 173 'day' => $st_date[2], 174 'month' => $st_date[1], 175 'year' => $st_date[0] 176 ); 177 $startdateObj = new DateTime($date_arr,true); 178 if($this->repeat_monthby == 'date') 179 { 180 if($this->rptmonth_datevalue <= $st_date[2]) 181 { 182 $index = $this->rptmonth_datevalue - 1; 183 $day = $this->rptmonth_datevalue; 184 if(isset($this->recur_freq)) 185 $month = $st_date[1] + $this->recur_freq; 186 else 187 $month = $st_date[1] + 1; 188 $year = $st_date[0]; 189 $tempdateObj = $startdateObj->getThismonthDaysbyIndex($index,$day,$month,$year); 190 } 191 else 192 { 193 $index = $this->rptmonth_datevalue - 1; 194 $day = $this->rptmonth_datevalue; 195 $month = $st_date[1]; 196 $year = $st_date[0]; 197 $tempdateObj = $startdateObj->getThismonthDaysbyIndex($index,$day,$month,$year); 198 } 199 } 200 elseif($this->repeat_monthby == 'day') 201 { 202 if($this->rptmonth_daytype == 'first') 203 { 204 $date_arr = Array( 205 'day' => 1, 206 'month' => $st_date[1], 207 'year' => $st_date[0] 208 ); 209 $tempdateObj = new DateTime($date_arr,true); 210 $firstdayofmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0],$tempdateObj); 211 if($firstdayofmonthObj->get_formatted_date() <= $tempdate) 212 { 213 if(isset($this->recur_freq)) 214 $month = $firstdayofmonthObj->month + $this->recur_freq; 215 else 216 $month = $firstdayofmonthObj->month + 1; 217 $dateObj = $firstdayofmonthObj->getThismonthDaysbyIndex(0,1,$month,$firstdayofmonthObj->year); 218 $nextmonthObj = $this->getFistdayofmonth($this->dayofweek_to_rpt[0],$dateObj); 219 $tempdateObj = $nextmonthObj; 220 } 221 else 222 { 223 $tempdateObj = $firstdayofmonthObj; 224 } 225 226 } 227 elseif($this->rptmonth_daytype == 'last') 228 { 229 $date_arr = Array( 230 'day' => $startdateObj->daysinmonth, 231 'month' => $startdateObj->month, 232 'year' => $startdateObj->year 233 ); 234 $tempdateObj = new DateTime($date_arr,true); 235 $lastdayofmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0],$tempdateObj); 236 if($lastdayofmonthObj->get_formatted_date() <= $tempdate) 237 { 238 if(isset($this->recur_freq)) 239 $month = $lastdayofmonthObj->month + $this->recur_freq; 240 else 241 $month = $lastdayofmonthObj->month + 1; 242 $dateObj = $lastdayofmonthObj->getThismonthDaysbyIndex(0,1,$month,$lastdayofmonthObj->year); 243 $dateObj = $dateObj->getThismonthDaysbyIndex($dateObj->daysinmonth-1,$dateObj->daysinmonth,$month,$lastdayofmonthObj->year); 244 $nextmonthObj = $this->getLastdayofmonth($this->dayofweek_to_rpt[0],$dateObj); 245 $tempdateObj = $nextmonthObj; 246 } 247 else 248 { 249 $tempdateObj = $lastdayofmonthObj; 250 } 251 } 252 } 253 else 254 { 255 $date_arr = Array( 256 'day' => $st_date[2], 257 'month' => $st_date[1]+1, 258 'year' => $st_date[0] 259 ); 260 $tempdateObj = new DateTime($date_arr,true); 261 } 262 $tempdate = $tempdateObj->get_formatted_date(); 263 $recurringDates[] = $tempdate; 264 } 265 elseif($this->recur_type == 'Yearly') 266 { 267 $recurringDates[] = $tempdate; 268 $st_date = explode("-",$tempdate); 269 if(isset($this->recur_freq)) 270 $index = $st_date[0] + $this->recur_freq; 271 else 272 $index = $st_date[0] + 1; 273 if ($index > 2037 || $index < 1970) 274 { 275 print("<font color='red'>Sorry, Year must be between 1970 and 2037</font>"); 276 exit; 277 } 278 $date_arr = Array( 279 'day' => $st_date[2], 280 'month' => $st_date[1], 281 'year' => $index 282 ); 283 $tempdateObj = new DateTime($date_arr,true); 284 $tempdate = $tempdateObj->get_formatted_date(); 285 } 286 else 287 { 288 die("Recurring Type ".$this->recur_type." is not defined"); 289 } 290 } 291 return $recurringDates; 292 } 293 294 /** Function to get first day of the month(like first Monday or Friday and etc.) 295 * @param $dayofweek -- day of the week to repeat the event :: Type string 296 * @param $dateObj -- date object :: Type DateTime Object 297 * return $dateObj -- the date object on which the event repeats :: Type DateTime Object 298 */ 299 function getFistdayofmonth($dayofweek,& $dateObj) 300 { 301 if($dayofweek < $dateObj->dayofweek) 302 { 303 $index = (7 - $dateObj->dayofweek) + $dayofweek; 304 $day = 1 + $index; 305 $month = $dateObj->month; 306 $year = $dateObj->year; 307 $dateObj = $dateObj->getThismonthDaysbyIndex($index,$day,$month,$year); 308 } 309 else 310 { 311 $index = $dayofweek - $dateObj->dayofweek; 312 $day = 1 + $index; 313 $month = $dateObj->month; 314 $year = $dateObj->year; 315 $dateObj = $dateObj->getThismonthDaysbyIndex($index,$day,$month,$year); 316 } 317 return $dateObj; 318 } 319 320 /** Function to get last day of the month(like last Monday or Friday and etc.) 321 * @param $dayofweek -- day of the week to repeat the event :: Type string 322 * @param $dateObj -- date object :: Type DateTime Object 323 * return $dateObj -- the date object on which the event repeats :: Type DateTime Object 324 */ 325 326 function getLastdayofmonth($dayofweek,& $dateObj) 327 { 328 if($dayofweek == $dateObj->dayofweek) 329 { 330 return $dateObj; 331 } 332 else 333 { 334 if($dayofweek > $dateObj->dayofweek) 335 $day = $dateObj->day - 7 + ($dayofweek - $dateObj->dayofweek); 336 else 337 $day = $dateObj->day - ($dateObj->dayofweek - $dayofweek); 338 $index = $day - 1; 339 $month = $dateObj->month; 340 $year = $dateObj->year; 341 $dateObj = $dateObj->getThismonthDaysbyIndex($index,$day,$month,$year); 342 return $dateObj; 343 } 344 345 } 346 347 } 348 349 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |