From bcddfd878a3e7532018684f6023658a70ee61c91 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Mon, 13 Feb 2012 09:44:24 +0100
Subject: [PATCH] Fix: bad entity with ajax constant on/off

---
 htdocs/core/ajax/constantonoff.php | 4 ++--
 htdocs/core/lib/ajax.lib.php       | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php
index ac2f244969a..3ed30274972 100644
--- a/htdocs/core/ajax/constantonoff.php
+++ b/htdocs/core/ajax/constantonoff.php
@@ -47,10 +47,10 @@ print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY
 // Registering the location of boxes
 if ((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) )
 {
-	$entity = (GETPOST('entity','int') >= 0 ? GETPOST('entity','int') : $conf->entity);
+	$entity = GETPOST('entity','int');
 	$action = GETPOST('action', 'alpha');
 	$name = GETPOST('name', 'alpha');
-	
+
 	if ($user->admin)
 	{
 		if ($action == 'set')
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index ec500d7ae46..937c187d1e5 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2007-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2007-2011 Regis Houssin        <regis@dolibarr.fr>
+ * Copyright (C) 2007-2012 Regis Houssin        <regis@dolibarr.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -229,7 +229,7 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
 {
 	global $conf, $langs;
 
-	$entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
+	$entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity);
 
 	$out= '<script type="text/javascript">
 		$(function() {
-- 
GitLab