TIP게시판

제목 고영창님의 만세력
글쓴이 darkninja 작성시각 2023/01/10 11:04:17
댓글 : 0 추천 : 0 스크랩 : 0 조회수 : 10918   RSS

아직 구정은 멀었지만 초보분들에게 유용했으면 하는? 설날 선물입니다

(제가 코딩한 달력소스는 오류가 있을수 있습니다, 소스를 완전히 이해하고 만든게 아니라서)

내일부터는 여태 미뤄둔 본업인 서툰 농사일을 시작해야 하기에

ci 공부는 다음에 또 ...

 

도움 받은 곳

https://link2me.tistory.com/1545

http://oops.org/project/manse/

http://www.responsivegridsystem.com/calculator/

http://afnmp3.homeip.net/~kohyc/calendar/index.cgi

소스 구하는 곳

https://github.com/OOPS-ORG-PHP/Lunar

Lunar.php * import myException class

http://pear.oops.org/package/myException

https://github.com/OOPS-ORG-PHP/myException/

 


<!DOCTYPE html>

<head>
	<title>태양태음력</title>

<style>
p { 
	margin: 2px 0px 2px 0px; 
    padding:3px;
}

textarea {
    border:1px solid #999999;
    margin: 0px 0px 0px 0px;
    padding:3px;
}

.span1_7,
.span2_7,
.span3_7,
.span4_7,
.span5_7,
.span6_7,
.span7_7 {
	margin:0;clear:none;float:left;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;*behavior:url(boxsizing.htc)
}

.span1_12,
.span2_12,
.span3_12,
.span4_12, 
.span5_12, 
.span6_12, 
.span7_12, 
.span8_12, 
.span9_12, 
.span10_12,
.span11_12,
.span12_12 {
	margin:0;clear:none;float:left;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;*behavior:url(boxsizing.htc)
}

.span1_7 { width: 14.28%; }
.span2_7 { width: 28.57%; }
.span3_7 { width: 42.85%; }
.span4_7 { width: 57.14%; }
.span5_7 { width: 71.42%; }
.span6_7 { width: 85.71%; }
.span7_7 { width: 100%; }

.span1_12 {	width: 8.333%; }
.span2_12 {	width: 16.66%; }
.span3_12 {	width: 25%; }
.span4_12 {	width: 33.33%; }
.span5_12 {	width: 41.66%; }
.span6_12 {	width: 50%; }
.span7_12 {	width: 58.33%; }
.span8_12 {	width: 66.66%; }
.span9_12 {	width: 75%; }
.span10_12 { width: 83.33%; }
.span11_12 { width: 91.66%; }
.span12_12 { width: 100%; }

/*  SECTIONS  */
.section {
	clear: both;
	padding: 0px;
    margin-top: 0px;
    margin-left: 0px;	
    margin-right: 0px;
    margin-bottom: 0px;
}

/*  COLUMN SETUP top, right, bottom, left */
.section .col {
	display: block;
	float:left;
	margin: 0;
    padding-top: 8px;
    padding-left: 6px;	
    padding-right: 0px;
    padding-bottom: 0px;
	border: 1px solid #aaa;
	line-height: 115%;
}
.col:first-child { margin-left: 0; }

/*  GROUPING  */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }


/*  GO FULL WIDTH BELOW 480 PIXELS */
@media only screen and (max-width: 480px) {
	.col {  margin: 0 0 0 0; }
	.span1_7, .span2_7, .span3_7, .span4_7, .span5_7, .span6_7, .span7_7 { width: 100%; }
    .span1_12, .span2_12, .span3_12, .span4_12, .span5_12, .span6_12, .span7_12, .span8_12, .span9_12, .span10_12, .span11_12, .span12_12 {	width: 100%; }
}

.calendar-title {
	background-color : #7799AA;
}	

.col.week {
	background-color: #2579cf;
}

.days-info.active {
	background-color : #BBEEFF;
}	

.days-info.smallmoon {
	background-color : #EEFFAA;
}	
		
.days-info.largemoon {
	background-color : #FFFF99;
}	

.days-info.season24 {
	background-color : #AA99FF;
}	

.schedule_form_div.active {
	background-color : #BBEEFF;
}

.schedule_check_div.active {
	background-color : #99AACC;
}
.weekscheck_div.active {
	background-color : #99AACC;
}

