* @copyright 2007-2017 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ @ini_set('max_execution_time', 0); /** No max line limit since the lines can be more than 4096. Performance impact is not significant. */ define('MAX_LINE_SIZE', 0); /** Used for validatefields diying without user friendly error or not */ define('UNFRIENDLY_ERROR', false); /** this value set the number of columns visible on each page */ define('MAX_COLUMNS', 6); /** correct Mac error on eof */ @ini_set('auto_detect_line_endings', '1'); class AdminImportControllerCore extends AdminController { public static $column_mask; public $entities = array(); public $available_fields = array(); public $required_fields = array(); public $cache_image_deleted = array(); public static $default_values = array(); public static $validators = array( 'active' => array('AdminImportController', 'getBoolean'), 'tax_rate' => array('AdminImportController', 'getPrice'), 'reduction_price' => array('AdminImportController', 'getPrice'), 'reduction_percent' => array('AdminImportController', 'getPrice'), 'wholesale_price' => array('AdminImportController', 'getPrice'), 'ecotax' => array('AdminImportController', 'getPrice'), 'name' => array('AdminImportController', 'createMultiLangField'), 'description' => array('AdminImportController', 'createMultiLangField'), 'description_short' => array('AdminImportController', 'createMultiLangField'), 'meta_title' => array('AdminImportController', 'createMultiLangField'), 'meta_keywords' => array('AdminImportController', 'createMultiLangField'), 'meta_description' => array('AdminImportController', 'createMultiLangField'), 'link_rewrite' => array('AdminImportController', 'createMultiLangField'), 'available_now' => array('AdminImportController', 'createMultiLangField'), 'available_later' => array('AdminImportController', 'createMultiLangField'), 'category' => array('AdminImportController', 'split'), 'online_only' => array('AdminImportController', 'getBoolean'), ); public $separator; public $multiple_value_separator; public function __construct() { $this->bootstrap = true; $this->entities = array( $this->l('Properties'), $this->l('Room Types'), $this->l('Rooms'), $this->l('Categories'), $this->l('Service Products'), $this->l('Bookings'), $this->l('Customers'), ); $this->entities = array_flip($this->entities); switch ((int)Tools::getValue('entity')) { case $this->entities[$this->l('Categories')]: $this->required_fields = array( 'name' ); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID'), 'help' => $this->l('Please note: Default categories will not be overridden even with force ids.Ex: Home, Root, Service, Location')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'parent' => array('label' => $this->l('Parent category')), 'image' => array('label' => $this->l('Image URL')), ); self::$default_values = array( 'active' => '1', 'parent' => Configuration::get('PS_HOME_CATEGORY'), ); break; case $this->entities[$this->l('Properties')]: $this->required_fields = array( 'hotel_name', 'phone', 'email', 'address', 'rating', 'check_in', 'check_out', 'id_country', 'id_state', 'city', 'postcode' ); self::$validators['short_description'] = array('AdminImportController', 'createMultiLangField'); self::$validators['policies'] = array('AdminImportController', 'createMultiLangField'); self::$validators['hotel_name'] = array('AdminImportController', 'createMultiLangField'); self::$validators['image'] = array('AdminImportController', 'split'); self::$validators['refund_ids'] = array('AdminImportController', 'split'); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'hotel_name' => array('label' => $this->l('Property Name *')), 'short_description' => array('label' => $this->l('Short Description')), 'description' => array('label' => $this->l('Description')), 'phone' => array('label' => $this->l('Mobile phone *')), 'email' => array('label' => $this->l('Email *')), 'address' => array('label' => $this->l('Address *')), 'rating' => array('label' => $this->l('Rating *')), 'check_in' => array('label' => $this->l('Check-In *')), 'check_out' => array('label' => $this->l('Check-Out *')), 'id_country' => array('label' => $this->l('Country ID*')), 'id_state' => array('label' => $this->l('State ID')), 'city' => array('label' => $this->l('City *')), 'postcode' => array('label' => $this->l('Zip Code *')), 'fax' => array('label' => $this->l('Fax')), 'policies' => array('label' => $this->l('Property Policies')), 'active_refund' => array('label' => $this->l('Allow Refund (0 = No, 1 = Yes)')), 'refund_ids' => array('label' => $this->l('Refund IDs (x,y,z...)')), 'max_checkout_offset' => array('label' => $this->l('Maximum checkout offset')), 'min_booking_offset' => array('label' => $this->l('Minimum booking offset')), 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), 'delete_existing_images' => array( 'label' => $this->l('Delete existing images (0 = No, 1 = Yes)') ), ); break; case $this->entities[$this->l('Room Types')]: $this->required_fields = array('id_hotel', 'name'); self::$validators['image'] = array('AdminImportController', 'split'); self::$validators['id_service_products'] = array('AdminImportController', 'split'); self::$validators['id_features'] = array('AdminImportController', 'split'); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'id_hotel' => array('label' => $this->l('Property ID *')), 'price' => array('label' => $this->l('Pre-tax retail price')), 'wholesale_price' => array('label' => $this->l('Pre-tax operating cost')), 'id_tax_rules_group' => array('label' => $this->l('Tax rule ID')), 'advance_payment' => array('label' => $this->l('Allow advance payment(0 = Yes, 1 = No)')), 'payment_type' => array( 'label' => $this->l('Room type advance payment (0/1/2)'), 'help' => $this->l('0 = use global, 1 = Percentage, 2 = Fixed amount') ), 'payment_value' => array( 'label' => $this->l('Value for the advance payment'), 'help' => $this->l('Required if advance payment allowed.') ), 'tax_included' => array( 'label' => $this->l('Include tax with advance payment'), 'help' => $this->l('Required if advance payment allowed.') ), 'min_len_stay' => array('label' => $this->l('Minimum length of stay (1 = No Limit)')), 'max_len_stay' => array('label' => $this->l('Maximum length of stay (0 = No Limit)')), 'base_adults' => array('label' => $this->l('Base adults')), 'base_children' => array('label' => $this->l('Base children')), 'max_adults' => array('label' => $this->l('Maximum adults')), 'max_children' => array('label' => $this->l('Maximum children')), 'max_room_occupancy' => array('label' => $this->l('Maximum room occupancy')), 'show_at_front' => array('label' => $this->l('Show at front (0/1)')), 'id_service_products' => array('label' => $this->l('Service products IDs (x, y, z...)')), 'id_features' => array('label' => $this->l('Feature IDs (x, y, z...)')), 'description_short' => array('label' => $this->l('Short description')), 'description' => array('label' => $this->l('Description')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'link_rewrite' => array('label' => $this->l('URL rewritten')), 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), 'delete_existing_images' => array( 'label' => $this->l('Delete existing images (0 = No, 1 = Yes)') ), ); self::$default_values = array( 'id_category' => array((int) Configuration::get('PS_HOME_CATEGORY')), 'id_category_default' => null, 'active' => '1', 'minimal_quantity' => 1, 'price' => 0, 'id_tax_rules_group' => 0, 'description_short' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'show_at_front' => true, 'available_date' => date('Y-m-d'), 'date_add' => date('Y-m-d H:i:s'), 'date_upd' => date('Y-m-d H:i:s'), ); break; case $this->entities[$this->l('Rooms')]: $this->required_fields = array('room_num', 'id_status', 'id_product'); self::$validators['dates'] = array('AdminImportController', 'split'); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'room_num' => array('label' => $this->l('Room No *'),), 'floor' => array('label' => $this->l('Floor')), 'id_product' => array('label' => $this->l('Room Type ID *')), 'id_status' => array( 'label' => $this->l('Room status (1/2)'), 'help' => $this->l('1 = Active, 2 = Inactive')), 'comment' => array('label' => $this->l('Extra Information')), 'dates' => array('label' => $this->l('Disable date ranges and Reason(yyyy-mm-dd)'), 'help' => $this->l('date_from:date_to:reason, date_from:date_to:reason,...') ), ); break; case $this->entities[$this->l('Service Products')]: self::$validators['image'] = array('AdminImportController', 'split'); self::$validators['id_room_types'] = array('AdminImportController', 'split'); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'category' => array('label' => $this->l('Categories (x,y,z...)')), 'id_room_types' => array('label' => $this->l('Associated room types (x,y,z...) *')), 'price' => array('label' => $this->l('Pre-tax retail price')), 'wholesale_price' => array('label' => $this->l('Pre-tax operating cost')), 'id_tax_rules_group' => array('label' => $this->l('Tax rule ID')), 'auto_add_to_cart' => array('label' => $this->l('Auto add to cart (0 = No, 1 = Yes)')), 'price_addition_type' => array('label' => $this->l('Price display preference'), 'help' => $this->l('1 = With room price, 2 = As convenience fee')), 'show_at_front' => array('label' => $this->l('Show at front office (0 = No, 1 = Yes)')), 'price_calculation_method' => array('label' => $this->l('Price calculation method'), 'help' => $this->l('1 = Once per booking, 2 = Each day')), 'description_short' => array('label' => $this->l('Short description')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), 'delete_existing_images' => array( 'label' => $this->l('Delete existing images (0 = No, 1 = Yes)') ), ); self::$default_values = array( 'id_category' => array((int) Configuration::get('PS_SERVICE_CATEGORY')), 'id_category_default' => Configuration::get('PS_SERVICE_CATEGORY'), 'active' => '1', 'price' => 0, 'id_tax_rules_group' => 0, 'description_short' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'date_add' => date('Y-m-d H:i:s'), 'date_upd' => date('Y-m-d H:i:s'), ); break; case $this->entities[$this->l('Bookings')]: $this->required_fields = array('id_customer', 'duration_dates', 'num_rooms', 'id_product'); self::$validators['duration_dates'] = array('AdminImportController', 'split'); self::$validators['id_service_products'] = array('AdminImportController', 'split'); $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id_order' => array( 'label' => $this->l('Order Reference ID'), 'help' => $this->l('This is only used to group together orders from multiple rows as a single order.') ), 'id_customer' => array( 'label' => $this->l('Customer ID *'), 'help' => $this->l('Orders with same Order Reference ID will use Customer ID from the first row only.') ), 'id_product' => array('label'=> 'Room Type ID'), 'duration_dates' => array( 'label' => $this->l('Duration * (yyyy-mm-dd)'), 'help' => $this->l('Check_in, Check_out') ), 'num_rooms' => array('label' => $this->l('Number Of Rooms')), 'amount' => array('label' => $this->l('Order Price')), 'due_amount' => array('label' => $this->l('Due Amount')), 'id_currency' => array('label' => $this->l('Currency ID')), 'id_order_status' => array('label' => $this->l('Order Status ID')), 'id_service_products' => array( 'label' => $this->l('Service Product IDs (x:n, y:n, z:n,..)'), 'help' => $this->l('id_service_product:quantity') ), ); break; case $this->entities[$this->l('Customers')]: $this->required_fields = array('email', 'passwd', 'lastname', 'firstname'); if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) { $this->required_fields[] = 'phone'; } $this->available_fields = array( 'no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'id_gender' => array('label' => $this->l('Titles ID (Mr = 1, Ms = 2, else 0)')), 'email' => array('label' => $this->l('Email *')), 'passwd' => array('label' => $this->l('Password *')), 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), 'phone' => array('label' => $this->l('Phone'). (Configuration::get('PS_ONE_PHONE_AT_LEAST') ? ' *' : '' )), 'newsletter' => array('label' => $this->l('Newsletter (0/1)')), 'optin' => array('label' => $this->l('Opt-in (0/1)')), 'group' => array('label' => $this->l('Groups (x,y,z...)')), 'id_default_group' => array('label' => $this->l('Default group ID')), ); self::$default_values = array('active' => '1'); break; } $this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator : ';'; $this->multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator : ','; parent::__construct(); } public function setMedia() { $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_.$bo_theme.DIRECTORY_SEPARATOR .'template')) { $bo_theme = 'default'; } // We need to set parent media first, so that jQuery is loaded before the dependant plugins parent::setMedia(); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); $this->addJs(__PS_BASE_URI__.$this->admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js'); $this->addJs(__PS_BASE_URI__.'js/vendor/spin.js'); $this->addJs(__PS_BASE_URI__.'js/vendor/ladda.js'); } public function renderForm() { if (!is_dir(AdminImportController::getPath())) { return !($this->errors[] = Tools::displayError('The import directory does not exist.')); } if (!is_writable(AdminImportController::getPath())) { $this->displayWarning($this->l('The import directory must be writable (CHMOD 755 / 777).')); } if (isset($this->warnings) && count($this->warnings)) { $warnings = array(); foreach ($this->warnings as $warning) { $warnings[] = $warning; } } $files_to_import = scandir(AdminImportController::getPath()); uasort($files_to_import, array('AdminImportController', 'usortFiles')); foreach ($files_to_import as $k => &$filename) { //exclude . .. .svn and index.php and all hidden files if (preg_match('/^\..*|index\.php/i', $filename)) { unset($files_to_import[$k]); } } unset($filename); $this->fields_form = array(''); $this->toolbar_scroll = false; $this->toolbar_btn = array(); // adds fancybox $this->addJqueryPlugin(array('fancybox')); $entity_selected = 0; if (isset($this->entities[$this->l(Tools::ucfirst(Tools::getValue('import_type')))])) { $entity_selected = $this->entities[$this->l(Tools::ucfirst(Tools::getValue('import_type')))]; $this->context->cookie->entity_selected = (int)$entity_selected; } elseif (isset($this->context->cookie->entity_selected)) { $entity_selected = (int)$this->context->cookie->entity_selected; } $csv_selected = ''; if (isset($this->context->cookie->csv_selected) && @filemtime(AdminImportController::getPath( urldecode($this->context->cookie->csv_selected)))) { $csv_selected = urldecode($this->context->cookie->csv_selected); } else { $this->context->cookie->csv_selected = $csv_selected; } $id_lang_selected = ''; if (isset($this->context->cookie->iso_lang_selected) && $this->context->cookie->iso_lang_selected) { $id_lang_selected = (int)Language::getIdByIso(urldecode($this->context->cookie->iso_lang_selected)); } $separator_selected = $this->separator; if (isset($this->context->cookie->separator_selected) && $this->context->cookie->separator_selected) { $separator_selected = urldecode($this->context->cookie->separator_selected); } $multiple_value_separator_selected = $this->multiple_value_separator; if (isset($this->context->cookie->multiple_value_separator_selected) && $this->context->cookie->multiple_value_separator_selected) { $multiple_value_separator_selected = urldecode($this->context->cookie->multiple_value_separator_selected); } //get post max size $post_max_size = ini_get('post_max_size'); $bytes = (int)trim($post_max_size); $last = strtolower($post_max_size[strlen($post_max_size) - 1]); switch ($last) { case 'g': $bytes *= 1024; case 'm': $bytes *= 1024; case 'k': $bytes *= 1024; } if (!isset($bytes) || $bytes == 0) { $bytes = 20971520; } // 20Mb $this->tpl_form_vars = array( 'post_max_size' => (int)$bytes, 'module_confirmation' => Tools::isSubmit('import') && (isset($this->warnings) && !count($this->warnings)), 'path_import' => AdminImportController::getPath(), 'entities' => $this->entities, 'entity_selected' => $entity_selected, 'csv_selected' => $csv_selected, 'separator_selected' => $separator_selected, 'multiple_value_separator_selected' => $multiple_value_separator_selected, 'files_to_import' => $files_to_import, 'languages' => Language::getLanguages(false), 'id_language' => ($id_lang_selected) ? $id_lang_selected : $this->context->language->id, 'available_fields' => $this->getAvailableFields(), 'truncateAuthorized' => (Shop::isFeatureActive() && $this->context->employee->isSuperAdmin()) || !Shop::isFeatureActive(), 'PS_ADVANCED_STOCK_MANAGEMENT' => Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'), ); return parent::renderForm(); } public function ajaxProcessuploadCsv() { $filename_prefix = date('YmdHis').'-'; if (isset($_FILES['file']) && !empty($_FILES['file']['error'])) { switch ($_FILES['file']['error']) { case UPLOAD_ERR_INI_SIZE: $_FILES['file']['error'] = Tools::displayError('The uploaded file exceeds the upload_max_filesize directive in php.ini. If your server configuration allows it, you may add a directive in your .htaccess.'); break; case UPLOAD_ERR_FORM_SIZE: $_FILES['file']['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini. If your server configuration allows it, you may add a directive in your .htaccess, for example:') .'
php_value post_max_size 20M '. Tools::displayError('(click to open "Generators" page)').''; break; break; case UPLOAD_ERR_PARTIAL: $_FILES['file']['error'] = Tools::displayError('The uploaded file was only partially uploaded.'); break; break; case UPLOAD_ERR_NO_FILE: $_FILES['file']['error'] = Tools::displayError('No file was uploaded.'); break; break; } } elseif (!preg_match('/.*\.csv$/i', $_FILES['file']['name'])) { $_FILES['file']['error'] = Tools::displayError('The extension of your file should be .csv.'); } elseif (!@filemtime($_FILES['file']['tmp_name']) || !@move_uploaded_file($_FILES['file']['tmp_name'], AdminImportController::getPath().$filename_prefix.str_replace("\0", '', $_FILES['file']['name']))) { $_FILES['file']['error'] = $this->l('An error occurred while uploading / copying the file.'); } else { @chmod(AdminImportController::getPath().$filename_prefix.$_FILES['file']['name'], 0664); $_FILES['file']['filename'] = $filename_prefix.str_replace('\0', '', $_FILES['file']['name']); } die(json_encode($_FILES)); } public function renderView() { $this->addJS(_PS_JS_DIR_.'admin/import.js'); $handle = $this->openCsvFile(); $nb_column = $this->getNbrColumn($handle, $this->separator); $nb_table = ceil($nb_column / MAX_COLUMNS); $res = array(); foreach ($this->required_fields as $elem) { $res[] = '\''.$elem.'\''; } $data = array(); for ($i = 0; $i < $nb_table; $i++) { $data[$i] = $this->generateContentTable($i, $nb_column, $handle, $this->separator); } $this->context->cookie->entity_selected = (int)Tools::getValue('entity'); $this->context->cookie->iso_lang_selected = urlencode(Tools::getValue('iso_lang')); $this->context->cookie->separator_selected = urlencode($this->separator); $this->context->cookie->multiple_value_separator_selected = urlencode($this->multiple_value_separator); $this->context->cookie->csv_selected = urlencode(Tools::getValue('csv')); $this->tpl_view_vars = array( 'import_matchs' => Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'import_match', true, false), 'fields_value' => array( 'csv' => Tools::getValue('csv'), 'convert' => Tools::getValue('convert'), 'entity' => (int)Tools::getValue('entity'), 'iso_lang' => Tools::getValue('iso_lang'), 'truncate' => Tools::getValue('truncate'), 'forceIDs' => Tools::getValue('forceIDs'), 'regenerate' => Tools::getValue('regenerate'), 'match_ref' => Tools::getValue('match_ref'), 'separator' => $this->separator, 'multiple_value_separator' => $this->multiple_value_separator ), 'nb_table' => $nb_table, 'nb_column' => $nb_column, 'res' => implode(',', $res), 'max_columns' => MAX_COLUMNS, 'no_pre_select' => array('price_tin', 'feature'), 'available_fields' => $this->available_fields, 'data' => $data ); return parent::renderView(); } public function initToolbar() { switch ($this->display) { case 'import': // Default cancel button - like old back link $back = Tools::safeOutput(Tools::getValue('back', '')); if (empty($back)) { $back = self::$currentIndex.'&token='.$this->token; } $this->toolbar_btn['cancel'] = array( 'href' => $back, 'desc' => $this->l('Cancel') ); // Default save button - action dynamically handled in javascript $this->toolbar_btn['save-import'] = array( 'href' => '#', 'desc' => $this->l('Import .CSV data') ); break; } } protected function generateContentTable($current_table, $nb_column, $handle, $glue) { $html = ''; // Header for ($i = 0; $i < $nb_column; $i++) { if (MAX_COLUMNS * (int)$current_table <= $i && (int)$i < MAX_COLUMNS * ((int)$current_table + 1)) { $html .= ''; } } $html .= ''; AdminImportController::setLocale(); for ($current_line = 0; $current_line < 10 && $line = fgetcsv($handle, MAX_LINE_SIZE, $glue, escape: ""); $current_line++) { /* UTF-8 conversion */ if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $html .= ''; foreach ($line as $nb_c => $column) { if ((MAX_COLUMNS * (int)$current_table <= $nb_c) && ((int)$nb_c < MAX_COLUMNS * ((int)$current_table + 1))) { $html .= ''; } } $html .= ''; } $html .= ''; AdminImportController::rewindBomAware($handle); return $html; } public function init() { parent::init(); if (Tools::isSubmit('submitImportFile')) { $this->display = 'import'; } } public function initContent() { $this->initTabModuleList(); // toolbar (save, cancel, new, ..) $this->initToolbar(); $this->initPageHeaderToolbar(); if ($this->display == 'import') { if (Tools::getValue('csv')) { $this->content .= $this->renderView(); } else { $this->errors[] = $this->l('You must upload a file in order to proceed to the next step'); $this->content .= $this->renderForm(); } } else { $this->content .= $this->renderForm(); } $this->context->smarty->assign(array( 'content' => $this->content, 'url_post' => self::$currentIndex.'&token='.$this->token, 'show_page_header_toolbar' => $this->show_page_header_toolbar, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn )); } protected static function rewindBomAware($handle) { // A rewind wrapper that skips BOM signature wrongly if (!is_resource($handle)) { return false; } rewind($handle); if (($bom = fread($handle, 3)) != "\xEF\xBB\xBF") { rewind($handle); } } protected static function getBoolean($field) { return (bool)$field; } protected static function getPrice($field) { $field = ((float)str_replace(',', '.', $field)); $field = ((float)str_replace('%', '', $field)); return $field; } protected static function split($field) { if (empty($field)) { return array(); } $separator = Tools::getValue('multiple_value_separator'); if (is_null($separator) || trim($separator) == '') { $separator = ','; } do { $uniqid_path = _PS_UPLOAD_DIR_.uniqid(); } while (file_exists($uniqid_path)); file_put_contents($uniqid_path, $field); $tab = ''; if (!empty($uniqid_path)) { $fd = fopen($uniqid_path, 'r'); $tab = fgetcsv($fd, MAX_LINE_SIZE, $separator, escape: ""); fclose($fd); if (file_exists($uniqid_path)) { @unlink($uniqid_path); } } if (empty($tab) || (!is_array($tab))) { return array(); } return $tab; } protected static function createMultiLangField($field) { $res = array(); foreach (Language::getIDs(false) as $id_lang) { $res[$id_lang] = $field; } return $res; } protected function getTypeValuesOptions($nb_c) { $i = 0; $no_pre_select = array('price_tin', 'feature'); $options = ''; foreach ($this->available_fields as $k => $field) { $options .= '