public function ajaxCallBackOffice($category_box = array(), $id_layered_filter = null) { global $cookie; if (!empty($id_layered_filter)) { $layered_filter = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) $id_layered_filter); if ($layered_filter && isset($layered_filter['filters']) && !empty($layered_filter['filters'])) { $layered_values = Tools::unSerialize($layered_filter['filters']); } if (isset($layered_values['categories']) && count($layered_values['categories'])) { foreach ($layered_values['categories'] as $id_category) { $category_box[] = (int) $id_category; } } } /* Clean categoryBox before use */ if (isset($category_box) && is_array($category_box)) { foreach ($category_box as &$value) { $value = (int) $value; } } else { $category_box = array(); } $attribute_groups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n FROM ' . _DB_PREFIX_ . 'attribute_group ag LEFT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) LEFT JOIN ' . _DB_PREFIX_ . 'attribute a ON (a.id_attribute_group = ag.id_attribute_group) ' . (count($category_box) ? ' LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON (pac.id_attribute = a.id_attribute) LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON (pa.id_product_attribute = pac.id_product_attribute)' . Shop::addSqlAssociation('product_attribute', 'pa') . ' LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = pa.id_product)' : '') . ' WHERE agl.id_lang = ' . (int) $cookie->id_lang . (count($category_box) ? ' AND cp.id_category IN (' . implode(',', $category_box) . ')' : '') . ' GROUP BY ag.id_attribute_group'); $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM ' . _DB_PREFIX_ . 'feature_lang fl LEFT JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature = fl.id_feature) ' . (count($category_box) ? ' LEFT JOIN ' . _DB_PREFIX_ . 'feature_product fp ON (fp.id_feature = fv.id_feature) LEFT JOIN ' . _DB_PREFIX_ . 'category_product cp ON (cp.id_product = fp.id_product)' : '') . ' WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = ' . (int) $cookie->id_lang . (count($category_box) ? ' AND cp.id_category IN (' . implode(',', $category_box) . ')' : '') . ' GROUP BY fl.id_feature'); $n_elements = count($attribute_groups) + count($features) + 4; if ($n_elements > 20) { $n_elements = 20; } $html = ' <div id="layered_container_right" style="width: 360px; float: left; margin-left: 20px; height: ' . (int) (30 + $n_elements * 38) . 'px; overflow-y: auto;"> <h3>' . $this->l('Available filters') . ' <span id="num_avail_filters">(0)</span></h3> <ul id="all_filters"></ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_subcategories" name="layered_selection_subcategories" /> <span class="position"></span>' . $this->l('Sub-categories filter') . ' <select class="filter_show_limit" name="layered_selection_subcategories_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_subcategories_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_stock" name="layered_selection_stock" /> <span class="position"></span>' . $this->l('Product stock filter') . ' <select class="filter_show_limit" name="layered_selection_stock_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_stock_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_condition" name="layered_selection_condition" /> <span class="position"></span>' . $this->l('Product condition filter') . ' <select class="filter_show_limit" name="layered_selection_condition_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_condition_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_manufacturer" name="layered_selection_manufacturer" /> <span class="position"></span>' . $this->l('Product manufacturer filter') . ' <select class="filter_show_limit" name="layered_selection_manufacturer_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_manufacturer_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_weight_slider" name="layered_selection_weight_slider" /> <span class="position"></span>' . $this->l('Product weight filter (slider)') . ' <select class="filter_show_limit" name="layered_selection_weight_slider_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_weight_slider_filter_type"> <option value="0">' . $this->l('Slider') . '</option> <option value="1">' . $this->l('Inputs area') . '</option> <option value="2">' . $this->l('List of values') . '</option> </select> </li> </ul> <ul> <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_price_slider" name="layered_selection_price_slider" /> <span class="position"></span>' . $this->l('Product price filter (slider)') . ' <select class="filter_show_limit" name="layered_selection_price_slider_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_price_slider_filter_type"> <option value="0">' . $this->l('Slider') . '</option> <option value="1">' . $this->l('Inputs area') . '</option> <option value="2">' . $this->l('List of values') . '</option> </select> </li> </ul>'; if (count($attribute_groups)) { $html .= '<ul>'; foreach ($attribute_groups as $attribute_group) { $html .= ' <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '" /> <span class="position"></span> ' . ($attribute_group['n'] > 1 ? sprintf($this->l('Attribute group: %1$s (%2$d attributes)'), $attribute_group['name'], $attribute_group['n']) : sprintf($this->l('Attribute group: %1$s (%2$d attribute)'), $attribute_group['name'], $attribute_group['n'])) . ')' . ($attribute_group['is_color_group'] ? ' <img src="../img/admin/color_swatch.png" alt="" title="' . $this->l('This group will allow user to select a color') . '" />' : '') . ' <select class="filter_show_limit" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_ag_' . (int) $attribute_group['id_attribute_group'] . '_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li>'; } $html .= '</ul>'; } if (count($features)) { $html .= '<ul>'; foreach ($features as $feature) { $html .= ' <li class="ui-state-default layered_right"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <input type="checkbox" id="layered_selection_feat_' . (int) $feature['id_feature'] . '" name="layered_selection_feat_' . (int) $feature['id_feature'] . '" /> <span class="position"></span> ' . ($feature['n'] > 1 ? sprintf($this->l('Feature: %1$s (%2$d values)'), $feature['name'], $feature['n']) : sprintf($this->l('Feature: %1$s (%2$d value)'), $feature['name'], $feature['n'])) . ') <select class="filter_show_limit" name="layered_selection_feat_' . (int) $feature['id_feature'] . '_filter_show_limit"> <option value="0">' . $this->l('No limit') . '</option> <option value="4">4</option> <option value="5">5</option> <option value="10">10</option> <option value="20">20</option> </select> <select class="filter_type" name="layered_selection_feat_' . (int) $feature['id_feature'] . '_filter_type"> <option value="0">' . $this->l('Checkbox') . '</option> <option value="1">' . $this->l('Radio button') . '</option> <option value="2">' . $this->l('Drop-down list') . '</option> </select> </li>'; } $html .= '</ul>'; } $html .= ' </div>'; if (isset($layered_values)) { $html .= ' <script type="text/javascript"> $(document).ready(function() { $(\'#selected_filters li\').remove(); '; foreach ($layered_values as $key => $layered_value) { if ($key != 'categories' && $key != 'shop_list') { $html .= ' $(\'#' . $key . '\').click(); $(\'select[name=' . $key . '_filter_type]\').val(' . $layered_value['filter_type'] . '); $(\'select[name=' . $key . '_filter_show_limit]\').val(' . $layered_value['filter_show_limit'] . '); '; } } if (isset($layered_values['categories']) && count($layered_values['categories'])) { $html .= ' function expandCategories(categories, iteration, id_category, init) { if (categories[iteration]) { category = $(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+categories[iteration]+\']\'); if (category.length) { if (category.parent().hasClass(\'expandable\')) { $(\'#\'+categories[iteration]+\' .hitarea\').click(); } if (parseInt(categories[iteration]) == parseInt(id_category)) { $(\'#layered-cat-counter\').html(parseInt($(\'#layered-cat-counter\').html()) + 1); if ($(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']:checked\').length == 0) { $(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']\').click(); clickOnCategoryBox($(\'#categories-treeview\').find(\'input[name="categoryBox[]"][value=\'+id_category+\']\')); } collapseAllCategories(); } } else { setTimeout(function() { expandCategories(categories, iteration, id_category, false); }, 20 ); return; } $(\'#categories-treeview\').parent().parent().show(); expandCategories(categories, iteration+1, id_category); if (typeof(lock_treeview_hidding) == \'undefined\' || !lock_treeview_hidding) $(\'#categories-treeview\').parent().parent().hide(); } } $(\'#layered-cat-counter\').html(0); $(\'.nb_sub_cat_selected\').hide(); $(\'#categories-treeview\').find(\'input[name="categoryBox[]"]:checked\').each(function(i, it) { $(it).click(); updateNbSubCategorySelected($(it), false); });'; foreach ($layered_values['categories'] as $id_category) { if ($id_category != 1) { $category = new Category($id_category); $parent_list = array_reverse($category->getParentsCategories()); } else { $parent_list = array(array('id_category' => 1)); } $html .= 'var categories = []; '; foreach ($parent_list as $parent) { $html .= ' categories.push(' . (int) $parent['id_category'] . ');'; } $html .= ' expandCategories(categories, 0, ' . (int) $id_category . ', false);'; } $html .= ' updCatCounter(); $(\'#scope_1\').attr(\'checked\', \'\'); $(\'#scope_2\').attr(\'checked\', \'checked\'); '; } else { $html .= ' $(\'#scope_2\').attr(\'checked\', \'\'); $(\'#scope_1\').attr(\'checked\', \'checked\'); '; } $html .= ' $(\'#layered_tpl_name\').val(\'' . addslashes($layered_filter['name']) . '\'); $(\'#id_layered_filter\').val(\'' . (int) $layered_filter['id_layered_filter'] . '\'); '; $html .= ' }); </script>'; } if (!empty($id_layered_filter)) { if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) { $shops = Shop::getShops(true, null, true); if (count($shops) > 1) { $helper = new HelperForm(); $helper->id = (int) $id_layered_filter; $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; $helper->base_folder = Tools::getValue('base_folder') . '/themes/default/template/helpers/form/'; $html .= ' <div id="shop_association_ajax">' . $helper->renderAssoShop() . '</div> <script type="text/javascript"> $(document).ready(function() { $(\'#shop_association\').html($(\'#shop_association_ajax\').html()); $(\'#shop_association_ajax\').remove(); // Initialize checkbox $(\'.input_shop\').each(function(k, v) { check_shop_group_status($(v).val()); check_all_shop(); }); }); </script>'; } } } return $html; }
public function getContent() { global $cookie; $message = ''; if (Tools::isSubmit('SubmitFilter')) { if (!Tools::getValue('layered_tpl_name')) { $message = $this->displayError($this->l('Filter template name required (cannot be empty)')); } elseif (!Tools::getValue('categoryBox')) { $message = $this->displayError($this->l('You must select at least one category.')); } else { if (Tools::getValue('id_layered_filter')) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); $this->buildLayeredCategories(); } if (Tools::getValue('scope') == 1) { Db::getInstance()->execute('TRUNCATE TABLE ' . _DB_PREFIX_ . 'layered_filter'); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT id_category FROM ' . _DB_PREFIX_ . 'category'); foreach ($categories as $category) { $_POST['categoryBox'][] = (int) $category['id_category']; } } $id_layered_filter = (int) Tools::getValue('id_layered_filter'); if (!$id_layered_filter) { $id_layered_filter = (int) Db::getInstance()->Insert_ID(); } $shop_list = array(); if (isset($_POST['checkBoxShopAsso_layered_filter'])) { foreach ($_POST['checkBoxShopAsso_layered_filter'] as $id_shop => $row) { $assos[] = array('id_object' => (int) $id_layered_filter, 'id_shop' => (int) $id_shop); $shop_list[] = (int) $id_shop; } } else { $shop_list = array(Context::getContext()->shop->id); } Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter_shop WHERE `id_layered_filter` = ' . (int) $id_layered_filter); if (count($_POST['categoryBox'])) { /* Clean categoryBox before use */ if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox'])) { foreach ($_POST['categoryBox'] as &$category_box_tmp) { $category_box_tmp = (int) $category_box_tmp; } } $filter_values = array(); foreach ($_POST['categoryBox'] as $idc) { $filter_values['categories'][] = (int) $idc; } $filter_values['shop_list'] = $shop_list; $values = false; foreach ($_POST['categoryBox'] as $id_category_layered) { foreach ($_POST as $key => $value) { if (substr($key, 0, 17) == 'layered_selection' && $value == 'on') { $values = true; $type = 0; $limit = 0; if (Tools::getValue($key . '_filter_type')) { $type = Tools::getValue($key . '_filter_type'); } if (Tools::getValue($key . '_filter_show_limit')) { $limit = Tools::getValue($key . '_filter_show_limit'); } $filter_values[$key] = array('filter_type' => (int) $type, 'filter_show_limit' => (int) $limit); } } } $values_to_insert = array('name' => pSQL(Tools::getValue('layered_tpl_name')), 'filters' => pSQL(serialize($filter_values)), 'n_categories' => (int) count($filter_values['categories']), 'date_add' => date('Y-m-d H:i:s')); if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) { $values_to_insert['id_layered_filter'] = (int) Tools::getValue('id_layered_filter'); } Db::getInstance()->autoExecute(_DB_PREFIX_ . 'layered_filter', $values_to_insert, 'INSERT'); $id_layered_filter = (int) Db::getInstance()->Insert_ID(); if (isset($assos)) { foreach ($assos as $asso) { Db::getInstance()->execute(' INSERT INTO ' . _DB_PREFIX_ . 'layered_filter_shop (`id_layered_filter`, `id_shop`) VALUES(' . $id_layered_filter . ', ' . (int) $asso['id_shop'] . ')'); } } $this->buildLayeredCategories(); $message = $this->displayConfirmation($this->l('Your filter') . ' "' . Tools::safeOutput(Tools::getValue('layered_tpl_name')) . '" ' . (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter'] ? $this->l('was updated successfully.') : $this->l('was added successfully.'))); } } } else { if (Tools::isSubmit('submitLayeredSettings')) { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', (int) Tools::getValue('ps_layered_hide_0_values')); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', (int) Tools::getValue('ps_layered_show_qties')); Configuration::updateValue('PS_LAYERED_FULL_TREE', (int) Tools::getValue('ps_layered_full_tree')); Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', (int) Tools::getValue('ps_layered_filter_price_usetax')); Configuration::updateValue('PS_LAYERED_FILTER_CATEGORY_DEPTH', (int) Tools::getValue('ps_layered_filter_category_depth')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int) Tools::getValue('ps_layered_filter_index_availability')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int) Tools::getValue('ps_layered_filter_index_condition')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_MNF', (int) Tools::getValue('ps_layered_filter_index_manufacturer')); Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CAT', (int) Tools::getValue('ps_layered_filter_index_category')); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $message = '<div class="alert alert-success">' . $this->l('Settings saved successfully') . '</div>'; } else { $message = '<div class="conf">' . $this->l('Settings saved successfully') . '</div>'; } } else { if (Tools::getValue('deleteFilterTemplate')) { $layered_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT filters FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); if ($layered_values) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'layered_filter WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter') . ' LIMIT 1'); $this->buildLayeredCategories(); $message = $this->displayConfirmation($this->l('Filter template deleted, categories updated (reverted to default Filter template).')); } else { $message = $this->displayError($this->l('Filter template not found')); } } } } $category_box = array(); $attribute_groups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n FROM ' . _DB_PREFIX_ . 'attribute_group ag LEFT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) LEFT JOIN ' . _DB_PREFIX_ . 'attribute a ON (a.id_attribute_group = ag.id_attribute_group) WHERE agl.id_lang = ' . (int) $cookie->id_lang . ' GROUP BY ag.id_attribute_group'); $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM ' . _DB_PREFIX_ . 'feature_lang fl LEFT JOIN ' . _DB_PREFIX_ . 'feature_value fv ON (fv.id_feature = fl.id_feature) WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = ' . (int) $cookie->id_lang . ' GROUP BY fl.id_feature'); if (Shop::isFeatureActive() && count(Shop::getShops(true, null, true)) > 1) { $helper = new HelperForm(); $helper->id = Tools::getValue('id_layered_filter', null); $helper->table = 'layered_filter'; $helper->identifier = 'id_layered_filter'; $this->context->smarty->assign('asso_shops', $helper->renderAssoShop()); } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $tree_categories_helper = new HelperTreeCategories('categories-treeview'); $tree_categories_helper->setRootCategory(Shop::getContext() == Shop::CONTEXT_SHOP ? Category::getRootCategory()->id_category : 0)->setUseCheckBox(true); } else { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $root_category = Category::getRootCategory(); $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name); } else { $root_category = array('id_category' => '0', 'name' => $this->l('Root')); } $tree_categories_helper = new Helper(); } $module_url = Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST'] . $this->getPathUri(); if (method_exists($this->context->controller, 'addJquery')) { $this->context->controller->addJS($this->_path . 'js/blocklayered_admin.js'); if (version_compare(_PS_VERSION_, '1.6.0.3', '>=') === true) { $this->context->controller->addjqueryPlugin('sortable'); } elseif (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->controller->addJS(_PS_JS_DIR_ . 'jquery/plugins/jquery.sortable.js'); } else { $this->context->controller->addJS($this->_path . 'js/jquery.sortable.js'); } } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->controller->addCSS($this->_path . 'css/blocklayered_admin_1.6.css'); } else { $this->context->controller->addCSS($this->_path . 'css/blocklayered_admin.css'); } if (Tools::getValue('add_new_filters_template')) { $this->context->smarty->assign(array('current_url' => $this->context->link->getAdminLink('AdminModules') . '&configure=blocklayered&tab_module=front_office_features&module_name=blocklayered', 'uri' => $this->getPathUri(), 'id_layered_filter' => 0, 'template_name' => sprintf($this->l('My template - %s'), date('Y-m-d')), 'attribute_groups' => $attribute_groups, 'features' => $features, 'total_filters' => 6 + count($attribute_groups) + count($features))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->context->smarty->assign('categories_tree', $tree_categories_helper->render()); } else { $this->context->smarty->assign('categories_tree', $tree_categories_helper->renderCategoryTree($root_category, array(), 'categoryBox')); } if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/add_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/add.tpl'); } } else { if (Tools::getValue('edit_filters_template')) { $template = Db::getInstance()->getRow(' SELECT * FROM `' . _DB_PREFIX_ . 'layered_filter` WHERE id_layered_filter = ' . (int) Tools::getValue('id_layered_filter')); $filters = unserialize($template['filters']); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $tree_categories_helper->setSelectedCategories($filters['categories']); $this->context->smarty->assign('categories_tree', $tree_categories_helper->render()); } else { $this->context->smarty->assign('categories_tree', $tree_categories_helper->renderCategoryTree($root_category, $filters['categories'], 'categoryBox')); } $select_shops = $filters['shop_list']; unset($filters['categories']); unset($filters['shop_list']); $this->context->smarty->assign(array('current_url' => $this->context->link->getAdminLink('AdminModules') . '&configure=blocklayered&tab_module=front_office_features&module_name=blocklayered', 'uri' => $this->getPathUri(), 'id_layered_filter' => (int) Tools::getValue('id_layered_filter'), 'template_name' => $template['name'], 'attribute_groups' => $attribute_groups, 'features' => $features, 'filters' => Tools::jsonEncode($filters), 'total_filters' => 6 + count($attribute_groups) + count($features))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/add_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/add.tpl'); } } else { $this->context->smarty->assign(array('message' => $message, 'uri' => $this->getPathUri(), 'PS_LAYERED_INDEXED' => Configuration::getGlobalValue('PS_LAYERED_INDEXED'), 'current_url' => Tools::safeOutput(preg_replace('/&deleteFilterTemplate=[0-9]*&id_layered_filter=[0-9]*/', '', $_SERVER['REQUEST_URI'])), 'id_lang' => Context::getContext()->cookie->id_lang, 'token' => substr(Tools::encrypt('blocklayered/index'), 0, 10), 'base_folder' => urlencode(_PS_ADMIN_DIR_), 'price_indexer_url' => $module_url . 'blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10), 'full_price_indexer_url' => $module_url . 'blocklayered-price-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&full=1', 'attribute_indexer_url' => $module_url . 'blocklayered-attribute-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10), 'url_indexer_url' => $module_url . 'blocklayered-url-indexer.php' . '?token=' . substr(Tools::encrypt('blocklayered/index'), 0, 10) . '&truncate=1', 'filters_templates' => Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'layered_filter ORDER BY date_add DESC'), 'hide_values' => Configuration::get('PS_LAYERED_HIDE_0_VALUES'), 'show_quantities' => Configuration::get('PS_LAYERED_SHOW_QTIES'), 'full_tree' => Configuration::get('PS_LAYERED_FULL_TREE'), 'category_depth' => Configuration::get('PS_LAYERED_FILTER_CATEGORY_DEPTH'), 'price_use_tax' => Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX'), 'index_cdt' => Configuration::get('PS_LAYERED_FILTER_INDEX_CDT'), 'index_qty' => Configuration::get('PS_LAYERED_FILTER_INDEX_QTY'), 'index_mnf' => Configuration::get('PS_LAYERED_FILTER_INDEX_MNF'), 'index_cat' => Configuration::get('PS_LAYERED_FILTER_INDEX_CAT'), 'limit_warning' => $this->displayLimitPostWarning(21 + count($attribute_groups) * 3 + count($features) * 3))); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { return $this->display(__FILE__, 'views/templates/admin/view_1.6.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/view.tpl'); } } } }
private function displayForm3() { $res = true; $theme_directory = Tools::getValue('theme_directory'); $xml = simplexml_load_file(_IMPORT_FOLDER_ . XMLFILENAME); $this->xml = $xml; if ($this->selected_variations && count($this->selected_variations) > 0) { $ok = array(); foreach ($this->selected_variations as $variation) { if ($variation == $this->default_theme) { continue; } if ($variation != $theme_directory) { $theme_directory = $variation; } if (empty($theme_directory)) { $theme_directory = str_replace(' ', '', (string) $this->xml['name']); } if (_PS_VERSION_ < '1.5') { self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, _PS_ALL_THEMES_DIR_ . $variation); if (file_exists(_PS_ALL_THEMES_DIR_ . $variation)) { $ok[] = $variation; } } else { $target_dir = _PS_ALL_THEMES_DIR_ . $theme_directory; $res &= self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, $target_dir); $new_theme = new Theme(); $new_theme->name = (string) $this->xml['name']; $new_theme->directory = $theme_directory; $name_exist = true; // Check name theme $themes = $new_theme->getThemes(); foreach ($themes as $row) { if ($row->name == $new_theme->name) { $name_exist &= false; } } if ($name_exist) { $res &= $new_theme->add(); } if ($res) { $ok[] = $variation; } } } if (count($ok) > 0) { $msg = $this->l('The following themes were successfully imported:') . '<ul><i>'; foreach ($ok as $row) { $msg .= '<li> ' . $row . '</li>'; } $msg .= '</i></ul>'; $this->_msg = parent::displayConfirmation($msg); } } self::getModules(); if (file_exists(_IMPORT_FOLDER_ . 'doc') && count($xml->docs->doc) != 0) { self::loadDocForm(); } $this->_html .= '<fieldset>'; if ($this->to_install && count($this->to_install) > 0) { $var = ''; foreach ($this->to_install as $row) { if (file_exists(_IMPORT_FOLDER_ . 'modules/' . $row)) { $module_already_exists = file_exists(_PS_MODULE_DIR_ . $row); $var .= '<input type="checkbox" name="modulesToExport[]" id="' . $row . '" value="' . $row . '" checked="checked" /> <label style="display:bock;float:none" for="' . $row . '">' . $row . ($module_already_exists ? ' <span style="font-size:0.8em;color:red;">' . $this->l('Warning: a module with the same name already exists.') . '</span>' : '') . '</label><br />'; } } if ($var != '') { $this->_html .= ' <fieldset> <legend>' . $this->l('Select the theme\'s modules you wish to install') . '</legend> <p class="margin-form">' . $var . '</p> </fieldset> <p> </p>'; } } $var = ''; if (is_array($this->to_enable) && !empty($this->to_enable)) { $list_to_disabled = array_diff($this->native_modules, $this->to_enable); } else { $list_to_disabled = $this->native_modules; } foreach ($list_to_disabled as $row) { $obj = Module::getInstanceByName($row); if (Validate::isLoadedObject($obj)) { if (!file_exists(_IMPORT_FOLDER_ . 'modules/' . $row) && $obj->tab == 'front_office_features') { $var .= '<input type="checkbox" name="modulesToDisable[]" id="' . $row . '" value="' . $row . '" checked="checked" /> <label style="display:bock;float:none" for="' . $row . '">' . $row . '</label><br />'; } } } if (!empty($var)) { $this->_html .= ' <fieldset> <legend>' . $this->l('Select the modules which must be disabled for this theme') . '</legend> <p class="margin-form">' . $var . '</p> </fieldset> <p> </p>'; } $this->_html .= ' <fieldset> <legend>' . $this->l('Native modules configuration') . '</legend> <p>' . $this->l('This option determines which existing native modules have to be enabled/disabled.') . '</p> <ul class="margin-form" style="list-style:none"> <li> <input type="radio" name="nativeModules" value="1" id="nativemoduleconfig1"/> <label style="display:bock;float:none" for="nativemoduleconfig1">' . $this->l('Keep my current configuration') . '</label> </li> <li> <input type="radio" name="nativeModules" value="2" id="nativemoduleconfig2" checked="checked" /> <label style="display:bock;float:none" for="nativemoduleconfig2">' . $this->l('Use the theme\'s configuration (recommended)') . '</label> </li> <li> <input type="radio" name="nativeModules" value="3" id="nativemoduleconfig3" /> <label style="display:bock;float:none" for="nativemoduleconfig3">' . $this->l('Use both my configuration and the theme\'s configuration') . '</label> </li> </ul> </fieldset> <p> </p>'; if ($this->context->shop->isFeatureActive()) { $helper_form = new HelperForm(); $this->_html .= ' <fieldset> <legend>' . $this->l('Select the shop that will use this theme:') . '</legend> <div class="margin-form">' . $helper_form->renderAssoShop() . '</div> </fieldset> <p> </p>'; } $this->_html .= ' <p class="clear"> </p> <input type="submit" class="button" name="prevThemes" value="' . $this->l('Previous') . '" /> <input type="submit" class="button" name="submitModules" value="' . $this->l('Next') . '" /> </fieldset> </form>'; }
private function _displayForm() { /* Language */ $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $div_lang_name = 'text¤title'; $links = ''; /* Title */ $title_url = Configuration::get('PS_TMBLOCKLINK1_URL'); if (!Tools::isSubmit('submitLinkAdd')) { if ($id_link = (int) Tools::getValue('id_link')) { $res = Db::getInstance()->executeS(' SELECT * FROM ' . _DB_PREFIX_ . 'tmblocklink1 b LEFT JOIN ' . _DB_PREFIX_ . 'tmblocklink1_lang bl ON (b.id_tmblocklink1 = bl.id_tmblocklink1) WHERE b.id_tmblocklink1=' . (int) $id_link); if ($res) { foreach ($res as $row) { $links['text'][(int) $row['id_lang']] = $row['text']; $links['url'] = $row['url']; $links['new_window'] = $row['new_window']; } } } } $this->_html .= ' <script type="text/javascript"> id_language = Number(' . (int) $id_lang_default . '); </script> <fieldset> <legend><img src="' . $this->_path . 'add.png" alt="" title="" /> ' . $this->l('Add a new link') . '</legend> <form method="post" action="index.php?controller=adminmodules&configure=' . Tools::safeOutput(Tools::getValue('configure')) . '&token=' . Tools::safeOutput(Tools::getValue('token')) . '&tab_module=' . Tools::safeOutput(Tools::getValue('tab_module')) . '&module_name=' . Tools::safeOutput(Tools::getValue('module_name')) . '"> <input type="hidden" name="id_link" value="' . (int) Tools::getValue('id_link') . '" /> <label>' . $this->l('Text:') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->_html .= ' <div id="text_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input type="text" name="text_' . $language['id_lang'] . '" id="textInput_' . $language['id_lang'] . '" value="' . (isset($links) && isset($links['text'][$language['id_lang']]) ? $links['text'][$language['id_lang']] : '') . '" /><sup> *</sup> </div>'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $div_lang_name, 'text', true); $this->_html .= ' <div class="clear"></div> </div> <label>' . $this->l('URL:') . '</label> <div class="margin-form"><input type="text" name="url" id="url" value="' . (isset($links) && isset($links['url']) ? Tools::safeOutput($links['url']) : '') . '" /><sup> *</sup></div> <label>' . $this->l('Open in a new window:') . '</label> <div class="margin-form"><input type="checkbox" name="newWindow" id="newWindow" ' . (isset($links) && $links['new_window'] ? 'checked="checked"' : '') . ' /></div>'; $shops = Shop::getShops(true, null, true); if (Shop::isFeatureActive() && count($shops) > 1) { $helper = new HelperForm(); $helper->id = (int) Tools::getValue('id_link'); $helper->table = 'tmblocklink1'; $helper->identifier = 'id_tmblocklink1'; $this->_html .= '<label for="shop_association">' . $this->l('Shop association:') . '</label><div id="shop_association" class="margin-form">' . $helper->renderAssoShop() . '</div>'; } $this->_html .= ' <div class="margin-form"> <input type="submit" class="button" name="submitLinkAdd" value="' . $this->l('Add this link') . '" /> </div> </form> </fieldset> <fieldset class="space"> <legend><img src="' . $this->_path . 'logo.gif" alt="" title="" /> ' . $this->l('Block title') . '</legend> <form method="post" action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '"> <label>' . $this->l('Block title:') . '</label> <div class="margin-form">'; foreach ($languages as $language) { $this->_html .= ' <div id="title_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang_default ? 'block' : 'none') . '; float: left;"> <input type="text" name="title_' . $language['id_lang'] . '" value="' . Tools::safeOutput($this->error && Tools::getIsset('title') ? Tools::getIsset('title') : Configuration::get('PS_TMBLOCKLINK1_TITLE', $language['id_lang'])) . '" /><sup> *</sup> </div>'; } $this->_html .= $this->displayFlags($languages, $id_lang_default, $div_lang_name, 'title', true); $this->_html .= ' <div class="clear"></div> </div> <label>' . $this->l('Block URL:') . '</label> <div class="margin-form"><input type="text" name="title_url" value="' . Tools::safeOutput($this->error && Tools::getIsset('title_url') ? Tools::getValue('title_url') : $title_url) . '" /></div> <div class="margin-form"><input type="submit" class="button" name="submitTitle" value="' . $this->l('Update') . '" /></div> </form> </fieldset>'; }
private function displayForm3() { $res = true; $theme_directory = Tools::getValue('theme_directory'); $xml = simplexml_load_file(_IMPORT_FOLDER_ . XMLFILENAME); $this->xml = $xml; if ($this->selected_variations && count($this->selected_variations) > 0) { $ok = array(); foreach ($this->selected_variations as $variation) { if ($variation == $this->default_theme) { continue; } if ($variation != $theme_directory) { $theme_directory .= $variation; } if (empty($theme_directory)) { $theme_directory = str_replace(' ', '', (string) $this->xml['name']); } $target_dir = _PS_ALL_THEMES_DIR_ . $theme_directory; $res &= self::recurseCopy(_IMPORT_FOLDER_ . 'themes/' . $variation, $target_dir); $new_theme = new Theme(); $new_theme->name = (string) $this->xml['name']; $new_theme->directory = $theme_directory; $name_exist = true; // Check name theme $themes = $new_theme->getThemes(); foreach ($themes as $row) { if ($row->name == $new_theme->name) { $name_exist &= false; } } if ($name_exist) { $res &= $new_theme->add(); } if ($res) { $ok[] = $variation; } } if (count($ok) > 0) { $msg = $this->l('The following themes were successfully imported') . ':<ul><i>'; foreach ($ok as $row) { $msg .= '<li> ' . $row; } $msg .= '</i></ul>'; $this->_msg = parent::displayConfirmation($msg); } } self::getModules(); if (file_exists(_IMPORT_FOLDER_ . 'doc') && count($xml->docs->doc) != 0) { self::loadDocForm(); } $this->_html .= '<fieldset>'; if ($this->to_install && count($this->to_install) > 0) { $var = ''; foreach ($this->to_install as $row) { if (file_exists(_IMPORT_FOLDER_ . 'modules/' . $row)) { $module_already_exists = file_exists(_PS_MODULE_DIR_ . $row); $var .= '<input type="checkbox" name="modulesToExport[]" id="' . $row . '" value="' . $row . '" checked="checked" /> <label style="display:bock;float:none" for="' . $row . '">' . $row . ($module_already_exists ? ' <span style="font-size:0.8em">-> ' . $this->l('Warning: a module with the same name already exists') . '</span>' : '') . '</label><br />'; } } if ($var != '') { $this->_html .= ' <fieldset> <legend>' . $this->l('Select the theme\'s modules you wish to install') . '</legend> <p class="margin-form">' . $var . '</p> </fieldset> <p> </p>'; } } $var = ''; foreach (array_diff($this->native_modules, $this->to_disable) as $row) { $obj = Module::getInstanceByName($row); if (Validate::isLoadedObject($obj)) { if (!file_exists(_IMPORT_FOLDER_ . 'modules/' . $row) && $obj->tab == 'front_office_features') { $var .= '<input type="checkbox" name="modulesToDisable[]" id="' . $row . '" value="' . $row . '" /> <label style="display:bock;float:none" for="' . $row . '">' . $row . '</label><br />'; } } } $this->_html .= ' <fieldset> <legend>' . $this->l('Select modules which must be disabled for this theme') . '</legend> <p class="margin-form">' . $var . '</p> </fieldset> <p> </p>'; $this->_html .= ' <fieldset> <legend>' . $this->l('Native modules configuration') . '</legend> <ul class="margin-form" style="list-style:none"> <li> <input type="radio" name="nativeModules" value="1" id="nativemoduleconfig1"/> <label style="display:bock;float:none" for="nativemoduleconfig1">' . $this->l('Current configuration') . '</label> </li> <li> <input type="radio" name="nativeModules" value="2" id="nativemoduleconfig2" checked="checked" /> <label style="display:bock;float:none" for="nativemoduleconfig2">' . $this->l('Theme\'s configuration') . '</label> </li> <li> <input type="radio" name="nativeModules" value="3" id="nativemoduleconfig3" /> <label style="display:bock;float:none" for="nativemoduleconfig3">' . $this->l('Both') . '</label> </li> </ul> </fieldset> <p> </p>'; if (Shop::isFeatureActive()) { $helper_form = new HelperForm(); $this->_html .= ' <fieldset> <legend>' . $this->l('Select your shop that will use this theme:') . '</legend> <div class="margin-form">' . $helper_form->renderAssoShop() . '</div> </fieldset> <p> </p>'; } $this->_html .= ' <p class="clear"> </p> <input type="submit" class="button" name="prevThemes" value="' . $this->l('Previous') . '" /> <input type="submit" class="button" name="submitModules" value="' . $this->l('Next') . '" /> </fieldset> </form> <script type="text/javascript"> $(document).ready(function() { $.ajax({ type : "POST", url : "' . str_replace('index', 'ajax-tab', AdminController::$currentIndex) . '", data : { "theme_list" : ' . Tools::jsonEncode(array((string) $this->xml->theme_key)) . ', "controller" : "AdminModules", "action" : "wsThemeCall", "token" : "' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id) . '" }, dataType: "json", success: function(json) { //console.log(json); }, error: function(xhr, ajaxOptions, thrownError) { //jAlert("TECHNICAL ERROR"+res); } }); }); </script>'; }
public function renderForm() { $form_output = ''; $defaultLanguage = $this->default_form_language; if (!$this->loadObject(true)) { return; } $obj = $this->object; $lang_value = $this->default_form_language; $activeLanguages = Language::getLanguages(true); $form_output .= '<form class="defaultForm adminposts" id="' . $this->table . '_form" action="' . self::$currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" enctype="multipart/form-data"> ' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : ''); $form_output .= '</fieldset><div class="clear space"> </div> <fieldset> <legend><img src="../img/admin/translation.gif"> ' . $this->l('Content') . '</legend>'; if (count($activeLanguages) > 1) { $lang_options = array(); foreach ($activeLanguages as $l) { $lang_options[] = array('value' => $l['id_lang'], 'title' => $l['name']); } $lang_options[] = array('value' => 0, 'title' => $this->l('All languages')); $form_output .= HelperFieldForm::displaySelectField('id_lang', $lang_options, $obj->id_lang, $this->l('Language :')); } else { $form_output .= '<input type="hidden" name="id_lang" value="0" />'; } $form_output .= HelperFieldForm::displayTextField('title', $this->getFieldValue($obj, 'title'), 'text', $this->l('Title :'), NULL, array('required' => true, 'class' => 'copy2friendlyBlogUrl', 'id' => 'title_' . $lang_value)); $form_output .= HelperFieldForm::displayTextField('excerpt', $this->getFieldValue($obj, 'excerpt'), 'textarea', $this->l('Excerpt :'), $this->l('Article summary for lists'), array('rows' => 3)); $form_output .= HelperFieldForm::displayTextField('content', $this->getFieldValue($obj, 'content'), 'textarea', $this->l('Content :'), NULL, array('tinymce' => true)); $form_output .= '</fieldset><div class="clear space"> </div>'; // MEDIAS $form_output .= '<fieldset> <legend><img src="../img/admin/picture.gif"> ' . $this->l('Medias') . '</legend> <label>' . $this->l('Images/Videos :') . ' </label> <div class="margin-form"> <input type="file" accept="gif|jpg|png|mp4|flv|wmv" maxlength="' . $this->conf['nb_max_img'] . '" id="blog_img" name="blog_img[]" /> .jpg, .png, .gif, .mp4, .flv, .wmv </div> <div class="margin-form" id="blog-img-list"></div> <div class="margin-form">'; $relative = rtrim($this->conf['img_save_path'], '/') . "/"; $images = Tools::getValue('id_blog_post') ? $obj->getImages() : array(); if (count($images)) { $form_output .= '<table class="table" cellpadding="0" cellspacing="0" style="min-width:700px;"> <tr> <th>' . $this->l('Image/Video') . '</th> <th>' . $this->l('Default') . '</th> <th>' . $this->l('Position') . '</th> <th>' . $this->l('Delete') . '</th> </tr>'; $irow = 0; foreach ($images as $val) { $filename = $val['img_name']; if (file_exists(_PS_ROOT_DIR_ . "/" . $relative . $filename)) { $form_output .= '<tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td><img src="' . __PS_BASE_URI__ . $relative . 'thumb/' . $filename . '" alt="' . $filename . '" style="max-height:200px;" /></td> <td><input type="radio" id="blog_img_default_' . $val['id_blog_image'] . '" name="blog_img_default" ' . (intval($val['default']) == 1 ? 'checked' : '') . ' value="' . $val['id_blog_image'] . '" /></td> <td><input type="text" name="img_pos[' . $val['id_blog_image'] . ']" value="' . $val['position'] . '" size="2" /></td> <td style="width:70px; text-align:center"> <a href="' . self::$currentIndex . '&deleteImg&update' . $this->table . '&token=' . $this->token . '&id_' . $this->table . '=' . $obj->id . '&id_img=' . $val['id_blog_image'] . '" title="' . $this->l('Delete') . '" onclick="if(!confirm(\'' . $this->l('Are you sure you want to delete this picture ?') . '\')) return false;"><img src="../img/admin/delete.gif" alt="' . $this->l('Delete') . '" /></a></td> </tr>'; } } $form_output .= "</table>"; } $form_output .= '</fieldset>'; $form_output .= '<div class="clear space"> </div>'; if (isset($this->conf['category_active']) && $this->conf['category_active'] == 1) { // CATEGORIES $form_output .= '<fieldset><legend><img src="../img/admin/tab-categories.gif"> ' . $this->l('Categories') . '</legend>'; $form_output .= '<label> </label> <div class="margin-form"> '; $post_categories = Tools::getValue('groupBox', $obj->getCategories()); $categories = BlogCategory::listCategories(false, false); if (is_array($categories) && count($categories)) { $form_output .= '<table cellspacing="0" cellpadding="0" class="table" style="min-width:500px;"> <tr> <th style="width:40px;"><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'groupBox[]\', this.checked)" /></th> <th style="width:30px;">' . $this->l('ID') . '</th> <th>' . $this->l('Category name') . '</th> </tr>'; $irow = 0; foreach ($categories as $cat) { $form_output .= ' <tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td><input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_' . $cat['id_blog_category'] . '" value="' . $cat['id_blog_category'] . '" ' . (in_array($cat['id_blog_category'], $post_categories) ? 'checked="checked" ' : '') . '/></td> <td>' . $cat['id_blog_category'] . '</td> <td><label for="groupBox_' . $cat['id_blog_category'] . '" class="t">' . $cat['name'] . ' ' . (count($activeLanguages) > 1 && $cat['iso_code'] != '' ? '(' . $cat['iso_code'] . ')' : '') . ' </label></td> </tr>'; } $form_output .= ' </table> <p style="padding:0px; margin:10px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of categories to which the post is to be in') . '</p>'; } else { $form_output .= '<p>' . $this->l('No category created') . '</p>'; } $form_output .= '</div>'; $form_output .= '</fieldset><div class="clear space"> </div>'; } if (isset($this->conf['product_active']) && $this->conf['product_active'] == 1) { // PRODUCTS $form_output .= '<fieldset> <legend><img src="../img/admin/tab-products.gif"> ' . $this->l('Related products') . '</legend>'; $accessories = Tools::getValue('id_blog_post') ? $obj->getProducts(false) : array(); $form_output .= '<div id="divAccessories">'; foreach ($accessories as $accessory) { $form_output .= $accessory['name'] . (!empty($accessory['reference']) ? ' (' . $accessory['reference'] . ')' : '') . ' <span class="delAccessory" name="' . $accessory['id_product'] . '" style="cursor:pointer;"><img src="../img/admin/delete.gif" class="middle" alt="Delete" /></span><br />'; } $form_output .= '</div>'; $form_output .= '<div class="margin-form"> <input type="hidden" name="inputAccessories" id="inputAccessories" value="'; foreach ($accessories as $accessory) { $form_output .= $accessory['id_product'] . '-'; } $form_output .= '" /> <input type="hidden" name="nameAccessories" id="nameAccessories" value="'; foreach ($accessories as $accessory) { $form_output .= $accessory['name'] . '¤'; } $form_output .= '" />'; $form_output .= '<div id="ajax_choose_product" style="padding:6px; padding-top:2px; width:600px;"> <p class="clear">' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '</p> <input type="text" value="" id="product_autocomplete_input" /> <img onclick="$(this).prev().search();" style="cursor: pointer;" src="../img/admin/add.gif" alt="' . $this->l('Add a product') . '" /> </div'; $form_output .= '</div>'; $form_output .= '</fieldset><div class="clear space"> </div>'; } if (isset($this->conf['related_active']) && $this->conf['related_active'] == 1) { // RELATED ARTICLES $form_output .= '<fieldset> <legend><img src="../img/admin/tab-categories.gif"> ' . $this->l('Related blog posts') . '</legend>'; $blog_related = Tools::getValue('groupRelated', $obj->getRelatedIds(true)); $articles = BlogPost::listPosts(false, false, null, null, false, null, null, $obj->id); $form_output .= '<label> </label> <div class="margin-form" style="height:140px; overflow-x:hidden; overflow-y:scroll; padding:0;">'; if (count($articles)) { $form_output .= '<table cellspacing="0" cellpadding="0" class="table" style="min-width:500px;"> <tr> <th style="width:40px;"></th> <th style="width:30px;">' . $this->l('ID') . '</th> <th>' . $this->l('Title') . '</th> </tr>'; $irow = 0; foreach ($articles as $post) { if ($post['id_blog_post'] == $obj->id) { continue; } $iso = count($activeLanguages) > 1 && $post['id_lang'] != 0 ? '(' . Language::getIsoById($post['id_lang']) . ')' : ''; $form_output .= '<tr class="' . ($irow++ % 2 ? 'alt_row' : '') . '"> <td><input type="checkbox" name="groupRelated[]" class="groupBox" id="groupRelated_' . $post['id_blog_post'] . '" value="' . $post['id_blog_post'] . '" ' . (in_array($post['id_blog_post'], $blog_related) ? 'checked="checked" ' : '') . '/></td> <td>' . $post['id_blog_post'] . '</td> <td><label for="groupRelated_' . $post['id_blog_post'] . '" class="t">' . $post['title'] . ' ' . $iso . '</label></td> </tr>'; } $form_output .= '</table>'; $form_output .= '</div> <p style="font-size:11px;">' . $this->l('Select related posts') . '</p> <div class="clear"> </div>'; } else { $form_output .= '<p>' . $this->l('No posts created') . '</p>'; } $form_output .= '</fieldset><div class="clear space"> </div>'; } $form_output .= '<fieldset><legend>' . $this->l('SEO - Post metas') . '</legend>'; $form_output .= HelperFieldForm::displayTextField('link_rewrite', $this->getFieldValue($obj, 'link_rewrite'), 'text', $this->l('Friendly URL :'), $this->l('Only letters and the minus (-) character are allowed'), array('id' => 'link_rewrite_' . $lang_value)); $form_output .= HelperFieldForm::displayTextField('meta_description', $this->getFieldValue($obj, 'meta_description'), 'textarea', $this->l('META description :'), $this->l('Search engines meta description'), array('rows' => 2)); $form_output .= HelperFieldForm::displayTextField('meta_keywords', $this->getFieldValue($obj, 'meta_keywords'), 'text', $this->l('META keywords :'), $this->l('Separate keywords by ,')); $form_output .= '</fieldset><div class="clear space"> </div>'; $form_output .= '<fieldset><legend><img src="../img/admin/cog.gif"> ' . $this->l('Publication options') . '</legend>'; $status_options = array(array('value' => 'published', 'title' => $this->l('Published')), array('value' => 'drafted', 'title' => $this->l('Drafted')), array('value' => 'suspended', 'title' => $this->l('Suspended'))); $status_value = $this->getFieldValue($obj, 'status'); $form_output .= HelperFieldForm::displaySelectField('status', $status_options, $status_value, $this->l('Status :')); if (isset($this->conf['comment_active']) && $this->conf['comment_active'] == 1) { $comments_options = array(array('value' => '1', 'title' => $this->l('Enabled')), array('value' => '0', 'title' => $this->l('Disabled'))); $comments_value = !$obj->id ? 1 : $this->getFieldValue($obj, 'allow_comments'); $form_output .= HelperFieldForm::displayRadioField('allow_comments', $comments_options, $comments_value, $this->l('Allow comments :')); } $date_on = $this->getFieldValue($obj, 'date_on') == "" ? date('Y-m-d') : $this->getFieldValue($obj, 'date_on'); $form_output .= HelperFieldForm::displayDateField('date_on', $date_on, $this->l('Publication date :')); if (Shop::isFeatureActive()) { $form_output .= '<label> </label> <div class="margin-form">'; $helperForm = new HelperForm(); $helperForm->identifier = $this->identifier; $helperForm->table = $this->table; $helperForm->id = $obj->id; $form_output .= $helperForm->renderAssoShop(); $form_output .= '</div>'; } $form_output .= '</fieldset><div class="clear space"> </div>'; $form_output .= '<div class="small"><sup>*</sup> ' . $this->l('Required field') . '</div> <input type="submit" class="button" name="submitAdd' . $this->table . '" value="' . $this->l('Save') . '" id="' . $this->table . '_form_submit_btn" /> </form> <div class="clear space"> </div>'; $helper = new HelperCore(); $helper->module = new Psblog(); $template = $helper->createTemplate('form_blog_post.tpl'); $iso_code = $this->context->language->iso_code; $iso = file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso_code . '.js') ? $iso_code : 'en'; $iso_tiny_mce = file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_code . '.js') ? $iso_code : 'en'; $this->addjQueryPlugin(array('autocomplete', 'ajaxfileupload', 'date')); $this->addJS(array(_MODULE_DIR_ . $this->module->name . '/js/psblog.js', _MODULE_DIR_ . $this->module->name . '/js/jquery.MultiFile.pack.js', _PS_JS_DIR_ . 'tiny_mce/tiny_mce.js', _PS_JS_DIR_ . 'tinymce.inc.js', _PS_JS_DIR_ . 'fileuploader.js')); $this->addJqueryUI(array('ui.core', 'ui.datepicker')); $this->toolbar_btn['save-and-stay'] = array('href' => '#', 'desc' => $this->l('Save and stay')); $title = array($this->l('Blog'), $obj->id ? $this->l('Edit') : $this->l('Add new')); $template->assign(array('show_toolbar' => true, 'path_css' => _THEME_CSS_DIR_, 'toolbar_btn' => $this->toolbar_btn, 'currentIndex' => self::$currentIndex, 'toolbar_scroll' => true, 'title' => $title, 'ad' => dirname($_SERVER['PHP_SELF']), 'form_content' => $form_output, 'iso_tiny_mce' => $iso_tiny_mce, 'iso' => $iso, 'tinymce' => true, 'vat_number' => file_exists(_PS_MODULE_DIR_ . 'vatnumber/ajax.php'), 'languages' => $this->_languages, 'id_lang_default' => $defaultLanguage, 'defaultFormLanguage' => $defaultLanguage, 'allowEmployeeFormLang' => $this->allow_employee_form_lang)); $form_content = $template->fetch(); return $form_content; }