Xpoint
   [напомнить пароль]

Простой календарь в "русском" формате

К моему большому удивлению найти готовый скрипт PHP календаря в "русском" формате (первый день недели — понедельник, а не воскресенье) оказалось довольно непросто.

Устав искать, я переделал чужую "буржуйскую" версию под себя.

Вот код — он сыроват, но работоспособен. Фичи: подсветка текущего дня.

<?php
#######################
##     Настройки     ##
#######################

$text_bgcolor = '#FFFFFF';
$highlight_today = 1;
$today_bgcolor = '#660000';
$today_txtcolor = '#FFFFFF';
$image_dir = '.';
$image_name = '1pix.gif';
$column_width = 22;

#######################
##      Функции      ##
#######################

// Generate the Stop Value (returns the number of days in the month)
function genSet_Stop($month,$year) {
    if ($month == '12') {
    $month = 1;
    $year++;
    }
    else $month++;

    $stop = date("d", mktime(0,0,0,$month,0,$year));
    return $stop;
}

// Generates the information to be displayed
function genCalendar_Month($month,$year,$stop,$column_width) {
global $PHP_SELF, $today_bgcolor, $today_txtcolor, $highlight_today, $image_dir, $image_name;

$month=intval($month);

if ($month == 12) {
    $prev_month = $month - 1;
    $prev_year = $year;
    $next_month = 1;
    $next_year = $year + 1;
}
elseif ($month == 1) {
    $prev_month = 12;
    $prev_year = $year - 1;
    $next_month = $month + 1;
    $next_year = $year;
}
else {
    $prev_month = $month - 1;
    $prev_year = $year;
    $next_month = $month + 1;
    $next_year = $year;
}

$Month_Text['1'] = 'Январь';
$Month_Text['2'] = 'Февраль';
$Month_Text['3'] = 'Март';
$Month_Text['4'] = 'Апрель';
$Month_Text['5'] = 'Май';
$Month_Text['6'] = 'Июнь';
$Month_Text['7'] = 'Июль';
$Month_Text['8'] = 'Август';
$Month_Text['9'] = 'Сентябрь';
$Month_Text['10'] = 'Октябрь';
$Month_Text['11'] = 'Ноябрь';
$Month_Text['12'] = 'Декабрь';

        $string = '<tr>' .
                  '<td colspan="1" align="right" valign="center"><a href="'."$PHP_SELF?month=$prev_month&year=$prev_year&mode=month".'" class="cal_nav">&lt;&lt;</a></td>' .
          '<td colspan="5" align="center"><b>'.$year.' '.$Month_Text[$month].'</b></td>' .
          '<td colspan="1" align="left" valign="center"><a href="'."$PHP_SELF?month=$next_month&year=$next_year&mode=month".'" class="cal_nav">&gt;&gt;</a></td>' .
          '</tr>' .

          '<tr><td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Пн<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Вт<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Ср<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Чт<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Пт<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Сб<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td>'."\n" .
          '<td width="'.$column_width.'" bgcolor="#660000" align="center"><font color="#FFFFFF">Вс<img src="'.$image_dir.'/'.$image_name.'" height="1" width="'.$column_width.'" border="0" /></font></td></tr>'."\n" .
          '<tr>';

    $start = date("w",mktime(0,0,0,$month,1,$year)) - 1;
    if ($start == -1) $start = 6;
    for ($i=0; $i<$start; $i++)   $string .= '<td>&nbsp;</td>';

    $frame = $start - 1;

    for ($i=1; $i<=$stop; $i++) {
        $day = mktime(0,0,0,date("m"),$i,date("Y"));
        $frame++;
        if($frame > 6) {
            $string .= "</tr>\n";
            if($i < $stop) $string .= '<tr>';
            $frame = 0;
        }

        if($month == date("m", $day) && $year == date("Y", $day) && date("d") == date("d", $day) && $highlight_today == 1) {
            $string .= "<td width=\"$column_width\" bgcolor=\"$today_bgcolor\" align=\"center\">" .
                       "<b><font color=\"$today_txtcolor\">$i</font></b></td>";
            continue;
        }

        if ($frame == 5 || $frame == 6) {
            $string .= "<td width=\"$column_width\" align=\"center\">" .
                       "<font color=\"#996666\"><b>$i</b></font></td>";
        }

        else {
            $string .= "<td width=\"$column_width\" align=\"center\">" .
                       "<b>$i</b></td>";
        }
    }

    for ($i=1; $frame < 6; $frame++) $string .= "<td>&nbsp;</td>";

    if ($frame < 6) $string .= "</tr>";
    return $string;
}

######################
## Вывод Скрипта    ##
######################

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru">
<head>
<title>Календарь</title>
<style>
td { font-family:arial; font-size:7pt; }
a.cal_nav { text-decoration:none; }
a.cal_nav:hover { text-decoration:underline; }
</style>
<meta http-equiv="content-type" content="text/html; charset=windows-1251" />
</head>
<body bgcolor="#FFFFFF">
<center>
<table width="150" cellpadding="1" cellspacing="0">
<tr>
<td>
<table width="150" cellpadding="0" cellspacing="1" border="0">
<?php

if (@!$month) {
    $month = date("m");
    $year = date("Y");
}
$day_number = genSet_Stop($month,$year);
print $mid_html = genCalendar_Month($month, $year, $day_number, $column_width);

?>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
Powered by POEM™ Engine Copyright © 2002-2005