public function reOrderPositions() { $id_slide = $this->id; $context = Context::getContext(); $id_shop = $context->shop->id; $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(hss.`position`) as position FROM `' . _DB_PREFIX_ . 'friendslider_slides` hss, `' . _DB_PREFIX_ . 'friendslider` hs WHERE hss.`id_friendslider_slides` = hs.`id_friendslider_slides` AND hs.`id_shop` = ' . (int) $id_shop); if ((int) $max == (int) $id_slide) { return true; } $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hss.`position` as position, hss.`id_friendslider_slides` as id_slide FROM `' . _DB_PREFIX_ . 'friendslider_slides` hss LEFT JOIN `' . _DB_PREFIX_ . 'friendslider` hs ON (hss.`id_friendslider_slides` = hs.`id_friendslider_slides`) WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position); foreach ($rows as $row) { $current_slide = new FriendsSlide($row['id_slide']); --$current_slide->position; $current_slide->update(); unset($current_slide); } return true; }
</div>'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'legend', true); $this->_html .= '</div><br /><br />'; /* Description */ $this->_html .= ' <label>' . $this->l('Description:') . ' </label> <div class="margin-form">'; foreach ($languages as $language) { $this->_html .= '<div id="description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . ';float: left;"> <textarea name="description_' . $language['id_lang'] . '" rows="10" cols="29">' . (isset($slide->description[$language['id_lang']]) ? $slide->description[$language['id_lang']] : '') . '</textarea> </div>'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'description', true); $this->_html .= '</div><div class="clear"></div><br />'; /* Active */ $this->_html .= ' <label for="active_on">' . $this->l('Active:') . '</label> <div class="margin-form"> <img src="../img/admin/enabled.gif" alt="Yes" title="Yes" /> <input type="radio" name="active_slide" id="active_on" ' . ($slide && (isset($slide->active) && (int) $slide->active == 0) ? '' : 'checked="checked" ') . ' value="1" /> <label class="t" for="active_on">' . $this->l('Yes') . '</label> <img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" /> <input type="radio" name="active_slide" id="active_off" ' . ($slide && (isset($slide->active) && (int) $slide->active == 0) ? 'checked="checked" ' : '') . ' value="0" /> <label class="t" for="active_off">' . $this->l('No') . '</label> </div>'; /* Save */ $this->_html .= ' <p class="center"> <input style="min-height:26px" type="submit" class="button" name="submitSlide" value="' . $this->l('Save') . '" /> <a class="button" style="position:relative; padding:4px 3px;" href="' . AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '">' . $this->l('Cancel') . '</a> </p>'; /* End of fieldset & form */ $this->_html .= ' <p>*' . $this->l('Required fields') . '</p> </fieldset> </form>'; } private function _postValidation() { $errors = array(); /* Validation for Slider configuration */ if (Tools::isSubmit('submitSlider')) { if (!Validate::isInt(Tools::getValue('FRIENDSLIDER_SPEED')) || !Validate::isInt(Tools::getValue('FRIENDSLIDER_PAUSE')) || !Validate::isInt(Tools::getValue('FRIENDSLIDER_WIDTH')) || !Validate::isInt(Tools::getValue('FRIENDSLIDER_HEIGHT'))) { $errors[] = $this->l('Invalid values'); } } elseif (Tools::isSubmit('changeStatus')) { if (!Validate::isInt(Tools::getValue('id_slide'))) { $errors[] = $this->l('Invalid slide'); } } elseif (Tools::isSubmit('submitSlide')) { /* Checks state (active) */ if (!Validate::isInt(Tools::getValue('active_slide')) || Tools::getValue('active_slide') != 0 && Tools::getValue('active_slide') != 1) { $errors[] = $this->l('Invalid slide state'); } /* Checks position */ if (!Validate::isInt(Tools::getValue('position')) || Tools::getValue('position') < 0) { $errors[] = $this->l('Invalid slide position'); } /* If edit : checks id_slide */ if (Tools::isSubmit('id_slide')) { if (!Validate::isInt(Tools::getValue('id_slide')) && !$this->slideExists(Tools::getValue('id_slide'))) { $errors[] = $this->l('Invalid id_slide'); } } /* Checks title/url/legend/description/image */ $languages = Language::getLanguages(false); foreach ($languages as $language) { if (Tools::strlen(Tools::getValue('title_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The title is too long.'); } if (Tools::strlen(Tools::getValue('legend_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The legend is too long.'); } if (Tools::strlen(Tools::getValue('url_' . $language['id_lang'])) > 255) { $errors[] = $this->l('The URL is too long.'); } if (Tools::strlen(Tools::getValue('description_' . $language['id_lang'])) > 4000) { $errors[] = $this->l('The description is too long.'); } if (Tools::strlen(Tools::getValue('url_' . $language['id_lang'])) > 0 && !Validate::isUrl(Tools::getValue('url_' . $language['id_lang']))) { $errors[] = $this->l('The URL format is not correct.'); } if (Tools::getValue('image_' . $language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_' . $language['id_lang']))) { $errors[] = $this->l('Invalid filename'); } if (Tools::getValue('image_old_' . $language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_' . $language['id_lang']))) { $errors[] = $this->l('Invalid filename'); } } /* Checks title/url/legend/description for default lang */ $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); if (Tools::strlen(Tools::getValue('title_' . $id_lang_default)) == 0) { $errors[] = $this->l('The title is not set.'); } if (Tools::strlen(Tools::getValue('legend_' . $id_lang_default)) == 0) { $errors[] = $this->l('The legend is not set.'); } if (Tools::strlen(Tools::getValue('url_' . $id_lang_default)) == 0) { $errors[] = $this->l('The URL is not set.');