public function sync_cal($ical_id) { require_once "app/views/templates/blue/rooms/codebase/class.php"; $exporter = new ICalExporter(); $ical_urls = $this->db->where('id', $ical_id)->get('ical_import'); if ($ical_urls->num_rows() != 0) { foreach ($ical_urls->result() as $row) { $ical_content = file_get_contents($row->url); $events = $exporter->toHash($ical_content); $success_num = 0; $error_num = 0; $id = $row->list_id; /*! inserting events in database */ $check_tb = $this->db->select('group_id')->where('list_id', $id)->order_by('id', 'desc')->limit(1)->get('calendar'); //$query = $this->db->last_query(); //echo $query;exit; //print_r($check_tb->num_rows());exit; if ($check_tb->num_rows() != 0) { $i1 = $check_tb->row()->group_id; } else { $i1 = 1; } for ($i = 1; $i <= count($events); $i++) { $event = $events[$i]; $days = (strtotime($event["end_date"]) - strtotime($event["start_date"])) / (60 * 60 * 24); $created = $event["start_date"]; for ($j = 1; $j <= $days; $j++) { if ($days == 1) { $direct = 'single'; } else { if ($days > 1) { if ($j == 1) { $direct = 'left'; } else { if ($days == $j) { $direct = 'right'; } else { $direct = 'both'; } } } } $startdate1 = $event["start_date"]; $check_dates = $this->db->where('list_id', $id)->where('booked_days', strtotime($startdate1))->get('calendar'); if ($check_dates->num_rows() != 0) { $conflict = $i; } else { $data = array('id' => NULL, 'list_id' => $id, 'group_id' => $i + $i1, 'availability' => "Booked", 'value' => 0, 'currency' => "EUR", 'notes' => "Not Available", 'style' => $direct, 'booked_using' => 0, 'booked_days' => strtotime($startdate1), 'created' => strtotime($created)); $this->Common_model->insertData('calendar', $data); } // if(isset($conflict)) // { // $this->db->where('list_id',$id)->where('group_id',$conflict)->delete('calendar'); // } $abc = $event["start_date"]; $newdate = strtotime('+1 day', strtotime($abc)); $event["start_date"] = date("m/d/Y", $newdate); } $success_num++; } //for loop end $update_sync['last_sync'] = date('d M Y, g:i a', gmt_to_local(time(), get_user_timezone(), false)); $this->db->where('id', $row->id)->update('ical_import', $update_sync); } } redirect('rooms/lys_next/edit/' . $ical_urls->row()->list_id); }
$data = array('id' => NULL, 'list_id' => $this->uri->segment(3), 'url' => $this->input->post('ical_url'), 'last_sync' => date("d M Y, g:i a")); $this->Common_model->insertData('ical_import', $data); $log = array(); $query1 = $this->db->query("SELECT table_name FROM information_schema.tables WHERE table_schema = '{$db_name}' AND table_name = '{$db_table}' LIMIT 1"); /* if($query1->num_rows()==1) { if ($db_delete_old_data) { $condition = array("list_id" => $this->uri->segment(3)); $this->Common_model->deleteTableData('calendar',$condition); } } */ /* ! exporting event from source into hash */ require_once "codebase/class.php"; $exporter = new ICalExporter(); $events = $exporter->toHash($ical_content); $success_num = 0; $error_num = 0; /* ! inserting events in database */ $check_tb = $this->db->select('group_id')->where('list_id', $this->uri->segment(3))->order_by('id', 'desc')->limit(1)->get('calendar'); if ($check_tb->num_rows() != 0) { $i1 = $check_tb->row()->group_id; } else { $i1 = 1; } for ($i = $i1; $i <= count($events); $i++) { $event = $events[$i]; $days = (strtotime($event["end_date"]) - strtotime($event["start_date"])) / (60 * 60 * 24); $created = $event["start_date"]; for ($j = 1; $j <= $days; $j++) {