diff --git a/ChangeLog b/ChangeLog
index 9d084f3a98e1b8d7c60c1daaeed7b2c5c8e18f9c..7f210c6fab1afaffb967ce7054ff8b2ce8275f75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -41,6 +41,31 @@ Dolibarr better:
 - Method commande->deleteline($lindeid) has been replaced with commande->deleteline($user, $lineid).
 
 
+
+***** ChangeLog for 4.0.2 compared to 4.0.1 *****
+FIX: #5340
+FIX: #5779
+FIX: #5849
+FIX: #5866
+FIX: #5907
+FIX: Addline if $txlocaltax1 is empty
+FIX: Avoid error 500 if phpexcel is disabled
+FIX: Avoid errors on debian
+FIX: Can edit the customer ref even if order is not draft.
+FIX: Documents not moved in new directory if we change reference of the task.
+FIX: Error when CATEGORIE_RECURSIV_ADD is enabled and new category is child of an already linked to object
+FIX: Extra fields of task not copied on project cloning
+FIX: Hidden option PRODUCT_MAX_VISIBLE_PHOTO
+FIX: Link on supplier invoice in widget was not clickable
+FIX: margin tab on customer card must filter on current entity invoices
+FIX: missing column into SQL on thirdparty list
+FIX: Nber of attached files were not reported in event report of email sent
+FIX: only show projects of related third if external user
+FIX: Search provider by price
+FIX: Solve backup when using mysqldump that return warning
+FIX: Sql error in widget of product for stock alerts
+FIX: updateligne if $txlocaltax1 is null
+
 ***** ChangeLog for 4.0.1 compared to 4.0.0 *****
 FIX: #2853
 FIX: #2991
diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl
index 41ae64834e4b8e953cb4413fba98fd4948272f62..fb3b39feca3bea0dfc8d88d799ee0aa4c1e11f99 100755
--- a/build/makepack-dolibarr.pl
+++ b/build/makepack-dolibarr.pl
@@ -159,6 +159,7 @@ $REL1 = $newbuild; $REL1 =~ s/-.*$//gi;
 if ($RPMSUBVERSION eq 'auto') { $RPMSUBVERSION = $newbuild; $RPMSUBVERSION =~ s/^.*-//gi; }
 $FILENAMETGZ2="$PROJECT-$MAJOR.$MINOR.$REL1";
 $FILENAMERPM=$FILENAMETGZ2."-".$RPMSUBVERSION.".".$ARCH.".rpm";
+$FILENAMERPMSRC=$FILENAMETGZ2."-".$RPMSUBVERSION.".src.rpm";
 # For Deb
 $newbuild = $BUILD;
 $newbuild =~ s/(dev|alpha)/1/gi;                # dev
@@ -733,8 +734,8 @@ if ($nboftargetok) {
 
 			print "Remove target ".$FILENAMERPM."...\n";
 			unlink("$NEWDESTI/".$FILENAMERPM);
-			print "Remove target ".$FILENAMETGZ2."-".$RPMSUBVERSION.".src.rpm...\n";
-			unlink("$NEWDESTI/".$FILENAMETGZ2."-".$RPMSUBVERSION.".src.rpm");
+			print "Remove target ".$FILENAMERPMSRC."...\n";
+			unlink("$NEWDESTI/".$FILENAMERPMSRC);
 
 			print "Create directory $BUILDROOT/$FILENAMETGZ2\n";
 			$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2`;
@@ -1140,10 +1141,11 @@ if ($nboftargetok) {
 	
 		print "\nList of files to publish (BUILD=$BUILD)\n";
 		%filestoscansf=(
-			"$DESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"=>'signatures',
+			"$DESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"=>'none',				# none means it won't be published on SF
 			"$DESTI/package_rpm_generic/$FILENAMERPM"=>'Dolibarr installer for Fedora-Redhat-Mandriva-Opensuse (DoliRpm)',
+			"$DESTI/package_rpm_generic/$FILENAMERPMSRC"=>'none',						# none means it won't be published on SF
 			"$DESTI/package_debian-ubuntu/${FILENAMEDEB}_all.deb"=>'Dolibarr installer for Debian-Ubuntu (DoliDeb)',
-			"$DESTI/package_debian-ubuntu/${FILENAMEDEBSHORT}.orig.tar.gz"=>'none',
+			"$DESTI/package_debian-ubuntu/${FILENAMEDEBSHORT}.orig.tar.gz"=>'none',		# none means it won't be published on SF
 			"$DESTI/package_windows/$FILENAMEEXEDOLIWAMP.exe"=>'Dolibarr installer for Windows (DoliWamp)',
 			"$DESTI/standard/$FILENAMETGZ.tgz"=>'Dolibarr ERP-CRM',
 			"$DESTI/standard/$FILENAMETGZ.zip"=>'Dolibarr ERP-CRM'
@@ -1151,6 +1153,7 @@ if ($nboftargetok) {
 		%filestoscanstableasso=(
 			"$DESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"=>'signatures',
 			"$DESTI/package_rpm_generic/$FILENAMERPM"=>'package_rpm_generic',
+			"$DESTI/package_rpm_generic/$FILENAMERPMSRC"=>'package_rpm_generic',
 			"$DESTI/package_debian-ubuntu/${FILENAMEDEB}_all.deb"=>'package_debian-ubuntu',
 			"$DESTI/package_debian-ubuntu/${FILENAMEDEBSHORT}.orig.tar.gz"=>'package_debian-ubuntu',
 			"$DESTI/package_windows/$FILENAMEEXEDOLIWAMP.exe"=>'package_windows',
@@ -1212,9 +1215,10 @@ if ($nboftargetok) {
 				my $filesize = -s $file;
 				if (! $filesize) { next; }
 
-				print "\n";
-	    		
-	    		if ($target eq 'SF' && $filestoscan{$file} ne 'none') { 
+	    		if ($target eq 'SF') {
+	    			if ($filestoscan{$file} eq 'none') {
+	    				next;
+	    			} 
 	    			$destFolder="$NEWPUBLISH/$filestoscan{$file}/".$MAJOR.'.'.$MINOR.'.'.$BUILD;
 	    		}
 	    		elsif ($target eq 'ASSO' and $NEWPUBLISH =~ /stable/) {
@@ -1231,6 +1235,8 @@ if ($nboftargetok) {
 	    			$filenameonly =~ s/.*\/[^\/]+\/([^\/])+$/$1/;  
 	    			$destFolder="$NEWPUBLISH/$dirnameonly";
 	    		}
+
+				print "\n";
 	    		print "Publish file ".$file." to ".$destFolder."\n";
 
 				# mkdir	   
diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec
index 4ad1441104d03e73bc505674473206c42521ecf3..e65e6bc3b7dd10b7be8cbfd26d70536b119cede8 100755
--- a/build/rpm/dolibarr_fedora.spec
+++ b/build/rpm/dolibarr_fedora.spec
@@ -34,7 +34,7 @@ AutoReqProv: no
 
 
 %description
-An easy to use CRM & ERP open source/free software for small  
+An easy to use CRM & ERP open source/free software package for small  
 and medium companies, foundations or freelances. It includes different 
 features for Enterprise Resource Planning (ERP) and Customer Relationship 
 Management (CRM) but also for different other activities.
diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec
index f20b20472253fa637147fd6454fa6f99533de1dc..655ef87f9259d367438651efebbb79e1924ef1a5 100755
--- a/build/rpm/dolibarr_generic.spec
+++ b/build/rpm/dolibarr_generic.spec
@@ -75,7 +75,7 @@ AutoReqProv: no
 
 
 %description
-An easy to use CRM & ERP open source/free software for small  
+An easy to use CRM & ERP open source/free software package for small  
 and medium companies, foundations or freelances. It includes different 
 features for Enterprise Resource Planning (ERP) and Customer Relationship 
 Management (CRM) but also for different other activities.
diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec
index ca836bc47d6124e5e6712aec8eab996b1c7aa94b..55fb718373403f76a449bcb51a35533df2d9190d 100755
--- a/build/rpm/dolibarr_mandriva.spec
+++ b/build/rpm/dolibarr_mandriva.spec
@@ -33,7 +33,7 @@ AutoReqProv: no
 
 
 %description
-An easy to use CRM & ERP open source/free software for small  
+An easy to use CRM & ERP open source/free software package for small  
 and medium companies, foundations or freelances. It includes different 
 features for Enterprise Resource Planning (ERP) and Customer Relationship 
 Management (CRM) but also for different other activities.
diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec
index fcff3363213130bde0c5be6944580df4ee8c332b..f7e29927ebb4938f5e7045bae807a6427936d107 100755
--- a/build/rpm/dolibarr_opensuse.spec
+++ b/build/rpm/dolibarr_opensuse.spec
@@ -36,7 +36,7 @@ AutoReqProv: no
 
 
 %description
-An easy to use CRM & ERP open source/free software for small  
+An easy to use CRM & ERP open source/free software package for small  
 and medium companies, foundations or freelances. It includes different 
 features for Enterprise Resource Planning (ERP) and Customer Relationship 
 Management (CRM) but also for different other activities.
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 1b03c0a6d3ec4408914e595a4c0cc79eb89939f6..bce8a063ecb2f604ea9100b6d6cc848c260c37a8 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -1786,12 +1786,14 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 			print '<td>';
 			if (! empty($conf->accounting->enabled))
 			{
-				$accountancy_account = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
+			    $fieldname = $fieldlist[$field];
+				$accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
 				print $formaccountancy->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
 			}
 			else
 			{
-				print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" name="'.$fieldlist[$field].'">';
+			    $fieldname = $fieldlist[$field];
+			    print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname)?$obj->$fieldname:'').'" name="'.$fieldlist[$field].'">';
 			}
 			print '</td>';
 		}
diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php
index ecc6b6a01665128870c5b4507c77d14ae77fba43..b0c81ec18af37e18ea50b45ef762ba01e7f70ae0 100644
--- a/htdocs/admin/websites.php
+++ b/htdocs/admin/websites.php
@@ -535,7 +535,8 @@ if ($id)
                         {
                             $showfield=1;
                         	$align="left";
-                            $valuetoshow=$obj->$fieldlist[$field];
+                        	$fieldname=$fieldlist[$field];
+                            $valuetoshow=$obj->$fieldname;
 
 							// Show value for field
 							if ($showfield) print '<td align="'.$align.'">'.$valuetoshow.'</td>';
@@ -613,14 +614,15 @@ function fieldListWebsites($fieldlist, $obj='', $tabname='', $context='')
 
 	foreach ($fieldlist as $field => $value)
 	{
+	    $fieldname = $fieldlist[$field];
 		if ($fieldlist[$field] == 'lang')
 		{
 			print '<td>';
 			print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
 			print '</td>';
 		}
-		elseif ($fieldlist[$field] == 'code' && isset($obj->$fieldlist[$field])) {
-			print '<td><input type="text" class="flat" value="'.(! empty($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
+		elseif ($fieldlist[$field] == 'code' && isset($obj->$fieldname)) {
+			print '<td><input type="text" class="flat" value="'.(! empty($obj->$fieldname)?$obj->$fieldname:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
 		}
 		else
 		{
@@ -631,7 +633,7 @@ function fieldListWebsites($fieldlist, $obj='', $tabname='', $context='')
 			if ($fieldlist[$field]=='libelle') $size='size="32" ';
 			if ($fieldlist[$field]=='tracking') $size='size="92" ';
 			if ($fieldlist[$field]=='sortorder') $size='size="2" ';
-			print '<input type="text" '.$size.' class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" name="'.$fieldlist[$field].'">';
+			print '<input type="text" '.$size.' class="flat" value="'.(isset($obj->$fieldname)?$obj->$fieldname:'').'" name="'.$fieldlist[$field].'">';
 			print '</td>';
 		}
 	}
diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index ab82466d32da5e11a8907233fa97272ae207f508..e9883a78ec7459b72b27786cc4a8a8b85e1ee36d 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -9,7 +9,6 @@
  * Copyright (C) 2013      Alexandre Spangaro          <aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2015      Frederic France             <frederic.france@free.fr>
  * Copyright (C) 2015      Marcos GarcĂ­a               <marcosgdf@gmail.com>
- *
  * 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
  * the Free Software Foundation; either version 3 of the License, or
@@ -89,7 +88,7 @@ $hookmanager->initHooks(array('commcard','globalcard'));
  * Actions
  */
 
-$parameters = array('socid' => $id);
+$parameters = array('id' => $id, 'socid' => $id);
 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 
@@ -440,7 +439,8 @@ if ($id > 0)
     {
         $langs->load("members");
         $langs->load("users");
-        print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
+
+        print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
         print '<td>';
         $adh=new Adherent($db);
         $result=$adh->fetch('','',$object->id);
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 1c88cbc1e9aa0374b3fdbce7c96cf7e5d42fc8e8..d7414a4683595f4578720d3383ef25c41a3a1e5b 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -390,7 +390,21 @@ function dol_buildpath($path, $type=0)
 		
 		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
 		{
-			if ($key == 'main') continue;
+			if ($key == 'main') 
+			{
+			    if ($type == 3)
+			    {
+			        global $dolibarr_main_url_root;
+			        	
+			        // Define $urlwithroot
+			        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+			        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
+			        //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
+
+			        $res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).'/'.$path;     // Test on start with http is for old conf syntax
+			    }
+			    continue;
+			}
 			preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs);    // Take part before '?'
 			if (! empty($regs[1]))
 			{
@@ -414,7 +428,7 @@ function dol_buildpath($path, $type=0)
 					    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
 					    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
 					    					
-					    $res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).$conf->file->dol_url_root[$key].'/'.$path;
+					    $res=(preg_match('/^http/i',$conf->file->dol_url_root[$key])?'':$urlwithroot).$conf->file->dol_url_root[$key].'/'.$path;     // Test on start with http is for old conf syntax
 					}
 					break;
 				}
diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php
index ee7288e2928044568fb32dd49971b37840da7bd3..f967b53d9db4e80e311cfa6a9caf7f5cab8519f8 100644
--- a/test/phpunit/FunctionsLibTest.php
+++ b/test/phpunit/FunctionsLibTest.php
@@ -119,6 +119,32 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
     }
 
 
+
+	/**
+	 * testDolBuildPath
+	 *
+	 * @return boolean
+	 */
+	public function testDolBuildPath()
+	{
+	    /*$tmp=dol_buildpath('/google/oauth2callback.php', 0);
+	    var_dump($tmp);
+	    */
+	     
+	    /*$tmp=dol_buildpath('/google/oauth2callback.php', 1);
+	    var_dump($tmp);
+	    */
+	     
+	    $result=dol_buildpath('/google/oauth2callback.php', 2);
+	    print __METHOD__." result=".$result."\n";
+	    $this->assertStringStartsWith('http', $result);
+	     
+	    $result=dol_buildpath('/google/oauth2callback.php', 3);
+        print __METHOD__." result=".$result."\n";
+        $this->assertStringStartsWith('http', $result);
+	}
+    
+    
     /**
     * testGetBrowserInfo
     *
@@ -1009,5 +1035,5 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
 
 		return true;
 	}
-
+	
 }