<div class="form-group"> <?php echo Form::label('Year Level', 'year_level', array('class' => 'control-label')); ?> <?php echo Form::select('year_level', Input::post('year_level', isset($student) ? $student->year_level : ''), Config::get('year_level'), array('class' => 'form-control')); ?> </div> <div class="form-group"> <?php echo Form::label('Courses', 'course_id', array('class' => 'control-label')); ?> <?php echo Form::select('course_id', Input::post('course_id', isset($student) ? $student->course_id : ''), Model_Course::getCoursesOptions(), array('class' => 'form-control')); ?> </div> <?php echo Form::hidden('user_id', Input::post('user_id', $student->user_id, array('class' => 'col-md-4 form-control'))); ?> <br/><br/> <div class="form-group text-center"> <label class='control-label'> </label> <?php echo Form::submit('submit', 'Save', array('class' => 'btn btn-primary')); ?> <?php echo Html::anchor('site/student', 'Back', array('class' => 'btn btn-primary')); ?>
public function action_edit($id = null) { $where = ['id' => $id]; if (Model_User::is_current_user('teacher')) { $where['subject.user_id'] = Auth::get('id'); } $book = Model_Book::find('first', ['where' => $where, 'related' => ['subject']]); if (empty($book)) { Session::set_flash('error', 'Book does not exist.'); Response::redirect('site/book'); } $val = Model_Book::validate('edit'); if ($val->run()) { $bookUploadConfig = Config::get('upload_book_url'); $bookUploadConfig['base_path'] = $bookUploadConfig['path']; $bookUploadConfig['path'] = $this->getFilePath($bookUploadConfig['path'], Input::post('sub_folder'), Input::post('course_id')); $isReuploaded = false; $book->book_name = Input::post('book_name'); $book->subject_id = Input::post('subject_id'); $book->course_id = Input::post('course_id'); $book->is_institutional = Input::post('is_institutional'); $book->sub_folder = Input::post('sub_folder'); Upload::process(Config::get('upload_profile_picture')); if (empty(Upload::get_files()) || Upload::is_valid()) { if (!empty(Upload::get_files())) { Upload::save(); $value = Upload::get_files(); foreach ($value as $files) { $book->cover_photo = $value[0]['saved_as']; } } Upload::process($bookUploadConfig); if (Upload::get_files() || empty(Upload::is_valid())) { if (!empty(Upload::get_files())) { Upload::save(); $value = Upload::get_files(); foreach ($value as $files) { unlink($bookUploadConfig['base_path'] . '/' . $book->book_url); $book->book_url = str_replace($bookUploadConfig['base_path'] . '/', '', $bookUploadConfig['path']) . '/' . $value[0]['saved_as']; $isReuploaded = true; } } $tmpPath = str_replace($bookUploadConfig['base_path'] . '/', '', $bookUploadConfig['path']); if (!$isReuploaded && strpos($book->book_url, $tmpPath) == false) { rename($bookUploadConfig['base_path'] . '/' . $book->book_url, $bookUploadConfig['path'] . '/' . preg_replace('/^.+\\//', '', $book->book_url)); $book->book_url = $tmpPath . '/' . preg_replace('/^.+\\//', '', $book->book_url); } if ($book->save()) { Session::set_flash('success', e('Updated book #' . $id)); Response::redirect('site/book'); } else { Session::set_flash('error', e('Could not update book #' . $id)); } } else { Session::set_flash('error', 'Uploaded book is invalid.'); $this->template->set_global('book', $book, false); } } else { Session::set_flash('error', 'Cover photo is invalid.'); $this->template->set_global('book', $book, false); } } else { if (Input::method() == 'POST') { $book->book_url = $val->validated('book_url'); $book->book_name = $val->validated('book_name'); $book->subject_id = $val->validated('subject_id'); $book->cover_photo = $val->validated('cover_photo'); $book->course_id = $val->validated('course_id'); $book->is_institutional = $val->validated('is_institutional'); $book->sub_folder = $val->validated('sub_folder'); Session::set_flash('error', $val->error()); } $this->template->set_global('book', $book, false); } $subjects = Model_Subject::getSubjectOptions(); $courses = Model_Course::getCoursesOptions(); $this->template->set_global('subjects', $subjects, false); $this->template->set_global('courses', $courses, false); $this->template->title = "Books"; $this->template->content = View::forge('site/book/edit'); }
public function action_edit($id = null) { $where = ['id' => $id]; if (Model_User::is_current_user('teacher')) { $where['user_id'] = Auth::get('id'); } $subject = Model_Subject::find('first', ['where' => $where]); if (empty($subject)) { Session::set_flash('error', 'Subject does not exist.'); Response::redirect('site/subject'); } $val = Model_Subject::validate('edit'); if ($val->run()) { $subject->subject_code = Input::post('subject_code'); $subject->subject_desc = Input::post('subject_desc'); $subject->semester = Input::post('semester'); $subject->year = Input::post('year'); $subject->user_id = Input::post('user_id'); $subject->course_id = Input::post('course_id'); if ($subject->save()) { Session::set_flash('success', e('Updated subject #' . $id)); Response::redirect('site/subject'); } else { Session::set_flash('error', e('Could not update subject #' . $id)); } } else { if (Input::method() == 'POST') { $subject->subject_code = $val->validated('subject_code'); $subject->subject_desc = $val->validated('subject_desc'); $subject->semester = $val->validated('semester'); $subject->year = $val->validated('year'); $subject->user_id = $val->validated('user_id'); $subject->course_id = $val->validated('course_id'); Session::set_flash('error', $val->error()); } $this->template->set_global('subject', $subject, false); } $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/edit'); }