<?
$format
=$_POST['format']?$_POST['format']:"year";

$year=$_POST['year']?$_POST['year']:date("Y");
$month=$_POST['month']?$_POST['month']:date("m");
$lang=$_POST['lang']?$_POST['lang']:"fr";
$mondayFirst=$_POST['mondayFirst']=="on"?"1":"0";
$weekpre=$_POST['weekpre']?$_POST['weekpre']:"Week ";
$weekprewiki=$_POST['weekprewiki']=="on"?"1":"0";
$showweek=$_POST['showweek']=="on"?"1":"0";
$weekpost=$_POST['weekpost']=="on"?"1":"0";
$short=$_POST['short']?$_POST['short']:"3";
$holiday=$_POST['holiday']=="on"?"1":"0";
$holidayback=$_POST['holidayback']=="on"?"1":"0";

$weekendcolor=$_POST['weekendcolor']?$_POST['weekendcolor']:"DEDEAD";
$holidaycolor=$_POST['holidaycolor']?$_POST['holidaycolor']:"FDBD20";

$weekend1=0;$weekend2=6;

if (
$lang=="fr") {
 
$monthnames = array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aoűt","Septembre","Octobre","Novembre","Decembre");
 
$alldays = array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi');
 
$holidays = array("1-1","1-5","5-5","8-5","16-5","14-7","15-8","1-11","11-11","25-12");
} elseif (
$lang=="en") {
 
$monthnames = array("January","February","March","April","May","June","July","August","September","October","November","December");
 
$alldays = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
 
$holidays = array("4-7","25-12");
} elseif (
$lang=="it") {
 
$monthnames = array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
 
$alldays = array('Domenica','Lunedý','Martedý','Mercoledý','Giovedý','Venerdý','Sabato');
 
$holidays = array("1-1","25-12");
} elseif (
$lang=="de") {
 
$monthnames = array("Januar","Februar","Mńrz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
 
$alldays = array('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag');
 
$holidays = array("1-1","25-12");
} elseif (
$lang=="nl") {
 
$monthnames = array("Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December");
 
$alldays = array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag');
 
$holidays = array("1-1","25-12");
}

if (
$mondayFirst==1) {
 
array_push($alldays,array_shift($alldays));
 
$weekend1=5;
}
function 
short($str) {global $short; return substr($str0$short);}
?>

<form method=post action="?">
<h4>Main parameters :</h4>
Year : <input type="text" name=year size="4" value="<?=$year?>"/> Month : <input type="text" name=month size="2" value="<?=$month?>" /><br/>
<h4>Week and day format :</h4>
Monday First ? <input type="checkbox" name="mondayFirst" <?=$mondayFirst=="1"?"checked":"";?> /><br/>
Show Week number : <input type="checkbox" name="showweek" <?=$showweek=="1"?"checked":"";?> />
Week prefix : <input type="text" name=weekpre value="<?=$weekpre?>"/>
Wikify week ? <input type="checkbox" name="weekprewiki" <?=$weekprewiki=="1"?"checked":"";?> />
Use year postfix for week ?<input type="checkbox" name="weekpost" <?=$weekpost=="1"?"checked":"";?> /><br/>
Day name lenght : <input type="text" name=short size="4" value="<?=$short?>"/><br/>
<h4>Holidays :</h4>
Show holidays ? <input type="checkbox" name="holiday" <?=$holiday=="1"?"checked":"";?> />
<h4>Display parameters</h4>
Weekend color <input type="text" size="6" name=weekendcolor value="<?=$weekendcolor?>"/><br/>
Holidays color <input type="text" size="6" name=holidaycolor value="<?=$holidaycolor?>"/>
Show holidays with background color ? <input type="checkbox" name="holidayback" <?=$holidayback=="1"?"checked":"";?> />
<h4>Output format :</h4>
<select name="format">
<option value="year" <?=$format=="year"?"selected":"";?>>Year
<option value="month" <?=$format=="month"?"selected":"";?>>Month
</select>
Language :
<select name="lang">
<option value="fr" <?=$lang=="fr"?"selected":"";?>>Franšais
<option value="en" <?=$lang=="en"?"selected":"";?>>English
<option value="it" <?=$lang=="it"?"selected":"";?>>Italiano
<option value="de" <?=$lang=="de"?"selected":"";?>>German
<option value="nl" <?=$lang=="nl"?"selected":"";?>>Dutch
</select><br/>

<input type="submit" value="Submit"/>
</form>

<?
function nf($num) {
 if (
$num<=9) return $num";
 else return 
$num;
}

function 
cal($month,$year) {
 global 
$alldays,$monthnames,$mondayFirst,$weekpre,$short,$weekprewiki,$weekpost,$weekendcolor,$weekend1,$weekend2,$holidays,$holidaycolor,$holiday,$holidayback,$showweek;
 
$calresult=array();
 
$calresultline=0;

 
$dayone date("w",mktime(1,1,1,$month,1,$year));
 if (
$mondayFirst==1) { $dayone-=1; if ($dayone==-1$dayone=6;};
 
$numdays date("t",mktime(1,1,1,$month,1,$year));
 
$alldaysshort=array_map("short"$alldays);


$monthdisplay=$monthnames[$month-1];
if (
$showweek==1$calresult[$calresultline]="|>"; else $calresult[$calresultline]="";
$calresult[$calresultline].="|>|>|>|>|>|>| !$monthdisplay |";
$calresultline++;
if (
$showweek==1$calresult[$calresultline].="|Week|"; else $calresult[$calresultline].="|";
for (
$d=0;$d<=6;$d++)
 
$calresult[$calresultline].=" ".$alldaysshort[$d]." |";
$calresultline++;
//display blank days as nbsp's
if ($showweek==1) { $calresult[$calresultline].= "|".($weekprewiki==1?"[[":"").$weekpre.date("W",mktime(1,1,1,$month,1,$year)).($weekpost==1?"-".$year:"").($weekprewiki==1?"]]":""); }
$calresult[$calresultline].="|";
for (
$i 0$i $dayone-1$i++) {
  
$calresult[$calresultline].= ">|";
}
if (
$i$dayone) { $calresult[$calresultline].= "!|"$i++;}
//display days
for ($zz 1$zz <= $numdays$zz++) {
 if (
$i >= 7) {
  
$calresultline++;
  if (
$showweek==1) {
   
$calresult[$calresultline].= "|".($weekprewiki==1?"[[":"").$weekpre.date("W",mktime(1,1,1,$month,$zz,$year)).($weekpost==1?"-".$year:"").($weekprewiki==1?"]]":"");
  }
  
$calresult[$calresultline].="|";
  
$i=0;
  }

 if (
$holiday==1&&$holidayback==1&&in_array($zz."-".$month$holidays))
  
$calresult[$calresultline].= "bgcolor(#".$holidaycolor."):";
 elseif (
$i==$weekend1||$i==$weekend2)
  
$calresult[$calresultline].= "bgcolor(#".$weekendcolor."):";

 
$calresult[$calresultline].= " ";

 if (
$holiday==1&&$holidayback==0&&in_array($zz."-".$month$holidays))
  
$calresult[$calresultline].= "@@color(#".$holidaycolor."):".$zz."@@ |";
 else
  
$calresult[$calresultline].= $zz." |";

 
$i++;
}
$create_emptys - (($dayone $numdays) % 7);
if (
$create_emptys == 7) { $create_emptys 0; }
//display blank remaining cells
if ($create_emptys != 0) {
 for(
$i=0;$i<$create_emptys-1;$i++)
  
$calresult[$calresultline].= ">|";
 if (
$i$create_emptys) { $calresult[$calresultline].= "!|"$i++;}
}
return 
$calresult;
}
$c =array();
for (
$h=1;$h<=12;) {
   
$at array_values(cal($h++,$year));
   
$bt array_values(cal($h++,$year));
   
$diff=count($at)-count($bt);
   if (
$diff==0) {
    foreach(
$at as $key=>$avalarray_push($c,$at[$key]."!".$bt[$key]);
   }
   if (
$diff>0) {
    for(
$i=0;$i<$diff;$i++) array_push($bt,"|>|>|>|>|>|>|>|!|");
    foreach(
$at as $key=>$avalarray_push($c,$at[$key]."!".$bt[$key]);
   }
   if (
$diff<0) {
    for(
$i=0;$i<-$diff;$i++) array_push($at,"|>|>|>|>|>|>|>|!|");
    foreach(
$at as $key=>$avalarray_push($c,$at[$key]."!".$bt[$key]);
   }

}

$result="";
if (
$format=="year") {
 
$result.="| Agenda ".$year." |c\n";
 foreach(
$c as $key=>$val$result.=$val."\n";
} elseif (
$format=="month") {
 
$c=cal($month,$year);
 foreach(
$c as $key=>$val$result.=$val."\n";
}

echo 
"<hr/>";
echo 
"<PRE>$result</PRE>";


?>