diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 235ffcd304c..1445de07d24 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2083,3 +2083,4 @@ CountryIfSpecificToOneCountry=Country (if specific to a given country) YouMayFindSecurityAdviceHere=You may find security advisory here ModuleActivatedMayExposeInformation=This module may expose sensitive data. If you don't need it, disable it. ModuleActivatedDoNotUseInProduction=A module designed for the development has been enabled. Do not enable it on a production environment. +CombinationsSeparator=Separator character for product combinations \ No newline at end of file diff --git a/htdocs/projet/tasks/contact.php b/htdocs/projet/tasks/contact.php index 9c71a6f7042..3f44422f158 100644 --- a/htdocs/projet/tasks/contact.php +++ b/htdocs/projet/tasks/contact.php @@ -80,13 +80,11 @@ if ($action == 'addcontact' && $user->rights->projet->creer) } } - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject ? '&withproject=1' : '')); exit; - } else {$nbofcontacts - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); } else { @@ -98,8 +96,7 @@ if ($action == 'addcontact' && $user->rights->projet->creer) // bascule du statut d'un contact if ($action == 'swapstatut' && $user->rights->projet->creer) { - if ($object->fetch($id, $ref)) - { + if ($object->fetch($id, $ref)) { $result = $object->swapContactStatus(GETPOST('ligne')); } else { dol_print_error($db); @@ -408,7 +405,6 @@ if ($id > 0 || !empty($ref)) print ''; if ($withproject) print ''; - print ''; print ''; diff --git a/htdocs/variants/admin/admin.php b/htdocs/variants/admin/admin.php index 7e5683e710b..64209076916 100644 --- a/htdocs/variants/admin/admin.php +++ b/htdocs/variants/admin/admin.php @@ -22,44 +22,57 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; $langs->loadLangs(array("admin", "products")); +$action = GETPOST('action', 'alphanohtml'); + // Security check if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) accessforbidden(); -if ($_POST) { +$error = 0; + + +/* + * Actions + */ + +if ($action) { $value = GETPOST('PRODUIT_ATTRIBUTES_HIDECHILD'); - if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_HIDECHILD', $value, 'chaine', 0, '', $conf->entity)) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - } else { + if (!dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_HIDECHILD', $value, 'chaine', 0, '', $conf->entity)) { setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors'); + $error++; } - if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_SEPARATOR', GETPOST('PRODUIT_ATTRIBUTES_SEPARATOR'), 'chaine', 0, '', $conf->entity)) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - } else { + if (!dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_SEPARATOR', GETPOST('PRODUIT_ATTRIBUTES_SEPARATOR'), 'chaine', 0, '', $conf->entity)) { setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors'); + $error++; + } + + if (!$error) { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); } } -$title = $langs->trans('ModuleSetup').' '.$langs->trans('ProductAttributes'); +$title = $langs->trans('ModuleSetup').' '.$langs->trans('Module610Name'); llxHeader('', $title); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title, $linkback, 'title_setup'); -print dol_get_fiche_head(array(), 'general', $tab, 0, 'product'); - print '
'; print ''; +print ''; print ''; + print ''; -print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; + print ''; + print ''; if (isset($conf->global->PRODUIT_ATTRIBUTES_SEPARATOR)) { $separator = $conf->global->PRODUIT_ATTRIBUTES_SEPARATOR; @@ -67,8 +80,11 @@ if (isset($conf->global->PRODUIT_ATTRIBUTES_SEPARATOR)) { $separator = "_"; } print ''; + print '
'.$langs->trans("Parameters").''."\n"; -print ''.$langs->trans("Value").''."\n"; -print ' 
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'.$langs->trans('HideProductCombinations').''; print $form->selectyesno("PRODUIT_ATTRIBUTES_HIDECHILD", $conf->global->PRODUIT_ATTRIBUTES_HIDECHILD, 1).'
'.$langs->trans('CombinationsSeparator').'
'; + print '
'; + print '
'; // End of page diff --git a/htdocs/variants/card.php b/htdocs/variants/card.php index 057e184d184..6cda745056a 100644 --- a/htdocs/variants/card.php +++ b/htdocs/variants/card.php @@ -43,7 +43,7 @@ if ($object->fetch($id) < 1) { if ($cancel) $action = ''; -if ($_POST) { +if ($action) { if ($action == 'edit') { $object->ref = $ref; $object->label = $label; diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index f690ec8e3f6..3a2936d0df5 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -72,7 +72,7 @@ $selectedvariant = $_SESSION['addvariant_'.$object->id]; if ($cancel) { $action = ''; - $massactions = ''; + $massaction = ''; unset($_SESSION['addvariant_'.$object->id]); } @@ -101,179 +101,177 @@ $prodcomb2val = new ProductCombination2ValuePair($db); $productCombination2ValuePairs1 = array(); -if ($_POST) { - if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST('selectvariant', 'alpha')) // We click on Create all defined combinations - { - //$features = GETPOST('features', 'array'); - $features = $_SESSION['addvariant_'.$object->id]; +if (($action == 'add' || $action == 'create') && empty($massaction) && !GETPOST('selectvariant', 'alpha')) // We click on Create all defined combinations +{ + //$features = GETPOST('features', 'array'); + $features = $_SESSION['addvariant_'.$object->id]; - if (!$features) { - setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors'); - } else { - $reference = trim($reference); - if (empty($reference)) { - $reference = false; - } - $weight_impact = price2num($weight_impact); - $price_impact = price2num($price_impact); - - // for conf PRODUIT_MULTIPRICES - if ($conf->global->PRODUIT_MULTIPRICES) { - $level_price_impact = array_map('price2num', $level_price_impact); - } - else { - $level_price_impact = array(1 => $price_impact); - $level_price_impact_percent = array(1 => $price_impact_percent); - } - - $sanit_features = array(); - - //First, sanitize - foreach ($features as $feature) { - $explode = explode(':', $feature); - - if ($prodattr->fetch($explode[0]) < 0) { - continue; - } - - if ($prodattr_val->fetch($explode[1]) < 0) { - continue; - } - - // Valuepair - $sanit_features[$explode[0]] = $explode[1]; - - $tmp = new ProductCombination2ValuePair($db); - $tmp->fk_prod_attr = $explode[0]; - $tmp->fk_prod_attr_val = $explode[1]; - - $productCombination2ValuePairs1[] = $tmp; - } - - $db->begin(); - - // sanit_feature is an array with 1 (and only 1) value per attribute. - // For example: Color->blue, Size->Small, Option->2 - //var_dump($sanit_features); - if (!$prodcomb->fetchByProductCombination2ValuePairs($id, $sanit_features)) - { - $result = $prodcomb->createProductCombination($user, $object, $sanit_features, array(), $level_price_impact_percent, $level_price_impact, $weight_impact, $reference); - if ($result > 0) - { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - unset($_SESSION['addvariant_'.$object->id]); - - $db->commit(); - header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); - exit(); - } else { - $langs->load("errors"); - setEventMessages($prodcomb->error, $prodcomb->errors, 'errors'); - } - } else { - setEventMessages($langs->trans('ErrorRecordAlreadyExists'), null, 'errors'); - } - - $db->rollback(); + if (!$features) { + setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors'); + } else { + $reference = trim($reference); + if (empty($reference)) { + $reference = false; } - } elseif (!empty($massaction)) - { - $bulkaction = $massaction; - $error = 0; - - - - $db->begin(); - - foreach ($toselect as $prodid) { - // need create new of Product to prevent rename dir behavior - $prodstatic = new Product($db); - - if ($prodstatic->fetch($prodid) < 0) { - continue; - } - - if ($bulkaction == 'on_sell') { - $prodstatic->status = 1; - $res = $prodstatic->update($prodstatic->id, $user); - } elseif ($bulkaction == 'on_buy') { - $prodstatic->status_buy = 1; - $res = $prodstatic->update($prodstatic->id, $user); - } elseif ($bulkaction == 'not_sell') { - $prodstatic->status = 0; - $res = $prodstatic->update($prodstatic->id, $user); - } elseif ($bulkaction == 'not_buy') { - $prodstatic->status_buy = 0; - $res = $prodstatic->update($prodstatic->id, $user); - } elseif ($bulkaction == 'delete') { - $res = $prodstatic->delete($user, $prodstatic->id); - } else { - break; - } - - if ($res <= 0) { - $error++; - break; - } - } - - if ($error) { - $db->rollback(); - - if ($prodstatic->error) { - setEventMessages($prodstatic->error, $prodstatic->errors, 'errors'); - } else { - setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors'); - } - } else { - $db->commit(); - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - } - } elseif ($valueid > 0) { - if ($prodcomb->fetch($valueid) < 0) { - dol_print_error($db, $langs->trans('ErrorRecordNotFound')); - exit(); - } - - $prodcomb->variation_weight = $weight_impact; + $weight_impact = price2num($weight_impact); + $price_impact = price2num($price_impact); // for conf PRODUIT_MULTIPRICES if ($conf->global->PRODUIT_MULTIPRICES) { $level_price_impact = array_map('price2num', $level_price_impact); - - $prodcomb->variation_price = $level_price_impact[1]; - $prodcomb->variation_price_percentage = (bool) $level_price_impact_percent[1]; } else { $level_price_impact = array(1 => $price_impact); $level_price_impact_percent = array(1 => $price_impact_percent); - - $prodcomb->variation_price = $price_impact; - $prodcomb->variation_price_percentage = $price_impact_percent; } - if ($conf->global->PRODUIT_MULTIPRICES) { - $prodcomb->combination_price_levels = array(); - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { - $productCombinationLevel = new ProductCombinationLevel($db); - $productCombinationLevel->fk_product_attribute_combination = $prodcomb->id; - $productCombinationLevel->fk_price_level = $i; - $productCombinationLevel->variation_price = $level_price_impact[$i]; - $productCombinationLevel->variation_price_percentage = (bool) $level_price_impact_percent[$i]; - $prodcomb->combination_price_levels[$i] = $productCombinationLevel; + $sanit_features = array(); + + //First, sanitize + foreach ($features as $feature) { + $explode = explode(':', $feature); + + if ($prodattr->fetch($explode[0]) < 0) { + continue; } + + if ($prodattr_val->fetch($explode[1]) < 0) { + continue; + } + + // Valuepair + $sanit_features[$explode[0]] = $explode[1]; + + $tmp = new ProductCombination2ValuePair($db); + $tmp->fk_prod_attr = $explode[0]; + $tmp->fk_prod_attr_val = $explode[1]; + + $productCombination2ValuePairs1[] = $tmp; } - if ($prodcomb->update($user) > 0) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); - exit(); + $db->begin(); + + // sanit_feature is an array with 1 (and only 1) value per attribute. + // For example: Color->blue, Size->Small, Option->2 + //var_dump($sanit_features); + if (!$prodcomb->fetchByProductCombination2ValuePairs($id, $sanit_features)) + { + $result = $prodcomb->createProductCombination($user, $object, $sanit_features, array(), $level_price_impact_percent, $level_price_impact, $weight_impact, $reference); + if ($result > 0) + { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + unset($_SESSION['addvariant_'.$object->id]); + + $db->commit(); + header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); + exit(); + } else { + $langs->load("errors"); + setEventMessages($prodcomb->error, $prodcomb->errors, 'errors'); + } } else { - setEventMessages($prodcomb->error, $prodcomb->errors, 'errors'); + setEventMessages($langs->trans('ErrorRecordAlreadyExists'), null, 'errors'); + } + + $db->rollback(); + } +} elseif (!empty($massaction)) { + $bulkaction = $massaction; + $error = 0; + + + + $db->begin(); + + foreach ($toselect as $prodid) { + // need create new of Product to prevent rename dir behavior + $prodstatic = new Product($db); + + if ($prodstatic->fetch($prodid) < 0) { + continue; + } + + if ($bulkaction == 'on_sell') { + $prodstatic->status = 1; + $res = $prodstatic->update($prodstatic->id, $user); + } elseif ($bulkaction == 'on_buy') { + $prodstatic->status_buy = 1; + $res = $prodstatic->update($prodstatic->id, $user); + } elseif ($bulkaction == 'not_sell') { + $prodstatic->status = 0; + $res = $prodstatic->update($prodstatic->id, $user); + } elseif ($bulkaction == 'not_buy') { + $prodstatic->status_buy = 0; + $res = $prodstatic->update($prodstatic->id, $user); + } elseif ($bulkaction == 'delete') { + $res = $prodstatic->delete($user, $prodstatic->id); + } else { + break; + } + + if ($res <= 0) { + $error++; + break; } } + + if ($error) { + $db->rollback(); + + if ($prodstatic->error) { + setEventMessages($prodstatic->error, $prodstatic->errors, 'errors'); + } else { + setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors'); + } + } else { + $db->commit(); + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + } +} elseif ($valueid > 0) { + if ($prodcomb->fetch($valueid) < 0) { + dol_print_error($db, $langs->trans('ErrorRecordNotFound')); + exit(); + } + + $prodcomb->variation_weight = $weight_impact; + + // for conf PRODUIT_MULTIPRICES + if ($conf->global->PRODUIT_MULTIPRICES) { + $level_price_impact = array_map('price2num', $level_price_impact); + + $prodcomb->variation_price = $level_price_impact[1]; + $prodcomb->variation_price_percentage = (bool) $level_price_impact_percent[1]; + } + else { + $level_price_impact = array(1 => $price_impact); + $level_price_impact_percent = array(1 => $price_impact_percent); + + $prodcomb->variation_price = $price_impact; + $prodcomb->variation_price_percentage = $price_impact_percent; + } + + if ($conf->global->PRODUIT_MULTIPRICES) { + $prodcomb->combination_price_levels = array(); + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { + $productCombinationLevel = new ProductCombinationLevel($db); + $productCombinationLevel->fk_product_attribute_combination = $prodcomb->id; + $productCombinationLevel->fk_price_level = $i; + $productCombinationLevel->variation_price = $level_price_impact[$i]; + $productCombinationLevel->variation_price_percentage = (bool) $level_price_impact_percent[$i]; + $prodcomb->combination_price_levels[$i] = $productCombinationLevel; + } + } + + if ($prodcomb->update($user) > 0) { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); + exit(); + } else { + setEventMessages($prodcomb->error, $prodcomb->errors, 'errors'); + } } + // Reload variants $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id); diff --git a/htdocs/variants/create.php b/htdocs/variants/create.php index ce00ac51a1a..84530e01cb5 100644 --- a/htdocs/variants/create.php +++ b/htdocs/variants/create.php @@ -22,13 +22,14 @@ require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; $ref = GETPOST('ref', 'alpha'); $label = GETPOST('label', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); +$action = GETPOST('action', 'alpha'); /* * Actions */ -if ($_POST) { +if ($action == 'create') { if (empty($ref) || empty($label)) { setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors'); } else {