From f352f5cba2f19e141796d06c4fea1447bb5c9e00 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Tue, 24 Jan 2012 01:40:17 +0800
Subject: [PATCH] Fix: add current entity if not defined

---
 htdocs/core/ajax/constantonoff.php | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php
index 1231b4ff9eb..277d62191c3 100644
--- a/htdocs/core/ajax/constantonoff.php
+++ b/htdocs/core/ajax/constantonoff.php
@@ -45,17 +45,21 @@ top_httphead();
 print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
 
 // Registering the location of boxes
-if((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) )
+if ((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) )
 {
+	$entity = (GETPOST('entity','int') ? GETPOST('entity','int') : $conf->entity);
+	$action = GETPOST('action', 'alpha');
+	$name = GETPOST('name', 'alpha');
+	
 	if ($user->admin)
 	{
-		if ($_GET['action'] == 'set')
+		if ($action == 'set')
 		{
-			dolibarr_set_const($db, GETPOST('name','alpha'), 1, 'chaine', 0, '', GETPOST('entity','int'));
+			dolibarr_set_const($db, $name, 1, 'chaine', 0, '', $entity);
 		}
-		else if ($_GET['action'] == 'del')
+		else if ($action == 'del')
 		{
-			dolibarr_del_const($db, GETPOST('name','alpha'), GETPOST('entity','int'));
+			dolibarr_del_const($db, $name, $entity);
 		}
 	}
 }
-- 
GitLab