Esempio n. 1
0
File: book.php Progetto: xXLXx/ddc
 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');
 }
Esempio n. 2
0
 public function action_edit($id = null)
 {
     $where = ['id' => $id];
     if (Model_User::is_current_user('teacher')) {
         $where['subject.user_id'] = Auth::get('id');
     }
     $syllabus = Model_Syllabus::find('first', ['where' => $where, 'related' => ['subject']]);
     if (empty($syllabus)) {
         Session::set_flash('error', 'Syllabus does not exist.');
         Response::redirect('site/syllabuses');
     }
     $val = Model_Syllabus::validate('edit');
     if ($val->run()) {
         $syllabus->title = Input::post('title');
         $syllabus->file_url = Input::post('file_url');
         $syllabus->subject_id = Input::post('subject_id');
         if ($syllabus->save()) {
             Session::set_flash('success', e('Updated syllabus #' . $id));
             Response::redirect('site/syllabuses');
         } else {
             Session::set_flash('error', e('Could not update syllabus #' . $id));
         }
     } else {
         if (Input::method() == 'POST') {
             $syllabus->title = $val->validated('title');
             $syllabus->file_url = $val->validated('file_url');
             $syllabus->subject_id = $val->validated('subject_id');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('syllabus', $syllabus, false);
     }
     $subjects = Model_Subject::getSubjectOptions();
     $this->template->set_global('subjects', $subjects, false);
     $this->template->title = "Syllabuses";
     $this->template->content = View::forge('site/syllabuses/edit');
 }
Esempio n. 3
0
File: _form.php Progetto: xXLXx/ddc
		</div>
		<div class="form-group is-institutional">
	        <?php 
echo Form::checkbox('is_institutional', 1, Input::post('is_institutional', isset($activity) ? $activity->is_institutional : ''));
?>
			<?php 
echo Form::label('Is Institutional', 'is_institutional', array('class' => 'control-label'));
?>
		</div>

		<div class="form-group">
			<?php 
echo Form::label('Subject', 'subject_id', array('class' => 'control-label'));
?>
	        <?php 
echo Form::select('subject_id', Input::post('subject_id', isset($activity) ? $activity->subject_id : ''), Model_Subject::getSubjectOptions(), array('class' => 'subject form-control'));
?>
		</div>

		<div class="form-group">
			<?php 
echo Form::label('Activity', 'activity_content', array('class' => 'control-label'));
?>

				<?php 
echo Form::textarea('activity_content', Input::post('activity_content', isset($activity) ? $activity->activity_content : ''), array('class' => 'col-md-8 form-control', 'rows' => 8, 'placeholder' => 'Activity content'));
?>
		</div>

		<div class="form-group text-center">
			<label class='control-label'>&nbsp;</label>