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

<?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 = $xepath."modules/sboard/skins/xe_splanner/";   // 스킨 설치 경로지정
//echo "$linkpath <br>";
//echo "$skinpath <br>";
?>


<?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 제거 - 줄바꿈 사용않음

//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 = "<tr><td bgcolor=".$plan_bgcolor." >";
				if($plan_check)
				{
					$outtext .= "<img src='images/icon/".$plan_check."' >";
				}
/*
				$outtext .= "<font style='font-size:10pt' >"."<a href=".$plan_url." title='".$plan_detail."'>".$nickname.":".$plan_title."</a>".$exImg."</font></td></tr>";
*/
				$outtext .= "<font style='font-size:10pt' >"."<a href=".$plan_url." title='[".$nickname."]<br/>".$plan_detail."'>".$plan_title."</a></font>";
				if($plan_reply)
					$outtext .= "<font style='font-size:8pt'>[".$plan_reply."]</font>";
				$outtext .= $exImg."</td></tr>";
				$arr_plan[$j] .= $outtext;
			}
		}
    }
}	
?>
<!--@end-->
<br>
<div class="splanner">
<table class="splanner" width="100%" border="0" cellspacing="0" cellpadding="0" >
	<tr>
		<td height="28">
			<table class='splanner_hd' width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					
					<td align=right >
					
						<table border="0" cellspacing="0" cellpadding="1">
							<tr>
								<td align="left" width="200">
							  <!--//숫자형식으로 년월 표시-->
							  <FONT SIZE="4" COLOR=green><b><?php echo $pYear?>年 <?php echo $pMonth?>月&nbsp;&nbsp;(<?php echo $pYear+2333?>)</b></font>
							  <!--//영문형식으로 년월 표시-->
							  <!-- //<FONT SIZE="4" COLOR=green><b><?php echo $pMon?>&nbsp;&nbsp;<?php echo $pYear?></b></font>-->
								</td>
								<td width="80">
									<table border="0" cellspacing="0" cellpadding="0" width="70">
										<tr>
											<td>
											<a href="<?php echo $linkpath?>&pYear=<?php echo $pYear-1?>&pMonth=<?php echo $pMonth?>&listStyle=planner" title='전년'><img src="images/calendar/btn_prev_year.gif" width="17" height="15" border="0"></a></td>

											<td><img src="images/calendar/year_t.gif" width="31" height="15"></td>

											<td align="left" width= 23>
											<a href="<?php echo $linkpath?>&pYear=<?php echo $pYear+1?>&pMonth=<?php echo $pMonth?>&listStyle=planner" title='후년'>
											<img src="images/calendar/btn_next_year.gif" width="17" height="15" border="0" ></a></td>
										</tr>
									</table>
								</td>
								<td width="10"></td>

								<td><img src="images/calendar/month_t.gif" width="39" height="15"></td>
											
								<td>
								<?php if($pMonth == 1) 
										{
											$tmp_m = 12;
											$tmp_y = $pYear - 1;
										} else 
										{
											$tmp_m = $pMonth - 1;
											$tmp_y = $pYear;
										}
								?>
									<a href="<?php echo $linkpath?>&pYear=<?php echo $tmp_y?>&pMonth=<?php echo $tmp_m ?>&listStyle=planner" title='전월'><img src="images/calendar/btn_prev_year.gif" width="17" height="15" border="0" ></a></td>
						<?php 
								FOR ($i=1; $i < 13; $i++) {
						?>
								<td>
								<a href="<?php echo $linkpath?>&pYear=<?php echo $pYear?>&pMonth=<?php echo $i?>&listStyle=planner" title='<?php echo $i?>월'>
								<img src="images/calendar/month_<?php echo $i?><?php IF($pMonth == $i){ ?>_on<?php }?>.gif" width="17" height="15" border="0" ></a></td>
						<?php
								}
						?>
								<td align="left" width= 23>
								<?php if($pMonth == 12) 
										{
											$tmp_m = 1;
											$tmp_y = $pYear + 1;
										} else 
										{
											$tmp_m = $pMonth + 1;
											$tmp_y = $pYear;
										}
								?>
									<a href="<?php echo $linkpath?>&pYear=<?php echo $tmp_y?>&pMonth=<?php echo $tmp_m?>&listStyle=planner" title='익월'><img src="images/calendar/btn_next_year.gif" width="17" height="15" border="0" ></a></td>
							</tr>
						</table>					
					</td>
				</tr>
			</table>
		</td>
	</tr>
<!--// 달력 -->
	<tr>
		<td>
			<table cellspacing="0" cellpadding="0" width="100%" border="1" bordercolor="#CCCCCC" style="border-collapse:collapse"  align="left">
				<tr align="center" height="25" style="border-right:0;border-left:0;font-family:tahoma;font-size:10pt;font-weight:bold">
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png"><font color=red>Sun</font></td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Mon</td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Tue</td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Wed</td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Thu</td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png">Fri</td>
					<td width="14%" background="<?php echo $skinpath?>images/calendar/tablehd_bg.png"><font color=blue>Sat</font></td>
				</tr>
