Código fuente de 'Calendario del mes 4.php'

<html>
<head>
<title>Calendario del mes 4</title>
</head>
<body style="font-family: Arial; font-size: 9pt">

<center><b><font face="Arial" size="3">Calendario del mes 4</font></b><br><br>
<br>


<?php

###########################################################################
# configuration
###########################################################################

# display date or month calendar?
# 0 - Date
# 1 - Month
$Cal = 1;

# display in what language?
# 0 - Chinese
# 1 - English
# 2 - German (Friedemann Lindenthal)
# 3 - French (Jean-Francois Rouault)
$Lang = 1;

###########################################################################
# main programme
###########################################################################

# get argument, if any
if (isset($_GET['Cal']))  {$Cal = $_GET['Cal'];}
if (isset($_GET['Lang'])) {$Lang = $_GET['Lang'];}

$TimeNow = localtime(time(), 1);
if (isset($_GET['Year'])) {
  $Year = $_GET['Year']-1900;
} else {
  $Year = $TimeNow['tm_year'];
}
if (isset($_GET['Month'])) {
  $Month = $_GET['Month'];
} else {
  $Month = $TimeNow['tm_mon']+1;
}
if (isset($_GET['Date'])) {
  $Date = $_GET['Date'];
} else {
  $Date = $TimeNow['tm_mday'];
}

# define constants
$MonthDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (isLeap($Year+1900)) {$MonthDays[1]=29;}

$Month0 = array('¤@¤ë', '¤G¤ë', '¤T¤ë', '¥|¤ë', '¤­¤ë', '¤»¤ë', '¤C¤ë',
                '¤K¤ë', '¤E¤ë', '¤Q¤ë', '¤Q¤@¤ë', '¤Q¤G¤ë');
$Month1 = array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio',
                'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
$Month2 = array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
                'Agosto', 'Septiembre', 'Oktober', 'Noviembre', 'Dezember');
$Month3 = array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet',
                'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
$Day0   = array('¬P´Á¤é', '¬P´Á¤@', '¬P´Á¤G', '¬P´Á¤T', '¬P´Á¥|', '¬P´Á¤­', '¬P´Á¤»');
$Day1   = array('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado');
$Day2   = array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
$Day3   = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
$Week00 = '²Ä';
$Week01 = '¶g';
$Week1  = 'Semana';
$Week2  = 'Woche';
$Week3  = 'Semaine';

$Space = '&nbsp;';

# table cell space packing for Netscape browser only
if ( preg_match('/Mozilla/i', getenv('HTTP_USER_AGENT')) &&
     (! preg_match('/MSIE/i', getenv('HTTP_USER_AGENT'))) ) {
  $Pack = '<FONT STYLE="font-size:1pt">&nbsp;</FONT>';
} else {
  $Pack = '';
}

# get time
$aTime = localtime(mktime(0,0,0,$Month,$Date,$Year));

# construct calendar
if ($Cal==0) {
  $out = calDate();
} else if ($Cal==1) {
  $out = calMonth();
}

# show output
print $out;

###########################################################################
# functions
###########################################################################

