diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index 1b2e3b520..f171ff0f1 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -193,10 +193,8 @@ if ($step = (int)(Tools::getValue('ajaxProductTab'))) if (Tools::isSubmit('getAvailableFields') AND Tools::isSubmit('entity')) { - AdminTab::$currentIndex = 'index.php?tab=AdminImport'; $jsonArray = array(); - require_once(dirname(__FILE__).'/tabs/AdminImport.php'); - $import = new AdminImport(); + $import = new AdminImportController(); $languages = Language::getLanguages(false); $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT')); diff --git a/admin-dev/tabs/AdminImport.php b/admin-dev/tabs/AdminImport.php deleted file mode 100644 index 5720b258f..000000000 --- a/admin-dev/tabs/AdminImport.php +++ /dev/null @@ -1,1867 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7310 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -include_once(_PS_ADMIN_DIR_.'/../images.inc.php'); -@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); - -define('UNFRIENDLY_ERROR', false); // Used for validatefields diying without user friendly error or not - -// 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 AdminImport extends AdminTab -{ - public static $column_mask; - - public $entities = array(); - - public $available_fields = array(); - - public static $required_fields = array('name'); - - public static $default_values = array(); - - public $_warnings = array(); - - public static $validators = array( - 'active' => array('AdminImport', 'getBoolean'), - 'tax_rate' => array('AdminImport', 'getPrice'), - 'price_tex' => array('AdminImport', 'getPrice'), // Tax excluded - 'price_tin' => array('AdminImport', 'getPrice'), // Tax included - 'reduction_price' => array('AdminImport', 'getPrice'), - 'reduction_percent' => array('AdminImport', 'getPrice'), - 'wholesale_price' => array('AdminImport', 'getPrice'), - 'ecotax' => array('AdminImport', 'getPrice'), - 'name' => array('AdminImport', 'createMultiLangField'), - 'description' => array('AdminImport', 'createMultiLangField'), - 'description_short' => array('AdminImport', 'createMultiLangField'), - 'meta_title' => array('AdminImport', 'createMultiLangField'), - 'meta_keywords' => array('AdminImport', 'createMultiLangField'), - 'meta_description' => array('AdminImport', 'createMultiLangField'), - 'link_rewrite' => array('AdminImport', 'createMultiLangField'), - 'available_now' => array('AdminImport', 'createMultiLangField'), - 'available_later' => array('AdminImport', 'createMultiLangField'), - 'category' => array('AdminImport', 'split'), - 'online_only' => array('AdminImport', 'getBoolean') - ); - - public function __construct() - { - $this->entities = array_flip(array($this->l('Categories'), $this->l('Products'), $this->l('Combinations'), $this->l('Customers'), $this->l('Addresses'), $this->l('Manufacturers'), $this->l('Suppliers'))); - - switch ((int)(Tools::getValue('entity'))) - { - case $this->entities[$this->l('Combinations')]: - self::$required_fields = array('id_product', 'group', 'attribute'); - $this->available_fields = array( - 'no' => array('label' => $this->l('Ignore this column')), - 'id_product' => array('label' => $this->l('Product ID').'*'), - 'group' => array('label' => $this->l('Group (Name:Position)').'*', - 'help' => $this->l('Position of the group attribute.')), - 'attribute' => array('label' => $this->l('Attribute (Value:Position)').'*', - 'help' => $this->l('Position of the attribute in the attribute group.')), - 'reference' => array('label' => $this->l('Reference')), - 'supplier_reference' => array('label' => $this->l('Supplier reference')), - 'ean13' => array('label' => $this->l('EAN13')), - 'upc' => array('label' => $this->l('UPC')), - 'wholesale_price' => array('label' => $this->l('Wholesale price')), - 'price' => array('label' => $this->l('Price')), - 'ecotax' => array('label' => $this->l('Ecotax')), - 'quantity' => array('label' => $this->l('Quantity')), - 'weight' => array('label' => $this->l('Weight')), - 'default_on' => array('label' => $this->l('Default')), - 'image_position' => array('label' => $this->l('Image position'), - 'help' => $this->l('Position of the product image to use for this combination. If you use this field, leave image URL empty.')), - 'image_url' => array('label' => $this->l('Image URL')), - 'delete_existing_images' => array( - 'label' => $this->l('Delete existing images (0 = no, 1 = yes)'), - 'help' => $this->l('If you do not specify this column and you specify the column images, all images of the product will be replaced by those specified in the import file')), - ); - - self::$default_values = array( - 'reference' => '', - 'supplier_reference' => '', - 'ean13' => '', - 'upc' => '', - 'wholesale_price' => 0, - 'price' => 0, - 'ecotax' => 0, - 'quantity' => 0, - 'weight' => 0, - 'default_on' => 0 - ); - break; - - case $this->entities[$this->l('Categories')]: - $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 *')), - 'parent' => array('label' => $this->l('Parent category')), - '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 URL')), - ); - - self::$default_values = array('active' => '1', 'parent' => '1', 'link_rewrite' => ''); - break; - - case $this->entities[$this->l('Products')]: - self::$validators['image'] = array('AdminImport', '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...)')), - 'price_tex' => array('label' => $this->l('Price tax excl.')), - 'price_tin' => array('label' => $this->l('Price tax incl.')), - 'id_tax_rules_group' => array('label' => $this->l('Tax rules id')), - 'wholesale_price' => array('label' => $this->l('Wholesale price')), - 'on_sale' => array('label' => $this->l('On sale (0/1)')), - 'reduction_price' => array('label' => $this->l('Discount amount')), - 'reduction_percent' => array('label' => $this->l('Discount percent')), - 'reduction_from' => array('label' => $this->l('Discount from (yyyy-mm-dd)')), - 'reduction_to' => array('label' => $this->l('Discount to (yyyy-mm-dd)')), - 'reference' => array('label' => $this->l('Reference #')), - 'supplier_reference' => array('label' => $this->l('Supplier reference #')), - 'supplier' => array('label' => $this->l('Supplier')), - 'manufacturer' => array('label' => $this->l('Manufacturer')), - 'ean13' => array('label' => $this->l('EAN13')), - 'upc' => array('label' => $this->l('UPC')), - 'ecotax' => array('label' => $this->l('Ecotax')), - 'weight' => array('label' => $this->l('Weight')), - 'quantity' => array('label' => $this->l('Quantity')), - 'description_short' => array('label' => $this->l('Short description')), - 'description' => array('label' => $this->l('Description')), - 'tags' => array('label' => $this->l('Tags (x,y,z...)')), - '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')), - 'available_now' => array('label' => $this->l('Text when in-stock')), - 'available_later' => array('label' => $this->l('Text if back-order allowed')), - 'available_for_order' => array('label' => $this->l('Available for order')), - 'date_add' => array('label' => $this->l('Date add product')), - 'show_price' => array('label' => $this->l('Show price')), - 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), - 'delete_existing_images' => array( - 'label' => $this->l('Delete existing images (0 = no, 1 = yes)'), - 'help' => $this->l('If you do not specify this column and you specify the column images, all images of the product will be replaced by those specified in the import file') - ), - 'features' => array('label' => $this->l('Feature(Name:Value:Position)'), - 'help' => $this->l('Position of the feature.')), - 'online_only' => array('label' => $this->l('Only available online')), - 'condition' => array('label' => $this->l('Condition')), - 'shop' => array( - 'label' => $this->l('ID / Name of shop'), - 'help' => $this->l('Ignore this field if you don\'t use multishop tool. If you leave this field empty, default shop will be used'), - ), - ); - - self::$default_values = array( - 'id_category' => array(1), - 'id_category_default' => 1, - 'active' => '1', - 'quantity' => 0, - 'price' => 0, - 'id_tax_rules_group' => 0, - 'description_short' => array((int)(Configuration::get('PS_LANG_DEFAULT')) => ''), - 'link_rewrite' => array((int)(Configuration::get('PS_LANG_DEFAULT')) => ''), - 'online_only' => 0, - 'condition' => 'new', - 'shop' => Configuration::get('PS_SHOP_DEFAULT'), - 'date_add' => date('Y-m-d H:i:s'), - 'condition' => 'new', - ); - break; - - case $this->entities[$this->l('Customers')]: - //Overwrite required_fields AS only email is required whereas other entities - self::$required_fields = array('email', 'passwd', 'lastname', 'firstname'); - - $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('Gender ID (Mr = 1, Ms = 2, else 0)')), - 'email' => array('label' => $this->l('E-mail *')), - 'passwd' => array('label' => $this->l('Password *')), - 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')), - 'lastname' => array('label' => $this->l('Lastname *')), - 'firstname' => array('label' => $this->l('Firstname *')), - 'newsletter' => array('label' => $this->l('Newsletter (0/1)')), - 'optin' => array('label' => $this->l('Opt in (0/1)')), - 'id_shop' => array( - 'label' => $this->l('ID / Name of shop'), - 'help' => $this->l('Ignore this field if you don\'t use multishop tool. If you leave this field empty, default shop will be used'), - ), - ); - - self::$default_values = array( - 'active' => '1', - 'id_shop' => Configuration::get('PS_SHOP_DEFAULT'), - ); - break; - - case $this->entities[$this->l('Addresses')]: - //Overwrite required_fields - self::$required_fields = array('lastname', 'firstname', 'address1', 'postcode', 'country', 'city'); - - $this->available_fields = array( - 'no' => array('label' => $this->l('Ignore this column')), - 'id' => array('label' => $this->l('ID')), - 'alias' => array('label' => $this->l('Alias *')), - 'active' => array('label' => $this->l('Active (0/1)')), - 'customer_email' => array('label' => $this->l('Customer e-mail')), - 'manufacturer' => array('label' => $this->l('Manufacturer')), - 'supplier' => array('label' => $this->l('Supplier')), - 'company' => array('label' => $this->l('Company')), - 'lastname' => array('label' => $this->l('Lastname *')), - 'firstname' => array('label' => $this->l('Firstname *')), - 'address1' => array('label' => $this->l('Address 1 *')), - 'address2' => array('label' => $this->l('Address 2')), - 'postcode' => array('label' => $this->l('Postcode*/ Zipcode*')), - 'city' => array('label' => $this->l('City *')), - 'country' => array('label' => $this->l('Country *')), - 'state' => array('label' => $this->l('State')), - 'other' => array('label' => $this->l('Other')), - 'phone' => array('label' => $this->l('Phone')), - 'phone_mobile' => array('label' => $this->l('Mobile Phone')), - 'vat_number' => array('label' => $this->l('VAT number')), - ); - - self::$default_values = array('alias' => 'Alias', 'postcode' => 'X'); - break; - - case $this->entities[$this->l('Manufacturers')]: - case $this->entities[$this->l('Suppliers')]: - //Overwrite validators AS name is not MultiLangField - self::$validators = array( - 'description' => array('AdminImport', 'createMultiLangField'), - 'description_short' => array('AdminImport', 'createMultiLangField'), - 'meta_title' => array('AdminImport', 'createMultiLangField'), - 'meta_keywords' => array('AdminImport', 'createMultiLangField'), - 'meta_description' => array('AdminImport', 'createMultiLangField'), - ); - - $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 *')), - 'description' => array('label' => $this->l('Description')), - 'short_description' => 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')), - 'shop' => array( - 'label' => $this->l('ID / Name of group shop'), - 'help' => $this->l('Ignore this field if you don\'t use multishop tool. If you leave this field empty, default shop will be used'), - ), - ); - - self::$default_values = array( - 'shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')), - ); - break; - } - parent::__construct(); - } - - private static function rewindBomAware($handle) - { - // A rewind wrapper that skip BOM signature wrongly - rewind($handle); - if (($bom = fread($handle,3)) != "\xEF\xBB\xBF") { - rewind($handle); - } - } - - private static function getBoolean($field) - { - return (boolean)$field; - } - - private static function getPrice($field) - { - $field = ((float)(str_replace(',', '.', $field))); - $field = ((float)(str_replace('%', '', $field))); - return $field; - } - - private static function split($field) - { - if (empty($field)) - return array(); - $separator = ((is_null(Tools::getValue('multiple_value_separator')) OR trim(Tools::getValue('multiple_value_separator')) == '' ) ? ',' : Tools::getValue('multiple_value_separator')); - $temp = tmpfile(); - fwrite($temp,$field); - rewind($temp); - $tab = fgetcsv($temp, MAX_LINE_SIZE, $separator); - fclose($temp); - if (empty($tab) || (!is_array($tab))) - return array(); - return $tab; - - } - - private static function createMultiLangField($field) - { - $languages = Language::getLanguages(false); - $res = array(); - foreach ($languages AS $lang) - $res[$lang['id_lang']] = $field; - return $res; - } - - private function getTypeValuesOptions($nb_c) - { - $i = 0; - $noPreSelect = array('price_tin', 'feature'); - - $options = ''; - foreach ($this->available_fields AS $k => $field) - { - $options .= '