 |
|
|  |
|
 |
15년 전 |
date함수와 mktime함수를 이용한 간단한 달력입니다.
자세한 내용은 소스를 참조하세요... ^^*
=======================================================
<?
# 현재 페이지 URL
$php_url = "cal.php";
# 날짜별 색상값
$col_sun = "red";
$col_sat = "blue";
$col_day = "balck";
$col_today = "#B6CADE";
# 각 칸의 넓이 높이
$day_width = 80;
$day_height = 80;
$last_line = false; # 마지막 주인가?
# 넘어온 날자값 받기
$cur_year = $_REQUEST['year']; # 년도값
$cur_mon = $_REQUEST['mon']; # 월값
$cur_day = date("d"); # 일값
# 날짜값 받아오기 - 넘어온값이 없으면 오늘 날짜값 호출
if($cur_year == "" || $cur_mon == "") {
$cur_year = date("Y");
$cur_mon = date("m");
}
# 이전달 다음달 값가져오기
$prev_mon = sprintf("%02d", $cur_mon - 1);
if($prev_mon == 0) {
$prev_mon = 12;
$prev_year = $cur_year - 1;
}
else {
$prev_year = $cur_year;
}
$next_mon = sprintf("%02d", $cur_mon + 1);
if($next_mon > 12) {
$next_mon = "01";
$next_year = $cur_year + 1;
}
else {
$next_year = $cur_year;
}
# 해당월 첫째날 요일값 가져오기: 예) 일요일-0 토요일-6
$first_week = date("w", mktime(0, 0, 0, $cur_mon, 1, $cur_year));
# 해당월 마지막 날짜값 가져오기 예) 28, 30, 31
$last_day = date("t", mktime(0, 0, 0, $cur_mon, 1, $cur_year));
# 요일 배열
$arr_week = array("일", "월", "화", "수", "목", "금", "토");
echo "<div align=center>\n";
// 날짜표시 및 월이동부분 출력
$tbl_width = $day_width*7;
echo "<table border=0 width=$tbl_width>";
echo "<tr>";
echo "<td width=130><a href=$php_url?year=$prev_year&mon=$prev_mon>이전달</a></td>";
echo "<td align=center>$cur_year 년 $cur_mon 월</td>";
echo "<td width=130 align=right><a href=$php_url?year=$next_year&mon=$next_mon>다음달</a></td>";
echo "</tr>\n";
echo "</table>\n";
echo "<br>\n";
echo "<table border=1>";
echo "<tr>";
foreach($arr_week as $week) {
$week_col = ($week == "일") ? $col_sun : (($week == "토") ? $col_sat : $col_day);
echo "<td align=center style='color:$week_col'>$week</td>";
}
# 임시 일자
$tmp_day = 1;
# 각 주별로 출력
for($cnt_line = 1; $cnt_line <= 6; $cnt_line++) {
echo "<tr>";
for($cnt_week = 0; $cnt_week < 7; $cnt_week++) {
$week_col = ($cnt_week == 0) ? $col_sun : (($cnt_week == 6) ? $col_sat : $col_day);
# 블렝크 출력 체킹 (1. 첫주면서 철일의 요일 이전, 2. 마지막 일자값이 지난경우)
if(($cnt_line == 1 && $cnt_week < $first_week) || $tmp_day > $last_day) {
$day_val = " ";
}
else {
$day_val = $tmp_day;
$tmp_day++;
}
# 오늘 날짜 스타일 적용 폰트굵게 배경색 지정
$style_day = ($cur_year == date("Y") && $cur_mon == date("m") && $day_val == $cur_day) ? "font-weight:bold;background-color:$col_today" : "";
echo "<td width=$day_width height=$day_height align=center style='color:$week_col;$style_day'>$day_val</td>";
}
echo "</tr>\n";
# 마지막 주 체킹
if($tmp_day > $last_day) {
break;
}
}
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
?>
|
|
추천 : 933 |
추천
목록
|
|
|  |
|