Exemple #1
0
 public function action_edit($id = null)
 {
     parent::has_access("add_leave");
     is_null($id) and Response::redirect('leaves');
     if (!($leave = Model_Leave::find($id))) {
         Session::set_flash('error', 'Could not find leave #' . $id);
         Response::redirect('leaves');
     }
     $val = Model_Leave::validate('edit');
     if ($val->run()) {
         $var_dol_day = Input::post('dol_day');
         $var_dol_month = Input::post('dol_month');
         $var_dol_year = Input::post('dol_year');
         $var_dol = $var_dol_year . '-' . $var_dol_month . '-' . $var_dol_day;
         $leave->date_of_leave = $var_dol;
         $leave->time = Input::post('time');
         $leave->type = Input::post('type');
         if ($leave->save()) {
             Session::set_flash('success', 'Updated leave #' . $id);
             Response::redirect('leaves/view/' . $leave->employee_id);
         } else {
             Session::set_flash('error', 'Could not update leave #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $leave->date_of_leave = $val->validated('date_of_leave');
             $leave->time = $val->validated('time');
             $leave->type = $val->validated('type');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('leave', $leave, false);
     }
     $this->template->title = "Leaves";
     $this->template->content = View::forge('leaves/edit');
 }
Exemple #2
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('leaves');
     if (!($leave = Model_Leave::find($id))) {
         Session::set_flash('error', 'Could not find leave #' . $id);
         Response::redirect('leaves');
     }
     $val = Model_Leave::validate('edit');
     if ($val->run()) {
         $leave->date_of_leave = Input::post('date_of_leave');
         $leave->reason = Input::post('reason');
         $leave->type = Input::post('type');
         if ($leave->save()) {
             Session::set_flash('success', 'Updated leave #' . $id);
             Response::redirect('leaves');
         } else {
             Session::set_flash('error', 'Could not update leave #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $leave->employee_id = $val->validated('employee_id');
             $leave->date_of_leave = $val->validated('date_of_leave');
             $leave->reason = $val->validated('reason');
             $leave->type = $val->validated('type');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('leave', $leave, false);
     }
     $this->template->title = "Leaves";
     $this->template->content = View::forge('leaves/edit');
 }