ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • fullcalendar 이벤트 추가 및 ajax event 등록
    JQUERY 2020. 4. 22. 10:20
    $(document).ready(function() {
               
                $('#calendar').fullCalendar({
                      header: {
                            left: 'prevYear,prev,next,nextYear',
                      center: 'title',
                      right: '<?= $write_href ? "addEventButton" : false ?>'
                      },
                      height: 'parent',
                      contentHeight:"auto",
                      lang:'ko',
                      googleCalendarApiKey : "AIzaSyDcnW6WejpTOCffshGDDb4neIrXVUA1EAE",
                    defaultDate: '<?= $year."-".$month?>',
                      
                      events: function(start, end, timezone, callback){
                            var events = [];
                            var tmpDateS = start.unix() * 1000;
                                  var dateS = new Date(tmpDateS);
                                  var yyyyS = dateS.getFullYear();
                                var MMS = dateS.getMonth()+1;
                                var ddS = dateS.getDate();
                                var tmpDateE = end.unix() * 1000;
                                  var dateE = new Date(tmpDateE);
                                  var yyyyE = dateE.getFullYear();
                                var MME = dateE.getMonth()+1;
                                var ddE = dateE.getDate();
                                var tmpUnix = start.unix();
                                while(tmpUnix < end.unix())
                                {
                                  tmpUnix = tmpUnix + 1 * 60 * 60 * 24;
                                  var tmp = new Date(tmpUnix * 1000);
                                  var yyyyT = tmp.getFullYear();
                                      var MMT = addzero(tmp.getMonth()+1);
                                      var ddT = addzero(tmp.getDate());
                                      events.push({title:"오전", start: yyyyT+"-"+MMT+"-"+ddT, url:'<?= G5_BBS_URL ?>/write.php?bo_table=31&year='+yyyyT+'&month='+MMT+'&day='+ddT+'&time=AM'},{title:"오후", start: yyyyT+"-"+MMT+"-"+ddT, url:'<?= G5_BBS_URL ?>/write.php?bo_table=31&year='+yyyyT+'&month='+MMT+'&day='+ddT+'&time=PM'});
                                }
                                
                                $.ajaxSetup({ async:false }); //비동기화처리후
                                $.post("./ajax.board.php", {"bo_table" : "게시판번호", "start" : yyyyS+"-"+MMS+"-"+ddS, "end" : yyyyE+"-"+MME+"-"+ddE},function(res){
                                  arr = jQuery.parseJSON(res);
                                  $.each(arr, function(index, wr){
                                  	events.push({title:wr.wr_subject, start: wr.wr_1, url:'/bbs/board.php?bo_table=51&wr_id='+wr.wr_id});
                                  });
                                });
                                callback(events);
                                  
                      },
                      eventSources : [
                        {
                            googleCalendarId : "ko.south_korea#holiday@group.v.calendar.google.com",
                            className : "koHolidays",
                            color : "#FF0000",
                            textColor : "#FFFFFF",
                                  editable : false
                        }
                      ],
                            
                    dayClick: function(date, jsEvent, view) {
                            return false;
                      },
                      //공휴일 클릭 방지
                      eventAfterRender: function( event, element, view  ) {
                        $(".koHolidays").attr("href", "javascript:void(0);");
                    }
                });
            });
    

    /ajax.board.php

    <?php
    include_once "./common.php";
    
    $bo_table = $_POST["bo_table"];
    
    $start = $_POST["start"];
    $end = $_POST["end"];
    
    $sql = " SELECT * FROM g5_write_{$bo_table} WHERE wr_1 >= '{$start}' AND wr_2 <= '{$end}' ";
    $res = sql_query($sql); 
    
    $list = array();
    while($row = sql_fetch_array($res))
    {
        $list[] = $row;    
    }
    
    die(json_encode($list));
    ?>

    댓글

Designed by Tistory.