Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

427
classes/helper/Helper.php Executable file
View File

@@ -0,0 +1,427 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperCore
{
public $currentIndex;
public $table = 'configuration';
public $identifier;
public $token;
public $toolbar_btn;
public $ps_help_context;
public $title;
public $show_toolbar = true;
public $context;
public $toolbar_scroll = false;
public $bootstrap = false;
/**
* @var Module
*/
public $module;
/** @var string Helper tpl folder */
public $base_folder;
/** @var string Controller tpl folder */
public $override_folder;
/**
* @var Smarty_Internal_Template base template object
*/
protected $tpl;
/**
* @var string base template name
*/
public $base_tpl = 'content.tpl';
public $tpl_vars = array();
public function __construct()
{
$this->context = Context::getContext();
}
public function setTpl($tpl)
{
$this->tpl = $this->createTemplate($tpl);
}
/**
* Create a template from the override file, else from the base file.
*
* @param string $tpl_name filename
*
* @return Smarty_Internal_Template
*/
public function createTemplate($tpl_name)
{
if ($this->override_folder) {
if ($this->context->controller instanceof ModuleAdminController) {
$override_tpl_path = $this->context->controller->getTemplatePath() . $this->override_folder . $this->base_folder . $tpl_name;
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/_configure/' . $this->override_folder . $this->base_folder . $tpl_name;
} else {
if (file_exists($this->context->smarty->getTemplateDir(1) . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(1) . $this->override_folder . $this->base_folder . $tpl_name;
} elseif (file_exists($this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name)) {
$override_tpl_path = $this->context->smarty->getTemplateDir(0) . 'controllers' . DIRECTORY_SEPARATOR . $this->override_folder . $this->base_folder . $tpl_name;
}
}
} elseif ($this->module) {
$override_tpl_path = _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/_configure/' . $this->base_folder . $tpl_name;
}
if (isset($override_tpl_path) && file_exists($override_tpl_path)) {
return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty);
} else {
return $this->context->smarty->createTemplate($this->base_folder . $tpl_name, $this->context->smarty);
}
}
/**
* default behaviour for helper is to return a tpl fetched.
*
* @return string
*/
public function generate()
{
$this->tpl->assign($this->tpl_vars);
return $this->tpl->fetch();
}
/**
* @deprecated 1.5.0
*/
public static function renderAdminCategorieTree(
$translations,
$selected_cat = array(),
$input_name = 'categoryBox',
$use_radio = false,
$use_search = false,
$disabled_categories = array(),
$use_in_popup = false
) {
Tools::displayAsDeprecated();
$helper = new Helper();
if (isset($translations['Root'])) {
$root = $translations['Root'];
} elseif (isset($translations['Home'])) {
$root = array('name' => $translations['Home'], 'id_category' => 1);
} else {
throw new PrestaShopException('Missing root category parameter.');
}
return $helper->renderCategoryTree($root, $selected_cat, $input_name, $use_radio, $use_search, $disabled_categories, $use_in_popup);
}
/**
* @param array $root array with the name and ID of the tree root category, if null the Shop's root category will be used
* @param array $selected_cat array of selected categories
*
* @usage
* Format
* Array( [0] => 1, [1] => 2)
* OR
* Array([1] => Array([id_category] => 1, [name] => Home page))
*
* @param string $input_name name of input
* @param bool $use_radio use radio tree or checkbox tree
* @param bool $use_search display a find category search box
* @param array $disabled_categories
*
* @return string
*/
public function renderCategoryTree(
$root = null,
$selected_cat = array(),
$input_name = 'categoryBox',
$use_radio = false,
$use_search = false,
$disabled_categories = array()
) {
$translator = Context::getContext()->getTranslator();
$translations = array(
'selected' => $translator->trans('Selected', array(), 'Admin.Global'),
'Collapse All' => $translator->trans('Collapse All', array(), 'Admin.Actions'),
'Expand All' => $translator->trans('Expand All', array(), 'Admin.Actions'),
'Check All' => $translator->trans('Check All', array(), 'Admin.Actions'),
'Uncheck All' => $translator->trans('Uncheck All', array(), 'Admin.Actions'),
'search' => $translator->trans('Find a category', array(), 'Admin.Actions'),
);
if (Tools::isSubmit('id_shop')) {
$id_shop = Tools::getValue('id_shop');
} elseif (Context::getContext()->shop->id) {
$id_shop = Context::getContext()->shop->id;
} elseif (!Shop::isFeatureActive()) {
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
} else {
$id_shop = 0;
}
$shop = new Shop($id_shop);
$root_category = Category::getRootCategory(null, $shop);
$disabled_categories[] = (int) Configuration::get('PS_ROOT_CATEGORY');
if (!$root) {
$root = array('name' => $root_category->name, 'id_category' => $root_category->id);
}
if (!$use_radio) {
$input_name = $input_name . '[]';
}
if ($use_search) {
$this->context->controller->addJs(_PS_JS_DIR_ . 'jquery/plugins/autocomplete/jquery.autocomplete.js');
}
$html = '
<script type="text/javascript">
var inputName = \'' . addcslashes($input_name, '\'') . '\';' . "\n";
if (count($selected_cat) > 0) {
if (isset($selected_cat[0])) {
$html .= ' var selectedCat = "' . implode(',', array_map('intval', $selected_cat)) . '";' . "\n";
} else {
$html .= ' var selectedCat = "' . implode(',', array_map('intval', array_keys($selected_cat))) . '";' . "\n";
}
} else {
$html .= ' var selectedCat = \'\';' . "\n";
}
$html .= ' var selectedLabel = \'' . $translations['selected'] . '\';
var home = \'' . addcslashes($root['name'], '\'') . '\';
var use_radio = ' . (int) $use_radio . ';';
$html .= '</script>';
$html .= '
<div class="category-filter">
<a class="btn btn-link" href="#" id="collapse_all"><i class="icon-collapse"></i> ' . $translations['Collapse All'] . '</a>
<a class="btn btn-link" href="#" id="expand_all"><i class="icon-expand"></i> ' . $translations['Expand All'] . '</a>
' . (!$use_radio ? '
<a class="btn btn-link" href="#" id="check_all"><i class="icon-check"></i> ' . $translations['Check All'] . '</a>
<a class="btn btn-link" href="#" id="uncheck_all"><i class="icon-check-empty"></i> ' . $translations['Uncheck All'] . '</a>' : '')
. ($use_search ? '
<div class="row">
<label class="control-label col-lg-6" for="search_cat">' . $translations['search'] . ' :</label>
<div class="col-lg-6">
<input type="text" name="search_cat" id="search_cat"/>
</div>
</div>' : '')
. '</div>';
$home_is_selected = false;
if (is_array($selected_cat)) {
foreach ($selected_cat as $cat) {
if (is_array($cat)) {
$disabled = in_array($cat['id_category'], $disabled_categories);
if ($cat['id_category'] != $root['id_category']) {
$html .= '<input ' . ($disabled ? 'disabled="disabled"' : '') . ' type="hidden" name="' . $input_name . '" value="' . $cat['id_category'] . '" >';
} else {
$home_is_selected = true;
}
} else {
$disabled = in_array($cat, $disabled_categories);
if ($cat != $root['id_category']) {
$html .= '<input ' . ($disabled ? 'disabled="disabled"' : '') . ' type="hidden" name="' . $input_name . '" value="' . $cat . '" >';
} else {
$home_is_selected = true;
}
}
}
}
$root_input = '';
if ($root['id_category'] != (int) Configuration::get('PS_ROOT_CATEGORY') || (Tools::isSubmit('ajax') && Tools::getValue('action') == 'getCategoriesFromRootCategory')) {
$root_input = '
<p class="checkbox"><i class="icon-folder-open"></i><label>
<input type="' . (!$use_radio ? 'checkbox' : 'radio') . '" name="'
. $input_name . '" value="' . $root['id_category'] . '" '
. ($home_is_selected ? 'checked' : '') . ' onclick="clickOnCategoryBox($(this));" />'
. $root['name'] .
'</label></p>';
}
$html .= '
<div class="container">
<div class="well">
<ul id="categories-treeview">
<li id="' . $root['id_category'] . '" class="hasChildren">
<span class="folder">' . $root_input . ' </span>
<ul>
<li><span class="placeholder">&nbsp;</span></li>
</ul>
</li>
</ul>
</div>
</div>';
if ($use_search) {
$html .= '<script type="text/javascript">searchCategory();</script>';
}
return $html;
}
/**
* use translations files to replace english expression.
*
* @deprecated use Context::getContext()->getTranslator()->trans($id, $parameters, $domain, $locale); instead
*
* @param mixed $string term or expression in english
* @param string $class
* @param bool $addslashes if set to true, the return value will pass through addslashes(). Otherwise, stripslashes().
* @param bool $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
*
* @return string the translation if available, or the english default text
*/
protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
{
// if the class is extended by a module, use modules/[module_name]/xx.php lang file
$current_class = get_class($this);
if (Module::getModuleNameFromClass($current_class)) {
return Translate::getModuleTranslation(Module::$classInModule[$current_class], $string, $current_class);
}
return Translate::getAdminTranslation($string, get_class($this), $addslashes, $htmlentities);
}
/**
* Render a form with potentials required fields.
*
* @param string $class_name
* @param string $identifier
* @param array $table_fields
*
* @return string
*/
public function renderRequiredFields($class_name, $identifier, $table_fields)
{
$rules = call_user_func_array(array($class_name, 'getValidationRules'), array($class_name));
$required_class_fields = array($identifier);
foreach ($rules['required'] as $required) {
$required_class_fields[] = $required;
}
/** @var ObjectModel $object */
$object = new $class_name();
$res = $object->getFieldsRequiredDatabase();
$required_fields = array();
foreach ($res as $row) {
$required_fields[(int) $row['id_required_field']] = $row['field_name'];
}
$this->tpl_vars = array(
'table_fields' => $table_fields,
'irow' => 0,
'required_class_fields' => $required_class_fields,
'required_fields' => $required_fields,
'current' => $this->currentIndex,
'token' => $this->token,
);
$tpl = $this->createTemplate('helpers/required_fields.tpl');
$tpl->assign($this->tpl_vars);
return $tpl->fetch();
}
public function renderModulesList($modules_list)
{
$this->tpl_vars = array(
'modules_list' => $modules_list,
'modules_uri' => __PS_BASE_URI__ . basename(_PS_MODULE_DIR_),
);
// The translations for this are defined by AdminModules, so override the context for the translations
$override_controller_name_for_translations = Context::getContext()->override_controller_name_for_translations;
Context::getContext()->override_controller_name_for_translations = 'AdminModules';
$tpl = $this->createTemplate('helpers/modules_list/list.tpl');
$tpl->assign($this->tpl_vars);
$html = $tpl->fetch();
// Restore the previous context
Context::getContext()->override_controller_name_for_translations = $override_controller_name_for_translations;
return $html;
}
/**
* Render shop list.
*
* @deprecated deprecated since 1.6.1.0 use HelperShop->getRenderedShopList
*
* @return string
*/
public static function renderShopList()
{
Tools::displayAsDeprecated('Use HelperShop->getRenderedShopList instead');
if (!Shop::isFeatureActive() || Shop::getTotalShops(false, null) < 2) {
return null;
}
$tree = Shop::getTree();
$context = Context::getContext();
// Get default value
$shop_context = Shop::getContext();
if ($shop_context == Shop::CONTEXT_ALL || ($context->controller->multishop_context_group == false && $shop_context == Shop::CONTEXT_GROUP)) {
$value = '';
} elseif ($shop_context == Shop::CONTEXT_GROUP) {
$value = 'g-' . Shop::getContextShopGroupID();
} else {
$value = 's-' . Shop::getContextShopID();
}
// Generate HTML
$url = $_SERVER['REQUEST_URI'] . (($_SERVER['QUERY_STRING']) ? '&' : '?') . 'setShopContext=';
$shop = new Shop(Shop::getContextShopID());
// $html = '<a href="#"><i class="icon-home"></i> '.$shop->name.'</a>';
$html = '<select class="shopList" onchange="location.href = \'' . htmlspecialchars($url) . '\'+$(this).val();">';
$html .= '<option value="" class="first">' . Translate::getAdminTranslation('All shops') . '</option>';
foreach ($tree as $group_id => $group_data) {
if ((!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP)) {
$html .= '<option class="group" value="g-' . $group_id . '"' . (((empty($value) && $shop_context == Shop::CONTEXT_GROUP) || $value == 'g-' . $group_id) ? ' selected="selected"' : '') . ($context->controller->multishop_context_group == false ? ' disabled="disabled"' : '') . '>' . Translate::getAdminTranslation('Group:') . ' ' . htmlspecialchars($group_data['name']) . '</option>';
} else {
$html .= '<optgroup class="group" label="' . Translate::getAdminTranslation('Group:') . ' ' . htmlspecialchars($group_data['name']) . '"' . ($context->controller->multishop_context_group == false ? ' disabled="disabled"' : '') . '>';
}
if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_SHOP) {
foreach ($group_data['shops'] as $shop_id => $shop_data) {
if ($shop_data['active']) {
$html .= '<option value="s-' . $shop_id . '" class="shop"' . (($value == 's-' . $shop_id) ? ' selected="selected"' : '') . '>' . ($context->controller->multishop_context_group == false ? htmlspecialchars($group_data['name']) . ' - ' : '') . $shop_data['name'] . '</option>';
}
}
}
if (!(!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP)) {
$html .= '</optgroup>';
}
}
$html .= '</select>';
return $html;
}
}

