/** * Edit background of category * * @param int $id cat. ID * * @author Nguyen Van Hiep * @access public * * @version 1.0 * @since 1.0 */ public function action_img($id = null) { $cat = Model_Categories::get_cat_with_expected_size($id); if (!$cat or $id < 4) { Session::set_flash('error', __('message.cat_not_exists')); Response::redirect('admin/categories'); } $this->add_js('img_preparation.js'); $up_dir = DOCROOT . 'assets/img/cat/temp/'; $img_dir = DOCROOT . 'assets/img/cat/'; $view = View::forge('admin/categories/img'); $view->cat = $cat; $view->error = array(); $view->img = ''; $view->width = 0; $view->height = 0; $view->pw = 0; $view->ph = 0; $view->rat = $cat['sizes']; if (Input::post('submit') == 'upload') { // Custom configuration for this upload $config = array('path' => $up_dir, 'randomize' => false, 'ext_whitelist' => array('jpg', 'jpeg', 'gif', 'png'), 'max_size' => MAX_IMG_SIZE, 'auto_rename' => true, 'overwrite' => false, 'prefix' => 'c' . $id . '_'); Upload::process($config); if (Upload::is_valid()) { File::delete_dir($up_dir, true, false); Upload::save(); $info = Upload::get_files(0); $filepath = $info['saved_to'] . $info['saved_as']; $view->img = $info['saved_as']; list($view->width, $view->height) = getimagesize($filepath); list($view->pw, $view->ph) = explode(':', $cat['sizes']); Session::set_flash('success', __('message.slider_uploaded')); } else { $err = Upload::get_errors()[0]['errors'][0]; $view->error['img'] = $err['message']; } } if (Input::post('submit') == 'save') { $x1 = Input::post('x1'); $y1 = Input::post('y1'); $x2 = Input::post('x2'); $y2 = Input::post('y2'); $w = Input::post('w'); $h = Input::post('h'); $img = Input::post('img'); $scale = 1; $this->resize_img($img_dir . $img, $up_dir . $img, $w, $h, $x1, $y1, $scale); Model_Categories::save_bg($id, $img, $cat['bg']); Session::set_flash('success', __('message.img_resized')); Response::redirect('admin/categories'); } $this->template->title = __('cat.edit'); $this->template->content = $view; }