| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:19:23 2008 ] | [ PBS Helpdesk 0.93 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************** 3 * calendar.inc 4 * (c) Thomas Sutton, 2003 5 * This software is released under the GNU General Public License, Version 2 6 * ONLY. 7 * 8 * To use this script, edit the settings variables below and include() it 9 * within the <head> section of an HTML PHP document. Then call 10 * drawCalendar($URL, $DATE) where the calendar should appear in your 11 * document. 12 * 13 * Example: 14 * drawCalendar("cal.php?", "") will result in the calendar for this month 15 * with links like cal.php?2003-11-24 for days with events and cal.php?2003-11 16 * for next and previous months. 17 **************************************************************************/ 18 19 if (! isset($CALENDAR)) { 20 21 /* Settings.... */ 22 23 /* Do not modify below here.... */ 24 $CALENDAR = "DONE"; 25 26 echo "\t<style type='text/css'>\n"; 27 fpassthru(fopen("calendar.css", "r")); 28 echo "\t</style>\n"; 29 30 /* 31 * Returns the number of days in the specified month. 32 */ 33 function daysInMonth($year, $month) { 34 switch ($month) { 35 case 1: case 3: case 5: case 7: case 8: case 10: case 12: 36 $days = 31; 37 break; 38 case 2: 39 $days = ((($year % 4) == 0) ? 29 : 28); 40 break; 41 case 4: case 6: case 9: case 11: 42 $days = 30; 43 break; 44 default: 45 $days = 0; 46 break; 47 } 48 return $days; 49 } 50 51 /* 52 * Returns the month previous to the supplied month 53 */ 54 function lastMonth($year, $month) { 55 $TEMP = getdate(mktime(0, 0, 0, $month, 1, $year)); 56 $MONTH = $TEMP["mon"]; 57 $YEAR = $TEMP["year"]; 58 $DAY = $TEMP["mday"]; 59 $TEMP = getdate(mktime(0, 0, 0, $month - 1, 1, $year)); 60 $RETVAL = array($TEMP["year"], $TEMP["mon"]); 61 return $RETVAL; 62 } 63 64 /* 65 * Returns the month after the supplied month 66 */ 67 function nextMonth($year, $month) { 68 $TEMP = getdate(mktime(0, 0, 0, $month, 1, $year)); 69 $MONTH = $TEMP["mon"]; 70 $YEAR = $TEMP["year"]; 71 $DAY = $TEMP["mday"]; 72 $TEMP = getdate(mktime(0, 0, 0, $month + 1, 1, $year)); 73 $RETVAL = array($TEMP["year"], $TEMP["mon"]); 74 return $RETVAL; 75 } 76 77 /* 78 * Return the weekday the first of the specified month falls on. 79 * 0 = Mon ... 6 = Sun 80 */ 81 function dayOfFirst($year, $month) { 82 $TEMP = getdate(mktime(0, 0, 0, $month, 1, $year)); 83 if ($TEMP["wday"] == 0) $DAY = 6; else $DAY = $TEMP["wday"] - 1; 84 return $DAY; 85 } 86 87 function drawDay($YEAR, $MONTH, $DAY, $NOW, $base, $mysql_id,$caltype) { 88 global $TABLE; 89 echo "\t\t\t<td"; 90 if (($DAY == $NOW['mday']) && ($MONTH == $NOW['mon']) && ($YEAR == $NOW['year'])) 91 echo " class='today'"; 92 echo ">"; 93 94 // ...link to them 95 // echo "<a href='$base$YEAR-$MONTH-$DAY' title='$EVENTS_COUNT[0] item"; 96 if ($EVENTS_COUNT[0] > 1) 97 echo "s"; 98 // echo "'>$DAY </a>)"; 99 if($MONTH<10) $MONTH1='0'.$MONTH; else $MONTH1=$MONTH; 100 if($DAY<10) $DAY1='0'.$DAY; else $DAY1=$DAY; 101 102 if($caltype==0) echo "<A href=\"javascript: void tfset1('$YEAR','$MONTH1','$DAY1','$base')\">$DAY</A>"; 103 else echo "<A href=\"javascript: void tfset2('$YEAR','$MONTH1','$DAY1','$base')\">$DAY</A>"; 104 echo "</td>\n"; 105 $DAY++; 106 } 107 108 function drawCalendar($base, $str = "",$caltype) { 109 global $HOSTNAME, $DATABASE, $USERNAME, $PASSWORD; 110 // Current date 111 $STAMP_NOW = mktime(); 112 $NOW = getdate($STAMP_NOW); 113 $TEMP = ""; 114 115 // Parse date we were given or use the current date 116 if ($str != "") { 117 $DATE = explode("-", $str); 118 $TEMP = getdate(mktime(1, 1, 1, $DATE[1], 1, $DATE[0])); 119 unset($DATE); 120 } else { 121 $TEMP = $NOW; 122 } 123 124 // Recreate date members from input 125 $MONTH = $TEMP["mon"]; 126 $YEAR = $TEMP["year"]; 127 $DAY = $TEMP["mday"]; 128 $MONTHNAME = "$TEMP[month] $YEAR"; 129 130 // How many days/weeks in month? 131 $DAYS = daysInMonth($YEAR, $MONTH); 132 $WEEKS = round(($DAYS + dayOfFirst($YEAR, $MONTH)) / 7); 133 if (($DAYS + dayOfFirst($YEAR, $MONTH)) % 7) $WEEKS++; 134 135 // Generate links to previous and next months 136 $TEMP = getdate(mktime(0,0,0, $MONTH - 1, 1, $YEAR)); 137 // $PREV_A = "<a href='$base$TEMP[year]-$TEMP[mon]' title='$TEMP[month] $TEMP[year]'><</a>"; 138 $TEMP = getdate(mktime(0,0,0, $MONTH + 1, 1, $YEAR)); 139 // $NEXT_A = "<a href='$base$TEMP[year]-$TEMP[mon]' title='$TEMP[month] $TEMP[year]'>></a>"; 140 141 142 // Open table and display header 143 echo "\t<table class='calendar' cellspacing='0'>\n"; 144 echo "\t\t<!-- Calendar Heading -->\n"; 145 echo "\t\t<tr class='month'>\n"; 146 echo "\t\t\t<th>$PREV_A</th>\n"; 147 // echo "\t\t\t<th colspan='5'><a href='$base$YEAR-$MONTH' title='$MONTHNAME'>" . 148 // "$MONTHNAME</a></th>\n"; 149 echo "\t\t\t<th colspan='5'>$MONTHNAME</th>\n"; 150 echo "\t\t\t<th>$NEXT_A</th>\n"; 151 echo "\t\t</tr>\n"; 152 153 echo "\n\t\t<!-- Column Headings -->\n"; 154 echo "\t\t<tr class='days'>\n"; 155 echo "\t\t\t<th>M</th>\n"; 156 echo "\t\t\t<th>T</th>\n"; 157 echo "\t\t\t<th>W</th>\n"; 158 echo "\t\t\t<th>T</th>\n"; 159 echo "\t\t\t<th>F</th>\n"; 160 echo "\t\t\t<th>S</th>\n"; 161 echo "\t\t\t<th>S</th>\n"; 162 echo "\t\t</tr>\n"; 163 164 165 $CHOPPED_DAYS = 0; // Number of days moved to the 1st week from end 166 $FIRST = dayOfFirst($YEAR, $MONTH); // The index of the first day of the month 167 $DAY = 1; // Day counter 168 $i = 0; // Loop counter 169 170 /* 171 * XXX: This needs tracking down. Ideally, should use $DAYS + $FIRST to make 172 * decision in loop conditions 173 */ 174 if ($WEEKS > 5) { 175 // How many days should be moved to the spaces at the start of the month? 176 if (($DAYS - (($WEEKS - 1) * 7))<$FIRST) { 177 $CHOPPED_DAYS = ($DAYS - ((5 * 7)-$FIRST)); 178 if ($CHOPPED_DAYS < 0) $CHOPPED_DAYS = 0; 179 } 180 181 // Insert chopped days 182 if ($CHOPPED_DAYS) { 183 $DAYS -= $CHOPPED_DAYS; 184 $CHOPPED_DAY = $DAYS + 1; 185 $WEEKS--; 186 } 187 } 188 189 // Display Week 1 190 echo "\n\t\t<!-- Week 1 -->\n"; 191 echo "\t\t<tr>\n"; 192 // There was a bug with 31 on Th. - Torsten 193 // for (;$i < $CHOPPED_DAYS; $i++) 194 // drawDay($YEAR, $MONTH, $CHOPPED_DAY, $NOW, $base, $mysql_id,$caltype); 195 for (;$i < $CHOPPED_DAYS; $i++){ 196 drawDay($YEAR, $MONTH, $CHOPPED_DAY, $NOW, $base, $mysql_id,$caltype); 197 $CHOPPED_DAY++; 198 } 199 200 for (;$i < $FIRST; $i++) 201 echo "\t\t\t<td></td>\n"; 202 for (;$i < 7; $i++) { 203 drawDay($YEAR, $MONTH, $DAY, $NOW, $base, $mysql_id,$caltype); 204 $DAY++; 205 } 206 echo "\t\t</tr>\n"; 207 208 /* Output following weeks */ 209 for ($week = 2; $week <= $WEEKS; $week++) { 210 echo "\n\t\t<!-- Week $week -->\n\t\t<tr>\n"; 211 for ($day = 0; $day < 7; $day++) { 212 if ($DAY <= $DAYS) { 213 drawDay($YEAR, $MONTH, $DAY, $NOW, $base, $mysql_id,$caltype); 214 $DAY++; 215 } else { 216 echo "\t\t\t<td></td>\n"; 217 } 218 } 219 echo "\t\t</tr>\n"; 220 } 221 // Close table 222 echo "\t</table>\n"; 223 } // drawCalendar(); 224 } // isset($CALENDAR) 225 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |