From 179da9a2206fcbe7d7bf98b71a6aa60918222f8b Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis.houssin@capnetworks.com>
Date: Thu, 25 Sep 2014 13:49:33 +0200
Subject: [PATCH] Fix: uniformize code

---
 htdocs/admin/expedition.php | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php
index d89b406280b..2efdfdd56ba 100644
--- a/htdocs/admin/expedition.php
+++ b/htdocs/admin/expedition.php
@@ -138,6 +138,35 @@ else if ($action == 'specimen')
 	}
 }
 
+// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
+else if ($action == 'setModuleOptions')
+{
+	$post_size=count($_POST);
+
+	$db->begin();
+
+	for($i=0;$i < $post_size;$i++)
+	{
+		if (array_key_exists('param'.$i,$_POST))
+		{
+			$param=GETPOST("param".$i,'alpha');
+			$value=GETPOST("value".$i,'alpha');
+			if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
+			if (! $res > 0) $error++;
+		}
+	}
+	if (! $error)
+	{
+		$db->commit();
+		setEventMessage($langs->trans("SetupSaved"));
+	}
+	else
+	{
+		$db->rollback();
+		setEventMessage($langs->trans("Error"),'errors');
+	}
+}
+
 // Activate a model
 else if ($action == 'set')
 {
@@ -175,14 +204,6 @@ else if ($action == 'setmodel')
 {
 	dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
 }
-else if ($action=='setModuleOptions') {
-	if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF_ODT_PATH",GETPOST('value1'),'chaine',0,'',$conf->entity))
-	{
-		// La constante qui a ete lue en avant du nouveau set
-		// on passe donc par une variable pour avoir un affichage coherent
-		$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH = GETPOST('value1');
-	}
-}
 
 
 /*
-- 
GitLab