<?php
session_start();
$boardDir = "../board";
include "../board/lib.php"; 
include "../board/function.php";

$sub_f_key = "04";
$sub_m_key = "05";

include ("../inc/header.php"); ?>

<?php
if( empty($yearx9) ){    $yearx9 = date("Y");  }     
if( empty($monthx9) ){    $monthx9  = date("n");  }
if( empty($dayx9) ){     $dayx9 = date("d");   }
if (strlen($monthx9)==1) { $monthx9='0'.$monthx9;	}
if (strlen($dayx9)==1) { $dayx9='0'.$dayx9;	}
$on_datexx = $yearx9."-".$monthx9."-".$dayx9;
//$on_datexx = date("Y-m-d", strtotime("$date059 + 1 days"));

$row2 = MyFetchArray("select * from tb_eat where title='$on_datexx'  ", $connect);
$lunch_menu2 = str_replace("\n","<br>",$row2['content']);
$dinner_menu2 = str_replace("\n","<br>",$row2['dinner']);

$yearx = clearxss($_GET['yearx'],"");
$monthx = clearxss($_GET['monthx'],"");

if(empty($yearx)) $yearx = clearxss($_POST['yearx'],"");
if(empty($monthx)) $monthx = clearxss($_POST['monthx'],"");

if(empty($yearx)) $yearx = $yearx9;
if(empty($monthx)) $monthx = $monthx9;

$yoil = array("일","월","화","수","목","금","토");

$monthx = intval($monthx);

if($monthx=='14')	{
	$monthx  = 12;
	$yearx = $yearx - 1;

	$p_yearx = $yearx;
	$n_yearx = $yearx + 1;
	$p_monthx = $monthx - 1;
	$n_monthx = $monthx + 1;

}	else if($monthx==13)	{	
	$monthx  = 1;
	$yearx = $yearx + 1;

	$p_yearx = $yearx - 1;
	$n_yearx = $yearx + 1;
	$p_monthx = 12;
	$n_monthx = $monthx + 1;

}	else	{
	$p_yearx = $yearx;
	$n_yearx = $yearx + 1;
	$p_monthx = $monthx - 1;
	$n_monthx = $monthx + 1;

	if($p_monthx == 0)	$p_monthx = 14;
}

$first_day = mktime(0,0,0,$monthx,1,$yearx);
$first_day = date('w',$first_day);

// 달의 총 일수를 구한다.

$total_days = get_month_last_day($yearx,$monthx);

$c_year = date('Y');
$c_month = date('m');
$c_day = date('d');

if (strlen($monthx)==1) { $monthx='0'.$monthx;	}
?>
        <!-- contents -->
        <div id="contents" class="sub_contwrap">
           <div class="container">
                <div class="sub_contlayout">
                    <div class="side_menu board">
                        <div class="side_menu_top">
                            <p>알림마당</p>
                        </div>
                        <div class="side_menu_bottom">
                            <ul>
                                <li>
                                    <a href="board_01.php">공지사항</a>
                                </li>
                                <li>
                                    <a href="board_04.php">언론보도</a>
                                </li>
                                <li>
                                    <a href="board_02.php">사진자료실</a>
                                </li>
                                <li>
                                    <a href="board_05.php">고충처리함</a>
                                </li>
                                <li class="active">
                                    <a href="board_03.php">이달의 식단</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="sub_cont">
                        <div class="subtit_area">
                            <h2 class="sub_tit">이달의 식단</h2>
                            <ul class="sub_utilewrap">
                                <li>HOME</li>
                                <li>알림마당</li>
                                <li>이달의 식단</li>
                            </ul>
                        </div>
                        <div class="sub_maincont_area">
                            <div class="todaydiet">
                                <div class="todaydiet_L">
                                    <div class="todaydiet_img"><img src="../images/diet_img.png" alt=""></div>
                                    <div class="todaytit">
                                        오늘의 식단 <br>
                                        <span class="todaydate"><?=$yearx9?>년 <?=$monthx9?>월 <?=$dayx9?>일</span>
                                    </div>
                                </div>
                                <div class="todaydiet_R">
                                    <div class="todaydiet_lunch">
                                        <div class="diet-time">
                                          중식
                                        </div>
                                        <div class="diet-desc">
                                          <?=$lunch_menu2?>
                                        </div>
                                    </div>
                                    <div class="todaydiet_dinner">
                                        <div class="diet-time">
                                          석식
                                        </div>
                                        <div class="diet-desc">
                                          <?=$dinner_menu2?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="calendar_header">
                                <a href="<?=$PHP_SELF?>?yearx=<?=$p_yearx?>&amp;monthx=<?=$p_monthx?>"><img src="../images/calendar_arrowL.png" alt=""></a>
                                <h3><?=$yearx?>.<?=$monthx?></h3>
                                <a href="<?=$PHP_SELF?>?yearx=<?=$yearx?>&amp;monthx=<?=$n_monthx?>"><img src="../images/calendar_arrowR.png" alt=""></a>
                            </div>

                            <table id="calendar">
                                <caption><?=$yearx?>.<?=$monthx?></caption>
                                <tr class="weekdays">
                                  <th scope="col">일</th>
                                  <th scope="col">월</th>
                                  <th scope="col">화</th>
                                  <th scope="col">수</th>
                                  <th scope="col">목</th>
                                  <th scope="col">금</th>
                                  <th scope="col">토</th>
                                </tr>
                            
                                <tr>
