public function add_dine() { $this->_checkPermission(); $data = $_POST['dine']; Flash::set('postdata', $data); $image = $_POST['upload']; $path = str_replace('..', '', $image['path']); $overwrite = false; // verification if (empty($data['title'])) { Flash::set('error', __('You have to specify a dine title!')); redirect(get_url('dine/create')); } if (isset($_FILES)) { // no image file selected if (empty($_FILES['upload_file']['name'])) { Flash::set('error', __('You have to select a image to be uploaded!')); redirect(get_url('dine/create')); } } else { Flash::set('error', __('You have to select a image to be uploaded!')); redirect(get_url('dine/create')); } $dine = new Dine($data); $dine->created_by_id = AuthUser::getId(); $dine->created_on = date('Y-m-d H:i:s'); if (!$dine->save()) { Flash::set('error', __('Dine is not added!')); redirect(get_url('dine/create')); } else { if (isset($_FILES)) { $dine_id = $dine->lastInsertId(); $file = $this->upload_file($_FILES['upload_file']['name'], FILES_DIR . '/dine/images/', $_FILES['upload_file']['tmp_name'], $overwrite, $dine_id); if ($file === false) { Flash::set('error', __('Dine image has not been uploaded!')); } //Add Image to database $data = $_POST['dine']; Flash::set('post_data', (object) $data); $dine = Record::findByIdFrom('Dine', $dine_id); if (!$dine->update('Dine', array('filename' => $file), 'id=' . $dine_id)) { Flash::set('error', __('Image has not been updated.')); } else { Flash::set('success', __('Dine has been updated!')); if (isset($_POST['commit'])) { redirect(get_url('dine')); } else { redirect(get_url('dine/view/' . $dine->id)); } } } Flash::set('success', __('Dine has been added!')); } redirect(get_url('dine')); }