<!--// XE ver.1.2.x 게시판을 이용한 플래너/음력달력 위젯 Mini calendar 형-----------------------
## [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.2 : Keysung Chung, 2010, 01, 25
##  - PlannerXE123 ver. 0.2 : Keysung Chung, 2009, 11, 09
##	- PlannerXE123 ver. 0.1 : Keysung Chung, 2009, 07, 28
----------------------------------------------------------------------- -->
<?php 
$pYear = $__Context->pYear;
$pMonth = $__Context->pMonth;
?>

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

{@ $today_bgcolor=yellow}   <!--// 달력의 당일 칸 배경색 -->

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

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

<!--// 날자 설정 ---------------------------------- -->
<?php 
$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;
}

$__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;
$module_info = $__Context->widget_info->module_info;
$xepath = $__Context->XE_path;
$skinpath = $tpl_path;
$widget = new splanner_widget();
$Calmain = $widget->fn_get_month_sun($pYear,$pMonth);
$days = $widget->fn_get_reg_days($pYear,$pMonth,$module_info->plan_holi_text);
if($module_info->plan_holi == 'Y')
{
	$aMonthHoliday = $widget->fn_holidays($pYear, $pMonth);  // 휴일
	if($days != null)
	{
		foreach($days as $k => $v)
			$aMonthHoliday[$k] .= $v;
		unset($days);
	}
} else
{
	if($days != null)
	{
		$aMonthHoliday = $days;
		unset($days);
	}
}
?>


<!--// -----일정관련 확장변수, 내용등 지정 ----------------------- -->
<!--@foreach($widget_info->document_list as $document)-->
    <!--// 일정 얻기 -->
	{@ $plan_title = $document->getTitle($widget_info->subject_cut_size)}
	{@ $plan_start = $document->get('plan_sdate')}
	{@ $plan_end = $document->get('plan_edate')}
	{@ $plan_period = $document->get('plan_period')}
	{@ $plan_value = $document->get('plan_value')}
	<?php
		$plan_title = $__Context->plan_title;
		$plan_start = $__Context->plan_start;
		$plan_end = $__Context->plan_end;
		$plan_period = $__Context->plan_period;
		$plan_value = $__Context->plan_value;
	?>
    {@ $nickname = $document->getNickName()}
    <?php
    $nickname = $__Context->nickname;
    ?>

<?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 )
	{
		if($plan_period)
		{
			$arr_repeat = $widget->fn_repeat_schedule($Calmain, $plan_period, $plan_value, $aMonthHoliday);
		}
		for ($j = $plnstartDD; $j <= $plnendDD; $j++ ) {
			if ( $plan_period==0 || $arr_repeat[$j] == "*") {
				if($arr_plan[$j]) $arr_plan[$j] .= '<br \>';
				$arr_plan[$j] .= "[".$nickname."]".$plan_title;
			}
		}
    }
}
?>
<!--@end-->

<!--// -----달력작성 ----------------------- -->
<?php
$__Context->pYear = $pYear;
$tempmonth = substr("0".$pMonth, -2);       //월 을 "7" 에서 "07"로
$__Context->tempMonth = $tempmonth;
if(count($_POST) > 0)
	$curr = $_POST;
else
	$curr = $_GET;
if($pMonth == 1)
{
$curr['pYear'] = $pYear - 1;
$curr['pMonth'] = 12;
} else
{
$curr['pYear'] = $pYear;
$curr['pMonth'] = $pMonth -1;
}
foreach($curr as $k => $v)
{
	if($prevM) $prevM .= '&';
	$prevM .= $k.'='.$v;
}
if($pMonth == 12)
{
$curr['pYear'] = $pYear + 1;
$curr['pMonth'] = 1;
} else
{
$curr['pYear'] = $pYear;
$curr['pMonth'] = $pMonth +1;
}
foreach($curr as $k => $v)
{
	if($nextM) $nextM .= '&';
	$nextM .= $k.'='.$v;
}
$curr['pYear'] = $pYear+1;
$curr['pMonth'] = $pMonth;
foreach($curr as $k => $v)
{
	if($nextY) $nextY .= '&';
	$nextY .= $k.'='.$v;
}
$curr['pYear'] = $pYear -1;
$curr['pMonth'] = $pMonth;
foreach($curr as $k => $v)
{
	if($prevY) $prevY .= '&';
	$prevY .= $k.'='.$v;
}
$templink = $daylinkpath."&mid=".$module_info->mid."&act=dispSboardWrite&plan_sdate=";
/*
debugPrint("info\n".print_r($__Context->widget_info->module_info,true));
debugPrint("prevM\n".print_r($prevM,true));
		<button type="button" class="prevMonth" onclick="location.href='<?php echo $btnlinkpath?>&pYear=<?php echo $pYear?>&pMonth=<?php echo $pMonth-1?>'">&lt;</button>
*/
?>

