<!--// 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. 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
----------------------------------------------------------------------- -->
{$widget_info->testfld}
<?php 
$pYear = $__Context->pYear;
$pMonth = $__Context->pMonth;
?>

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

{@ $today_bgcolor="#f0fff0"}   <!--// 달력의 당일 칸 배경색 -->
{@ $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" || $colorset == "white")-->
    <!--%import("./css/widget.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;
?>

<!--// 툴팁 박스 스크립트를 인클루드합니다 -->
<script type="text/javascript" src="<?php echo $skinpath ?>wz_tooltip/wz_tooltip.js"></script> 

<!--// -----일정관련 확장변수, 내용등 지정 ----------------------- -->
<!--@foreach($widget_info->document_list as $oDocument)-->
	{@$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)} 

	{@$option_view_arr  = $widget_info->option_view_arr}
	{@$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}
	<!--@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
	$option_view_arr = $__Context->option_view_arr;		// Display 옵션 unit

	$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;
		}
	}

	$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); // FF를 제거 textbox보이기위해
	$plan_detail = str_replace(chr(015), "", $plan_detail);		// SI을 제거 textbox보이기위해 -줄바꿈
//	$plan_detail = strip_tags($plan_detail);					// HTML tag 제거 - 줄바꿈 사용않음

	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."||";	// 어레이에 추가 1차분리자= "||", 2차 분리자 "~:~"
			}
		}
	  }
	}
}	
?>
<!--@end-->

<!--// -----달력작성 ----------------------- -->
<style type="text/css">
td .scheduled_day_bg { background-image:url("<?php echo $skinpath ?>images/icon/folder.png");  background-repeat:no-repeat; background-position:center }
</style>

<?php
$Calmain = planner_ksc_widget::fn_CalMain($pYear,$pMonth);			// 달력일자
$Holiday = planner_ksc_widget::fn_HolidayChk($pYear, $pMonth);		// 휴일
?>

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

