From 0f49ae8e44cb7ccae1947f84053e31bdf4109660 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Oct 2007 14:45:42 +0000 Subject: [PATCH] Uniformisation du code par utilisation de la fonction dolibarr_set_const --- htdocs/admin/adherent.php | 56 +++--------- htdocs/admin/editeur.php | 6 +- htdocs/admin/modules.php | 30 ++++-- htdocs/admin/produit.php | 187 +++++++++++++++++--------------------- 4 files changed, 123 insertions(+), 156 deletions(-) diff --git a/htdocs/admin/adherent.php b/htdocs/admin/adherent.php index 9df1ffe6673..d3abada682e 100644 --- a/htdocs/admin/adherent.php +++ b/htdocs/admin/adherent.php @@ -39,75 +39,47 @@ if (!$user->admin) accessforbidden(); -// positionne la variable pour le test d'affichage de l'icone - -$main_use_mailman = ADHERENT_USE_MAILMAN; -$main_use_glasnost = ADHERENT_USE_GLASNOST; -$main_use_glasnost_auto = ADHERENT_USE_GLASNOST_AUTO; -$main_use_spip = ADHERENT_USE_SPIP; -$main_use_spip_auto = ADHERENT_USE_SPIP_AUTO; - $typeconst=array('yesno','texte','chaine'); -$var=True; // Action mise a jour ou ajout d'une constante if ($_POST["action"] == 'update' || $_POST["action"] == 'add') { - if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'')) + $result=dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:''); + if ($result < 0) { print $db->error(); } - else - { - Header("Location: adherent.php"); - exit; - } } // Action activation d'un sous module du module adhérent if ($_GET["action"] == 'set') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$_GET["name"]."' ;"; - $result=$db->query($sql); - if (! $result) { - dolibarr_print_error($db); - exit; - } - - $sql =''; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."const(name,value,visible) values ('".$_GET["name"]."','".$_GET["value"]."', 0);"; - - $result=$db->query($sql); - if ($result) - { - Header("Location: adherent.php"); - exit; - } - else { - dolibarr_print_error($db); - exit; - } + $result=dolibarr_set_const($db, $_GET["name"],$_GET["value"]); + if ($result < 0) + { + print $db->error(); + } } // Action désactivation d'un sous module du module adhérent if ($_GET["action"] == 'unset') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$_GET["name"]."'"; - - if ($db->query($sql)) - { - Header("Location: adherent.php"); - exit; - } + $result=dolibarr_del_const($db,$_GET["name"]); + if ($result < 0) + { + print $db->error(); + } } + llxHeader(); /* * Interface de configuration de certaines variables de la partie adherent */ +$var=True; print_fiche_titre($langs->trans("MembersSetup"),'','setup'); print "
"; diff --git a/htdocs/admin/editeur.php b/htdocs/admin/editeur.php index 9a4d5a899c8..ae1ada7b125 100644 --- a/htdocs/admin/editeur.php +++ b/htdocs/admin/editeur.php @@ -38,7 +38,11 @@ if (!$user->admin) if ($_POST["action"] == 'set') { $name = "EDITEUR_LIVRE_FORMAT_".time(); - dolibarr_set_const($db, $name, $_POST["format"]); + $result=dolibarr_set_const($db, $name, $_POST["format"]); + if ($result < 0) + { + print $db->error(); + } } // Action désactivation d'un sous module du module adhérent diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 7b60dc45594..dd9116c647c 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -180,12 +180,26 @@ while (($file = readdir($handle))!==false) $j = 1000 + $i; } - $modules[$i] = $objMod; - $filename[$i]= $modName; - $orders[$i] = "$objMod->family"."_".$j; // Tri par famille puis numero module - $categ[$objMod->special]++; // Array of all different modules categories - $j++; - $i++; + $modulequalified=1; + + // We discard modules that does not respect constraint on menu handlers + if ($objMod->needleftmenu && sizeof($objMod->needleftmenu) && ! in_array($conf->left_menu,$objMod->needleftmenu)) $modulequalified=0; + if ($objMod->needtopmenu && sizeof($objMod->needtopmenu) && ! in_array($conf->top_menu,$objMod->needtopmenu)) $modulequalified=0; + + // We dsicard modules according to features level (if active we always show them) + $const_name = $objMod->const_name; + if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0; + if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0; + + if ($modulequalified) + { + $modules[$i] = $objMod; + $filename[$i]= $modName; + $orders[$i] = "$objMod->family"."_".$j; // Tri par famille puis numero module + $categ[$objMod->special]++; // Array of all different modules categories + $j++; + $i++; + } } } } @@ -280,10 +294,6 @@ foreach ($orders as $key => $value) $modName = $filename[$key]; $objMod = $modules[$key]; - // Show modules according to features level - if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - $const_name = $objMod->const_name; if ($oldfamily && $family!=$oldfamily && $atleastoneforfamily) { diff --git a/htdocs/admin/produit.php b/htdocs/admin/produit.php index 84cb13c0205..43b2dcdff13 100644 --- a/htdocs/admin/produit.php +++ b/htdocs/admin/produit.php @@ -42,14 +42,10 @@ if (!$user->admin) if ($_POST["action"] == 'nbprod') { dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", $_POST["value"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'multiprix_num') { dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", $_POST["value"]); - Header("Location: produit.php"); - exit; } if ($_POST["action"] == 'multiprix') { @@ -68,16 +64,12 @@ if ($_POST["action"] == 'multiprix') } dolibarr_set_const($db, "PRODUIT_MULTIPRICES", $_POST["activate_multiprix"]); dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); - Header("Location: produit.php"); - exit; } else { dolibarr_syslog("Table definition for ".MAIN_DB_PREFIX."societe already ok"); 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') @@ -99,66 +91,47 @@ else if ($_POST["action"] == 'sousproduits') else { dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); - Header("Location: produit.php"); - exit; } } else { dolibarr_syslog("Table definition already ok"); dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $_POST["activate_sousproduits"]); - Header("Location: produit.php"); - exit; } } else if ($_POST["action"] == 'changeproductdesc') { dolibarr_set_const($db, "PRODUIT_CHANGE_PROD_DESC", $_POST["activate_changeproductdesc"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'viewProdDescInForm') { dolibarr_set_const($db, "PRODUIT_DESC_IN_FORM", $_POST["activate_viewProdDescInForm"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'confirmDeleteProdLineInForm') { dolibarr_set_const($db, "PRODUIT_CONFIRM_DELETE_LINE", $_POST["activate_confirmDeleteProdLineInForm"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'ProductCanvasAbility') { dolibarr_set_const($db, "PRODUCT_CANVAS_ABILITY", $_POST["ProductCanvasAbility"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'usesearchtoselectproduct') { dolibarr_set_const($db, "PRODUIT_USE_SEARCH_TO_SELECT", $_POST["activate_usesearchtoselectproduct"]); - Header("Location: produit.php"); - exit; } else if ($_GET["action"] == 'set') { - $const = "PRODUIT_SPECIAL_".strtoupper($_GET["spe"]); - dolibarr_set_const($db, $const, $_GET["value"]); - Header("Location: produit.php"); - exit; + $const = "PRODUIT_SPECIAL_".strtoupper($_GET["spe"]); + if ($_GET["value"]) dolibarr_set_const($db, $const, $_GET["value"]); + else dolibarr_del_const($db, $const); } else if ($_POST["action"] == 'useecotaxe') { dolibarr_set_const($db, "PRODUIT_USE_ECOTAXE", $_POST["activate_useecotaxe"]); - Header("Location: produit.php"); - exit; } else if ($_POST["action"] == 'setdefaultbarcodetype') { dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $_POST["coder_id"]); - Header("Location: produit.php"); - exit; } @@ -198,7 +171,7 @@ $var=!$var; print "
"; print ""; print ""; -print ''.$langs->trans("MultiPricesAbility").''; +print ''.$langs->trans("MultiPricesAbility").''; print ''; print $html->selectyesno("activate_multiprix",$conf->global->PRODUIT_MULTIPRICES,1); print ''; @@ -227,7 +200,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("AssociatedProductsAbility").''; +print ''.$langs->trans("AssociatedProductsAbility").''; print ''; print $html->selectyesno("activate_sousproduits",$conf->global->PRODUIT_SOUSPRODUITS,1); print ''; @@ -241,7 +214,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("UseSearchToSelectProduct").''; +print ''.$langs->trans("UseSearchToSelectProduct").''; if (! $conf->use_ajax) { print ''; @@ -265,7 +238,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("ModifyProductDescAbility").''; +print ''.$langs->trans("ModifyProductDescAbility").''; print ''; print $html->selectyesno("activate_changeproductdesc",$conf->global->PRODUIT_CHANGE_PROD_DESC,1); print ''; @@ -279,7 +252,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("ViewProductDescInFormAbility").''; +print ''.$langs->trans("ViewProductDescInFormAbility").''; print ''; print $html->selectyesno("activate_viewProdDescInForm",$conf->global->PRODUIT_DESC_IN_FORM,1); print ''; @@ -293,7 +266,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("ConfirmDeleteProductLineAbility").''; +print ''.$langs->trans("ConfirmDeleteProductLineAbility").''; print ''; print $html->selectyesno("activate_confirmDeleteProdLineInForm",$conf->global->PRODUIT_CONFIRM_DELETE_LINE,1); print ''; @@ -307,7 +280,7 @@ $var=!$var; print ""; print ""; print ""; -print ''.$langs->trans("UseEcoTaxeAbility").''; +print ''.$langs->trans("UseEcoTaxeAbility").''; print ''; print $html->selectyesno("activate_useecotaxe",$conf->global->PRODUIT_USE_ECOTAXE,1); print ''; @@ -321,83 +294,91 @@ if ($conf->barcode->enabled && $conf->global->PRODUIT_USE_BARCODE) { $var=!$var; print ""; - print ""; - print ""; - print ''.$langs->trans("SetDefaultBarcodeType").''; - print ''; - print $html->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"coder_id",1); - print ''; - print ''; - print ""; - print ''; - print '
'; + print ""; + print ""; + print ''.$langs->trans("SetDefaultBarcodeType").''; + print ''; + print $html->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"coder_id",1); + print ''; + print ''; + print ""; + print ''; + print ''; } -print ''; -print " ".$langs->trans("ProductSpecial")."\n"; -print " ".$langs->trans("Value")."\n"; -print "  \n"; -print '
'; -print ''; -print ""; -print ''.$langs->trans("ProductCanvasAbility").''; -print ''; -print $html->selectyesno("ProductCanvasAbility",$conf->global->PRODUCT_CANVAS_ABILITY,1); -print ''; -print ''; -print ""; -print '
'; - -require_once(DOL_DOCUMENT_ROOT . "/product.class.php"); -$dir = DOL_DOCUMENT_ROOT . "/product/canvas/"; - -if ($conf->global->PRODUCT_CANVAS_ABILITY==="1") +if ($conf->left_menu == 'default.php') { - if(is_dir($dir) ) - { - $handle=opendir($dir); - $var=true; - - while (($file = readdir($handle))!==false) + // Propose utilisation de canvas. + // Ces derniers ne sont geres que par le menu default + $var = false; + + print ''; + print " ".$langs->trans("ProductSpecial")."\n"; + print " ".$langs->trans("Value")."\n"; + print "  \n"; + + print '
'; + print ''; + print ""; + print ''.$langs->trans("ProductCanvasAbility").''; + print ''; + print $html->selectyesno("ProductCanvasAbility",$conf->global->PRODUCT_CANVAS_ABILITY,1); + print ''; + print ''; + print ""; + print '
'; + + require_once(DOL_DOCUMENT_ROOT . "/product.class.php"); + $dir = DOL_DOCUMENT_ROOT . "/product/canvas/"; + + if ($conf->global->PRODUCT_CANVAS_ABILITY) { - if (substr($file, strlen($file) -10) == '.class.php' && substr($file,0,8) == 'product.') - { - $parts = explode('.',$file); - $classname = 'Product'.ucfirst($parts[1]); - require_once($dir.$file); - $module = new $classname(); - - $var=!$var; - print ""; - - print $module->description; - - print ''; - - if (defined ("PRODUIT_SPECIAL_LIVRE") && PRODUIT_SPECIAL_LIVRE == 1) + if(is_dir($dir) ) { - print img_tick(); - print ''; - print ''.$langs->trans("Disable").''; + $handle=opendir($dir); + + while (($file = readdir($handle))!==false) + { + if (substr($file, strlen($file) -10) == '.class.php' && substr($file,0,8) == 'product.') + { + $parts = explode('.',$file); + $classname = 'Product'.ucfirst($parts[1]); + require_once($dir.$file); + $module = new $classname(); + + $var=!$var; + print ""; + + print $module->description; + + print ''; + + $const = "PRODUIT_SPECIAL_".strtoupper($parts[1]); + if ($conf->global->$const) + { + print img_tick(); + print ''; + print ''.$langs->trans("Disable").''; + } + else + { + print ' '; + print ''.$langs->trans("Activate").''; + } + + print ''; + } + } + closedir($handle); } - else + else { - print ' '; - print ''.$langs->trans("Activate").''; + print "ERROR: $dir is not a directory !\n"; } - - print ''; - } } - closedir($handle); - } - else - { - print "ERROR: $dir is not a directory !\n"; - } + print ''; } -print ''; $db->close();