Пример #1
0
 public function postProcess()
 {
     if (Tools::isSubmit('viewblog') && ($id_leoblog_blog = (int) Tools::getValue('id_leoblog_blog')) && ($blog = new LeoBlogBlog($id_leoblog_blog, $this->context->language->id)) && Validate::isLoadedObject($blog)) {
         $this->redirect_after = $this->getPreviewUrl($blog);
     }
     if (Tools::isSubmit('submitAddleoblog_blog') || Tools::isSubmit('submitAddleoblog_blogAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_leoblog_blog = (int) Tools::getValue('id_leoblog_blog'))) {
             $blog = new LeoBlogBlog();
             $this->copyFromPost($blog, 'blog');
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 if (!($image = $this->_uploadImage($_FILES['image'], '', ''))) {
                     return false;
                 }
                 $blog->image = $image;
             }
             $blog->id_employee = $this->context->employee->id;
             if (!$blog->add()) {
                 $this->errors[] = Tools::displayError('An error occurred while creating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 # validate module
                 $this->updateAssoShop($blog->id);
             }
         } else {
             $blog = new LeoBlogBlog($id_leoblog_blog);
             $this->copyFromPost($blog, 'blog');
             //$folder = _LEOBLOG_BLOG_IMG_DIR_; # validate module
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 if (file_exists(_LEOBLOG_CACHE_IMG_DIR_ . 'b/' . $id_leoblog_blog)) {
                     LeoBlogHelper::rrmdir(_LEOBLOG_CACHE_IMG_DIR_ . 'b/' . $id_leoblog_blog);
                 }
                 if (!($image = $this->_uploadImage($_FILES['image'], '', ''))) {
                     return false;
                 }
                 $blog->image = $image;
             }
             if (!$blog->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 # validate module
                 $this->updateAssoShop($blog->id);
             }
         }
         if (Tools::isSubmit('submitAddblogAndPreview')) {
             # validate module
             $this->redirect_after = $this->previewUrl($blog);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             # validate module
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $blog->id . '&conf=4&update' . $this->table . '&token=' . Tools::getValue('token'));
         } else {
             # validate module
             Tools::redirectAdmin(self::$currentIndex . '&id_leoblogcat=' . $blog->id_leoblogcat . '&conf=4&token=' . Tools::getValue('token'));
         }
     } else {
         parent::postProcess(true);
     }
 }