diff --git a/ChangeLog b/ChangeLog
index 603d7a5930f9abe7821e915e286b2c318026c1d8..667dfa3cf7a9a84a3cc2675b2333de2e5dc1714f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -51,6 +51,24 @@ removed. You must now use the 6 parameters way. See file modMyModule.class.php f
 - Remove the javascrit function ac_delay() that is not used anymore by core code.
 
 
+***** ChangeLog for 3.5.1 compared to 3.5.0 *****
+Fix: Bug of import of agenda when using https link
+Fix: Field nature not saved correctly
+Fix: Substituion of extra field was ko for order
+Fix: Bad translation of date format for pt_BR.
+Fix: priority field of agenda record is smallint.
+Fix: Missing loading of lang in some pages.
+Fix: Write note in invoice when using pos module.
+Fix: Link to paypal was invalid into email text.
+Fix: ref and date of supplier invoice.
+Fix: Check on bank account.
+Fix: Problem with file upload and download.
+Fix: Page load not ending when large number of thirdparies. We 
+     added option MAIN_DISABLE_AJAX_COMBOX to disable javascript
+     combo feature that is root cause of problem.
+Fix: [ bug #1231 ] PDF always generated in interventions
+Fix: Be sure there is no duplicate default rib.
+
 ***** ChangeLog for 3.5 compared to 3.4.* *****
 For users:
 - New: Add hidden option BANK_DISABLE_DIRECT_INPUT.
diff --git a/build/debian/changelog b/build/debian/changelog
index bf65a5a43e322a6ade2a8486e2204ac392b25da2..c4e31ec51c8715e37af9e5e5750650fcfe4ba349 100644
--- a/build/debian/changelog
+++ b/build/debian/changelog
@@ -3,7 +3,14 @@ dolibarr (3.6.0-1) unstable; urgency=low
   [ Laurent Destailleur (eldy) ]
   * New upstream release.
     
- -- Laurent Destailleur (eldy) <eldy@users.sourceforge.net>  Mon, 30 Dec 2013 12:00:00 +0100     
+ -- Laurent Destailleur (eldy) <eldy@users.sourceforge.net>  Sat, 8 Feb 2014 12:00:00 +0100      
+
+dolibarr (3.5.1-3) unstable; urgency=low
+
+  [ Laurent Destailleur (eldy) ]
+  * New upstream release.
+    
+ -- Laurent Destailleur (eldy) <eldy@users.sourceforge.net>  Fri, 7 Feb 2014 12:00:00 +0100     
 
 dolibarr (3.5.0-3) unstable; urgency=low
 
diff --git a/build/perl/virtualmin/dolibarr.pl b/build/perl/virtualmin/dolibarr.pl
index 849042e120e59ffd8e4b01ab745cf33f28af994b..31abc0138ee64ffe8cd85a007b21bcdc15f07648 100644
--- a/build/perl/virtualmin/dolibarr.pl
+++ b/build/perl/virtualmin/dolibarr.pl
@@ -30,7 +30,7 @@ return "Regis Houssin";
 # script_dolibarr_versions()
 sub script_dolibarr_versions
 {
-return ( "3.6.0", "3.5.0", "3.4.1", "3.4.0", "3.3.3", "3.3.2", "3.3.1", "3.3.0", "3.2.1", "3.1.1" );
+return ( "3.6.0", "3.5.1", "3.5.0", "3.4.1", "3.4.0", "3.3.3", "3.3.2", "3.3.1", "3.3.0", "3.2.1", "3.1.1" );
 }
 
 sub script_dolibarr_category
diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec
index e509deb8f4b9c0c8e3820fdb0d4dc8321c88a9cd..4cbf9c11171e4013136c5e04a7d13fc75a5ef377 100755
--- a/build/rpm/dolibarr_fedora.spec
+++ b/build/rpm/dolibarr_fedora.spec
@@ -331,5 +331,8 @@ fi
 
 # version x.y.z-0.1.a for alpha, x.y.z-0.2.b for beta, x.y.z-0.3 for release
 %changelog
-* Mon Dec 30 2013 Laurent Destailleur 3.6.0-0.2.b
+* Fri Feb 7 2014 Laurent Destailleur 3.6.0-0.2.b
+- Upstream release
+
+* Mon Dec 30 2013 Laurent Destailleur 3.5.0-0.3
 - Initial version (#723326)
diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec
index 5a7f9eb1db5c100c6911aa840e9395cbc590b2a5..d37a41390f07a8d5cf46b05c44e0e18ecaa0ec17 100755
--- a/build/rpm/dolibarr_generic.spec
+++ b/build/rpm/dolibarr_generic.spec
@@ -559,5 +559,8 @@ fi
 
 # version x.y.z-0.1.a for alpha, x.y.z-0.2.b for beta, x.y.z-0.3 for release
 %changelog
-* Mon Dec 30 2013 Laurent Destailleur 3.6.0-0.2.b
+* Mon Feb 7 2014 Laurent Destailleur 3.6.0-0.2.b
+- Upstream release
+
+* Mon Dec 30 2013 Laurent Destailleur 3.5.0-0.3
 - Initial version (#723326)
diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec
index e0ca516608ef29cce8645660fec004d8ad7c7f11..0645eb55f4edf338116e6c5c75f57a4413e0f4a6 100755
--- a/build/rpm/dolibarr_mandriva.spec
+++ b/build/rpm/dolibarr_mandriva.spec
@@ -336,5 +336,8 @@ fi
 
 # version x.y.z-0.1.a for alpha, x.y.z-0.2.b for beta, x.y.z-0.3 for release
 %changelog
-* Mon Dec 30 2013 Laurent Destailleur 3.6.0-0.2.b
+* Mon Feb 7 2014 Laurent Destailleur 3.6.0-0.2.b
+- Upstream release
+
+* Mon Dec 30 2013 Laurent Destailleur 3.5.0-0.3
 - Initial version (#723326)
diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec
index a919ef0d566f31775cb56ae8d1ecf7b75779710e..06feacf42c2fae933e09ebc52eb0f19359e9336a 100755
--- a/build/rpm/dolibarr_opensuse.spec
+++ b/build/rpm/dolibarr_opensuse.spec
@@ -346,5 +346,8 @@ fi
 
 # version x.y.z-0.1.a for alpha, x.y.z-0.2.b for beta, x.y.z-0.3 for release
 %changelog
-* Mon Dec 30 2013 Laurent Destailleur 3.6.0-0.2.b
+* Mon Feb 7 2014 Laurent Destailleur 3.6.0-0.2.b
+- Upstream release
+
+* Mon Dec 30 2013 Laurent Destailleur 3.5.0-0.3
 - Initial version (#723326)
diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php
index e7ca2216bf340f6a5b9e579f013863de9a5feece..4bb3cb8c4f3d230bc7f943c2b609ec00cd9e8e1c 100644
--- a/htdocs/admin/agenda_extsites.php
+++ b/htdocs/admin/agenda_extsites.php
@@ -67,7 +67,7 @@ if ($actionsave)
 		$color=trim(GETPOST('agenda_ext_color'.$i,'alpha'));
 		if ($color=='-1') $color='';
 
-		if (! empty($src) && ! preg_match('/^(http\s*|ftp\s*):/', $src))
+		if (! empty($src) && ! dol_is_url($src))
 		{
 			setEventMessage($langs->trans("ErrorParamMustBeAnUrl"),'errors');
 			$error++;
diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php
index 848c8057b6d426bb9463a6af5f192e2362ee55fe..9ca99f8634bd3f962fba2f04c5192a175cf1fe67 100644
--- a/htdocs/comm/action/document.php
+++ b/htdocs/comm/action/document.php
@@ -55,16 +55,16 @@ if ($user->societe_id > 0)
 }
 $result = restrictedArea($user, 'agenda', $objectid, 'actioncomm&societe', 'myactions&allactions', 'fk_soc', 'id');
 
-$act = new ActionComm($db);
+$object = new ActionComm($db);
 
 if ($objectid > 0)
 {
-	$ret = $act->fetch($objectid);
+	$ret = $object->fetch($objectid);
 	if ($ret > 0) {
 		$company=new Societe($db);
-		$company->fetch($act->societe->id);
-		$act->societe=$company; // For backward compatibility
-		$act->thirdparty=$company;
+		$company->fetch($object->societe->id);
+		$object->societe=$company; // For backward compatibility
+		$object->thirdparty=$company;
 	}
 }
 
@@ -79,6 +79,9 @@ $pagenext = $page + 1;
 if (! $sortorder) $sortorder="ASC";
 if (! $sortfield) $sortfield="name";
 
+$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
+$modulepart='contract';
+
 
 /*
  * Actions
@@ -96,17 +99,15 @@ $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
 llxHeader('',$langs->trans("Agenda"),$help_url);
 
 
-if ($act->id > 0)
+if ($object->id > 0)
 {
-	$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
-
 	$author=new User($db);
-	$author->fetch($act->author->id);
-	$act->author=$author;
+	$author->fetch($object->author->id);
+	$object->author=$author;
 
-	if ($act->contact->id) $act->fetch_contact($act->contact->id);
+	if ($object->contact->id) $object->fetch_contact($object->contact->id);
 
-	$head=actions_prepare_head($act);
+	$head=actions_prepare_head($object);
 	dol_fiche_head($head, 'documents', $langs->trans("Action"),0,'action');
 
 	// Affichage fiche action en mode visu
@@ -116,53 +117,53 @@ if ($act->id > 0)
 
 	// Ref
 	print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
-	print $form->showrefnav($act, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', '');
+	print $form->showrefnav($object, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', '');
 	print '</td></tr>';
 
 	// Type
 	if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
 	{
-		print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
+		print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$object->type.'</td></tr>';
 	}
 
 	// Title
-	print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
+	print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$object->label.'</td></tr>';
 
 	// Full day event
-	print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent).'</td></tr>';
+	print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent).'</td></tr>';
 
 	// Date start
 	print '<tr><td width="30%">'.$langs->trans("DateActionStart").'</td><td colspan="2">';
-	if (! $act->fulldayevent) print dol_print_date($act->datep,'dayhour');
-	else print dol_print_date($act->datep,'day');
-	if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
+	if (! $object->fulldayevent) print dol_print_date($object->datep,'dayhour');
+	else print dol_print_date($object->datep,'day');
+	if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
 	print '</td>';
 	print '<td rowspan="4" align="center" valign="middle" width="180">'."\n";
 	print '<form name="listactionsfiltermonth" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 	print '<input type="hidden" name="action" value="show_month">';
-	print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
-	print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
-	print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
-	//print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
+	print '<input type="hidden" name="year" value="'.dol_print_date($object->datep,'%Y').'">';
+	print '<input type="hidden" name="month" value="'.dol_print_date($object->datep,'%m').'">';
+	print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
+	//print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
 	print img_picto($langs->trans("ViewCal"),'object_calendar').' <input type="submit" style="width: 120px" class="button" name="viewcal" value="'.$langs->trans("ViewCal").'">';
 	print '</form>'."\n";
 	print '<form name="listactionsfilterweek" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 	print '<input type="hidden" name="action" value="show_week">';
-	print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
-	print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
-	print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
-	//print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
+	print '<input type="hidden" name="year" value="'.dol_print_date($object->datep,'%Y').'">';
+	print '<input type="hidden" name="month" value="'.dol_print_date($object->datep,'%m').'">';
+	print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
+	//print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
 	print img_picto($langs->trans("ViewCal"),'object_calendarweek').' <input type="submit" style="width: 120px" class="button" name="viewweek" value="'.$langs->trans("ViewWeek").'">';
 	print '</form>'."\n";
 	print '<form name="listactionsfilterday" action="'.DOL_URL_ROOT.'/comm/action/index.php" method="POST">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 	print '<input type="hidden" name="action" value="show_day">';
-	print '<input type="hidden" name="year" value="'.dol_print_date($act->datep,'%Y').'">';
-	print '<input type="hidden" name="month" value="'.dol_print_date($act->datep,'%m').'">';
-	print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
-	//print '<input type="hidden" name="day" value="'.dol_print_date($act->datep,'%d').'">';
+	print '<input type="hidden" name="year" value="'.dol_print_date($object->datep,'%Y').'">';
+	print '<input type="hidden" name="month" value="'.dol_print_date($object->datep,'%m').'">';
+	print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
+	//print '<input type="hidden" name="day" value="'.dol_print_date($object->datep,'%d').'">';
 	print img_picto($langs->trans("ViewCal"),'object_calendarday').' <input type="submit" style="width: 120px" class="button" name="viewday" value="'.$langs->trans("ViewDay").'">';
 	print '</form>'."\n";
 	print '</td>';
@@ -170,43 +171,43 @@ if ($act->id > 0)
 
 	// Date end
 	print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="2">';
-	if (! $act->fulldayevent) print dol_print_date($act->datef,'dayhour');
-	else print dol_print_date($act->datef,'day');
-	if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now- $delay_warning)) print img_warning($langs->trans("Late"));
+	if (! $object->fulldayevent) print dol_print_date($object->datef,'dayhour');
+	else print dol_print_date($object->datef,'day');
+	if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now- $delay_warning)) print img_warning($langs->trans("Late"));
 	print '</td></tr>';
 
 	// Status
 	print '<tr><td class="nowrap">'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="2">';
-	print $act->getLibStatut(4);
+	print $object->getLibStatut(4);
 	print '</td></tr>';
 
 	// Location
-	print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$act->location.'</td></tr>';
+	print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$object->location.'</td></tr>';
 
 
 	print '</table><br><br><table class="border" width="100%">';
 
 
 	// Third party - Contact
-	print '<tr><td width="30%">'.$langs->trans("ActionOnCompany").'</td><td>'.($act->societe->id?$act->societe->getNomUrl(1):$langs->trans("None"));
-	if ($act->societe->id && $act->type_code == 'AC_TEL')
+	print '<tr><td width="30%">'.$langs->trans("ActionOnCompany").'</td><td>'.($object->societe->id?$object->societe->getNomUrl(1):$langs->trans("None"));
+	if ($object->societe->id && $object->type_code == 'AC_TEL')
 	{
-		if ($act->societe->fetch($act->societe->id))
+		if ($object->societe->fetch($object->societe->id))
 		{
-			print "<br>".dol_print_phone($act->societe->phone);
+			print "<br>".dol_print_phone($object->societe->phone);
 		}
 	}
 	print '</td>';
 	print '<td>'.$langs->trans("Contact").'</td>';
 	print '<td>';
-	if ($act->contact->id > 0)
+	if ($object->contact->id > 0)
 	{
-		print $act->contact->getNomUrl(1);
-		if ($act->contact->id && $act->type_code == 'AC_TEL')
+		print $object->contact->getNomUrl(1);
+		if ($object->contact->id && $object->type_code == 'AC_TEL')
 		{
-			if ($act->contact->fetch($act->contact->id))
+			if ($object->contact->fetch($object->contact->id))
 			{
-				print "<br>".dol_print_phone($act->contact->phone_pro);
+				print "<br>".dol_print_phone($object->contact->phone_pro);
 			}
 		}
 	}
@@ -221,10 +222,10 @@ if ($act->id > 0)
 	if (! empty($conf->projet->enabled))
 	{
 		print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
-		if ($act->fk_project)
+		if ($object->fk_project)
 		{
 			$project=new Project($db);
-			$project->fetch($act->fk_project);
+			$project->fetch($object->fk_project);
 			print $project->getNomUrl(1);
 		}
 		print '</td></tr>';
@@ -232,7 +233,7 @@ if ($act->id > 0)
 
 	// Priority
 	print '<tr><td class="nowrap">'.$langs->trans("Priority").'</td><td colspan="3">';
-	print ($act->priority?$act->priority:'');
+	print ($object->priority?$object->priority:'');
 	print '</td></tr>';
 
 
@@ -255,7 +256,7 @@ if ($act->id > 0)
 
 	$modulepart = 'actions';
 	$permission = $user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create;
-	$param = '&id=' . $act->id;
+	$param = '&id=' . $object->id;
 	include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
 }
 else
diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php
index 4e6ac38c81010924416354103c92f98608defaf6..1d2f792ab2f39ef1d10fb692b2c2b91513ca5c78 100644
--- a/htdocs/comm/list.php
+++ b/htdocs/comm/list.php
@@ -196,8 +196,8 @@ if ($result)
 	print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$param,"",$sortfield,$sortorder);
     print_liste_field_titre($langs->trans("AccountancyCode"),$_SERVER["PHP_SELF"],"s.code_compta","",$param,'align="left"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec","",$param,'align="right"',$sortfield,$sortorder);
-    print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="right"',$sortfield,$sortorder);
-    print '<td class="liste_titre" width="1%">&nbsp;</td>';
+    print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="center"',$sortfield,$sortorder);
+    print '<td class="liste_titre">&nbsp;</td>';
     $parameters=array();
     $formconfirm=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
 
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 5bce6e0f658762542da1354459a219565bd40c8d..a164253dc690ba92eb3629f0c0862bdd78742c9c 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3910,7 +3910,10 @@ else if ($id > 0 || ! empty($ref))
 		$formmail->frommail = $user->email;
 		$formmail->withfrom=1;
 		$liste=array();
-		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
+		foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)
+		{
+			$liste[$key]=$value;
+		}
 		$formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste;
 		$formmail->withtocc=$liste;
 		$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php
index a4606d669c2852318150078e3136bc7ddd9510d9..018bbdb9d40eb7f2c70fc12e49a935a1fc3a2a88 100644
--- a/htdocs/compta/prelevement/class/bonprelevement.class.php
+++ b/htdocs/compta/prelevement/class/bonprelevement.class.php
@@ -683,16 +683,16 @@ class BonPrelevement extends CommonObject
         $sql = "SELECT count(f.rowid)";
         $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
         $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
-        if ($banque == 1 || $agence == 1) $sql.=", ".MAIN_DB_PREFIX."societe_rib as sr";
+        if ($banque || $agence) $sql.=", ".MAIN_DB_PREFIX."societe_rib as sr";
         $sql.= " WHERE f.fk_statut = 1";
         $sql.= " AND f.entity = ".$conf->entity;
         $sql.= " AND f.rowid = pfd.fk_facture";
         $sql.= " AND f.paye = 0";
         $sql.= " AND pfd.traite = 0";
         $sql.= " AND f.total_ttc > 0";
-        if ($banque == 1 || $agence == 1) $sql.= " AND f.fk_soc = sr.rowid";
-        if ($banque == 1) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
-        if ($agence == 1) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
+        if ($banque || $agence) $sql.= " AND f.fk_soc = sr.rowid";
+        if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
+        if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
 
         $resql = $this->db->query($sql);
 
@@ -716,8 +716,8 @@ class BonPrelevement extends CommonObject
     /**
      *	Create a withdraw
      *
-     *	@param 	int		$banque		code of bank
-     *	@param	int		$agence		code of bank office (guichet)
+     *	@param 	int		$banque		code of bank (to withdraw a specific bankof a specific customer. By default '')
+     *	@param	int		$agence		code of bank office (guichet) (to withdraw a specific bankof a specific customer. By default '')
      *	@param	string	$mode		real=do action, simu=test only
      *	@return	int					<0 if KO, nbre of invoice withdrawed if OK
      */
@@ -755,17 +755,17 @@ class BonPrelevement extends CommonObject
             $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
             $sql.= ", ".MAIN_DB_PREFIX."societe as s";
             $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
-            if ($banque == 1 || $agence ==1) $sql.= ", ".MAIN_DB_PREFIX."societe_rib as sr";
+            if ($banque || $agence) $sql.= ", ".MAIN_DB_PREFIX."societe_rib as sr";
             $sql.= " WHERE f.rowid = pfd.fk_facture";
             $sql.= " AND f.entity = ".$conf->entity;
             $sql.= " AND s.rowid = f.fk_soc";
-            if ($banque == 1 || $agence ==1) $sql.= " AND s.rowid = sr.fk_soc";
+            if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc";
             $sql.= " AND f.fk_statut = 1";
             $sql.= " AND f.paye = 0";
             $sql.= " AND pfd.traite = 0";
             $sql.= " AND f.total_ttc > 0";
-            if ($banque == 1) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
-            if ($agence == 1) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
+            if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
+            if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
 
             dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG);
             $resql = $this->db->query($sql);
@@ -777,7 +777,7 @@ class BonPrelevement extends CommonObject
                 while ($i < $num)
                 {
                     $row = $this->db->fetch_row($resql);
-                    $factures[$i] = $row;
+                    $factures[$i] = $row;	// All fields
                     $i++;
                 }
                 $this->db->free($resql);
@@ -802,10 +802,10 @@ class BonPrelevement extends CommonObject
 
             if (count($factures) > 0)
             {
-                foreach ($factures as $fac)
+                foreach ($factures as $key => $fac)
                 {
                     $fact = new Facture($this->db);
-                    if ($fact->fetch($fac[0]) >= 0)
+                    if ($fact->fetch($fac[0]) >= 0)		// Field 0 of $fac is rowid of invoice
                     {
                         if ($soc->fetch($fact->socid) >= 0)
                         {
@@ -820,8 +820,8 @@ class BonPrelevement extends CommonObject
                             }
                             else
 							{
-                                dol_syslog("Error on third party bank number RIB/IBAN ".$fact->socid." ".$soc->nom, LOG_ERR);
-                                $facture_errors[$fac[0]]="Error on third party bank number RIB/IBAN ".$fact->socid." ".$soc->nom;
+								dol_syslog("Error on default bank number RIB/IBAN for thirdparty reported by verif() ".$fact->socid." ".$soc->nom, LOG_ERR);
+                                $facture_errors[$fac[0]]="Error on default bank number RIB/IBAN for thirdparty reported by function verif() ".$fact->socid." ".$soc->nom;
                             }
                         }
                         else
diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php
index 115902db228502db013f43c6864a35d32cd1f0a3..81bb679473699d5c64e39fc564cab9910c5a1ab7 100644
--- a/htdocs/compta/prelevement/create.php
+++ b/htdocs/compta/prelevement/create.php
@@ -58,9 +58,9 @@ if ($action == 'modify')
         dolibarr_set_const($db, GETPOST("nom$i"), GETPOST("value$i"),'chaine',0,'',$conf->entity);
     }
 }
-
 if ($action == 'create')
 {
+	// $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty
     $bprev = new BonPrelevement($db);
     $result=$bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET);
     if ($result < 0)
diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php
index c8fc4a917f2c8cef2618b24e4c7a9c0812a3e89f..f87cf1697577ea9dd05c87508d24b3d7870e8917 100644
--- a/htdocs/core/boxes/box_graph_invoices_permonth.php
+++ b/htdocs/core/boxes/box_graph_invoices_permonth.php
@@ -81,6 +81,12 @@ class box_graph_invoices_permonth extends ModeleBoxes
 				'target'=>'none'	// Set '' to get target="_blank"
 		);
 
+		$dir=''; 	// We don't need a path because image file will not be saved into disk
+		$prefix='';
+		$socid=0;
+		if ($user->societe_id) $socid=$user->societe_id;
+		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
+		
 		if ($user->rights->facture->lire)
 		{
 			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
@@ -119,9 +125,9 @@ class box_graph_invoices_permonth extends ModeleBoxes
 			{
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/invoicesnbinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."invoicesnbinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$endyear.'.png';
 
 				$px1 = new DolGraph();
 				$mesg = $px1->isGraphKo();
@@ -157,9 +163,9 @@ class box_graph_invoices_permonth extends ModeleBoxes
 			{
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/invoicesamountinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."invoicesamountinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$endyear.'.png';
 
 				$px2 = new DolGraph();
 				$mesg = $px2->isGraphKo();
diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php
index 45f3be02933a2255b18e6eafbef7a364bacbc1f9..e732270c0442504c3ab79579e605d4d9a48ee2ee 100644
--- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php
+++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php
@@ -80,6 +80,12 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
 				'target'=>'none'	// Set '' to get target="_blank"
 		);
 
+		$dir=''; 	// We don't need a path because image file will not be saved into disk
+		$prefix='';
+		$socid=0;
+		if ($user->societe_id) $socid=$user->societe_id;
+		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
+		
 		if ($user->rights->fournisseur->facture->lire)
 		{
 			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
@@ -118,7 +124,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
 			{
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/invoicessuppliernbinyear-".$year.".png";
+				$filenamenb = $dir."/".$prefix."invoicessuppliernbinyear-".$year.".png";
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
 				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessuppliernbinyear-'.$year.'.png';
 
@@ -156,7 +162,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
 			{
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/invoicessupplieramountinyear-".$year.".png";
+				$filenamenb = $dir."/".$prefix."invoicessupplieramountinyear-".$year.".png";
 				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
 				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicessupplieramountinyear-'.$year.'.png';
 
diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php
index 17fc0215fef708c66b0a49ad9f6b9ef7f5f8805c..704117834c4d3a0fc91c7e56c287e840e7ff2eca 100644
--- a/htdocs/core/boxes/box_graph_orders_permonth.php
+++ b/htdocs/core/boxes/box_graph_orders_permonth.php
@@ -81,6 +81,12 @@ class box_graph_orders_permonth extends ModeleBoxes
 				'target'=>'none'	// Set '' to get target="_blank"
 		);
 
+		$dir=''; 	// We don't need a path because image file will not be saved into disk
+		$prefix='';
+		$socid=0;
+		if ($user->societe_id) $socid=$user->societe_id;
+		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
+		
 		if ($user->rights->commande->lire)
 		{
 			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
@@ -119,9 +125,9 @@ class box_graph_orders_permonth extends ModeleBoxes
 			{
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/ordersnbinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersnbinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."ordersnbinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersnbinyear-'.$endyear.'.png';
 
 				$px1 = new DolGraph();
 				$mesg = $px1->isGraphKo();
@@ -157,9 +163,9 @@ class box_graph_orders_permonth extends ModeleBoxes
 			{
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/ordersamountinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersamountinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."ordersamountinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=ordersamountinyear-'.$endyear.'.png';
 
 				$px2 = new DolGraph();
 				$mesg = $px2->isGraphKo();
diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php
index 61cc4f8fe8736c605d489ba4e45241c7feddc943..5267bf3ffb5bec368d0527cdb1449886fcebb38b 100644
--- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php
+++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php
@@ -80,6 +80,12 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
 				'target'=>'none'	// Set '' to get target="_blank"
 		);
 
+		$dir=''; 	// We don't need a path because image file will not be saved into disk
+		$prefix='';
+		$socid=0;
+		if ($user->societe_id) $socid=$user->societe_id;
+		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
+		
 		if ($user->rights->fournisseur->commande->lire)
 		{
 			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
@@ -118,9 +124,9 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
 			{
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/orderssuppliernbinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssuppliernbinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."orderssuppliernbinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersnbinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssuppliernbinyear-'.$endyear.'.png';
 
 				$px1 = new DolGraph();
 				$mesg = $px1->isGraphKo();
@@ -156,9 +162,9 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
 			{
 				$data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 
-				$filenamenb = $dir."/orderssupplieramountinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssupplieramountinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."orderssupplieramountinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&amp;file=ordersamountinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&amp;file=orderssupplieramountinyear-'.$endyear.'.png';
 
 				$px2 = new DolGraph();
 				$mesg = $px2->isGraphKo();
diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php
index 8fd42d525fdfa483f25486092407a3ab7fa13bf9..58d00ce97fea068a2cf58679fbf88a8e5d15d5d2 100644
--- a/htdocs/core/boxes/box_graph_propales_permonth.php
+++ b/htdocs/core/boxes/box_graph_propales_permonth.php
@@ -81,6 +81,12 @@ class box_graph_propales_permonth extends ModeleBoxes
 				'target'=>'none'	// Set '' to get target="_blank"
 		);
 
+		$dir=''; 	// We don't need a path because image file will not be saved into disk
+		$prefix='';
+		$socid=0;
+		if ($user->societe_id) $socid=$user->societe_id;
+		if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-';	// If user has no permission to see all, output dir is specific to user
+		
 		if ($user->rights->propal->lire)
 		{
 			$param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
@@ -120,9 +126,9 @@ class box_graph_propales_permonth extends ModeleBoxes
 				$data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
 				$datatype1 = array_pad(array(), ($endyear-$startyear+1), 'bars');
 
-				$filenamenb = $dir."/propalsnbinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsnbinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&amp;file=propalsnbinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."propalsnbinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsnbinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&amp;file=propalsnbinyear-'.$endyear.'.png';
 
 				$px1 = new DolGraph();
 				$mesg = $px1->isGraphKo();
@@ -161,9 +167,9 @@ class box_graph_propales_permonth extends ModeleBoxes
 				$datatype2 = array_pad(array(), ($endyear-$startyear+1), 'bars');
 				//$datatype2 = array('lines','bars');
 
-				$filenamenb = $dir."/propalsamountinyear-".$year.".png";
-				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsamountinyear-'.$year.'.png';
-				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&amp;file=propalsamountinyear-'.$year.'.png';
+				$filenamenb = $dir."/".$prefix."propalsamountinyear-".$endyear.".png";
+				if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsamountinyear-'.$endyear.'.png';
+				if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&amp;file=propalsamountinyear-'.$endyear.'.png';
 
 				$px2 = new DolGraph();
 				$mesg = $px2->isGraphKo();
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index e15d1eac8a72a5bc501fb14eb9bfeafa41a92383..ae705ee7ab85fd8ad4ce27cdfb341175271bfbda 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -516,7 +516,7 @@ class ExtraFields
 	/**
 	 * 	Load array this->attribute_label
 	 *
-	 * 	@param	string		$elementtype		Type of element
+	 * 	@param	string		$elementtype		Type of element ('adherent', 'commande', societe', 'facture', 'propal', 'product', ...)
 	 * 	@param	boolean		$forceload			Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED
 	 * 	@return	array							Array of attributes for all extra fields
 	 */
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index 172d65b4ca6b0d8a1e6d8b60c9c075d016c2d8da..1319ad766d0f67e5b4d726289444629550ad9d3d 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -765,6 +765,7 @@ class FormFile
 					{
 						$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
 						if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2).$relativepath;
+						if ($object->element == 'member') $relativepath=get_exdir($object->id,2).$relativepath;
 					}
 
 					$var=!$var;
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index e5dc008fc2ef6a0175c80b3cb17419e35144521d..66fd945c01d8d2909c67ca320909c4847dbffe21 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -566,12 +566,12 @@ class FormMail
         			if ($this->param["models"]=='order_send')
         			{
         				$url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']);
-        				$this->substit['__PERSONALIZED__']=$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url);
+        				$this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url));
         			}
         			if ($this->param["models"]=='facture_send')
         			{
         				$url=getPaypalPaymentUrl(0,'invoice',$this->substit['__FACREF__']);
-        				$this->substit['__PERSONALIZED__']=$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url);
+        				$this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url));
         			}
         		}
 
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index dd4ff4b6ed39d146f2f8904fb2f873d96a2840d5..d2310e25ac07d48f7fc99eed7217e0c72f27dca2 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -1564,6 +1564,15 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
 		$original_file=$conf->projet->dir_output.'/'.$original_file;
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
 	}
+	else if ($modulepart == 'project_task')
+	{
+		if ($fuser->rights->projet->lire || preg_match('/^specimen/i',$original_file))
+		{
+			$accessallowed=1;
+		}
+		$original_file=$conf->projet->dir_output.'/'.$original_file;
+		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
+	}
 
 	// Wrapping pour les commandes fournisseurs
 	else if ($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier')
@@ -1786,6 +1795,12 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
 		}
 		else
 		{
+			if (empty($conf->$modulepart->dir_output))	// modulepart not supported
+			{
+				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
+				exit;
+			}
+
 			$perm=GETPOST('perm');
 			$subperm=GETPOST('subperm');
 			if ($perm || $subperm)
diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php
index 1ef865c643d87cdc6e858f45faf57cfd807c044e..a546d229481e428b7204864af30d730129758b96 100644
--- a/htdocs/core/lib/price.lib.php
+++ b/htdocs/core/lib/price.lib.php
@@ -45,8 +45,8 @@
  *		@param	string	$price_base_type 			HT=on calcule sur le HT, TTC=on calcule sur le TTC
  *		@param	int		$info_bits					Miscellaneous informations on line
  *		@param	int		$type						0/1=Product/service
- *		@param  string	$seller						Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier.
- *		@param  array	$localtaxes_array			Array with localtaxes info (loaded by getLocalTaxesFromRate function)
+ *		@param  string	$seller						Thirdparty seller (we need $seller->country_id property). Provided only if seller is the supplier, otherwise $seller will be $mysoc.
+ *		@param  array	$localtaxes_array			Array with localtaxes info (loaded by getLocalTaxesFromRate function).
  *		@return result[ 0=total_ht,
  *						 1=total_vat,
  *						 2=total_ttc,
diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
index 1195722e29e95d89a87257e56b4d83f8b7abf74a..e3ca8814a70535f0b6a267d8a513c237db2f3e07 100644
--- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
+++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
@@ -140,6 +140,16 @@ class doc_generic_order_odt extends ModelePDFCommandes
 			$resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva;
 		}
 
+		// Retrieve extrafields
+		if(is_array($object->array_options) && count($object->array_options))
+		{
+			require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+			$extrafields = new ExtraFields($this->db);
+			$extralabels = $extrafields->fetch_name_optionals_label('commande',true);
+			$object->fetch_optionals($object->id,$extralabels);
+
+			$resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key='object',$outputlangs);
+		}
 		return $resarray;
 	}
 
diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
index b515742a8e1fc37d43c0137ec87ee740ca5f670e..d1642023c2452311f1964d3302a93e420ca9ecef 100644
--- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
+++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
@@ -142,6 +142,8 @@ class doc_generic_invoice_odt extends ModelePDFFactures
 		'object_note_private'=>$object->note,
 		'object_note'=>$object->note_public,
 		// Payments
+		'object_already_payed_locale'=>price($alreadypayed, 0, $outputlangs),
+		'object_remain_to_pay_locale'=>price($object->total_ttc - $sumpayed, 0, $outputlangs),
 		'object_already_payed'=>$alreadypayed,
 		'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed)
 		);
diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php
index eeb598d20f8af1f9fac076dd33e2364b726475a3..2ae7b9ad595cfa0c82bd2eaf150455b618def14f 100644
--- a/htdocs/core/tpl/document_actions_post_headers.tpl.php
+++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php
@@ -42,7 +42,7 @@ $formfile=new FormFile($db);
 
 // Show upload form (document and links)
 $formfile->form_attach_new_file(
-    $_SERVER["PHP_SELF"].'?id='.$object->id,
+    $_SERVER["PHP_SELF"].'?id='.$object->id.(empty($withproject)?'':'&withproject=1'),
     '',
     0,
     0,
diff --git a/htdocs/core/tpl/document_actions_pre_headers.tpl.php b/htdocs/core/tpl/document_actions_pre_headers.tpl.php
index 7bfc59641407bfa5cc387c65c603d918856ad90a..989a3bcaf73d689b44e74d3f56a7b14aed06e3a9 100644
--- a/htdocs/core/tpl/document_actions_pre_headers.tpl.php
+++ b/htdocs/core/tpl/document_actions_pre_headers.tpl.php
@@ -16,6 +16,7 @@
  * or see http://www.gnu.org/
  */
 
+// Variable $upload_dir must be defined when entering here
 
 // Send file/link
 if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) {
diff --git a/htdocs/document.php b/htdocs/document.php
index bb6bd032301c6fbc956f8a16318dff10a4761c18..1b3d494d1a126b36c70d356965cecf6838e77ae8 100644
--- a/htdocs/document.php
+++ b/htdocs/document.php
@@ -168,7 +168,7 @@ if (! file_exists($original_file_osencoded))
 	exit;
 }
 
-// Les drois sont ok et fichier trouve, on l'envoie
+// Permissions are ok and file found, so we return it
 
 header('Content-Description: File Transfer');
 if ($encoding)   header('Content-Encoding: '.$encoding);
diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index ba5f4d986c41248cad19f50c307edfa6b3cba9eb..563663a770804c1c691b2653aab340e07765bd77 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -112,7 +112,8 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->fichein
 			$outputlangs = new Translate("",$conf);
 			$outputlangs->setDefaultLang($newlang);
 		}
