public function postProcess()
 {
     if (Tools::isSubmit('deletesmart_blog_category') && Tools::getValue('id_smart_blog_category') != '') {
         $id_lang = (int) Context::getContext()->language->id;
         $catpost = (int) SmartBlogPost::getToltalByCategory($id_lang, Tools::getValue('id_smart_blog_category'));
         if ((int) $catpost != 0) {
             $this->errors[] = Tools::displayError('You need to delete all posts associate with this category .');
         } else {
             $BlogCategory = new BlogCategory((int) Tools::getValue('id_smart_blog_category'));
             if (!$BlogCategory->delete()) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbdeletecat', array('BlogCategory' => $BlogCategory));
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         }
     } elseif (Tools::isSubmit('submitAddsmart_blog_category')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_smart_blog_category = (int) Tools::getValue('id_smart_blog_category'))) {
             $BlogCategory = new BlogCategory();
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 if (Tools::getValue('link_rewrite_' . $language['id_lang']) == '' && Tools::getValue('link_rewrite_' . $language['id_lang']) == null) {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('meta_title_' . $language['id_lang']));
                 } else {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
                 }
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->created = Date('y-m-d H:i:s');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             } else {
                 Hook::exec('actionsbnewcat', array('BlogCategory' => $BlogCategory));
                 $this->processImageCategory($_FILES, $BlogCategory->id);
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         } elseif ($id_smart_blog_category = Tools::getValue('id_smart_blog_category')) {
             $BlogCategory = new BlogCategory($id_smart_blog_category);
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbupdatecat', array('BlogCategory' => $BlogCategory));
             }
             $this->processImageCategory($_FILES, $BlogCategory->id_smart_blog_category);
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
         }
     } elseif (Tools::isSubmit('statussmart_blog_category') && Tools::getValue($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Hook::exec('actionsbtogglecat', array('SmartBlogCat' => $this->object));
                     $identifier = (int) $object->id_parent ? '&id_smart_blog_category=' . (int) $object->id_parent : '';
                     Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('smart_blog_categoryOrderby') && Tools::isSubmit('smart_blog_categoryOrderway')) {
         $this->_defaultOrderBy = Tools::getValue('smart_blog_categoryOrderby');
         $this->_defaultOrderWay = Tools::getValue('smart_blog_categoryOrderway');
     }
 }
 public function postProcess()
 {
     if (Tools::isSubmit('viewcms') && ($id_cms = (int) Tools::getValue('id_cms')) && ($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) {
         $redir = $this->context->link->getCMSLink($cms);
         if (!$cms->active) {
             $admin_dir = dirname($_SERVER['PHP_SELF']);
             $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
             $redir .= '?adtoken=' . Tools::getAdminTokenLite('AdminCmsContent') . '&ad=' . $admin_dir . '&id_employee=' . (int) $this->context->employee->id;
         }
         Tools::redirectAdmin($redir);
     } elseif (Tools::isSubmit('deletecms')) {
         if (Tools::getValue('id_cms') == Configuration::get('PS_CONDITIONS_CMS_ID')) {
             Configuration::updateValue('PS_CONDITIONS', 0);
             Configuration::updateValue('PS_CONDITIONS_CMS_ID', 0);
         }
         $cms = new CMS((int) Tools::getValue('id_cms'));
         $cms->cleanPositions($cms->id_cms_category);
         if (!$cms->delete()) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=1&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::getValue('submitDel' . $this->table)) {
         if ($this->tabAccess['delete'] === '1') {
             if (Tools::isSubmit($this->table . 'Box')) {
                 $cms = new CMS();
                 $result = true;
                 $result = $cms->deleteSelection(Tools::getValue($this->table . 'Box'));
                 if ($result) {
                     $cms->cleanPositions((int) Tools::getValue('id_cms_category'));
                     $token = Tools::getAdminTokenLite('AdminCmsContent');
                     Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . $token . '&id_cms_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->errors[] = Tools::displayError('An error occurred while deleting this selection.');
             } else {
                 $this->errors[] = Tools::displayError('You must select at least one element to delete.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_cms = (int) Tools::getValue('id_cms'))) {
             $cms = new CMS();
             $this->copyFromPost($cms, 'cms');
             if (!$cms->add()) {
                 $this->errors[] = Tools::displayError('An error occurred while creating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         } else {
             $cms = new CMS($id_cms);
             $this->copyFromPost($cms, 'cms');
             if (!$cms->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         }
         if (Tools::isSubmit('submitAddcmsAndPreview')) {
             $alias = $this->getFieldValue($cms, 'link_rewrite', $this->context->language->id);
             $preview_url = $this->context->link->getCMSLink($cms, $alias, $this->context->language->id);
             if (!$cms->active) {
                 $admin_dir = dirname($_SERVER['PHP_SELF']);
                 $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                 $params = http_build_query(array('adtoken' => Tools::getAdminTokenLite('AdminCmsContent'), 'ad' => $admin_dir, 'id_employee' => (int) $this->context->employee->id));
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $params = '?' . $params;
                 } else {
                     $params = '&' . $params;
                 }
                 $preview_url .= $cms->active ? '' : $params;
             }
             Tools::redirectAdmin($preview_url);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $cms->id . '&conf=4&update' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && Tools::isSubmit('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
         } elseif (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) {
             $this->errors[] = Tools::displayError('Failed to update the position.');
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=5&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitBulkdeletecms')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'bulkdelete';
             $this->boxes = Tools::getValue($this->table . 'Box');
             if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) {
                 $firstCms = new CMS((int) $this->boxes[0]);
                 $id_cms_category = (int) $firstCms->id_cms_category;
                 if (!($res = parent::postProcess(true))) {
                     return $res;
                 }
                 Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCmsContent') . '&id_cms_category=' . $id_cms_category);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } else {
         parent::postProcess(true);
     }
 }
 public function validateRules($class_name = false)
 {
     $employee = new Employee((int) Tools::getValue('id_employee'));
     if (!Validate::isLoadedObject($employee) && !Validate::isPasswd(Tools::getvalue('passwd'), Validate::ADMIN_PASSWORD_LENGTH)) {
         return !($this->errors[] = sprintf(Tools::displayError('The password must be at least %s characters long.'), Validate::ADMIN_PASSWORD_LENGTH));
     }
     return parent::validateRules($class_name);
 }
 public function postProcess()
 {
     if (Tools::isSubmit('viewcms') && ($id_cms = (int) Tools::getValue('id_cms'))) {
         parent::postProcess();
         if (($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) {
             $this->redirect_after = $this->getPreviewUrl($cms);
             Tools::redirectAdmin($this->redirect_after);
         }
     } elseif (Tools::isSubmit('deletecms')) {
         if (Tools::getValue('id_cms') == Configuration::get('PS_CONDITIONS_CMS_ID')) {
             Configuration::updateValue('PS_CONDITIONS', 0);
             Configuration::updateValue('PS_CONDITIONS_CMS_ID', 0);
         }
         $cms = new CMS((int) Tools::getValue('id_cms'));
         $cms->cleanPositions($cms->id_cms_category);
         if (!$cms->delete()) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=1&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::getValue('submitDel' . $this->table)) {
         if ($this->tabAccess['delete'] === '1') {
             if (Tools::isSubmit($this->table . 'Box')) {
                 $cms = new CMS();
                 $result = true;
                 $result = $cms->deleteSelection(Tools::getValue($this->table . 'Box'));
                 if ($result) {
                     $cms->cleanPositions((int) Tools::getValue('id_cms_category'));
                     $token = Tools::getAdminTokenLite('AdminCmsContent');
                     Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . $token . '&id_cms_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->errors[] = Tools::displayError('An error occurred while deleting this selection.');
             } else {
                 $this->errors[] = Tools::displayError('You must select at least one element to delete.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_cms = (int) Tools::getValue('id_cms'))) {
             $cms = new CMS();
             $this->copyFromPost($cms, 'cms');
             if (!$cms->add()) {
                 $this->errors[] = Tools::displayError('An error occurred while creating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         } else {
             $cms = new CMS($id_cms);
             $this->copyFromPost($cms, 'cms');
             if (!$cms->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         }
         if (Tools::isSubmit('view' . $this->table)) {
             $this->redirect_after = $this->getPreviewUrl($cms);
             Tools::redirectAdmin($this->redirect_after);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $cms->id . '&conf=4&update' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && Tools::isSubmit('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
         } elseif (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) {
             $this->errors[] = Tools::displayError('Failed to update the position.');
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=5&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitBulkdeletecms')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'bulkdelete';
             $this->boxes = Tools::getValue($this->table . 'Box');
             if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) {
                 $firstCms = new CMS((int) $this->boxes[0]);
                 $id_cms_category = (int) $firstCms->id_cms_category;
                 if (!($res = parent::postProcess(true))) {
                     return $res;
                 }
                 Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCmsContent') . '&id_cms_category=' . $id_cms_category);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } else {
         parent::postProcess(true);
     }
 }
 public function postProcess()
 {
     $SmartBlogPost = new SmartBlogPost();
     $BlogPostCategory = new BlogPostCategory();
     if (Tools::isSubmit('deletesmart_blog_post') && Tools::getValue('id_smart_blog_post') != '') {
         $SmartBlogPost = new SmartBlogPost((int) Tools::getValue('id_smart_blog_post'));
         if (!$SmartBlogPost->delete()) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Hook::exec('actionsbdeletepost', array('SmartBlogPost' => $SmartBlogPost));
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
         }
     } elseif (Tools::getValue('deleteImage')) {
         $this->processForceDeleteImage();
         if (Tools::isSubmit('forcedeleteImage')) {
             Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminBlogPost') . '&conf=7');
         }
     } elseif (Tools::isSubmit('submitAddsmart_blog_post')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_smart_blog_post = (int) Tools::getValue('id_smart_blog_post'))) {
             $SmartBlogPost = new $SmartBlogPost();
             $id_lang_default = Configuration::get('PS_LANG_DEFAULT');
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = Tools::link_rewrite(Tools::getValue('meta_title_' . $language['id_lang']));
                 $SmartBlogPost->meta_title[$language['id_lang']] = $title;
                 $SmartBlogPost->meta_keyword[$language['id_lang']] = (string) Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $SmartBlogPost->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $SmartBlogPost->short_description[$language['id_lang']] = (string) Tools::getValue('short_description_' . $language['id_lang']);
                 $SmartBlogPost->content[$language['id_lang']] = Tools::getValue('content_' . $language['id_lang']);
                 if (Tools::getValue('link_rewrite_' . $language['id_lang']) == '' && Tools::getValue('link_rewrite_' . $language['id_lang']) == null) {
                     $SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('meta_title_' . $id_lang_default));
                 } else {
                     $SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('link_rewrite_' . $language['id_lang']));
                 }
             }
             $SmartBlogPost->id_parent = Tools::getValue('id_parent');
             $SmartBlogPost->position = 0;
             $SmartBlogPost->active = Tools::getValue('active');
             $SmartBlogPost->id_category = Tools::getValue('id_category');
             $SmartBlogPost->comment_status = Tools::getValue('comment_status');
             $SmartBlogPost->id_author = $this->context->employee->id;
             $SmartBlogPost->created = Date('y-m-d H:i:s');
             $SmartBlogPost->modified = Date('y-m-d H:i:s');
             $SmartBlogPost->available = 1;
             $SmartBlogPost->is_featured = Tools::getValue('is_featured');
             $SmartBlogPost->viewed = 1;
             $SmartBlogPost->post_type = Tools::getValue('post_type');
             if (!$SmartBlogPost->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             } else {
                 Hook::exec('actionsbnewpost', array('SmartBlogPost' => $SmartBlogPost));
                 $this->updateTags($languages, $SmartBlogPost);
                 $this->processImage($_FILES, $SmartBlogPost->id);
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
             }
         } elseif ($id_smart_blog_post = Tools::getValue('id_smart_blog_post')) {
             $SmartBlogPost = new $SmartBlogPost($id_smart_blog_post);
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = Tools::link_rewrite(Tools::getValue('meta_title_' . $language['id_lang']));
                 $SmartBlogPost->meta_title[$language['id_lang']] = $title;
                 $SmartBlogPost->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $SmartBlogPost->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $SmartBlogPost->short_description[$language['id_lang']] = Tools::getValue('short_description_' . $language['id_lang']);
                 $SmartBlogPost->content[$language['id_lang']] = Tools::getValue('content_' . $language['id_lang']);
                 $SmartBlogPost->link_rewrite[$language['id_lang']] = Tools::link_rewrite(Tools::getValue('link_rewrite_' . $language['id_lang']));
             }
             $SmartBlogPost->is_featured = Tools::getValue('is_featured');
             $SmartBlogPost->id_parent = Tools::getValue('id_parent');
             $SmartBlogPost->active = Tools::getValue('active');
             $SmartBlogPost->id_category = Tools::getValue('id_category');
             $SmartBlogPost->comment_status = Tools::getValue('comment_status');
             $SmartBlogPost->id_author = $this->context->employee->id;
             $SmartBlogPost->modified = Date('y-m-d H:i:s');
             if (!$SmartBlogPost->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbupdatepost', array('SmartBlogPost' => $SmartBlogPost));
             }
             $this->updateTags($languages, $SmartBlogPost);
             $this->processImage($_FILES, $SmartBlogPost->id_smart_blog_post);
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
         }
     } elseif (Tools::isSubmit('statussmart_blog_post') && Tools::getValue($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Hook::exec('actionsbtogglepost', array('SmartBlogPost' => $this->object));
                     $identifier = (int) $object->id_parent ? '&id_smart_blog_post=' . (int) $object->id_parent : '';
                     Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogPost'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('smart_blog_postOrderby') && Tools::isSubmit('smart_blog_postOrderway')) {
         $this->_defaultOrderBy = Tools::getValue('smart_blog_postOrderby');
         $this->_defaultOrderWay = Tools::getValue('smart_blog_postOrderway');
     }
 }
 public function postProcess()
 {
     //ADD
     if (Tools::isSubmit('submitAddcampaign')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         // ADD WAY
         if (!($id_campaign = (int) Tools::getValue('id_campaign')) && empty($this->errors)) {
             $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
             // Include voucher :
             // Create campaign :
             $campaign = new Campaign();
             $campaign->name = Tools::getValue('name');
             $campaign->email_tpl = Tools::getValue('email_tpl');
             $campaign->execution_time_day = Tools::getValue('execution_time_day');
             $campaign->execution_time_hour = Tools::getValue('execution_time_hour');
             $campaign->voucher_prefix = Tools::getValue('voucher_prefix');
             $campaign->voucher_amount = Tools::getValue('voucher_amount');
             $campaign->voucher_amount_type = Tools::getValue('voucher_amount_type');
             $campaign->voucher_day = Tools::getValue('voucher_day');
             $campaign->active = Tools::getValue('active');
             // Create email files :
             $path = _PS_ROOT_DIR_ . '/modules/superabandonedcart/mails/' . $defaultLanguage->iso_code . '/';
             if (!file_exists($path)) {
                 if (!mkdir($path, 0777, true)) {
                     $this->errors[] = Tools::displayError('Mails directory could not be created. Please check system permissions');
                 }
             }
             $tpl_file_name = $campaign->getFileName('html');
             // create html files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, $campaign->email_tpl);
             fwrite($f, PHP_EOL);
             fclose($f);
             $tpl_file_name = $campaign->getFileName('txt');
             // create txt files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, strip_tags($campaign->email_tpl));
             fwrite($f, PHP_EOL);
             fclose($f);
             if (!$campaign->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             }
             // UPDATE WAY
         } elseif ($id_campaign = Tools::getValue('id_campaign')) {
             $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
             // Create campaign :
             $campaign = new Campaign($id_campaign);
             $campaign->name = Tools::getValue('name');
             $campaign->email_tpl = Tools::getValue('email_tpl');
             $campaign->execution_time_day = Tools::getValue('execution_time_day');
             $campaign->execution_time_hour = Tools::getValue('execution_time_hour');
             $campaign->voucher_prefix = Tools::getValue('voucher_prefix');
             $campaign->voucher_amount = Tools::getValue('voucher_amount');
             $campaign->voucher_amount_type = Tools::getValue('voucher_amount_type');
             $campaign->voucher_day = Tools::getValue('voucher_day');
             $campaign->active = Tools::getValue('active');
             $path = _PS_ROOT_DIR_ . '/modules/superabandonedcart/mails/' . $defaultLanguage->iso_code . '/';
             if (!file_exists($path)) {
                 if (!mkdir($path, 0777, true)) {
                     $this->errors[] = Tools::displayError('Mails directory could not be created. Please check system permissions');
                 }
             }
             $tpl_file_name = $campaign->getFileName('html');
             // create html files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, $campaign->email_tpl);
             fwrite($f, PHP_EOL);
             fclose($f);
             $tpl_file_name = $campaign->getFileName('txt');
             // create txt files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, strip_tags($campaign->email_tpl));
             fwrite($f, PHP_EOL);
             fclose($f);
             if (!$campaign->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             }
         }
     } elseif (Tools::isSubmit('statuscampaign') && Tools::getValue($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     $identifier = (int) $object->id_parent ? '&id_campaign=' . (int) $object->id_parent : '';
                     Tools::redirectAdmin($this->context->link->getAdminLink('AdminSuperAbandonedCart'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::getIsset('deletecampaign') && Tools::getValue($this->identifier)) {
         $id_campaign = (int) Tools::getValue($this->identifier);
         $b = new Campaign($id_campaign);
         $b->delete();
         unset($b);
     } elseif (Tools::getIsset('submitBulkenableSelectioncampaign') && Tools::getValue('campaignBox')) {
         $ids_banner_deleted = Tools::getValue('campaignBox');
         // remove each banner
         foreach ($ids_banner_deleted as $id) {
             $b = new Campaign($id);
             $b->toggleStatus();
             unset($b);
         }
     } elseif (Tools::getIsset('submitBulkdisableSelectioncampaign') && Tools::getValue('campaignBox')) {
         $ids_banner_deleted = Tools::getValue('campaignBox');
         // remove each banner
         foreach ($ids_banner_deleted as $id) {
             $b = new Campaign($id);
             $b->toggleStatus();
             unset($b);
         }
     }
 }