Esempio n. 1
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Subject::validate('create');
         if ($val->run()) {
             $subject = Model_Subject::forge(array('subject_code' => Input::post('subject_code'), 'subject_desc' => Input::post('subject_desc'), 'semester' => Input::post('semester'), 'year' => Input::post('year'), 'user_id' => Input::post('user_id'), 'course_id' => Input::post('course_id')));
             if ($subject and $subject->save()) {
                 Session::set_flash('success', e('Added subject #' . $subject->id . '.'));
                 Response::redirect('site/subject');
             } else {
                 Session::set_flash('error', e('Could not save subject.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $courses = Model_Course::getCoursesOptions();
     $this->template->set_global('courses', $courses, false);
     // Global variables
     $teachers = Model_User::get_list_of_teachers();
     $this->template->set_global('teachers', $teachers, false);
     $this->template->title = "Subjects";
     $this->template->content = View::forge('site/subject/create');
 }