<?php 
	$weekcount = count($Calmain);
for($i=0; $i<$weekcount; $i++) { 
	echo ("<tr>");
	for ($j=0; $j<7; $j++) { 
		$tempday=$Calmain[$i][$j]; 
		if($tempday == $todayDD and $pMonth == $todayMM and $pYear == $todayYY)
			$today_flag = 1;
		else
			$today_flag = 0;
?>
		<td valign="top" <?php if($today_flag == 1) { ?>	style="border:medium solid;border-color:CadetBlue" <?php } ?> height="80" width="14%" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#DDFFFA'" style="word-break:break-all;padding:0px">
		<FONT SIZE="2">
		<table cellspacing="0" cellpadding="0" width="98%" border="0">
<?php 		
		$outtext = null;
		if($tempday)
		{

// --해당일의 음력일자,휴일,기념일 얻기---
			$tmpHoli = $aMonthHoliday[$tempday];

// 첫줄 --일자,음력,휴일---
			$outtext = "<tr>";

			if($today_flag == 1) {
				$outtext .= "<td style='background:".$__Context->today_bgcolor.";'>";   // 당일
			} else
			{
				$outtext .= "<td>";	// 평일
			}

			if ($j==0 or $tmpHoli != null) {
				$color = "red"; // 일요일 및 휴일
			} elseif ($j==6) {
				$color = "blue"; // 토요일
			} else  {
				$color = "black";	// 평일
			}
			$tmpfld = "<font color=".$color." style='font:bold 16px Georgia;'>".$tempday."</font>";
			$templink = getUrl('act','dispSboardWrite','document_srl','') ;	// 일자 클릭시 쓰기로 이동
			$templink = $templink."&plan_sdate=".$pYear.$tempmonth.substr("0".$tempday,-2);
			$templink = "<a href=".$templink.">";

			$outtext = $outtext."&nbsp;<B>".$templink.$tmpfld."</a></B>";	// 일자
			?>

			<?php 
			$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 = $outtext."&nbsp;"."<font color=maroon style='font-size:9pt' >".$tmpfld1."</font>";	// 음력
			}
			$tmpJeolki = $aJeolki[$tempday];
			if($tmpJeolki)
			$outtext .= "&nbsp;<font color='blue' style='font-size:10pt' ><b>".$tmpJeolki."</b></font>";	// 절기
			if($tmpHoli)
			$outtext .= "&nbsp;<font color=red style='font-size:10pt' ><b>".$tmpHoli."</b></font>"; // 공휴일

			if($j == 1)	// 월요일
			{
				$tmp_flag = 0;
				if($pYear >= 2010)
				{
					if($pYear < $todayYY)
					{
						$tmp_flag = 1;
					} else if($pYear == $todayYY)
					{
						if($pMonth < $todayMM)
						{
							$tmp_flag = 1;
						} else if($pMonth == $todayMM)
						{
							if($tempday < $todayDD)
								$tmp_flag = 1;
						}
					}
				}
/*
				for($k=0;$k<7;$k++)
				{
					if(($tempday + $k) > 31) break;
					if($atimecard[$tempday + $k])
					{
						$tmp_flag = 1;
						break;
					}
				}
*/
				if($tmp_flag == 1)
				{
					$tmp_sdate = $pYear * 10000 + $pMonth * 100 + $tempday;
			$outtext .= "<font color=red style='font-size:10pt' >&nbsp;<a href=/?mid=download&sdate=".$tmp_sdate."><b>근태수정</b></font>";
				}
			}
			$outtext .= "</td></tr>";
			echo ($outtext);

// 두째줄 --기념일---
			if ($aMonthMemday[$tempday] != null) {
				$outtext = "<tr><td >";
				$outtext .= "&nbsp;<font color=darkcyan style='font-size:10pt' >".$aMonthMemday[$tempday]."</font>"; // 기념일
				$outtext .= "</td></tr>";
				echo ($outtext);
			}
// 세째줄 --근태--
			if ($atimecard[$tempday] != null) {
				echo ($atimecard[$tempday]);
			}
// 세째줄 --휴가--
			if ($aVacation[$tempday] != null) {
				echo ($aVacation[$tempday]);
			}

// 세째줄 --일정/플랜---
			if ($arr_plan[$tempday]!= null) {
				echo ($arr_plan[$tempday]);
			}

		}
		echo ("</table></FONT></td>");
	}
	echo ("</tr>");
} 
?>
</table>

</td>
</tr>
</table>
</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 a[title]').qtip({
      position: { //bottomLeft, bottomRight, bottomMiddle, topRight, topLeft, topMiddle
         corner: { //leftMiddle, leftTop, leftBottom, rightMiddle, rightBottom, rightTop
            target: 'topMiddle', //일정의 어느부분에 툴팁을 위치하는지를 정한다
            tooltip: 'bottomMiddle' //툴팁박스의 어느부분이 위치하는지를 정한다
		  }
      },
      style: {
         name: 'green', //cream,light,dark,red,green,blue
         padding: '7px 13px',
         width: {
            max: 250,
            min: 0
         },
         tip: true
      }
   });
});
//]]></script>

