diff --git a/ChangeLog b/ChangeLog
index 965ff2b3443e6ee04f0b21fd4b6d661d998a85ab..803837953253068d5f6b3bc8eb57b99b903b0c96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 English Dolibarr ChangeLog
 --------------------------------------------------------------
 
+
+***** 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.
+
 ***** ChangeLog for 3.5 compared to 3.4.* *****
 For users:
 - New: Add hidden option BANK_DISABLE_DIRECT_INPUT.
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/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php
index 86d924b5fa29e47f7b5587f8dd00924d76740aa8..f636831952c28b719d0997dafcb67a407177b5de 100644
--- a/htdocs/core/class/commondocgenerator.class.php
+++ b/htdocs/core/class/commondocgenerator.class.php
@@ -260,7 +260,7 @@ abstract class CommonDocGenerator
 	    	$array_key.'_total_localtax2'=>price2num($object->total_localtax2),
     		$array_key.'_total_ttc'=>price2num($object->total_ttc),
 	    	$array_key.'_total_discount_ht' => price2num($object->getTotalDiscount()),
-    			
+
 	    	$array_key.'_vatrate'=>vatrate($object->tva),
 	    	$array_key.'_note_private'=>$object->note,
 	    	$array_key.'_note'=>$object->note_public,
@@ -314,7 +314,7 @@ abstract class CommonDocGenerator
     	'line_date_end'=>$line->date_end
     	);
     }
-	
+
     /**
      * Define array with couple substitution key => substitution value
      *
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/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/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);