/classes/controller/AdminController.php
PHP | 3861 lines | 2880 code | 475 blank | 506 comment | 763 complexity | 6366fbe0beb391373768ff6c94a464ae MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * 2007-2014 PrestaShop
- *
- * 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:
- * http://opensource.org/licenses/osl-3.0.php
- * 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 http://www.prestashop.com for more information.
- *
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2014 PrestaShop SA
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * International Registered Trademark & Property of PrestaShop SA
- */
- class AdminControllerCore extends Controller
- {
- public $path;
- public static $currentIndex;
- public $content;
- public $warnings = array();
- public $informations = array();
- public $confirmations = array();
- public $shopShareDatas = false;
-
- public $_languages = array();
- public $default_form_language;
- public $allow_employee_form_lang;
- public $layout = 'layout.tpl';
- public $bootstrap = false ;
- protected $meta_title;
- public $template = 'content.tpl';
- /** @var string Associated table name */
- public $table = 'configuration';
- public $list_id;
- /** @var string Object identifier inside the associated table */
- protected $identifier = false;
- protected $identifier_name = 'name';
- /** @var string Tab name */
- public $className;
- /** @var array tabAccess */
- public $tabAccess;
- /** @var integer Tab id */
- public $id = -1;
- public $required_database = false;
- /** @var string Security token */
- public $token;
- /** @var string shop | group_shop */
- public $shopLinkType;
- /** @var string Default ORDER BY clause when $_orderBy is not defined */
- protected $_defaultOrderBy = false;
- protected $_defaultOrderWay = 'ASC';
- public $tpl_form_vars = array();
- public $tpl_list_vars = array();
- public $tpl_delete_link_vars = array();
- public $tpl_option_vars = array();
- public $tpl_view_vars = array();
- public $tpl_required_fields_vars = array();
- public $base_tpl_view = null;
- public $base_tpl_form = null;
- /** @var bool if you want more fieldsets in the form */
- public $multiple_fieldsets = false;
- public $fields_value = false;
- /** @var array Errors displayed after post processing */
- public $errors = array();
- /** @var define if the header of the list contains filter and sorting links or not */
- protected $list_simple_header;
- /** @var array list to be generated */
- protected $fields_list;
-
- /** @var array modules list filters */
- protected $filter_modules_list = null;
-
- /** @var array modules list filters */
- protected $modules_list = array();
-
- /** @var array edit form to be generated */
- protected $fields_form;
- /** @var override of $fields_form */
- protected $fields_form_override;
-
- /** @var override form action */
- protected $submit_action;
- /** @var array list of option forms to be generated */
- protected $fields_options = array();
- protected $shopLink;
- /** @var string SQL query */
- protected $_listsql = '';
- /** @var array Cache for query results */
- protected $_list = array();
- /** @var define if the header of the list contains filter and sorting links or not */
- protected $toolbar_title;
- /** @var array list of toolbar buttons */
- protected $toolbar_btn = null;
- /** @var boolean scrolling toolbar */
- protected $toolbar_scroll = true;
- /** @var boolean set to false to hide toolbar and page title */
- protected $show_toolbar = true;
- /** @var boolean set to true to show toolbar and page title for options */
- protected $show_toolbar_options = false;
- /** @var integer Number of results in list */
- protected $_listTotal = 0;
- /** @var boolean Automatically join language table if true */
- public $lang = false;
- /** @var array WHERE clause determined by filter fields */
- protected $_filter;
- /** @var array Temporary SQL table WHERE clause determinated by filter fields */
- protected $_tmpTableFilter = '';
- /** @var array Number of results in list per page (used in select field) */
- protected $_pagination = array(20, 50, 100, 300, 1000);
- /** @var integer Default number of results in list per page */
- protected $_default_pagination = 50;
- /** @var string ORDER BY clause determined by field/arrows in list header */
- protected $_orderBy;
- /** @var string Order way (ASC, DESC) determined by arrows in list header */
- protected $_orderWay;
- /** @var array list of available actions for each list row - default actions are view, edit, delete, duplicate */
- protected $actions_available = array('view', 'edit', 'duplicate', 'delete');
- /** @var array list of required actions for each list row */
- protected $actions = array();
- /** @var array list of row ids associated with a given action for witch this action have to not be available */
- protected $list_skip_actions = array();
- /* @var boolean don't show header & footer */
- protected $lite_display = false;
- /** @var bool boolean List content lines are clickable if true */
- protected $list_no_link = false;
- protected $allow_export = false;
- /** @var array $cache_lang cache for traduction */
- public static $cache_lang = array();
- /** @var array required_fields to display in the Required Fields form */
- public $required_fields = array();
-
- /** @var Helper */
- protected $helper;
- /**
- * @var array actions to execute on multiple selections
- * Usage:
- * array(
- * 'actionName' => array(
- * 'text' => $this->l('Message displayed on the submit button (mandatory)'),
- * 'confirm' => $this->l('If set, this confirmation message will pop-up (optional)')),
- * 'anotherAction' => array(...)
- * );
- *
- * If your action is named 'actionName', you need to have a method named bulkactionName() that will be executed when the button is clicked.
- */
- protected $bulk_actions;
- /**
- * @var array ids of the rows selected
- */
- protected $boxes;
-
- /** @var string Do not automatically select * anymore but select only what is necessary */
- protected $explicitSelect = false;
- /** @var string Add fields into data query to display list */
- protected $_select;
- /** @var string Join tables into data query to display list */
- protected $_join;
- /** @var string Add conditions into data query to display list */
- protected $_where;
- /** @var string Group rows into data query to display list */
- protected $_group;
- /** @var string Having rows into data query to display list */
- protected $_having;
- protected $is_cms = false;
- /** @var string identifier to use for changing positions in lists (can be omitted if positions cannot be changed) */
- protected $position_identifier;
- protected $position_group_identifier;
- /** @var boolean Table records are not deleted but marked as deleted if set to true */
- protected $deleted = false;
- /**
- * @var bool is a list filter set
- */
- protected $filter;
- protected $noLink;
- protected $specificConfirmDelete = null;
- protected $colorOnBackground;
- /** @var bool If true, activates color on hover */
- protected $row_hover = true;
- /** @string Action to perform : 'edit', 'view', 'add', ... */
- protected $action;
- protected $display;
- protected $_includeContainer = true;
- protected $tab_modules_list = array('default_list' => array(), 'slider_list' => array());
- public $tpl_folder;
- protected $bo_theme;
- /** @var bool Redirect or not ater a creation */
- protected $_redirect = true;
- /** @var array Name and directory where class image are located */
- public $fieldImageSettings = array();
- /** @var string Image type */
- public $imageType = 'jpg';
- /** @var instanciation of the class associated with the AdminController */
- protected $object;
- /** @var int current object ID */
- protected $id_object;
- /**
- * @var current controller name without suffix
- */
- public $controller_name;
- public $multishop_context = -1;
- public $multishop_context_group = true;
- /**
- * Current breadcrumb position as an array of tab names
- */
- protected $breadcrumbs;
- //Bootstrap variable
- public $show_page_header_toolbar = false;
- public $page_header_toolbar_title;
- public $page_header_toolbar_btn = array();
- public $show_form_cancel_button;
- public $admin_webpath;
-
- protected $list_natives_modules = array();
- protected $list_partners_modules = array();
-
- public $modals = array();
-
- protected $logged_on_addons = false;
-
- public function __construct()
- {
- global $timer_start;
- $this->timer_start = $timer_start;
- // Has to be remove for the next Prestashop version
- global $token;
- $this->controller_type = 'admin';
- $this->controller_name = get_class($this);
- if (strpos($this->controller_name, 'Controller'))
- $this->controller_name = substr($this->controller_name, 0, -10);
- parent::__construct();
- if ($this->multishop_context == -1)
- $this->multishop_context = Shop::CONTEXT_ALL | Shop::CONTEXT_GROUP | Shop::CONTEXT_SHOP;
- $this->bo_theme = ((Validate::isLoadedObject($this->context->employee) && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default');
- if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$this->bo_theme.DIRECTORY_SEPARATOR.'template'))
- $this->bo_theme = 'default';
- $this->bo_css = ((Validate::isLoadedObject($this->context->employee) && $this->context->employee->bo_css) ? $this->context->employee->bo_css : 'admin-theme.css');
- if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$this->bo_theme.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.$this->bo_css))
- $this->bo_css = 'admin-theme.css';
- $this->context->smarty->setTemplateDir(array(
- _PS_BO_ALL_THEMES_DIR_.$this->bo_theme.DIRECTORY_SEPARATOR.'template',
- _PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates'
- ));
- $this->id = Tab::getIdFromClassName($this->controller_name);
- $this->token = Tools::getAdminToken($this->controller_name.(int)$this->id.(int)$this->context->employee->id);
- $token = $this->token;
- $this->_conf = array(
- 1 => $this->l('Successful deletion'),
- 2 => $this->l('The selection has been successfully deleted.'),
- 3 => $this->l('Successful creation'),
- 4 => $this->l('Successful update'),
- 5 => $this->l('The status has been successfully updated.'),
- 6 => $this->l('The settings have been successfully updated.'),
- 7 => $this->l('The image was successfully deleted.'),
- 8 => $this->l('The module was successfully downloaded.'),
- 9 => $this->l('The thumbnails were successfully regenerated.'),
- 10 => $this->l('The message was successfully sent to the customer.'),
- 11 => $this->l('Comment successfully added'),
- 12 => $this->l('Module(s) installed successfully.'),
- 13 => $this->l('Module(s) uninstalled successfully.'),
- 14 => $this->l('The translation was successfully copied.'),
- 15 => $this->l('The translations have been successfully added.'),
- 16 => $this->l('The module transplanted successfully to the hook.'),
- 17 => $this->l('The module was successfully removed from the hook.'),
- 18 => $this->l('Successful upload'),
- 19 => $this->l('Duplication was completed successfully.'),
- 20 => $this->l('The translation was added successfully, but the language has not been created.'),
- 21 => $this->l('Module reset successfully.'),
- 22 => $this->l('Module deleted successfully.'),
- 23 => $this->l('Localization pack imported successfully.'),
- 24 => $this->l('Localization pack imported successfully.'),
- 25 => $this->l('The selected images have successfully been moved.'),
- 26 => $this->l('Your cover image selection has been saved.'),
- 27 => $this->l('The image\'s shop association has been modified.'),
- 28 => $this->l('A zone has been assigned to the selection successfully.'),
- 29 => $this->l('Successful upgrade'),
- 30 => $this->l('A partial refund was successfully created.'),
- 31 => $this->l('The discount was successfully generated.'),
- 32 => $this->l('Successfully signed in to PrestaShop Addons')
- );
- if (!$this->identifier) $this->identifier = 'id_'.$this->table;
- if (!$this->_defaultOrderBy) $this->_defaultOrderBy = $this->identifier;
- $this->tabAccess = Profile::getProfileAccess($this->context->employee->id_profile, $this->id);
- // Fix for homepage
- if ($this->controller_name == 'AdminDashboard')
- $_POST['token'] = $this->token;
- if (!Shop::isFeatureActive())
- $this->shopLinkType = '';
- //$this->base_template_folder = _PS_BO_ALL_THEMES_DIR_.$this->bo_theme.'/template';
- $this->override_folder = Tools::toUnderscoreCase(substr($this->controller_name, 5)).'/';
- // Get the name of the folder containing the custom tpl files
- $this->tpl_folder = Tools::toUnderscoreCase(substr($this->controller_name, 5)).'/';
- $this->initShopContext();
- $this->context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
-
- $this->admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
- $this->admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $this->admin_webpath);
-
- // Check if logged on Addons
- if (isset($this->context->cookie->username_addons) && isset($this->context->cookie->password_addons) && !empty($this->context->cookie->username_addons) && !empty($this->context->cookie->password_addons))
- $this->logged_on_addons = true;
- }
- /**
- * Set breadcrumbs array for the controller page
- */
- public function initBreadcrumbs($tab_id = null, $tabs = null)
- {
- if (is_array($tabs) || count($tabs))
- $tabs = array();
-
- if (is_null($tab_id))
- $tab_id = $this->id;
-
- $tabs = Tab::recursiveTab($tab_id, $tabs);
- $dummy = array('name' => '', 'href' => '', 'icon' => '');
- $breadcrumbs2 = array(
- 'container' => $dummy,
- 'tab' => $dummy,
- 'action' => $dummy
- );
- if (isset($tabs[0]))
- {
- $breadcrumbs2['tab']['name'] = $tabs[0]['name'];
- $breadcrumbs2['tab']['href'] = __PS_BASE_URI__.basename(_PS_ADMIN_DIR_ ).'/'.$this->context->link->getAdminLink($tabs[0]['class_name']);
- if (!isset($tabs[1]))
- $breadcrumbs2['tab']['icon'] = 'icon-'.$tabs[0]['class_name'];
- }
- if (isset($tabs[1]))
- {
- $breadcrumbs2['container']['name'] = $tabs[1]['name'];
- $breadcrumbs2['container']['href'] = __PS_BASE_URI__.basename(_PS_ADMIN_DIR_ ).'/'.$this->context->link->getAdminLink($tabs[1]['class_name']);
- $breadcrumbs2['container']['icon'] = 'icon-'.$tabs[1]['class_name'];
- }
- /* content, edit, list, add, details, options, view */
- switch ($this->display)
- {
- case 'add':
- $breadcrumbs2['action']['name'] = $this->l('Add', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-plus';
- break;
- case 'edit':
- $breadcrumbs2['action']['name'] = $this->l('Edit', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-pencil';
- break;
- case '':
- case 'list':
- $breadcrumbs2['action']['name'] = $this->l('List', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-th-list';
- break;
- case 'details':
- case 'view':
- $breadcrumbs2['action']['name'] = $this->l('View details', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-zoom-in';
- break;
- case 'options':
- $breadcrumbs2['action']['name'] = $this->l('Options', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-cogs';
- break;
- case 'generator':
- $breadcrumbs2['action']['name'] = $this->l('Generator', null, null, false);
- $breadcrumbs2['action']['icon'] = 'icon-flask';
- break;
- }
- $this->context->smarty->assign('breadcrumbs2', $breadcrumbs2);
- /* BEGIN - Backward compatibility < 1.6.0.3 */
- $this->breadcrumbs[] = $tabs[0]['name'];
- $navigationPipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
- $this->context->smarty->assign('navigationPipe', $navigationPipe);
- /* END - Backward compatibility < 1.6.0.3 */
- }
- /**
- * set default toolbar_title to admin breadcrumb
- *
- * @return void
- */
- public function initToolbarTitle()
- {
- $this->toolbar_title = is_array($this->breadcrumbs) ? array_unique($this->breadcrumbs) : array($this->breadcrumbs);
- switch ($this->display)
- {
- case 'edit':
- $this->toolbar_title[] = $this->l('Edit', null, null, false);
- break;
- case 'add':
- $this->toolbar_title[] = $this->l('Add new', null, null, false);
- break;
- case 'view':
- $this->toolbar_title[] = $this->l('View', null, null, false);
- break;
- }
- if ($filter = $this->addFiltersToBreadcrumbs())
- $this->toolbar_title[] = $filter;
- }
-
- public function addFiltersToBreadcrumbs()
- {
- if ($this->filter && is_array($this->fields_list))
- {
- $filters = array();
- foreach ($this->fields_list as $field => $t)
- {
- if (isset($t['filter_key']))
- $field = $t['filter_key'];
- if ($val = Tools::getValue($this->table.'Filter_'.$field))
- {
- if (!is_array($val))
- {
- $filter_value = '';
- if (isset($t['type']) && $t['type'] == 'bool')
- $filter_value = ((bool)$val) ? $this->l('yes') : $this->l('no');
- elseif (is_string($val))
- $filter_value = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
- if (!empty($filter_value))
- $filters[] = sprintf($this->l('%s: %s'), $t['title'], $filter_value);
- }
- else
- {
- $filter_value = '';
- foreach ($val as $v)
- if (is_string($v) && !empty($v))
- $filter_value .= ' - '.htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
- $filter_value = ltrim($filter_value, ' -');
- if (!empty($filter_value))
- $filters[] = sprintf($this->l('%s: %s'), $t['title'], $filter_value);
- }
- }
- }
- if (count($filters))
- return sprintf($this->l('filter by %s'), implode(', ', $filters));
- }
- }
- /**
- * Check rights to view the current tab
- *
- * @param bool $disable
- * @return boolean
- */
- public function viewAccess($disable = false)
- {
- if ($disable)
- return true;
- if ($this->tabAccess['view'] === '1')
- return true;
- return false;
- }
- /**
- * Check for security token
- */
- public function checkToken()
- {
- $token = Tools::getValue('token');
- return (!empty($token) && $token === $this->token);
- }
- /**
- * Set the filters used for the list display
- */
- public function processFilter()
- {
- if (!isset($this->list_id))
- $this->list_id = $this->table;
- $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
- if (isset($this->list_id))
- {
- foreach ($_POST as $key => $value)
- {
- if ($value === '')
- unset($this->context->cookie->{$prefix.$key});
- elseif (stripos($key, $this->list_id.'Filter_') === 0)
- $this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : serialize($value);
- elseif (stripos($key, 'submitFilter') === 0)
- $this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
- }
- foreach ($_GET as $key => $value)
- if (stripos($key, $this->list_id.'Orderby') === 0 && Validate::isOrderBy($value))
- {
- if ($value === '' || $value == $this->_defaultOrderBy)
- unset($this->context->cookie->{$prefix.$key});
- else
- $this->context->cookie->{$prefix.$key} = $value;
- }
- elseif (stripos($key, $this->list_id.'Orderway') === 0 && Validate::isOrderWay($value))
- {
- if ($value === '' || $value == $this->_defaultOrderWay)
- unset($this->context->cookie->{$prefix.$key});
- else
- $this->context->cookie->{$prefix.$key} = $value;
- }
- }
- $filters = $this->context->cookie->getFamily($prefix.$this->list_id.'Filter_');
- foreach ($filters as $key => $value)
- {
- /* Extracting filters from $_POST on key filter_ */
- if ($value != null && !strncmp($key, $prefix.$this->list_id.'Filter_', 7 + Tools::strlen($prefix.$this->list_id)))
- {
- $key = Tools::substr($key, 7 + Tools::strlen($prefix.$this->list_id));
- /* Table alias could be specified using a ! eg. alias!field */
- $tmp_tab = explode('!', $key);
- $filter = count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0];
- if ($field = $this->filterToField($key, $filter))
- {
- $type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false)); if (($type == 'date' || $type == 'datetime') && is_string($value))
- $value = Tools::unSerialize($value);
- $key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`';
- // Assignement by reference
- if (array_key_exists('tmpTableFilter', $field))
- $sql_filter = & $this->_tmpTableFilter;
- elseif (array_key_exists('havingFilter', $field))
- $sql_filter = & $this->_filterHaving;
- else
- $sql_filter = & $this->_filter;
- /* Only for date filtering (from, to) */
- if (is_array($value))
- {
- if (isset($value[0]) && !empty($value[0]))
- {
- if (!Validate::isDate($value[0]))
- $this->errors[] = Tools::displayError('The \'From\' date format is invalid (YYYY-MM-DD)');
- else
- $sql_filter .= ' AND '.pSQL($key).' >= \''.pSQL(Tools::dateFrom($value[0])).'\'';
- }
- if (isset($value[1]) && !empty($value[1]))
- {
- if (!Validate::isDate($value[1]))
- $this->errors[] = Tools::displayError('The \'To\' date format is invalid (YYYY-MM-DD)');
- else
- $sql_filter .= ' AND '.pSQL($key).' <= \''.pSQL(Tools::dateTo($value[1])).'\'';
- }
- }
- else
- {
- $sql_filter .= ' AND ';
- $check_key = ($key == $this->identifier || $key == '`'.$this->identifier.'`');
- if ($type == 'int' || $type == 'bool')
- $sql_filter .= (($check_key || $key == '`active`') ? 'a.' : '').pSQL($key).' = '.(int)$value.' ';
- elseif ($type == 'decimal')
- $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' = '.(float)$value.' ';
- elseif ($type == 'select')
- $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' = \''.pSQL($value).'\' ';
- else
- {
- if ($type == 'price')
- $value = (float)str_replace(',', '.', $value);
- $sql_filter .= ($check_key ? 'a.' : '').pSQL($key).' LIKE \'%'.pSQL($value).'%\' ';
- }
- }
- }
- }
- }
- }
- /**
- * @todo uses redirectAdmin only if !$this->ajax
- */
- public function postProcess()
- {
- try {
- if ($this->ajax)
- {
- // from ajax-tab.php
- $action = Tools::getValue('action');
- // no need to use displayConf() here
- if (!empty($action) && method_exists($this, 'ajaxProcess'.Tools::toCamelCase($action)))
- {
- Hook::exec('actionAdmin'.ucfirst($this->action).'Before', array('controller' => $this));
- Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this));
- $return = $this->{'ajaxProcess'.Tools::toCamelCase($action)}();
- Hook::exec('actionAdmin'.ucfirst($this->action).'After', array('controller' => $this, 'return' => $return));
- Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return));
- return $return;
- }
- elseif (!empty($action) && $this->controller_name == 'AdminModules' && Tools::getIsset('configure'))
- {
- $module_obj = Module::getInstanceByName(Tools::getValue('configure'));
- if (Validate::isLoadedObject($module_obj) && method_exists($module_obj, 'ajaxProcess'.$action))
- return $module_obj->{'ajaxProcess'.$action}();
- }
- elseif (method_exists($this, 'ajaxProcess'))
- return $this->ajaxProcess();
- }
- else
- {
- // Process list filtering
- if ($this->filter)
- $this->processFilter();
- // If the method named after the action exists, call "before" hooks, then call action method, then call "after" hooks
- if (!empty($this->action) && method_exists($this, 'process'.ucfirst(Tools::toCamelCase($this->action))))
- {
- // Hook before action
- Hook::exec('actionAdmin'.ucfirst($this->action).'Before', array('controller' => $this));
- Hook::exec('action'.get_class($this).ucfirst($this->action).'Before', array('controller' => $this));
- // Call process
- $return = $this->{'process'.Tools::toCamelCase($this->action)}();
- // Hook After Action
- Hook::exec('actionAdmin'.ucfirst($this->action).'After', array('controller' => $this, 'return' => $return));
- Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => $return));
- return $return;
- }
- }
- } catch (PrestaShopException $e) {
- $this->errors[] = $e->getMessage();
- };
- return false;
- }
- /**
- * Object Delete images
- */
- public function processDeleteImage()
- {
- if (Validate::isLoadedObject($object = $this->loadObject()))
- {
- if (($object->deleteImage()))
- {
- $redirect = self::$currentIndex.'&add'.$this->table.'&'.$this->identifier.'='.Tools::getValue($this->identifier).'&conf=7&token='.$this->token;
- if (!$this->ajax)
- $this->redirect_after = $redirect;
- else
- $this->content = 'ok';
- }
- }
- $this->errors[] = Tools::displayError('An error occurred while attempting to delete the image. (cannot load object).');
- return $object;
- }
-
- public function processExport($text_delimiter = '"')
- {
- // clean buffer
- if (ob_get_level() && ob_get_length() > 0)
- ob_clean();
- $this->getList($this->context->language->id, null, null, 0, false);
- if (!count($this->_list))
- return;
- header('Content-type: text/csv');
- header('Content-Type: application/force-download; charset=UTF-8');
- header('Cache-Control: no-store, no-cache');
- header('Content-disposition: attachment; filename="'.$this->table.'_'.date('Y-m-d_His').'.csv"');
- $headers = array();
- foreach ($this->fields_list as $datas)
- $headers[] = Tools::htmlentitiesDecodeUTF8($datas['title']);
- $content = array();
- foreach ($this->_list as $i => $row)
- {
- $content[$i] = array();
- $path_to_image = false;
- foreach ($this->fields_list as $key => $params)
- {
- $field_value = isset($row[$key]) ? Tools::htmlentitiesDecodeUTF8(
- Tools::nl2br($row[$key])) : '';
- if ($key == 'image')
- {
- if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES'))
- $path_to_image = Tools::getShopDomain(true)._PS_IMG_.$params['image'].'/'.$row['id_'.$this->table].(isset($row['id_image']) ? '-'.(int)$row['id_image'] : '').'.'.$this->imageType;
- else
- $path_to_image = Tools::getShopDomain(true)._PS_IMG_.$params['image'].'/'.Image::getImgFolderStatic($row['id_image']).(int)$row['id_image'].'.'.$this->imageType;
- if ($path_to_image)
- $field_value = $path_to_image;
- }
- if (isset($params['callback']))
- {
- $callback_obj = (isset($params['callback_object'])) ? $params['callback_object'] : $this->context->controller;
- $field_value = call_user_func_array(array($callback_obj, $params['callback']), array($field_value, $row));
- }
- $content[$i][] = $field_value;
- }
- }
- $this->context->smarty->assign(array(
- 'export_precontent' => "\xEF\xBB\xBF",
- 'export_headers' => $headers,
- 'export_content' => $content,
- 'text_delimiter' => $text_delimiter
- )
- );
- $this->layout = 'layout-export.tpl';
- }
- /**
- * Object Delete
- */
- public function processDelete()
- {
- if (Validate::isLoadedObject($object = $this->loadObject()))
- {
- $res = true;
- // check if request at least one object with noZeroObject
- if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1)
- {
- $this->errors[] = Tools::displayError('You need at least one object.').
- ' <b>'.$this->table.'</b><br />'.
- Tools::displayError('You cannot delete all of the items.');
- }
- elseif (array_key_exists('delete', $this->list_skip_actions) && in_array($object->id, $this->list_skip_actions['delete'])) //check if some ids are in list_skip_actions and forbid deletion
- $this->errors[] = Tools::displayError('You cannot delete this item.');
- else
- {
- if ($this->deleted)
- {
- if (!empty($this->fieldImageSettings))
- $res = $object->deleteImage();
- if (!$res)
- $this->errors[] = Tools::displayError('Unable to delete associated images.');
- $object->deleted = 1;
- if ($res = $object->update())
- $this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token;
- }
- elseif ($res = $object->delete())
- $this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token;
- $this->errors[] = Tools::displayError('An error occurred during deletion.');
- if ($res)
- PrestaShopLogger::addLog(sprintf($this->l('%s deletion', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
- }
- }
- else
- {
- $this->errors[] = Tools::displayError('An error occurred while deleting the object.').
- ' <b>'.$this->table.'</b> '.
- Tools::displayError('(cannot load object)');
- }
- return $object;
- }
- /**
- * Call the right method for creating or updating object
- *
- * @return mixed
- */
- public function processSave()
- {
- if ($this->id_object)
- {
- $this->object = $this->loadObject();
- return $this->processUpdate();
- }
- else
- return $this->processAdd();
- }
- /**
- * Object creation
- */
- public function processAdd()
- {
- if (!isset($this->className) || empty($this->className))
- return false;
- $this->validateRules();
- if (count($this->errors) <= 0)
- {
- $this->object = new $this->className();
- $this->copyFromPost($this->object, $this->table);
- $this->beforeAdd($this->object);
- if (method_exists($this->object, 'add') && !$this->object->add())
- {
- $this->errors[] = Tools::displayError('An error occurred while creating an object.').
- ' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
- }
- /* voluntary do affectation here */
- elseif (($_POST[$this->identifier] = $this->object->id) && $this->postImage($this->object->id) && !count($this->errors) && $this->_redirect)
- {
- PrestaShopLogger::addLog(sprintf($this->l('%s addition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
- $parent_id = (int)Tools::getValue('id_parent', 1);
- $this->afterAdd($this->object);
- $this->updateAssoShop($this->object->id);
- // Save and stay on same form
- if (empty($this->redirect_after) && $this->redirect_after !== false && Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
- $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&conf=3&update'.$this->table.'&token='.$this->token;
- // Save and back to parent
- if (empty($this->redirect_after) && $this->redirect_after !== false && Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
- $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$this->token;
- // Default behavior (save and back)
- if (empty($this->redirect_after) && $this->redirect_after !== false)
- $this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$this->object->id : '').'&conf=3&token='.$this->token;
- }
- }
- $this->errors = array_unique($this->errors);
- if (!empty($this->errors))
- {
- // if we have errors, we stay on the form instead of going back to the list
- $this->display = 'edit';
- return false;
- }
- return $this->object;
- }
- /**
- * Object update
- */
- public function processUpdate()
- {
- /* Checking fields validity */
- $this->validateRules();
- if (empty($this->errors))
- {
- $id = (int)Tools::getValue($this->identifier);
- /* Object update */
- if (isset($id) && !empty($id))
- {
- $object = new $this->className($id);
- if (Validate::isLoadedObject($object))
- {
- /* Specific to objects which must not be deleted */
- if ($this->deleted && $this->beforeDelete($object))
- {
- // Create new one with old objet values
- $object_new = $object->duplicateObject();
- if (Validate::isLoadedObject($object_new))
- {
- // Update old object to deleted
- $object->deleted = 1;
- $object->update();
- // Update new object with post values
- $this->copyFromPost($object_new, $this->table);
- $result = $object_new->update();
- if (Validate::isLoadedObject($object_new))
- $this->afterDelete($object_new, $object->id);
- }
- }
- else
- {
- $this->copyFromPost($object, $this->table);
- $result = $object->update();
- $this->afterUpdate($object);
- }
- if ($object->id)
- $this->updateAssoShop($object->id);
- if (!$result)
- {
- $this->errors[] = Tools::displayError('An error occurred while updating an object.').
- ' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')';
- }
- elseif ($this->postImage($object->id) && !count($this->errors) && $this->_redirect)
- {
- $parent_id = (int)Tools::getValue('id_parent', 1);
- // Specific back redirect
- if ($back = Tools::getValue('back'))
- $this->redirect_after = urldecode($back).'&conf=4';
- // Specific scene feature
- // @todo change stay_here submit name (not clear for redirect to scene ... )
- if (Tools::getValue('stay_here') == 'on' || Tools::getValue('stay_here') == 'true' || Tools::getValue('stay_here') == '1')
- $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=4&updatescene&token='.$this->token;
- // Save and stay on same form
- // @todo on the to following if, we may prefer to avoid override redirect_after previous value
- if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
- $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=4&update'.$this->table.'&token='.$this->token;
- // Save and back to parent
- if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
- $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=4&token='.$this->token;
- // Default behavior (save and back)
- if (empty($this->redirect_after) && $this->redirect_after !== false)
- $this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=4&token='.$this->token;
- }
- PrestaShopLogger::addLog(sprintf($this->l('%s edition', 'AdminTab', false, false), $this->className), 1, null, $this->className, (int)$object->id, true, (int)$this->context->employee->id);
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while updating an object.').
- ' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
- }
- }
- $this->errors = array_unique($this->errors);
- if (!empty($this->errors))
- {
- // if we have errors, we stay on the form instead of going back to the list
- $this->display = 'edit';
- return false;
- }
- if (isset($object))
- return $object;
- return;
- }
- /**
- * Change object required fields
- */
- public function processUpdateFields()
- {
- if (!is_array($fields = Tools::getValue('fieldsBox')))
- $fields = array();
- $object = new $this->className();
- if (!$object->addFieldsRequiredDatabase($fields))
- $this->errors[] = Tools::displayError('An error occurred when attempting to update the required fields.');
- else
- $this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
- return $object;
- }
- /**
- * Change object status (active, inactive)
- */
- public function processStatus()
- {
- if (Validate::isLoadedObject($object = $this->loadObject()))
- {
- if ($object->toggleStatus())
- {
- $matches = array();
- if (preg_match('/[\?|&]controller=([^&]*)/', (string)$_SERVER['HTTP_REFERER'], $matches) !== FALSE
- && strtolower($matches[1]) != strtolower(preg_replace('/controller/i', '', get_class($this))))
- $this->redirect_after = preg_replace('/[\?|&]conf=([^&]*)/i', '', (string)$_SERVER['HTTP_REFERER']);
- else
- $this->redirect_after = self::$currentIndex.'&token='.$this->token;
- $id_category = (($id_category = (int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '';
- $this->redirect_after .= '&conf=5'.$id_category;
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while updating the status.');
- }
- else
- $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.').
- ' <b>'.$this->table.'</b> '.
- Tools::displayError('(cannot load object)');
- return $object;
- }
- /**
- * Change object position
- */
- public function processPosition()
- {
- if (!Validate::isLoadedObject($object = $this->loadObject()))
- {
- $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.').
- ' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
- }
- elseif (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position')))
- $this->errors[] = Tools::displayError('Failed to update the position.');
- else
- {
- $id_identifier_str = ($id_identifier = (int)Tools::getValue($this->identifier)) ? '&'.$this->identifier.'='.$id_identifier : '';
- $redirect = self::$currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.$id_identifier_str.'&token='.$this->token;
- $this->redirect_after = $redirect;
- }
- return $object;
- }
- /**
- * Cancel all filters for this tab
- */
- public function processResetFilters($list_id = null)
- {
- if ($list_id === null)
- $list_id = isset($this->list_id) ? $this->list_id : $this->table;
- $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
- $filters = $this->context->cookie->getFamily($prefix.$list_id.'Filter_');
- foreach ($filters as $cookie_key => $filter)
- if (strncmp($cookie_key, $prefix.$list_id.'Filter_', 7 + Tools::strlen($prefix.$list_id)) == 0)
- {
- $key = substr($cookie_key, 7 + Tools::strlen($prefix.$list_id));
- if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list))
- $this->context->cookie->$cookie_key = null;
- unset($this->context->cookie->$cookie_key);
- }
- if (isset($this->context->cookie->{'submitFilter'.$list_id}))
- unset($this->context->cookie->{'submitFilter'.$list_id});
- if (isset($this->context->cookie->{$prefix.$list_id.'Orderby'}))
- unset($this->context->cookie->{$prefix.$list_id.'Orderby'});
- if (isset($this->context->cookie->{$prefix.$list_id.'Orderway'}))
- unset($this->context->cookie->{$prefix.$list_id.'Orderway'});
- $_POST = array();
- $this->_filter = false;
- unset($this->_filterHaving);
- unset($this->_having);
- }
- /**
- * Update options and preferences
- */
- protected function processUpdateOptions()
- {
- $this->beforeUpdateOptions();
- $languages = Language::getLanguages(false);
- $hide_multishop_checkbox = (Shop::getTotalShops(false, null) < 2) ? true : false;
- foreach ($this->fields_options as $category_data)
- {
- if (!isset($category_data['fields']))
- continue;
- $fields = $category_data['fields'];
- foreach ($fields as $field => $values)
- {
- if (isset($values['type']) && $values['type'] == 'selectLang')
- {
- foreach ($languages as $lang)
- if (Tools::getValue($field.'_'.strtoupper($lang['iso_code'])))
- $fields[$field.'_'.strtoupper($lang['iso_code'])] = array(
- 'type' => 'select',
- 'cast' => 'strval',
- 'identifier' => 'mode',
- 'list' => $values['list']
- );
- }
- }
- // Validate fields
- foreach ($fields as $field => $values)
- {
- // We don't validate fields with no visibility
- if (!$hide_multishop_checkbox && Shop::isFeatureActive() && isset($values['visibility']) && $values['visibility'] > Shop::getContext())
- continue;
- // Check if field is required
- if ((!Shop::isFeatureActive() && isset($values['required']) && $values['required'])
- || (Shop::isFeatureActive() && isset($_POST['multishopOverrideOption'][$field]) && isset($values['required']) && $values['required']))
- if (isset($values['type']) && $values['type'] == 'textLang')
- {
- foreach ($languages as $language)
- if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false && (string)$value != '0')
- $this->errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
- }
- elseif (($value = Tools::getValue($field)) == false && (string)$value != '0')
- $this->errors[] = sprintf(Tools::displayError('field %s is required.'), $values['title']);
- // Check field validator
- if (isset($values['type']) && $values['type'] == 'textLang')
- {
- foreach ($languages as $language)
- if (Tools::getValue($field.'_'.$language['id_lang']) && isset($values['validation']))
- if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang'])))
- $this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
- }
- elseif (Tools::getValue($field) && isset($values['validation']))
- if (!Validate::$values['validation'](Tools::getValue($field)))
- $this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $values['title']);
- // Set default value
- if (Tools::getValue($field) === false && isset($values['default']))
- $_POST[$field] = $values['default'];
- }
- if (!count($this->errors))
- {
- foreach ($fields as $key => $options)
- {
- if (!$hide_multishop_checkbox && Shop::isFeatureActive() && isset($options['visibility']) && $options['visibility'] > Shop::getContext())
- continue;
- if (!$hide_multishop_checkbox && Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && empty($options['no_multishop_checkbox']) && empty($_POST['multishopOverrideOption'][$key]))
- {
- Configuration::deleteFromContext($key);
- continue;
- }
- // check if a method updateOptionFieldName is available
- $method_name = 'updateOption'.Tools::toCamelCase($key, true);
- if (method_exists($this, $method_name))
- $this->$method_name(Tools::getValue($key));
- elseif (isset($options['type']) && in_array($options['type'], array('textLang', 'textareaLang')))
- {
- $list = array();
- foreach ($languages as $language)
- {
- $key_lang = Tools::getValue($key.'_'.$language['id_lang']);
- $val = (isset($options['cast']) ? $options['cast']($key_lang) : $key_lang);
- if ($this->validateField($val, $options))
- {
- if (Validate::isCleanHtml($val))
- $list[$language['id_lang']] = $val;
- else
- $this->errors[] = Tools::displayError('Can not add configuration '.$key.' for lang '.Language::getIsoById((int)$language['id_lang']));
- }
- }
- Configuration::updateValue($key, $list);
- }
- else
- {
- $val = (isset($options['cast']) ? $options['cast'](Tools::getValue($key)) : Tools::getValue($key));
- if ($this->validateField($val, $options))
- {
- if (Validate::isCleanHtml($val))
- Configuration::updateValue($key, $val);
- else
- $this->errors[] = Tools::displayError('Can not add configuration '.$key);
- }
- }
- }
- }
- }
- $this->display = 'list';
- if (empty($this->errors))
- $this->confirmations[] = $this->_conf[6];
- }
- public function initPageHeaderToolbar()
- {
- if (empty($this->toolbar_title))
- $this->initToolbarTitle();
- if (!is_array($this->toolbar_title))
- $this->toolbar_title = array($this->toolbar_title);
- switch ($this->display)
- {
- case 'view':
- // Default cancel button - like old back link
- $back = Tools::safeOutput(Tools::getValue('back', ''));
- if (empty($back))
- $back = self::$currentIndex.'&token='.$this->token;
- if (!Validate::isCleanHtml($back))
- die(Tools::displayError());
- if (!$this->lite_display)
- $this->page_header_toolbar_btn['back'] = array(
- 'href' => $back,
- 'desc' => $this->l('Back to list')
- );
- $obj = $this->loadObject(true);
- if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name}))
- {
- array_pop($this->toolbar_title);
- $this->toolbar_title[] = is_array($obj->{$this->identifier_name}) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name};
- }
- break;
- case 'edit':
- $obj = $this->loadObject(true);
- if (Validate::isLoadedObject($obj) && isset($obj->{$this->identifier_name}) && !empty($obj->{$this->identifier_name}))
- {
- array_pop($this->toolbar_title);
- $this->toolbar_title[] = sprintf($this->l('Edit: %s'),
- is_array($obj->{$this->identifier_name}) ? $obj->{$this->identifier_name}[$this->context->employee->id_lang] : $obj->{$this->identifier_name});
- }
- break;
- }
- if (is_array($this->page_header_toolbar_btn)
- && $this->page_header_toolbar_btn instanceof Traversable
- || count($this->toolbar_title))
- $this->show_page_header_toolbar = true;
- if (empty($this->page_header_toolbar_title))
- $this->page_header_toolbar_title = array_pop($this->toolbar_title);
- $this->addPageHeaderToolBarModulesListButton();
- $this->context->smarty->assign('help_link', 'http://help.prestashop.com/'.$this->context->language->iso_code.'/doc/'.Tools::getValue('controller').'?version='._PS_VERSION_.'&country='.$this->context->country->iso_code);
- }
- /**
- * assign default action in toolbar_btn smarty var, if they are not set.
- * uses override to specifically add, modify or remove items
- *
- */
- public function initToolbar()
- {
- switch ($this->display)
- {
- case 'add':
- case 'edit':
- // Default save button - action dynamically handled in javascript
- $this->toolbar_btn['save'] = array(
- 'href' => '#',
- 'desc' => $this->l('Save')
- );
- $back = Tools::safeOutput(Tools::getValue('back', ''));
- if (empty($back))
- $back = self::$currentIndex.'&token='.$this->token;
- if (!Validate::isCleanHtml($back))
- die(Tools::displayError());
- if (!$this->lite_display)
- $this->toolbar_btn['cancel'] = array(
- 'href' => $back,
- 'desc' => $this->l('Cancel')
- );
- break;
- case 'view':
- // Default cancel button - like old back link
- $back = Tools::safeOutput(Tools::getValue('back', ''));
- if (empty($back))
- $back = self::$currentIndex.'&token='.$this->token;
- if (!Validate::isCleanHtml($back))
- die(Tools::displayError());
- if (!$this->lite_display)
- $this->toolbar_btn['back'] = array(
- 'href' => $back,
- 'desc' => $this->l('Back to list')
- );
- break;
- case 'options':
- $this->toolbar_btn['save'] = array(
- 'href' => '#',
- 'desc' => $this->l('Save')
- );
- break;
- default: // list
- $this->toolbar_btn['new'] = array(
- 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
- 'desc' => $this->l('Add new')
- );
- if ($this->allow_export)
- $this->toolbar_btn['export'] = array(
- 'href' => self::$currentIndex.'&export'.$this->table.'&token='.$this->token,
- 'desc' => $this->l('Export')
- );
- }
- $this->addToolBarModulesListButton();
- }
- /**
- * Load class object using identifier in $_GET (if possible)
- * otherwise return an empty object, or die
- *
- * @param boolean $opt Return an empty object if load fail
- * @return object|boolean
- */
- protected function loadObject($opt = false)
- {
- if (!isset($this->className) || empty($this->className))
- return true;
- $id = (int)Tools::getValue($this->identifier);
- if ($id && Validate::isUnsignedId($id))
- {
- if (!$this->object)
- $this->object = new $this->className($id);
- if (Validate::isLoadedObject($this->object))
- return $this->object;
- // throw exception
- $this->errors[] = Tools::displayError('The object cannot be loaded (or found)');
- return false;
- }
- elseif ($opt)
- {
- if (!$this->object)
- $this->object = new $this->className();
- return $this->object;
- }
- else
- {
- $this->errors[] = Tools::displayError('The object cannot be loaded (the identifier is missing or invalid)');
- return false;
- }
- }
- /**
- * Check if the token is valid, else display a warning page
- */
- public function checkAccess()
- {
- if (!$this->checkToken())
- {
- // If this is an XSS attempt, then we should only display a simple, secure page
- // ${1} in the replacement string of the regexp is required,
- // because the token may begin with a number and mix up with it (e.g. $17)
- $url = preg_replace('/([&?]token=)[^&]*(&.*)?$/', '${1}'.$this->token.'$2', $_SERVER['REQUEST_URI']);
- if (false === strpos($url, '?token=') && false === strpos($url, '&token='))
- $url .= '&token='.$this->token;
- if (strpos($url, '?') === false)
- $url = str_replace('&token', '?controller=AdminDashboard&token', $url);
- $this->context->smarty->assign('url', htmlentities($url));
- return false;
- }
- return true;
- }
- protected function filterToField($key, $filter)
- {
- if (!isset($this->fields_list))
- return false;
- foreach ($this->fields_list as $field)
- if (array_key_exists('filter_key', $field) && $field['filter_key'] == $key)
- return $field;
- if (array_key_exists($filter, $this->fields_list))
- return $this->fields_list[$filter];
- return false;
- }
- public function displayNoSmarty()
- {
- }
- public function displayAjax()
- {
- if ($this->json)
- {
- $this->context->smarty->assign(array(
- 'json' => true,
- 'status' => $this->status,
- ));
- }
- $this->layout = 'layout-ajax.tpl';
- $this->display_header = false;
- $this->display_footer = false;
- return $this->display();
- }
- protected function redirect()
- {
- header('Location: '.$this->redirect_after);
- exit;
- }
- public function display()
- {
- $this->context->smarty->assign(array(
- 'display_header' => $this->display_header,
- …
Large files files are truncated, but you can click here to view the full file