diff --git a/htdocs/admin/boxes.php b/htdocs/admin/boxes.php index 31d313b84e9..5c2c8176842 100644 --- a/htdocs/admin/boxes.php +++ b/htdocs/admin/boxes.php @@ -57,7 +57,7 @@ if ($action == 'add') $db->begin(); - // Initialize distinctfkuser with all already existing values of fk_user (user that use a personalized view of boxes for pos) + // Initialize distinct fkuser with all already existing values of fk_user (user that use a personalized view of boxes for page "pos") $distinctfkuser=array(); if (! $error) { @@ -85,14 +85,31 @@ if ($action == 'add') } } + $distinctfkuser['0']='0'; // Add entry for fk_user = 0. We must use string as key and val + foreach($distinctfkuser as $fk_user) { - if (! $error && $fk_user != 0) // We will add fk_user = 0 later. + if (! $error && $fk_user != '') { + $nbboxonleft=$nbboxonright=0; + $sql = "SELECT box_order FROM ".MAIN_DB_PREFIX."boxes WHERE position = ".GETPOST("pos","alpha")." AND fk_user = ".$fk_user." AND entity = ".$conf->entity; + dol_syslog("boxes.php activate box sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + while($obj = $db->fetch_object($resql)) + { + $boxorder=$obj->box_order; + if (preg_match('/A/',$boxorder)) $nbboxonleft++; + if (preg_match('/B/',$boxorder)) $nbboxonright++; + } + } + else dol_print_error($db); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes ("; $sql.= "box_id, position, box_order, fk_user, entity"; $sql.= ") values ("; - $sql.= GETPOST("boxid","int").", ".GETPOST("pos","alpha").", 'A01', ".$fk_user.", ".$conf->entity; + $sql.= GETPOST("boxid","int").", ".GETPOST("pos","alpha").", '".(($nbboxonleft > $nbboxonright) ? 'B01' : 'A01')."', ".$fk_user.", ".$conf->entity; $sql.= ")"; dol_syslog("boxes.php activate box sql=".$sql); @@ -105,24 +122,6 @@ if ($action == 'add') } } - // If value 0 was not included, we add it. - if (! $error) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes ("; - $sql.= "box_id, position, box_order, fk_user, entity"; - $sql.= ") values ("; - $sql.= GETPOST("boxid","int").", ".GETPOST("pos","alpha").", 'A01', 0, ".$conf->entity; - $sql.= ")"; - - dol_syslog("boxes.php activate box sql=".$sql); - $resql = $db->query($sql); - if (! $resql) - { - $errmesg=$db->lasterror(); - $error++; - } - } - if (! $error) { header("Location: boxes.php"); diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index b4c3436b624..ae3e92268df 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -336,4 +336,4 @@ class CategorieTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/CompanyBankAccountTest.php b/test/phpunit/CompanyBankAccountTest.php index bb5e729c4de..24d6ad03d80 100644 --- a/test/phpunit/CompanyBankAccountTest.php +++ b/test/phpunit/CompanyBankAccountTest.php @@ -233,4 +233,4 @@ class CompanyBankAccountTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/CoreTest.php b/test/phpunit/CoreTest.php index 7ac69f9c4c8..2142f69e646 100755 --- a/test/phpunit/CoreTest.php +++ b/test/phpunit/CoreTest.php @@ -297,4 +297,4 @@ class CoreTest extends PHPUnit_Framework_TestCase $this->assertEquals($result,$expectedresult); } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/DateLibTzFranceTest.php b/test/phpunit/DateLibTzFranceTest.php index 23947c0f753..5630664c91c 100644 --- a/test/phpunit/DateLibTzFranceTest.php +++ b/test/phpunit/DateLibTzFranceTest.php @@ -199,4 +199,4 @@ class DateLibTzFranceTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php index ca1c69da2e5..d5938fc4691 100755 --- a/test/phpunit/ExportTest.php +++ b/test/phpunit/ExportTest.php @@ -265,4 +265,4 @@ class ExportTest extends PHPUnit_Framework_TestCase return true; } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index 36e499bb613..9551c6ce02e 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -329,4 +329,4 @@ class FactureTest extends PHPUnit_Framework_TestCase return $retAr; } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/FactureTestRounding.php b/test/phpunit/FactureTestRounding.php index 9961c74c385..6adeb71471d 100644 --- a/test/phpunit/FactureTestRounding.php +++ b/test/phpunit/FactureTestRounding.php @@ -333,4 +333,4 @@ class FactureTestRounding extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/ImportTest.php b/test/phpunit/ImportTest.php index 6cd5beecad7..af3b53a837e 100755 --- a/test/phpunit/ImportTest.php +++ b/test/phpunit/ImportTest.php @@ -134,4 +134,4 @@ class ImportTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/JsonLibTest.php b/test/phpunit/JsonLibTest.php index ad7a31bb537..e5610981399 100755 --- a/test/phpunit/JsonLibTest.php +++ b/test/phpunit/JsonLibTest.php @@ -170,4 +170,4 @@ class JsonLibTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index 26f76e942f9..4adf6530190 100755 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -146,4 +146,4 @@ class ModulesTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/PropalTest.php b/test/phpunit/PropalTest.php index 772a792e367..87c81b61413 100644 --- a/test/phpunit/PropalTest.php +++ b/test/phpunit/PropalTest.php @@ -287,4 +287,4 @@ class PropalTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 1f619beae6b..13bc3fe3eee 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -176,4 +176,4 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/WebservicesOrdersTest.php b/test/phpunit/WebservicesOrdersTest.php index e1ecca1371e..f4f40979ac7 100755 --- a/test/phpunit/WebservicesOrdersTest.php +++ b/test/phpunit/WebservicesOrdersTest.php @@ -175,4 +175,4 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/WebservicesOtherTest.php b/test/phpunit/WebservicesOtherTest.php index 005e3e9114e..74564727260 100755 --- a/test/phpunit/WebservicesOtherTest.php +++ b/test/phpunit/WebservicesOtherTest.php @@ -176,4 +176,4 @@ class WebservicesOtherTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?> diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 84c433f9716..d672e53b193 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -176,4 +176,4 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase } } -?> \ No newline at end of file +?>