diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 5a4db149b8792b53afa5bef1498c41d34d34a134..779a7da96f5ada2919af9ce0b49d03fa06f9aa31 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -448,11 +448,12 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         	$ok=0;
         	$msg.= $langs->transnoentities('ErrorCodeCantContainZero').'<br>';
         }
-        if (!is_numeric($_POST['code']))
+        // FIXME regresion if code with not in numeric base
+        /*if (!is_numeric($_POST['code']))
     	{
 	    	$ok = 0;
 	    	$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
-	    }
+	    }*/
     }
     if (isset($_POST["pays"]) && $_POST["pays"]=='0') {
         $ok=0;
diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php
index 9fcbca3e743ef67549bf1149e694b761cc1dfd2f..6a576c580cab149b9026911e18a9b74a38502a2e 100755
--- a/htdocs/comm/action/document.php
+++ b/htdocs/comm/action/document.php
@@ -51,6 +51,19 @@ if ($user->societe_id > 0)
 	$socid = $user->societe_id;
 }
 
+$act = new ActionComm($db);
+
+if ($objectid > 0)
+{
+	$ret = $act->fetch($objectid);
+	if ($ret > 0) {
+		$company=new Societe($db);
+		$company->fetch($act->societe->id);
+		$act->societe=$company; // For backward compatibility
+		$act->thirdparty=$company;
+	}
+}
+
 // Get parameters
 $sortfield = GETPOST("sortfield",'alpha');
 $sortorder = GETPOST("sortorder",'alpha');
@@ -79,7 +92,7 @@ if ($action == 'delete')
 {
 	$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
 	$file = $upload_dir . '/' . $_GET['urlfile'];	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
-	$ret=dol_delete_file($file);
+	$ret=dol_delete_file($file,0,0,0,$act);
 	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 	$action='';
@@ -96,184 +109,172 @@ $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
 llxHeader('',$langs->trans("Agenda"),$help_url);
 
 
-if ($objectid > 0)
+if ($act->id > 0)
 {
-	$act = new ActionComm($db);
-	if ($act->fetch($objectid))
-	{
-		$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
+	$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($objectid);
 
-		$company=new Societe($db);
-		$company->fetch($act->societe->id);
-		$act->societe=$company;
+	$author=new User($db);
+	$author->fetch($act->author->id);
+	$act->author=$author;
 
-		$author=new User($db);
-		$author->fetch($act->author->id);
-		$act->author=$author;
+	if ($act->contact->id) $act->fetch_contact($act->contact->id);
 
-        if ($act->contact->id) $act->fetch_contact($act->contact->id);
+	$head=actions_prepare_head($act);
+	dol_fiche_head($head, 'documents', $langs->trans("Action"),0,'action');
 
-		$head=actions_prepare_head($act);
-		dol_fiche_head($head, 'documents', $langs->trans("Action"),0,'action');
+	// Affichage fiche action en mode visu
+	print '<table class="border" width="100%">';
 
-		// Affichage fiche action en mode visu
-		print '<table class="border" width="100%">';
+	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/index.php">'.$langs->trans("BackToList").'</a>';
 
-		$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/index.php">'.$langs->trans("BackToList").'</a>';
+	// 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 '</td></tr>';
 
-		// 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 '</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>';
+	}
 
-		// Type
-		if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
+	// Title
+	print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
+
+	// Full day event
+	print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->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"));
+	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 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 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 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>';
+	print '</tr>';
+
+	// 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"));
+	print '</td></tr>';
+
+	// Status
+	print '<tr><td nowrap>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="2">';
+	print $act->getLibStatut(4);
+	print '</td></tr>';
+
+	// Location
+	print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$act->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')
+	{
+		if ($act->societe->fetch($act->societe->id))
 		{
-			print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
+			print "<br>".dol_print_phone($act->societe->tel);
 		}
+	}
+	print '</td>';
+	print '<td>'.$langs->trans("Contact").'</td>';
+	print '<td>';
+	if ($act->contact->id > 0)
+	{
+		print $act->contact->getNomUrl(1);
+		if ($act->contact->id && $act->type_code == 'AC_TEL')
+		{
+			if ($act->contact->fetch($act->contact->id))
+			{
+				print "<br>".dol_print_phone($act->contact->phone_pro);
+			}
+		}
+	}
+	else
+	{
+		print $langs->trans("None");
+	}
 
-		// Title
-		print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
-
-        // Full day event
-        print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->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"));
-		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 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 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 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>';
-		print '</tr>';
-
-		// 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"));
-		print '</td></tr>';
-
-		// Status
-		print '<tr><td nowrap>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="2">';
-		print $act->getLibStatut(4);
-		print '</td></tr>';
+	print '</td></tr>';
 
-        // Location
-        print '<tr><td>'.$langs->trans("Location").'</td><td colspan="2">'.$act->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')
-        {
-            if ($act->societe->fetch($act->societe->id))
-            {
-                print "<br>".dol_print_phone($act->societe->tel);
-            }
-        }
-        print '</td>';
-        print '<td>'.$langs->trans("Contact").'</td>';
-        print '<td>';
-        if ($act->contact->id > 0)
-        {
-            print $act->contact->getNomUrl(1);
-            if ($act->contact->id && $act->type_code == 'AC_TEL')
-            {
-                if ($act->contact->fetch($act->contact->id))
-                {
-                    print "<br>".dol_print_phone($act->contact->phone_pro);
-                }
-            }
-        }
-        else
-        {
-            print $langs->trans("None");
-        }
-
-        print '</td></tr>';
-
-        // Project
-        if (! empty($conf->projet->enabled))
-        {
-            print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
-            if ($act->fk_project)
-            {
-                $project=new Project($db);
-                $project->fetch($act->fk_project);
-                print $project->getNomUrl(1);
-            }
-            print '</td></tr>';
-        }
-
-        // Priority
-        print '<tr><td nowrap>'.$langs->trans("Priority").'</td><td colspan="3">';
-        print ($act->priority?$act->priority:'');
-        print '</td></tr>';
-
-
-        print '</table><br><br><table class="border" width="100%">';
-
-		// Construit liste des fichiers
-		$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
-		$totalsize=0;
-		foreach($filearray as $key => $file)
+	// Project
+	if (! empty($conf->projet->enabled))
+	{
+		print '<tr><td valign="top">'.$langs->trans("Project").'</td><td colspan="3">';
+		if ($act->fk_project)
 		{
-			$totalsize+=$file['size'];
+			$project=new Project($db);
+			$project->fetch($act->fk_project);
+			print $project->getNomUrl(1);
 		}
+		print '</td></tr>';
+	}
 
+	// Priority
+	print '<tr><td nowrap>'.$langs->trans("Priority").'</td><td colspan="3">';
+	print ($act->priority?$act->priority:'');
+	print '</td></tr>';
 
-		print '<tr><td width="30%" nowrap>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
-		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
-		print '</table>';
 
-		print '</div>';
+	print '</table><br><br><table class="border" width="100%">';
 
+	// Construit liste des fichiers
+	$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
+	$totalsize=0;
+	foreach($filearray as $key => $file)
+	{
+		$totalsize+=$file['size'];
+	}
 
-		// Affiche formulaire upload
-	   	$formfile=new FormFile($db);
-		$formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create));
 
