[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.3 | 6 // +---------------------------------------------------------------------------+ 7 // | calendar.class.php | 8 // | | 9 // | Geeklog calendar library. | 10 // +---------------------------------------------------------------------------+ 11 // | Much of this code is from Jim Wright jdlwright@yahoo.com with minor | 12 // | customizations. | 13 // | | 14 // | Copyright (C) 2000-2004 by the following authors: | 15 // | | 16 // | Authors: Tony Bibbs - tony@tonybibbs.com | 17 // +---------------------------------------------------------------------------+ 18 // | | 19 // | This program is free software; you can redistribute it and/or | 20 // | modify it under the terms of the GNU General Public License | 21 // | as published by the Free Software Foundation; either version 2 | 22 // | of the License, or (at your option) any later version. | 23 // | | 24 // | This program is distributed in the hope that it will be useful, | 25 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 26 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 27 // | GNU General Public License for more details. | 28 // | | 29 // | You should have received a copy of the GNU General Public License | 30 // | along with this program; if not, write to the Free Software Foundation, | 31 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 32 // | | 33 // +---------------------------------------------------------------------------+ 34 // 35 // $Id: calendar.class.php,v 1.8 2006/05/14 17:58:52 ospiess Exp $ 36 37 /** 38 * This file contains the two classes used to help support the calendar pages. 39 * Please note that our calendar code is in shambles and is hard to understand. 40 * Not so much this file as /calendar/index.php and calendar/event.php. 41 * Those files along with this class need to be reworked to be easier 42 * to maintain and support rich calendaring features 43 * 44 * @author Tony Bibbs <tony@tonybibbs.com> 45 */ 46 47 /** 48 * This class represents the logical structure of a calendar day and is used by 49 * the greater calendar class 50 * 51 */ 52 class CalendarDay { 53 var $daynumber = 0; 54 var $year = 0; 55 56 var $weekendflag = false; 57 var $holidayflag = false; 58 var $selectedflag = false; 59 60 /** 61 * Constructur 62 * 63 */ 64 function CalendarDay() 65 { 66 $this->weekendflag = false; 67 $this->holidayflag = false; 68 $this->selectedflag = false; 69 } 70 71 /** 72 * Returns if this day is on a weekend 73 * 74 * @return boolean true if is on weekend otherwise false 75 * 76 */ 77 function isWeekend() 78 { 79 return $this->weekendflag; 80 } 81 82 /** 83 * Returns if this day is a holiday 84 * 85 * @return boolean true if day is a holiday otherwise false 86 * 87 */ 88 function isHoliday() 89 { 90 return $this->holdiayflag; 91 } 92 93 /** 94 * Returns if this day is selected 95 * 96 * @return boolean true if day is selected otherwise false 97 * 98 */ 99 function isSelected() 100 { 101 return $this->selectedflag; 102 } 103 104 } 105 106 class Calendar { 107 108 // PRIVATE PROPERTIES 109 110 /** 111 * @access private 112 */ 113 var $_rollingmode; 114 /** 115 * @access private 116 */ 117 var $_lang_days; 118 /** 119 * @access private 120 */ 121 var $_lang_months; 122 /** 123 * @access private 124 */ 125 var $_week_start; 126 /** 127 * @access private 128 */ 129 var $_default_year; 130 /** 131 * @access private 132 */ 133 var $_selected_days; 134 /** 135 * @access private 136 */ 137 var $_holidays; 138 /** 139 * @access private 140 */ 141 var $_matrix; 142 143 // PRIVATE METHODS 144 145 /** 146 * Returns if calendar is in rolling mode 147 * 148 * @return boolean returns true if in rolling mode otherwise false 149 * @access private 150 * 151 */ 152 function _isRollingMode() 153 { 154 return $this->_rollingmode; 155 } 156 157 /** 158 * Constructor 159 * 160 * Initializes calendar object 161 * 162 */ 163 function Calendar() 164 { 165 $this->setRollingMode(false); 166 $dateArray = getdate(time()); 167 $this->_default_year = $dateArray['year']; 168 $this->setLanguage(); 169 } 170 171 /** 172 * Returns the day of the week (1-7) for given date 173 * 174 * @param int $day Number of day in month (1-31) 175 * @param int $month Number of the month (1-12) 176 * @param int $year Four digit year 177 * @return int Returns integer for day of week 1 = Sunday through 7 = Saturday 178 * 179 */ 180 function getDayOfWeek($day = 1, $month = 1, $year = '') 181 { 182 if (empty($year)) { 183 $year = $this->_default_year; 184 } 185 186 $dateArray = getdate(mktime(0,0,0,$month,$day,$year)); 187 $result = $dateArray['wday']; 188 if ($this->_week_start == 'Mon') { 189 $result = ($result == 0) ? 6 : $result - 1; 190 } 191 return $result; 192 } 193 194 /** 195 * Returns the week of the month (1-5) for a given date 196 * 197 * @param int $day Number of day in month (1-31) 198 * @param int $month Number of the month (1-12) 199 * @param int $year Four digit year 200 * @return int Week of the month, 1 - 5 201 * 202 */ 203 function getWeekOfMonth($day = 1, $month = 1, $year = '') 204 { 205 if (empty($year)) { 206 $year = $this->_default_year; 207 } 208 209 $firstDayOfMonth = 1 + $this->getDayOfWeek(1,$month,$year); 210 211 //we know first day of month is in the first week 212 $dDiff = $day - $firstDayOfMonth; 213 $wDiff = round($dDiff/7); 214 return $wDiff + 1; 215 } 216 217 /** 218 * Determines if given year is a leap year or not 219 * 220 * @param int $year Four digit year 221 * @return boolean returns true if year is a leap year otherwise false 222 * 223 */ 224 function isLeapYear($year = '') 225 { 226 if (empty($year)) { 227 $year = $this->_default_year; 228 } 229 230 if (round(($year - 2000)/4) == (($year - 2000)/4)){ 231 return 1; 232 } else { 233 return 0; 234 } 235 } 236 237 /** 238 * Returns the number of days in a given month/year 239 * 240 * If no year is given, the default year is used 241 * 242 * @param int $month Month (1-12) 243 * @param int $year Four digit year 244 * @return int Returns the number of days in the month 245 * 246 */ 247 function getDaysInMonth($month = 1, $year = '') 248 { 249 if (empty($year)) { 250 $year = $this->_default_year; 251 } 252 switch ($month - 1) { 253 case 0: 254 return 31; 255 break; 256 case 1: 257 if ($this->isLeapYear($year)) { 258 return 29; 259 } else { 260 return 28; 261 } 262 break; 263 case 2: 264 return 31; 265 break; 266 case 3: 267 return 30; 268 break; 269 case 4: 270 return 31; 271 break; 272 case 5: 273 return 30; 274 break; 275 case 6: 276 return 31; 277 break; 278 case 7: 279 return 31; 280 break; 281 case 8: 282 return 30; 283 break; 284 case 9: 285 return 31; 286 break; 287 case 10: 288 return 30; 289 break; 290 case 11: 291 return 31; 292 break; 293 default: 294 return 0; 295 break; 296 297 } 298 } 299 300 /** 301 * Returns the name of the day of the week 302 * 303 * This aims to help with multilingual support 304 * 305 * @param int $day Numeric day of week (1-7) 306 * @return string Returns the text for the given day of the week 307 * 308 */ 309 function getDayName($day = 1) { 310 if ($this->_week_start == 'Mon') { 311 if ($day == 7) { 312 return $this->_lang_days['sunday']; 313 } else { 314 $day += 1; 315 } 316 } 317 switch ($day - 1) { 318 case 0: 319 return $this->_lang_days['sunday']; 320 break; 321 case 1: 322 return $this->_lang_days['monday']; 323 break; 324 case 2: 325 return $this->_lang_days['tuesday']; 326 break; 327 case 3: 328 return $this->_lang_days['wednesday']; 329 break; 330 case 4: 331 return $this->_lang_days['thursday']; 332 break; 333 case 5: 334 return $this->_lang_days['friday']; 335 break; 336 case 6: 337 return $this->_lang_days['saturday']; 338 break; 339 default: 340 return 0; 341 break; 342 } 343 } 344 345 /** 346 * Returns the name of the given month (can handle different languages) 347 * 348 * This aims to help with multi-lingual support 349 * 350 * @param int $month Month (1-12) to get name of 351 * @return string returns text for current month name 352 * 353 */ 354 function getMonthName($month = 1) 355 { 356 $month = $month - 1; 357 if (empty($this->_lang_months)) $this->setLanguage(); 358 359 switch ($month) { 360 case 0: 361 return $this->_lang_months['january']; 362 break; 363 case 1: 364 return $this->_lang_months['february']; 365 break; 366 case 2: 367 return $this->_lang_months['march']; 368 break; 369 case 3: 370 return $this->_lang_months['april']; 371 break; 372 case 4: 373 return $this->_lang_months['may']; 374 break; 375 case 5: 376 return $this->_lang_months['june']; 377 break; 378 case 6: 379 return $this->_lang_months['july']; 380 break; 381 case 7: 382 return $this->_lang_months['august']; 383 break; 384 case 8: 385 return $this->_lang_months['september']; 386 break; 387 case 9: 388 return $this->_lang_months['october']; 389 break; 390 case 10: 391 return $this->_lang_months['november']; 392 break; 393 case 11: 394 return $this->_lang_months['december']; 395 break; 396 default: 397 return 0; 398 break; 399 } 400 } 401 402 /** 403 * Sets the rolling mode status 404 * 405 * Will put calendar in normal mode or in rolling mode. Rolling 406 * mode 407 * 408 * @param boolean $flag True of False 409 * 410 */ 411 function setRollingMode($flag) 412 { 413 $this->_rollingmode = $flag; 414 } 415 416 /** 417 * Sets the language for days of the week and months of year 418 * 419 * This function defaults to English. 420 * Day array format is _lang_days['<daynameinenglish>'] = '<translation>' 421 * Mondy array format is _lang_months['<monthnameinenglish'] = '<translation>' 422 * 423 * @param array $lang_days Array of strings holding day language 424 * @param array $lang_months Array of string holding month language 425 * 426 */ 427 function setLanguage($lang_days='', $lang_months='', $week_start='Sun') 428 { 429 if (empty($lang_days)) { 430 $this->_lang_days['sunday'] = 'Sunday'; 431 $this->_lang_days['monday'] = 'Monday'; 432 $this->_lang_days['tuesday'] = 'Tuesday'; 433 $this->_lang_days['wednesday'] = 'Wednesday'; 434 $this->_lang_days['thursday'] = 'Thursday'; 435 $this->_lang_days['friday'] = 'Friday'; 436 $this->_lang_days['saturday'] = 'Saturday'; 437 } else { 438 $this->_lang_days = $lang_days; 439 } 440 441 if (empty($lang_months)) { 442 $this->_lang_months['january'] = 'January'; 443 $this->_lang_months['february'] = 'February'; 444 $this->_lang_months['march'] = 'March'; 445 $this->_lang_months['april'] = 'April'; 446 $this->_lang_months['may'] = 'May'; 447 $this->_lang_months['june'] = 'June'; 448 $this->_lang_months['july'] = 'July'; 449 $this->_lang_months['august'] = 'August'; 450 $this->_lang_months['september'] = 'September'; 451 $this->_lang_months['october'] = 'October'; 452 $this->_lang_months['november'] = 'November'; 453 $this->_lang_months['december'] = 'December'; 454 } else { 455 $this->_lang_months = $lang_months; 456 } 457 if ($week_start != 'Mon') { 458 $this->_week_start = 'Sun'; 459 } else { 460 $this->_week_start = $week_start; 461 } 462 } 463 464 /** 465 * Builds logical model of the month in memory 466 * 467 * @param int $month Month to build matrix for 468 * @param int $year Year to build matrix for 469 * @param string $selecteddays Comma seperated list of days to select 470 * 471 */ 472 function setCalendarMatrix($month, $year, $selecteddays='') 473 { 474 $firstday = 1 + $this->getDayOfWeek(1,$month,$year); 475 $nextday = 1; 476 $lastday = $this->getDaysInMonth(); 477 478 $monthname = $this->getMonthName($month); 479 480 // There are as many as 6 weeks in a calendar grid (I call these 481 // absolute weeks hence the variable name aw. Loop through and 482 // populate data 483 for ($aw = 1; $aw <= 6; $aw++) { 484 for ($wd = 1; $wd <= 7; $wd++) { 485 if ($aw == 1 && $wd < $firstday) { 486 $week[$aw][$wd] = ''; 487 } else { 488 $cur_day = new CalendarDay(); 489 $cur_day->year = $year; 490 $cur_day->daynumber = $nextday; 491 $week[$aw][$wd] = $cur_day; 492 493 // Bail if we just printed last day 494 if ($nextday < $this->getDaysInMonth($month,$year)) { 495 $nextday++; 496 } else { 497 $aw++; 498 while ($aw <= 6) { 499 $week[$aw] = ''; 500 $aw++; 501 } 502 $aw = 7; 503 } 504 } 505 } 506 } 507 508 $this->_matrix = $week; 509 510 } 511 512 /** 513 * Gets data for a given day 514 * 515 * @param int $week week of day to get data for 516 * @param int $daynum Number of day to get data for 517 * @return object Returns calendarDay object 518 * 519 */ 520 function getDayData($week,$daynum) { 521 if (isset ($this->_matrix[$week][$daynum])) { 522 return $this->_matrix[$week][$daynum]; 523 } 524 525 return ''; 526 } 527 528 } 529 530 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |