본문 바로가기

Web/PHP

스케줄 달력 (class.Calendar2.php)

<?php
//
// Function
//
if(!is_file($sMoonDir."/$this->nMonth.php"))                                            // 음력 정보가 없으면 음력 관련 파일을 불러들인다.
{
    //include $_SERVER[DOCUMENT_ROOT]."/include/function/solmoon.php";

    //
    // 원래 계산하는 방식에서 table 식으로 변경 속도도 빠르다고하니..
    // 가장 큰 문제는 저게 계산이 계속 틀리네 ㅡ,.ㅡ; 썩을놈의 것
    // 요건 제대로 맞는지는 아직 확증은 없음.
    // 윤달 확인 안됨.
    //
    include $_SERVER[DOCUMENT_ROOT]."/include/function/solmoon2.php";
}
//
// Class
//
class Calendar2
{
    var $nYear;
    var $nMonth;
    var $sOverColor;
    var $aSolEventR = array(        // 쉬는 기념일
        '0101'    => '신정',
        '0301'    => '삼일절',
        '0405'    => '식목일',
        '0505'    => '어린이날',
        '0515'    => '석가탄신일',
        '0606'    => '현충일',
        '0717'    => '제헌절',
        '0815'    => '광복절',
        '1003'    => '개천절',
        '1225'    => '성탄절',
    );
    var $aSolEventB = array(        // 안쉬는 기념일
        '0114'    => '다이어리데이',
        '0214'    => '발렌타인데이',
        '0314'    => '화이트데이',
        '0414'    => '블랙데이',
        '0514'    => '로즈데이',
        '0614'    => '키스데이',
        '0714'    => '실버데이',
        '0814'    => '그린데이',
        '0914'    => '포토데이',
        '1014'    => '와인데이',
        '1114'    => '무비데이',
        '1111'    => '빼빼로데이',
        '1214'    => '허그데이',
        '0501'    => '근로자의 날',
        '0508'    => '어버이날',
        '0515'    => '스승의날',
        '0516'    => '성년의날',
        '0625'    => '6.25사변일',
        '1009'    => '한글날',
        '1001'    => '국군의날',
    );
    var $aMoonEvent = array(        // 음력으로 기념일 쉬는날
        '1230'    => ' ',
        '0101'    => '구정',
        '0102'    => ' ',
        '0814'    => ' ',
        '0815'    => '추석',
        '0816'    => ' ',
    );
    var $aMoonEvent2 = array(        // 음력으로 기념일 절기
        '0115'    => '대보름',
        '0505'    => '단오',
        '0707'    => '칠석',
    );
    var $aEvent24 = array(            // 24절기

        '20050105'    => '소한',    // 2005
        '20050120'    => '대한',
        '20050204'    => '입춘',
        '20050218'    => '우수',
        '20050305'    => '경칩',
        '20050320'    => '춘분',
        '20050420'    => '곡우',
        '20050506'    => '입하',
        '20050521'    => '소만',
        '20050605'    => '망종',
        '20050621'    => '하지',
        '20050707'    => '소서',
        '20050723'    => '대서',
        '20050807'    => '입추',
        '20050823'    => '처서',
        '20050907'    => '백로',
        '20050923'    => '추분',
        '20051008'    => '한로',
        '20051023'    => '상강',
        '20051107'    => '입동',
        '20051122'    => '소설',
        '20051207'    => '대설',
        '20051222'    => '동지',

        '20060105'    => '소한',    // 2006
        '20060120'    => '대한',
        '20060204'    => '입춘',
        '20060219'    => '우수',
        '20060306'    => '경칩',
        '20060321'    => '춘분',
        '20060420'    => '곡우',
        '20060506'    => '입하',
        '20060521'    => '소만',
        '20060605'    => '망종',
        '20060621'    => '하지',
        '20060707'    => '소서',
        '20060723'    => '대서',
        '20060808'    => '입추',
        '20060823'    => '처서',
        '20060908'    => '백로',
        '20060923'    => '추분',
        '20061008'    => '한로',
        '20061023'    => '상강',
        '20061107'    => '입동',
        '20061122'    => '소설',
        '20061207'    => '대설',
        '20061222'    => '동지',

        '20070106'    => '소한',    // 2007
        '20070120'    => '대한',
        '20070204'    => '입춘',
        '20070219'    => '우수',
        '20070306'    => '경칩',
        '20070321'    => '춘분',
        '20070420'    => '곡우',
        '20070506'    => '입하',
        '20070521'    => '소만',
        '20070605'    => '망종',
        '20070622'    => '하지',
        '20070707'    => '소서',
        '20070723'    => '대서',
        '20070808'    => '입추',
        '20070823'    => '처서',
        '20070908'    => '백로',
        '20070923'    => '추분',
        '20071009'    => '한로',
        '20071024'    => '상강',
        '20071108'    => '입동',
        '20071123'    => '소설',
        '20071207'    => '대설',
        '20071222'    => '동지',
    );


    var $aStripCode = array(        // 스케줄 내용 부분에서 Js처리를 위해 \r\n을 br로 변경한다.
        "\r\n",
        "\n",
    );
    var $aStripCode2 = array(
        " ",
        '"',
        "'",
        ',',
        //'<',
        //'>',
        //'(',
        //')',
    );
    var $aStripCode3 = array(
        ' ',
        '″',
        '′',
        '¸',
        //'<',
        //'&rt;',
        //'(',
        //')',
    );

    function Calendar2()
    {
        $this->nYear        = $GLOBALS[nYear];
        $this->nMonth        = $GLOBALS[nMonth];
        $this->sOverColor    = $GLOBALS[sOverColor];
    }

    function setData(&$aData)
    {
        foreach($aData as $index => $value) $this->$index = $value;
    }

    // 이번달의 마지막 날을 구한다.
    function getLastDay()
    {
        $this->nLastDay = date(t, mktime(0, 0, 0, $this->nMonth, 1, $this->nYear));
    }

    // 달의 첫번째 날요일구하기
    function getFirstDay()
    {
        $this->nFirstDay = date(w, mktime(0, 0, 0, $this->nMonth, 1, $this->nYear));
    }

    // 년, 월을 변경해주는 함수
    function change($nType)
    {
        $setTime = mktime(0,0,0,$this->nMonth, 1, $this->nYear);
        switch( $nType )
        {
            case('1') : $rtn = strtotime("-1 year", $setTime); break;
            case('2') : $rtn = strtotime("-1 month", $setTime); break;
            case('3') : $rtn = strtotime("+1 month", $setTime); break;
            case('4') : $rtn = strtotime("+1 year", $setTime); break;
        }
        return "nYear=".date(Y,$rtn)."&nMonth=".date(m,$rtn);
    }

    function printFirstBlank()
    {
        for($i=0; $i<$this->nFirstDay; $i++) echo "<td class='calendar_black_td'> </td>";
    }

