<!--// XE ver.1.2.x 게시판을 이용한 플래너/음력달력 ( Official Planner)-----------------------
## [author]
##  - Keysung Chung, 2009, 07, 28
##  - http://chungfamily.ffhosting.net/
## [function]
##  - 24절기 일자를 구하기 위해 Chilbong Kim님의 class.calendar.php와 class.solar.php를 사용
##  - 기타 펑션은 인터넷에서 구하거나 직접 코딩함.
## [changes]
##  - PlannerXE123 ver. 0.2 : Keysung Chung, 2009, 11, 09
##  - PlannerXE123 ver. 0.1 : Keysung Chung, 2009, 07, 28
## [modification]
##  - PlannerXE123 ver. 0.3 -> splanner 2.0.0 : muhak 2010.3.13
----------------------------------------------------------------------- -->

<?php
$GLOBALS['pYear'] = Context::get('pYear');  // XE변수 넘겨받기 위해서.
$pYear=$GLOBALS['pYear'];                   // XE변수 넘겨받기 위해서.
$GLOBALS['pMonth'] = Context::get('pMonth');    // XE변수 넘겨받기 위해서.
$pMonth=$GLOBALS['pMonth'];                     // XE변수 넘겨받기 위해서.

$logged_info = $_SESSION['logged_info'];
global $member_srl;
$member_srl = $logged_info->member_srl;
$__Context->member_srl = $member_srl;
unset($logged_info);
?>

<?php
// Time zone을 Seoul로 지정 ( php4.대에서는 에러 발생, php5.1 이상에서 정상작동)
// date_default_timezone_set('Asia/Seoul');     // 시간대 목록은 이곳에서( http://kr.php.net/manual/kr/timezones.php )
$starttime = microtime();
?>

<!--#include(calendar.html)-->

{@ $link_path = getUrl('','mid',$mid,'dummy',1)}
{@ $XE_path = getUrl('')}

{@ $today_bgcolor='#ffff00'}   <!--// 달력의 당일 칸 배경색 -->
<!--@if($module_info->colorset == "black")-->
    {@ $day_bgcolor='#f0f8ff'}      <!--// 달력의 평일 칸 배경색 -->
<!--@else-->
    {@ $day_bgcolor='#f5f5dc'}      <!--// 달력의 평일 칸 배경색 -->
<!--@end-->

<?php
$linkpath = $__Context->link_path;
$xepath = $__Context->XE_path;
$skinpath = $tpl_path; // 스킨 설치 경로지정
//echo $linkpath;
//echo $skinpath;
?>

<?php 
    /**
     * @brief XE에 설정된 타임존을 반영한 시간값을 구함
     * @param none,  XE함수 zgap() 사용
     * @return int
     **/
$xetoday = time() + zgap();
$todayYY = intval(date("Y",$xetoday));	// 당일년도
$todayMM = intval(date("n",$xetoday));	// 당일월
$todayDD = intval(date("j",$xetoday));	// 당일일

if ($pYear == null ) {
	$pYear = $todayYY;
}

if ($pMonth == null ) {
	$pMonth = $todayMM;
}

if ($pDay == null ) {
	$pDay = $todayDD;
}
if($pMonth > 12)
{
	$pYear++;
	$pMonth = 1;
}
if($pMonth < 1)
{
	$pYear--;
	$pMonth = 12;
}
$Calmain = fn_get_month_sun($pYear,$pMonth);        // 달력일자
if($__Context->module_info->plan_lunar != 'N')
	$Lunar = fn_get_month_lunar($pYear,$pMonth);        // 음력 달력일자
$mm = fn_get_reg_days($pYear,$pMonth,$__Context->module_info->plan_holi_text);
if($__Context->module_info->plan_holi == 'Y')
{
	$aMonthHoliday = fn_holidays($pYear, $pMonth);	// 휴일
	if($mm != null)
	{
		foreach($mm as $k => $v)
		{
			$aMonthHoliday[$k] .= $v;
		}
		unset($mm);
	}
} else
{
	if($mm != null)
	{
		$aMonthHoliday = $mm;
		unset($mm);
	}
}
$mm = fn_get_reg_days($pYear,$pMonth,$__Context->module_info->plan_memo_text);
if($__Context->module_info->plan_memorial == 'Y')
{
	$aMonthMemday = fn_get_Memday($pYear, $pMonth);	// 기념일
	if($mm != null)
	{
		foreach($mm as $k => $v)
		{
			$aMonthMemday[$k] .= $v;
		}
		unset($mm);
	}
} else
{
	if($mm != null)
	{
		$aMonthMemday = $mm;
		unset($mm);
	}
}
if($__Context->module_info->plan_jeolki == 'Y')
	$aJeolki = fn_get_jeolki($pYear,$pMonth);	// 24절기 초,중,말복 한식 단오

