1

カレンダーを特定の形式で表示するコントローラーがあります。

function eventCalendar($year = null, $month = null)
{
    if (!$year) {
        $year = date('Y');
    }
    if (!$month) {
        $month = date('m');
    }       
    $this->load->model('event_Model','em');
    //this is the attribute that displays the calendar
    $data['calendar'] = $this->em->generate($year, $month);
            //-------
    $data['semester'] = $this->em->getSemester();
    $data['levelyear'] = $this->em->getLevelYear();
    $data['tahun_akademik'] = $this->em->getAcademicYear();
    $data['isi'] = 'eventCalendar';
    $data['kategori'] = $this->em->getKategoriEvent();
    $data['title'] = 'Event Registration';
    $this -> load -> view('index', $data); 
}

次に、コントローラーからの属性が渡されて処理されるモデルがあります

function get_calendar_data($year,$month)    
{
    $query = $this->db->query("SELECT DISTINCT DATE_FORMAT(TanggalMulai, '%Y-%m-%e') AS TanggalMulai
                                        FROM trevent
                                        WHERE TanggalMulai LIKE '$year-$month%' "); //date format eliminates zeros make
                                                                       //days look 05 to 5

        /*$query = $this->db->select('date, data')->from('calendar')
        ->like('date', "$year-$month", 'after')->get();*/

    $cal_data = array();

    foreach ($query->result() as $row) {
        $a = array();
        $b = array();
        $i = 0;

        $query2 = $this->db->query("SELECT *
                                            FROM trevent
                                            WHERE TanggalMulai LIKE DATE_FORMAT('$row->TanggalMulai', '%Y-%m-%d') ");

                                                        //date format change back the date format
                                                        //that fetched earlier

        foreach ($query2->result() as $r) {
                     $a[$i] = $r->NamaEvent;     //make data array to put to specific date
                     $b[$i] = $r->IDevent;
                     $c[$i] = $r->IDkategoriEvent;
                     $query3 = $this->db->query("SELECT * FROM mskategorievent WHERE IDkategoriEvent = '".$c[$i]."'");
                     foreach($query3->result() as $rowke)
                     {
                        $d[$i] = $rowke->WarnaKategoriEvent; 
                     }
                     $i++;                         
                 }

        /*if(substr($row->date,8,1)==0) {
            $cal_data[substr($row->date,9,1)] = $row->data;
        } else {*/
        $date_begin = intval(substr($r->TanggalMulai,8,2));
        $date_end = intval(substr($r->TanggalAkhir,8,2));

        for($j=$date_begin;$j<=$date_end;$j++)
        {
            for($k=0;$k<$i;$k++)
            {
                $cal_data[$j][] = "<table style=\"table-layout: fixed; width: 100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".$d[$k]."\"><tr><td style=\"word-wrap: break-word\"><font size=\"2px\"><b>".$a[$k]."</b></font></td></tr></table>";
            }
        }
        //}
    }

    return $cal_data;

}

function generate($year,$month) {
    $this->load->library('calendar', $this->conf);

    $cal_data = $this->get_calendar_data($year, $month);

    return $this->calendar->generate($year, $month, $cal_data);
}

私のビューには、クリックしたときにカレンダーの属性を変更したいコンボボックスがあります(通常のjqueryまたはajaxのいずれか)

<td width="157"><label for="cb_academicYear"></label>
  <select name="cb_academicYear" id="cb_academicYear">
  <?php 
  $sem=0;
        foreach ($tahun_akademik->result() as $ta)
        {
            echo "<option value=\"".$ta->TahunAkademik."-".$ta->IDsemester."\">".$ta->TahunAkademik."-".$ta->IDsemester."</option>";
        }
    ?>
  </select></td>

ページをリダイレクトまたはリロードせずにカレンダーを変更したい場合、ajax で何ができますか? 多分ajaxで...可能であれば。この問題の答えを教えてください。よろしくお願いします。

4

0 に答える 0