    function Calendar()
    {
        echo '<tr>';
        $this->getFirstDay();
        $this->printFirstBlank();
        $this->getLastDay();

        $nYearMonth = $this->nYear.$this->nMonth;

        $sMoonDir = './moondate/'.$this->nYear;
        if(!is_file($sMoonDir."/$this->nMonth.php"))                                            // 음력 정보가 없으면 음력 관련 파일을 불러들인다.
        {            
            print(`mkdir $sMoonDir -p`);

            $fp = fopen($sMoonDir."/$this->nMonth.php", w);
            fwrite($fp, "<?php\n");
            for($i=1; $i<=$this->nLastDay; ++$i)
            {
                $moon            = soltolun($this->nYear, $this->nMonth, $i);
                //$moon[month]    = $moon[month]<10    ?'0'.$moon[month]:$moon[month];        // solmoon2 로 변경해서 지움
                //$moon[day]        = $moon[day]<10        ?'0'.$moon[day]:$moon[day];
                $moondate        = $moon[month].'|'.$moon[day];
                $moon_d[$i]        = $moondate;
                fwrite($fp, "\$moon_d[$i] = \"$moondate\";\n");
            }
            fwrite($fp, "\n?>\n");
            fclose($fp);
            unset($moon);
        }
        else
        {
            include $sMoonDir."/$this->nMonth.php";        // 해당 월에 있는 내용을 가져오기
        }

        // ------------------------------------    Where option
        include "list_WhereOption.php";
        // ------------------------------------

        //
        // 쿼리 돌리는 걸 줄이기 위해서 미리 날짜에 관해 가져오자.
        //
        $res = sql_query("SELECT sDate FROM schedule WHERE sDate BETWEEN ${nYearMonth}01 AND ${nYearMonth}31 $sWhere GROUP BY sDate ORDER BY sDate ASC");
        while($rs = mysql_fetch_array($res, MYSQL_ASSOC))
        {
            $day = substr($rs[sDate],-2);
            $nExist[$day] = 1;                // 해당월에 날짜 01~31 의 Index를 가지는 변수 생성
        }
        //printR($nExist);
        mysql_free_result($res);


        $j = $this->nFirstDay+1;
        for($i=1; $i<=$this->nLastDay; $i++)
        {
            $nWeek = $j%7;
            $day = $i<10?'0'.$i:$i;

            switch($nWeek)
            {
                case('1'):    $sTxtColor = "calendar_sun"; break;
                case('0'):    $sTxtColor = "calendar_sat"; break;
                default:    $sTxtColor = "calendar_nor"; break;
            }

            $solE = $this->nMonth.$day;
            if($this->aSolEventR[$solE])
            {
                $sTxtColor = 'calendar_sun';
                $sMsg = $this->aSolEventR[$solE];
            }
            else $sMsg = '';
            if($this->aSolEventB[$solE])
            {
                //$sTxtColor = 'calendar_sat';
                $sMsg2 = $this->aSolEventB[$solE];
            }
            else $sMsg2 = '';

            $sTodayColor = (date(Ymd) == $this->nYear.$this->nMonth.$day) ? ' calendar_today' : '';

            //
            // 음력 처리
            //
            $moon = explode('|',$moon_d[$i]);
            $moondate = $moon[0].$moon[1];
            //$leap = $moon[2]?'윤 ':'';
            $sol = ($i%5==0)?"<div class='moon'>($moon[0].$moon[1])</div>":'';

            if($this->aMoonEvent[$moondate])
            {
                $sTxtColor = 'calendar_sun';
                $sMsg3 = $this->aMoonEvent[$moondate];
            }
            else $sMsg3 = '';

            if($this->aMoonEvent2[$moondate])
            {
                $sMsg4 = '<nobr style=color:6b6b6b>'.$this->aMoonEvent2[$moondate].'</nobr>';
            }
            else $sMsg4 = '';

            if($this->aEvent24[$nYearMonth.$day])
            {
                $sMsg5 = '<nobr style=color:6b6b6b>'.$this->aEvent24[$nYearMonth.$day].'</nobr>';
            }
            else $sMsg5='';

            //
            // 음력 처리 추가. 2004-11-15
            //
            echo "<td width='14.5%' onMouseOver=Trbg(this,'$this->sOverColor'); onMouseOut=Trbg(this); class='calendar_td $sTxtColor$sTodayColor'><a href=\"javascript:DayView($this->nYear$this->nMonth$day)\" class='$sTxtColor$sTodayColor'>$i</a> $sMsg$sMsg2$sMsg3$sMsg4$sMsg5 $sol ";

            //
            // 스케줄 디비에서 가져오기(일반 작성 이벤트), 회원이벤트추후포함시키자.
            //
            $Date[f] = mktime(0,0,0,$this->nMonth,$i,$this->nYear);
            $Date[s] = mktime(0,0,0,$this->nMonth,$i+1,$this->nYear);

            if($nExist[$day])            // true 일때만 Query를 불러들인다.
            {
                $res = sql_query("SELECT sTitle,sContent,no,sID,nTeam,nSType,sColor FROM schedule WHERE sDate='$nYearMonth$day' $sWhere"); // 한달치 검색
                //echo "SELECT sTitle,sContent,no,sID,nTeam,nSType,sColor FROM schedule WHERE sDate='$nYearMonth$day' $sWhere";
                $nTtlCut = 5;
                while($rs = mysql_fetch_array($res, MYSQL_ASSOC))
                {
                    //
                    // Pop Menu
                    //
                    $rs[sContent] = str_replace($this->aStripCode2,$this->aStripCode3,strcut($rs[sContent],120));
                    $rs[sContent] = str_replace($this->aStripCode,"<br>",$rs[sContent]);
                    $sTitle         = str_replace($this->aStripCode2,$this->aStripCode3,$rs[sTitle]);

                    $sMsg = "onMouseOver=\"pop('<b>$sTitle</b><br>$rs[sContent]');\" onMouseOut='kill();'";
                    echo "<div>•<a href='javascript:ScheduleView($rs[no]);' $sMsg";

                    //
                    // Apply title of color
                    //
                    if($rs[sColor])
                        echo " style='color:$rs[sColor]'>".strcut($rs[sTitle],$nTtlCut);
                    else
                        echo ">".strcut($rs[sTitle],$nTtlCut);
                    echo "</a></div>";

                    //
                    // Reset variant value
                    //
                    $sMsg = null;
                }
                mysql_free_result($res);
            }

            echo "</td>";
            if($nWeek == 0) echo '</tr><tr>';
            ++$j;
        }
        --$j;
        while($j%7 != 0)
        {
            echo "<td class='calendar_black_td'></td>";
            ++$j;
        }
    }
}


if(!$objCalendar) $objCalendar = & new Calendar2;
?>

'Web > PHP' 카테고리의 다른 글

스케줄 달력 (schedule.html)  (0) 2013.09.26
스케줄 달력 (solmoon2.php)  (0) 2013.09.26
양력 -> 음력  (0) 2013.09.26
pdf만들기  (0) 2013.09.26
소수  (0) 2013.09.26