인터넷정보

PHP 달력 소스

알 수 없는 사용자 2007. 10. 13. 16:23
달력 소스

<?php
/* 빈칸을 출력한다.
* @param $count : 출력할 빈칸(<td> tag) 의 갯수
*/
function tdN($count){
for ($i=0; $i<$count; $i++) {
echo '<td>  </td>';
}
}

/* 달력 출력함수
* @param $month : 해당 월
* @param $year        : 해당 년
*/
function calendar($month, $year, $mode=0){

// 기본 설정값으로 현재 달을 설정
if ($month=="" and $year =="") {
$month=date('m');
$year=date('Y');
}

// 여기서 달과 년도를 바꾼다. 꽁수죠..^^
if ($mode == 1) $month= $month-1;
else if ($mode == 2) $month = $month+1;
else if ($mode == 3) $year = $year-1;
else if ($mode == 4) $year = $year+1;

// 한계치 설정
if ($month == 0) {
$month = 12;
$year = $year-1;
} else if ($month == 13) {
$month = 1;
$year = $year+1;
}

// 변수
$date=01;
$day=01;
$off=0;
$td_end = "</td>";
$td_normal = "<td> ";
$td_head = "<td align=center height='40' width='14%' bgcolor='#FFEBCA'>";
$td_show = "<td align=center height='40' width='14%' bgcolor='#FCFBF3' onMouseOut=this.style.backgroundColor='' onMouseOver=this.style.backgroundColor='#F6F0F3' style='word-break:break-all;padding:0px;' align='center'>";

// header
echo "<meta http-equiv=Content-Type content=text/html; charset=EUC-KR>";
echo "<style type=\"text/css\">";
echo "<!--";
echo "td { font-weight:600; font-family: \"굴림\", \"굴림체\", \"바탕\"; font-size: 9pt; line-height: 16px}";
echo "a:link {font-size:10pt; font-family:굴림; text-decoration:none; color:000000;}";
echo "a:visited {font-size:10pt; font-family:굴림; text-decoration:none; color:000000;}";
echo "a:hover {font-size:10pt; font-family:굴림; text-decoration:none; color:0000ff;}";
echo "a:active {font-size:10pt; font-family:굴림; text-decoration:none; color:0000ff;}";
echo "-->";
echo "</style>";

// 전월, 이월 링크
echo "<table border=0 align=center cellpadding=3 >";
echo "<tr><td> </td></tr>";
echo "<tr bgcolor='#ffffff' ><td align=center>";
echo "<a href='$PHP_SELF?year=$year&month=$month&mode=3'>▼</a>";
echo "<a href='$PHP_SELF?year=$year&month=$month&mode=1'>◀</a>";
echo $year.'년 '.$month.'월';
echo "<a href='$PHP_SELF?year=$year&month=$month&mode=2'>▶</a>";
echo "<a href='$PHP_SELF?year=$year&month=$month&mode=4'>▲</a>";
echo "</td></tr></table>";

// table
echo "<table bgcolor='#ffffff' cellspacing=0 cellpadding=1 bordercolorlight='#c0c0c0' bordercolordark='#ffffff' width='600' border=1 align='center'>";
echo "<tr>";

// 제목 줄 출력
echo "$td_head<font class=ver9 color='red'><b>일<b></font>$td_end";
echo "$td_head<b>월</b></font>$td_end";
echo "$td_head<font class=ver9 color='black'><b>화</b></font>$td_end";
echo "$td_head<font class=ver9 color='black'><b>수</b></font>$td_end";
echo "$td_head<font class=ver9 color='black'><b>목</b></font>$td_end";
echo "$td_head<font class=ver9 color='black'><b>금</b></font>$td_end";
echo "$td_head<font class=ver9 color='#a6a6a9'><b>토</b></font>$td_end";
echo "<tr>";

// 이번달의 마지막 날을 $date에 저장한다.
while (checkdate($month,$date,$year)):
$date++;
endwhile;

// $day 를 $date(이번달의 마지막날)까지 증가하면서 출력한다.
while ($day<$date):
// 첫번째 날이 무슨요일인지 확인하여 앞의 빈칸과 같이 출력한다.
if ($day == '01') {
$temp = date("w", mktime(0,0,0,$month,$day,$year));
echo tdN($temp);
echo $td_show.$day.$td_end;
$off = $temp+1;
} else // 그외 경우는 날짜만 출력한다.
echo $td_show.$day.$td_end;

// $day와 $off 증가
$day++;
$off++;

// 요일($off)가 토요일(7)까지 가면 줄을 바꾼다.
if ($off>7) {
echo "</tr><tr>";
$off='01';
}
endwhile;

// 마지막 남은 빈칸들 출력
while($off<8 && $off!='01'):
$off++;
echo "$td_normal$td_end";
endwhile;

// tailer
echo "</tr></table>";
}
?>
<? echo calendar($month,$year,$mode); ?>
반응형