Calendar PHP does not work
Posted by: gorilla (---.dsl.bell.ca)
Date: October 26, 2007 01:28AM

I am trying to preview this in IExplorer7
with Dreamweaver, it does NOT work.

<html>
<head>
<title>Calendar</title>
<style type="text/css">
<!--Sets the style for the calendar--!>
.table.calendar {border: 1px solid #000000; border-collapse: collapse; color: #000000; background: #FFFFFF; }
<!--Sets the style for today on the calendar--!>
.td.today { border: 1px solid white; color: #000000; background:#EFEFEF; font-weight: bold;}
<!--Sets the style for the days of the month--!>
.monthdays {border: 1px solid #434470; color: #000000; background: #FFFFFF;}
<!--Sets the style for the nonmonth days--!>
.td.nonmonthdays { border: 1px solid white; color: #000000; background: #EFEFEF;}
</style>
<body>
<?php
//Set error_reporting to 0 therefore no errors will be displayed in browser
error_reporting('0');
ini_set('display_errors','0');
if(!isset($_Request['date'])){
//gets currentd month/date/year
$date=mktime(0,0,0,date('m'),date('d'),date('Y'));
}else{
$date=$_request['date'];
}
$day=date('d',$date);
$month=date('m',$date);
$year=date('Y',$date);
//get first day of the month
$month_start=mktime(0,0,0,$month,1,$year);
//get month name
$month_name = date('M', $month_start);
//gets which day of the week the month starts on
$month_start_day = date('D', $month_start);
//a switch which gives each day of the week a variable which makes it easier to create calendar
switch($month_start_day){
case "Sun": $offset = 0; break;
case "Mon": $offset = 1; break;
case "Tue": $offset = 2; break;
case "Wed": $offset = 3; break;
case "Thu": $offset = 4; break;
case "Fri": $offset = 5; break;
case "Sat": $offset = 6; break;
}
//determine how many days are in the last month
if($month==1){
$num_days_last=cal_days_in_month(0,12,($year-1));
)else(
$num_days_last=cal_days_in_month(0,($month-1),$year);
}
//determine how many days are in the current month
$num_days_current=cal_days_in_month(0,$month,$year);
//build an array for the current days in the month
for($i = 1; $i <= $num_days_current; $i++){
$num_days_array[] = $i;
}
//build an array for the number of days in last month
for($i = 1; $i <= $num_days_last; $i++){
$num_days_last_array[] = $i;
}
if($offset > 0){
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
$offset_count = count($offset_correction);
}else{
$new_count = $num_days_array;
}
//count how many days we have with the two previous arrays merged together
$current_num = count($new_count);
if($current_num > 35){
$num_weeks = 6;
$outset = (42 - $current_num);
}elseif($current_num < 35){
$num_weeks = 5;
$outset = (35 - $current_num);
}
if($current_num == 35){
$num_weeks = 5;
$outset = 0;
}
for($i = 1; $i <= $outset; $i++){
$new_count[] = $i;
}
$weeks = array_chunk($new_count, 7);
$previous_link="<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month==1){
$previous_link.=mktime(0,0,0,12,$day,($year-1));
)else{
$previous_link.=mktime(0,0,0,($month-1),$day,$year);
)
$previous_link.="\"><<Prev</a>";
$next_link="<a href=\"".$_Server['PHP_SELF']."?date=";
if($month==12){
$next_link.=mktime(0,0,0,1,$day,($year+1));
}else{
$next_link.=mktime(0,0,0,($month+1),$day,$year);
}
$next_link.="\">Next>></a>";
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" class=\Calendar\">\n".
"<td colspan=\"7\">".
"<table align=\"center\">".
"<tr>".
"<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
"<td colspan=\"3\" width=\"150\" align=\"center\">$month_name $year</td>\n".
"<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n".
"</tr>\n".
"</table>\n".
"</td>\n".
"<tr>\n".
"<td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td>\n".
"</tr>\n";
$i=0
foreach($week as $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=". mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset )){
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\">$d</td>\n";
}else{
echo "<td class=\"days\"><a href=\"".$_SERVER[ 'PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year). "\">$d</a></td>\n";
}
}elseif($i >= ($num_weeks * 7) - $outset) {
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=". mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
$i++;
}
echo "</tr>\n";
}
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table>';
?>
</body>
</html>

Options: ReplyQuote


Sorry, only registered users may post in this forum.