?>


<?php
$__Context->pYear = $pYear;
$tempmonth = substr("0".$pMonth, -2);       //월 을 "7" 에서 "07"로
$__Context->tempMonth = $tempmonth;
?>

<!--// 공지사항과 일반문서 합치기 (반복일정의경우 공지사항으로 작성하여 리스트 앞으로 가져오기위함)  -->
<!--@if($notice_list != null)-->
    {@ $planner_document_list = $notice_list}
    <!--@if($document_list != null)-->
        {@ $planner_document_list = $planner_document_list + $document_list}
    <!--@end-->
<!--@else-->
    {@ $planner_document_list = $document_list}
<!--@end-->

<!--// Xe 확장변수 변수를 작업 ($key 등은 board설정시 목록에 포함되어야 들어옴)  -->
<!--@foreach($planner_document_list as $no => $document)-->

	<!--@if($document->get('is_secret') == 'Y' && $document->get('member_srl') != $member_srl)-->
        <?php continue; ?>
	<!--@end-->

    <!--// Category title & color값 얻기  -->
    <!--@if($module_info->use_category == "Y" && $document->get('category_srl'))-->
        <!--@if($category_list[$document->get('category_srl')]->color)-->
        {@ $category_color = $category_list[$document->get('category_srl')]->color}
        <!--@end-->
        {@ $category_title = $category_list[$document->get('category_srl')]->title}
    <!--@else-->
        {@ $category_color = null}
        {@ $category_title = null}
    <!--@end-->
    <?php
        $category_title = $__Context->category_title;
        $category_color = $__Context->category_color;
    ?>

    <!--// 댓글 숫자 얻기  -->
    <!--@if($document->getCommentCount())-->
        {@ $plan_reply = $document->getCommentCount()}
    <!--@else-->
        {@ $plan_reply = null}
    <!--@end-->
    <?php
        $plan_reply = $__Context->plan_reply;
    ?>

    {@ $nickname = $document->getNickName()}
    <?php
    $nickname = $__Context->nickname;
    ?>

    <!--// 일정 얻기  -->
    {@ $plan_title = $document->getTitle($module_info->subject_cut_size)}
    {@ $plan_detail = $document->getSummary($module_info->content_cut_size)}
    {@ $plan_start = $document->getPlanSdate()}
    {@ $plan_end = $document->getPlanEdate()}
    {@ $plan_bgcolor = $document->getPlanBgcolor()}
    {@ $plan_check = $document->getPlanCheck()}
    {@ $plan_period = $document->get('plan_period')}
    {@ $plan_value = $document->get('plan_value')}
    {@ $plan_time = $document->get('plan_time')}
	{@ $exImg = $document->printExtraImages(60*60*$module_info->duration_new)}
    {@ $plan_url = getUrl('document_srl',$document->document_srl, 'listStyle', $listStyle, 'cpage','')}
        <?php
        $plan_title = $__Context->plan_title;
        $plan_detail = $__Context->plan_detail;
        $plan_url = $__Context->plan_url;
        $plan_start = $__Context->plan_start;           // 일정시작
        $plan_end = $__Context->plan_end;           // 일정종료
        $plan_bgcolor = $__Context->plan_bgcolor;
        $plan_check = $__Context->plan_check;
        $plan_period = $__Context->plan_period;
        $plan_value = $__Context->plan_value;
        $plan_time = $__Context->plan_time;
        $exImg = $__Context->exImg;
//debugPrint($plan_title."\n".$plan_detail."\n".$plan_url."\n".$plan_start."\n".$plan_end."\n".$plan_bgcolor."\n".$plan_check."\n".$plan_period."\n".$plan_value);
        ?>
<?php 
if ($plan_start != null ) {
	$plnstartYY = (int)($plan_start/10000);
	$plnstartMM = (int)(($plan_start%10000)/100);
	$plnstartDD = (int)($plan_start%100);
	if($plan_end)
	{
		$plnendYY = (int)($plan_end/10000);
		$plnendMM = (int)(($plan_end%10000)/100);
		$plnendDD = (int)($plan_end%100);
	} else
	{
		$plnendYY = $plnstartYY;
		$plnendMM = $plnstartMM;
		$plnendDD = $plnstartDD;
	}
	if ($plnstartYY == $pYear and $plnstartMM == $pMonth) {     // 당월 시작 이>면서 당월 이후 종료
		if ($plnendYY > $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) {
			$plnendYY = $pYear;
			$plnendMM = $pMonth;
			$plnendDD = 31;
		}
	}
	elseif ($plnstartYY < $pYear or $plnstartYY == $pYear and $plnstartMM < $pMonth) {  // 당월 이전 시작 이면서 당월 종료
		if ($plnendYY == $pYear and $plnendMM == $pMonth) {
			$plnstartYY = $pYear;
			$plnstartMM = $pMonth;
			$plnstartDD = 1;
		}
		if ($plnendYY > $pYear or $plnendYY == $pYear and $plnendMM > $pMonth) { // 당월 이전시작 이면서 당월 이후 종료
			$plnstartYY = $pYear;
			$plnstartMM = $pMonth;
			$plnstartDD = 1;
			$plnendYY = $pYear;
			$plnendMM = $pMonth;
			$plnendDD = 31;
		}
	}

	if( $plnstartYY == $pYear and $plnstartMM == $pMonth )
	{
		$plan_detail = str_replace("'", "`", $plan_detail);			// '을 `로 대체 textbox보이기위해
		$plan_detail = str_replace("\"", "&quot;", $plan_detail);	// "를 &quot;로 대체 textbox보이기위해
		$plan_detail = str_replace(chr(012), "<br/>", $plan_detail);		// LF를 제거 textbox보이기위해
		$plan_detail = str_replace(chr(015), "", $plan_detail); // CR을 제거 textbox보이기위해 -줄바꿈
	//	$plan_detail = strip_tags($plan_detail);					// HTML tag 제거 - 줄바꿈 사용않음

		$plan_detail = "[".$nickname."]<br/>".$plan_detail;

//debugPrint("plan: $plan_start $plan_end $plan_period $plnstartDD $plnendDD $plan_value");
		if($plan_period)
		{
			$arr_repeat = fn_repeat_schedule($Calmain, $plan_period, $plan_value, $aMonthHoliday);
		}
		if($plan_time != null) $plan_time = "(".$plan_time.")";
		for ($j = $plnstartDD; $j <= $plnendDD; $j++ ) {
			if ( $plan_period==0 || $arr_repeat[$j] == "*") {
				$outtext = null;
/*
				if($category_title)
					$outtext .= "<span style='color:".$category_color."'>[".$category_title."] </span>"; // 분류
*/
				$outtext .= "<span style='background-color:".$plan_bgcolor.";'>";
				if($plan_check)
					$outtext .= "<img src='images/icon/".$plan_check."' >";
				$outtext .= "<a href=".$plan_url." title='".$plan_detail."'>".$plan_time.$plan_title."</a></span>";
				if($plan_reply)
					$outtext .= "<span class='small'>[".$plan_reply."] </span>"; // 댓글숫자
				$arr_plan[$j] .= $outtext.$exImg."<br/>";
			}
		}
    }
}	
?>
<!--@end-->

