The Ninja Space Goat wrote:how would that help?
It cheers you up.
But seriously: I've used the same script some time back (from the manual) and hacked around. The result won't win any design-contests, but it did what it had to then.
Code: Select all
//wrap this into some class
function set_calendar_grid(){
$days = $this->get_month_days();
$this->month_name = $days["month"];
for($i=$days["first_day"];$i<$days["days_in_month"]+$days["first_day"];$i++){
$weekday = ((int)$i%7);
$this->grid[$i] = array("day"=>$this->weekday[$weekday]);
$this->grid[$i]["weekday"] = $weekday;
$this->grid[$i]["weeknumber"] = date("W",mktime(0,0,0,$this->month,$i,$this->year));
if($i==$days["first_day"]){
$this->grid[$i]["first_day"]=true;
$this->grid[$i]["css_class"]="firstday";
if($weekday==6 || $weekday==0){
$this->grid[$i]["css_class"].="weekend";
}
}
elseif($weekday==6 || $weekday==0){
$this->grid[$i]["css_class"].="weekend";
}
else{
$this->grid[$i]["css_class"]="normal";
}
if(date("d")==$i){
$this->grid[$i]["today"]=true;
}
}
$this->offset = $days["first_day"]-1;
}
function get_month_days(){
$return["days_in_month"] = date("t",mktime(0,0,0,$this->month,1,$this->year));
$return["first_day"] = (date("w",mktime(0,0,0,$this->month,1,$this->year))) ? date("w",mktime(0,0,0,$this->month,1,$this->year)) : 7;
$return["month"] = date("F",mktime(0,0,0,$this->month,1,$this->year));
return $return;
}
and the calling script/page
Code: Select all
require_once(ROOT_PATH."classes/class_calendar.inc.php");
$calendar = &new calendar(filter::sanitise_number($_GET["m"]),filter::sanitise_number($_GET["y"]));
$calendar->set_calendar_grid();
$calendar->set_url_parameters();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Calendar</title>
<style type="text/css" media="screen">
@import "css/main.css";
@import "css/calendar_grey.css";
</style>
<!-- We hates IE, we hates it. Yes, precious. We hates it. -->
<!--[if IE]>
<link
href="css/mainIE.css"
rel="stylesheet"
type="text/css"
media="screen">
<link
href="css/calendar.css"
rel="stylesheet"
type="text/css"
media="screen">
<![endif]-->
</head>
<body>
<?php include("templates/header.html");?>
<table width="100%" height="100%" class="calendar" summary="view of calendar">
<tr class="navigation">
<td colspan="8"><span><a href="<?php echo $_SERVER["PHP_SELF"]."?".$calendar->url["month_previous"]?>"><img src="graphix/arrow_left.gif" alt="previous month" width="12" height="11" border="0"></a> <?php echo $calendar->month_name." ".$calendar->year;?> <a href="<?php echo $_SERVER["PHP_SELF"]."?".$calendar->url["month_next"]?>"><img src="graphix/arrow_right.gif" alt="next month" width="12" height="13" border="0"></a></span></td>
</tr>
<tr>
<th class="weeknumber">Week</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Sun</th>
</tr>
<tr>
<?php
for($i=1;$i<=35;$i++){
if($i==1 || $i==8 || $i==15 || $i==22 || $i==29){
echo "<td class='weeknumber'>".date("W",mktime(0,0,0,$calendar->month,$i,$calendar->year))."</td>";
}
if($calendar->grid[$i]){
echo '<td id="day'.$i.'" class="'.$calendar->grid[$i]["css_class"].'"><span class="day">'.($i-$calendar->offset).'</span></td>';
}
else{
echo '<td class="blank"> </td>';
}
if(!($i%7)){
echo "</tr><tr>";
}
}
?>
</tr>
</table>
</div>
</body>
</html>
edit: If you use it and refactor it: please post your version.