Hi guys thanks for taking the time to read my question.
I am trying to create an Event Calendar where user can input data into the calendar.
How do I show two months calendar on the same page (e.g. show December 2012 and January 2013 side by side rather than through a link.)
I have gotten my codes from http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-the-calendar-library/
Any help is very much appreciated. =)
//CONTROLLER
class Mycal extends CI_Controller {
public function index() {
$this->display();
}
function display($year = null, $month = null){
if (!$year) {
$year = date('Y');
}
if (!$month) {
$month = date('m');
}
$this->load->model('Mycal_model');
if($day = $this->input->post('day')){
$this->Mycal_model->add_calendar_data(
"$year-$month-$day",
$this->input->post('data')
);
}
$data['calendar'] = $this->Mycal_model->generate($year, $month);
$this->load->view('mycal_view', $data);
}
}
//MODEL
class Mycal_model extends CI_Model{
function get_calendar_data($year, $month){
$query = $this->db->select('date, data')->from('calendar')
->like('date', "$year-$month", 'after')->get();
$cal_data = array();
foreach ($query->result() as $row){
$cal_data[substr($row->date,8,2)] = $row->data;
}
return $cal_data;
}
function add_calendar_data($date, $data){
if($this->db->select('date')->from('calendar')
->where('date', $date)->count_all_results()) {
$this->db->where('date', $date)->update('calendar', array(
'date'=>$date,
'data'=>$data
));
}else{
$this->db->insert('calendar', array(
'date'=>$date,
'data'=>$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)
}
function generate ($year, $month){
// to generate 2nd calendar for the next month?
$this->load->library('calendar', $this->conf);
$cal_data = $this->get_calendar_data($year, $month+1);
return $this->calendar->generate($year, $month+1, $cal_data)
}
//VIEW
<?php echo $calendar; ?>
// to generate 2nd calendar for the next month?
<?php echo $calendar2; ?>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Stuff', $(this).find('.content').html());
if(day_data !=null){
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg){
location.reload();
}
});
}
});
});
</script>