[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 4 5 /** 6 * \ingroup Data 7 * 8 * Generates an html calendar 9 * 10 * PHP Calendar Class Version 1.4 (5th March 2001) 11 * 12 * Copyright David Wilkinson 2000 - 2001. All Rights reserved. 13 * 14 * This software may be used, modified and distributed freely 15 * providing this copyright notice remains intact at the head 16 * of the file. 17 * 18 * This software is freeware. The author accepts no liability for 19 * any loss or damages whatsoever incurred directly or indirectly 20 * from the use of this script. The author of this software makes 21 * no claims as to its fitness for any purpose whatsoever. If you 22 * wish to use this software you should first satisfy yourself that 23 * it meets your requirements. 24 * 25 * URL: http://www.cascade.org.uk/software/php/calendar/ 26 * Email: davidw@cascade.org.uk 27 * 28 * Modified by fuze (http://www.fuze.org) on 2004/07/11 29 * 30 * Just changed the html table output for better (CSS) accessibility 31 * and variable names. 32 */ 33 34 class Calendar 35 { 36 /* 37 Constructor for the Calendar class 38 */ 39 function Calendar() 40 { 41 42 } 43 44 45 /** 46 * Get the array of strings used to label the days of the week. This array contains seven 47 * elements, one for each day of the week. The first entry in this array represents Sunday. 48 */ 49 function getDayNames() 50 { 51 return $this->dayNames; 52 } 53 54 55 /** 56 * Set the array of strings used to label the days of the week. This array must contain seven 57 * elements, one for each day of the week. The first entry in this array represents Sunday. 58 */ 59 function setDayNames($names) 60 { 61 $this->dayNames = $names; 62 } 63 64 /** 65 * Get the array of strings used to label the months of the year. This array contains twelve 66 * elements, one for each month of the year. The first entry in this array represents January. 67 */ 68 function getMonthNames() 69 { 70 return $this->monthNames; 71 } 72 73 /** 74 * Set the array of strings used to label the months of the year. This array must contain twelve 75 * elements, one for each month of the year. The first entry in this array represents January. 76 */ 77 function setMonthNames($names) 78 { 79 $this->monthNames = $names; 80 } 81 82 /** 83 * Gets the start day of the week. This is the day that appears in the first column 84 * of the calendar. Sunday = 0. 85 */ 86 function getStartDay() 87 { 88 return $this->startDay; 89 } 90 91 /** 92 * Sets the start day of the week. This is the day that appears in the first column 93 * of the calendar. Sunday = 0. 94 */ 95 function setStartDay($day) 96 { 97 $this->startDay = $day; 98 } 99 100 101 /** 102 * Gets the start month of the year. This is the month that appears first in the year 103 * view. January = 1. 104 */ 105 function getStartMonth() 106 { 107 return $this->startMonth; 108 } 109 110 /** 111 * Sets the start month of the year. This is the month that appears first in the year 112 * view. January = 1. 113 */ 114 function setStartMonth($month) 115 { 116 $this->startMonth = $month; 117 } 118 119 120 /** 121 * Return the URL to link to in order to display a calendar for a given month/year. 122 * You must override this method if you want to activate the "forward" and "back" 123 * feature of the calendar. 124 * 125 * Note: If you return an empty string from this function, no navigation link will 126 * be displayed. This is the default behaviour. 127 * 128 * If the calendar is being displayed in "year" view, $month will be set to zero. 129 */ 130 function getCalendarLink($month, $year) 131 { 132 return ""; 133 } 134 135 /** 136 * Return the URL to link to for a given date. 137 * You must override this method if you want to activate the date linking 138 * feature of the calendar. 139 * 140 * Note: If you return an empty string from this function, no navigation link will 141 * be displayed. This is the default behaviour. 142 */ 143 function getDateLink($day, $month, $year) 144 { 145 return ""; 146 } 147 148 149 /** 150 * Return the HTML for the current month 151 */ 152 function getCurrentMonthView() 153 { 154 $d = getdate(time()); 155 return $this->getMonthView($d["mon"], $d["year"]); 156 } 157 158 159 /** 160 * Return the HTML for the current year 161 */ 162 function getCurrentYearView() 163 { 164 $d = getdate(time()); 165 return $this->getYearView($d["year"]); 166 } 167 168 169 /** 170 * Return the HTML for a specified month 171 */ 172 function getMonthView($month, $year) 173 { 174 return $this->getMonthHTML($month, $year); 175 } 176 177 178 /** 179 * Return the HTML for a specified year 180 */ 181 function getYearView($year) 182 { 183 return $this->getYearHTML($year); 184 } 185 186 187 188 /******************************************************************************** 189 190 The rest are private methods. No user-servicable parts inside. 191 192 You shouldn't need to call any of these functions directly. 193 194 *********************************************************************************/ 195 196 197 /** 198 * Calculate the number of days in a month, taking into account leap years. 199 */ 200 function getDaysInMonth($month, $year) 201 { 202 if ($month < 1 || $month > 12) 203 { 204 return 0; 205 } 206 207 $d = $this->daysInMonth[$month - 1]; 208 209 if ($month == 2) 210 { 211 // Check for leap year 212 // Forget the 4000 rule, I doubt I'll be around then... 213 214 if ($year%4 == 0) 215 { 216 if ($year%100 == 0) 217 { 218 if ($year%400 == 0) 219 { 220 $d = 29; 221 } 222 } 223 else 224 { 225 $d = 29; 226 } 227 } 228 } 229 230 return $d; 231 } 232 233 234 /** 235 * Generate the HTML for a given month 236 */ 237 function getMonthHTML($m, $y, $showYear = 1, $timestamp = 0) 238 { 239 $s = ""; 240 241 $a = $this->adjustDate($m, $y); 242 $month = $a[0]; 243 $year = $a[1]; 244 245 $daysInMonth = $this->getDaysInMonth($month, $year); 246 $date = getdate(mktime(12, 0, 0, $month, 1, $year)); 247 248 $first = $date["wday"]; 249 $monthName = $this->monthNames[$month - 1]; 250 251 $prev = $this->adjustDate($month - 1, $year); 252 $next = $this->adjustDate($month + 1, $year); 253 254 if ($showYear == 1) 255 { 256 $prevMonth = $this->getCalendarLink($prev[0], $prev[1]); 257 $nextMonth = $this->getCalendarLink($next[0], $next[1]); 258 $nextMonthName = $this->monthNames[ $next[0] - 1 ].(($showYear > 0) ? " " . $next[1] : ""); 259 $prevMonthName = $this->monthNames[ $prev[0] - 1 ].(($showYear > 0) ? " " . $prev[1] : ""); 260 } 261 else 262 { 263 $prevMonth = ""; 264 $nextMonth = ""; 265 } 266 267 $header = $monthName . (($showYear > 0) ? " " . $year : ""); 268 //$s .= '<h2>'.$header.'</h2>'; // remove this line #1 269 $s .= "<table class=\"calMonth\" summary=\"\">\n"; 270 271 ///* // remove this line #2 272 $s .= "<thead>\n"; 273 $s .= "<tr class=\"calMonthNav\">\n"; 274 $s .= "\t<th class=\"calMonthBackward\">" . (($prevMonth == "") ? " " : "<a href=\"$prevMonth\" title=\"$prevMonthName\">«</a>") . "</th>\n"; 275 $s .= "\t<th class=\"calMonthCurrent\" colspan=\"5\">$header</th>\n"; 276 $s .= "\t<th class=\"calMonthForward\">" . (($nextMonth == "") ? " " : "<a href=\"$nextMonth\" title=\"$nextMonthName\">»</a>") . "</th>\n"; 277 $s .= "</tr>\n"; 278 // */ // remove this line #3 to go to t 279 280 $s .= "<tr class=\"calMonthHeader\">\n"; 281 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay)%7] . "\">" . $this->dayNamesShort[($this->startDay)%7] . "</th>\n"; 282 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+1)%7] . "\">" . $this->dayNamesShort[($this->startDay+1)%7] . "</th>\n"; 283 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+2)%7] . "\">" . $this->dayNamesShort[($this->startDay+2)%7] . "</th>\n"; 284 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+3)%7] . "\">" . $this->dayNamesShort[($this->startDay+3)%7] . "</th>\n"; 285 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+4)%7] . "\">" . $this->dayNamesShort[($this->startDay+4)%7] . "</th>\n"; 286 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+5)%7] . "\">" . $this->dayNamesShort[($this->startDay+5)%7] . "</th>\n"; 287 $s .= "\t<th scope=\"col\" abbr=\"" . $this->dayNames[($this->startDay+6)%7] . "\">" . $this->dayNamesShort[($this->startDay+6)%7] . "</th>\n"; 288 $s .= "</tr>\n"; 289 $s .= "</thead>\n"; 290 $s .= "<tbody>\n"; 291 292 // We need to work out what date to start at so that the first appears in the correct column 293 $d = $this->startDay + 1 - $first; 294 while ($d > 1) 295 { 296 $d -= 7; 297 } 298 299 // Make sure we know when today is, so that we can use a different CSS style 300 if ( $timestamp == 0 ) 301 { 302 $today = getdate(time()); 303 } 304 else 305 { 306 $today = getdate($timestamp); 307 } 308 309 while ($d <= $daysInMonth) 310 { 311 $s .= "<tr>\n"; 312 313 for ($i = 0; $i < 7; $i++) 314 { 315 $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? " class=\"calMonthToday\"" : " class=\"calMonthDay\""; 316 $s .= "\t<td$class>"; 317 if ($d > 0 && $d <= $daysInMonth) 318 { 319 $link = $this->getDateLink($d, $month, $year); 320 $s .= (($link == "") ? $d : "<a href=\"$link\">$d</a>"); 321 } 322 else 323 { 324 $s .= " "; 325 } 326 $s .= "</td>\n"; 327 $d++; 328 } 329 $s .= "</tr>\n"; 330 } 331 $s .= "</tbody>\n"; 332 $s .= "</table>\n"; 333 334 return $s; 335 } 336 337 338 /** 339 * Generate the HTML for a given year 340 */ 341 function getYearHTML($year) 342 { 343 $s = ""; 344 $prev = $this->getCalendarLink(0, $year - 1); 345 $next = $this->getCalendarLink(0, $year + 1); 346 347 $s .= "<table class=\"calYear\" summary=\"\">\n"; 348 $s .= "<thead>\n"; 349 $s .= "<tr>"; 350 $s .= "\t<th class=\"calYearBackward\">" . (($prev == "") ? " " : "<a href=\"$prev\">«</a>") . "</th>\n"; 351 $s .= "\t<th class=\"calYearCurrent\">" . (($this->startMonth > 1) ? $year . " - " . ($year + 1) : $year) ."</th>\n"; 352 $s .= "\t<th class=\"calYearForward\">" . (($next == "") ? " " : "<a href=\"$next\">»</a>") . "</th>\n"; 353 $s .= "</tr>\n"; 354 $s .= "</thead>\n"; 355 $s .= "<tbody>\n"; 356 $s .= "<tr>"; 357 $s .= "\t<td>" . $this->getMonthHTML(0 + $this->startMonth, $year, 0) ."</td>\n"; 358 $s .= "\t<td>" . $this->getMonthHTML(1 + $this->startMonth, $year, 0) ."</td>\n"; 359 $s .= "\t<td>" . $this->getMonthHTML(2 + $this->startMonth, $year, 0) ."</td>\n"; 360 $s .= "</tr>\n"; 361 $s .= "<tr>\n"; 362 $s .= "\t<td>" . $this->getMonthHTML(3 + $this->startMonth, $year, 0) ."</td>\n"; 363 $s .= "\t<td>" . $this->getMonthHTML(4 + $this->startMonth, $year, 0) ."</td>\n"; 364 $s .= "\t<td>" . $this->getMonthHTML(5 + $this->startMonth, $year, 0) ."</td>\n"; 365 $s .= "</tr>\n"; 366 $s .= "<tr>\n"; 367 $s .= "\t<td>" . $this->getMonthHTML(6 + $this->startMonth, $year, 0) ."</td>\n"; 368 $s .= "\t<td>" . $this->getMonthHTML(7 + $this->startMonth, $year, 0) ."</td>\n"; 369 $s .= "\t<td>" . $this->getMonthHTML(8 + $this->startMonth, $year, 0) ."</td>\n"; 370 $s .= "</tr>\n"; 371 $s .= "<tr>\n"; 372 $s .= "\t<td>" . $this->getMonthHTML(9 + $this->startMonth, $year, 0) ."</td>\n"; 373 $s .= "\t<td>" . $this->getMonthHTML(10 + $this->startMonth, $year, 0) ."</td>\n"; 374 $s .= "\t<td>" . $this->getMonthHTML(11 + $this->startMonth, $year, 0) ."</td>\n"; 375 $s .= "</tr>\n"; 376 $s .= "</tbody>\n"; 377 $s .= "</table>\n"; 378 379 return $s; 380 } 381 382 /** 383 * Adjust dates to allow months > 12 and < 0. Just adjust the years appropriately. 384 * e.g. Month 14 of the year 2001 is actually month 2 of year 2002. 385 */ 386 function adjustDate($month, $year) 387 { 388 $a = array(); 389 $a[0] = $month; 390 $a[1] = $year; 391 392 while ($a[0] > 12) 393 { 394 $a[0] -= 12; 395 $a[1]++; 396 } 397 398 while ($a[0] <= 0) 399 { 400 $a[0] += 12; 401 $a[1]--; 402 } 403 404 return $a; 405 } 406 407 /** 408 * The start day of the week. This is the day that appears in the first column 409 * of the calendar. Sunday = 0. 410 */ 411 var $startDay = 1; 412 413 /** 414 * The start month of the year. This is the month that appears in the first slot 415 * of the calendar in the year view. January = 1. 416 */ 417 var $startMonth = 1; 418 419 /** 420 * The labels to display for the days of the week. The first entry in this array 421 * represents Sunday. 422 */ 423 var $dayNames = array("S", "M", "T", "W", "T", "F", "S"); 424 425 /** 426 * The labels to display for the months of the year. The first entry in this array 427 * represents January. 428 */ 429 var $monthNames = array("January", "February", "March", "April", "May", "June", 430 "July", "August", "September", "October", "November", "December"); 431 432 433 /** 434 * The number of days in each month. You're unlikely to want to change this... 435 * The first entry in this array represents January. 436 */ 437 var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 438 439 } 440 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |