<!--// XE ver.1.2.x 게시판을 이용한 플래너/음력달력 위젯 Calendar_simple형-----------------------
## [author]
##  - Keysung Chung, 2009, 07, 28
##  - http://chungfamily.ffhosting.net/
## [function]
##  - 24절기 일자를 구하기 위해 Chilbong Kim님의 class.calendar.php와 class.solar.php를 사용
##  - 기타 펑션은 인터넷에서 구하거나 직접 코딩함.
## [changes]
##  - 위젯 PlannerXE123 ver. 1.0.0 : Keysung Chung, 2010, 04, 01
##  - 위젯 PlannerXE123 ver. 0.2.2 : Keysung Chung, 2010, 01, 25
##  - PlannerXE123 ver. 0.2 : Keysung Chung, 2009, 11, 09
##	- PlannerXE123 ver. 0.1 : Keysung Chung, 2009, 07, 28
----------------------------------------------------------------------- -->
{@print_r($widget_info->testfld)}
<?php 
print_r($widget_info->testfld);
$pYear = $__Context->pYear;
$pMonth = $__Context->pMonth;
?>

<?php 
$starttime = microtime();
?>

{@ $today_bgcolor="#CDE6AC"}   <!--// 달력의 당일 칸 배경색 -->
{@ $today_bodercolor="#58792E"}   <!--// 달력의 당일 칸 border 색 -->
{@ $mouseover_bgcolor="#ddfffa"}   <!--// 달력의 칸에 마우스오버시 배경색 -->

<!--@if($widget_info->bg_color == null)-->
	{@ $day_bgcolor=white}      <!--// 달력의 평일 칸 배경색 -->
<!--@else-->
	{@ $day_bgcolor=$widget_info->bg_color}      <!--// 달력의 평일 칸 배경색 -->
<!--@end-->

<!--// 설정된 컬러셋의 종류에 따라서 css파일을 import 합니다 -->
<!--@if($colorset == "black")-->
    <!--%import("./css/common.css")-->
    <!--%import("./css/black.css")-->
<!--@else-->
    <!--%import("./css/common.css")-->
    <!--%import("./css/white.css")-->
<!--@end-->

<!--// 날자 설정 ---------------------------------- -->
<?php 
if ($pYear == null ) {
	$pYear = date("Y", planner_ksc_widget::fn_xetimestamp());
}

if ($pMonth == null ) {
	$pMonth = date("n", planner_ksc_widget::fn_xetimestamp());
}

if ($pMon == null ) {
	$pMon = date("F", planner_ksc_widget::fn_xetimestamp());
}

if ($pDay == null ) {
	$pDay = date("j", planner_ksc_widget::fn_xetimestamp());
}

if ($pOption < 1 or $pOption > 3 ) {
	$pOption=1;		// 간지옵션
}

$pYear =date("Y", mktime(0, 0, 0, $pMonth, 1, $pYear)); 
$pMonth =date("n", mktime(0, 0, 0, $pMonth, 1, $pYear));
$pMon =date("F", mktime(0, 0, 0, $pMonth, 1, $pYear));

$todayYY = date("Y", planner_ksc_widget::fn_xetimestamp());	// 당일년도
$todayMM = date("n", planner_ksc_widget::fn_xetimestamp());	// 당일월
$todayDD = date("j", planner_ksc_widget::fn_xetimestamp());	// 당일일

$__Context->pYear = $pYear;
$__Context->pMonth = $pMonth;

?>

<!--// -----위젯, 게시판등 경로지정 --------------- -->
{@ $btnlink_path = getUrl('','mid',$mid,'dummy',1)}
{@ $daylink_path = getUrl('','mid',$widget_info->mid,'dummy',2)}
{@ $XE_path = getUrl('')}

<?php
$btnlinkpath = $__Context->btnlink_path;
$daylinkpath = $__Context->daylink_path;
$xepath = $__Context->XE_path;
$skinpath = $tpl_path;
?>

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

<!--// -----일정관련 확장변수, 내용등 지정 ----------------------- -->
<!--@foreach($widget_info->document_list as $oDocument)-->

	<!--// Category title & color값 얻기  -->
	<!--@if($oDocument->get('category_srl'))-->
		<!--@if($widget_info->category_list[$oDocument->get('category_srl')]->color)-->
		{@ $category_color = $widget_info->category_list[$oDocument->get('category_srl')]->color}
		<!--@end-->
		{@ $category_title = $widget_info->category_list[$oDocument->get('category_srl')]->title}
    <!--@end-->
	<?php
		$category_title = $__Context->category_title;
		$category_color = $__Context->category_color;
	?>

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

	<!--// 확장변수값 얻기  -->
	{@$plan_start = $oDocument->getExtraValue(1)}
	{@$plan_end = $oDocument->getExtraValue(2)} 
	{@$plan_bgcolor = $oDocument->getExtraValue(3)} 
	{@$plan_flagicon = $oDocument->getExtraValue(4)} 
	{@$plan_repeat_cycle = $oDocument->getExtraValue(5)} 
	{@$plan_repeat_unit = $oDocument->getExtraValue(6)} 
	{@$plan_time = $oDocument->getExtraValue(7)} 

	{@$plan_title  = $oDocument->getTitle($widget_info->subject_cut_size)}
	{@$plan_detail = $oDocument->getSummary($widget_info->content_cut_size)}
	{@$plan_url = $oDocument->getPermanentUrl()}
	{@$plan_docurl = $oDocument->document_srl}
	{@$plan_board_skin = $oDocument->module_skin}
	<!--@if($plan_end == null )-->
		{@ $plan_end = $plan_start}
	<!--@end-->

<?php
	$plan_title = $__Context->plan_title;		
	$plan_detail = $__Context->plan_detail;		
	$plan_url = $__Context->plan_url;			
	$plan_bgcolor = $__Context->plan_bgcolor;	
	$plan_flagicon = $__Context->plan_flagicon;	
	$plan_repeat_cycle = $__Context->plan_repeat_cycle;		// 반복일정 cycle
	$plan_repeat_unit = $__Context->plan_repeat_unit;		// 반복일정 unit
	$plan_time = $__Context->plan_time;						// 시간대 (11:00|@|12:00  형식)
	$plan_board_skin = $__Context->plan_board_skin;			// board skin 폴더명

	$plan_start = $__Context->plan_start;		
	$plnstartYY = substr($plan_start, 0, 4);			
	$plnstartMM = substr($plan_start, 4, 2);			
	$plnstartDD = substr($plan_start, 6, 2);			
	$plnstartMM = ltrim( $plnstartMM, "0" );	//  앞의 "0" 제거
	$plnstartDD = ltrim( $plnstartDD, "0" );	//  앞의 "0" 제거

	$plan_end = $__Context->plan_end;			
	$plnendYY = substr($plan_end, 0, 4);			
	$plnendMM = substr($plan_end, 4, 2);			
	$plnendDD = substr($plan_end, 6, 2);			
	$plnendMM = ltrim( $plnendMM, "0" );	//  앞의 "0" 제거
	$plnendDD = ltrim( $plnendDD, "0" );	//  앞의 "0" 제거

if ($plnstartYY != null ) {
	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) {			// 일정관련자료 어레이에 출력
	  $arr_repeat = planner_ksc_widget::fn_repeat_schedule($pYear, $pMonth, $plan_start, $plan_end, $plan_repeat_cycle, $plan_repeat_unit);
	  For	($i = $plnstartMM; $i <= $plnendMM; $i++) {
		For ($j = $plnstartDD; $j <= $plnendDD; $j++ ) {
			if ( $arr_repeat[$i][$j] == "*") {
			    $arr_plan[$i][$j] = $arr_plan[$i][$j].$plan_title."~:~".$plan_url."~:~".$plan_detail."~:~".$plan_bgcolor."~:~".$plan_flagicon."~:~".$category_title."~:~".$category_color."~:~".$plan_reply."~:~".$plan_time."~:~".$plan_board_skin."|#|";	// 어레이에 추가 1차분리자= "|#|", 2차 분리자 "~:~"
			}
		}
	  }
	}
}	
?>
<!--@end-->

<!--// option에 따라 음력, 휴일, 기념일등 구하기 -->
{@$option_view_arr  = $widget_info->option_view_arr}

<?php
$option_view_arr = $__Context->option_view_arr;				// Display 옵션 unit
$Calmain = planner_ksc_widget::fn_CalMain($pYear,$pMonth);	// 달력일자

$count = count($option_view_arr);
for ($k = 0; $k < $count; $k++) {
	if ($option_view_arr[$k] == "lunar_calendar") {
		$id_lunar = "Y";
		$Lunarday = planner_ksc_widget::fn_sol2lun_ary($pYear,$pMonth);		// 음력일자
	}
	else if ($option_view_arr[$k] == "holiday") {
		$id_holiday = "Y";
		$Holiday = planner_ksc_widget::fn_HolidayChk($pYear, $pMonth);		// 휴일
	}
	else if ($option_view_arr[$k] == "memday") {
		$id_memday = "Y";
		$Memday = planner_ksc_widget::fn_MemdayChk($pYear, $pMonth);		// 기념일
	}
	else if ($option_view_arr[$k] == "solar_terms") {
		$id_terms = "Y";
	}
	else if ($option_view_arr[$k] == "iljin") {
		$id_iljin = "Y";
	}
}
?>

<!--// -----달력작성 ----------------------- -->
<!--// planner title -->
    <div class="boardHeader">
    <div class="boardHeaderBorder">
	<h2>
<!--@if($widget_info->title)-->
	{$widget_info->title}
<!--@else-->
	{$widget_info->module_info->browser_title}
<!--@end-->
    </h2>
	</div>
    </div>
<br>