+	print '<tr><td width="30%" nowrap>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
+	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
+	print '</table>';
 
-		// List of document
-		$param='&id='.$act->id;
-		$formfile->list_of_documents($filearray,$act,'actions',$param,0,'',$user->rights->agenda->myactions->create);
-	}
-	else
-	{
-		dol_print_error($db);
-	}
+	print '</div>';
+
+
+	// Affiche formulaire upload
+	$formfile=new FormFile($db);
+	$formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create),50,$act);
+
+
+	// List of document
+	$param='&id='.$act->id;
+	$formfile->list_of_documents($filearray,$act,'actions',$param,0,'',$user->rights->agenda->myactions->create);
 }
 else
 {
diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php
index 6fbd0a23143e79bdbb8f4bfea54c0c386f74097c..f62b2fcc59447232691a1a9365fe0e347cadffd1 100644
--- a/htdocs/compta/sociales/class/chargesociales.class.php
+++ b/htdocs/compta/sociales/class/chargesociales.class.php
@@ -30,7 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  */
 class ChargeSociales extends CommonObject
 {
-    public $element='rowid';
+    public $element='chargesociales';
     public $table='chargesociales';
     public $table_element='chargesociales';
 
diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php
index dcb082b41d7dd281c4d81e69f7af7adab42cdd2d..452de21285ac71adeb76f1b9bff3b7eebd629e14 100644
--- a/htdocs/compta/sociales/document.php
+++ b/htdocs/compta/sociales/document.php
@@ -79,7 +79,7 @@ if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
 if ($action == 'delete')
 {
 	$file = $upload_dir . '/' . GETPOST("urlfile");	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
-	$ret=dol_delete_file($file);
+	$ret=dol_delete_file($file,0,0,0,$object);
 	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 }
@@ -172,7 +172,7 @@ if ($object->id)
 
     // Affiche formulaire upload
    	$formfile=new FormFile($db);
-   	$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id,'',0,0,$user->rights->tax->charges->creer);
+   	$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id,'',0,0,$user->rights->tax->charges->creer,50,$object);
 
 
    	// List of document