View File

@@ -0,0 +1,277 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperCalendarCore extends Helper
{
const DEFAULT_DATE_FORMAT = 'Y-mm-dd';
const DEFAULT_COMPARE_OPTION = 1;
private $_actions;
private $_compare_actions;
private $_compare_date_from;
private $_compare_date_to;
private $_compare_date_option;
private $_date_format;
private $_date_from;
private $_date_to;
private $_rtl;
public function __construct()
{
$this->base_folder = 'helpers/calendar/';
$this->base_tpl = 'calendar.tpl';
parent::__construct();
}
public function setActions($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Actions value must be an traversable array');
}
$this->_actions = $value;
return $this;
}
public function getActions()
{
if (!isset($this->_actions)) {
$this->_actions = array();
}
return $this->_actions;
}
public function setCompareActions($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Actions value must be an traversable array');
}
$this->_compare_actions = $value;
return $this;
}
public function getCompareActions()
{
if (!isset($this->_compare_actions)) {
$this->_compare_actions = array();
}
return $this->_compare_actions;
}
public function setCompareDateFrom($value)
{
$this->_compare_date_from = $value;
return $this;
}
public function getCompareDateFrom()
{
return $this->_compare_date_from;
}
public function setCompareDateTo($value)
{
$this->_compare_date_to = $value;
return $this;
}
public function getCompareDateTo()
{
return $this->_compare_date_to;
}
public function setCompareOption($value)
{
$this->_compare_date_option = (int) $value;
return $this;
}
public function getCompareOption()
{
if (!isset($this->_compare_date_option)) {
$this->_compare_date_option = self::DEFAULT_COMPARE_OPTION;
}
return $this->_compare_date_option;
}
public function setDateFormat($value)
{
if (!is_string($value)) {
throw new PrestaShopException('Date format must be a string');
}
$this->_date_format = $value;
return $this;
}
public function getDateFormat()
{
if (!isset($this->_date_format)) {
$this->_date_format = self::DEFAULT_DATE_FORMAT;
}
return $this->_date_format;
}
public function setDateFrom($value = '')
{
if (empty($value)) {
$value = strtotime('-31 days');
}
if (!is_string($value)) {
throw new PrestaShopException('Date must be a string');
}
$this->_date_from = date('Y-m-d', strtotime($value));
return $this;
}
public function getDateFrom()
{
if (!isset($this->_date_from)) {
$this->setDateFrom();
}
return $this->_date_from;
}
public function setDateTo($value = '')
{
if (empty($value)) {
$value = strtotime('-31 days');
}
if (!is_string($value)) {
throw new PrestaShopException('Date must be a string');
}
$this->_date_to = date('Y-m-d', strtotime($value));
return $this;
}
public function getDateTo()
{
if (!isset($this->_date_to)) {
$this->setDateTo();
}
return $this->_date_to;
}
public function setRTL($value)
{
$this->_rtl = (bool) $value;
return $this;
}
public function addAction($action)
{
if (!isset($this->_actions)) {
$this->_actions = array();
}
$this->_actions[] = $action;
return $this;
}
public function addCompareAction($action)
{
if (!isset($this->_compare_actions)) {
$this->_compare_actions = array();
}
$this->_compare_actions[] = $action;
return $this;
}
public function generate()
{
$context = Context::getContext();
$admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($context->employee)
&& $context->employee->bo_theme) ? $context->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_ . $bo_theme . DIRECTORY_SEPARATOR
. 'template')) {
$bo_theme = 'default';
}
if ($context->controller->ajax) {
$html = '<script type="text/javascript" src="' . __PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/date-range-picker.js"></script>';
$html .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/calendar.js"></script>';
} else {
$html = '';
$context->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/date-range-picker.js');
$context->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/calendar.js');
}
$this->tpl = $this->createTemplate($this->base_tpl);
$this->tpl->assign(array(
'date_format' => $this->getDateFormat(),
'date_from' => $this->getDateFrom(),
'date_to' => $this->getDateTo(),
'compare_date_from' => $this->getCompareDateFrom(),
'compare_date_to' => $this->getCompareDateTo(),
'actions' => $this->getActions(),
'compare_actions' => $this->getCompareActions(),
'compare_option' => $this->getCompareOption(),
'is_rtl' => $this->isRTL(),
));
$html .= parent::generate();
return $html;
}
public function isRTL()
{
if (!isset($this->_rtl)) {
$this->_rtl = Context::getContext()->language->is_rtl;
}
return $this->_rtl;
}
}

View File

