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_ . 'homesliderpro_slides` hss, `' . _DB_PREFIX_ . 'homesliderpro` hs WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_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_homeslider_slides` as id_slide FROM `' . _DB_PREFIX_ . 'homesliderpro_slides` hss LEFT JOIN `' . _DB_PREFIX_ . 'homesliderpro` hs ON (hss.`id_homeslider_slides` = hs.`id_homeslider_slides`) WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position); foreach ($rows as $row) { $current_slide = new HomeSlidePro($row['id_slide']); --$current_slide->position; $current_slide->update(); unset($current_slide); } return true; }
$data = Tools::getValue('settings'); $settings = unserialize(Configuration::get('SLIDERSEVERYWHERE_SETS')); $settings['permissions'] = $data['permissions']; $settings['img_ql'] = $data['img_ql']; Configuration::updateValue('SLIDERSEVERYWHERE_SETS', serialize($settings)); } if (Tools::getValue('action') == 'changeStatus') { $slide = new HomeSlidePro((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $response = array(); $response['success'] = 0; if ($res = $slide->update()) { $response['success'] = 1; } $response['message'] = $res ? $home_slider->l('Status changed!') : $home_slider->l('The status cannot be changed.'); echo json_encode($response); } if (Tools::getValue('action') == 'updateConfiguration') { $configs = Tools::getValue('conf'); $shop = Tools::getValue('shop'); if ($home_slider->saveConfiguration($configs, $shop)) { echo $home_slider->l('Configuration updated'); } else { echo $home_slider->l('Problem changing configuration'); } } if (Tools::getValue('action') == 'updateDB') {
public function ajaxResponse() { $this->_conf = array(); //remove confirmation messages from admin controller... conflict with parameter name.. if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides')) { $slides = Tools::getValue('slides'); foreach ($slides as $position => $id_slide) { $res = Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'homesliderpro_slides` SET `position` = ' . (int) $position . ' WHERE `id_homeslider_slides` = ' . (int) $id_slide); } echo $this->l('Positions Updated'); $this->module->clearCache(); } // ACTIVATE CMS HOOK if (Tools::getValue('action') == 'activateCMS') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (!isset($settings['CMS']) || $settings['CMS'] == 0) { $cms_tpl = _PS_THEME_DIR_ . 'cms.tpl'; $cms_bakup = _PS_THEME_DIR_ . 'cms.tpl.bak'; $theme_file = file_get_contents($cms_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CMS="1"}') !== false) { //hook found $settings['CMS'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CMS functionality already activated'); exit; } else { if (strpos($theme_file, '{$cms->content}') !== false) { //string found if (!is_writable(_PS_THEME_DIR_)) { echo $this->l('Cannot create the backup, your theme directory is not writable'); exit; } file_put_contents($cms_bakup, $theme_file); $theme_file = str_replace('{$cms->content}', '<!-- added by SlidersEverywhere module -->' . "\n" . '{hook h="DisplaySlidersPro" CMS="1"}' . "\n" . '<!-- END added by SlidersEverywhere module -->' . "\n" . '{$cms->content}', $theme_file); file_put_contents($cms_tpl, $theme_file); $settings['CMS'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CMS functionality activated!'); } else { echo $this->l('Cannot activate an error occurred!'); } } } else { echo $this->l('CMS functionality already activated'); exit; } $this->module->clearCache(); } // deactivate CMS hook; if (Tools::getValue('action') == 'deactivateCMS') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (isset($settings['CMS']) && $settings['CMS'] == 1) { $cms_tpl = _PS_THEME_DIR_ . 'cms.tpl'; $cms_bakup = _PS_THEME_DIR_ . 'cms.tpl.bak'; if (file_exists($cms_bakup)) { if (unlink($cms_tpl)) { if (rename($cms_bakup, $cms_tpl)) { $settings['CMS'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } else { echo $this->l('Error: cannot rename ') . ' ' . $cms_bakup; } } else { echo $this->l('Error: cannot delete ') . ' ' . $cms_tpl; } } else { //backup doesn' t exists check if the module is activated $theme_file = file_get_contents($cms_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CMS="1"}') !== false) { //it is activated but without backup echo $this->l('Error: backup file') . ' "' . $cms_bakup . '" ' . $this->l('not found! Please manually remove from cms.tpl') . ': {hook h="DisplaySlidersPro" CMS="1"}'; } else { // it wasn't activated update the database $settings['CMS'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } } } else { echo $this->l('Cannot deactivate unactive CMS functionality'); } } // ACTIVATE CATEGORY HOOK if (Tools::getValue('action') == 'activateCat') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (!isset($settings['CAT']) || $settings['CAT'] == 0) { $checkVersion = version_compare(_PS_VERSION_, '1.6'); if ($checkVersion >= 0) { //we are on ps 1.6 $searchString = '{if $category->id AND $category->active}'; } else { //we are on ps 1.5 $searchString = '{if $scenes || $category->description || $category->id_image}'; } $cat_tpl = _PS_THEME_DIR_ . 'category.tpl'; $cat_bakup = _PS_THEME_DIR_ . 'category.tpl.bak'; $theme_file = file_get_contents($cat_tpl); //check if hook is in theme file if (strpos($theme_file, '{hook h="DisplaySlidersPro" CAT="1"}') !== false) { $settings['CAT'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CATEGORY functionality already activated'); exit; } else { if (strpos($theme_file, $searchString) !== false) { if (!is_writable(_PS_THEME_DIR_)) { echo $this->l('Cannot create the backup, your theme directory is not writable'); exit; } file_put_contents($cat_bakup, $theme_file); $theme_file = str_replace($searchString, '<!-- added by SlidersEverywhere module -->' . "\n" . '{hook h="DisplaySlidersPro" CAT="1"}' . "\n" . '<!-- END added by SlidersEverywhere module -->' . "\n" . $searchString, $theme_file); file_put_contents($cat_tpl, $theme_file); $settings['CAT'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CATEGORY functionality activated!'); } else { echo $this->l('Cannot activate an error occurred!'); } } } else { echo $this->l('CATEGORY functionality already activated'); exit; } $this->module->clearCache(); } // deactivate category hook if (Tools::getValue('action') == 'deactivateCat') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (isset($settings['CAT']) && $settings['CAT'] == 1) { $cat_tpl = _PS_THEME_DIR_ . 'category.tpl'; $cat_bakup = _PS_THEME_DIR_ . 'category.tpl.bak'; if (file_exists($cat_bakup)) { if (unlink($cat_tpl)) { if (rename($cat_bakup, $cat_tpl)) { $settings['CAT'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } else { echo $this->l('Error: cannot rename') . ' ' . $cat_bakup; } } else { echo $this->l('Error: cannot delete') . ' ' . $cat_tpl; } } else { $theme_file = file_get_contents($cat_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CAT="1"}') !== false) { //it is activated but without backup echo $this->l('Error: backup file') . ' "' . $cat_bakup . '" ' . $this->l('not found! Please manually remove from category.tpl') . ': {hook h="DisplaySlidersPro" CAT="1"}'; } else { // it wasn't activated update the database $settings['CAT'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } echo $this->l('Error: backup file') . ' "' . $cat_bakup . '" ' . $this->l('not found!'); } } else { echo $this->l('Cannot deactivate unactive CATEGORY functionality'); } } // edit Permissions if (Tools::getValue('action') == 'editPermissions') { $data = Tools::getValue('settings'); $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['permissions'] = $data['permissions']; $settings['img_ql'] = $data['img_ql']; $settings['media_steps'] = $data['media_steps']; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('Settings Saved!'); } // change slide active status if (Tools::getValue('action') == 'changeStatus') { $slide = new HomeSlidePro((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $response = array(); $response['success'] = 0; if ($res = $slide->update()) { $response['success'] = 1; } $response['message'] = $res ? $this->l('Status changed!') : $this->l('The status cannot be changed.'); echo json_encode($response); } if (Tools::getValue('action') == 'updateConfiguration') { $configs = Tools::getValue('configs'); $shop = Tools::getValue('shop'); if ($this->module->saveSlideConfiguration($configs, $shop)) { echo $this->l('Configuration updated', $filename); } else { echo $this->l('Problem changing configuration'); } } if (Tools::getValue('action') == 'updateDB') { $sql = 'ALTER TABLE `' . _DB_PREFIX_ . 'category` ADD proslider varchar(255) NULL'; if (Db::getInstance()->execute($sql)) { echo $this->l('Database Updated!'); } else { echo $this->l('Error Occurred'); } } if (Tools::getValue('action') == 'updateModule') { if ($this->downloadUpdate($this->module)) { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['need_update'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('Module Updated!'); } else { echo $this->l('Error'); } } /** ajax image resize */ if (Tools::getValue('action') == 'resizeImages') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $quality = isset($settings['img_ql']) ? $settings['img_ql'] : 90; $hook = Tools::getValue('hookname'); $sql = 'SELECT lang.image , sl.id_homeslider_slides FROM `' . _DB_PREFIX_ . 'homesliderpro` sl LEFT JOIN `' . _DB_PREFIX_ . 'homesliderpro_slides_lang` lang ON (sl.id_homeslider_slides = lang.id_homeslider_slides) WHERE sl.id_hook = "' . $hook . '"'; if ($images = Db::getInstance()->executeS($sql)) { $ImageNames = array(); $c = 0; foreach ($images as $k => $image) { if (!in_array($image['image'], $ImageNames)) { $ImageNames[$c] = $image['image']; $c++; } } if (!empty($ImageNames)) { $confs = $this->module->getSlideConfiguration($hook, $shop); $configuration = $confs[$hook]; $folder = dirname(__FILE__) . '/images/'; $success = false; foreach ($ImageNames as $in) { $resizeObj = new PerfectResize($folder . $in); $resizeObj->resizeImage($configuration['width'], $configuration['height'], 'crop'); $resizeObj->saveImage($folder . '/resize_' . $in, $quality); $success = true; } if ($success) { echo $this->l('Images resized for slider') . ': ' . $hook; } else { echo $this->l('No image to resize for') . ': ' . $hook; } } } } // new version alert if (Tools::getValue('action') == 'alertNewVersion') { $v = Tools::getValue('params'); if (!empty($v)) { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['need_update'] = $v; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo 'New Version Available: ' . $v; } } // autocomplete helpre for product filters if (Tools::getValue('action') == 'autocomplete') { if (Tools::getValue('value') == 'products') { $s = Tools::getValue('s'); $q = 'SELECT DISTINCT `name`, `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `name` LIKE "%' . $s . '%" LIMIT 10'; if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($q)) { $response = array(); foreach ($result as $k => $r) { $response[$k]['label'] = $r['name']; $response[$k]['value'] = $r['id_product']; } echo json_encode($response); } } } }