1stPHP
カレンダー
ソース
<?php
include "../../d/common.php";
$common = new common;
$common->showHead("カレンダー-".$common->cfg[title],"../../css/main.css","","../../d/count/top.cgi");
$common->showAdd();
$common->smpmenu("カレンダー","./calender.php");
//日時を取得
$date = getdate();
//月の日数を取得
$daycount = date("t");
print "<h3>{$date['year']}年{$date['mon']}月</h3>";
print "<table class=\"main\">\n";
//曜日表示用の配列
$w_ary = array('日', '月', '火', '水', '木', '金', '土');
//曜日を表示
print "<tr>";
foreach ($w_ary as $value) {
print "<th>$value</th>";
}
print "</tr>\n";
//一日の曜日を取得
$w_day = date("w", mktime(0, 0, 0, $date['mon'], 1, $date['year']));
//日曜から一日の曜日までスペースで埋める
print "<tr>";
for ($i = 0; $i < $w_day; $i++) {
echo "<td> </td>";
}
//一日から月の日数までループ
for ($d = 1; $d <= $daycount; $d++) {
//今日なら背景をaqua
if ($d == $date['mday']){
$font = "background:aqua;";
}else{
$font = "";
}
//土曜はblue 日曜はred
if ($w_day == 0) {
$color = "color:red;";
}elseif ($w_day == 6) {
$color = "color:blue;";
}else{
$color = "";
}
//日曜なら<tr>
if ($w_day == 0) {
print "<tr>";
}
//日付を表示
if ($font || $color){
$style="style=\"$font $color\"";
print "<td $style>$d</td>";
}else{
print "<td>$d</td>";
}
//土曜なら</tr>
if ($w_day == 6) {
print "</tr>\n";
}
//曜日を上げる
$w_day++;
//土曜を越えたら0にする
if ($d != $daycount){
if ($w_day > 6) $w_day = 0;
}
}
//最終日の曜日から土曜までスペースで埋める
for ($i = $w_day; $i <= 6; $i++) {
echo "<td> </td>";
}
print "</tr>\n";
print "</table>\n";
$common->showFoot();
?>