<?php
	$count = 0;
	for($i=0; $i < $first_day; $i++){
?>	
	    							<td class="day other-month">&nbsp;</td>
<?php		
	$count++;
	}

// 달력 출력	
	for($today = 1; $today <= $total_days; $today++){

        if( $yearx==$c_year && $monthx==$c_month && $today==$c_day ){ $td_class  = " today"; }
		else{ $td_class=""; }

		if(strlen($today)==1)	{
			$todayx = "0".$today;
		}	else {
			$todayx = $today;
		}

		$i_datexx = $yearx."-".$monthx."-".$todayx;

		$row1 = MyFetchArray("select * from tb_eat where title='$i_datexx'  ", $connect);
		$lunch_menu = str_replace("\n","<br>",$row1['content']);
		$dinner_menu = str_replace("\n","<br>",$row1['dinner']);

        switch($count){
	        case "0":	//일요일인 경우 
?>		
								<tr>
                                  <td class="day">
                                    <div class="date"><?=$today?></div>
									<?php if($lunch_menu) { ?>
                                    <div class="diet <?=$td_class?>">
									  <?php if($dinner_menu) { ?>
                                      <div class="diet-time">
                                        중식
                                      </div>
									  <?php } ?>
                                      <div class="diet-desc">
                                        <?=$lunch_menu?>
                                      </div>
                                    </div>
									<?php } ?>
									<?php if($dinner_menu) { ?>
                                    <div class="diet">
                                      <div class="diet-time">
                                        석식
                                      </div>
                                      <div class="diet-desc">
                                        <?=$dinner_menu?>
                                      </div>
                                    </div>
									<?php } ?>
                                  </td>
<?php				
                $count++;
                break;
            case "6":	//토요일인 경우 파란색으로
?>		
                                  <td class="day">
                                    <div class="date"><?=$today?></div>
									<?php if($lunch_menu) { ?>
                                    <div class="diet <?=$td_class?>">
									  <?php if($dinner_menu) { ?>
                                      <div class="diet-time">
                                        중식
                                      </div>
									  <?php } ?>
                                      <div class="diet-desc">
                                        <?=$lunch_menu?>
                                      </div>
                                    </div>
									<?php } ?>
									<?php if($dinner_menu) { ?>
                                    <div class="diet">
                                      <div class="diet-time">
                                        석식
                                      </div>
                                      <div class="diet-desc">
                                        <?=$dinner_menu?>
                                      </div>
                                    </div>
									<?php } ?>
                                  </td>
								</tr>
<?php				
                $count = 0;
                break;
            default:	//평일인 경우 검은색으로
?>		
                                  <td class="day">
                                    <div class="date"><?=$today?></div>
									<?php if($lunch_menu) { ?>
                                    <div class="diet <?=$td_class?>">
									  <?php if($dinner_menu) { ?>
                                      <div class="diet-time">
                                        중식
                                      </div>
									  <?php } ?>
                                      <div class="diet-desc">
                                        <?=$lunch_menu?>
                                      </div>
                                    </div>
									<?php } ?>
									<?php if($dinner_menu) { ?>
                                    <div class="diet">
                                      <div class="diet-time">
                                        석식
                                      </div>
                                      <div class="diet-desc">
                                        <?=$dinner_menu?>
                                      </div>
                                    </div>
									<?php } ?>
                                  </td>
<?php				
                $count++;
            }
        }

		while($count > 0 && $count < 7){
?>		
				<td class="day other-month"> &nbsp; </td>
<?php
			$count++;
		}

?>		

                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
           </div>
        </div>
        <!-- //contents -->
        
        <!-- footer -->
<?php include ("../inc/footer.php"); ?>