<div style='margin:20px 3px 10px 3px;' class="widgetContainer<!--@if($colorset=="black")--> black<!--@end-->">
    <div class="widgetCalendarNavigation">
        <button type="button" class="prevYear" onclick="location.href='<?php echo $__Context->XE_path?>?<?php echo $prevY?>'">&lt;&lt;</button> 
		<button type="button" class="prevMonth" onclick="location.href='<?php echo $__Context->XE_path ?>?<?php echo $prevM?>'">&lt;</button>
		<button type="button" class="nextMonth" onclick="location.href='<?php echo $__Context->XE_path?>?<?php echo $nextM ?>'">&gt;</button> 
		<button type="button" class="nextYear" onclick="location.href='<?php echo $__Context->XE_path?>?<?php echo $nextY?>'">&gt;&gt;</button>
		<button type="button" class="icon" onclick="location.href='<?php echo $daylinkpath?>&mid=<?php echo $module_info->mid; ?>&listStyle=planner&pYear=<?php echo $pYear?>&pMonth=<?php echo $pMonth?>'"> <img src='images/icon/calendar2.png' /></button>
    </div>
    <table border="0" cellspacing="0" class="widgetCalendar" >
        <caption>{$pYear." . ".$pMonth}&nbsp;&nbsp;
		</caption>
        <thead>
            <tr>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col" class="sun">{cut_str($lang->unit_week['Sunday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col">{cut_str($lang->unit_week['Monday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col">{cut_str($lang->unit_week['Tuesday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col">{cut_str($lang->unit_week['Wednesday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col">{cut_str($lang->unit_week['Thursday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0' scope="col">{cut_str($lang->unit_week['Friday'],2,"")}</th>
                <th style='border:1px solid;border-color:#e0e0e0; color:blue' scope="col">{cut_str($lang->unit_week['Saturday'],2,"")}</th>
            </tr>
        </thead>
        <tbody>

<?php 
$weekcount = count($Calmain);
for($i=0; $i<$weekcount; $i++) { 
	echo ("<tr align='center' >");
	for ($j=0; $j<7; $j++) { 
		$tempday=$Calmain[$i][$j];
		if ($pYear == $todayYY and $pMonth == $todayMM and $tempday == $todayDD ) {
			$today = 1;	// 당일
			$style = "style='border:2px solid;border-color:CadetBlue; padding:0px;'";
		}
		else  {
			$today = 0;				// 평일
			$style = "style='border:1px solid;border-color:#e0e0e0; padding:0px;'";
		}

?>

		<td valign="top" <?php echo $style; ?> onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#DDFFFA'" style="word-break:break-all;padding:0px;">

<?php 		
		$tmpfld_1 = null;
		$outtext = null;

		if ($tempday)
		{
// --해당일의 휴일/일정자료 얻기---
		$tmpHoli = $aMonthHoliday[$tempday];
		if($tmpHoli != null)
			$Holi = " title='".$tmpHoli."'";
		else $Holi = null;

// --일정 툴팁을 위하여---

// --해당일의 배경색 얻기---
			if ($pYear == $todayYY and $pMonth == $todayMM and $tempday == $todayDD ) {
			$bgcolor_output = $__Context->today_bgcolor;	// 당일
			}
			else  {
			$bgcolor_output = " ";				// 평일
			}

// --요일별 일자색---
			if($tempday < 10) $d_day = "&nbsp;&nbsp;".$tempday."&nbsp;&nbsp;";
			else $d_day = "&nbsp;".$tempday."&nbsp;";
			if ($j==0 or $tmpHoli != null) {
			$tmpfld = "<font color=red >".$d_day."</font>";	// 일요일 및 휴일
			}
			elseif ($j==6) {
			$tmpfld = "<font color=blue >".$d_day."</font>";	// 토요일
			}
			else  {
			$tmpfld = "<font color=black >".$d_day."</font>";	// 평일
			}
?>

<!-- 하루 출력  -->
	<table  align=center cellspacing="0" cellpadding="0" border="0">
<!--		<table  width=100% cellspacing="0" cellpadding="0" border="0"> -->
			<?php if ($arr_plan[$tempday] != null) { ?>
			  <tr class='splan_qtip'>
			    <td style='background:url(<?php echo $skinpath?>images/icon/circle_red.png) no-repeat center;' >
			<?php } else { ?>
			  <tr>
			    <td>
			<?php } ?>

			<?php $plan_sdate = sprintf("%04d%02d%02d",$pYear,$pMonth,$tempday);
			?>
			<?php if ($arr_plan[$tempday] != null) { ?>
			<a href="<?php echo $templink.$plan_sdate; ?>" <?php echo $Holi; ?> detail='<?php echo $arr_plan[$tempday]; ?>'> <b><?php echo $tmpfld ?></b> </a>  <!-- 일자 일정 있을때-->
			<?php } else { ?>
				<a href="<?php echo $templink.$plan_sdate; ?>"<?php echo $Holi; ?> > <?php echo $tmpfld ?> </a>  <!-- 일자 -->
			<?php } ?>

<?php 
		echo ("</td></tr></table>");
		} else {
			echo "&nbsp;";
		}
		echo ("</td>");	// 하루
	}
	echo ("</tr>");		// 일주
} 
?>

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


<!--// 툴팁 -->
<!--%load_js_plugin("qtip")-->
<!--%import("./qtip_option.js")-->
