Exemple #1
0
 public function getContent()
 {
     $output = '';
     $errors = array();
     $languages = Language::getLanguages();
     $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT');
     $id_lang = $this->context->language->id;
     if (Tools::getValue('confirm_msg')) {
         $output .= $this->displayConfirmation(Tools::getValue('confirm_msg'));
     }
     if (Tools::isSubmit('submitGlobal')) {
         $id_position = (int) Tools::getValue('id_position', 1);
         $html_id = $this->getHtmlIdByPosition($id_position);
         if ($html_id && count($html_id) > 0) {
             $htmlObject = new HtmlObject($html_id['id_htmlobject']);
         } else {
             $htmlObject = new HtmlObject();
         }
         $htmlObject->active = (int) Tools::getValue('active');
         //$hook_postition
         $htmlObject->hook_postition = (int) Tools::getValue('id_position');
         foreach ($languages as $language) {
             $htmlObject->title[$language['id_lang']] = Tools::getValue('item_title_' . $language['id_lang']);
             $htmlObject->content[$language['id_lang']] = Tools::getValue('item_html_' . $language['id_lang']);
         }
         if (!$errors || count($errors) < 1) {
             /* Update */
             if ($html_id && count($html_id) > 0) {
                 if (!$htmlObject->update()) {
                     $errors[] = $this->displayError($this->l('The Advertising slide could not be updated.'));
                 }
             } elseif (!$htmlObject->add()) {
                 $errors[] = $this->displayError($this->l('The Advertising slide could not be add.'));
             }
             /* Adds */
         }
         if (!isset($errors) || count($errors) < 1) {
             if ($html_id && count($html_id) > 0) {
                 $confirm_msg = $this->l('Slide successfully updated.');
             } else {
                 $confirm_msg = $this->l('New slide successfully added.');
             }
             Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('blockhtml.tpl'));
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg . '&id_position=' . $id_position);
         }
     }
     if (isset($errors) && count($errors)) {
         $output .= $this->displayError(implode('<br />', $errors));
     }
     return $output . $this->displayForm();
 }