diff --git a/htdocs/core/class/fileupload.class.php b/htdocs/core/class/fileupload.class.php
index c5e830179400d20e58725ae9b4cc7423ecdb904b..910ad55e0a0eaac8cfe4ef38670e7ba089c4f683 100644
--- a/htdocs/core/class/fileupload.class.php
+++ b/htdocs/core/class/fileupload.class.php
@@ -56,6 +56,8 @@ class FileUpload
 			$filename = $regs[2];
 		}
 
+		$parentForeignKey = '';
+
 		// For compatibility
 		if ($element == 'propal') {
 			$pathname = 'comm/propal';
@@ -69,6 +71,14 @@ class FileUpload
 			$element = $pathname = 'projet';
 			$dir_output=$conf->$element->dir_output;
 		}
+		elseif ($element == 'project_task') {
+			$pathname = 'projet'; $filename='task';
+			$dir_output=$conf->projet->dir_output;
+			$parentForeignKey = 'fk_project';
+			$parentClass = 'Project';
+			$parentElement = 'projet';
+			$parentObject = 'project';
+		}
 		elseif ($element == 'fichinter') {
 			$element='ficheinter';
 			$dir_output=$conf->$element->dir_output;
@@ -80,6 +90,17 @@ class FileUpload
 		elseif ($element == 'invoice_supplier') {
 			$pathname = 'fourn'; $filename='fournisseur.facture';
 			$dir_output=$conf->fournisseur->facture->dir_output;
+		}
+		elseif ($element == 'product') {
+			$dir_output = $conf->product->multidir_output[$conf->entity];
+		}
+		elseif ($element == 'action') {
+			$pathname = 'comm/action'; $filename='actioncomm';
+			$dir_output=$conf->agenda->dir_output;
+		}
+		elseif ($element == 'chargesociales') {
+			$pathname = 'compta/sociales'; $filename='chargesociales';
+			$dir_output=$conf->tax->dir_output;
 		} else {
 			$dir_output=$conf->$element->dir_output;
 		}
@@ -97,11 +118,23 @@ class FileUpload
 		$object = new $classname($db);
 
 		$object->fetch($fk_element);
-		$object->fetch_thirdparty();
+		if (!empty($parentForeignKey)) {
+			dol_include_once('/'.$parentElement.'/class/'.$parentObject.'.class.php');
+			$parent = new $parentClass($db);
+			$parent->fetch($object->$parentForeignKey);
+			if (!empty($parent->socid)) {
+				$parent->fetch_thirdparty();
+			}
+			$object->$parentObject = dol_clone($parent);
+		} else {
+			$object->fetch_thirdparty();
+		}
 
 		$object_ref = dol_sanitizeFileName($object->ref);
 		if ($element == 'invoice_supplier') {
 			$object_ref = get_exdir($object->id, 2) . $object_ref;
+		} else if ($element == 'project_task') {
+			$object_ref = $object->project->ref . '/' . $object_ref;
 		}
 
 		$this->options = array(
diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index f28e5d27e6d3f629a91b7268b05d52d9de09c6c8..12571aad64ae516e3bc76ff9d95cce7f5f202391 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -171,6 +171,7 @@ class Task extends CommonObject
         $sql.= " t.label,";
         $sql.= " t.description,";
         $sql.= " t.duration_effective,";
+        $sql.= " t.datec,";
         $sql.= " t.dateo,";
         $sql.= " t.datee,";
         $sql.= " t.fk_user_creat,";
diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php
index 5d42a44d54b67ee32b2b201f5e238a589575cbfb..90adc2925c22fccf52537cf8be86ce9ec471fa33 100644
--- a/htdocs/projet/tasks/document.php
+++ b/htdocs/projet/tasks/document.php
@@ -93,7 +93,11 @@ if ($id > 0 || ! empty($ref))
 	{
 		$projectstatic->fetch($object->fk_project);
 
-		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
+		if (! empty($projectstatic->socid)) {
+			$projectstatic->fetch_thirdparty();
+		}
+
+		$object->project = dol_clone($projectstatic);
 
 		$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
 	}
@@ -114,7 +118,7 @@ if ($action=='delete')
 {
     $langs->load("other");
 	$file = $upload_dir . '/' . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
-	$ret=dol_delete_file($file);
+	$ret=dol_delete_file($file,0,0,0,$object);
 	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
     header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);