function calDate() {
  global $Lang;
  global $Month0, $Day0, $Week00, $Week01;
  global $Month1, $Day1, $Week1;
  global $Month2, $Day2, $Week2;
  global $Month3, $Day3, $Week3;
  global $Pack;
  global $aTime;

  # define colours & constants
  $Head1Col = 'orange';                # Background colour for header
  $Head2Col = 'peru';                  # Shadow colour for header
  if ($aTime[6]==0) {                  # Text colour
    $ForeCol = 'red';
  } else {
    $ForeCol = 'green';
  }
  $BackCol   = 'lightyellow';          # Background colour
  $ShadowCol = 'silver';               # Shadow colour

  # construct time components
  if ($Lang==0) {                      # Chinese
    $Year  = $aTime[5]+1900;
    $Month = $Month0[$aTime[4]];
    $Date  = $aTime[3];
    $Day   = $Day0[$aTime[6]];
    if ($aTime[7]<=$aTime[6]) {
      $Week = $Week00.' 0 '.$Week01;
    } else {
      $Week = $Week00.' '.ceil(($aTime[7]-$aTime[6])/7).' '.$Week01;
    }

    $FontSize = '-2';
  } else if ($Lang==1) {               # English
    $Year  = $aTime[5]+1900;
    $Month = substr($Month1[$aTime[4]],0,3);
    $Date  = $aTime[3];
    $Day   = $Day1[$aTime[6]];
    if ($aTime[7]<=$aTime[6]) {
      $Week = $Week1.' 0';
    } else {
      $Week = $Week1.' '.ceil(($aTime[7]-$aTime[6])/7);
    }

    $FontSize = '+0';
  } else if ($Lang==2) {               # German
    $Year  = $aTime[5]+1900;
    $Month = substr($Month2[$aTime[4]],0,3);
    $Date  = $aTime[3];
    $Day   = $Day2[$aTime[6]];
    if ($aTime[7]<=$aTime[6]) {
      $Week = $Week2.' 0';
    } else {
      $Week = $Week2.' '.ceil(($aTime[7]-$aTime[6])/7);
    }

    $FontSize = '+0';
  } else if ($Lang==3) {               # French
    $Year  = $aTime[5]+1900;
    $Month = substr($Month3[$aTime[4]],0,3);
    $Date  = $aTime[3];
    $Day   = $Day3[$aTime[6]];
    if ($aTime[7]<=$aTime[6]) {
      $Week = $Week3.' 0';
    } else {
      $Week = $Week3.' '.ceil(($aTime[7]-$aTime[6])/7);
    }

    $FontSize = '+0';
  }

  # construct output
  $DateCal  = '';
  $DateCal .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD WIDTH=\"2\"  HEIGHT=\"6\" BGCOLOR=\"$Head1Col\">$Pack</TD>\n";
  $DateCal .= "<TD WIDTH=\"36\" BGCOLOR=\"$Head1Col\">$Pack</TD>\n";
  $DateCal .= "<TD WIDTH=\"36\" BGCOLOR=\"$Head1Col\">$Pack</TD>\n";
  $DateCal .= "<TD WIDTH=\"2\"  BGCOLOR=\"$Head1Col\">$Pack</TD>\n";
  $DateCal .= "<TD WIDTH=\"3\"  BGCOLOR=\"$Head2Col\">$Pack</TD>\n";
  $DateCal .= "</TR>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD HEIGHT=\"18\" BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\" ALIGN=\"LEFT\"><FONT FACE=\"Arial\" COLOR=\"$ForeCol\">$Year</FONT></TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\" ALIGN=\"RIGHT\"><FONT FACE=\"Arial\" SIZE=\"$FontSize\" COLOR=\"$ForeCol\">$Month</FONT></TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$ShadowCol\">$Pack</TD>\n";
  $DateCal .= "</TR>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD HEIGHT=\"42\" BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TH BGCOLOR=\"$BackCol\" ALIGN=\"CENTER\" COLSPAN=\"2\"><FONT FACE=\"Arial\" SIZE=\"+3\" COLOR=\"$ForeCol\">$Date</FONT></TH>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$ShadowCol\">$Pack</TD>\n";
  $DateCal .= "</TR>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD HEIGHT=\"12\" BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$ForeCol\" ALIGN=\"CENTER\" COLSPAN=\"2\"><FONT FACE=\"Arial\" SIZE=\"-2\" COLOR=\"$BackCol\">$Day</FONT></TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$ShadowCol\">$Pack</TD>\n";
  $DateCal .= "</TR>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD HEIGHT=\"18\" BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\" ALIGN=\"CENTER\" COLSPAN=\"2\"><FONT FACE=\"Arial\" SIZE=\"-2\" COLOR=\"$ForeCol\">$Week</FONT></TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$BackCol\">$Pack</TD>\n";
  $DateCal .= "<TD BGCOLOR=\"$ShadowCol\">$Pack</TD>\n";
  $DateCal .= "</TR>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "<TD HEIGHT=\"3\" BGCOLOR=\"$ShadowCol\" COLSPAN=\"5\">$Pack</TD>\n";
  $DateCal .= "<TR>\n";
  $DateCal .= "</TABLE>\n";

  return($DateCal);
}

