[php] 달력클래스
로빈아빠
본문
달력클래스
<? class seokhunCalendar { //일정에 관련된 변수들... var $year; var $month; var $day; //날짜와 날짜에 대한 정보....(뭔소린지 몰라요? 나두..ㅡ.ㅡ; 쉽고 좋은말 없남..ㅡ.ㅡ;;) 참고 [배열임] var $m_days; var $m_weeks0; var $m_weeks1; //에러값을 기록하는 변수 var $errmsg; //리턴값 설정 var $TRUE = 1; var $FALSE = 0; //생성자..년/월/일 받아서 데이터 초기화 시킴 function seokhunCalendar($year, $month, $day) { //날짜 체크 if($month>12 || $month<1 || $day>31 || $day<1){ $this->errmsg = "날짜가 범위를 초과하였습니다."; return $FALSE; } //2003-02-25이면 곤란하쟎아...타입 변환시킨다.. $this->year = (int)$year; $this->month = (int)$month; $this->day = (int)$day; //변수 초기화 함수 콜~~~~ $this->set_init(); return $TRUE; } //달력 만들기 function set_calendar() { echo "<br><b>[ $this->year-$this->month ]</b><br><br>"; echo "<table border=1 cellpadding=5 cellspacing=0>"; echo "<tr><td> </td>"; //먼저 날짜부터 찍는다. for($i=1; $i < $this->m_days[$this->month-1] + 1; $i++) echo "<td><font size=-1>$i</font></td>"; echo "</tr>"; //다 찍었으면 이제 요일을 찍는다. 찍기 전에 먼저 첫날의 요일을 알아야 한다. echo "<tr><td> </td>"; $yoil = $this->get_first_yoil($this->month, $this->year); for($i=0; $i<count($this->m_weeks0); $i++){ if($yoil == $this->m_weeks0[$i]) break; } //날자 찍장...ㅡ.ㅡ;;; for($k=1; $k < $this->m_days[$this->month-1] + 1; $k++){ if($i == 0) //일요일만 색처리...ㅡㅡ;;; echo "<td><font size=-1 color=red>" . $this->m_weeks1[$i] . "</font></td>"; else if($i == 6) //히히..재밌넹....ㅡ.ㅡ;;; echo "<td><font size=-1 color=blue>" . $this->m_weeks1[$i] . "</font></td>"; else if($k == $this->day && $this->day == date("d") && $this->month == date("m") && $this->year == date("Y")) //today echo "<td><font size=-1 color=yellow>" . $this->m_weeks1[$i] . "</font></td>"; else echo "<td><font size=-1>" . $this->m_weeks1[$i] . "</font></td>"; $i++; if($i > 6) $i %= 7; } echo "</tr>"; // 다 됐으니...일정을 추가해 보장....흘흘.... echo "</table>"; } //변수 초기화 함수 function set_init() { // 매달에 대한 마지막 날을 배열로 저장한다. $this->m_days[0] = 31; $this->m_days[1] = 28; $this->m_days[2] = 31; $this->m_days[3] = 30; $this->m_days[4] = 31; $this->m_days[5] = 30; $this->m_days[6] = 31; $this->m_days[7] = 31; $this->m_days[8] = 30; $this->m_days[9] = 31; $this->m_days[10] = 30; $this->m_days[11] = 31; // 윤년 확인 .... 윤년은 2월달이 29일까지임...ㅡ.ㅡ;;; 에흐..ㅡ.ㅡ;; 무쟈게 복잡하넹..ㅡ.ㅡ;; // 이거 엉터리당...반드시 확인할 것...ㅡ.ㅡ;;; if($this->month == 2) if(($this->year % 4) == 0 && ($this->year % 100) != 0 && ($this->year % 400) != 0) $this->m_days[1] = 29; //일주일의 요일을 저장한다..이건..순전히..ㅡ.ㅡ;; 에흐..ㅡ.ㅡ;;; //나중에 요일을 찍기 위함인데..좀더 좋은 방법이 없남..ㅡ.ㅡ;;;바보같당.... $this->m_weeks0[0] = "Sunday"; $this->m_weeks0[1] = "Monday"; $this->m_weeks0[2] = "Tuesday"; $this->m_weeks0[3] = "Wednesday"; $this->m_weeks0[4] = "Thursday"; $this->m_weeks0[5] = "Friday"; $this->m_weeks0[6] = "Saturday"; $this->m_weeks1[0] = "일"; $this->m_weeks1[1] = "월"; $this->m_weeks1[2] = "화"; $this->m_weeks1[3] = "수"; $this->m_weeks1[4] = "목"; $this->m_weeks1[5] = "금"; $this->m_weeks1[6] = "토"; } //첫번재 날 요일이 몰까?? function get_first_yoil($month, $year) { return date("l", mktime(0,0,0,$month,1,$year)); } //오늘 날짜 리턴 "Y-m-d" function get_today() { return date("Y-m-d"); } //특정 날짜 리턴 function get_daydiff($daydiff) { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month,$this->day + $daydiff, $this->year)); } //다음날짜 리턴 function get_nextday() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month,$this->day + 1, $this->year)); } //다음달 리턴 function get_nextmonth() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month + 1, $this->day, $this->year)); } //다음해 리턴 function get_nextyear() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month, $this->day, $this->year + 1)); } //이전 날짜 리턴 function get_prevday() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month,$this->day - 1, $this->year)); } //이전달 리턴 function get_prevmonth() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month - 1, $this->day, $this->year)); } //이전해 리턴 function get_prevyear() { return strftime("%Y-%m-%d", mktime(0,0,0,$this->month, $this->day, $this->year - 1)); } } ?> ======================================================================= // 사용해서 본 html코드입니다. <? include "class.seokhunCalendar.php"; if($_GET["mode"] == "post") $today = $_POST["m_year"] . "-" . $_POST["m_month"] . "-" . "01"; else if($_GET["mode"] == "get") $today = $_GET["today"]; else $today = date("Y-m-d"); $today = split("-", $today); $cal = new seokhunCalendar($today[0], $today[1], $today[2]); include "../head.html"; if($cal) $cal->set_calendar(); else echo "<script>alert($cal->errmsg);</script>"; ?> <script> function goURL(url) { href.location = url; } </script> <form action="project.php?mode=post" method="post"> <table width="750" border="0"> <tr> <td align="left"> <input type="text" name="m_year" size="4" maxlength="4">- <input type="text" name="m_month" size="2" maxlength="2"> <input type="submit" value="GO~!"> </td> <td> <input type="button" name="m_Today" value="진행 후" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_today(); ?>'"> <input type="button" name="m_Today" value="진행 중" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_today(); ?>'"> <input type="button" name="m_NextMonth" value="진행예정" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_nextmonth(); ?>'"> </td> <td align="right"> <input type="button" name="m_PrevYear" value="작 년" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_prevyear(); ?>'"> <input type="button" name="m_PrevMonth" value="이전달" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_prevmonth(); ?>'"> <input type="button" name="m_Today" value="오 늘" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_today(); ?>'"> <input type="button" name="m_NextMonth" value="다음달" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_nextmonth(); ?>'"> <input type="button" name="m_NextYear" value="내 년" onClick="javascript:location='project.php?mode=get&today=<? print $cal->get_nextyear(); ?>'"> </td> </tr> </table> </form> <? include "../tail.html"; ?>
관련링크
댓글목록
등록된 댓글이 없습니다.