Example #1
0
 public function themHaAction()
 {
     // TODO Auto-generated {0}::indexAction() default action
     $form = new Admin_Form_HinhAnh();
     $form->submitCon->setLabel('Lưu và tiếp tục');
     $form->submitExit->setLabel('Lưu và thoát');
     $form->cancel->setLabel('Không lưu');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             //determine filename and extension
             $info = pathinfo($form->ten_file->getFileName(null, false));
             $filename = $info['filename'];
             $ext = $info['extension'] ? "." . $info['extension'] : "";
             //filter for renaming.. prepend with current time
             $file = time() . '_' . Default_Model_Functions::convert_vi_to_en($filename) . $ext;
             $form->ten_file->addFilter(new Zend_Filter_File_Rename(array("target" => $file, "overwrite" => true)))->addFilter(new Khcn_Filter_File_Resize(array('width' => 720, 'height' => 720, 'keepRatio' => true)));
             $form->getValue('ten_file');
             $hinh_anh = new Default_Model_HinhAnh();
             $hinh_anh->setTrangThai($form->getValue('trang_thai'));
             $hinh_anh->setTenFile($file);
             $kq = $hinh_anh->them();
             if (!$kq) {
                 $_SESSION['msg'] = 'Lỗi !. Đã có lỗi trong quá trình xử lý, vui lòng thử lại .';
                 $_SESSION['type_msg'] = 'error';
                 $this->_redirect('/admin/cau-hinh/index');
             }
             $this->flash();
             $_SESSION['msg'] = 'Thành công !. Dữ liệu đã được lưu trữ .';
             $_SESSION['type_msg'] = 'success';
             if ($form->submitCon->isChecked()) {
                 $this->_redirect('/admin/cau-hinh/them-ha');
             } else {
                 $this->_redirect('/admin/cau-hinh/hinh-anh');
             }
         } else {
             $form->populate($formData);
         }
     }
 }
 public function themHaAction()
 {
     // TODO Auto-generated {0}::indexAction() default action
     $form = new Admin_Form_HinhAnh();
     $form->submitCon->setLabel('Lưu và tiếp tục');
     $form->submitExit->setLabel('Lưu và thoát');
     $form->cancel->setLabel('Không lưu');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             //determine filename and extension
             $info = pathinfo($form->ten_file->getFileName(null, false));
             $filename = $info['filename'];
             $ext = $info['extension'] ? "." . $info['extension'] : "";
             //filter for renaming.. prepend with current time
             $file = time() . '_' . Default_Model_Functions::convert_vi_to_en($filename) . $ext;
             $form->ten_file->addFilter(new Zend_Filter_File_Rename(array("target" => $file, "overwrite" => true)))->addFilter(new Khcn_Filter_File_Resize(array('width' => 720, 'height' => 720, 'keepRatio' => true)));
             $values = $form->getValues();
             $table = Khcn_Api::_()->getDbTable('hinh_anh', 'default');
             $row = $table->createRow();
             $row->slideshow = $values['slideshow'];
             $row->ten_file = $file;
             $row->save();
             $_SESSION['msg'] = 'Thành công !. Dữ liệu đã được lưu trữ .';
             $_SESSION['type_msg'] = 'success';
             if ($form->submitCon->isChecked()) {
                 $this->_redirect('/admin/gioi-thieu/them-ha');
             } else {
                 $this->_redirect('/admin/gioi-thieu/hinh-anh');
             }
         } else {
             $form->populate($formData);
         }
     }
 }