09-03-2008, 10:30 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
|
Calendar Script - Week View
Hi, I have a calendar script which i have cusomised slightly to just display a list of days in a month and for each day it checks to see if there are any events and echos them out.
What i need to do now is have the current week view, so Mon-Sun of the current week only. Could anyone suggest how i would do that - here is the script so far for the full month:
PHP Code:
<?php
$date = time();
$day = date('d', $date);
$todays_actual_date = mktime(0,0,0,date('m', $date), date('d', $date), date('Y', $date));
if($_GET['month'] == "")
$month = date('m', $date);
else
$month = $_GET['month'];
if($_GET['year'] == "")
$year = date('Y', $date);
else
$year = $_GET['year'];
$prevMonth = date("m",mktime(0,0,0,$month-1, $day, $year));
$prevMonth = "index.php?year=$year&month=$prevMonth";
$prevYear = date("Y",mktime(0,0,0,$month, $day, $year-1));
$prevYear = "index.php?year=$prevYear&month=$month";
$nextMonth = date("m",mktime(0,0,0,$month+1, $day, $year));
$nextMonth = "index.php?year=$year&month=$nextMonth";
$nextYear = date("Y",mktime(0,0,0,$month, $day, $year+1));
$nextYear = "index.php?year=$nextYear&month=$month";
$first_day = mktime(0,0,0,$month, 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;
}
$days_in_month = cal_days_in_month(0, $month, $year);
echo "<div id=\"calendar\">";
$day_count = 1;
echo "<tr>";
while($blank > 0)
{
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while($day_num <= $days_in_month)
{
$current_in_sequence_date = mktime(0,0,0,$month, $day_num, $year);
if($todays_actual_date == $current_in_sequence_date)
{
if(strlen($day_num) == 1)
echo "<span class=\"eventTitleCurrent\">0$day_num $title $year</strong>".$testCurrentDate.'</span>';
else
echo "<span class=\"eventTitleCurrent\">$day_num $title $year</strong>".$testCurrentDate.'</span>';
// ------------------------------------------------------- GET CURRENT DATE IN DATETIME FORMAT
if(strlen($day_num) == 1)
$testCurrentDate = "$year-$month-0$day_num";
else
$testCurrentDate = "$year-$month-$day_num";
$testCurrentDate = checkForEvents($testCurrentDate);
// ------------------------------------------------------- GET CURRENT DATE IN DATETIME FORMAT
}
else
{
if(strlen($day_num) == 1)
echo "<span class=\"eventTitle\">0$day_num $title $year".$testCurrentDate.'</span>';
else
echo "<span class=\"eventTitle\">$day_num $title $year".$testCurrentDate.'</span>';
// ------------------------------------------------------- GET CURRENT DATE IN DATETIME FORMAT
if(strlen($day_num) == 1)
$testCurrentDate = "$year-$month-0$day_num";
else
$testCurrentDate = "$year-$month-$day_num";
$testCurrentDate = checkForEvents($testCurrentDate);
// ------------------------------------------------------- GET CURRENT DATE IN DATETIME FORMAT
}
$day_num++;
$day_count++;
if($day_count > 7)
{
$day_count = 1;
}
}
while($day_count > 1 && $day_count <=7)
{
$day_count++;
}
?>
Thanks,
Mike
|
|
|