@@ -0,0 +1,359 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
/**
* @since 1.5.0
*/
class HelperFormCore extends Helper
{
public $id;
public $first_call = true;
/** @var array of forms fields */
protected $fields_form = array();
/** @var array values of form fields */
public $fields_value = array();
public $name_controller = '';
/** @var string if not null, a title will be added on that list */
public $title = null;
/** @var string Used to override default 'submitAdd' parameter in form action attribute */
public $submit_action;
public $token;
public $languages = null;
public $default_form_language = null;
public $allow_employee_form_lang = null;
public $show_cancel_button = false;
public $back_url = '#';
public function __construct()
{
$this->base_folder = 'helpers/form/';
$this->base_tpl = 'form.tpl';
parent::__construct();
}
public function generateForm($fields_form)
{
$this->fields_form = $fields_form;
return $this->generate();
}
public function generate()
{
$this->tpl = $this->createTemplate($this->base_tpl);
if (null === $this->submit_action) {
$this->submit_action = 'submitAdd' . $this->table;
}
$categories = true;
$color = true;
$date = true;
$tinymce = true;
$textarea_autosize = true;
$file = true;
foreach ($this->fields_form as $fieldset_key => &$fieldset) {
if (isset($fieldset['form']['tabs'])) {
$tabs[] = $fieldset['form']['tabs'];
}
if (isset($fieldset['form']['input'])) {
foreach ($fieldset['form']['input'] as $key => &$params) {
// If the condition is not met, the field will not be displayed
if (isset($params['condition']) && !$params['condition']) {
unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
}
switch ($params['type']) {
case 'select':
$field_name = (string) $params['name'];
// If multiple select check that 'name' field is suffixed with '[]'
if (isset($params['multiple']) && $params['multiple'] && stripos($field_name, '[]') === false) {
$params['name'] .= '[]';
}
break;
case 'categories':
if ($categories) {
if (!isset($params['tree']['id'])) {
throw new PrestaShopException('Id must be filled for categories tree');
}
$tree = new HelperTreeCategories($params['tree']['id'], isset($params['tree']['title']) ? $params['tree']['title'] : null);
if (isset($params['name'])) {
$tree->setInputName($params['name']);
}
if (isset($params['tree']['selected_categories'])) {
$tree->setSelectedCategories($params['tree']['selected_categories']);
}
if (isset($params['tree']['disabled_categories'])) {
$tree->setDisabledCategories($params['tree']['disabled_categories']);
}
if (isset($params['tree']['root_category'])) {
$tree->setRootCategory($params['tree']['root_category']);
}
if (isset($params['tree']['use_search'])) {
$tree->setUseSearch($params['tree']['use_search']);
}
if (isset($params['tree']['use_checkbox'])) {
$tree->setUseCheckBox($params['tree']['use_checkbox']);
}
if (isset($params['tree']['set_data'])) {
$tree->setData($params['tree']['set_data']);
}
$this->context->smarty->assign('categories_tree', $tree->render());
$categories = false;
}
break;
case 'file':
$uploader = new HelperUploader();
$uploader->setId(isset($params['id']) ? $params['id'] : null);
$uploader->setName($params['name']);
$uploader->setUrl(isset($params['url']) ? $params['url'] : null);
$uploader->setMultiple(isset($params['multiple']) ? $params['multiple'] : false);
$uploader->setUseAjax(isset($params['ajax']) ? $params['ajax'] : false);
$uploader->setMaxFiles(isset($params['max_files']) ? $params['max_files'] : null);
if (isset($params['files']) && $params['files']) {
$uploader->setFiles($params['files']);
} elseif (isset($params['image']) && $params['image']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_IMAGE,
'image' => isset($params['image']) ? $params['image'] : null,
'size' => isset($params['size']) ? $params['size'] : null,
'delete_url' => isset($params['delete_url']) ? $params['delete_url'] : null,
),
));
}
if (isset($params['file']) && $params['file']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_FILE,
'size' => isset($params['size']) ? $params['size'] : null,
'delete_url' => isset($params['delete_url']) ? $params['delete_url'] : null,
'download_url' => isset($params['file']) ? $params['file'] : null,
),
));
}
if (isset($params['thumb']) && $params['thumb']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_IMAGE,
'image' => isset($params['thumb']) ? '<img src="' . $params['thumb'] . '" alt="' . (isset($params['title']) ? $params['title'] : '') . '" title="' . (isset($params['title']) ? $params['title'] : '') . '" />' : null,
),
));
}
$uploader->setTitle(isset($params['title']) ? $params['title'] : null);
$params['file'] = $uploader->render();
break;
case 'color':
if ($color) {
// Added JS file
$this->context->controller->addJqueryPlugin('colorpicker');
$this->tpl_vars['color'] = true;
$color = false;
}
break;
case 'date':
if ($date) {
$this->context->controller->addJqueryUI('ui.datepicker');
$date = false;
}
break;
case 'textarea':
if ($tinymce) {
$iso = $this->context->language->iso_code;
$this->tpl_vars['iso'] = file_exists(_PS_CORE_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
$this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
$this->tpl_vars['ad'] = __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
$this->tpl_vars['tinymce'] = true;
$this->context->controller->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js');
$this->context->controller->addJS(_PS_JS_DIR_ . 'admin/tinymce.inc.js');
$tinymce = false;
}
if ($textarea_autosize) {
$this->context->controller->addJqueryPlugin('autosize');
$textarea_autosize = false;
}
break;
case 'shop':
$disable_shops = isset($params['disable_shared']) ? $params['disable_shared'] : false;
$params['html'] = $this->renderAssoShop($disable_shops);
if (Shop::getTotalShops(false) == 1) {
if ((isset($this->fields_form[$fieldset_key]['form']['force']) && !$this->fields_form[$fieldset_key]['form']['force']) || !isset($this->fields_form[$fieldset_key]['form']['force'])) {
unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
}
}
break;
}
}
}
}
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
$moduleManager = $moduleManagerBuilder->build();
$this->tpl->assign(array(
'title' => $this->title,
'toolbar_btn' => $this->toolbar_btn,
'show_toolbar' => $this->show_toolbar,
'toolbar_scroll' => $this->toolbar_scroll,
'submit_action' => $this->submit_action,
'firstCall' => $this->first_call,
'current' => $this->currentIndex,
'token' => $this->token,
'table' => $this->table,
'identifier' => $this->identifier,
'name_controller' => $this->name_controller,
'languages' => $this->languages,
'current_id_lang' => $this->context->language->id,
'defaultFormLanguage' => $this->default_form_language,
'allowEmployeeFormLang' => $this->allow_employee_form_lang,
'form_id' => $this->id,
'tabs' => (isset($tabs)) ? $tabs : null,
'fields' => $this->fields_form,
'fields_value' => $this->fields_value,
'required_fields' => $this->getFieldsRequired(),
'vat_number' => $moduleManager->isInstalled('vatnumber') && file_exists(_PS_MODULE_DIR_ . 'vatnumber/ajax.php'),
'module_dir' => _MODULE_DIR_,
'base_url' => $this->context->shop->getBaseURL(),
'contains_states' => (isset($this->fields_value['id_country'], $this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null,
'dni_required' => (isset($this->fields_value['id_country'], $this->fields_value['dni'])) ? Address::dniRequired($this->fields_value['id_country']) : null,
'show_cancel_button' => $this->show_cancel_button,
'back_url' => $this->back_url,
));
return parent::generate();
}
/**
* Return true if there are required fields.
*/
public function getFieldsRequired()
{
foreach ($this->fields_form as $fieldset) {
if (isset($fieldset['form']['input'])) {
foreach ($fieldset['form']['input'] as $input) {
if (!empty($input['required']) && $input['type'] != 'radio') {
return true;
}
}
}
}
return false;
}
/**
* Render an area to determinate shop association.
*
* @return string
*/
public function renderAssoShop($disable_shared = false, $template_directory = null)
{
if (!Shop::isFeatureActive()) {
return;
}
$assos = array();
if ((int) $this->id) {
$sql = 'SELECT `id_shop`, `' . bqSQL($this->identifier) . '`
FROM `' . _DB_PREFIX_ . bqSQL($this->table) . '_shop`
WHERE `' . bqSQL($this->identifier) . '` = ' . (int) $this->id;
foreach (Db::getInstance()->executeS($sql) as $row) {
$assos[$row['id_shop']] = $row['id_shop'];
}
} else {
switch (Shop::getContext()) {
case Shop::CONTEXT_SHOP:
$assos[Shop::getContextShopID()] = Shop::getContextShopID();
break;
case Shop::CONTEXT_GROUP:
foreach (Shop::getShops(false, Shop::getContextShopGroupID(), true) as $id_shop) {
$assos[$id_shop] = $id_shop;
}
break;
default:
foreach (Shop::getShops(false, null, true) as $id_shop) {
$assos[$id_shop] = $id_shop;
}
break;
}
}
/*$nb_shop = 0;
foreach ($tree as &$value)
{
$value['disable_shops'] = (isset($value[$disable_shared]) && $value[$disable_shared]);
$nb_shop += count($value['shops']);
}*/
$tree = new HelperTreeShops('shop-tree', 'Shops');
if (isset($template_directory)) {
$tree->setTemplateDirectory($template_directory);
}
$tree->setSelectedShops($assos);
$tree->setAttribute('table', $this->table);
return $tree->render();
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperImageUploaderCore extends HelperUploader
{
public function getMaxSize()
{
return (int) Tools::getMaxUploadSize();
}
public function getSavePath()
{
return $this->_normalizeDirectory(_PS_TMP_IMG_DIR_);
}
public function getFilePath($file_name = null)
{
//Force file path
return tempnam($this->getSavePath(), $this->getUniqueFileName());
}
protected function validate(&$file)
{
$file['error'] = $this->checkUploadError($file['error']);
$post_max_size = Tools::convertBytes(ini_get('post_max_size'));
$upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize'));
if ($post_max_size && ($this->_getServerVars('CONTENT_LENGTH') > $post_max_size)) {
$file['error'] = Context::getContext()->getTranslator()->trans('The uploaded file exceeds the post_max_size directive in php.ini', array(), 'Admin.Notifications.Error');
return false;
}
if ($upload_max_filesize && ($this->_getServerVars('CONTENT_LENGTH') > $upload_max_filesize)) {
$file['error'] = Context::getContext()->getTranslator()->trans('The uploaded file exceeds the upload_max_filesize directive in php.ini', array(), 'Admin.Notifications.Error');
return false;
}
if ($error = ImageManager::validateUpload($file, Tools::getMaxUploadSize($this->getMaxSize()), $this->getAcceptTypes())) {
$file['error'] = $error;
return false;
}
if ($file['size'] > $this->getMaxSize()) {
$file['error'] = Context::getContext()->getTranslator()->trans('File is too big. Current size is %1s, maximum size is %2s.', array($file['size'], $this->getMaxSize()), 'Admin.Notifications.Error');
return false;
}
return true;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperKpiCore extends Helper
{
public $base_folder = 'helpers/kpi/';
public $base_tpl = 'kpi.tpl';
public $id;
public $icon;
public $chart;
public $color;
public $title;
public $subtitle;
public $value;
public $data;
public $source;
public $refresh = true;
public $href;
public $tooltip;
public function generate()
{
$this->tpl = $this->createTemplate($this->base_tpl);
$this->tpl->assign(array(
'id' => $this->id,
'icon' => $this->icon,
'chart' => (bool) $this->chart,
'color' => $this->color,
'title' => $this->title,
'subtitle' => $this->subtitle,
'value' => $this->value,
'data' => $this->data,
'source' => $this->source,
'refresh' => $this->refresh,
'href' => $this->href,
'tooltip' => $this->tooltip,
));
return $this->tpl->fetch();
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperKpiRowCore extends Helper
{
public $base_folder = 'helpers/kpi/';
public $base_tpl = 'row.tpl';
public $kpis = array();
public $refresh = true;
public function generate()
{
$this->tpl = $this->createTemplate($this->base_tpl);
$this->tpl->assign('kpis', $this->kpis);
$this->tpl->assign('refresh', $this->refresh);
return $this->tpl->fetch();
}
}

View File

@@ -0,0 +1,887 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Routing\EntityLinkBuilderFactory;
use PrestaShop\PrestaShop\Adapter\Routing\AdminLinkBuilder;
use PrestaShop\PrestaShop\Adapter\Routing\LegacyHelperLinkBuilder;
use PrestaShop\PrestaShop\Core\Routing\Exception\BuilderNotFoundException;
/**
* @since 1.5.0
*/
class HelperListCore extends Helper
{
/** @var int size which is used for lists image thumbnail generation. */
const LIST_THUMBNAIL_SIZE = 45;
/** @var array Cache for query results */
protected $_list = array();
/** @var int Number of results in list */
public $listTotal = 0;
/** @var array WHERE clause determined by filter fields */
protected $_filter;
/** @var array Number of results in list per page (used in select field) */
public $_pagination = array(20, 50, 100, 300, 1000);
/** @var int Default number of results in list per page */
public $_default_pagination = 50;
/** @var string ORDER BY clause determined by field/arrows in list header */
public $orderBy;
/** @var string Default ORDER BY clause when $orderBy is not defined */
public $_defaultOrderBy = false;
/** @var array : list of vars for button delete */
public $tpl_delete_link_vars = array();
/** @var string Order way (ASC, DESC) determined by arrows in list header */
public $orderWay;
public $identifier;
protected $deleted = 0;
/** @var array $cache_lang use to cache texts in current language */
public static $cache_lang = array();
public $is_cms = false;
public $position_identifier;
public $table_id;
/** @var string */
public $title_icon = null;
/**
* @var array Customize list display
*
* align : determine value alignment
* prefix : displayed before value
* suffix : displayed after value
* image : object image
* icon : icon determined by values
* active : allow to toggle status
*/
protected $fields_list;
/** @var bool Content line is clickable if true */
public $no_link = false;
/** @var Smarty_Internal_Template|string */
protected $header_tpl = 'list_header.tpl';
/** @var Smarty_Internal_Template|string */
protected $content_tpl = 'list_content.tpl';
/** @var Smarty_Internal_Template|string */
protected $footer_tpl = 'list_footer.tpl';
/** @var array list of required actions for each list row */
public $actions = array();
/** @var array list of row ids associated with a given action for witch this action have to not be available */
public $list_skip_actions = array();
public $bulk_actions = false;
public $force_show_bulk_actions = false;
public $specificConfirmDelete = null;
public $colorOnBackground;
/** @var bool If true, activates color on hover */
public $row_hover = true;
/** @var string|null If not null, a title will be added on that list */
public $title = null;
/** @var bool ask for simple header : no filters, no paginations and no sorting */
public $simple_header = false;
public $ajax_params = array();
public $page;
/** @var EntityLinkBuilderFactory */
private $linkBuilderFactory;
public function __construct()
{
$this->base_folder = 'helpers/list/';
$this->base_tpl = 'list.tpl';
$adminLinkBuilder = new AdminLinkBuilder(Context::getContext()->link, [
'customer' => 'AdminCustomers',
'product' => 'AdminProducts',
]);
$this->linkBuilderFactory = new EntityLinkBuilderFactory([
$adminLinkBuilder,
new LegacyHelperLinkBuilder(),
]);
parent::__construct();
}
/**
* Return an html list given the data to fill it up.
*
* @param array $list entries to display (rows)
* @param array $fields_display fields (cols)
*
* @return string html
*/
public function generateList($list, $fields_display)
{
// Append when we get a syntax error in SQL query
if ($list === false) {
$this->context->controller->warnings[] = Context::getContext()->getTranslator()->trans('Bad SQL query', array(), 'Admin.Notifications.Error');
return false;
}
$this->tpl = $this->createTemplate($this->base_tpl);
$this->header_tpl = $this->createTemplate($this->header_tpl);
$this->content_tpl = $this->createTemplate($this->content_tpl);
$this->footer_tpl = $this->createTemplate($this->footer_tpl);
$this->_list = $list;
$this->fields_list = $fields_display;
$patternsOrderBy = array(
'/^([a-z _]*!)/Ui', // remove a. for example
'/^([a-z _]*\.)/Ui', // remove a! for example
'/`/', // remove ` char
);
$this->orderBy = preg_replace($patternsOrderBy, '', $this->orderBy);
$this->orderWay = preg_replace('/^([a-z _]*!)/Ui', '', $this->orderWay);
$this->tpl->assign(array(
'header' => $this->displayListHeader(), // Display list header (filtering, pagination and column names)
'content' => $this->displayListContent(), // Show the content of the table
'footer' => $this->displayListFooter(), // Close list table and submit button
));
return parent::generate();
}
/**
* Fetch the template for action enable.
*
* @param string $token
* @param string $id
* @param int $value state enabled or not
* @param string $active status
* @param int $id_category
* @param int $id_product
*
* @return string
*/
public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null, $ajax = false)
{
$tpl_enable = $this->createTemplate('list_action_enable.tpl');
$tpl_enable->assign(array(
'ajax' => $ajax,
'enabled' => (bool) $value,
'url_enable' => $this->currentIndex . '&' . $this->identifier . '=' . $id . '&' . $active . $this->table . ($ajax ? '&action=' . $active . $this->table . '&ajax=' . (int) $ajax : '') .
((int) $id_category && (int) $id_product ? '&id_category=' . (int) $id_category : '') . ($this->page && $this->page > 1 ? '&page=' . (int) $this->page : '') . '&token=' . ($token != null ? $token : $this->token),
));
return $tpl_enable->fetch();
}
public function displayListContent()
{
if (isset($this->fields_list['position'])) {
if ($this->position_identifier) {
if (isset($this->position_group_identifier)) {
$position_group_identifier = Tools::getIsset($this->position_group_identifier) ? (int) Tools::getValue($this->position_group_identifier) : $this->position_group_identifier;
} else {
$position_group_identifier = (int) Tools::getValue('id_' . ($this->is_cms ? 'cms_' : '') . 'category', ($this->is_cms ? '1' : Category::getRootCategory()->id));
}
} else {
$position_group_identifier = Category::getRootCategory()->id;
}
$positions = array_map(function ($elem) { return (int) ($elem['position']); }, $this->_list);
sort($positions);
}
// key_to_get is used to display the correct product category or cms category after a position change
$identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '';
if ($identifier) {
$key_to_get = 'id_' . ($this->is_cms ? 'cms_' : '') . 'category' . $identifier;
}
foreach ($this->_list as $index => $tr) {
$id = null;
if (isset($tr[$this->identifier])) {
$id = $tr[$this->identifier];
}
$name = isset($tr['name']) ? $tr['name'] : null;
if ($this->shopLinkType) {
$this->_list[$index]['short_shop_name'] = Tools::strlen($tr['shop_name']) > 15 ? Tools::substr($tr['shop_name'], 0, 15) . '...' : $tr['shop_name'];
}
$is_first = true;
// Check all available actions to add to the current list row
foreach ($this->actions as $action) {
//Check if the action is available for the current row
if (!array_key_exists($action, $this->list_skip_actions) || !in_array($id, $this->list_skip_actions[$action])) {
$method_name = 'display' . ucfirst($action) . 'Link';
if (method_exists($this->context->controller, $method_name)) {
$this->_list[$index][$action] = $this->context->controller->$method_name($this->token, $id, $name);
} elseif ($this->module instanceof Module && method_exists($this->module, $method_name)) {
$this->_list[$index][$action] = $this->module->$method_name($this->token, $id, $name);
} elseif (method_exists($this, $method_name)) {
$this->_list[$index][$action] = $this->$method_name($this->token, $id, $name);
}
}
if ($is_first && isset($this->_list[$index][$action])) {
$is_first = false;
if (!preg_match('/a\s*.*class/', $this->_list[$index][$action])) {
$this->_list[$index][$action] = preg_replace(
'/href\s*=\s*\"([^\"]*)\"/',
'href="$1" class="btn btn-default"',
$this->_list[$index][$action]
);
} elseif (!preg_match('/a\s*.*class\s*=\s*\".*btn.*\"/', $this->_list[$index][$action])) {
$this->_list[$index][$action] = preg_replace(
'/a(\s*.*)class\s*=\s*\"(.*)\"/',
'a $1 class="$2 btn btn-default"',
$this->_list[$index][$action]
);
}
}
}
$this->_list[$index]['link'] = in_array('view', $this->actions) ? $this->getViewLink($this->token, $id) : $this->getEditLink($this->token, $id);
// @todo skip action for bulk actions
// $this->_list[$index]['has_bulk_actions'] = true;
foreach ($this->fields_list as $key => $params) {
$tmp = explode('!', $key);
$key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
if (isset($params['active'])) {
// If method is defined in calling controller, use it instead of the Helper method
if (method_exists($this->context->controller, 'displayEnableLink')) {
$calling_obj = $this->context->controller;
} elseif (isset($this->module) && method_exists($this->module, 'displayEnableLink')) {
$calling_obj = $this->module;
} else {
$calling_obj = $this;
}
if (!isset($params['ajax'])) {
$params['ajax'] = false;
}
$this->_list[$index][$key] = $calling_obj->displayEnableLink(
$this->token,
$id,
$tr[$key],
$params['active'],
Tools::getValue('id_category'),
Tools::getValue('id_product'),
$params['ajax']
);
} elseif (isset($params['activeVisu'])) {
$this->_list[$index][$key] = (bool) $tr[$key];
} elseif (isset($params['position'])) {
$this->_list[$index][$key] = array(
'position' => $tr[$key],
'position_url_down' => $this->currentIndex .
(isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $position_group_identifier : '') .
'&' . $this->position_identifier . '=' . $id .
'&way=1&position=' . ((int) $tr['position'] + 1) . '&token=' . $this->token,
'position_url_up' => $this->currentIndex .
(isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $position_group_identifier : '') .
'&' . $this->position_identifier . '=' . $id .
'&way=0&position=' . ((int) $tr['position'] - 1) . '&token=' . $this->token,
);
} elseif (isset($params['image'])) {
// item_id is the product id in a product image context, else it is the image id.
$item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES')) {
$path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType;
} else {
$path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . Image::getImgFolderStatic($tr['id_image']) . (int) $tr['id_image'] . '.' . $this->imageType;
}
$this->_list[$index][$key] = ImageManager::thumbnail($path_to_image, $this->table . '_mini_' . $item_id . '_' . $this->context->shop->id . '.' . $this->imageType, self::LIST_THUMBNAIL_SIZE, $this->imageType);
} elseif (isset($params['icon'], $tr[$key]) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) {
if (!$this->bootstrap) {
if (isset($params['icon'][$tr[$key]]) && is_array($params['icon'][$tr[$key]])) {
$this->_list[$index][$key] = array(
'src' => $params['icon'][$tr[$key]]['src'],
'alt' => $params['icon'][$tr[$key]]['alt'],
);
} else {
$this->_list[$index][$key] = array(
'src' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'],
'alt' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'],
);
}
} elseif (isset($params['icon'][$tr[$key]])) {
$this->_list[$index][$key] = $params['icon'][$tr[$key]];
}
} elseif (isset($params['type']) && $params['type'] == 'float') {
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
} elseif (isset($tr[$key])) {
$echo = $tr[$key];
if (isset($params['callback'])) {
$callback_obj = (isset($params['callback_object'])) ? $params['callback_object'] : $this->context->controller;
$this->_list[$index][$key] = call_user_func_array(array($callback_obj, $params['callback']), array($echo, $tr));
} else {
$this->_list[$index][$key] = $echo;
}
}
}
}
$showShopColumn = $this->shopLinkType;
$isMultiShopActive = Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
$this->content_tpl->assign(array_merge($this->tpl_vars, array(
'shop_link_type' => $showShopColumn,
'multishop_active' => $isMultiShopActive,
'name' => isset($name) ? $name : null,
'position_identifier' => $this->position_identifier,
'identifier' => $this->identifier,
'table' => $this->table,
'token' => $this->token,
'color_on_bg' => $this->colorOnBackground,
'position_group_identifier' => isset($position_group_identifier) ? $position_group_identifier : false,
'bulk_actions' => $this->bulk_actions,
'positions' => isset($positions) ? $positions : null,
'order_by' => $this->orderBy,
'order_way' => $this->orderWay,
'is_cms' => $this->is_cms,
'fields_display' => $this->fields_list,
'list' => $this->_list,
'actions' => $this->actions,
'no_link' => $this->no_link,
'current_index' => $this->currentIndex,
'view' => in_array('view', $this->actions),
'edit' => in_array('edit', $this->actions),
'has_actions' => !empty($this->actions),
'list_skip_actions' => $this->list_skip_actions,
'row_hover' => $this->row_hover,
'list_id' => isset($this->list_id) ? $this->list_id : $this->table,
'checked_boxes' => Tools::getValue((isset($this->list_id) ? $this->list_id : $this->table) . 'Box'),
)));
return $this->content_tpl->fetch();
}
/**
* Display duplicate action link.
*/
public function displayDuplicateLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_duplicate.tpl');
if (!array_key_exists('Bad SQL query', self::$cache_lang)) {
self::$cache_lang['Duplicate'] = Context::getContext()->getTranslator()->trans('Duplicate', array(), 'Admin.Actions');
}
if (!array_key_exists('Copy images too?', self::$cache_lang)) {
self::$cache_lang['Copy images too?'] = Context::getContext()->getTranslator()->trans('This will copy the images too. If you wish to proceed, click "Yes". If not, click "No".', array(), 'Admin.Catalog.Notification');
}
$duplicate = $this->currentIndex . '&' . $this->identifier . '=' . $id . '&duplicate' . $this->table;
$confirm = self::$cache_lang['Copy images too?'];
if (($this->table == 'product') && !Image::hasImages($this->context->language->id, (int) $id)) {
$confirm = '';
}
$tpl->assign(array(
'href' => $this->currentIndex . '&' . $this->identifier . '=' . $id . '&view' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['Duplicate'],
'confirm' => $confirm,
'location_ok' => $duplicate . '&token=' . ($token != null ? $token : $this->token),
'location_ko' => $duplicate . '&noimage=1&token=' . ($token ? $token : $this->token),
));
return $tpl->fetch();
}
/**
* Display action show details of a table row
* This action need an ajax request with a return like this:
* {
* use_parent_structure: true // If false, data need to be an html
* data:
* [
* {field_name: 'value'}
* ],
* fields_display: // attribute $fields_list of the admin controller
* }
* or somethins like this:
* {
* use_parent_structure: false // If false, data need to be an html
* data:
* '<p>My html content</p>',
* fields_display: // attribute $fields_list of the admin controller
* }.
*/
public function displayDetailsLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_details.tpl');
if (!array_key_exists('Details', self::$cache_lang)) {
self::$cache_lang['Details'] = Context::getContext()->getTranslator()->trans('Details', array(), 'Admin.Global');
}
$ajax_params = $this->ajax_params;
if (!is_array($ajax_params) || !isset($ajax_params['action'])) {
$ajax_params['action'] = 'details';
}
$tpl->assign(array(
'id' => $id,
'href' => $this->currentIndex . '&' . $this->identifier . '=' . $id . '&details' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'controller' => str_replace('Controller', '', get_class($this->context->controller)),
'token' => $token != null ? $token : $this->token,
'action' => self::$cache_lang['Details'],
'params' => $ajax_params,
'json_params' => json_encode($ajax_params),
));
return $tpl->fetch();
}
/**
* Display view action link.
*/
public function displayViewLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_view.tpl');
if (!array_key_exists('View', self::$cache_lang)) {
self::$cache_lang['View'] = Context::getContext()->getTranslator()->trans('View', array(), 'Admin.Actions');
}
$href = $this->getViewLink($token, $id);
$tpl->assign(array(
'href' => $href,
'action' => self::$cache_lang['View'],
));
return $tpl->fetch();
}
/**
* Display edit action link.
*/
public function displayEditLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_edit.tpl');
if (!array_key_exists('Edit', self::$cache_lang)) {
self::$cache_lang['Edit'] = Context::getContext()->getTranslator()->trans('Edit', array(), 'Admin.Actions');
}
$href = $this->getEditLink($token, $id);
$tpl->assign(array(
'href' => $href,
'action' => self::$cache_lang['Edit'],
'id' => $id,
));
return $tpl->fetch();
}
/**
* Display delete action link.
*/
public function displayDeleteLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_delete.tpl');
if (!array_key_exists('Delete', self::$cache_lang)) {
self::$cache_lang['Delete'] = Context::getContext()->getTranslator()->trans('Delete', array(), 'Admin.Actions');
}
if (!array_key_exists('DeleteItem', self::$cache_lang)) {
self::$cache_lang['DeleteItem'] = Context::getContext()->getTranslator()->trans('Delete selected item?', array(), 'Admin.Notifications.Info');
}
if (!array_key_exists('Name', self::$cache_lang)) {
self::$cache_lang['Name'] = Context::getContext()->getTranslator()->trans('Name:', array(), 'Admin.Global');
}
if (null !== $name) {
$name = addcslashes('\n\n' . self::$cache_lang['Name'] . ' ' . $name, '\'');
}
$href = $this->currentIndex . '&' . $this->identifier . '=' . $id . '&delete' . $this->table . '&token=' . ($token != null ? $token : $this->token);
switch ($this->currentIndex) {
case 'index.php?controller=AdminProducts':
case 'index.php?tab=AdminProducts':
// New architecture modification: temporary behavior to switch between old and new controllers.
$pagePreference = SymfonyContainer::getInstance()->get('prestashop.core.admin.page_preference_interface');
$redirectLegacy = $pagePreference->getTemporaryShouldUseLegacyPage('product');
if (!$redirectLegacy && $this->identifier == 'id_product') {
$href = Context::getContext()->link->getAdminLink('AdminProducts', true, ['id_product' => $id, 'deleteproduct' => 1]);
}
break;
default:
}
$data = array(
$this->identifier => $id,
'href' => $href,
'action' => self::$cache_lang['Delete'],
);
if ($this->specificConfirmDelete !== false) {
$data['confirm'] = null !== $this->specificConfirmDelete ? '\r' . $this->specificConfirmDelete : Tools::safeOutput(self::$cache_lang['DeleteItem'] . $name);
}
$tpl->assign(array_merge($this->tpl_delete_link_vars, $data));
return $tpl->fetch();
}
/**
* Display default action link.
*/
public function displayDefaultLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_default.tpl');
if (!array_key_exists('Default', self::$cache_lang)) {
self::$cache_lang['Default'] = Context::getContext()->getTranslator()->trans('Default', array(), 'Admin.Global');
}
$tpl->assign(array(
'href' => $this->currentIndex . '&' . $this->identifier . '=' . (int) $id . '&default' . $this->table . '&token=' . ($token != null ? $token : $this->token),
'action' => self::$cache_lang['Default'],
'name' => $name,
));
return $tpl->fetch();
}
/**
* Display list header (filtering, pagination and column names).
*/
public function displayListHeader()
{
if (!isset($this->list_id)) {
$this->list_id = $this->table;
}
$id_cat = (int) Tools::getValue('id_' . ($this->is_cms ? 'cms_' : '') . 'category');
if (!isset($token) || empty($token)) {
$token = $this->token;
}
/* Determine total page number */
$pagination = $this->_default_pagination;
if (in_array((int) Tools::getValue($this->list_id . '_pagination'), $this->_pagination)) {
$pagination = (int) Tools::getValue($this->list_id . '_pagination');
} elseif (isset($this->context->cookie->{$this->list_id . '_pagination'}) && $this->context->cookie->{$this->list_id . '_pagination'}) {
$pagination = $this->context->cookie->{$this->list_id . '_pagination'};
}
$total_pages = max(1, ceil($this->listTotal / $pagination));
$identifier = Tools::getIsset($this->identifier) ? '&' . $this->identifier . '=' . (int) Tools::getValue($this->identifier) : '';
$order = '';
if (Tools::getIsset($this->table . 'Orderby')) {
$order = '&' . $this->table . 'Orderby=' . urlencode($this->orderBy) . '&' . $this->table . 'Orderway=' . urlencode(strtolower($this->orderWay));
}
$action = $this->currentIndex . $identifier . '&token=' . $token . '#' . $this->list_id;
/* Determine current page number */
$page = (int) Tools::getValue('submitFilter' . $this->list_id);
if (!$page) {
$page = 1;
}
if ($page > $total_pages) {
$page = $total_pages;
}
$this->page = (int) $page;
/* Choose number of results per page */
$selected_pagination = Tools::getValue(
$this->list_id . '_pagination',
isset($this->context->cookie->{$this->list_id . '_pagination'}) ? $this->context->cookie->{$this->list_id . '_pagination'} : $this->_default_pagination
);
if (!isset($this->table_id) && $this->position_identifier && (int) Tools::getValue($this->position_identifier, 1)) {
$this->table_id = substr($this->identifier, 3, strlen($this->identifier));
}
if ($this->position_identifier && ($this->orderBy == 'position' && $this->orderWay != 'DESC')) {
$table_dnd = true;
}
$prefix = isset($this->controller_name) ? str_replace(array('admin', 'controller'), '', Tools::strtolower($this->controller_name)) : '';
$ajax = false;
foreach ($this->fields_list as $key => $params) {
if (!isset($params['type'])) {
$params['type'] = 'text';
}
$value_key = $prefix . $this->list_id . 'Filter_' . (array_key_exists('filter_key', $params) ? $params['filter_key'] : $key);
if ($key == 'active' && strpos($key, '!') !== false) {
$keys = explode('!', $params['filter_key']);
$value_key = $keys[1];
}
$value = Context::getContext()->cookie->{$value_key};
if (!$value && Tools::getIsset($value_key)) {
$value = Tools::getValue($value_key);
}
switch ($params['type']) {
case 'bool':
if (isset($params['ajax']) && $params['ajax']) {
$ajax = true;
}
break;
case 'date':
case 'datetime':
if (is_string($value)) {
$value = json_decode($value, true);
}
if (!Validate::isCleanHtml($value[0]) || !Validate::isCleanHtml($value[1])) {
$value = '';
}
$name = $this->list_id . 'Filter_' . (isset($params['filter_key']) ? $params['filter_key'] : $key);
$name_id = str_replace('!', '__', $name);
$params['id_date'] = $name_id;
$params['name_date'] = $name;
$this->context->controller->addJqueryUI('ui.datepicker');
break;
case 'select':
foreach ($params['list'] as $option_value => $option_display) {
if (isset(Context::getContext()->cookie->{$prefix . $this->list_id . 'Filter_' . $params['filter_key']})
&& Context::getContext()->cookie->{$prefix . $this->list_id . 'Filter_' . $params['filter_key']} == $option_value
&& Context::getContext()->cookie->{$prefix . $this->list_id . 'Filter_' . $params['filter_key']} != '') {
$this->fields_list[$key]['select'][$option_value]['selected'] = 'selected';
}
}
break;
case 'text':
if (!Validate::isCleanHtml($value)) {
$value = '';
}
}
$params['value'] = $value;
$this->fields_list[$key] = $params;
}
$has_value = false;
$has_search_field = false;
foreach ($this->fields_list as $key => $field) {
if (isset($field['value']) && $field['value'] !== false && $field['value'] !== '') {
if (is_array($field['value']) && trim(implode('', $field['value'])) == '') {
continue;
}
$has_value = true;
break;
}
if (!(isset($field['search']) && $field['search'] === false)) {
$has_search_field = true;
}
}
Context::getContext()->smarty->assign(array(
'page' => $page,
'simple_header' => $this->simple_header,
'total_pages' => $total_pages,
'selected_pagination' => $selected_pagination,
'pagination' => $this->_pagination,
'list_total' => $this->listTotal,
'sql' => isset($this->sql) && $this->sql ? str_replace('\n', ' ', str_replace('\r', '', $this->sql)) : false,
'token' => $this->token,
'table' => $this->table,
'bulk_actions' => $this->bulk_actions,
'show_toolbar' => $this->show_toolbar,
'toolbar_scroll' => $this->toolbar_scroll,
'toolbar_btn' => $this->toolbar_btn,
'has_bulk_actions' => $this->hasBulkActions($has_value),
'filters_has_value' => (bool) $has_value,
));
if (null !== $this->title_icon) {
Context::getContext()->smarty->assign(['icon' => $this->title_icon]);
}
$isMultiShopActive = Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
$this->header_tpl->assign(array_merge(array(
'ajax' => $ajax,
'title' => array_key_exists('title', $this->tpl_vars) ? $this->tpl_vars['title'] : $this->title,
'show_filters' => ((count($this->_list) > 1 && $has_search_field) || $has_value),
'currentIndex' => $this->currentIndex,
'action' => $action,
'is_order_position' => $this->position_identifier && $this->orderBy == 'position',
'order_way' => $this->orderWay,
'order_by' => $this->orderBy,
'fields_display' => $this->fields_list,
'delete' => in_array('delete', $this->actions),
'identifier' => $this->identifier,
'id_cat' => $id_cat,
'shop_link_type' => $this->shopLinkType,
'multishop_active' => $isMultiShopActive,
'has_actions' => !empty($this->actions),
'table_id' => isset($this->table_id) ? $this->table_id : null,
'table_dnd' => isset($table_dnd) ? $table_dnd : null,
'name' => isset($name) ? $name : null,
'name_id' => isset($name_id) ? $name_id : null,
'row_hover' => $this->row_hover,
'list_id' => isset($this->list_id) ? $this->list_id : $this->table,
), $this->tpl_vars));
return $this->header_tpl->fetch();
}
public function hasBulkActions($has_value = false)
{
if ($this->force_show_bulk_actions) {
return true;
}
if (count($this->_list) <= 1 && !$has_value) {
return false;
}
if (isset($this->list_skip_actions) && count($this->list_skip_actions)
&& isset($this->bulk_actions) && is_array($this->bulk_actions) && count($this->bulk_actions)) {
foreach ($this->bulk_actions as $action => $data) {
if (array_key_exists($action, $this->list_skip_actions)) {
foreach ($this->_list as $key => $row) {
if (!in_array($row[$this->identifier], $this->list_skip_actions[$action])) {
return true;
}
}
return false;
}
}
}
return !empty($this->bulk_actions);
}
/**
* Close list table and submit button.
*/
public function displayListFooter()
{
if (!isset($this->list_id)) {
$this->list_id = $this->table;
}
$this->footer_tpl->assign(array_merge($this->tpl_vars, array(
'current' => $this->currentIndex,
'list_id' => $this->list_id,
)));
return $this->footer_tpl->fetch();
}
/**
* @param string|null $token
* @param int $id
*
* @return string
*
* @throws BuilderNotFoundException
* @throws PrestaShopException
*/
protected function getViewLink($token, $id)
{
$linkBuilder = $this->linkBuilderFactory->getBuilderFor($this->table);
$parameters = $this->buildLinkParameters($token, $id);
return $linkBuilder->getViewLink($this->table, $parameters);
}
/**
* @param string|null $token
* @param int $id
*
* @return string
*
* @throws BuilderNotFoundException
* @throws PrestaShopException
*/
protected function getEditLink($token, $id)
{
$linkBuilder = $this->linkBuilderFactory->getBuilderFor($this->table);
$parameters = $this->buildLinkParameters($token, $id);
return $linkBuilder->getEditLink($this->table, $parameters);
}
/**
* @param string|null $token
* @param int $id
*
* @return array
*/
protected function buildLinkParameters($token, $id)
{
$parameters = [
$this->identifier => $id,
'current_index' => $this->currentIndex,
'token' => $token != null ? $token : $this->token,
];
if ($this->page && $this->page > 1) {
$parameters['page'] = $this->page;
}
return $parameters;
}
}

