diff --git a/ChangeLog.md b/ChangeLog.md index eada329..6973394 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ ## Not Released +- FIX : Remove std import menu, keep discount rule import menu - *30/03/2022* - 2.17.2 - FIX : CSRF token protection - *17/03/2022* - 2.17.1 - FIX : css and js files doesn't need to be PHP file (need module reload) - *05/02/2022* - 2.17.0 - NEW : Add project category filter for rules *28/12/2021* - 2.16.0 diff --git a/class/importrule.class.php b/class/importrule.class.php index 1ac7aa6..7f1c3e6 100644 --- a/class/importrule.class.php +++ b/class/importrule.class.php @@ -33,6 +33,15 @@ class ImportRule{ */ public $nbErrors; + /** + * @var string csv separator char + */ + public $csvSeparator = ';'; + + /** + * @var string csv category separator char + */ + public $csvCatSeparator = ','; /** * @var int number imported lines @@ -76,7 +85,7 @@ function idrGetDiscountFromCSV($filePath, $srcEncoding = 'latin1', $importKey='e $csvFile = fopen($filePath, 'r'); $this->db->begin(); - for ($i = 1; $csvValues = fgetcsv($csvFile, '64000', ";", '"'); $i++) { + for ($i = 1; $csvValues = fgetcsv($csvFile, '64000', $this->csvSeparator, '"'); $i++) { $csvValues = array_map( function ($val) use ($srcEncoding) { if ($srcEncoding === 'UTF-8') return trim($val); @@ -358,7 +367,7 @@ function setProduct($ref_product, $catProducts, $langs, $lineNumber, &$objDiscou }else{ if ($this->validate->isNotEmptyString($catProducts)){ // Test des catégories - $TCactProducts = explode(",",$catProducts); + $TCactProducts = explode($this->csvCatSeparator,$catProducts); foreach ($TCactProducts as $catproduct){ // in the were param we can't pass $cat->MAP_ID[$cat::TYPE_PRODUCT] instead of 0 ... @@ -454,7 +463,7 @@ function setCompany($ref_company, $catCompanies, $langs, $lineNumber, &$objDisco }else{ if ($this->validate->isNotEmptyString($catCompanies)){ // Test des catégories - $TCactCompanies = explode(",",$catCompanies); + $TCactCompanies = explode($this->csvCatSeparator,$catCompanies); foreach ($TCactCompanies as $catcompany){ if (!$this->isCatInType($catcompany,"label",2)){ diff --git a/core/modules/moddiscountrules.class.php b/core/modules/moddiscountrules.class.php index f90001a..1cdf65e 100644 --- a/core/modules/moddiscountrules.class.php +++ b/core/modules/moddiscountrules.class.php @@ -73,7 +73,7 @@ public function __construct($db) // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' - $this->version = '2.17.1'; + $this->version = '2.17.2'; // Key used in llx_const table to save module status enabled/disabled (where discountrules is value of property name of module in uppercase) $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); @@ -382,60 +382,60 @@ public function __construct($db) // Imports profiles provided by this module $r = 1; /* BEGIN MODULEBUILDER IMPORT MYOBJECT */ - - $this->import_code[$r] = $this->rights_class.'_'.$r; - $this->import_label[$r] = "discountrules"; // Translation key - $this->import_icon[$r] = 'discountrules@discountrules'; - // for example csv file - $this->import_fields_array[$r] = array( - "label" => "label", - "fk_project" => "refProject", - "fk_product" => "refProduct", - "fk_company" => "refCompany", - "fk_country" => "refCountry", - "priority_rank" =>"priorityRank", - "fk_c_typent" => "cTypeEnt", - - - - "all_category_product" =>"allCategoryProduct", - "all_category_company" =>"allCategoryCompany", - - "reduction" => "reduction", - "from_quantity" => "fromQuantity", - "product_price" => "productPrice", - "product_reduction_amount" => "productReductionAmount", - "date_from" =>"dateFrom", - "date_to" =>"dateTo", - "activation" =>"activation", - - - ); - - //@todo exemple à remplir - $this->import_examplevalues_array[$r] = array( - "label" => "ligne Exemple", - - "fk_project" => "PJ2201-0001", - "fk_product" => "PRODUIT_IMPORT_01", - "fk_company" => "KEVIN", - "fk_country" => "code pays. ex : US", - "priority_rank" =>"vide ou 0 si pas de priorité sinon numérique entre 1 et 5", - "fk_c_typent" => "cTypeEnt", - - - "all_category_product" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02", - "all_category_company" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02", - - "from_quantity" => "numérique", - "product_price" => "numérique", - "product_reduction_amount" => "5", - "reduction" => "10", - "date_from" =>"date au format jj/mm/yyyy", - "date_to" =>"date au format jj/mm/yyyy", - "activation" =>"vide/0 pour désactiver 1 pour activer", - - ); +// +// $this->import_code[$r] = $this->rights_class.'_'.$r; +// $this->import_label[$r] = "discountrules"; // Translation key +// $this->import_icon[$r] = 'discountrules@discountrules'; +// // for example csv file +// $this->import_fields_array[$r] = array( +// "label" => "label", +// "fk_project" => "refProject", +// "fk_product" => "refProduct", +// "fk_company" => "refCompany", +// "fk_country" => "refCountry", +// "priority_rank" =>"priorityRank", +// "fk_c_typent" => "cTypeEnt", +// +// +// +// "all_category_product" =>"allCategoryProduct", +// "all_category_company" =>"allCategoryCompany", +// +// "reduction" => "reduction", +// "from_quantity" => "fromQuantity", +// "product_price" => "productPrice", +// "product_reduction_amount" => "productReductionAmount", +// "date_from" =>"dateFrom", +// "date_to" =>"dateTo", +// "activation" =>"activation", +// +// +// ); +// +// //@todo exemple à remplir +// $this->import_examplevalues_array[$r] = array( +// "label" => "ligne Exemple", +// +// "fk_project" => "PJ2201-0001", +// "fk_product" => "PRODUIT_IMPORT_01", +// "fk_company" => "KEVIN", +// "fk_country" => "code pays. ex : US", +// "priority_rank" =>"vide ou 0 si pas de priorité sinon numérique entre 1 et 5", +// "fk_c_typent" => "cTypeEnt", +// +// +// "all_category_product" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02", +// "all_category_company" =>"vide pour toutes les catégories sinon liste des ref séparées par des virgules. ex : TCP01,TCP02", +// +// "from_quantity" => "numérique", +// "product_price" => "numérique", +// "product_reduction_amount" => "5", +// "reduction" => "10", +// "date_from" =>"date au format jj/mm/yyyy", +// "date_to" =>"date au format jj/mm/yyyy", +// "activation" =>"vide/0 pour désactiver 1 pour activer", +// +// ); /* END MODULEBUILDER IMPORT MYOBJECT */ diff --git a/discount_rules_import.php b/discount_rules_import.php index bb35f77..17c4d2b 100644 --- a/discount_rules_import.php +++ b/discount_rules_import.php @@ -55,6 +55,7 @@ $startLine = GETPOSTISSET('startLine','int') ? GETPOST('startLine','int') : 2; $endline = GETPOSTISSET('endline','int') ? GETPOST('endline','int') : ''; +$importRule = new ImportRule($db); /* * ACTION @@ -75,7 +76,6 @@ $filePath = $_FILES['CSVFile']['tmp_name']; - $importRule = new ImportRule($db); $importLogs = $importRule->idrGetDiscountFromCSV( $filePath, GETPOST('srcEncoding', 'alpha'), @@ -248,7 +248,7 @@ function _showImportForm($form,$startline,$endline) { function _showHelp() { - global $langs; + global $langs, $importRule; $key="csv"; $param="&datatoimport=discountrules_1"; @@ -257,7 +257,7 @@ function _showHelp() {