<?

  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  $Calendar_Time = $curtime[0];
  $Week_Start = cal_first;
  $Month_Days = date ('t', $Calendar_Time);
  $Month_Start_Day = date ('w', mktime (0, 0, 0, date ('n', $Calendar_Time), 1, date ('Y', $Calendar_Time)));
  $Month_Start_Day = abs ($Month_Start_Day - $Week_Start);
  if ((4 < $Month_Start_Day AND 30 < $Month_Days))
  {
    $long_month = 6;
  }
  else
  {
    $long_month = 5;
  }

  if (1 < date ('n', $Calendar_Time))
  {
    $PREVIOUS = mktime (0, 0, 0, date ('n', $Calendar_Time) - 1, date ('d', $Calendar_Time), date ('Y', $Calendar_Time));
  }
  else
  {
    $PREVIOUS = mktime (0, 0, 0, 12, date ('d', $Calendar_Time), date ('Y', $Calendar_Time) - 1);
  }

  if (date ('n', $Calendar_Time) < 13)
  {
    $NEXT = mktime (0, 0, 0, date ('n', $Calendar_Time) + 1, date ('d', $Calendar_Time), date ('Y', $Calendar_Time));
  }
  else
  {
    $NEXT = mktime (0, 0, 0, 1, date ('d', $Calendar_Time), date ('Y', $Calendar_Time) + 1);
  }

  echo '

<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1" style="background-color:';
  echo cal_bg_color;
  echo ';">
<TR>
	<TD ALIGN=center colspan="7">
		';
  echo '<S';
  echo 'ELECT NAME="cal_month">';
  for ($i = 0; $i < 12; ++$i)
  {
    echo '<OPTION VALUE="';
    echo $month[$i];
    echo '" ';
    if ($month[$i] == $month[date ('n', $Calendar_Time) - 1])
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $month[$i];
    echo '</OPTION>';
  }

  echo '</SELECT>
		';
  echo '<S';
  echo 'ELECT NAME="cal_year">';
  for ($i = 1980; $i <= date ('Y', $curtime[0]); ++$i)
  {
    echo '<OPTION VALUE="';
    echo $i;
    echo '" ';
    if ($i == date ('Y', $Calendar_Time))
    {
      echo 'SELECTED';
    }

    echo '>';
    echo $i;
    echo '</OPTION>';
  }

  echo '</SELECT>
		<input type="button" name="cal_time" value=">">
	</TD>
</TR>

<TR>
';
  for ($i = $Week_Start; $i < 7 + $Week_Start; ++$i)
  {
    $ii = $i;
    if (6 < $ii)
    {
      $ii = 0;
    }

    echo '<TD ALIGN=center BGCOLOR="';
    echo cal_wd_bg_color;
    echo '"><font color="';
    if (($ii == 0 OR $ii == 6))
    {
      echo 'red';
    }
    else
    {
      echo 'black';
    }

    echo '" STYLE="font-family:Tahoma; font-size:9px;">';
    echo $day[$ii];
    echo '</font></TD>';
  }

  echo '</TR>


';
  for ($j = 0; $j < $long_month; ++$j)
  {
    echo '<TR>';
    for ($i = 0; $i < 7; ++$i)
    {
      echo '				<TD ALIGN=center BGCOLOR="';
      if ($i + $j * 7 - $Month_Start_Day + 1 == date ('d', $Calendar_Time))
      {
        echo cal_cd_bg_color;
      }
      else
      {
        if (((($Week_Start == 0 AND $i == 0) OR ($Week_Start == 1 AND $i == 5)) OR 5 < $i))
        {
          echo cal_hd_bg_color;
        }
        else
        {
          echo '#FBFBFB';
        }
      }

      echo '">
				<font color="';
      if ($i + $j * 7 - $Month_Start_Day + 1 == date ('d', $Calendar_Time))
      {
        echo cal_cd_color;
      }
      else
      {
        echo cal_d_color;
      }

      echo '" STYLE="font-family:Tahoma; font-size:11px;">
				';
      $calendar_stamp = mktime (23, 59, 59, date ('n', $Calendar_Time), $i + $j * 7 - $Month_Start_Day + 1, date ('Y', $Calendar_Time));
      if (($row_MIN['tim'] < $calendar_stamp AND $calendar_stamp - 86399 < $curtime[0]))
      {
        echo '					<A HREF="javascript:" STYLE="color:';
        if ($i + $j * 7 - $Month_Start_Day + 1 == date ('d', $Calendar_Time))
        {
          echo cal_cd_color;
        }
        else
        {
          echo 'navy';
        }

        echo '; font-family:tahoma; font-size:10px; font-weight:bold; text-decoration:none;">
			';
      }

      echo '				';
      if (($Month_Start_Day <= $i + $j * 7 AND $i + $j * 7 - $Month_Start_Day + 1 <= $Month_Days))
      {
        echo $i + $j * 7 - $Month_Start_Day + 1;
      }

      echo '				</A></font></TD>';
    }

    echo '</TR>';
  }

  echo '
</TABLE>';
?>