View File

@@ -0,0 +1,312 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Use this helper to generate preferences forms, with values stored in the configuration table.
*/
class HelperOptionsCore extends Helper
{
public $required = false;
public function __construct()
{
$this->base_folder = 'helpers/options/';
$this->base_tpl = 'options.tpl';
parent::__construct();
}
/**
* Generate a form for options.
*
* @param array $option_list
*
* @return string html
*/
public function generateOptions($option_list)
{
$this->tpl = $this->createTemplate($this->base_tpl);
$tab = Tab::getTab($this->context->language->id, $this->id);
if (!isset($languages)) {
$languages = Language::getLanguages(false);
}
$use_multishop = false;
$hide_multishop_checkbox = (Shop::getTotalShops(false, null) < 2) ? true : false;
foreach ($option_list as $category => $category_data) {
if (!is_array($category_data)) {
continue;
}
if (!isset($category_data['image'])) {
$category_data['image'] = (!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . $tab['module'] . '/' . $tab['class_name'] . '.gif') ? _MODULE_DIR_ . $tab['module'] . '/' : '../img/t/') . $tab['class_name'] . '.gif';
}
if (!isset($category_data['fields'])) {
$category_data['fields'] = array();
}
$category_data['hide_multishop_checkbox'] = true;
if (isset($category_data['tabs'])) {
$tabs[$category] = $category_data['tabs'];
$tabs[$category]['misc'] = Context::getContext()->getTranslator()->trans('Miscellaneous', array(), 'Admin.Global');
}
foreach ($category_data['fields'] as $key => $field) {
if (empty($field['no_multishop_checkbox']) && !$hide_multishop_checkbox) {
$category_data['hide_multishop_checkbox'] = false;
}
// Set field value unless explicitly denied
if (!isset($field['auto_value']) || $field['auto_value']) {
$field['value'] = $this->getOptionValue($key, $field);
}
// Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop)
$is_disabled = $is_invisible = false;
if (Shop::isFeatureActive()) {
if (isset($field['visibility']) && $field['visibility'] > Shop::getContext()) {
$is_disabled = true;
$is_invisible = true;
} elseif (Shop::getContext() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key)) {
$is_disabled = true;
}
}
$field['is_disabled'] = $is_disabled;
$field['is_invisible'] = $is_invisible;
$field['required'] = isset($field['required']) ? $field['required'] : $this->required;
if ($field['type'] == 'color') {
$this->context->controller->addJqueryPlugin('colorpicker');
}
if ($field['type'] == 'textarea' || $field['type'] == 'textareaLang') {
if (isset($field['autoload_rte']) && $field['autoload_rte'] == true) {
$iso = $this->context->language->iso_code;
$this->tpl_vars['iso'] = file_exists(_PS_CORE_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en';
$this->tpl_vars['path_css'] = _THEME_CSS_DIR_;
$this->tpl_vars['ad'] = __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_);
$this->tpl_vars['tinymce'] = true;
$this->context->controller->addJS(_PS_JS_DIR_ . 'tiny_mce/tiny_mce.js');
$this->context->controller->addJS(_PS_JS_DIR_ . 'admin/tinymce.inc.js');
} else {
$this->context->controller->addJqueryPlugin('autosize');
}
}
if ($field['type'] == 'file') {
$uploader = new HelperUploader();
$uploader->setId(isset($field['id']) ? $field['id'] : null);
$uploader->setName($field['name']);
$uploader->setUrl(isset($field['url']) ? $field['url'] : null);
$uploader->setMultiple(isset($field['multiple']) ? $field['multiple'] : false);
$uploader->setUseAjax(isset($field['ajax']) ? $field['ajax'] : false);
$uploader->setMaxFiles(isset($field['max_files']) ? $field['max_files'] : null);
if (isset($field['files']) && $field['files']) {
$uploader->setFiles($field['files']);
} elseif (isset($field['image']) && $field['image']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_IMAGE,
'image' => isset($field['image']) ? $field['image'] : null,
'size' => isset($field['size']) ? $field['size'] : null,
'delete_url' => isset($field['delete_url']) ? $field['delete_url'] : null,
),
));
}
if (isset($field['file']) && $field['file']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_FILE,
'size' => isset($field['size']) ? $field['size'] : null,
'delete_url' => isset($field['delete_url']) ? $field['delete_url'] : null,
'download_url' => isset($field['file']) ? $field['file'] : null,
),
));
}
if (isset($field['thumb']) && $field['thumb']) { // Use for retrocompatibility
$uploader->setFiles(array(
0 => array(
'type' => HelperUploader::TYPE_IMAGE,
'image' => isset($field['thumb']) ? '<img src="' . $field['thumb'] . '" alt="' . $field['title'] . '" title="' . $field['title'] . '" />' : null,
),
));
}
$uploader->setTitle(isset($field['title']) ? $field['title'] : null);
$field['file'] = $uploader->render();
}
// Cast options values if specified
if ($field['type'] == 'select' && isset($field['cast'])) {
foreach ($field['list'] as $option_key => $option) {
$field['list'][$option_key][$field['identifier']] = $field['cast']($option[$field['identifier']]);
}
}
// Fill values for all languages for all lang fields
if (substr($field['type'], -4) == 'Lang') {
$field['value'] = array();
foreach ($languages as $language) {
if ($field['type'] == 'textLang') {
$value = Tools::getValue($key . '_' . $language['id_lang'], Configuration::get($key, $language['id_lang']));
} elseif ($field['type'] == 'textareaLang') {
$value = Configuration::get($key, $language['id_lang']);
} elseif ($field['type'] == 'selectLang') {
$value = Configuration::get($key, $language['id_lang']);
}
if (isset($value)) {
$field['languages'][$language['id_lang']] = $value;
} else {
$field['languages'][$language['id_lang']] = '';
}
$field['value'][$language['id_lang']] = $this->getOptionValue($key . '_' . strtoupper($language['iso_code']), $field);
}
}
// pre-assign vars to the tpl
// @todo move this
if ($field['type'] == 'maintenance_ip') {
$field['script_ip'] = '
<script type="text/javascript">
function addRemoteAddr()
{
var length = $(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\').length;
if (length > 0) {
if ($(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\').indexOf(\'' . Tools::getRemoteAddr() . '\') < 0) {
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\') +\',' . Tools::getRemoteAddr() . '\');
}
} else {
$(\'input[name=PS_MAINTENANCE_IP]\').attr(\'value\',\'' . Tools::getRemoteAddr() . '\');
}
}
</script>';
$field['link_remove_ip'] = '<button type="button" class="btn btn-default" onclick="addRemoteAddr();"><i class="icon-plus"></i> ' . $this->l('Add my IP', 'Helper') . '</button>';
}
// Multishop default value
$field['multishop_default'] = false;
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$is_invisible) {
$field['multishop_default'] = true;
$use_multishop = true;
}
// Assign the modifications back to parent array
$category_data['fields'][$key] = $field;
// Is at least one required field present?
if (isset($field['required']) && $field['required']) {
$category_data['required_fields'] = true;
}
}
// Assign the modifications back to parent array
$option_list[$category] = $category_data;
}
$this->tpl->assign(array(
'title' => $this->title,
'toolbar_btn' => $this->toolbar_btn,
'show_toolbar' => $this->show_toolbar,
'toolbar_scroll' => $this->toolbar_scroll,
'current' => $this->currentIndex,
'table' => $this->table,
'token' => $this->token,
'tabs' => (isset($tabs)) ? $tabs : null,
'option_list' => $option_list,
'current_id_lang' => $this->context->language->id,
'languages' => isset($languages) ? $languages : null,
'currency_left_sign' => $this->context->currency->getSign('left'),
'currency_right_sign' => $this->context->currency->getSign('right'),
'use_multishop' => $use_multishop,
));
return parent::generate();
}
/**
* Type = image.
*/
public function displayOptionTypeImage($key, $field, $value)
{
echo '<table cellspacing="0" cellpadding="0">';
echo '<tr>';
$i = 0;
foreach ($field['list'] as $theme) {
echo '<td class="center" style="width: 180px; padding:0px 20px 20px 0px;">';
echo '<input type="radio" name="' . $key . '" id="' . $key . '_' . $theme['name'] . '_on" style="vertical-align: text-bottom;" value="' . $theme['name'] . '"' . (_THEME_NAME_ == $theme['name'] ? 'checked="checked"' : '') . ' />';
echo '<label class="t" for="' . $key . '_' . $theme['name'] . '_on"> ' . Tools::strtolower($theme['name']) . '</label>';
echo '<br />';
echo '<label class="t" for="' . $key . '_' . $theme['name'] . '_on">';
echo '<img src="' . $theme['preview'] . '" alt="' . Tools::strtolower($theme['name']) . '">';
echo '</label>';
echo '</td>';
if (isset($field['max']) && ($i + 1) % $field['max'] == 0) {
echo '</tr><tr>';
}
++$i;
}
echo '</tr>';
echo '</table>';
}
/**
* Type = price.
*/
public function displayOptionTypePrice($key, $field, $value)
{
echo $this->context->currency->getSign('left');
$this->displayOptionTypeText($key, $field, $value);
echo $this->context->currency->getSign('right') . ' ' . $this->l('(tax excl.)', 'Helper');
}
/**
* Type = disabled.
*/
public function displayOptionTypeDisabled($key, $field, $value)
{
echo $field['disabled'];
}
public function getOptionValue($key, $field)
{
$value = Tools::getValue($key, Configuration::get($key));
if (!Validate::isCleanHtml($value)) {
$value = Configuration::get($key);
}
if (isset($field['defaultValue']) && !$value) {
$value = $field['defaultValue'];
}
return Tools::purifyHTML($value);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperShopCore extends Helper
{
/**
* Render shop list.
*
* @return string
*/
public function getRenderedShopList()
{
if (!Shop::isFeatureActive() || Shop::getTotalShops(false, null) < 2) {
return '';
}
$shop_context = Shop::getContext();
$context = Context::getContext();
if ($this->noShopSelection()) {
$current_shop_value = '';
} elseif ($shop_context == Shop::CONTEXT_GROUP) {
$current_shop_value = 'g-' . Shop::getContextShopGroupID();
} else {
$current_shop_value = 's-' . Shop::getContextShopID();
}
$tpl = $this->createTemplate('helpers/shops_list/list.tpl');
$tpl->assign(array(
'link' => $context->link,
'tree' => Shop::getTree(),
'current_shop_name' => $this->getCurrentShopName(),
'current_shop_value' => $current_shop_value,
'multishop_context' => $context->controller->multishop_context,
'multishop_context_group' => $context->controller->multishop_context_group,
'is_shop_context' => ($context->controller->multishop_context & Shop::CONTEXT_SHOP),
'is_group_context' => ($context->controller->multishop_context & Shop::CONTEXT_GROUP),
'is_all_context' => ($context->controller->multishop_context & Shop::CONTEXT_ALL),
'shop_context' => $shop_context,
'url' => $_SERVER['REQUEST_URI'] . (($_SERVER['QUERY_STRING']) ? '&' : '?') . 'setShopContext=',
));
return $tpl->fetch();
}
public function getCurrentShopName()
{
$shop_context = Shop::getContext();
$tree = Shop::getTree();
if ($this->noShopSelection()) {
$current_shop_name = Translate::getAdminTranslation('All shops');
} elseif ($shop_context == Shop::CONTEXT_GROUP) {
$current_shop_name = sprintf(Translate::getAdminTranslation('%s group'), $tree[Shop::getContextShopGroupID()]['name']);
} else {
foreach ($tree as $group_data) {
foreach ($group_data['shops'] as $shop_id => $shop_data) {
if ($shop_id == Shop::getContextShopID()) {
$current_shop_name = $shop_data['name'];
break;
}
}
}
}
return $current_shop_name;
}
/**
* @return bool
*/
protected function noShopSelection()
{
$shop_context = Shop::getContext();
$context = Context::getContext();
return $shop_context == Shop::CONTEXT_ALL ||
($context->controller->multishop_context_group == false && $shop_context == Shop::CONTEXT_GROUP);
}
}

View File

@@ -0,0 +1,492 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeCategoriesCore extends TreeCore
{
const DEFAULT_TEMPLATE = 'tree_categories.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_radio.tpl';
private $_disabled_categories;
private $_input_name;
private $_lang;
private $_root_category;
private $_selected_categories;
private $_full_tree = false;
private $_shop;
private $_use_checkbox;
private $_use_search;
private $_use_shop_restriction;
private $_children_only = false;
public function __construct(
$id,
$title = null,
$root_category = null,
$lang = null,
$use_shop_restriction = true
) {
parent::__construct($id);
if (isset($title)) {
$this->setTitle($title);
}
if (isset($root_category)) {
$this->setRootCategory($root_category);
}
$this->setLang($lang);
$this->setUseShopRestriction($use_shop_restriction);
}
private function fillTree(&$categories, $rootCategoryId)
{
$tree = array();
$rootCategoryId = (int) $rootCategoryId;
foreach ($categories[$rootCategoryId] as $category) {
$categoryId = (int) $category['id_category'];
$tree[$categoryId] = $category;
if (Category::hasChildren($categoryId, $this->getLang(), false, $this->getShop()->id)) {
$categoryChildren = Category::getChildren(
$categoryId,
$this->getLang(),
false,
$this->getShop()->id
);
foreach ($categoryChildren as $child) {
$childId = (int) $child['id_category'];
if (!array_key_exists('children', $tree[$categoryId])) {
$tree[$categoryId]['children'] = array($childId => $child);
} else {
$tree[$categoryId]['children'][$childId] = $child;
}
$categories[$childId] = array($child);
}
foreach ($tree[$categoryId]['children'] as $childId => $child) {
$subtree = $this->fillTree($categories, $childId);
foreach ($subtree as $subcategoryId => $subcategory) {
$tree[$categoryId]['children'][$subcategoryId] = $subcategory;
}
}
}
}
return $tree;
}
public function getData()
{
if (!isset($this->_data)) {
$shop = $this->getShop();
$lang = $this->getLang();
$root_category = (int) $this->getRootCategory();
if ($this->_full_tree) {
$this->setData(Category::getNestedCategories($root_category, $lang, false, null, $this->useShopRestriction()));
$this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
} elseif ($this->_children_only) {
if (empty($root_category)) {
$root_category = Category::getRootCategory()->id;
}
$categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id);
$children = $this->fillTree($categories, $root_category);
$this->setData($children);
} else {
if (empty($root_category)) {
$root_category = Category::getRootCategory()->id;
}
$new_selected_categories = array();
$selected_categories = $this->getSelectedCategories();
$categories[$root_category] = Category::getChildren($root_category, $lang, false, $shop->id);
foreach ($selected_categories as $selected_category) {
$category = new Category($selected_category, $lang, $shop->id);
$new_selected_categories[] = $selected_category;
$parents = $category->getParentsCategories($lang);
foreach ($parents as $value) {
$new_selected_categories[] = $value['id_category'];
}
}
$new_selected_categories = array_unique($new_selected_categories);
foreach ($new_selected_categories as $selected_category) {
$current_category = Category::getChildren($selected_category, $lang, false, $shop->id);
if (!empty($current_category)) {
$categories[$selected_category] = $current_category;
}
}
$tree = Category::getCategoryInformations(array($root_category), $lang);
$children = $this->fillTree($categories, $root_category);
if (!empty($children)) {
$tree[$root_category]['children'] = $children;
}
$this->setData($tree);
$this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
}
}
return $this->_data;
}
public function setChildrenOnly($value)
{
$this->_children_only = $value;
return $this;
}
public function setFullTree($value)
{
$this->_full_tree = $value;
return $this;
}
public function getFullTree()
{
return $this->_full_tree;
}
public function setDisabledCategories($value)
{
$this->_disabled_categories = $value;
return $this;
}
public function getDisabledCategories()
{
return $this->_disabled_categories;
}
public function setInputName($value)
{
$this->_input_name = $value;
return $this;
}
public function getInputName()
{
if (!isset($this->_input_name)) {
$this->setInputName('categoryBox');
}
return $this->_input_name;
}
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
public function getLang()
{
if (!isset($this->_lang)) {
$this->setLang($this->getContext()->employee->id_lang);
}
return $this->_lang;
}
public function getNodeFolderTemplate()
{
if (!isset($this->_node_folder_template)) {
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
}
return $this->_node_folder_template;
}
public function getNodeItemTemplate()
{
if (!isset($this->_node_item_template)) {
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
}
return $this->_node_item_template;
}
public function setRootCategory($value)
{
if (!Validate::isInt($value)) {
throw new PrestaShopException('Root category must be an integer value');
}
$this->_root_category = $value;
return $this;
}
public function getRootCategory()
{
return $this->_root_category;
}
public function setSelectedCategories($value)
{
if (!is_array($value)) {
throw new PrestaShopException('Selected categories value must be an array');
}
$this->_selected_categories = $value;
return $this;
}
public function getSelectedCategories()
{
if (!isset($this->_selected_categories)) {
$this->_selected_categories = array();
}
return $this->_selected_categories;
}
public function setShop($value)
{
$this->_shop = $value;
return $this;
}
public function getShop()
{
if (!isset($this->_shop)) {
if (Tools::isSubmit('id_shop')) {
$this->setShop(new Shop(Tools::getValue('id_shop')));
} elseif ($this->getContext()->shop->id) {
$this->setShop(new Shop($this->getContext()->shop->id));
} elseif (!Shop::isFeatureActive()) {
$this->setShop(new Shop(Configuration::get('PS_SHOP_DEFAULT')));
} else {
$this->setShop(new Shop(0));
}
}
return $this->_shop;
}
public function getTemplate()
{
if (!isset($this->_template)) {
$this->setTemplate(self::DEFAULT_TEMPLATE);
}
return $this->_template;
}
public function setUseCheckBox($value)
{
$this->_use_checkbox = (bool) $value;
return $this;
}
public function setUseSearch($value)
{
$this->_use_search = (bool) $value;
return $this;
}
public function setUseShopRestriction($value)
{
$this->_use_shop_restriction = (bool) $value;
return $this;
}
public function useCheckBox()
{
return isset($this->_use_checkbox) && $this->_use_checkbox;
}
public function useSearch()
{
return isset($this->_use_search) && $this->_use_search;
}
public function useShopRestriction()
{
return isset($this->_use_shop_restriction) && $this->_use_shop_restriction;
}
public function render($data = null)
{
if (!isset($data)) {
$data = $this->getData();
}
if (isset($this->_disabled_categories)
&& !empty($this->_disabled_categories)) {
$this->_disableCategories($data, $this->getDisabledCategories());
}
if (isset($this->_selected_categories)
&& !empty($this->_selected_categories)) {
$this->_getSelectedChildNumbers($data, $this->getSelectedCategories());
}
//Default bootstrap style of search is push-right, so we add this button first
if ($this->useSearch()) {
$this->addAction(new TreeToolbarSearchCategories(
'Find a category:',
$this->getId() . '-categories-search'
));
$this->setAttribute('use_search', $this->useSearch());
}
$collapse_all = new TreeToolbarLink(
'Collapse All',
'#',
'$(\'#' . $this->getId() . '\').tree(\'collapseAll\');$(\'#collapse-all-' . $this->getId() . '\').hide();$(\'#expand-all-' . $this->getId() . '\').show(); return false;',
'icon-collapse-alt'
);
$collapse_all->setAttribute('id', 'collapse-all-' . $this->getId());
$expand_all = new TreeToolbarLink(
'Expand All',
'#',
'$(\'#' . $this->getId() . '\').tree(\'expandAll\');$(\'#collapse-all-' . $this->getId() . '\').show();$(\'#expand-all-' . $this->getId() . '\').hide(); return false;',
'icon-expand-alt'
);
$expand_all->setAttribute('id', 'expand-all-' . $this->getId());
$this->addAction($collapse_all);
$this->addAction($expand_all);
if ($this->useCheckBox()) {
$check_all = new TreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedCategories($(\'#' . $this->getId() . '\')); return false;',
'icon-check-sign'
);
$check_all->setAttribute('id', 'check-all-' . $this->getId());
$uncheck_all = new TreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedCategories($(\'#' . $this->getId() . '\')); return false;',
'icon-check-empty'
);
$uncheck_all->setAttribute('id', 'uncheck-all-' . $this->getId());
$this->addAction($check_all);
$this->addAction($uncheck_all);
$this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl');
$this->setNodeItemTemplate('tree_node_item_checkbox.tpl');
$this->setAttribute('use_checkbox', $this->useCheckBox());
}
$this->setAttribute('selected_categories', $this->getSelectedCategories());
$this->getContext()->smarty->assign('root_category', Configuration::get('PS_ROOT_CATEGORY'));
$this->getContext()->smarty->assign('token', Tools::getAdminTokenLite('AdminProducts'));
return parent::render($data);
}
/* Override */
public function renderNodes($data = null)
{
if (!isset($data)) {
$data = $this->getData();
}
if (!is_array($data) && !$data instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$html = '';
foreach ($data as $item) {
if (is_array($item) && array_key_exists('children', $item)
&& !empty($item['children'])) {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeFolderTemplate()),
$this->getContext()->smarty
)->assign(array(
'input_name' => $this->getInputName(),
'children' => $this->renderNodes($item['children']),
'node' => $item,
))->fetch();
} else {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeItemTemplate()),
$this->getContext()->smarty
)->assign(array(
'input_name' => $this->getInputName(),
'node' => $item,
))->fetch();
}
}
return $html;
}
private function _disableCategories(&$categories, $disabled_categories = null)
{
foreach ($categories as &$category) {
if (!isset($disabled_categories) || in_array($category['id_category'], $disabled_categories)) {
$category['disabled'] = true;
if (array_key_exists('children', $category) && is_array($category['children'])) {
self::_disableCategories($category['children']);
}
} elseif (array_key_exists('children', $category) && is_array($category['children'])) {
self::_disableCategories($category['children'], $disabled_categories);
}
}
}
private function _getSelectedChildNumbers(&$categories, $selected, &$parent = null)
{
$selected_childs = 0;
foreach ($categories as $key => &$category) {
if (isset($parent) && in_array($category['id_category'], $selected)) {
++$selected_childs;
}
if (isset($category['children']) && !empty($category['children'])) {
$selected_childs += $this->_getSelectedChildNumbers($category['children'], $selected, $category);
}
}
if (!isset($parent['selected_childs'])) {
$parent['selected_childs'] = 0;
}
$parent['selected_childs'] = $selected_childs;
return $selected_childs;
}
}

