Cheap Home Insurance | Lockers | Find jobs | Maschinenbau für mischen und rühren | Cheap Home Insurance
Things to do php webcalendar script [Archive] - Muslim Programmers & Designers Community - Islamic Webhosting and Nasheeds

PDA

View Full Version : Things to do php webcalendar script



WiseOne
05-25-2003, 07:53 AM
<?php
1 class Calendar{
2 function generate_calendar($year, $month, $day_func = NULL, $day_heading_length = 3){
3 $date = date('d');
4 $dark_days = array();
5 $buff=mysql_query ("SELECT UNIX_TIMESTAMP(start_date), UNIX_TIMESTAMP(end_date) FROM things2do");
6
7 while ($line = mysql_fetch_assoc($buff)){
8 $counter++;
9 $dark_days[$counter]['start'] = $line['UNIX_TIMESTAMP(start_date)'];
10 $dark_days[$counter]['end'] = $line['UNIX_TIMESTAMP(end_date)'];
11 }
12
13 $first_of_month = mktime (0,0,0, $month, 1, $year);
14 static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');
15 $maxdays = date('t', $first_of_month);
16 $date_info = getdate($first_of_month);
17 $month = $date_info['mon'];
18 $year = $date_info['year'];
19
20 $calendar = "<table class=\"cal_main\" width=\"200\" celpadding=\"2\" cellspacing=\"2\" align=\"center\">\n";
21 $calendar .= "<tr class=\"cal_title\"><th colspan=\"7\" class=\"cal_month\">$date_info[month], $year</th></tr>\n";
22 $calendar .= "<tr class=\"cal_days\"><td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td></tr>\n";
23
24 $calendar .= '<tr>';
25
26 $weekday = $date_info['wday'];
27 $day = 1;
28
29 if($weekday > 0){
30 $calendar .= "<td colspan=\"$weekday\">&nbsp;</td>\n";
31 }
32
33
34 while ($day <= $maxdays){
35 if($weekday == 7){
36 $calendar .= "</tr>\n<tr>";
37 $weekday = 0;
38 }
39
40 $linkDate = mktime (0,0,0, $month, $day, $year);
41 if($linkDate == date('d')){
42 $class='cal_today';
43 } else {
44 $d = date('m/d/Y', $linkDate);
45 foreach($dark_days as $dark){
47 if( ($linkDate <= $dark['end']) and ($linkDate >= $dark['start']) ){
48 $darken= true;
49 }
50 }
51 if($darken){
52 $class = 'cal_post';
53 $darken = false;
54 } else {
55 $class = 'cal_empty';
56 }
57 }
58 $link = "/things2do/calendar.php?date=$linkDate";
59 $calendar .= "<td class=\"$class\"><a href=\"$link\">$day</a><br /></td>\n";
60 $day++;
61 $weekday++;
62 }
63 if($weekday != 7){
64 $calendar .= '<td colspan="' . (7 - $weekday) . '">&nbsp;</td>';
65 }
66 $calendar .= "</tr>\n";
67 $calendar .= "<tr><td bgcolor=\"white\" colspan=\"7\"><center><font color=\"red\">Red Dates</font> indicate events.</td></tr>\n";
68 $calendar .= "<tr><td bgcolor=\"white\" colspan=\"7\"><center><span class=\"cal_blinks\"><A href=\"".$_SERVER['PHP_SELF']."?".$this->previous_month($month, $year)."\">&lt;&lt; Previous</a>&nbsp;|&nbsp;<A href=\"".$_SERVER['PHP_SELF']."?".$this->next_month($month, $year)."\">Next &gt;&gt;</a></span></center></td></tr>\n";
69 $calendar .= "</table>\n";
70 return $calendar;
71 }
72
73 function previous_month($month, $year){
74 if($month > 1){
75 $month = $month - 1;
76 $year = $year;
77 } elseif($month == 1){
78 $month = 12;
79 $year = $year - 1;
80 }
81 $url = "month=$month&amp;year=$year";
82 return $url;
83 }
84
85 function next_month($month, $year){
86 if($month < 12){
87 $month = $month + 1;
88 $year = $year;
89 } elseif($month == 12){
90 $month = 1;
91 $year = $year + 1;
92 }
93 $url = "month=$month&amp;year=$year";
94 return $url;
95 }
96 }
97 ?>
?>


Source : http://www.stargeek.com/scripts.php?script=11&cat=blog