public function action_create() { if (Input::method() == 'POST') { $val = Model_Leave::validate('create'); if ($val->run()) { $leave = Model_Leave::forge(array('date_of_leave' => Input::post('date_of_leave'), 'reason' => Input::post('reason'), 'type' => Input::post('type'))); if ($leave and $leave->save()) { Session::set_flash('success', 'Added leave #' . $leave->id . '.'); Response::redirect('leaves'); } else { Session::set_flash('error', 'Could not save leave.'); } } else { Session::set_flash('error', $val->error()); } } $this->template->title = "Leaves"; $this->template->content = View::forge('leaves/create'); }
public function action_create($id = null) { parent::has_access("add_leave"); is_null($id) and Response::redirect('leaves'); $data['employees'] = Model_Employee::find('all', array('where' => array('id' => $id))); if (Input::method() == 'POST') { $dol_date = Input::post('dol_date'); foreach ($dol_date as $var_dol_date) { $var_dol_month = Input::post('dol_month'); $var_dol_year = Input::post('dol_year'); $var_dol = $var_dol_year . '-' . $var_dol_month . '-' . $var_dol_date; $leave = Model_Leave::forge(array('employee_id' => $id, 'date_of_leave' => $var_dol, 'time' => '8', 'type' => Input::post('type'))); if ($leave and $leave->save()) { Session::set_flash('success', 'Added leave for employee #' . $id . '.'); } else { Session::set_flash('error', 'Could not save leave.'); } } Response::redirect('leaves/view/' . $id); } $this->template->title = "Leaves"; $this->template->content = View::forge('leaves/create', $data); }