Scripts

Kalender

Een kalendertje is altijd wel handig... werkt zonder database

kalender
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<!-- kop met style plaatsen: style is van phpinfo() al je het bekend voor 
		 mocht komen ;) -->
	 
		 
<head>
  <style type="text/css"><!--
  a { text-decoration: none; }
  a:hover { text-decoration: underline; }
	acronym {border-bottom: 1px dotted #000; cursor:help;}
  h1 { font-family: arial, helvetica, sans-serif; 
  	 	 font-size: 18pt; font-weight: bold;}
  h2 { font-family: arial, helvetica, sans-serif; 
  	 	 font-size: 14pt; font-weight: bold;}
  body  {  font-family: arial, helvetica, 
  				 	  sans-serif; font-size: 10pt;
						  scrollbar-3dlight-color:#ffffff;
              scrollbar-arrow-color:#cccccc;
              scrollbar-base-color: #9999cc;
              scrollbar-darkshadow-color:#000000;
              scrollbar-face-color:#9999cc;
              scrollbar-highlight-color:#9999cc;
              scrollbar-shadow-color: #ccccff;}
				  }
	.line {border: 1px #000000 solid;}
  td {background-color:#cccccc;}					
  th {background-color:#ccccff; 
      	font-family: arial, helvetica, sans-serif; 
  	 	 font-size: 11pt; font-weight: bold; }
	input{ background-color: #9999cc;	border: 1px #000000 solid;}
option { background-color: #9999cc; border: 1px #000000 solid;}
textarea { background-color: #9999cc;	border: 1px #000000 solid;}
select {background-color: #9999cc; border: 1px #000000 solid; }		 
  //--></style>
  <title>Calendar</title>
</head>

<?php
function alias($monthnr){

  //-------------
	// pre: monthnr is een integer
	// post: retourneerd de naam van de maand
  switch ($monthnr){
    case "01": return "Januari";
    case "02": return "Februari";
    case "03": return "Maart";
    case "04": return "April";
		case "05": return "Mei";
		case "06": return "Juni";
		case "07": return "Juli";
		case "08": return "Augustus";
		case "09": return "September";
		case "10": return "Oktober";
		case "11": return "November";
		case "12": return "December";				
	}	
}

function calendar($day,$month,$year){

  //-------------
	// pre: -
	// post: retourneerd een overzicht van een maand met wat knopjes
  $today=$day;
  $firstdayofthemonth= date ("w", mktime(0, 0, 0, $month, 0, $year));
  $dayforloop = 1 - $firstdayofthemonth;
  $lastdayofthemonth= date ("d", mktime(0, 0, 0, $month+1, -1, $year));
  $endweekday =	date ("w", mktime(0, 0, 0, $month+1, -1, $year));
	if (!$endweekday==0)
	  $endday = $lastdayofthemonth + (7-$endweekday);
	else $endday = $lastdayofthemonth;
  
  echo "<form method=\"post\">";
	echo "<input type=\"hidden\" name=\"day\" value=\"$day\"></input>";
	echo "<input type=\"hidden\" name=\"month\" value=\"$month\"></input>";
	echo "<input type=\"hidden\" name=\"year\" value=\"$year\"></input>";
		  
  echo "<table border=\"0\" cellpadding=\"03\" cellspacing=\"0\">";
	
  echo "<tr><th align=\"center\" colspan=\"6\"><input type=\"text\" align=\"center\" name=\"date\" value=\"".
			 date ("d/m/y", mktime(0, 0, 0, $month, $day, $year))."\"></input></th><th>".
			 "<input type=\"submit\" name=\"button\" value=\"go\"></input>".
			 "</th></tr>";
	
	echo "<tr><th colspan=\"7\">".alias($month)."/$year</th></tr>";
			 
  echo "<tr>
  		  <th align=\"center\">ma </th>
  			<th align=\"center\">di </th>
  			<th align=\"center\">wo </th>
  			<th align=\"center\">do </th>
  			<th align=\"center\">vr </th>
  			<th align=\"center\">za </th>
  			<th align=\"center\">zo</th>
  			</tr>";
  echo "<tr>";

	
  while ($dayforloop<=$endday){
	 // als de dag niet bij de huidige maand hoort, andere kleur geven
	 if ( ($dayforloop<=0)|(($dayforloop-1)>$lastdayofthemonth) ) {echo "<td align=\"center\">";
	   echo "<font color=\"#dddddd\">".date ("d", mktime(0, 0, 0, $month, $dayforloop, $year))."</font></td>";}
	
	 // als het vandaag is, dan een mooi randje om de cel maken	 
	 elseif ($dayforloop==$today) echo "<td class=\"line\" align=\"center\">$dayforloop</td>";
	 
     // zoniet, dan gewoon printen	 
	 	 else echo "<td align=\"center\">".date ("d", mktime(0, 0, 0, $month, $dayforloop, $year))."</td>";
   
	 // wel of niet een nieuwe tablerow starten
	 if (date ("w", mktime(0, 0, 0, $month, $dayforloop, $year))==0)
	 if ( ($endday>=dayforloop)|(date("w",mktime(0,0,0,$month,$endday,$year))==0) ) echo"</tr>";
	 else echo"</tr><tr>";

   	$dayforloop++; 
  }
	
	// nog wat knopjes voor navigatie
	echo "<tr><th><input type=\"submit\" name=\"button\" value=\"<\"></input></th>";
  echo "<th align=\"center\" colspan =\"5\"><input type=\"submit\" name=\"button\" value=\"today\"></input></th>";
  echo "<th><input type=\"submit\" name=\"button\" value=\">\"></input></th>";
  echo "</tr>";
  echo "</table>";
	echo "</form>";
}

//////////////////
// main
//////////////////

// formulier afvangen
switch ($_POST['button']){
  case "<":
	  //down
		if ($_POST['month']==1) {$month=12; $year=$_POST['year']-1; $year="0".$year;}
		else {$month = $_POST['month']-1; $year=$_POST['year'];}
		calendar($_POST['day'],$month,$year);
	  break;
	case ">":
	  //up
		if ($_POST['month']==12) {$month=1; $year=$_POST['year']+1;$year="0".$year;}
		else {$month = $_POST['month']+1; $year=$_POST['year'];}
		calendar($_POST['day'],$month,$year);
	  break;
	case "today":
	  calendar(date("d"),date("m"),date("y"));
	  break;
	case "go":
		calendar(substr($_POST['date'],0,2),substr($_POST['date'],3,2),substr($_POST['date'],6,2));
		break;
	default:
	  calendar(date("d"),date("m"),date("y"));
	  break;
}

?>

Reacties

0
Nog geen reacties.