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

<?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);
?>

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

<!--@if($module_info->colorset == "black")-->
	{@ $day_bgcolor=aliceblue}      <!--// 달력의 평일 칸 배경색 -->
<!--@else-->
	{@ $day_bgcolor=beige}      <!--// 달력의 평일 칸 배경색 -->
<!--@end-->

<?php 
$linkpath = $__Context->link_path;
$xepath = $__Context->XE_path;
$skinpath = $xepath."modules/sboard/skins/xe_splanner/";   // 스킨 설치 경로지정
//echo "$linkpath <br>";
//echo "$skinpath <br>";
?>

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

<?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 등은 sboard설정시 목록에 포함되어야 들어옴)  -->

<!--@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 = "";
				if($category_title)
					$outtext .= "<span style='color:".$category_color."'>[".$category_title."] </span>&nbsp;";
				$outtext .= "<span>";
				$outtext .= "<font style='font-size:10pt; background-color: ".$plan_bgcolor.";' >";
				$outtext .= "<a href=".$plan_url." title='".$plan_detail."'>".$plan_time.$plan_title."</a></font></span>&nbsp;";
				if($plan_check)
				{
					$outtext .= "<img src='images/icon/".$plan_check."'>";
				}
				$arr_plan[$j] .= $outtext.$exImg."<br/>";
			}
		}
    }
}	
?>
<!--@end-->
<tr><td>
<style type="text/css">
.splanner { clear:both; }
.splanner_qtip { width:100%; border-spacing:0; padding:0; border=1px; border-collapse:collapse; align:left; }
.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_line { border-spacing:0; padding:0; align:left; border:0px; border-collapse:collapse; margin-top:1px;}
.planner_tbl_day { border-spacing:0; padding:0; width:100%; border:1px solid; border-color:#dbdbdb; margin:0;}
</style>
<div class="splanner">
	<fieldset style ="margin:1px; padding:0; border:0" >
    <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" style="float:right;" >
			<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>
<br/>

<!-- 달력 -->

<table class='splanner_qtip'  border='1' bordercolor="#dbdbdb" cellspacing="0" cellpadding="0" >
<tr><td>
	<table cellspacing="0" cellpadding="0" width="100%" border="1" bordercolor="#dbdbdb" style="border-collapse:collapse;"  align="left">
		<tr align="center" height="25" style="font-family:tahoma;font-size:10pt;color:#666666;">
			<td width=100 align=center background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Date</td>
			<td align=center background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Schedule</td>
			<td width=118 align=center background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Note</td> 
		</tr>
	</table>
</td></tr>

<?php
$weekcount = count($Calmain);
for($i=0; $i<$weekcount; $i++) { 
/*
	echo "<tr><td><table cellspacing=0 cellpadding=0 width=100% align=left border=1 bordercolor=#dbdbdb style='border-collapse:collapse; margin-top:1px;' >";
*/
	echo "<tr><td><table class='planner_calendar_line' >";
	for ($j=0; $j<7; $j++) { 
		$tempday = $Calmain[$i][$j];
		if($tempday == 0) continue; //  달력상의 빈날제거
		if($tempday == $todayDD and $pMonth == $todayMM and $pYear == $todayYY)
            $today_flag = 1;
        else
            $today_flag = 0;
?>
  <tr>
		<td valign="top" <?php if($today_flag == 1) { ?>	style="border:2px solid;border-color:CadetBlue" <?php } ?> height="33" width="14%" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#DDFFFA'" style="word-break:break-all;padding:0px;" <?php if($j==0) echo "bgcolor=#fff0f0"; else if($j == 6) echo "bgcolor=#f0f0ff"; ?> >
	  <FONT SIZE="2" face='Georgia'>
		<table cellspacing=0 cellpadding=0 width=100% style="border:1px solid;border-color:#dbdbdb; margin:0">

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

// --해당일의 휴일 얻기---
		$tmpHoli = $aMonthHoliday[$tempday];

		
// 첫칸 첫째줄 왼쪽 --일자---

		$outtext = "<tr>";

		if($today_flag == 1)
			$outtext = $outtext."<td width=99><table width=99 cellspacing=0 cellpadding=0 border=0><tr><td width=35 align=center valign=middle >";
		else
			$outtext = $outtext."<td width=100><table width=100 cellspacing=0 cellpadding=0 border=0><tr><td width=35 align=center valign=middle >";

		if ($j==0 or $tmpHoli != null) {
			$color = "#ee2222";	// 일요일 및 휴일
		}
		elseif ($j==6) {
			$color = "#2266ee";	// 토요일
		}
		else  {
			$color = "#666666";	// 평일
		}
		$tmpfld = "<font color=".$color." style='font-size:12pt;'>".$tempday."</font>";
		$templink = getUrl(act,dispSboardWrite,'document_srl','') ;			// 일자 클릭시 쓰기로 이동
		$templink = $templink."&plan_sdate=".$pYear.$tempmonth.substr("0".$tempday,-2);
		$templink = "<a href=".$templink.">";
		$outtext .= "&nbsp;<B>".$templink.$tmpfld."</B></a>";	// 일자
		$outtext .= "</td>";
		?>

		<?php
// 첫칸 첫째줄 오른쪽 --음력/절기---

		$outtext = $outtext."<td width=65 align=left valign=top>";
		// 음력: 모든 날자 표시
		$tmpLunar = $Lunar[$tempday];
		if($tmpLunar)
		{
			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;"."<font color=maroon style='font-size:8pt;' >".$tmpfld1."</font>"; // 음력
		}

		$tmpJeolki = $aJeolki[$tempday];
		if($tmpJeolki)
		$outtext .= "&nbsp;<font color='blue' style='font-size:8pt;' >".$tmpJeolki."</font>";	// 절기

		$outtext .= "</td></tr>";

// 첫칸 두째줄 왼쪽 --요일---

		static $yoil = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		$tmpfldw = "<font color=".$color." style='font-size:8pt;font-family:tahoma;'>".$yoil[$j]."</font>";
		$outtext .= "<tr><td width=35 align=center valign=bottom >";
		$outtext .= "$tmpfldw";	// 요일
		$outtext .= "</td>";

// 첫칸 두째줄 오른쪽 --공휴일---

		$outtext = $outtext."<td width=65 align=left valign=bottom>";
		if ($tmpHoli) {
		$outtext .= "&nbsp;<font color=red style='font-size:8pt;' >".$tmpHoli."</font>"; // 공휴일
		}
		$outtext .= "</td></tr></table></td>";
		echo ($outtext);

// 두째칸 --일정/플랜---
		
		echo ("<td style='padding:1px; border-left:1px solid; border-color:#dbdbdb; font-family:times'>");

		if($arr_plan[$tempday]!= null)
		{
			echo ($arr_plan[$tempday]);
		}
		else { // 일정이 없을때 table이 깨지는것 방지
			echo "<span>&nbsp;</span>";
		}

		echo ("</td>");
		if($today_flag == 1)
			echo "<td width=117 style='border-left:1px solid; border-color:#dbdbdb'>";
		else
			echo "<td width=118 style='border-left:1px solid; border-color:#dbdbdb'>";
		
// 셋째칸 첫줄 --공휴일---
		if ($aMonthMemday[$tempday] != null)
		{
			$outtext = "<table cellspacing=0 cellpadding=0 width=112 border=0 align=left><tr><td width=112 align=right valign=top>";
			$outtext .= "</td></tr>";

// 셋째칸 두째줄 --기념일---

			$outtext = $outtext."<tr><td width=112 align=right valign=bottom>";
			$outtext = $outtext."&nbsp;<font color=darkcyan style='font-size:8pt;' >".$aMonthMemday[$tempday]."</font>"; // 기념일
			$outtext = $outtext."</td></tr></table>";
			echo ($outtext);
		}
		else {	// 기념일 또는 공휴일이 없을때 table이 깨지는것 방지
			echo "&nbsp;";
		}
		echo ("</td></tr></table></FONT></td></tr>\n");

	}
	echo ("</table></td></tr>\n");
} 
?>
</table>
	</fieldset>
</div>

<!--// 관리자로 로그인 했을경우 리스트 출력 -->
<!--@if($grant->manager)-->
<!--#include("./style.list.html")-->
<!--@end-->
<!--%load_js_plugin("qtip")-->
<script type="text/javascript">//<![CDATA[
var $j = jQuery.noConflict();
$j(document).ready(function()
{
   $j('table:.splanner_qtip a[title]').qtip({
      position: { //bottomLeft, bottomRight, bottomMiddle, topRight, topLeft, topMiddle
         corner: { //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', //cream,light,dark,red,green,blue
         padding: '7px 13px',
         width: {
            max: 250,
            min: 0
         },
         tip: true
      }
   });
});
//]]></script>