View File

@@ -0,0 +1,194 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeShopsCore extends TreeCore
{
const DEFAULT_TEMPLATE = 'tree_shops.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_checkbox_shops.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_checkbox_shops.tpl';
private $_lang;
private $_selected_shops;
public function __construct($id, $title = null, $lang = null)
{
parent::__construct($id);
if (isset($title)) {
$this->setTitle($title);
}
$this->setLang($lang);
}
public function getData()
{
if (!isset($this->_data)) {
$this->setData(Shop::getTree());
}
return $this->_data;
}
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
public function getLang()
{
if (!isset($this->_lang)) {
$this->setLang($this->getContext()->employee->id_lang);
}
return $this->_lang;
}
public function getNodeFolderTemplate()
{
if (!isset($this->_node_folder_template)) {
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
}
return $this->_node_folder_template;
}
public function getNodeItemTemplate()
{
if (!isset($this->_node_item_template)) {
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
}
return $this->_node_item_template;
}
public function setSelectedShops($value)
{
if (!is_array($value)) {
throw new PrestaShopException('Selected shops value must be an array');
}
$this->_selected_shops = $value;
return $this;
}
public function getSelectedShops()
{
if (!isset($this->_selected_shops)) {
$this->_selected_shops = array();
}
return $this->_selected_shops;
}
public function getTemplate()
{
if (!isset($this->_template)) {
$this->setTemplate(self::DEFAULT_TEMPLATE);
}
return $this->_template;
}
public function render($data = null, $use_default_actions = true, $use_selected_shop = true)
{
if (!isset($data)) {
$data = $this->getData();
}
if ($use_default_actions) {
$this->setActions(array(
new TreeToolbarLink(
'Collapse All',
'#',
'$(\'#' . $this->getId() . '\').tree(\'collapseAll\'); return false;',
'icon-collapse-alt'
),
new TreeToolbarLink(
'Expand All',
'#',
'$(\'#' . $this->getId() . '\').tree(\'expandAll\'); return false;',
'icon-expand-alt'
),
new TreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedShops($(\'#' . $this->getId() . '\')); return false;',
'icon-check-sign'
),
new TreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedShops($(\'#' . $this->getId() . '\')); return false;',
'icon-check-empty'
),
));
}
if ($use_selected_shop) {
$this->setAttribute('selected_shops', $this->getSelectedShops());
}
return parent::render($data);
}
public function renderNodes($data = null)
{
if (!isset($data)) {
$data = $this->getData();
}
if (!is_array($data) && !$data instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$html = '';
foreach ($data as $item) {
if (array_key_exists('shops', $item)
&& !empty($item['shops'])) {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeFolderTemplate()),
$this->getContext()->smarty
)->assign($this->getAttributes())->assign(array(
'children' => $this->renderNodes($item['shops']),
'node' => $item,
))->fetch();
} else {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeItemTemplate()),
$this->getContext()->smarty
)->assign($this->getAttributes())->assign(array(
'node' => $item,
))->fetch();
}
}
return $html;
}
}