<style type="text/css">
.planner123 { 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 .saturday { color:#0000ff; }
.planner_calendar_inner li .weekday { color:#303030; }
.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; }
</style>

<div class="planner123">
    <!--//  버튼 -->
    <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 $btnlinkpath?>&amp;pOption=<?php echo $pOption?>&amp;pYear=' +this.options[this.selectedIndex].value +'&amp;pMonth=<?php echo $pMonth?>'">
			<option value='<?php echo $pYear?>'><?php echo $pYear?></option>
			<?php for ($j=$todayYY+10; $j>=$todayYY-5; $j-- ) { echo ("<option value='".$j."'>".$j."</option>"); } ?>
			</select></form>&nbsp;&nbsp;
 
            <img src="images/calendar/month_t.gif" width="39" height="15" /><a href="<?php echo $btnlinkpath?>&amp;pOption=<?php echo $pOption?>&amp;pYear=<?php echo $pYear?>&amp;pMonth=<?php echo $pMonth-1?>"><img src="images/calendar/btn_prev_year.gif" width="17" height="15" alt="전월" /></a>
            <?php
            for ($i=1; $i < 13; $i++) {
            ?>
            <a href="<?php echo $btnlinkpath?>&amp;pOption=<?php echo $pOption?>&amp;pYear=<?php echo $pYear?>&amp;pMonth=<?php echo $i?>"><img src="images/calendar/month_<?php echo $i?><?php IF($pMonth == $i){ ?>_on<?php }?>.gif" width="17" height="15" alt="<?php echo $i?>월" /></a>
            <?php
            }
            ?>
            <a href="<?php echo $btnlinkpath?>&amp;pOption=<?php echo $pOption?>&amp;pYear=<?php echo $pYear?>&amp;pMonth=<?php echo $pMonth+1?>"><img src="images/calendar/btn_next_year.gif" width="17" height="15" alt="익월" /></a>
        </div>
    </div>
    <!--//  달력 -->
    <table class="planner_calendar" summary="플래너123">
        <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++) {
        ?>
                <td <?php if($pYear == $todayYY && $pMonth == $todayMM && $Calmain[$i][$j] == $todayDD) { ?> bgcolor="{$today_bgcolor}" style="border:medium solid; border-color:{$today_bodercolor};" <?php } else { ?> bgcolor="{$day_bgcolor}"<?php } ?> onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='{$mouseover_bgcolor}'">
                <ul class="planner_calendar_inner">
                <?php
                $tmpfld_1 = null;
                $outtext = null;
                $k = $Calmain[$i][$j];
 
                if ($Calmain[$i][$j]== "*"){
                    $Calmain[$i][$j]=null;
                    echo "<li></li>";
                }
                else
                {
                    $tempday=$Calmain[$i][$j];
 
                    // --해당일의 음력일자,휴일,기념일 얻기---
                    $tmparr=explode("-",$Lunarday[$pMonth][$Calmain[$i][$j]]);  //음력날자
                    if ($tmparr[3] == "윤달") {
                        $youndal = "윤";
                    }
                    else {
                        $youndal = null;
                    }
                    $tmpfld1 ="(".$youndal.$tmparr[1]."-".$tmparr[2].")";
 
                    $tmparr4=explode("-",$Holiday[$pMonth][$Calmain[$i][$j]]);  // 공휴일
                    $tmparr5=explode("-",$Memday[$pMonth][$Calmain[$i][$j]]);   // 기념일
                    $tmparr6=explode("|#|",$arr_plan[$pMonth][$Calmain[$i][$j]]);    // 일정/플랜  1차 "|#|",로 분리
 
                    // 첫줄 --일자,음력,절기,공휴일---
                    if ($pYear == $todayYY and $pMonth == $todayMM and $Calmain[$i][$j] == $todayDD ) {
                        $outtext = "<li style='background:".$__Context->today_bgcolor.";'>";   // 당일
                    }
                    else  {
                        $outtext = "<li>";                 // 평일
                    }
 
                    if ($j==0 or $tmparr4[0] != null) {
                        $tmpfld = "<span class='holiday'>".$Calmain[$i][$j]."</span>";    // 일요일 및 휴일
                    }
                    elseif ($j==6) {
                        $tmpfld = "<span class='saturday'>".$Calmain[$i][$j]."</span>";   // 토요일
                    }
                    else  {
                        $tmpfld = "<span class='weekday'>".$Calmain[$i][$j]."</span>";  // 평일
                    }
                    
					$templink = $daylinkpath."&amp;act=dispBoardWrite" ;			// 일자 클릭시 쓰기로 이동
                    $templink .= "&amp;extra_vars1=$pYear-$tempmonth-".substr("0".$tempday,-2);   // 일정시작 값 넣기위해
                    $templink = "<a href=".$templink." class='strong font_big'>";
                    $outtext .= "&nbsp;".$templink.$tmpfld."</a>";   // 일자

					if ($id_lunar == "Y") {
						//if ($Calmain[$i][$j] != null) {								// 음력: 모든 날자 표시
						if ($tmparr[2] == 1 or $tmparr[2] == 10 or $tmparr[2] == 15 or $tmparr[2] == 20) {	// 음력: 1,10,15,20일 표시
	                     $outtext .= "&nbsp;"."<span class='lunar'>".$tmpfld1."</span>";    // 음력
						}
					}
					if ($id_holiday == "Y" and $Calmain[$i][$j] != null) {	   
		                $outtext .= "&nbsp;<span class='holiday strong'>".$tmparr4[0]."</span>"; // 공휴일
					}
                    $outtext .= "</li>";
                    echo ($outtext);

                    // 두째줄 --일정/플랜---
                    if (!empty($tmparr6[0]))
                    {
                        foreach ($tmparr6 as $val)
                        {
                            if (!$val = trim($val)) continue; // 빈어레이는 무시하고 빠진다.
                            $tmparr7=explode("~:~",$val);
                            if (!empty($tmparr7[0]))
                            {
                                //$lplan_cat = (!empty($tmparr7[5]))?"<span style='color:".$tmparr7[6].";'>[".$tmparr7[5]."] </span>":""; // 분류
								$lplan_state = null;
								if (!empty($tmparr7[4]))
								{
									$arr_icon = explode("|@|",$tmparr7[4]);
									foreach ($arr_icon as $icon)
									{
										if ($icon = trim($icon))
										{
			                                $lplan_state .= "<img src='".$xepath."modules/board/skins/".$tmparr7[9]."/images/icon/".$icon."'/>"; //일정확인
										}
									}
								}
                                //$lplan_reply = (!empty($tmparr7[7]))?"<span class='small'>[".$tmparr7[7]."]</span>":""; //댓글숫자
								$tmp_time = explode("|@|",$tmparr7[8]);		//시작종료시간
                            }
							if ($tmparr7[8]){ $time_disply_fld = "[".trim($tmp_time[0])."-".trim($tmp_time[1])."]"; } else { $time_disply_fld = null; }
                        echo "<li style='background-color:".$tmparr7[3].";'>".$lplan_state."<a href=".$tmparr7[1]." title='".$time_disply_fld." ".$tmparr7[2]."'>".trim($tmp_time[0])." ".$tmparr7[0]."</a></li>"; //시간+일정제목
                        }
                   }

				   // 셋째줄 기념일---
				   if ($id_memday == "Y" and $Calmain[$i][$j] != null) {	   
						if (!empty($tmparr5[0])) { // 기념일만 체크
                        echo "<li><span class='memorial'>".$tmparr5[0]."</span></li>"; // 기념일
						}
                    }
                }
                echo ("</ul>");
                echo ("</td>\n");
            }
            echo ("</tr>\n");
        }
        ?>
 
        </tbody>
    </table>
</div>
