public function ajax_update()
{
$this->_validate();
if ($this->input->post('remove_photo') AND empty($_FILES['photo']['name'])) {
$data['error_string'][] = 'انتخاب عکس اجباری است';
$data['inputerror'][] = 'photo';
$data['status'] = FALSE;
}
$data = array(
'title' => $this->input->post('title'),
'sub_title' => $this->input->post('sub_title'),
'message' => $this->input->post('message',FALSE),
//'captcha' => $this->input->post('captcha'),
'tarikh' => time("NOW")
);
if ($this->input->post('remove_photo')) // if remove photo checked
{
if (file_exists(base_url() . 'assets/img/' . $this->input->post('remove_photo')) && $this->input->post('remove_photo'))
unlink(base_url() . 'assets/img/' . $this->input->post('remove_photo'));
$data['image'] = '';
}
if (!empty($_FILES['photo']['name'])) {
$upload = $this->_do_upload();
//delete file
$person = $this->person->get_by_id($this->table, $this->input->post('id'), $this->where);
if (file_exists(base_url() . 'assets/img/' . $person->image) && $person->image)
unlink(base_url() . 'assets/img/' . $person->image);
$data['image'] = $upload;
}
$where = ['id' => $this->input->post('id'), 'position' => $this->position];
print_r($data);
$num = $this->person->update($this->table, $where, $data);
$this->logfile->message('product', '', 'update id'.$this->input->post('id'));
echo json_encode(array("status" => TRUE, 'number affected rows' => $num));
}