View File

@@ -0,0 +1,309 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperUploaderCore extends Uploader
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/uploader';
const DEFAULT_TEMPLATE = 'simple.tpl';
const DEFAULT_AJAX_TEMPLATE = 'ajax.tpl';
const TYPE_IMAGE = 'image';
const TYPE_FILE = 'file';
private $_context;
private $_drop_zone;
private $_id;
private $_files;
private $_name;
private $_max_files;
private $_multiple;
private $_post_max_size;
protected $_template;
private $_template_directory;
private $_title;
private $_url;
private $_use_ajax;
public function setContext($value)
{
$this->_context = $value;
return $this;
}
public function getContext()
{
if (!isset($this->_context)) {
$this->_context = Context::getContext();
}
return $this->_context;
}
public function setDropZone($value)
{
$this->_drop_zone = $value;
return $this;
}
public function getDropZone()
{
if (!isset($this->_drop_zone)) {
$this->setDropZone("$('#" . $this->getId() . "-add-button')");
}
return $this->_drop_zone;
}
public function setId($value)
{
$this->_id = (string) $value;
return $this;
}
public function getId()
{
if (!isset($this->_id) || trim($this->_id) === '') {
$this->_id = $this->getName();
}
return $this->_id;
}
public function setFiles($value)
{
$this->_files = $value;
return $this;
}
public function getFiles()
{
if (!isset($this->_files)) {
$this->_files = array();
}
return $this->_files;
}
public function setMaxFiles($value)
{
$this->_max_files = isset($value) ? (int) $value : $value;
return $this;
}
public function getMaxFiles()
{
return $this->_max_files;
}
public function setMultiple($value)
{
$this->_multiple = (bool) $value;
return $this;
}
public function setName($value)
{
$this->_name = (string) $value;
return $this;
}
public function getName()
{
return $this->_name;
}
public function setPostMaxSize($value)
{
$this->_post_max_size = $value;
$this->setMaxSize($value);
return $this;
}
public function getPostMaxSize()
{
if (!isset($this->_post_max_size)) {
$this->_post_max_size = parent::getPostMaxSize();
}
return $this->_post_max_size;
}
public function setTemplate($value)
{
$this->_template = $value;
return $this;
}
public function getTemplate()
{
if (!isset($this->_template)) {
$this->setTemplate(self::DEFAULT_TEMPLATE);
}
return $this->_template;
}
public function setTemplateDirectory($value)
{
$this->_template_directory = $value;
return $this;
}
public function getTemplateDirectory()
{
if (!isset($this->_template_directory)) {
$this->_template_directory = self::DEFAULT_TEMPLATE_DIRECTORY;
}
return $this->_normalizeDirectory($this->_template_directory);
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== false) {
$controller_name = strtolower($matches[0][1]);
}
if ($this->getContext()->controller instanceof ModuleAdminController
&& file_exists($this->_normalizeDirectory($this->getContext()->controller->getTemplatePath()) . $this->getTemplateDirectory() . $template)
) {
return $this->_normalizeDirectory($this->getContext()->controller->getTemplatePath())
. $this->getTemplateDirectory() . $template;
} elseif ($this->getContext()->controller instanceof AdminController && isset($controller_name)
&& file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template;
} else {
return $this->getTemplateDirectory() . $template;
}
}
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function setUrl($value)
{
$this->_url = (string) $value;
return $this;
}
public function getUrl()
{
return $this->_url;
}
public function setUseAjax($value)
{
$this->_use_ajax = (bool) $value;
return $this;
}
public function isMultiple()
{
return isset($this->_multiple) && $this->_multiple;
}
public function render()
{
$admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_ . $bo_theme . DIRECTORY_SEPARATOR
. 'template')) {
$bo_theme = 'default';
}
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/jquery.iframe-transport.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/jquery.fileupload.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/jquery.fileupload-process.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath
. '/themes/' . $bo_theme . '/js/jquery.fileupload-validate.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__ . 'js/vendor/spin.js');
$this->getContext()->controller->addJs(__PS_BASE_URI__ . 'js/vendor/ladda.js');
if ($this->useAjax() && !isset($this->_template)) {
$this->setTemplate(self::DEFAULT_AJAX_TEMPLATE);
}
$template = $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()),
$this->getContext()->smarty
);
$template->assign(array(
'id' => $this->getId(),
'name' => $this->getName(),
'url' => $this->getUrl(),
'multiple' => $this->isMultiple(),
'files' => $this->getFiles(),
'title' => $this->getTitle(),
'max_files' => $this->getMaxFiles(),
'post_max_size' => $this->getPostMaxSizeBytes(),
'drop_zone' => $this->getDropZone(),
));
return $template->fetch();
}
public function useAjax()
{
return isset($this->_use_ajax) && $this->_use_ajax;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperViewCore extends Helper
{
public $id;
public $toolbar = true;
public $table;
public $token;
/** @var string|null If not null, a title will be added on that list */
public $title = null;
public function __construct()
{
$this->base_folder = 'helpers/view/';
$this->base_tpl = 'view.tpl';
parent::__construct();
}
public function generateView()
{
$this->tpl = $this->createTemplate($this->base_tpl);
$this->tpl->assign(array(
'title' => $this->title,
'current' => $this->currentIndex,
'token' => $this->token,
'table' => $this->table,
'show_toolbar' => $this->show_toolbar,
'toolbar_scroll' => $this->toolbar_scroll,
'toolbar_btn' => $this->toolbar_btn,
'link' => $this->context->link,
));
return parent::generate();
}
}

34
classes/helper/index.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../');
exit;