/ Published in: PHP
Shows a month calendar, forward and backward navigation by month. Week numbers are shown at left col. Days and weeks are clickable. Days, weeks and months names are in Danish. Comments and suggestions are welcome
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Kalender</title> <style type="text/css"> body{ width: 300px; margin: 100px auto; background-color: #999999; text-align: center; font-family:"Trebuchet MS", arial, verdana; font-size: 12px; } #ContentBox{ width: 250px; border: thin #333333 solid; } table{ width: 100%; border-collapse: collapse; background-color: #fffeff; } th{ background-color: #333333; color: #F4F4F4; font-size: 14px; } tr.nav{ border-bottom: thin #333333 solid ; } a:link{ text-decoration: none; color: black; } a:visited{ text-decoration: none; color: black; } a:hover{ text-decoration: none; color: white; } a:active{ text-decoration: none; color: black; } .navig:link{ font-weight: bold; display: block; text-decoration: none; } .navig:visited{ font-weight: bold; background-color: #999999; text-decoration: none; } .navig:hover{ font-weight: bold; background-color: #333333; text-decoration: none; color:white; } .navig:active{ font-weight: bold; background-color: #333333; text-decoration: none; color:white; } .today{ font-weight: bold; text-decoration: underline ; } .sunday{ background-color: #CCCCCC; } .todaysunday{ font-weight: bold; background-color: #990000; } </style> </head> <body> <?php function SmallCalender(){ }; }; }; }; //Define current month, year and date $cMonth = $_GET["month"]; $cYear = $_GET["year"]; $cWeek = $_GET["week"]; $cDay = $_GET["day"]; //Calling to itself $self = @$_SERVER["PHP_SELF"]; //Variables for previous-next month and previous-next year $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth - 1; $next_month = $cMonth + 1; //Behaviour when months move from 1 to 12 and go to previous year if ($prev_month == 0){ $prev_month = 12; $prev_year = $cYear - 1; }; //Behaviour when months move from 12 to 1 and go to next year if ($next_month == 13){ $next_month = 1; $next_year = $cYear + 1; }; //Check last day of the current month //Count days in current month //Get numeric representation of day week ISO-8601 "", "Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn", ); "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December" ); //---------- echoing year and month navigation ------------------------------------------------- echo "<table>"; echo "<tr class=\"nav\">"; //upper row links to prev and next months echo "<th colspan=\"6\"> <strong> ".$monthnames[$cMonth]." ".$cYear." </strong> </th>"; echo "<td >"; echo "<a class=\"navig\" href='".$self."?month=".$prev_month."&year=".$prev_year."'> < </a> </td><td> <a class=\"navig\" href = '".$self."?month=".$next_month."&year=".$next_year."'> > </a>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td> Uge </td>"; $cell = 1; while ($cell <= 7){ if ($cell == 7){ $style = " class=\"sunday\""; }else{ $style = ""; } echo "<td {$style}>"; echo $daynames[$cell]; echo "</td>"; $cell++; } echo "</tr>"; echo "<tr>"; //Print empty cells - Add weeknumbers if ($firstday > 1){ echo "<td> <a href='".$self."?week=".$w."&month=".$cMonth."&year=".$cYear."'>"; echo $w; echo "</a></td>"; for ($empty_cell = 1; $empty_cell < $firstday; $empty_cell++){ echo "<td> </td>"; } } for ($d = 1; $d <= $lastday; $d++){ if ($N == 7){ $style = " class=\"sunday\""; }elseif ($j == $today){ $style = " class=\"today\""; }elseif ($j == $today && $N == 7){ $style = " class=\"todaysunday\""; }else{ $style = " "; } if ($N == 1){ echo "</tr><tr>"; echo "<td {$style} ><a href='".$self."?week=".$w."&month=".$cMonth."&year=".$cYear."'>"; echo $w; echo "</a></td>"; } echo "<td {$style}> <a href='".$self."?day=".$d."&month=".$cMonth."&year=".$cYear."'>"; echo $d; echo "</a></td>"; } echo "</tr>"; echo "</table>"; //Link to current date **** if ($cMonth <> $thismonth or $cYear <> $this_year){ echo "<a class=\"a\" href='".$self."?month=".$thismonth."&year=".$this_year."'> Vis nuværende måned </a>"; } } echo "<div id='ContentBox'>"; SmallCalender(); echo "</div>"; ?> </body> </html>