-		$result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
+
 		header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 		exit;
 	}
@@ -137,7 +138,8 @@ else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->fich
 			$outputlangs = new Translate("",$conf);
 			$outputlangs->setDefaultLang($newlang);
 		}
-		$result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs);
+		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs);
+
 		header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 		exit;
 	}
@@ -452,7 +454,7 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
 		{
 			$db->commit();
 
-			fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 			header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 			exit;
 		}
@@ -522,7 +524,7 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST(
 		$outputlangs = new Translate("",$conf);
 		$outputlangs->setDefaultLang($newlang);
 	}
-	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 
 	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 	exit;
@@ -557,7 +559,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
 		$outputlangs = new Translate("",$conf);
 		$outputlangs->setDefaultLang($newlang);
 	}
-	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 }
 
 /*
@@ -578,7 +580,8 @@ else if ($action == 'up' && $user->rights->ficheinter->creer)
 		$outputlangs = new Translate("",$conf);
 		$outputlangs->setDefaultLang($newlang);
 	}
-	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+
 	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
 	exit;
 }
@@ -597,7 +600,8 @@ else if ($action == 'down' && $user->rights->ficheinter->creer)
 		$outputlangs = new Translate("",$conf);
 		$outputlangs->setDefaultLang($newlang);
 	}
-	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
+
 	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
 	exit;
 }
diff --git a/htdocs/install/check.php b/htdocs/install/check.php
index 73ddaca65c408f76703ceae2c9772675dcbc7435..cd4c1cb881c416dd4d6534657dd07bb611913234 100644
--- a/htdocs/install/check.php
+++ b/htdocs/install/check.php
@@ -394,24 +394,32 @@ else
 		foreach ($migrationscript as $migarray)
 		{
 			$count++;
-            $versionfrom=$migarray['from'];
+            $version=preg_split('/[\.-]/',DOL_VERSION);
+			$versionfrom=$migarray['from'];
             $versionto=$migarray['to'];
-            $newversionfrom=preg_replace('/(\.[0-9]+)$/i','.*',$versionfrom);
-            $newversionto=preg_replace('/(\.[0-9]+)$/i','.*',$versionto);
+            $versionarray=preg_split('/[\.-]/',$version);
             $dolibarrversionfromarray=preg_split('/[\.-]/',$versionfrom);
             $dolibarrversiontoarray=preg_split('/[\.-]/',$versionto);
-            $version=preg_split('/[\.-]/',DOL_VERSION);
+            // Define string newversionxxx that are used for text to show
+            $newversionfrom=preg_replace('/(\.[0-9]+)$/i','.*',$versionfrom);
+            $newversionto=preg_replace('/(\.[0-9]+)$/i','.*',$versionto);
             $newversionfrombis='';
-            if (versioncompare($dolibarrversiontoarray,$version) < -2) $newversionfrombis=' '.$langs->trans("or").' '.$versionto;
+            if (versioncompare($dolibarrversiontoarray,$version) < -2)	// From x.y.z -> x.y.z+1
+            {
+            	$newversionfrombis=' '.$langs->trans("or").' '.$versionto;
+            }
 			print '<tr class="listofchoices"><td class="listofchoices nowrap" align="center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
 			print '<td class="listofchoices">';
 			print $langs->trans("UpgradeDesc");
+
 			if ($ok)
 			{
-				if (count($dolibarrlastupgradeversionarray) >= 2)	// If a database access is available and a version x.y already available
+				if (count($dolibarrlastupgradeversionarray) >= 2)	// If a database access is available and last upgrade version is known
 				{
 					// Now we check if this is the first qualified choice
-					if ($allowupgrade && empty($foundrecommandedchoice) && versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0)
+					if ($allowupgrade && empty($foundrecommandedchoice) &&
+						(versioncompare($dolibarrversiontoarray,$dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray,$version) < -2)
+						)
 					{
 						print '<br>';
 						//print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 593ae33ebcc227d2744b915b1a51d2247cfba0ff..2bcb244690e3bc8557599ccd8e1eeb9a5198327e 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -1459,7 +1459,7 @@ function migrate_price_propal($db,$langs,$conf)
 }
 
 /**
- * Mise a jour des totaux lignes de propal
+ * Update total of contract lines
  *
  * @param	DoliDB		$db		Database handler
  * @param	Translate	$langs	Object langs
@@ -1470,6 +1470,10 @@ function migrate_price_contrat($db,$langs,$conf)
 {
     $db->begin();
 
+   	$tmpmysoc=new Societe($db);
+	$tmpmysoc->setMysoc($conf);
+    if (empty($tmpmysoc->country_id)) $tmpmysoc->country_id=0;	// Ti not have this set to '' or will make sql syntax error.
+
     print '<tr><td colspan="4">';
 
     print '<br>';
@@ -1506,7 +1510,7 @@ function migrate_price_contrat($db,$langs,$conf)
                 //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis
                 $contratligne->rowid=$rowid;
 
-                $result=calcul_price_total($qty,$pu,$remise_percent,$txtva,0,0,0,'HT',$info_bits,0);
+                $result=calcul_price_total($qty,$pu,$remise_percent,$txtva,0,0,0,'HT',$info_bits,0,$tmpmysoc);
                 $total_ht  = $result[0];
                 $total_tva = $result[1];
                 $total_ttc = $result[2];
diff --git a/htdocs/langs/fr_FR/withdrawals.lang b/htdocs/langs/fr_FR/withdrawals.lang
index 538dafdd3979670e500acd252482baad66370886..5cfef386e88a961c00a6a71bd31ff5e9a98c0c51 100644
--- a/htdocs/langs/fr_FR/withdrawals.lang
+++ b/htdocs/langs/fr_FR/withdrawals.lang
@@ -32,7 +32,7 @@ LastWithdrawalReceipt=Les %s derniers bons de prélèvements
 MakeWithdrawRequest=Faire une demande de prélèvement
 ThirdPartyBankCode=Code banque du tiers
 ThirdPartyDeskCode=Code guichet du tiers
-NoInvoiceCouldBeWithdrawed=Aucune facture percevable, prélevée avec succès. Vérifiez que les factures sont sur des sociétés dont le RIB est correctement renseigné.
+NoInvoiceCouldBeWithdrawed=Aucune facture percevable, prélevée avec succès. Vérifiez que les factures sont sur des sociétés dont le compte bancaire par défaut est correctement renseigné.
 ClassCredited=Classer crédité
 ClassCreditedConfirm=Êtes-vous sûr de vouloir classer ce bon de prélèvement comme crédité sur votre compte bancaire ?
 TransData=Date de transmission
diff --git a/htdocs/langs/pt_BR/main.lang b/htdocs/langs/pt_BR/main.lang
index 8686afedf815947123c90593ccb1b39fa9843146..e33b22f9ef935eb0eabe2f447bd37cabb75f91ac 100644
--- a/htdocs/langs/pt_BR/main.lang
+++ b/htdocs/langs/pt_BR/main.lang
@@ -8,12 +8,12 @@ FONTFORPDF=helvetica
 FONTSIZEFORPDF=10
 SeparatorDecimal=,
 SeparatorThousand=None
-FormatDateShort=%m/%d/%Y
-FormatDateShortInput=%m/%d/%Y
-FormatDateShortJava=mm/dd/aaaa
-FormatDateShortJavaInput=mm/dd/aaaa
-FormatDateShortJQuery=mm/dd/aa
-FormatDateShortJQueryInput=mm/dd/aa
+FormatDateShort=%d/%m/%Y
+FormatDateShortInput=%d/%m/%Y
+FormatDateShortJava=dd/mm/yyyy
+FormatDateShortJavaInput=dd/mm/yyyy
+FormatDateShortJQuery=dd/mm/yy
+FormatDateShortJQueryInput=dd/mm/yy
 FormatHourShort=%I:%M %p
 FormatHourShortDuration=%H:%M
 FormatDateTextShort=%b %d, %Y
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 103df7ee322cc62454d03eaf6d437cc424539e06..22a1277b9d5cf8bf08f7daa4d213bcd3c1685e1e 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -349,7 +349,7 @@ class Product extends CommonObject
 				$sql.= ", '".$this->accountancy_code_buy."'";
 				$sql.= ", '".$this->accountancy_code_sell."'";
 				$sql.= ", '".$this->canvas."'";
-				$sql.= ", ".((empty($this->finished) || $this->finished < 0)?'null':$this->finished);
+				$sql.= ", ".((! isset($this->finished) || $this->finished < 0)?'null':$this->finished);
 				$sql.= ")";
 
 				dol_syslog(get_class($this)."::Create sql=".$sql);
@@ -493,7 +493,7 @@ class Product extends CommonObject
 
 		$sql.= ", tosell = " . $this->status;
 		$sql.= ", tobuy = " . $this->status_buy;
-		$sql.= ", finished = " . ((empty($this->finished) || $this->finished < 0) ? "null" : $this->finished);
+		$sql.= ", finished = " . ((! isset($this->finished) || $this->finished < 0) ? "null" : $this->finished);
 		$sql.= ", weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null');
 		$sql.= ", weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null');
 		$sql.= ", length = " . ($this->length!='' ? "'".$this->length."'" : 'null');
diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php
index 68ae665febbd0f6149690f3ded22d57e03d58287..70bca06b0d4f10d6b5b44ba451f4bd18387168b9 100644
--- a/htdocs/societe/rib.php
+++ b/htdocs/societe/rib.php
@@ -60,7 +60,7 @@ if ($action == 'update' && ! $_POST["cancel"])
 
     $account->fetch($id);
 
-	$account->socid           = $soc->id;
+    $account->socid           = $soc->id;
 
 	$account->bank            = $_POST["bank"];
 	$account->label           = $_POST["label"];
@@ -84,6 +84,12 @@ if ($action == 'update' && ! $_POST["cancel"])
 	}
 	else
 	{
+		// If this account is the default bank account, we disable others
+		if ($account->default_rib)
+		{
+			$account->setAsDefault($id);	// This will make sure there is only one default rib
+		}
+
 		$url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id;
         header('Location: '.$url);
         exit;