Example #1
0
/**
 * PrintCalendar() - prints the calendar with events 
 */
function PrintCalendar()
{
    $date = time();
    date_default_timezone_set("America/New_York");
    //EASTERN TIME ZONE
    //GET values for month and year
    $month = $_GET['month'];
    $year = $_GET['year'];
    $useCurDate = true;
    //check to makes sure month and year are in the desired ranges
    if (!empty($month) && !empty($year) && $month > 0 && $month < 13 && $year > 1990) {
        $useCurDate = false;
    }
    //check to see if the get variables are for todays month
    if ($month == date('n', $date) && $year == date('Y', $date)) {
        $useCurDate = true;
    }
    //use current date unless GET values are set
    if ($useCurDate) {
        $day = date('d', $date);
        $today = date('j', $date);
        $month = date('m', $date);
        $monthNum = date('n', $date);
        $year = date('Y', $date);
    } else {
        $monthNum = $month;
        //if GET values are equal to curdate, set $today
        if ($year == date('Y', $date) && $monthNum == date('n', $date)) {
            $today = date('j', $date);
        } else {
            $today = 0;
        }
    }
    /* Accounts for the last couple days from the previous months */
    $first_day = mktime(0, 0, 0, $monthNum, 1, $year);
    $title = date('F', $first_day);
    $day_of_week = date('D', $first_day);
    switch ($day_of_week) {
        case "Sun":
            $blank = 0;
            break;
        case "Mon":
            $blank = 1;
            break;
        case "Tue":
            $blank = 2;
            break;
        case "Wed":
            $blank = 3;
            break;
        case "Thu":
            $blank = 4;
            break;
        case "Fri":
            $blank = 5;
            break;
        case "Sat":
            $blank = 6;
            break;
    }
    /* calculates the days in the current month */
    $days_in_month = cal_days_in_month(0, $monthNum, $year);
    //makes sure that previous year is not year 0
    if ($monthNum == 1) {
        $previous_month = 12;
        $previous_year = $year - 1;
    } else {
        $previous_month = $monthNum - 1;
        $previous_year = $year;
    }
    //makes sure the next year is not year 13
    if ($monthNum == 12) {
        $next_month = 1;
        $next_year = $year + 1;
    } else {
        $next_month = $monthNum + 1;
        $next_year = $year;
    }
    ?>
		             
		<center>
			<table class="calendar" style="background-color:white;" cellspacing="1" cellpadding="0">	
				<tr style="background-color:#999999; height:27px;">
					<td colspan="50" style="vertical-align:middle; text-align:center;">
		    			<a href="?op=calendar&month=<?php 
    echo $previous_month . '&year=' . $previous_year;
    ?>
"><<</a>
		    			<!-- Month Name and Year -->
		    			&nbsp;&nbsp;<span class="monthTitle"><?php 
    echo strtoupper($title) . ' ' . $year;
    ?>
</span>&nbsp;&nbsp;
						<a href="?op=calendar&month=<?php 
    echo $next_month . '&year=' . $next_year;
    ?>
">>></a>
					</td>
				</tr>
					
				<tr>
					<th class="weekday">Sun</th><th class="weekday">Mon</th><th class="weekday">Tue</th><th class="weekday">Wed</th>
					<th class="weekday">Thu</th><th class="weekday">Fri</th><th class="weekday">Sat</th>
				</tr>
				
				<tr>
		<?php 
    $day_count = 1;
    //holds the current day of the week 1-7
    $day_num = 1;
    //holds the current day of the month 1-31
    $days_monthbefore = cal_days_in_month(0, $previous_month, $year);
    //prints the numbers of days for the previous month
    while ($blank > 0) {
        $blank = $blank - 1;
        $days_before = $days_monthbefore - $blank;
        echo '<td class="cal_notmonth">' . $days_before . '</td>';
        //'.$days_before.'</td>';
        $day_count++;
    }
    $events = GetEventsOnInterval("{$year}-{$monthNum}-01", "{$year}-{$monthNum}-{$days_in_month}");
    //loop printing each day of the CURRENT month ONLY
    while ($day_num <= $days_in_month) {
        if ($day_count == 1 || $day_count == 7) {
            echo '<td class="cal_weekend">';
            //weekends
        } else {
            echo '<td class="cal_weekday">';
            //weekdays
        }
        $sqlDate = date("Y-m-d", mktime(0, 0, 0, $monthNum, $day_num, $year));
        //checks to see if the current day has events
        $isEvent = false;
        foreach ($events as $event) {
            if ($event['date'] == $sqlDate) {
                $isEvent = true;
            }
        }
        if ($useCurDate) {
            echo "<a href=\"?op=calendar&list={$year}-{$monthNum}-{$day_num}\">";
        } else {
            echo "<a href=\"?op=calendar&month={$monthNum}&year={$year}&list={$year}-{$monthNum}-{$day_num}\">";
        }
        if ($day_num == $today && $isEvent == true) {
            echo '<div class="eventtoday">' . $day_num . '</div>';
        } else {
            if ($day_num == $today && $isEvent == false) {
                echo '<div class="monthtoday">' . $day_num . '</div>';
            } else {
                if ($day_num != $today && $isEvent == true) {
                    echo '<div class="event" id="event' . $day_num . '" onmouseover="highlightEvent(this.id)" onmouseout="normEvent(this.id)">';
                    echo $day_num;
                    echo '</div>';
                } else {
                    echo $day_num;
                }
            }
        }
        echo "</a>";
        echo '</td>';
        $day_num++;
        $day_count++;
        if ($day_count > 7) {
            echo '</tr><tr>';
            $day_count = 1;
        }
    }
    $days_after = 1;
    //loop for printing the days for the next month
    while ($day_count > 1 && $day_count <= 7) {
        echo '<td class="cal_notmonth">' . $days_after . '</td>';
        //'.$days_after.'</td>';
        $days_after++;
        $day_count++;
    }
    ?>
			 
		 	</tr>
		</table>
		</center>
<?php 
}
Example #2
0
function PrintCalendar()
{
    $date = time();
    date_default_timezone_set("America/New_York");
    //EASTERN TIME ZONE
    $day = date('d', $date);
    $today = date('j', $date);
    $month = date('m', $date);
    $monthNum = date('n', $date);
    $year = date('Y', $date);
    /* Accounts for the last couple days from the previous months */
    $first_day = mktime(0, 0, 0, $monthNum, 1, $year);
    $title = date('F', $first_day);
    $day_of_week = date('D', $first_day);
    switch ($day_of_week) {
        case "Sun":
            $blank = 0;
            break;
        case "Mon":
            $blank = 1;
            break;
        case "Tue":
            $blank = 2;
            break;
        case "Wed":
            $blank = 3;
            break;
        case "Thu":
            $blank = 4;
            break;
        case "Fri":
            $blank = 5;
            break;
        case "Sat":
            $blank = 6;
            break;
    }
    /* calculates the days in the current month */
    $days_in_month = cal_days_in_month(0, $monthNum, $year);
    //makes sure that previous year is not year 0
    if ($monthNum == 1) {
        $previous_month = 12;
        $previous_year = $year - 1;
    } else {
        $previous_month = $monthNum - 1;
        $previous_year = $year;
    }
    //makes sure the next year is not year 13
    if ($monthNum == 12) {
        $next_month = 1;
        $next_year = $year + 1;
    } else {
        $next_month = $monthNum + 1;
        $next_year = $year;
    }
    ?>
		             
		<center>
			<table class="calendar" style="background-color:white;" cellspacing="1" cellpadding="0">	
				<tr style="background-color:#999999; height:20px;">
					<td colspan="50" style="vertical-align:middle; text-align:center;">
		    			<!-- <a href="?op=calendar&month=<?php 
    echo $previous_month . '&year=' . $previous_year;
    ?>
"><<</a> -->
		    			<!-- Month Name and Year -->
		    			&nbsp;&nbsp;<span class="monthTitle"><?php 
    echo strtoupper($title) . ' ' . $year;
    ?>
</span>&nbsp;&nbsp;
						<!-- <a href="?op=calendar&month=<?php 
    echo $next_month . '&year=' . $next_year;
    ?>
">>></a> -->
					</td>
				</tr>
					
				<tr>
					<th class="weekday">Sun</th><th class="weekday">Mon</th><th class="weekday">Tue</th><th class="weekday">Wed</th>
					<th class="weekday">Thu</th><th class="weekday">Fri</th><th class="weekday">Sat</th>
				</tr>
				
				<tr>
		<?php 
    $day_count = 1;
    //holds the current day of the week 1-7
    $day_num = 1;
    //holds the current day of the month 1-31
    $days_monthbefore = cal_days_in_month(0, $previous_month, $year);
    //prints the numbers of days for the previous month
    while ($blank > 0) {
        $blank = $blank - 1;
        $days_before = $days_monthbefore - $blank;
        echo '<td class="cal_notmonth">' . $days_before . '</td>';
        //'.$days_before.'</td>';
        $day_count++;
    }
    $sqlToday = date("Y-m-d", mktime(0, 0, 0, $monthNum, $today, $year));
    $events = GetEventsOnInterval("{$year}-{$monthNum}-01", "{$year}-{$monthNum}-{$days_in_month}");
    //loop printing each day of the CURRENT month ONLY
    while ($day_num <= $days_in_month) {
        if ($day_count == 1 || $day_count == 7) {
            echo '<td class="cal_weekend">';
            //weekends
        } else {
            echo '<td class="cal_weekday">';
            //weekdays
        }
        $sqlDate = date("Y-m-d", mktime(0, 0, 0, $monthNum, $day_num, $year));
        //checks to see if the current day has events
        $isEvent = false;
        foreach ($events as $event) {
            if ($event['date'] == $sqlDate) {
                $isEvent = true;
                if ($event['date'] == $sqlToday) {
                    $todaysEvents[] = $event;
                }
            }
        }
        if ($day_num == $today && $isEvent == true) {
            echo '<div class="eventtoday">' . $day_num . '</div>';
        } else {
            if ($day_num == $today && $isEvent == false) {
                echo '<div class="monthtoday">' . $day_num . '</div>';
            } else {
                if ($day_num != $today && $isEvent == true) {
                    echo "<div class=\"event\" onclick=\"openEvent('{$sqlDate}')\">";
                    echo $day_num;
                    echo '</div>';
                } else {
                    echo $day_num;
                }
            }
        }
        echo '</td>';
        $day_num++;
        $day_count++;
        if ($day_count > 7) {
            echo '</tr><tr>';
            $day_count = 1;
        }
    }
    $days_after = 1;
    //loop for printing the days for the next month
    while ($day_count > 1 && $day_count <= 7) {
        echo '<td class="cal_notmonth">' . $days_after . '</td>';
        //'.$days_after.'</td>';
        $days_after++;
        $day_count++;
    }
    ?>
			 
		 	</tr>
		</table>
		</center>
<?php 
    //list events for today
    if (count($todaysEvents) > 0) {
        echo "<h3>Today's Events</h3>";
        foreach ($todaysEvents as $event) {
            $time = date("g:i a", strtotime($event['date'] . " " . $event['time']));
            echo "<span style=\"background-color: {$event['color']}\">&nbsp;&nbsp;</span>&nbsp;{$event['title']} @ {$time}<br />";
        }
    }
}