I'm working on a codeIgniter project.I use fullCalendar to insert events. The concept that I want to implement is similar to google Calendar. When a user clicks on a day in the calendar, he inserts an event starting on the date of the clicked day. I did an ajax call from my view and post the date to the controller.Once in the controller, all what I want to do is to set the start date with this value and to insert the event in the calendar. Here is my code (controller)
function add_event()
{
$click_date = $this->input->post('date');
$date= explode(" ", "$click_date ");
$month= (int)$date[1];
$day= (int)$date[2];
$year= (int)$date[3];
$date_start = $this->unix_timestamp($year.'-'.$month.'-'.$day);
$this->load->library('gcal');
$date_end = $this->unix_timestamp('2012-08-15');
$params = array(
'calendarId' => 'my Google calendar id',
'allday' => true,
'start' => $date_start,
'end' => $date_end,
'summary' => 'event',
'description' => "My first event"
);
$response = $this->gcal->eventInsert($params);
if($response)
{
echo "true";
}
}
Here is my unix_timestamp function :
function unix_timestamp($date)
{
$date = str_replace(array(' ', ':'), '-', $date);
$c = explode('-', $date);
$c = array_pad($c, 6, 0);
array_walk($c, 'intval');
return mktime($c[3], $c[4], $c[5], $c[1], $c[2], $c[0]);
}
On the calendar, the event is inserted but not on the right starting date. It starts on 2012-01-01 which is the default date I guess. I don't understand why my starting date isn't set correctly. What I am doing wrong? Could someone please help me?
I found the answer. I should convert the fullCalendar date format into string before posting it to the controller. One line was missing :
Hope that it would help people who have the same problem `