<div class="widgetContainer<!--@if($colorset=="black")--> black<!--@end-->">
    <div class="widgetCalendarNavigation">
        <button type="button" class="prevYear" onclick="location.href='<?php echo $btnlinkpath?>&pOption=<?php echo $pOption?>&pYear=<?php echo $pYear-1?>&pMonth=<?php echo $pMonth?>'">&lt;&lt;</button> 
		<button type="button" class="prevMonth" onclick="location.href='<?php echo $btnlinkpath?>&pOption=<?php echo $pOption?>&pYear=<?php echo $pYear?>&pMonth=<?php echo $pMonth-1?>'">&lt;</button>
		<button type="button" class="nextMonth" onclick="location.href='<?php echo $btnlinkpath?>&pOption=<?php echo $pOption?>&pYear=<?php echo $pYear?>&pMonth=<?php echo $pMonth+1?>'">&gt;</button> 
		<button type="button" class="nextYear" onclick="location.href='<?php echo $btnlinkpath?>&pOption=<?php echo $pOption?>&pYear=<?php echo $pYear+1?>&pMonth=<?php echo $pMonth?>'">&gt;&gt;</button>
    </div>
    <table border="1" cellspacing="0" class="widgetCalendar">
        <caption>{$pYear." . ".$pMonth}&nbsp;&nbsp;
		<a href="<?php echo $daylinkpath?>&pOption=1&pYear=&pYear=<?php echo $pYear?>&pMonth=<?php echo $pMonth?>"><img src='images/icon/calendar2.png' /></a>
		</caption>
        <thead>
            <tr>
                <th scope="col" class="sun">{cut_str($lang->unit_week['Sunday'],2,"")}</th>
                <th scope="col">{cut_str($lang->unit_week['Monday'],2,"")}</th>
                <th scope="col">{cut_str($lang->unit_week['Tuesday'],2,"")}</th>
                <th scope="col">{cut_str($lang->unit_week['Wednesday'],2,"")}</th>
                <th scope="col">{cut_str($lang->unit_week['Thursday'],2,"")}</th>
                <th scope="col">{cut_str($lang->unit_week['Friday'],2,"")}</th>
                <th 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>");
	for ($j=0; $j<7; $j++) { 
?>

        <td <?php if($pYear == $todayYY && $pMonth == $todayMM && $Calmain[$i][$j] == $todayDD) { ?> bgcolor="{$today_bgcolor}" style="border:1px solid; border-color:{$today_bodercolor};" <?php } else { ?> bgcolor="{$day_bgcolor}"<?php } ?> onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='{$mouseover_bgcolor}'">

<?php 		
		$tmpfld_1 = null;
		$outtext = null;
		$k = $Calmain[$i][$j];

		if ($Calmain[$i][$j]== "*"){ 
			$Calmain[$i][$j]=null; 
			}
		else
		{
			$tempday=$Calmain[$i][$j];
			
// 일자 클릭시 쓰기로 이동할 주소
			$templink = $daylinkpath."&act=dispBoardWrite" ;			
			$templink = $templink."&extra_vars1=$pYear-$tempmonth-".substr("0".$tempday,-2);	// 확장변수에 값 넣는것은 잘 안됨

// --해당일의 휴일/일정자료 얻기---
			$tmparr4=explode("-",$Holiday[$pMonth][$Calmain[$i][$j]]);	// 공휴일
			$tmparr6=explode("||",$arr_plan[$pMonth][$Calmain[$i][$j]]);	// 일정/플랜  1차 "||",로 분리

// --일정 툴팁을 위하여---
			$tooltiptext = null;
			if ($tmparr6[0] != null) {
				$count = count($tmparr6);
		//		$tooltiptext = $tooltiptext."<ul>";
				for ($k = 0; $k < $count; $k++) {
					$tmparr7=explode("~:~",$tmparr6[$k]);
					if ($tmparr7[0] != null) {
					$tooltiptext = $tooltiptext."<li>";
					$tooltiptext = $tooltiptext."<a href=".$tmparr7[1].">";
					$tooltiptext = $tooltiptext.$tmparr7[0];
					$tooltiptext = $tooltiptext."</a>";
					$tooltiptext = $tooltiptext."</li>";
					}
				}
		//		$tooltiptext = $tooltiptext."</ul>";
			}

	$tooltiptext = str_replace("'", "`", $tooltiptext);			// '을 `로 대체 textbox보이기위해
	$tooltiptext = str_replace("\"", "&quot;", $tooltiptext);	// "를 &quot;로 대체 textbox보이기위해
	$tooltiptext = str_replace(chr(012), "<br />", $tooltiptext); // FF를 제거 textbox보이기위해
//	$tooltiptext = str_replace(chr(015), "<br />", $tooltiptext); // SI을 제거 textbox보이기위해 -줄바꿈
//	$tooltiptext = strip_tags($tooltiptext);					// HTML tag 제거 - 줄바꿈 사용않음

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

// --요일별 일자색---
			if ($j==0 or $tmparr4[0] != null) {
			$tmpfld = "<font color=red >".$Calmain[$i][$j]."</font>";	// 일요일 및 휴일
			}
			elseif ($j==6) {
			$tmpfld = "<font color=blue >".$Calmain[$i][$j]."</font>";	// 토요일
			}
			else  {
			$tmpfld = "<font color=black >".$Calmain[$i][$j]."</font>";	// 평일
			}
?>

<!-- 하루 출력  -->

			<?php if ($tmparr6[0] != null) { ?>
			<a href="<?php echo $templink ?>" onmouseover="Tip('<?php echo $tooltiptext ?>', DELAY, 400,  STICKY, true, CLOSEBTN, true, JUMPHORZ, true, OFFSETX, 8)" onmouseout="UnTip()"> <div class='scheduled_day_bg'><b><?php echo $tmpfld ?></b></div> </a>  <!-- 일자 일정 있을때-->
			<?php } else { ?>
				<a href="<?php echo $templink ?>"> <?php echo $tmpfld ?> </a>  <!-- 일자 -->
			<?php } ?>
<?php 
		}
		echo ("</td>");	// 하루
	}
	echo ("</tr>");		// 일주
} 
?>

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