Scripts
Kalender
Hier een simpele kalender met CSS, weeknummers enzovoorts. De kalender heeft alleen een maand-weergave. Zie voor meer het voorbeeld. Ik heb 2 grote bugs in ieder geval gefixt, maar mocht je er nog meer tegen komen, laat het dan ff weten.
kalender
kalender.php:
[code]
<?php
##########################
# Calendar-script in PHP #
# Copyright Sytze Loor #
# [email protected] #
# Last update 07-02-24 #
##########################
// Names for the days of the week (currently Dutch):
$weekday['all'] = array(1=>"ma","di","wo","do","vr","za","zo");
// Names for the months of the year (currently Dutch):
$month['all'] = array(1=>"januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december");
// Check the user-input, is it numeric and accepted by date():
if (($_GET['month'] > 0) && ($_GET['month'] <= 12) && ($_GET['year'] > 1902) && ($_GET['year'] < 2036)) {
if (is_numeric($_GET['month'])) {
$month['input'] = $_GET['month'];
}
if (is_numeric($_GET['year'])) {
$year['input'] = $_GET['year'];
}
} else {
// If no input of false input, take the current date:
$month['input'] = date(n);
$year['input'] = date(Y);
}
// The current year and month:
$month['current'] = date(n);
$year['current'] = date(Y);
// The timestamp from the first day of the current month:
$timestamp['start_month'] = mktime(0,0,0,$month['input'],1,$year['input']);
// Number of days in current month:
$i_days['month'] = date(t,$timestamp['start_month']);
// Sets the first day:
$day['start_day'] = date(j,$timestamp['start_month']);
// Which day of the week is the first day:
$weekday['start_day'] = date(N,$timestamp['start_month']);
// Sets the timestamp for the last day:
$timestamp['last_month'] = mktime(0,0,0,$month['input'],$i_days['month'],$year['input']);
// Sets the last day:
$day['last_day'] = date(j,$timestamp['last_month']);
// Which day of the week is the last day:
$weekday['last_day'] = date(N,$timestamp['last_month']);
// Collect all data (current month only!), from first to last day:
$i = 1;
while ($i <= $i_days['month']) {
$timestamp['now'] = mktime(0,0,0,$month['input'],$i,$year['input']);
$weekday['now'] = date(N,$timestamp['now']);
$day['all'][$i] = array($i,$month['input'],$year['input'],$weekday['all'][$weekday['now']]);
$i++;
}
// Collect data from previous month:
$i = $weekday['start_day']-1;
while ($i >= 1) {
$i_int = 1 - $i;
$timestamp['now'] = mktime(0,0,0,$month['input'],$i_int,$year['input']);
$weekday['now'] = date(N,$timestamp['now']);
$day['now'] = date(j,$timestamp['now']);
$month['now'] = date(n,$timestamp['now']);
$year['now'] = date(Y,$timestamp['now']);
$day['prev']['all'][$i] = array($day['now'],$month['now'],$year['now'],$weekday['all'][$weekday['now']]);
$i--;
}
// Sort the previous month:
@sort($day['prev']['all']);
// Collect data from next month:
if ($weekday['last_day'] < 7) {
$i = 1;
while ($i + $weekday['last_day'] <= 7) {
$i_int = $day['last_day'] + $i;
$timestamp['now'] = mktime(0,0,0,$month['input'],$i_int,$year['input']);
$weekday['now'] = date(N,$timestamp['now']);
$day['now'] = date(j,$timestamp['now']);
$month['now'] = date(n,$timestamp['now']);
$year['now'] = date(Y,$timestamp['now']);
$day['next']['all'][$i] = array($day['now'],$month['now'],$year['now'],$weekday['all'][$weekday['now']]);
$i++;
}
} else {
$day['next']['all'] == "";
}
// Set the links to the previous en next month:
$month['prev'] = $month['input'] - 1;
$year['prev'] = $year['input'];
if ($month['input'] == 1) {
$month['prev'] = 12;
$year['prev'] = $year['input'] - 1;
}
$month['next'] = $month['input'] + 1;
$year['next'] = $year['input'];
if ($month['input'] == 12) {
$month['next'] = 1;
$year['next'] = $year['input'] + 1;
}
// Create a default header:
$header = "";
$header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$header .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
$header .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
$header .= "<title>Kalender</title>\n";
$header .= "<link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
$header .= "</head>\n";
// Create the body:
$body = "";
$body .= "<body>\n";
// Create the table:
$table = "";
$table .= "<table cellspacing=\"0\" border=\"0\">\n";
// The tableheader:
$table .= "<tr>\n";
$table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"><a href=\"kalender.php?month=".$month['prev']."&year=".$year['prev']."\"><</a></td>\n";
$table .= "<td class=\"maand_header\" height=\"30\" colspan=\"6\">".ucfirst($month['all'][$month['input']])." ".$year['input']."</td>\n";
$table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"><a href=\"kalender.php?month=".$month['next']."&year=".$year['next']."\">></a></td>\n";
$table .= "</tr>\n";
// The days of the week:
$table .= "<tr>\n";
$table .= "<td class=\"dag_header\" height=\"30\" width=\"25\">Wk:</td>\n";
$i = 1;
while ($i <= count($weekday['all'])) {
$table .= "<td class=\"dag_header\" height=\"30\" width=\"25\">".ucfirst($weekday['all'][$i])."</td>\n";
$i++;
}
// Total days to display this month:
$day['total_prev'] = count($day['prev']['all']);
$day['total_all'] = count($day['all']);
$day['total_next'] = count($day['next']['all']);
$day['total'] = $day['total_prev'] + $day['total_all'] + $day['total_next'];
// Create a array with the days in the correct order:
$i = 0;
$i_int = 0;
while ($i_int <= $day['total_prev']) {
$day['display'][$i] = $day['prev']['all'][$i_int];
$i_int++;
$i++;
}
$i_int = 0;
while ($i_int <= $day['total_all']) {
$day['display'][$i] = $day['all'][$i_int];
$i_int++;
$i++;
}
if ($weekday['last_day'] < 7) {
$i_int = 0;
while ($i_int <= $day['total_next']) {
$day['display'][$i] = $day['next']['all'][$i_int];
$i_int++;
$i++;
}
}
// Display the days:
$i = 0;
while ($i < count($day['display'])) {
$i_int = 0;
if (($day['display'][$i][0] == "") && ($day['display'][$i][3] == "")) {
$timestamp['now'] = mktime(0,0,0,$day['display'][6][1],1,$day['display'][6][2]);
} else {
$timestamp['now'] = mktime(0,0,0,$day['display'][$i][1],$day['display'][$i][0],$day['display'][$i][2]);
}
$week['now'] = date(W,$timestamp['now']);
$table .= "<tr>\n";
$table .= "<td class=\"weken_tekst\" height=\"30\" width=\"25\">".$week['now']."</td>\n";
while ($i_int < 7) {
if (is_array($day['display'][$i])) {
if ($day['display'][$i][1] == $month['input']) {
$style = "dagen_dezemaand";
} else {
$style = "dagen_anderemaand";
}
if (($day['display'][$i][0] == date(j)) && ($day['display'][$i][1] == date(m)) && ($year['input'] == $year['current'])) {
$style = "dagen_vandaag";
}
$table .= "<td class=\"".$style."\" height=\"30\" width=\"25\">".$day['display'][$i][0]."</td>\n";
$i_int++;
}
$i++;
}
$table .= "</tr>\n";
}
// The tablefooter:
$table .= "<tr>\n";
$table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"> </td>\n";
$table .= "<td class=\"maand_header\" height=\"30\" colspan=\"6\"><a href=\"kalender.php?month=".$month['current']."&year=".$year['current']."\">naar huidige maand</a></td>\n";
$table .= "<td class=\"maand_header\" height=\"30\" width=\"25\"> </td>\n";
$table .= "</tr>\n";
$table .= "</table>\n";
$body .= $table;
$body .= "</body>\n";
// Create a default footer:
$footer = "";
$footer .= "</html>\n";
// Display the header, body and footer:
echo $header;
echo $body;
echo $footer;
?>
[/code]
default.css:
[code]
/* Standaard CSS */
body,td,th {
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
padding: 4px;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #006699;
}
a:visited {
color: #006699;
}
a:hover {
color: #FF9900;
}
a:active {
color: #FF9900;
}
.maand_header {
font-weight: bold;
text-align: center;
}
.dag_header {
font-style: italic;
text-align: center;
background-color: #EEE;
}
.dagen_dezemaand {
text-align: center;
}
.weken_tekst {
text-align: center;
background-color: #EEE;
}
.dagen_anderemaand {
text-align: center;
color: #666666;
background-color: #999999;
}
.dagen_vandaag {
text-align: center;
background-color: #FF0000;
}
[/code]
Reacties
0