/** * Register * * @access public * @author Dao Anh Minh */ public function action_register() { $view = View::forge('admin/gallery/register'); $view->err = array(); $view->data = array('description' => ''); if (Input::method() == 'POST') { Upload::process($this->config); if (Upload::is_valid()) { Upload::save(); $file_name = Upload::get_files(0)['saved_as']; if (!empty($file_name)) { $img = Model_Img::forge(); $img->name = $file_name; $img->active = Input::post('active', false); $img->type = IMG_GALLERY; $img->info = serialize(array('info' => Input::post('description', ''))); $img->save(); Session::set_flash('success', 'Đăng ký hình thành công'); Response::redirect('admin/gallery'); } else { Session::set_flash('error', 'Chỉ chấp nhận file hình'); Response::redirect('admin/gallery/register'); } } else { Session::set_flash('error', 'Hình bạn chọn không phù hợp, vui lòng thử lại'); $view->data = Input::post(); } } $this->template->title = 'Đăng ký hình'; $this->template->content = $view; }
/** * Register background * * @param integer $logo_id * * @access public * @author Dao Anh Minh */ public function action_register() { $view = View::forge('admin/mainlogo/register'); $view->err = array(); if (Input::method() == 'POST') { if (count(Input::file()) == 0) { Session::set_flash('error', 'Chưa chọn hình'); Response::redirect('admin/mainlogo/register'); } Upload::process($this->config); if (Upload::is_valid()) { Upload::save(); } else { Session::set_flash('error', 'Chỉ chấp nhận file hình'); Response::redirect('admin/mainlogo/register'); } $file_name = Upload::get_files(0)['saved_as']; if (!empty($file_name)) { $img = Model_Img::forge(); $active = Input::post('active', false); if ($active != false) { // update all background images to non-active Model_Img::query()->where('type', IMG_LOGO)->set('active', false)->update(); } $img->name = $file_name; $img->active = $active; $img->type = IMG_LOGO; $img->info = null; $img->save(); Session::set_flash('success', 'Đăng ký logo thành công'); Response::redirect('admin/mainlogo'); } else { Session::set_flash('error', 'Có lỗi xảy ra, vui lòng thử lại'); Response::redirect('admin/mainlogo'); } } $this->template->title = 'Đăng ký logo chính'; $this->template->content = $view; }