font.calendar  {font-family: tahoma; font-size: 22px; color: #ffffff; }
font.week      {font-family: tahoma; font-size: 12pt; color: #ffffff; }

font.holy      {font-family: tahoma; font-size: 25px; color: #CC1133; } /*ff6c21*/
font.black     {font-family: tahoma; font-size: 25px; color: #000000; }
font.blue      {font-family: tahoma; font-size: 25px; color: #0000ff; }
font.gray      {font-family: tahoma; font-size: 15px; color: #bbbbbb; }

font.su28      {font-family: tahoma; font-size: 14px; color: #424242; }
font.lunarday  {font-family: tahoma; font-size: 14px; color: #0000bb; }
font.gangi     {font-family: tahoma; font-size: 14px; color: #424242; }

font.holiname  {font-family: tahoma; font-size: 14px; color: #ff0000; }
font.season24s {font-family: tahoma; font-size: 14px; color: #0000ff; }
font.schedule  {font-family: tahoma; font-size: 14px; color: #0000ff; }
font.memorial  {font-family: tahoma; font-size: 14px; color: #0000ff; }
</style>

</head>

<body>

<?php
	//도움 받은 곳
    //https://link2me.tistory.com/1545
	//http://oops.org/project/manse/
	//http://www.responsivegridsystem.com/calculator/
	//http://afnmp3.homeip.net/~kohyc/calendar/index.cgi

	//소스 구하는 곳
    //https://github.com/OOPS-ORG-PHP/Lunar
    //Lunar.php * import myException class
    //http://pear.oops.org/package/myException
	//https://github.com/OOPS-ORG-PHP/myException/

	require_once 'Lunar.php';

	$lunar = new oops\Lunar();

	function ErrorMsg($msg) 
	{
		echo " <script>window.alert('$msg');history.go(-1);</script>";
		exit;
	}

	function tolunar($cdate, $c=false) 
	{
		global $lunar;
		
		$o = $lunar->tolunar($cdate);
		
		if ($c)
			return $o->year.'-'.$o->month.'-'.$o->day;
		else	
			return $o;
	}

	function tosolar($cdate, $c=false) 
	{
		global $lunar;
		
		$o = $lunar->tosolar($cdate);
		
		if ($c)
			return $o->year.'-'.$o->month.'-'.$o->day;
		else	
			return $o;
	}

	// 앙력 날짜의 요일을 리턴 일요일 0 토요일 6
	function isweekend($cdate)
	{
		//$time = mktime(0, 0, 0, $month, $day, $year);
		//$weekday = date('w', $time);
		//return $weekday; //($weekday == 0 || $weekday == 6);

		return date("w", strtotime($cdate));
	}

		//---- 오늘 날짜
		date_default_timezone_set('Asia/Seoul');
		$thisyear = date('Y'); // 4자리 연도
		$thismonth = date('n'); // 0을 포함하지 않는 월
		$today = date('j'); // 0을 포함하지 않는 일

// $year, $month 값이 없으면 현재 날짜
$year = isset($_GET['year']) ? $_GET['year'] : $thisyear;
$month = isset($_GET['month']) ? $_GET['month'] : $thismonth;
$day = isset($_GET['day']) ? $_GET['day'] : $today;

		if ( $year < -2000 ) {
			$year = -2000;
			$ErrorMsg("-2000년 이전은 웹에서 사용하는 것을 권장하지 않음.");
		}	
		else if ( $year > 2300 ) {
			$year = 2300;
			$ErrorMsg("2300년 이후는 웹에서 사용하는 것을 권장하지 않음.");
		}
		// 1391-02-05 ~ 2050-12-31 까지는 KASI data로 처리를 한다.

	   /*
		* Lunar 1.0.0에서는 is_leap method가 연도만으로 율리우스력
		* 판단을 하지 않으며로 아래과 같이 조건을 체크해야 한다.
		* if ( $lunar->is_leap ($year, $year < 1583 ? true : false) )
		* Lunar 1.0.1 부터는 2번째 인자가 없어도, 연도만으로
		* 율리우스력 판단을 한다.
		*/
		$lastdayofmonth = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		if ( $lunar->is_leap($year) )
			$lastdayofmonth[2] = 29;
		
		// 해당월의 총일수 구하기
		$lastday = $lastdayofmonth[(int) $month];
		//$lastday = date('t', mktime(0, 0, 0, $month, 1, $year)); 

		$scheduledays = array();

		$schedule_empty = array(
			'id' => '',
			'subject' => '',
			'contents' => '',
			'time' => '',
			'repeat' => 'once',
			'type' => 'none',
			'alarm' => 'none',
			'schedule_lunar' => 'solar',
			'schedule_month' => 0,
			'schedule_day' => 0,
			'schedule_check' => 0,
			'weekday' => 'none',
			'weeksdate' => 'none',
			'weeksmonth' => 0,
			'weekscheck' => 0,
			'start_date' => '',
			'end_date' => '',
		);	
		$schedule_11 = array(
			'id' => '',
			'subject' => '설날',
			'contents' => '설날 새로운 일정을 입력하세요',
			'time' => '',
			'repeat' => 'once',
			'type' => 'day',
			'alarm' => 'none',
			'schedule_lunar' => 'solar',
			'schedule_month' => 1,
			'schedule_day' => 1,
			'schedule_check' => 1,
			'weekday' => 'none',
			'weeksdate' => 'none',
			'weeksmonth' => 0,
			'weekscheck' => 0,
			'start_date' => '2023-01-1',
			'end_date' => '2023-01-1',
		);	
		$schedule_122 = array(
			'id' => '',
			'subject' => '진짜 설날',
			'contents' => '진짜 설날 새로운 일정을 입력하세요',
			'time' => '',
			'repeat' => 'once',
			'type' => 'day',
			'alarm' => 'none',
			'schedule_lunar' => 'solar',
			'schedule_month' => 1,
			'schedule_day' => 22,
			'schedule_check' => 1,
			'weekday' => 'none',
			'weeksdate' => 'none',
			'weeksmonth' => 0,
			'weekscheck' => 0,
			'start_date' => '2023-01-21',
			'end_date' => '2023-01-24',
		);	

		$holidays = array();

		$holidays[1][1] = '신정';
		$holidays[3][1] = '삼일절';
		$holidays[5][5] = '어린이날';
		$holidays[6][6] = '현충일';
		$holidays[8][15] = '광복절';
		$holidays[10][3] = '개천절';
		$holidays[10][9] = '한글날';
		$holidays[12][25] = '성탄절';

		$o = tosolar($year."-1-1");
		$t1 = strtotime($o->year.'-'.$o->month.'-'.$o->day) - (3600 * 24);
		$t2 = strtotime($o->year.'-'.$o->month.'-'.$o->day);
		$t3 = strtotime($o->year.'-'.$o->month.'-'.$o->day) + (3600 * 24);
		$holidays[date("n", $t1)][date("j", $t1)] = '';
		$holidays[date("n", $t2)][date("j", $t2)] = '설날';
		$holidays[date("n", $t3)][date("j", $t3)] = '';
		
		$o = tosolar($year."-4-8");
		$t = strtotime($o->year.'-'.$o->month.'-'.$o->day);
		$holidays[date("n", $t)][date("j", $t)] = '석가탄신일';
		
		$o = tosolar($year."-8-15");
		$t1 = strtotime($o->year.'-'.$o->month.'-'.$o->day) - (3600 * 24);
		$t2 = strtotime($o->year.'-'.$o->month.'-'.$o->day);
		$t3 = strtotime($o->year.'-'.$o->month.'-'.$o->day) + (3600 * 24);
		$holidays[date("n", $t1)][date("j", $t1)] = '';
		$holidays[date("n", $t2)][date("j", $t2)] = '추석';
		$holidays[date("n", $t3)][date("j", $t3)] = '';

		// 설날 대체공휴일 검사
		if ((isweekend(tosolar($year."-1-1", true)) == 0) || 
            (isweekend(tosolar($year."-1-1", true)) == 6) ||
		    (isweekend(tosolar($year."-1-2", true)) == 0)) 
		{
			$o = tosolar($year."-1-3");
			$holidays[$o->month][$o->day] = '대체공휴일';
		}	

		// 어린이날 대체공휴일 검사 : 어린이날은 토요일, 일요일인 경우 그 다음 평일을 대체공유일로 지정
		if (isweekend($year."-5-5") == 0) {
			$holidays[5][6] = '대체공휴일';
		}	
		if (isweekend($year."-5-5") == 6) {
			$holidays[5][7] = '대체공휴일';
		}	

		// 추석 대체공휴일 검사
		if ((isweekend(tosolar($year."-8-14", true)) == 0) || 
            (isweekend(tosolar($year."-8-15", true)) == 0) ||
		    (isweekend(tosolar($year."-8-16", true)) == 0)) 
		{
			$o = tosolar($year."-8-17");
			$holidays[$o->month][$o->day] = '대체공휴일';
		}	

		$memorialdays = array();
		$memorialdays[1][8] = '쉬는날';
		$memorialdays[1][15] = '노는날';

		//echo "<xmp>";
		//var_dump($season);
		//echo "</xmp>";

		$cyear = $year;
		$cmonth = $month;
		$cday = 1;
		$cdate = $cyear.'-'.$cmonth.'-'.$cday;

		$season = $lunar->seasondate ($cdate);
		$tune_day = $lunar->dayfortune($cdate);

		$fday = $lunar->tolunar($cdate);
		$lyear = $fday->year;
		$lmonth = $fday->month;
		$lday = $fday->day;
		
		$ly = array();
		$lm = array();
		$ld = array();
		$l28su = array();
		$y_liljin = array();
		$m_liljin = array();
		$d_liljin = array();
		$largemonth = array();
		$s28day = '';
		
		for ( $i=0; $i<$lastday; $i++ ) {
			$chk = false;

            //음력날짜 lyear, lmonth, lday
			if ( $fday->largemonth ) {
				if ( $lday > 30 ) {
					$lmonth = preg_replace ('/[^0-9]/', '', $fday->month);
					$lmonth ++;
					if ( $lmonth > 12 ) {
						$lyear ++;
						$lmonth -= 12;
					}	
					$lday -= 30;
					$chk = true;
				}
			} else {
				if ( $lday > 29 ) {
					$lmonth = preg_replace ('/[^0-9]/', '', $fday->month);
					$lmonth ++;
					if ( $lmonth > 12 ) {
						$lyear ++;
						$lmonth -= 12;
					}	
					$lday -= 29;
					$chk = true;
				}
			}

			//양력날짜 cyear, cmonth, cday
			if ( ($i + 1) > $lastdayofmonth[(int) $cmonth] ) {
				$cmonth = $cmonth + 1;
				if ($cmonth == 13) {
					$cmonth = 1;
					$cyear = $cyear + 1;
				}	
				$cday = ($i + 1) - $lastdayofmonth[$cmonth];
			} else {
				$cday = $i + 1;
			}

			$cdate = str_pad($cyear,4,"0",STR_PAD_LEFT)."-".str_pad($cmonth,2,"0",STR_PAD_LEFT)."-".str_pad($cday,2,"0",STR_PAD_LEFT);

			//read schedule data
			//$scheduledays[$cmonth][$cday] = $this->schedule_model->get_datetime($cdate); 

			if ($cdate == "2023-01-01") 
				$s = (object) $schedule_11;
			else if ($cdate == "2023-01-21" || $cdate == "2023-01-22" || $cdate == "2023-01-23" || $cdate == "2023-01-24") 
				$s = (object) $schedule_122;
			else 
				$s = (object) $schedule_empty;
			$scheduledays[$cmonth][$cday] = $s; 

			if ( $chk ) {
				if ( $season->center->month != $cmonth ) {
					$season = $lunar->seasondate ($cdate);
				}	
				$fday = $lunar->tolunar ($cdate);

				$lyear = $fday->year;
				$lmonth = $fday->month;
				$lday = $fday->day;

				$chk == false;
			}

			if ( $fday->largemonth ) 
				$largemonth[] = true;
			else	
				$largemonth[] = false;

			$ly[] = $lyear;
			$lm[] = ($fday->leap ? '(閏)' : '').$lmonth;
			$ld[] = $lday;
	
			$s28day = $lunar->s28day($cdate);
			$l28su[] = "(".$s28day->h.")";

			$tune_ym = $lunar->dayfortune(date("Y-m-d", strtotime($cdate)));
			$y_liljin[] = $tune_ym->hyear;
			$m_liljin[] = $tune_ym->hmonth;

			$d_gindex = $tune_day->data->d + $i;
			if ( $d_gindex >= 60 )
				$d_gindex -= 60;
			$d_liljin[] = $lunar->ganji_ref($d_gindex, true);

			$lday++;
		}

		$prevmonth = $month - 1;
		$nextmonth = $month + 1;
		$prevyear = $nextyear = $year;
		if ($month == 1) {
			$prevmonth = 12;
			$prevyear = $year - 1;
		} 
		elseif ($month == 12) {
			$nextmonth = 1;
			$nextyear = $year + 1;
		}
		$prev_year = $year - 1;
		$next_year = $year + 1;

		$view_data = array(
		    'year' => $year,
		    'month' => $month,
			'today' => $today,
		    'thisyear' => $thisyear,
		    'thismonth' => $thismonth,
		    'prev_year' => $prev_year,
		    'prevyear' => $prevyear,
		    'prevmonth' => $prevmonth,
		    'nextyear' => $nextyear,
		    'nextmonth' => $nextmonth,
		    'next_year' => $next_year,
		    'lastday' => $lastday,
			'ly' => $ly,
			'lm' => $lm,
			'ld' => $ld,
			'y_liljin' => $y_liljin,
			'm_liljin' => $m_liljin,
			'd_liljin' => $d_liljin,
			'l28su' => $l28su,
			'holidays' => $holidays,			
			'memorialdays' => $memorialdays,			
			'scheduledays' => $scheduledays,			
			'season' => $season,
			'lunar' => $lunar,
			'largemonth' => $largemonth,
		);
		
	function SkipOffset($no, $sdate = '', $edate = '') 
	{
		for ($i = 1; $i <= $no; $i++) {
			$ck = $no - $i + 1;
			if ($sdate)
				$num = date('n.j', $sdate - (3600 * 24) * $ck);
			if ($edate)
				$num = date('n.j', $edate + (3600 * 24) * ($i - 1));
			echo "<div class='col span1_7 days' valign='top'><font class='gray'>$num</font></div>";
		}
	}

	function CalendarPrint($day, $style, $s28, $lunarday, $gangi, $holiname, $memorialname, $schedulename, $season24s) 
	{
		echo "<a href='' class='ahref'>".
		     "<font class=".$style.">".$day."</font></a>".
		     "<font class='lunarday'> $lunarday</font>".
			 "<font class='su28'> $s28</font><br/>";
			 
		echo "<font class='gangi'>$gangi</font><br/>";
		echo "<font class='season24s'>$season24s</font><br/>";
		echo "<font class='holiname'>$holiname</font><br/>";
		echo "<font class='memorial'>$memorialname</font><br/>";
		echo "<font class='schedule'>$schedulename->subject</font>";
	}
	
	$path = "";
?>

<div class="group">
	<div class="col span9_12">
		<div class="section group">
			<div align="center" class="col span1_7 calendar-title">
				<font class="calendar"> </font>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<font class="calendar"> </font>
			</div>
			<div align="center" class="col span3_7 calendar-title">
				<font class="calendar">Lunar Calendar</font>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<font class="calendar"> </font>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<font class="calendar"> </font>
			</div>
		</div>

		<div class="section group">
			<div align="center" class="col span1_7 calendar-title">
				<a href="<?php echo $path.'calendar.php?year='.$prev_year.'&month='.$month.'&day=1'; ?>"><font class="calendar"> ◀◀ </font></a>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<a href="<?php echo $path.'calendar.php?year='.$prevyear.'&month='.$prevmonth.'&day=1'; ?>"><font class="calendar"> ◀ </font></a>
			</div>
			<div align="center" class="col span3_7 calendar-title">
				<a href="<?php echo $path.'calendar.php?=yeay='.$thisyear.'&month='.$thismonth.'&day=1'; ?>">
					<font class="calendar"><?php echo " ".$year . '년 '; ?></font>
					<font class="calendar"><?php echo " ".$month . '월 '; ?></font>
					<font class="calendar"><?php echo " ".$today . '일 '; ?></font>
				</a>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<a href="<?php echo $path.'calendar.php?year='.$nextyear.'&month='.$nextmonth.'&day=1'; ?>"><font class="calendar"> ▶ </font></a>
			</div>
			<div align="center" class="col span1_7 calendar-title">
				<a href="<?php echo $path.'calendar.php?year='.$next_year.'&month='.$month.'&day=1'; ?>"><font class="calendar"> ▶▶ </font></a>
			</div>
		</div>

		<div class="section group">
			<div align="center" class="col span1_7 week"><font class="week">일</font></div>
			<div align="center" class="col span1_7 week"><font class="week">월</font></div>
			<div align="center" class="col span1_7 week"><font class="week">화</font></div>
			<div align="center" class="col span1_7 week"><font class="week">수</font></div>
			<div align="center" class="col span1_7 week"><font class="week">목</font></div>
			<div align="center" class="col span1_7 week"><font class="week">금</font></div>
			<div align="center" class="col span1_7 week"><font class="week">토</font></div>
		</div>

		<div class='section group'>
		<?php
			$day = 1;
			$offset = 0;
			$ck_row = 0;

			$gangi_temp = $y_liljin[$day-1].' '.$m_liljin[$day-1];

			// 시작 요일 구하기 : date("w", strtotime($year."-".$month."-01"));
			$offset = date('w', mktime(0, 0, 0, $month, $day, $year)); // 0: 일요일, 6: 토요일
			SkipOffset($offset, mktime(0, 0, 0, $month, $day, $year));
	
			while ($day <= $lastday) 
			{
				if ($offset == 0)
					$style = "holy"; // 일요일 빨간색으로 표기
				else if($offset == 6)
					$style = "blue"; // 토요일 빨간색 또는 파란색
				else
					$style = "black";

				//28수
				$s28 = $l28su[$day-1];

				$gangi_ym = $y_liljin[$day-1].' '.$m_liljin[$day-1];

				//세차 월건 일진 표시 (1일, 음력1일,15일 월건값이 바뀔때)	
				if ($day == 1 || $ld[$day-1] == 1 || $ld[$day-1] == 15 || $gangi_ym != $gangi_temp) {
					$gangi_temp = $gangi_ym;
					$lunarday = $lm[$day-1].'.'.$ld[$day-1]; //年月日
					$gangi = $y_liljin[$day-1].' '.$m_liljin[$day-1].' '.$d_liljin[$day-1];
					if($gangi_ym != $gangi_temp)
						$gangi .= '***';
				}	
				else {
					// 음력 일자 및 간지 데이터
					$lunarday = $lm[$day-1].'.'.$ld[$day-1]; //年月日
					$gangi = $y_liljin[$day-1].' '.$m_liljin[$day-1].' '.$d_liljin[$day-1];
				}	

				// 법적 공휴일
				$holiname = false;
				if (isset($holidays[$month][$day])) {
					$style = "holy";
					$holiname = $holidays[$month][$day];
				}	

				// 기념일
				$memorialname = false;
				if (isset($memorialdays[$month][$day])) {
					$style = "holy";
					$memorialname = $memorialdays[$month][$day];
				}	

				// 사용자 일정 데이터
				$schedulename = false;
				if (isset($scheduledays[$month][$day])) {
					$style = "holy";
					$schedulename = $scheduledays[$month][$day];
				}	

				//24절기
				$season24s = false;
				if ($season->center->month == $month && $season->center->day == $day)
					$season24s = $season->center->name."(".$season->center->hname.")";
				if ($season->ccenter->month == $month && $season->ccenter->day == $day)
					$season24s = $season->ccenter->name."(".$season->ccenter->hname.")";
				if ($season->nenter->month == $month && $season->nenter->day == $day)
					$season24s = $season->nenter->name."(".$season->nenter->hname.")";

				//$sqltimestamp = $year."-".$month."-".$day." 00:00:00";
				//$unixtimestamp  = strtotime($sqltimestamp);
				//$id = date('Y-m-d\TH:i', $unixtimestamp);
				//$id = $year."-".$month."-".$day;

				//달력의 날짜들(1일부터 말일까지)들의 id
				$id = str_pad($year, 4, "0", STR_PAD_LEFT)."-".  
					str_pad($month, 2, "0", STR_PAD_LEFT)."-".  
					str_pad($day, 2, "0", STR_PAD_LEFT);  
			
				if ($year == $thisyear && $month == $thismonth && $day == $today) { 
					echo "<div class='col span1_7 days-info active' valign='top' id='".$id."'>";
				}	
				else {
					if ($season24s)
						echo "<div class='col span1_7 days-info season24' valign='top' id='".$id."'>";
					else if (($ld[$day-1] == 1) || ($ld[$day-1] == 15)) {
						if ($largemonth[$day-1])
							echo "<div class='col span1_7 days-info largemoon' valign='top' id='".$id."'>";
						else
							echo "<div class='col span1_7 days-info smallmoon' valign='top' id='".$id."'>";
					}	
					else
						echo "<div class='col span1_7 days-info' valign='top' id='".$id."'>";
				}	
				
				CalendarPrint($day, $style, $s28, $lunarday, $gangi, $holiname, $memorialname, $schedulename, $season24s);
				echo "</div>"; //close col span

				$offset++;
				//다음줄 넘김
				if ($offset == 7) {
					$offset = 0;
					echo "</div>"; //close section group
					//말일이 아니라면 다음줄 시작
					if ($day < $lastday) {
						echo "<div class='section group'>";
						$ck_row++;
					}
				}
						
				$day++; // 날짜 증가
			}

			//줄의 끝(토요일)에서 끝난 것이 아니라면
			if ($offset != 0) {
				SkipOffset((7 - $offset), '', mktime(0, 0, 0, $month + 1, 1, $year));
				echo "</div>"; //close section group
			}
		?>
	</div>

	<div class="col span3_12">
		<div class="section group">
		<div id="schedule_form_div" class="schedule_form_div">
			<form id="schedule" name="schedule">
				<p><strong><span id="schedule_form_title">일정 입력</span></strong> (type/repeat/alarm)</p>

				<p><input type="text" id="subject" name="subject" size="60" style="width: 98%" placeholder="새로운 일정을 입력하세요."></p>
				<p><textarea id="contents" name="contents" rows="10" style="width: 98%" placeholder="contents"></textarea><p>
				<p><input type="time" id="time" name="time"> 알림시간</p>

				<p><strong>repeat / type / alarm</strong></p>
				<p>
					<select id="repeat" name="repeat">
						<option value="once">once</option>
						<option value="repeat">repeat</option>
					</select>
					<select id="type" name="type">
						<option value="none">none</option>
						<option value="day">day</option>
						<option value="week">week</option>
						<option value="month">month</option>
						<option value="year">year</option>
					</select>
					<select id="alarm" name="alarm">
						<option value="none">none</option>
						<option value="once">once</option>
						<option value="repeat">repeat</option>
					</select>
				</p>
				
				<div id="schedule_check_div" class="border schedule_check_div">
				<p><strong>lunar / month / day / time / check</strong></p>
				<p>
					<select id="schedule_lunar" name="schedule_lunar">
						<option value="solar">solar</option>
						<option value="lunar">lunar</option>
					</select>
					<input type="number" name="schedule_month" id="schedule_month" min="00" max="12">
					<input type="number" name="schedule_day" id="schedule_day" min="00" max="31">
					<select id="schedule_check" name="schedule_check" onchange="schedule_check_onchange(this);">
						<option value=0>none</option>
						<option value=1>active</option>
						<option value=-1>disable</option>
					</select>
				</p>
				</div>
				
				<div id="weekscheck_div" class="border weekscheck_div">
				<p><strong>day / weeksdate / month / check</strong></p>
				<p>
					<select id="weekday" name="weekday">
						<option value="none">none</option>
						<option value="all">all</option>
						<option value="일요일">일요일</option>
						<option value="월요일">월요일</option>
						<option value="화요일">화요일</option>
						<option value="수요일">수요일</option>
						<option value="목요일">목요일</option>
						<option value="금요일">금요일</option>
						<option value="토요일">토요일</option>
					</select>
					<select id="weeksdate" name="weeksdate">
						<option value="none">none</option>
						<option value="all">all</option>
						<option value="first">first</option>
						<option value="second">second</option>
						<option value="third">third</option>
						<option value="fourth">fourth</option>
						<option value="fifth">fifth</option>
					</select>
					<input type="number" name="weeksmonth" id="weeksmonth" min="00" max="12">
					<select id="weekscheck" name="weekscheck" onchange="weekscheck_onchange(this);">
						<option value=0>none</option>
						<option value=1>active</option>
						<option value=-1>disable</option>
					</select>
				</p>
				</div>
				<p><input type="date" id="start_date" name="start_date"> 일정시작일</p>
				<p><input type="date" id="end_date" name="end_date"> 일정종료일</p>
				<p>	
					<button type="button" id="schedule_read">읽기</button>
					<button type="button" id="schedule_insert">등록</button>
					<button type="button" id="schedule_update">수정</button>
					<button type="button" id="schedule_delete">삭제</button>
				</p>
			</form>
		</div>
		</div>
		<div id="ajaxinfo" name="ajaxinfo">ajaxinfo </div>
		<div id="disp_msg" name="disp_msg">disp_msg </div>
	</div>
</div>

<!--script type="text/javascript" src="jquery-1.11.1.min.js"></script-->

<script type="text/javascript">

	function ajaxinfo(msg){
		document.getElementById("ajaxinfo").textContent = msg;
		document.getElementById("ajaxinfo").innerText = msg;
	}

	function disp_msg(msg){
		document.getElementById("disp_msg").textContent = msg;
		document.getElementById("disp_msg").innerText = msg;
	}

	function sortNumber(a,b) {
		if (a > b) return -1;
		else if (b > a) return 1;
		else return 0;	
	}

	function element_has_class(items, className) 
	{
		//alert(JSON.stringify(items));
		for(var i = 0; i < items.length; i++) {
			var classlist = items[i].classList;
			for(var j = 0; j < classlist.length; j++) {
				if (classlist[j] == className) {
					return items[i];
				}
			}	
		}
		return false;
	}

    //목록에서 같은 클래스 이름을 가지고 있는 구성원을 전부 구해서 배열로 반환
	function elements_has_class(items, className) {
		var ret_elements = [];
		for(var i = 0; i < items.length; i++) {
			var classlist = items[i].classList;
			for(var j = 0; j < classlist.length; j++) {
				if (classlist[j] == className) {
					ret_elements.push(items[i]);
				}
			}	
		}
		return ret_elements;
	}

	function schedule_read(schedule_date, msg=""){

		var js_data = false;
		var schedule = false;

		disp_msg(msg);

        if (schedule_date == "2023-01-01") {
			js_data = '<?php echo json_encode($schedule_11); ?>';
			schedule = JSON.parse(js_data );
		}
		else if (schedule_date == "2023-01-21" || schedule_date == "2023-01-22" || schedule_date == "2023-01-23" || schedule_date == "2023-01-24") {
			js_data = '<?php echo json_encode($schedule_122); ?>';
			schedule = JSON.parse(js_data );
		}
		else {
			js_data = '<?php echo json_encode($schedule_empty); ?>';
			schedule = JSON.parse(js_data );
		}	
		//alert(JSON.stringify(schedule));

		//document.forms['schedule']['schedule_id'].value = schedule.id;
		document.forms['schedule']['subject'].value = schedule.subject;
		document.forms['schedule']['contents'].value = schedule.contents;
		document.forms['schedule']['time'].value = schedule.time;

		document.forms['schedule']['repeat'].value = schedule.repeat;
		document.forms['schedule']['type'].value = schedule.type;
		document.forms['schedule']['alarm'].value = schedule.alarm;

		document.forms['schedule']['schedule_lunar'].value = schedule.schedule_lunar;
		document.forms['schedule']['schedule_month'].value = schedule.schedule_month;
		document.forms['schedule']['schedule_day'].value = schedule.schedule_day;
		document.forms['schedule']['schedule_check'].value = schedule.schedule_check;

		document.forms['schedule']['weekday'].value = schedule.weekday;
		document.forms['schedule']['weeksdate'].value = schedule.weeksdate;
		document.forms['schedule']['weeksmonth'].value = schedule.weeksmonth;
		document.forms['schedule']['weekscheck'].value = schedule.weekscheck;

		document.forms['schedule']['start_date'].value = schedule.start_date;
		document.forms['schedule']['end_date'].value = schedule.end_date;
	};

	document.getElementById("schedule_read").addEventListener('click', function(event)
	{
		event.preventDefault();

	    //schedule_read(document.forms['schedule']['start_date'].value);
		//return false; 
		
  		var item = element_has_class(daysinfoList, days_active);
		if (item) {
		    schedule_read(item.id, "읽기 버튼을 눌렀습니다.");
		}	
		return false;
	} );

	var daysinfoList = document.getElementsByClassName("days-info"); //1일부터 말일까지 네모들
	var daysList = document.getElementsByClassName("days"); //달력의 1일 왼쪽 말일 오른쪽 네모들
    var days_smallmoon = "smallmoon"; //음력달이 작은 달이면 1일, 15일에 smallmoon classname 있다
    var days_largemoon = "largemoon"; //음력달이 큰 달이면 1일, 15일에 largemoon classname 있다
    var days_season24 = "season24"; //24절기이면 해당날짜에 season24 classname 있다, 해당날짜가 음력 1,15일이라도 smallmoon,largemoon 보다 우선 적용
    var days_active = "active"; //선택(클릭)된 날짜를 표시할 class name
	var heights = new Array();
	var highest = 0;
	var day = false;

	var	el_smallmoons = elements_has_class(daysinfoList, days_smallmoon);
	var	el_largemoons = elements_has_class(daysinfoList, days_largemoon);
	var	el_season24s = elements_has_class(daysinfoList, days_season24);

	for(var i = 0; i < daysinfoList.length; i++) {
		
		//달력의 숫자 네모박스의 실제 높이를 계산
		var h_str = window.getComputedStyle(daysinfoList[i]).height;
		h_str = h_str.replace('px', '');
		h_num = Number(h_str);
		//높이를 배열에 추가
		heights.push(h_num);

		//달력의 숫자 네모박스를 클릭할 때
		daysinfoList[i].addEventListener('click', function() 
		{
			event.preventDefault();

			//이전에 선택된 날짜의 days_active class name을 제거한다
			for(var j = 0; j < daysinfoList.length; j++) {
				daysinfoList[j].classList.remove(days_active);
			}
			
			//현재 선택된 날짜가 24절기이면 days_season24 class name을 제거한다
			//다른 날짜들(el_season24s[])은 days_season24 class name을 추가한다 
			for(var i = 0; i < el_season24s.length; i++) {
				if (this == el_season24s[i])
					this.classList.remove(days_season24);
				else
					el_season24s[i].classList.add(days_season24);
			}	

			//현재 선택된 날짜의 음력달이 작은 달이면 days_smallmoon class name을 제거한다
			//다른 날짜들(el_smallmoons[])은 days_smallmoon class name을 추가한다 
			for(var i = 0; i < el_smallmoons.length; i++) {
				if (this == el_smallmoons[i])
					this.classList.remove(days_smallmoon);
				else
					el_smallmoons[i].classList.add(days_smallmoon);
			}	

			//현재 선택된 날짜의 음력달이 큰 달이면 days_largemoon class name을 제거한다
			//다른 날짜들(el_largemoons[])은 days_largemoon class name을 추가한다 
			for(var i = 0; i < el_largemoons.length; i++) {
				if (this == el_largemoons[i])
					this.classList.remove(days_largemoon);
				else
					el_largemoons[i].classList.add(days_largemoon);
			}
			
			//현재 선택된 날짜에 days_active class name을 추가한다 
			this.classList.add(days_active);

            //일정을 읽는다
			//달력의 날짜들(1일부터 말일까지)들의 id
			//$id = str_pad($year, 4, "0", STR_PAD_LEFT)."-".  
			//	str_pad($month, 2, "0", STR_PAD_LEFT)."-".  
			//	str_pad($day, 2, "0", STR_PAD_LEFT);  
			//document.forms['schedule']['start_date'].value = this.id;

			disp_msg("");

		    schedule_read(this.id);

			return false; 
		} );

		//달력의 숫자를 클릭할 때
		daysinfoList[i].querySelector('.ahref').addEventListener('click', function(event)
		{
			event.preventDefault();
			//this.parentNode.classList.add(days_active);
			//read schedule data
		    //schedule_read(this.parentNode.id);
			return false; 
		} );
	}

	//배열을 내림차순으로 정렬	
	heights = heights.sort(sortNumber);

    //제일 큰 숫자 : 높이
	if (isNaN(highest[0])) {
		highest = heights[0]+'px'; 
	}	
	else {
		highest = heights[0]; 
	}

	//alert(JSON.stringify(heights));
	//alert(highest);
	
	//달력의 날짜표시 네모들의 높이를 같은 크기로 만든다
	for(var i = 0; i < daysinfoList.length; i++) {
		daysinfoList[i].style.height = highest;
	}

	//달력의 날짜표시 네모들의 높이를 같은 크기로 만든다
	for(var i = 0; i < daysList.length; i++) {
		daysList[i].style.height = highest;
	}

	//days_active class name 을 가지고 있는 요소가 있으면 누른다
	day = element_has_class(daysinfoList, days_active); //현재 선택된 날짜 
	if (day) {
		day.querySelector('.ahref').click();
	}	
	
</script>

<script type="text/javascript">

	function schedule_check_onchange(el){
		if (el.value == 1) {
			document.getElementById("schedule_check_div").classList.add('active');
			document.getElementById("schedule_lunar").disabled = false;
			document.getElementById("schedule_month").disabled = false;
			document.getElementById("schedule_day").disabled = false;
			document.getElementById("schedule_check").disabled = false;

			document.getElementById("weekscheck_div").classList.remove('active');
			document.getElementById("weekday").disabled = true;
			document.getElementById("weeksdate").disabled = true;
			document.getElementById("weeksmonth").disabled = true;
			document.getElementById("weekscheck").disabled = true;
		}	
		else if (el.value == -1) {
			document.getElementById("schedule_check_div").classList.remove('active');
			document.getElementById("schedule_lunar").disabled = true;
			document.getElementById("schedule_month").disabled = true;
			document.getElementById("schedule_day").disabled = true;
			document.getElementById("schedule_check").disabled = true;
			document.getElementById("schedule_check").value = -1;

			document.getElementById("weekscheck_div").classList.add('active');
			document.getElementById("weekday").disabled = false;
			document.getElementById("weeksdate").disabled = false;
			document.getElementById("weeksmonth").disabled = false;
			document.getElementById("weekscheck").disabled = false;
			document.getElementById("weekscheck").value = 1;
		}	
		else {
			document.getElementById("schedule_check_div").classList.remove('active');
			document.getElementById("schedule_lunar").disabled = false;
			document.getElementById("schedule_month").disabled = false;
			document.getElementById("schedule_day").disabled = false;
			document.getElementById("schedule_check").disabled = false;
			document.getElementById("schedule_check").value = 0;

			document.getElementById("weekscheck_div").classList.remove('active');
			document.getElementById("weekday").disabled = false;
			document.getElementById("weeksdate").disabled = false;
			document.getElementById("weeksmonth").disabled = false;
			document.getElementById("weekscheck").disabled = false;
		}	
	}

	function weekscheck_onchange(el){
		if (el.value == 1) {
			document.getElementById("schedule_check_div").classList.remove('active');
			document.getElementById("schedule_lunar").disabled = true;
			document.getElementById("schedule_month").disabled = true;
			document.getElementById("schedule_day").disabled = true;
			document.getElementById("schedule_check").disabled = true;

			document.getElementById("weekscheck_div").classList.add('active');
			document.getElementById("weekday").disabled = false;
			document.getElementById("weeksdate").disabled = false;
			document.getElementById("weeksmonth").disabled = false;
			document.getElementById("weekscheck").disabled = false;
		}	
		else if (el.value == -1) {
			document.getElementById("schedule_check_div").classList.add('active');
			document.getElementById("schedule_lunar").disabled = false;
			document.getElementById("schedule_month").disabled = false;
			document.getElementById("schedule_day").disabled = false;
			document.getElementById("schedule_check").disabled = false;
			document.getElementById("schedule_check").value = 1;

			document.getElementById("weekscheck_div").classList.remove('active');
			document.getElementById("weekday").disabled = true;
			document.getElementById("weeksdate").disabled = true;
			document.getElementById("weeksmonth").disabled = true;
			document.getElementById("weekscheck").disabled = true;
			document.getElementById("weekscheck").value = -1;
		}	
		else {
			document.getElementById("schedule_check_div").classList.remove('active');
			document.getElementById("schedule_lunar").disabled = false;
			document.getElementById("schedule_month").disabled = false;
			document.getElementById("schedule_day").disabled = false;
			document.getElementById("schedule_check").disabled = false;

			document.getElementById("weekscheck_div").classList.remove('active');
			document.getElementById("weekday").disabled = false;
			document.getElementById("weeksdate").disabled = false;
			document.getElementById("weeksmonth").disabled = false;
			document.getElementById("weekscheck").disabled = false;
			document.getElementById("weekscheck").value = 0;
		}	
	}

</script>

</body>

</html>

 

 다음글 개발자에게 유용한 북마크 툴 소개
 이전글 simple tab

댓글

없음