function edit($id = FALSE) { if ($this->input->post()) { $e = new Event($id); $p = $this->input->post(); if ($this->input->post('smonth') && $this->input->post('sday') && $this->input->post('sday')) { $p['start'] = $this->input->post('syear') . '-' . $this->input->post('smonth') . '-' . $this->input->post('sday'); } if ($this->input->post('emonth') && $this->input->post('eday') && $this->input->post('eyear')) { $p['end'] = $this->input->post('eyear') . '-' . $this->input->post('emonth') . '-' . $this->input->post('eday'); } $e->from_array($p, array('category_id', 'title', 'start', 'end', 'cost', 'address', 'coords', 'description', 'end')); if ($e->save()) { $this->session->set_flashdata('msg', '<div class="alert alert-success"><a class="close" data-dismiss="alert">×</a> The event was succesfully edited.</div>'); redirect('events/index'); } else { $this->data['errors'] = $e->error->all; } } $e = new Event($id); list($syear, $smonth, $sday) = explode('-', $e->start); $this->data['sday'] = $sday; $this->data['smonth'] = $smonth; $this->data['syear'] = $syear; list($eyear, $emonth, $eday) = explode('-', $e->end); $this->data['eday'] = $eday; $this->data['emonth'] = $emonth; $this->data['eyear'] = $eyear; $this->data['e'] = $e; $c = new Category(); $c->get_iterated(); $this->data['categories'][''] = "Choose a category"; foreach ($c as $category) { $this->data['categories'][$category->id] = $category->name; } }