function calMonth() {
  global $Lang;
  global $MonthDays;
  global $Month0, $Day0;
  global $Month1, $Day1;
  global $Month2, $Day2;
  global $Month3, $Day3;
  global $Space, $Pack;
  global $aTime;

  # define colours & constants
  $SunCol    = 'red';                  # Text colour for sundays
  $DayCol    = 'black';                # Text colour for others
  $WeekBGCol = 'lightblue';            # Background colour for week header
  $NumBGCol  = 'lightcyan';            # Background colour for others
  $TodayCol  = 'lightyellow';          # Background highlight colour for today
  $BorderCol = 'skyblue';              # Border colour

  $Width = 30;

  # construct time components
  if ($Lang==0) {                      # Chinese
    $Year  = $aTime[5]+1900;
    $Month = $Month0[$aTime[4]];

    $D0 = substr($Day0[0],4,2); $D1 = substr($Day0[1],4,2);
    $D2 = substr($Day0[2],4,2); $D3 = substr($Day0[3],4,2);
    $D4 = substr($Day0[4],4,2); $D5 = substr($Day0[5],4,2);
    $D6 = substr($Day0[6],4,2);
  } else if ($Lang==1) {               # English
    $Year  = $aTime[5]+1900;
    $Month = $Month1[$aTime[4]];

    $D0 = substr($Day1[0],0,3); $D1 = substr($Day1[1],0,3);
    $D2 = substr($Day1[2],0,3); $D3 = substr($Day1[3],0,3);
    $D4 = substr($Day1[4],0,3); $D5 = substr($Day1[5],0,3);
    $D6 = substr($Day1[6],0,3);
  } else if ($Lang==2) {               # German
    $Year  = $aTime[5]+1900;
    $Month = $Month2[$aTime[4]];

    $D0 = substr($Day2[0],0,2); $D1 = substr($Day2[1],0,2);
    $D2 = substr($Day2[2],0,2); $D3 = substr($Day2[3],0,2);
    $D4 = substr($Day2[4],0,2); $D5 = substr($Day2[5],0,2);
    $D6 = substr($Day2[6],0,2);
  } else if ($Lang==3) {               # French
    $Year  = $aTime[5]+1900;
    $Month = $Month3[$aTime[4]];

    $D0 = substr($Day3[0],0,2); $D1 = substr($Day3[1],0,2);
    $D2 = substr($Day3[2],0,2); $D3 = substr($Day3[3],0,2);
    $D4 = substr($Day3[4],0,2); $D5 = substr($Day3[5],0,2);
    $D6 = substr($Day3[6],0,2);
  }

  # get weekday of day1
  $wday = $aTime[6]-($aTime[3]-1)%7;
  if ($wday<0) {$wday+=7;}

  # construct table header
  $MonthCal  = '';
  $MonthCal .= "<TABLE BGCOLOR=\"$NumBGCol\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n";
  $MonthCal .= "<TR BGCOLOR=\"$BorderCol\">\n";
  $MonthCal .= "<TH COLSPAN=\"9\">$Pack</TH>\n";
  $MonthCal .= "</TR>\n";
  $MonthCal .= "<TR>\n";
  $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
  $MonthCal .= "<TH COLSPAN=\"7\"><FONT COLOR=\"$DayCol\">$Year$Space$Space$Space$Month</FONT></TH>\n";
  $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
  $MonthCal .= "</TR>\n";
  $MonthCal .= "<TR BGCOLOR=\"$WeekBGCol\">\n";
  $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$SunCol\">$D0</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D1</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D2</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D3</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D4</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D5</FONT></TH>\n";
  $MonthCal .= "<TH WIDTH=\"$Width\"><FONT COLOR=\"$DayCol\">$D6</FONT></TH>\n";
  $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
  $MonthCal .= "</TR>\n";

  # construct pre-day1 table cells
  for ($i=0; $i<=($wday-1); $i++) {
    if ($i==0) {
      $MonthCal .= "<TR>\n";
      $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
    }
    $MonthCal .= "<TH>$Space</TH>\n";
  }

  # construct day1->dayLast table cells
  for ($i=1; $i<=$MonthDays[$aTime[4]]; $i++) {
    if ($i==$aTime[3]) {
      $j=" BGCOLOR=\"$TodayCol\"";
    } else {
      $j='';
    }

    if ($wday==0) {
      $MonthCal .= "<TR>\n";
      $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
      $MonthCal .= "<TH$j><FONT COLOR=\"$SunCol\">$i</FONT></TH>\n";
    } else if ($wday==6) {
      $MonthCal .= "<TH$j><FONT COLOR=\"$DayCol\">$i</FONT></TH>\n";
      $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
      $MonthCal .= "</TR>\n";
    } else {
      $MonthCal .= "<TH$j><FONT COLOR=\"$DayCol\">$i</FONT></TH>\n";
    }

    $wday++;
    if ($wday==7) {$wday=0;}
  }

  # construct post-dayLast table cells
  if ($wday!=0) {
    for ($i=$wday; $i<=6; $i++) {
      $MonthCal .= "<TH>$Space</TH>\n";
      if ($i==6) {
        $MonthCal .= "<TH BGCOLOR=\"$BorderCol\">$Pack</TH>\n";
        $MonthCal .= "</TR>\n";
      }
    }
  }

  # construct table footer
  $MonthCal .= "<TR BGCOLOR=\"$BorderCol\">\n";
  $MonthCal .= "<TH COLSPAN=\"9\">$Pack</TH>\n";
  $MonthCal .= "</TR>\n";
  $MonthCal .= "</TABLE>\n";

  return($MonthCal);
}

function isLeap($y) {
  if (($y%4==0)&&($y%100!=0)||($y%400==0)) {
    return(1);
  } else {
    return(0);
  }
}

?>

</center>
</body>
</html>