<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
.day_navi{font-size:14pt; font-weight:bold;}
.cal_btn {background-color:#ccc; color:#fff;}
</style>
<?php
/********** 사용자 설정값 **********/
//$startYear = 2007;
//$endYear = date( "Y" ) + 4;
/********** 입력값 **********/
$year = ( $_GET['toYear'] )? $_GET['toYear'] : date( "Y" );
$month = ( $_GET['toMonth'] )? $_GET['toMonth'] : date( "m" );
$doms = array( "일", "월", "화", "수", "목", "금", "토" );
/********** 계산값 **********/
$mktime = mktime( 0, 0, 0, $month, 1, $year ); // 입력된 값으로 년-월-01을 만든다
$days = date( "t", $mktime ); // 현재의 year와 month로 현재 달의 일수 구해오기
$startDay = date( "w", $mktime ); // 시작요일 알아내기
// 지난달 일수 구하기
$prevDayCount = date( "t", mktime( 0, 0, 0, $month, 0, $year ) ) - $startDay + 1;
$nowDayCount = 1; // 이번달 일자 카운팅
$nextDayCount = 1; // 다음달 일자 카운팅
// 이전, 다음 만들기
$prevYear = ( $month == 1 )? ( $year - 1 ) : $year;
$prevMonth = ( $month == 1 )? 12 : ( $month - 1 );
$nextYear = ( $month == 12 )? ( $year + 1 ) : $year;
$nextMonth = ( $month == 12 )? 1 : ( $month + 1 );
// 출력행 계산
$setRows = ceil( ( $startDay + $days ) / 7 );
?>
<div id="closed">
<div id="close_calendar">
<div align="center">
<a href="<?=$_SERVER['PHP_SELF']?>?toYear=<?=$prevYear?>&toMonth=<?=$prevMonth?>" class="btn btn-sm cal_btn">
<i class="fas fa-caret-left"></i>
</a>
<span class="day_navi">
<?=$year?>년 <?=$month?>월
</span>
<a href="<?=$_SERVER['PHP_SELF']?>?toYear=<?=$nextYear?>&toMonth=<?=$nextMonth?>" <?=$_SERVER['PHP_SELF']?>?toYear=<?=$nextYear?>&toMonth=<?=$nextMonth?> class="btn btn-sm cal_btn">
<i class="fas fa-caret-right"></i>
</a>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="padding:5px; ">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr height="20">
<td style="width:85%"> </td>
<td style="border:1px solid #27a9f4;width:20px"> </td>
<td style="font-size:12px;padding-left:5px;padding-right:5px;font-weight:bold">금일</td>
<td style="border:1px solid #ccc;width:20px"> </td>
<td style="font-size:12px;padding-left:5px;padding-right:5px;font-weight:bold">정상운영</td>
<td style="background:#eee;width:20px"> </td>
<td style="font-size:12px;padding-left:5px;padding-right:5px;font-weight:bold">부분운영</td>
<td style="background:#ddd;width:20px"> </td>
<td style="font-size:12px;padding-left:5px;padding-right:5px;font-weight:bold">휴관일</td>
</tr>
</table>
</td>
</tr>
</table>
<div style="padding-top:20px">
<table width="100%">
<colgroup>
<col width="15%">
<col width="14%">
<col width="14%">
<col width="14%">
<col width="14%">
<col width="14%">
<col width="15%">
</colgroup>
<thead>
<tr height="40">
<th style="color:red;border:1px solid #ccc">일요일</th>
<th style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">월요일</th>
<th style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">화요일</th>
<th style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">수요일</th>
<th style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">목요일</th>
<th style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">금요일</th>
<th style="color:blue;border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-top:1px solid #ccc;">토요일</th>
</tr>
</thead>
<tbody>
<? for( $rows = 0; $rows < $setRows; $rows++ ) { ?>
<tr height="120" valign="top">
<?
for( $cols = 0; $cols < 7; $cols++ ){
// 셀 인덱스 만들자
$cellIndex = ( 7 * $rows ) + $cols;
// 이번달이라면
if ( $startDay <= $cellIndex && $nowDayCount <= $days ) {
if($month == date("m") && $nowDayCount+1 == date("d")){ $txt_style = "border:2px solid #27a9f4; "; }else{ $txt_style = "border:1px solid #ccc; "; }
?>
<td align="right" style="padding-right:5px;padding-top:5px; <?= $txt_style ?>">
<? if ( date( "w", mktime( 0, 0, 0, $month, $nowDayCount, $year ) ) == 6 ) { ?>
<b><font color="blue"><?=$nowDayCount++?></font></b>
<? } else if ( date( "w", mktime( 0, 0, 0, $month, $nowDayCount, $year ) ) == 0 ) { ?>
<b><font color="red"><?=$nowDayCount++?></font></b>
<? } else { ?>
<b><?=$nowDayCount++?></b>
<? } ?>
</td>
<?
// 이전달이라면
} else if ( $cellIndex < $startDay ) {
?>
<td align="right" style="padding-right:5px;padding-top:5px;border:1px solid #ccc">
<font color="gray"><b><?=$prevDayCount++?></b></font>
</td>
<?
// 다음달 이라면
} else if ( $cellIndex >= $days ) {
?>
<td align="right" style="padding-right:5px;padding-top:5px;border:1px solid #ccc">
<font color="gray"><b><?=$nextDayCount++?></b></font>
</td>
<? }
}
?>
</tr>
<? } ?>
</tbody>
</table>
</div>
</div>
</div>
'웹 개발 이야기 > php' 카테고리의 다른 글
[PHP] AWS S3 Bucket에 파일 업로드 (0) | 2023.03.16 |
---|---|
[PHP] 스팸글 등록 방지를 위한 아주 간단한 방법 (0) | 2023.03.13 |
[PHP] 인스타그램 피드 가져오기 (Rapid API 이용) (0) | 2023.03.09 |
[PHP] 그누보드 자동 로그인 풀릴 때 (0) | 2023.03.09 |
[PHP] 텍스트자르고 말줄임표 붙이기 (0) | 2023.03.08 |
댓글