<style type="text/css">
.splanner { clear:both; }
.planner_control { width:100%; background:transparent; *zoom:1; }
.planner_control:after { planner_this:""; clear:both; display:block; }
.planner_this { width:200px; float:left; color:#008000; font: bold 20px verdana;  }
.planner_navigation { width:auto; float:right; }
.planner_calendar { clear:both; width:100%; border-collapse:collapse; table-layout:fixed; }
.planner_calendar th,td { padding:0; border-spacing:0; }
.planner_calendar thead th { border:1px solid #ccc; height:27px; background: url(<?php echo $skinpath?>images/calendar/tablehd_bg.png) repeat-x; }
.planner_calendar tbody td { border:1px solid #ccc; height:80px; padding:0; vertical-align:top; }
.planner_calendar_inner { margin:0; padding:0; width:100%; min-height:80px; display:block; }
.planner_calendar_inner ul { vertical-align:top; text-align:left; border:none; }
.planner_calendar_inner li { height:auto; padding:0px; list-style-type:none; }
.planner_calendar_inner li .holiday { color:#ff0000; }
.planner_calendar_inner li .sunday { color:#ff0000; font: bold 16px Georgia; }
.planner_calendar_inner li .saturday { color:#0000ff; font: bold 16px Georgia; }
.planner_calendar_inner li .weekday { color:#888888; font: bold 16px Georgia; }
.planner_calendar_inner li .lunar { color:#b03060; }
.planner_calendar_inner li .seasons24 { color:#0000ff; }
.planner_calendar_inner li .memorial { color:#008b8b; }
.planner_calendar_inner li .strong { font-weight:bold; }
.planner_calendar_inner li .font_big { font-size:14px; }
.planner_calendar tbody td .small { font-size:0.9em; }
</style>

<div class="splanner">
    <!--//  버튼 -->
    <div class="planner_control">
        <div class="planner_this">
            <!--//숫자형식으로 년월 표시-->
            <!--//    <font size="4" COLOR=green><b><?php echo $pYear?>年 <?php echo $pMonth?>月&nbsp;&nbsp;(<?php echo $pYear+2333?>)</b></font>-->
            <!--//영문형식으로 년월 표시-->
            <?php echo $pMon?>&nbsp;&nbsp;<?php echo $pYear?>
		</div>
        <div class="planner_navigation">
			<form style="float:left;" name = "fm_select_year">
			<select style ="height:17px; margin:0; padding:0; font-size:11px;" name="selectyear" onchange="document.location.href='<?php echo $linkpath?>&amp;listStyle={$module_info->default_style}&amp;pYear=' +this.options[this.selectedIndex].value +'&amp;pMonth=<?php echo $pMonth?>'">
			<option value='<?php echo $pYear?>'><?php echo $pYear?></option>
			<?php for ($j=2000; $j<2038; $j++ ) { echo ("<option value='".$j."'>".$j."</option>"); } ?>
			</select></form>&nbsp;&nbsp;

			<?php if($pMonth == 1) {
						$tmp_m = 12; $tmp_y = $pYear - 1;
					} else {
						$tmp_m = $pMonth - 1; $tmp_y = $pYear;
					}
			?>
            <img src="images/calendar/month_t.gif" width="39" height="15" /><a href="<?php echo $linkpath?>&amp;listStyle={$module_info->default_style}&amp;pYear=<?php echo $tmp_y?>&amp;pMonth=<?php echo $tmp_m?>" title='전월'><img src="images/calendar/btn_prev_year.gif" width="17" height="15" /></a>
            <?php
            for ($i=1; $i < 13; $i++) {
            ?>
            <a href="<?php echo $linkpath?>&amp;listStyle={$module_info->default_style}&amp;pYear=<?php echo $pYear?>&amp;pMonth=<?php echo $i?>" title='<?php echo $i ?>월' ><img src="images/calendar/month_<?php echo $i?><?php IF($pMonth == $i){ ?>_on<?php }?>.gif" width="17" height="15" /></a>
            <?php
            }
            ?>
			<?php if($pMonth == 12) {
						$tmp_m = 1; $tmp_y = $pYear + 1;
					} else {
						$tmp_m = $pMonth + 1; $tmp_y = $pYear;
					}
			?>
            <a href="<?php echo $linkpath?>&amp;listStyle={$module_info->default_style}&amp;pYear=<?php echo $tmp_y?>&amp;pMonth=<?php echo $tmp_m?>" title='익월'><img src="images/calendar/btn_next_year.gif" width="17" height="15" /></a>
        </div>
    </div>
    <!--//  달력 -->
    <table class="planner_calendar" border="0" summary="플래너123" style='margin-bottom:2px' >
        <thead>
            <tr>
                <th scope="col" width="14%"><font color="red">Sun</font></th>
                <th scope="col" width="14%">Mon</th>
                <th scope="col" width="14%">Tue</th>
                <th scope="col" width="14%">Wed</th>
                <th scope="col" width="14%">Thu</th>
                <th scope="col" width="14%">Fri</th>
                <th scope="col" width="14%"><font color="blue">Sat</font></th>
            </tr>
        </thead>
        <tbody>

        <?php
        $weekcount = count($Calmain);
        for($i=0; $i<$weekcount; $i++) {
            echo ("<tr>\n");
            for ($j=0; $j<7; $j++) {

				$tempday=$Calmain[$i][$j];
				if($tempday == $todayDD and $pMonth == $todayMM and $pYear == $todayYY)
				{
					$today_flag = 1;
					$style = "style='border:2px solid;border-color:CadetBlue'";
				}
				else
				{
					$today_flag = 0;
					$style = "";
				}
        ?>
                <td <?php echo $style; ?> bgcolor="{$day_bgcolor}" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#ddfffa'">
<!--// 오늘표시 : 테두리 표시 
                <td <?php if($today_flag == 1) { ?> style="border:2px solid;border-color:CadetBlue" <?php } ?> bgcolor="{$day_bgcolor}" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#ddfffa'">
-->
<!--// 오늘표시 : 배경색 표시
                <td <?php if($today_flag == 1) { ?> bgcolor='{$today_bgcolor}' <?php } ?> bgcolor="{$day_bgcolor}" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#ddfffa'">
-->
                <ul class="planner_calendar_inner">
                <?php
                $outtext = null;
				if($tempday)
                {
                    // --해당일의 휴일 얻기---
					$tmpHoli = $aMonthHoliday[$tempday];

                    // 첫줄 --일자,음력,절기---
                    if ($today_flag == 1) {
                        $outtext = "<li style='background:".$__Context->today_bgcolor.";'>";   // 당일
                    }
                    else  {
                        $outtext = "<li>";                 // 평일
                    }

                    if ($j==0 || $tmpHoli != null) {
                        $tmpfld = "<span class='sunday'>".$tempday."</span>";    // 일요일 및 휴일
                    }
                    elseif ($j==6) {
                        $tmpfld = "<span class='saturday'>".$tempday."</span>";   // 토요일
                    }
                    else  {
                        $tmpfld = "<span class='weekday'>".$tempday."</span>";  // 평일
                    }
                    $templink = getUrl('act','dispSboardWrite','document_srl','') ;  // 일자 클릭시 쓰기로 이동
                    $templink .= "&amp;plan_sdate=".$pYear.$tempmonth.substr("0".$tempday,-2);    // 일정시작 변수에 값 넣기위해
                    $templink = "<a href=".$templink." class='strong font_big'>";
                    $outtext .= "&nbsp;".$templink.$tmpfld."</a>";   // 일자

					// 음력 표시
					$tmpLunar = $Lunar[$tempday] % 100;	// 음력 일자 가져오기
					// 음력: 1,10,20일 표시
					if(($__Context->module_info->plan_lunar == 'A') ||
					   (($__Context->module_info->plan_lunar == '1')
                       &&($tmpLunar == 1 || $tmpLunar == 10 || $tmpLunar == 20))
					  )
					{  
						$tmpLunar = $Lunar[$tempday];
						if($tmpLunar > 10000)
						{
							$tmpLunar %= 10000;
							$tmpfld1 = sprintf("윤%d.%d",(int)($tmpLunar/100),$tmpLunar%100);
						} else
							$tmpfld1 = sprintf("%d.%d",(int)($tmpLunar/100),$tmpLunar%100);
                        $outtext .= "&nbsp;"."<span class='lunar'>".$tmpfld1."</span>";    // 음력
                    }
                    $outtext .= "&nbsp;<span class='seasons24 strong'>".$aJeolki[$tempday]."</span>";   // 절기
                    $outtext .= "&nbsp;<span class='holiday strong'>".$tmpHoli."</span>"; // 공휴일
                    $outtext .= "</li>\n";
                    echo ($outtext);

                    // 둘째줄 --기념일---
                    if ($aMonthMemday[$tempday] != null) { // 기념일만 체크
                        echo "<li><span class='memorial'>".$aMonthMemday[$tempday]."</span></li>\n"; // 기념일
                    }
                   // 세째줄 --일정/플랜---
                    if ($arr_plan[$tempday]!= null)
                    {
						echo "<li>".$arr_plan[$tempday]."</li>\n";
                    }

                 }
                echo ("</ul>");
                echo ("</td>\n");
            }
            echo ("</tr>\n");
        }
        ?>

        </tbody>
    </table>
</div>

<!--// 관리자로 로그인 했을경우 리스트 출력 -->
<!--@if($grant->manager)-->
<!--#include("./_style.list_planner.html")-->
<!--@end-->

<!--// 툴팁 -->
<!--%load_js_plugin("qtip")-->
<script type="text/javascript">//<![CDATA[
var $j = jQuery.noConflict();
$j(document).ready(function()
{
    // qtip
    $j('ul:.planner_calendar_inner a[title]').qtip({
      position: {
         corner: {        //bottomLeft, bottomRight, bottomMiddle, topRight, topLeft, topMiddle,
                        //leftMiddle, leftTop, leftBottom, rightMiddle, rightBottom, rightTop
            target: 'topMiddle',                                  
            tooltip: 'bottomMiddle'
         },
         adjust: {
            x: 0, y: 0,
            mouse: true,
            screen: true,
            scroll: true,
            resize: true
		}
      },
      style: {
         name: 'green', //defaults,cream,light,dark,red,green,blue
         padding: '7px 13px',
         width: {
            max: 250,
            min: 0
         },
      border: {
         width:  3,  //border 굵기 지정
         radius: 0   //coner round 반경 지정(색을 지정하려면 끝에 "0,"처럼 끝에,를 붙일것)
         //color: '#A9DB66' //border color
         },
         tip: true
      }
    });
});
//]]></script>
