diff --git a/htdocs/admin/produit.php b/htdocs/admin/produit.php index 80d4f5b9033cbeab13f4d2e018712358a44769ca..1aaf2e01f5d52d76acbc0a062296a3773a7dcaa1 100644 --- a/htdocs/admin/produit.php +++ b/htdocs/admin/produit.php @@ -50,71 +50,66 @@ else if ($_POST["action"] == 'multiprix_num') } if ($_POST["action"] == 'multiprix') { - if ($_POST["activate_multiprix"] == 1) + $res=$db -> desc_table(MAIN_DB_PREFIX."product_price","price_level"); + if(! $db -> fetch_row()) { - $res=$db -> desc_table(MAIN_DB_PREFIX."product_price","price_level"); - if(! $db -> fetch_row()) - { - // on ajoute le champ price_level dans la table societe - if(! $db -> add_field(MAIN_DB_PREFIX."societe","price_level",$field_desc)) - { - dolibarr_print_error($db); - print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; - } - // on cr�e la table societe_prices - else - { - $table = MAIN_DB_PREFIX."societe_prices"; - $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); - $fields['fk_soc'] = array('type'=>'int','value'=>'11','null'=>'not null','default'=> '0'); - $fields['tms'] = array('type'=>'timestamp','value'=>'14','null'=>'not null'); - $fields['datec'] = array('type'=>'datetime','default'=> 'null'); - $fields['fk_user_author'] = array('type'=>'int','value'=>'11','default'=> 'null'); - $fields['price_level'] = array('type'=>'tinyint','value'=>'4','default'=> '1'); - if(! $db -> create_table($table,$fields,"rowid","InnoDB")) - { - dolibarr_print_error($db); - print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; - } - else - { - dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]); - dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); - Header("Location: produit.php"); - } + // on ajoute le champ price_level dans la table societe + if(! $db -> add_field(MAIN_DB_PREFIX."societe","price_level",$field_desc)) + { + dolibarr_print_error($db); + print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; + } + // on cr�e la table societe_prices + else + { + $table = MAIN_DB_PREFIX."societe_prices"; + $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); + $fields['fk_soc'] = array('type'=>'int','value'=>'11','null'=>'not null','default'=> '0'); + $fields['tms'] = array('type'=>'timestamp','value'=>'14','null'=>'not null'); + $fields['datec'] = array('type'=>'datetime','default'=> 'null'); + $fields['fk_user_author'] = array('type'=>'int','value'=>'11','default'=> 'null'); + $fields['price_level'] = array('type'=>'tinyint','value'=>'4','default'=> '1'); + if(! $db -> create_table($table,$fields,"rowid","InnoDB")) + { + dolibarr_print_error($db); + print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; + } + else + { + dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]); + dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); + Header("Location: produit.php"); } } } else { dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]); + dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); Header("Location: produit.php"); } exit; } else if ($_POST["action"] == 'sousproduits') { - if ($_POST["activate_sousproduits"] == 1) - { - $res=$db -> desc_table(MAIN_DB_PREFIX."product_association"); - if(! $db -> fetch_row()) - { - $table = MAIN_DB_PREFIX."product_association"; - $fields['fk_product_pere'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0'); - $fields['fk_product_fils'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0'); - $fields['qty'] = array('type'=>'double','default'=> 'null'); - $keys['idx_product_association_fk_product_pere'] = "fk_product_pere" ; - $keys['idx_product_association_fk_product_fils'] = "fk_product_fils" ; - if(! $db -> create_table($table,$fields,"","InnoDB","","",$keys)) - { - dolibarr_print_error($db); - print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; - } + $res=$db -> desc_table(MAIN_DB_PREFIX."product_association"); + if(! $db -> fetch_row()) + { + $table = MAIN_DB_PREFIX."product_association"; + $fields['fk_product_pere'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0'); + $fields['fk_product_fils'] = array('type'=>'int','value'=>'11','null'=> 'not null','default'=> '0'); + $fields['qty'] = array('type'=>'double','default'=> 'null'); + $keys['idx_product_association_fk_product_pere'] = "fk_product_pere" ; + $keys['idx_product_association_fk_product_fils'] = "fk_product_fils" ; + if(! $db -> create_table($table,$fields,"","InnoDB","","",$keys)) + { + dolibarr_print_error($db); + print "<script language='JavaScript'>setTimeout(\"document.location='./produit.php'\",5000);</script>"; } else - { - dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); - Header("Location: produit.php"); + { + dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); + Header("Location: produit.php"); } } else