<?

if ( !$year ) {
	$intThisYear  = date("Y");

}else{
	$intThisYear = $year;
}

if ( !$month ) {
	$intThisMonth  =  sprintf('%02s',date("m"));
}else{
	$intThisMonth =  sprintf('%02s',$month);
}

$intThisMonth2 = sprintf('%02s',$intThisMonth); //1~9숫자 앞에 0붙이기



$gday			= date("d"); //오늘날짜
$datFirstDay	= date("w", mktime(0,0,0,$intThisMonth,1,$intThisYear)); //요일 구하기 (num)
$intLastDay		= date("t", mktime(0,0,0,$intThisMonth,1,$intThisYear)); //마지막날 구하기
$jucnt			= ceil(($datFirstDay+$intLastDay)/7);



// 이전, 다음 만들기 
$prevYear		= ( $intThisMonth == 1 )? ( $intThisYear - 1 ) : $intThisYear; 
$prevMonth		= ( $intThisMonth == 1 )? 12 : ( $intThisMonth - 1 ); 

$nextYear		= ( $intThisMonth == 12 )? ( $intThisYear + 1 ) : $intThisYear; 
$nextMonth		= ( $intThisMonth == 12 )? 1 : ( $intThisMonth + 1 ); 


?>


<?include("top.php"); //상단파일?>


<!-- 리스트 -->
<div id="board" style="width:<?=$a_width?>;">
	<?if($is_ad_cms == "Y"){?>
	<form id= "frm_list" action=""  method='post'>
	<div>
		<input type="hidden" name="status" />
		<input type="hidden" name="a_num" value="<?=$a_num?>" />

		<input type="hidden" id="chk_all" name="chk_all" /><!-- 전체체크 사용하려구.. -->
		
	</div>
	<?}?>
	

	<div class="top">
		<div class="cal_top">
			<a class="sp sp_b_prev2" href='<?=$_SERVER['PHP_SELF']?>?a_num=<?=$a_num?>&amp;year=<?=$prevYear-1?>&amp;month=<?=$intThisMonth?>' onmouseover="this.className='sp sp_b_prev2_on'" onfocus="this.className='sp sp_b_prev2_on'" onmouseout="this.className='sp sp_b_prev2'" onblur="this.className='sp sp_b_prev2'"><span class="blind">이전 해</span></a>
			<a class="sp sp_b_prev" href='<?=$_SERVER['PHP_SELF']?>?a_num=<?=$a_num?>&amp;year=<?=$prevYear?>&amp;month=<?=$prevMonth?>' onmouseover="this.className='sp sp_b_prev_on'" onfocus="this.className='sp sp_b_prev_on'" onmouseout="this.className='sp sp_b_prev'" onblur="this.className='sp sp_b_prev'"><span class="blind">이전 달</span></a>

			<span class="sp sp_null"></span>
			<span class="sp sp_n<?=$intThisYear[0]?>"><span class="blind"><?=$intThisYear[0]?></span></span>
			<span class="sp sp_n<?=$intThisYear[1]?>"><span class="blind"><?=$intThisYear[1]?></span></span>
			<span class="sp sp_n<?=$intThisYear[2]?>"><span class="blind"><?=$intThisYear[2]?></span></span>
			<span class="sp sp_n<?=$intThisYear[3]?>"><span class="blind"><?=$intThisYear[3]?></span></span>
			<span class="sp sp_ndot"><span class="blind">.</span></span>
			<span class="sp sp_n<?=$intThisMonth2[0]?>"><span class="blind"><?=$intThisMonth2[0]?></span></span>
			<span class="sp sp_n<?=$intThisMonth2[1]?>"><span class="blind"><?=$intThisMonth2[1]?></span></span>
			<span class="sp sp_null"></span>

			<a class="sp sp_b_next" href='<?=$_SERVER['PHP_SELF']?>?a_num=<?=$a_num?>&amp;year=<?=$nextYear?>&amp;month=<?=$nextMonth?>' onmouseover="this.className='sp sp_b_next_on'" onfocus="this.className='sp sp_b_next_on'" onmouseout="this.className='sp sp_b_next'" onblur="this.className='sp sp_b_next'"><span class="blind">다음 달</span></a>
			<a class="sp sp_b_next2" href='<?=$_SERVER['PHP_SELF']?>?a_num=<?=$a_num?>&amp;year=<?=$nextYear+1?>&amp;month=<?=$intThisMonth?>' onmouseover="this.className='sp sp_b_next2_on'" onfocus="this.className='sp sp_b_next2_on'" onmouseout="this.className='sp sp_b_next2'" onblur="this.className='sp sp_b_next2'"><span class="blind">다음 해</span></a>

			<span class="sp sp_null"></span>
			<a class="sp sp_b_today" href='<?=$_SERVER['PHP_SELF']?>?a_num=<?=$a_num?>&amp;year=<?=date("Y")?>&amp;month=<?=date("m")?>' style="margin-bottom: 4px;"><span class="blind">오늘</span></a>
		</div>
		<div class="cal_right">
			<?include("code.php"); //분류?>
		</div>
	</div>

	


	<!-- 리스트 테이블 -->
	<div class="cal_blist">

			<table cellspacing="0" >
			<caption><?=str_replace( " | ", "",$tit_name);?></caption>
				<colgroup>
				<col width="14%" />
				<col width="14%" />
				<col width="14%" />
				<col width="14%" />
				<col width="14%" />
				<col width="14%" />
				<col width="14%" />
				</colgroup>
			<thead>
				<tr>
					<th scope="col" class="sun">일요일</th>
					<th scope="col">월요일</th>
					<th scope="col">화요일</th>
					<th scope="col">수요일</th>
					<th scope="col">목요일</th>
					<th scope="col">금요일</th>
					<th scope="col" class="sat">토요일</th>
				</tr>
			</thead>



			<tbody>
				<?

				$cal	= $a_width / 7;
				$day	= -$datFirstDay + 1;	//날수1
				$day2	= -$datFirstDay + 1;	//날수2(내용할때)


				for( $ju = 0 ; $ju < $jucnt ; $ju++ ) { //주간 7개 돌리공..
				?>

				<tr>
					<?
					for ( $i = 0 ; $i < 7 ; $i++, $day++ ) {
						
						//글자색
						switch ( $i ) {
							case '0' : $tcolor="sun"; break;
							case '6' : $tcolor="sat"; break;
							default  : $tcolor="";
						}


						//날짜계산
						if( $day > 0 && $day <= $intLastDay ){
							$cday= $day;
						}else{
							$cday = "";
						}
						
		
			
						


					?>	

					<td class="day <?=$tcolor?>"><?=$cday?></td>

					<?
					}
					?>

				</tr>

				<!-- 내용 -->
				<tr>
					<?
						for ( $c = 0 ; $c < 7 ; $c++, $day2++ ) {
						

						//날짜계산
						if( $day2 > 0 && $day2 <= $intLastDay ){
							$cday2= $day2;
						}else{
							$cday2 = "";
						}

						$cday2 = sprintf('%02s',$cday2); //1~9숫자 앞에 0붙이기
						
						
						if($cday2 != "00"){
							
							$thisDate = $intThisYear."-".$intThisMonth."-".$cday2;
						}else{
							$thisDate = "";
						}	
					
					?>	
					<td><?today_list_new($thisDate)?></td>
					<?}?>
				</tr>
				<?}?>
				
			</tbody>
			</table>

	</div>
	<!-- //리스트 테이블 -->

	<!-- 버튼 -->
	<div class="board_button">
		<div class="fr">
			<span class="bt"><a href="list.php?a_num=<?=$a_num?>" ><img src="/content/board/default_calendar/img/list_bt.gif" width="62" height="23" alt="목록" /></a></span>
			<?if($is_write == "Y"){?>
			<span class="bt"><a href="write.php?a_num=<?=$a_num?>"><img src="/content/board/default_calendar/img/write_bt.gif" width="62" height="23" alt="쓰기" /></a></span>
			<?}?>
		</div>

	</div>
	<!-- //버튼 -->


	<?if($is_ad_cms == "Y"){?>
	</form>
	<? } ?>




</div>
<!-- //리스트 -->

<?include("bottom.php"); //하단파일?>

<?
function today_list_new($thisDate2){

	global $b_subject, $a_tablename, $board_skin1_url, $a_cate, $v_cate, $a_num, $b_num, $page_info, $a_type, $b_cate_str;

	

	$mysql_c = new Mysql_DB;
	$mysql_c->Connect();

	$R_Fields_code	= "b_num, b_subject, b_content, b_catename, b_open, b_sbjclr, b_cate";
	$order_by_code	= " ORDER BY b_sdate asc, b_edate asc";
	$thisDate3		= $thisDate2;

	


	//검색 옵션-------------------------------------------------------
	$sql_opt1	= " AND b_sdate <= '".$thisDate3."' AND b_edate >='".$thisDate3."'";

	//회원제 선택여부
	if($a_member == "Y"){
		$sql_opt2 = " AND  b_id = '".$_SESSION["ss_m_id"]."'";
	}


	//분류기능 사용시..
	if($a_cate == "Y" and  $v_cate != ""){
		$sql_opt3 = " AND  b_cate = ".$v_cate;
	}
	//----------------------------------------------------------------
	
	


	$SQL = "Select ".$R_Fields_code." FROM ".$a_tablename." WHERE b_num <> '0'";
	$SQL = $SQL . $sql_opt1 . $sql_opt2 . $sql_opt3;
	$SQL = $SQL . $order_by_code;
	//echo $SQL;
	$mysql_c->ParseExec($SQL);

	If ($mysql_c->RowCount() > 0) {
		
		//$zul = 1;
		while($mysql_c->FetchInto(&$rs_tdy)) {

			$b_num		= $rs_tdy["b_num"];
			$b_subject	= $rs_tdy["b_subject"];
			$b_content	= $rs_tdy["b_content"];
			$b_catename	= $rs_tdy["b_catename"];
			$b_open		= $rs_tdy["b_open"];

			$b_sbjclr	= $rs_tdy["b_sbjclr"];
			$b_cate		= $rs_tdy["b_cate"];

			

			

			
			$b_subject_str = $b_subject;
//			$b_subject_str = remove_tags($b_subject);
//			$b_subject_str = StringToHTML($b_subject_str, 18, false );

			
			//$_SESSOIN[$zul."_"."b_num"] = $b_num;

			//공개/비공개
			If ($a_type == "Y") {//사용하면

				if($b_open == "N"){//비공개이면
					
					$b_open_str = "<img src='/content/board/default_calendar/img/icon_key.gif' width='17' height='12' alt='비밀글' />";
				}else{//공개이면
					$b_open_str = "";
				}

			} Else {
				$b_open_str = "";
			}
			
	?>
		
	
		<a href="view.php?a_num=<?=$a_num?>&amp;b_num=<?=$b_num?>&amp;<?=$page_info?>" style="color:#6B6B6B;"><?=$b_cate_str[$b_cate]?><?=$b_subject_str?></a><?=$b_open_str?>




	<?
		
		//$_SESSOIN["zul_".$zul] = "";

		//$zul = $zul + 1;

		}
	}

	$mysql_c->ParseFree();

	

}
?>
