diff --git a/modules/export_seda/Ajax_transfer_SAE.php b/modules/export_seda/Ajax_transfer_SAE.php
index 28f0ab331547b6d296dfe4539237c2c8ededf881..d0529d7570fb7cd89c0a4ccfd550aa2930703d04 100644
--- a/modules/export_seda/Ajax_transfer_SAE.php
+++ b/modules/export_seda/Ajax_transfer_SAE.php
@@ -1,109 +1,114 @@
 <?php
-/*
-*   Copyright 2008-2017 Maarch
-*
-*   This file is part of Maarch Framework.
-*
-*   Maarch Framework is free software: you can redistribute it and/or modify
-*   it under the terms of the GNU General Public License as published by
-*   the Free Software Foundation, either version 3 of the License, or
-*   (at your option) any later version.
-*
-*   Maarch Framework is distributed in the hope that it will be useful,
-*   but WITHOUT ANY WARRANTY; without even the implied warranty of
-*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*   GNU General Public License for more details.
+
+/**
+* Copyright Maarch since 2008 under licence GPLv3.
+* See LICENCE.txt file at the root folder for more details.
+* This file is part of Maarch software.
 *
-*   You should have received a copy of the GNU General Public License
-*   along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
 */
-	$status = 0;
-	$error = $content = '';
-	if ($_REQUEST['reference']) {
-		$transferToSAE = new TransferToSAE();
-		$res = $transferToSAE->send($_REQUEST['reference']);
-		$status = $res['status'];
-		if ($status != 0) {
-			$error = $res['error'];
-		} else {
-			$content = $res['content'];
-		}
-		
-	} else {
-		$status = 1;
-	}
-
-	
-	echo "{status : " . $status . ", content : '" . addslashes($content) . "', error : '" . addslashes($error) . "'}";
-	exit ();
-
-class TransferToSAE{
-	protected $token;
+
+/**
+* @brief Export seda transfer
+* @author dev@maarch.org
+* @ingroup export_seda
+*/
+
+$status = 0;
+$error = $content = '';
+if ($_REQUEST['reference']) {
+    $transferToSAE = new TransferToSAE();
+    $res = $transferToSAE->send($_REQUEST['reference']);
+    $status = $res['status'];
+    if ($status != 0) {
+        $error = $res['error'];
+    } else {
+        $content = $res['content'];
+    }
+} else {
+    $status = 1;
+}
+
+    
+    echo "{status : " . $status . ", content : '" . addslashes($content) . "', error : '" . addslashes($error) . "'}";
+    exit ();
+
+class TransferToSAE
+{
+    protected $token;
     protected $SAE;
 
     public function __construct()
     {
-    	$config = parse_ini_file(__DIR__.'/config.ini');
+        $config = parse_ini_file(__DIR__.'/config.ini');
         $this->token = $config['token'];
         $this->SAE = $config['urlSAE'];
     }
 
     public function send($reference)
     {
-    	$res = [];
-    	$res['status'] = 0;
-    	$res['content'] = _RECEIVED_MESSAGE;
+        $res = [];
+        $res['status'] = 0;
+        $res['content'] = _RECEIVED_MESSAGE;
 
         $data = new stdClass();
-    	$messageDirectory = __DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$reference;
+        $messageDirectory = __DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$reference;
         $messageFile = $reference.".xml";
 
         $files = scandir($messageDirectory);
         $attachments = [];
         foreach ($files as $file) {
             if ($file != $messageFile && $file != ".." && $file != ".") {
-                $data->attachments[] = $messageDirectory.DIRECTORY_SEPARATOR.$file;
+                $attachment = new stdClass;
+                $attachment->data = base64_encode(
+                    file_get_contents($messageDirectory . DIRECTORY_SEPARATOR . $file)
+                );
+                $attachment->filename = $file;
+
+                $data->attachments[] = $attachment;
             }
         }
 
-        $data->messageFile = $messageDirectory.DIRECTORY_SEPARATOR.$reference.".xml";
+        $data->messageFile = base64_encode(
+            file_get_contents($messageDirectory . DIRECTORY_SEPARATOR . $reference.".xml")
+        );
 
-		$header = [
+        $header = [
             'accept:application/json',
             'content-type:application/json'
         ];
 
         $token = explode("LAABS-AUTH=", $this->token);
         if (count($token) != 0) {
-        	$urlencode = urlencode($token[1]);
-        	$this->token = "LAABS-AUTH=". $urlencode;
+            $urlencode = urlencode($token[1]);
+            $this->token = "LAABS-AUTH=". $urlencode;
         }
 
-    	try {
-    		$curl = curl_init();
-
-			curl_setopt($curl, CURLOPT_URL, $this->SAE);
-			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-			curl_setopt($curl, CURLOPT_POST, true);
-			curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
-			curl_setopt($curl, CURLOPT_COOKIE,$this->token);
-			curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
-			//curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post));
+        try {
+            $curl = curl_init();
 
-			$return = json_decode(curl_exec($curl));
+            curl_setopt($curl, CURLOPT_URL, $this->SAE);
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($curl, CURLOPT_POST, true);
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+            curl_setopt($curl, CURLOPT_COOKIE, $this->token);
+            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
+            //curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post));
             
-			if (!$return) {
-				$res['status'] = 1;
-				$res['error'] = _ERROR_MESSAGE;
-			} else {
+            $return = json_decode(curl_exec($curl));
+            
+            
+            if (!$return) {
+                $res['status'] = 1;
+                $res['error'] = _ERROR_MESSAGE;
+            } else {
                 $res['content'] .= $return->reference;
-             }
+            }
 
-			curl_close($curl);
-    	} catch(Exception $e) {
-    		var_dump($e);
-    	}
+            curl_close($curl);
+        } catch (Exception $e) {
+            var_dump($e);
+        }
         
         return $res;
     }
-}
\ No newline at end of file
+}
diff --git a/modules/export_seda/Ajax_validate_message.php b/modules/export_seda/Ajax_validate_message.php
index f2af91d1cefb53ce31d2a93ac9d1ee6953c92284..fac58f7aa70822a486b6880bc96e9524f54bee20 100644
--- a/modules/export_seda/Ajax_validate_message.php
+++ b/modules/export_seda/Ajax_validate_message.php
@@ -24,30 +24,29 @@ require_once 'apps/maarch_entreprise/Models/ContactsModel.php';
 require_once __DIR__.'/RequestSeda.php';
 require_once __DIR__.'/ArchiveTransfer.php';
 
-	$status = 0;
-	$error = $content = '';
-	if ($_REQUEST['reference']) {
-		$validateMessage = new ValidateMessage();
-		$res = $validateMessage->validate($_REQUEST['reference']);
-		$status = $res['status'];
-		if ($status != 0) {
-			$error = $res['error'];
-		} else {
-			$content = $res['content'];
-		}
-		
-	} else {
-		$status = 1;
-	}
-
-	
-	echo "{status : " . $status . ", content : '" . addslashes($content) . "', error : '" . addslashes($error) . "'}";
-	exit ();
-
-class ValidateMessage{
+$status = 0;
+$error = $content = '';
+if ($_REQUEST['reference']) {
+    $validateMessage = new ValidateMessage();
+    $res = $validateMessage->validate($_REQUEST['reference']);
+    $status = $res['status'];
+    if ($status != 0) {
+        $error = $res['error'];
+    } else {
+        $content = $res['content'];
+    }
+} else {
+    $status = 1;
+}
+
+echo "{status : " . $status . ", content : '" . addslashes($content) . "', error : '" . addslashes($error) . "'}";
+exit ();
+
+class ValidateMessage
+{
     private $db;
     private $res;
-    private $config;
+    private $deleteData;
 
     public function __construct()
     {
@@ -57,17 +56,18 @@ class ValidateMessage{
         $this->res['content'] = "";
 
         $config = parse_ini_file(__DIR__.'/config.ini');
+        $this->deleteData = $config['deleteData'];
     }
 
     public function validate($reference)
     {
         try {
-            if ($config['deleteData']) {
-            	$message = $this->db->getMessageByReference($reference);
+            if ($this->deleteData) {
+                $message = $this->db->getMessageByReference($reference);
 
                 $listResId = $this->db->getUnitIdentifierByMessageId($message->message_id);
 
-                for ($i=0;$i < count($listResId); $i++) {
+                for ($i=0; $i < count($listResId); $i++) {
                     $this->purgeResource($listResId[$i]->res_id);
 
                     $courrier = $this->db->getCourrier($listResId[$i]->res_id);
@@ -95,7 +95,7 @@ class ValidateMessage{
         $action = new \Core\Controllers\ResController();
         $data = [];
 
-        array_push($data,array(
+        array_push($data, array(
                 'column' => 'status',
                 'value' => 'DEL',
                 'type' => 'string'
@@ -119,4 +119,4 @@ class ValidateMessage{
             'id'=>$contactId
             ]);
     }
-}
\ No newline at end of file
+}
diff --git a/modules/export_seda/ArchiveTransfer.php b/modules/export_seda/ArchiveTransfer.php
index 5a8eb15eb6cbc11ad6f957fca1704acd5a69588b..ea18fa190e7bef1fd3703fe8c72575e3ff8ca9d1 100644
--- a/modules/export_seda/ArchiveTransfer.php
+++ b/modules/export_seda/ArchiveTransfer.php
@@ -22,378 +22,380 @@
 require_once __DIR__.'/RequestSeda.php';
 require_once __DIR__.'/DOMTemplateProcessor.php';
 
-class ArchiveTransfer {
-	private $db;
-
-	public function __construct() 
-	{
-		$this->db = new RequestSeda();
-		$_SESSION['error'] = "";
-	}
-
-	public function receive($listResId) {
-		if (!$listResId) {
-			return false;
-		}
-		
-		$messageObject = new stdClass();
-		$messageObject = $this->initMessage($messageObject);
-
-		$result = [];
-		foreach ($listResId as $resId) {
-			$result .= $resId.'#';
-
-			$letterbox = $this->db->getCourrier($resId);
-			$attachments = $this->db->getAttachments($letterbox->res_id);
-
-			$archiveUnitId = uniqid();
-			if ($letterbox->filename) {
-				$messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($letterbox, "File", $attachments,$archiveUnitId, $letterbox->res_id, null);
-				$messageObject->dataObjectPackage->binaryDataObject[] = $this->getBinaryDataObject($letterbox);
-			} else {
-				$messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($letterbox, "File");
-			}
-
-			if ($attachments) {
-				foreach ($attachments as $attachment) {
-					if ($attachment->attachment_type == "simple_attachment" || $attachment->attachment_type == "signed_response") {
-						if ($attachment->attachment_type == "signed_response" && $attachment->res_id_master == $letterbox->res_id) {
-							$messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($attachment, "Response", null, null,"attachment_".$attachment->res_id, $archiveUnitId);
-						}
-
-						$messageObject->dataObjectPackage->binaryDataObject[] = $this->getBinaryDataObject($attachment,true);
-					}
-				}
-			}
-		}
-
-		$res = $this->db->insertMessage($messageObject,$listResId);
-
-		if ($res) {
-			$this->sendXml($messageObject);
-		} else {
-			return $res;
-		}
-		
-		return $result;
-	}
-
-	public function sendXml($messageObject)
-	{
-		$DOMTemplate = new DOMDocument();
-		$DOMTemplate->load(__DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'ArchiveTransfer.xml');
-		$DOMTemplateProcessor = new DOMTemplateProcessor($DOMTemplate);
-		$DOMTemplateProcessor->setSource('ArchiveTransfer', $messageObject);
-		$DOMTemplateProcessor->merge();
-		$DOMTemplateProcessor->removeEmptyNodes();
-
-		if (!is_dir(__DIR__.DIRECTORY_SEPARATOR.'seda2')) {
-			mkdir(__DIR__.DIRECTORY_SEPARATOR.'seda2', 0777, true);
-		}
-
-		$messageId = $messageObject->messageIdentifier->value;
-		if (!is_dir(__DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId)) {
-			mkdir(__DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId, 0777, true);
-		}
+class ArchiveTransfer
+{
+    private $db;
+
+    public function __construct()
+    {
+        $this->db = new RequestSeda();
+        $_SESSION['error'] = "";
+    }
+
+    public function receive($listResId)
+    {
+        if (!$listResId) {
+            return false;
+        }
+        
+        $messageObject = new stdClass();
+        $messageObject = $this->initMessage($messageObject);
+
+        $result = [];
+        foreach ($listResId as $resId) {
+            $result .= $resId.'#';
+
+            $letterbox = $this->db->getCourrier($resId);
+            $attachments = $this->db->getAttachments($letterbox->res_id);
+
+            $archiveUnitId = uniqid();
+            if ($letterbox->filename) {
+                $messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($letterbox, "File", $attachments,$archiveUnitId, $letterbox->res_id, null);
+                $messageObject->dataObjectPackage->binaryDataObject[] = $this->getBinaryDataObject($letterbox);
+            } else {
+                $messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($letterbox, "File");
+            }
+
+            if ($attachments) {
+                foreach ($attachments as $attachment) {
+                    if ($attachment->attachment_type == "simple_attachment" || $attachment->attachment_type == "signed_response") {
+                        if ($attachment->attachment_type == "signed_response" && $attachment->res_id_master == $letterbox->res_id) {
+                            $messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit[] = $this->getArchiveUnit($attachment, "Response", null, null,"attachment_".$attachment->res_id, $archiveUnitId);
+                        }
+
+                        $messageObject->dataObjectPackage->binaryDataObject[] = $this->getBinaryDataObject($attachment,true);
+                    }
+                }
+            }
+        }
+
+        $res = $this->db->insertMessage($messageObject,$listResId);
+
+        if ($res) {
+            $this->sendXml($messageObject);
+        } else {
+            return $res;
+        }
+        
+        return $result;
+    }
+
+    public function sendXml($messageObject)
+    {
+        $DOMTemplate = new DOMDocument();
+        $DOMTemplate->load(__DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'ArchiveTransfer.xml');
+        $DOMTemplateProcessor = new DOMTemplateProcessor($DOMTemplate);
+        $DOMTemplateProcessor->setSource('ArchiveTransfer', $messageObject);
+        $DOMTemplateProcessor->merge();
+        $DOMTemplateProcessor->removeEmptyNodes();
+
+        if (!is_dir(__DIR__.DIRECTORY_SEPARATOR.'seda2')) {
+            mkdir(__DIR__.DIRECTORY_SEPARATOR.'seda2', 0777, true);
+        }
+
+        $messageId = $messageObject->messageIdentifier->value;
+        if (!is_dir(__DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId)) {
+            mkdir(__DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId, 0777, true);
+        }
 
         file_put_contents(__DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId.DIRECTORY_SEPARATOR.$messageId.'.xml', $DOMTemplate->saveXML());
 
         $this->sendAttachment($messageObject);
 
-		return $xml;
-	}
-
-	public function deleteMessage($listResId)
-	{
-		if (!$listResId) {
-			return false;
-		}
-
-		$resIds = [];
-		if(!is_array($listResId)) {
-			$resIds[] = $listResId;
-		} else {
-			$resIds = $listResId;
-		}
-
-
-		foreach ($resIds as $resId) {
-			$unitIdentifiers = $this->db->getUnitIdentifierByResId($resId);
-			foreach ($unitIdentifiers as $unitIdentifier) {
-				$this->db->deleteSeda($unitIdentifier->message_id);
-				$this->db->deleteUnitIdentifier($unitIdentifier->message_id);
-			}
-		}
-
-		return true;
-	}
-	private function sendAttachment($messageObject)
-	{
-		$messageId = $messageObject->messageIdentifier->value;
-
-		foreach ($messageObject->dataObjectPackage->binaryDataObject as $binaryDataObject) {
-			$basename = basename($binaryDataObject->uri);
-			$dest = __DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId.DIRECTORY_SEPARATOR.$basename;
-
-			copy($binaryDataObject->uri, $dest);
-		}
-	}
-
-	private function initMessage($messageObject)
-	{
-		$date = new DateTime;
-		$messageObject->date = $date->format(DateTime::ATOM);
-		$messageObject->messageIdentifier = new stdClass();
-		$messageObject->messageIdentifier->value = $_SESSION['user']['UserId'] . "-" . date('Ymd-His');
-
-		$messageObject->transferringAgency = new stdClass();
-		$messageObject->transferringAgency->identifier = new stdClass();
-
-		$messageObject->archivalAgency = new stdClass();
-		$messageObject->archivalAgency->identifier = new stdClass();
-
-		$messageObject->archivalAgreement = new stdClass();
-
-		foreach ($_SESSION['user']['entities'] as $entitie) {
-			$entitie = $this->db->getEntitie($entitie['ENTITY_ID']);
-			if ($entitie) {
-				$messageObject->transferringAgency->identifier->value = $entitie->business_id;
-				$messageObject->archivalAgency->identifier->value = $entitie->archival_agency;
-
-				if (!$entitie->business_id) {
-					$_SESSION['error'] .= _TRANSFERRING_AGENCY_SIREN_COMPULSORY;
-				}
-
-				if (!$entitie->archival_agency) {
-					$_SESSION['error'] .= _ARCHIVAL_AGENCY_SIREN_COMPULSORY;
-				}
-
-				$messageObject->archivalAgreement->value = $entitie->archival_agreement;
-			} else {
-				// TODO return error;
-			}
-		}
-		
-		$messageObject->dataObjectPackage = new stdClass();
-		$messageObject->dataObjectPackage->binaryDataObject = [];
-		$messageObject->dataObjectPackage->descriptiveMetadata = new stdClass();
-		$messageObject->dataObjectPackage->managementMetadata = new stdClass();
-		$messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit = [];
-
-		return $messageObject;
-	}
-
-	private function getArchiveUnit($object, $type, $attachments =null, $archiveUnitId = null, $dataObjectReferenceId = null, $relatedObjectReference =null)
-	{
-		$messageArchiveUnit = new stdClass();
-
-		if ($archiveUnitId) {
-			$messageArchiveUnit->id = $archiveUnitId;
-		} else {
-			$messageArchiveUnit->id = uniqid();
-		}
-		
-		if ($relatedObjectReference) {
-			$messageArchiveUnit->content = $this->getContent($object, $type, $relatedObjectReference);
-		} else {
-			$messageArchiveUnit->content = $this->getContent($object, $type);
-		}
-
-		if ($object->type_id != 0) {
-			$messageArchiveUnit->management = $this->getManagement($object);
-		}
-
-		if ($dataObjectReferenceId) {
-			$messageArchiveUnit->dataObjectReference = new stdClass();
-			$messageArchiveUnit->dataObjectReference->dataObjectReferenceId = "doc_".$dataObjectReferenceId;
-		}
-
-		
-		if ($attachments) {
-			$messageArchiveUnit->archiveUnit = [];
-			foreach ($attachments as $attachment) {
-				if ($attachment->res_id_master == $object->res_id) {
-					if ($attachment->attachment_type == "simple_attachment") {
-						$messageArchiveUnit->archiveUnit[] = $this->getArchiveUnit($attachment, "Item", null, null, "attachment_".$attachment->res_id);
-					}
-				}
-			}
-		}
-
-		if (count($messageArchiveUnit->archiveUnit) == 0) {
-			unset($messageArchiveUnit->archiveUnit);
-		}
-		
-		return $messageArchiveUnit;
-	}
-
-	private function getContent($object, $type, $relatedObjectReference = null)
-	{
-		$content = new stdClass();
-
-		if ($type == "File") {
-			$content->descriptionLevel = $type;
-			$content->receivedDate = $object->admission_date;
-			$sentDate = new DateTime($object->doc_date);
-			$receivedDate = new DateTime($object->admission_date);
-			$content->sentDate = $sentDate->format(DateTime::ATOM);
-			$content->receivedDate = $receivedDate->format(DateTime::ATOM);
-
-			$content->addressee = [];
-			$content->keyword = [];
-
-			if ($object->exp_contact_id) {
-				
-				$contact = $this->db->getContact($object->exp_contact_id);
-				$entitie = $this->db->getEntitie($object->destination);
-
-				$content->keyword[] = $this->getKeyword($contact);
-				$content->addressee[] = $this->getAddresse($entitie,"entitie");
-			} else if ($object->dest_contact_id) {
-				$contact = $this->db->getContact($object->dest_contact_id);
-				$entitie = $this->db->getEntitie($object->destination);
-
-				$content->addressee[] = $this->getAddresse($contact);
-				$content->keyword[] = $this->getKeyword($entitie,"entitie");
-			} else if ($object->exp_user_id) {
-				$user = $this->db->getUserInformation($object->exp_user_id);
-				$entitie = $this->db->getEntitie($object->initiator);
-				//$entitie = $this->getEntitie($letterbox->destination);
-
-				$content->keyword[] = $this->getKeyword($user);
-				$content->addressee[] = $this->getAddresse($entitie,"entitie");
-			}
-			
-			$content->source = $_SESSION['mail_nature'][$object->nature_id];
-
-			$content->documentType = $object->type_label;
-			$content->originatingAgencyArchiveUnitIdentifier = $object->alt_identifier;
-			$content->originatingSystemId = $object->res_id;
-			$content->title = [];
-			$content->title[] = $object->subject;
-			$endDate = new DateTime($object->process_limit_date);
-			$content->endDate = $endDate->format(DateTime::ATOM);
-
-		} else {
-			$content->descriptionLevel = "Item";
-			$content->title = [];
-			$content->title[] = $object->title;
-			$content->originatingSystemId = $object->res_id;
-			$content->documentType = "Attachment";
-
-			if ($type == "Response") {
-				$reference = new stdClass();
-				$reference->repositoryArchiveUnitPID = $relatedObjectReference;
-
-				$content->relatedObjectReference = new stdClass();
-				$content->relatedObjectReference->references = [];
-
-				$repositoryArchiveUnitPID = new stdClass();
-				$repositoryArchiveUnitPID = $reference;
-				$content->relatedObjectReference->references[] = $repositoryArchiveUnitPID;
-			}
-		}
-
-		/*$notes = $this->getNotes($letterbox->res_id);
-		$content->custodialHistory = new stdClass();
-		$content->custodialHistory->custodialHistoryItem = [];
-
-		foreach ($notes as $note) {
-			$content->custodialHistory->custodialHistoryItem[] = $this->getCustodialHistoryItem($note);
-		}*/
-
-		return $content;
-	}
-
-	private function getManagement($letterbox) {
-		$management = new stdClass();
-
-		$docTypes = $this->db->getDocTypes($letterbox->type_id);
-
-		$management->appraisalRule = new stdClass();
-		$management->appraisalRule->rule = new stdClass();
-		$management->appraisalRule->rule->value = $docTypes->retention_rule;
-		if ($docTypes->retention_final_disposition == "preservation") {
-			$management->appraisalRule->finalAction = "Keep";
-		} else {
-			$management->appraisalRule->finalAction = "Destroy";
-		}
-		
-		
-		return $management;
-	}
-
-	private function getBinaryDataObject($object, $isAttachment = false)
-	{
-		$docServers = $this->db->getDocServer($object->docserver_id);
-
-		$binaryDataObject = new stdClass();
-
-		if ($isAttachment) {
-			$binaryDataObject->id = "attachment_".$object->res_id;
-		} else {
-			$binaryDataObject->id = $object->res_id;
-		}
-		
-		$binaryDataObject->messageDigest = new stdClass();
-		$binaryDataObject->messageDigest->value = $object->fingerprint;
-		$binaryDataObject->messageDigest->algorithm = "xxx";
-
-		$binaryDataObject->size = new stdClass();
-		$binaryDataObject->size->value = $object->filesize;
-
-		$uri = str_replace("##", DIRECTORY_SEPARATOR, $object->path);
-		$uri =  str_replace("#", DIRECTORY_SEPARATOR, $uri);
-		$uri .= $object->filename;
-		$binaryDataObject->uri = $docServers->path_template.$uri;
-
-		return $binaryDataObject;
-	}
-
-	private function getKeyword($informations, $type = null)
-	{
-		$keyword = new stdClass();
-		$keyword->keywordContent = new stdClass();
-
-		if ($type == "entitie") {
-			$keyword->keywordType = "corpname";
-			$keyword->keywordContent = $informations->business_id;
-		} else if ($informations->is_corporate_person == "Y") {
-			$keyword->keywordType = "corpname";
-			$keyword->keywordContent->value = $informations->society;
-		} else {
-			$keyword->keywordType = "personname";
-			$keyword->keywordContent->value = $informations->lastname . " " . $informations->firstname;
-		}
-
-		return $keyword;
-	}
-
-	private function getAddresse($informations, $type = null)
-	{
-		$addressee = new stdClass();
-		if ($type == "entitie") {
-			$addressee->corpname = $informations->entity_label;
-			$addressee->identifier = $informations->business_id;
-		} else if ($informations->is_corporate_person == "Y") {
-			$addressee->corpname = $informations->society;
-			$addressee->identifier = $informations->contact_id;
-		} else {
-			$addressee->firstName = $informations->firstname;
-			$addressee->birthName = $informations->lastname;
-		}
-			
-
-		return $addressee;
-	}
-
-	private function getCustodialHistoryItem($note) 
-	{
-		$custodialHistoryItem = new stdClass();
-
-		$custodialHistoryItem->value = $note->note_text;
-		$custodialHistoryItem->when = $note->date_note;
-
-		return $custodialHistoryItem;
-	}
+        return $xml;
+    }
+
+    public function deleteMessage($listResId)
+    {
+        if (!$listResId) {
+            return false;
+        }
+
+        $resIds = [];
+        if (!is_array($listResId)) {
+            $resIds[] = $listResId;
+        } else {
+            $resIds = $listResId;
+        }
+
+
+        foreach ($resIds as $resId) {
+            $unitIdentifiers = $this->db->getUnitIdentifierByResId($resId);
+            foreach ($unitIdentifiers as $unitIdentifier) {
+                $this->db->deleteSeda($unitIdentifier->message_id);
+                $this->db->deleteUnitIdentifier($unitIdentifier->message_id);
+            }
+        }
+
+        return true;
+    }
+    private function sendAttachment($messageObject)
+    {
+        $messageId = $messageObject->messageIdentifier->value;
+
+        foreach ($messageObject->dataObjectPackage->binaryDataObject as $binaryDataObject) {
+            $basename = basename($binaryDataObject->uri);
+            $dest = __DIR__.DIRECTORY_SEPARATOR.'seda2'.DIRECTORY_SEPARATOR.$messageId.DIRECTORY_SEPARATOR.$basename;
+
+            copy($binaryDataObject->uri, $dest);
+        }
+    }
+
+    private function initMessage($messageObject)
+    {
+        $date = new DateTime;
+        $messageObject->date = $date->format(DateTime::ATOM);
+        $messageObject->messageIdentifier = new stdClass();
+        $messageObject->messageIdentifier->value = $_SESSION['user']['UserId'] . "-" . date('Ymd-His');
+
+        $messageObject->transferringAgency = new stdClass();
+        $messageObject->transferringAgency->identifier = new stdClass();
+
+        $messageObject->archivalAgency = new stdClass();
+        $messageObject->archivalAgency->identifier = new stdClass();
+
+        $messageObject->archivalAgreement = new stdClass();
+
+        foreach ($_SESSION['user']['entities'] as $entitie) {
+            $entitie = $this->db->getEntitie($entitie['ENTITY_ID']);
+            if ($entitie) {
+                $messageObject->transferringAgency->identifier->value = $entitie->business_id;
+                $messageObject->archivalAgency->identifier->value = $entitie->archival_agency;
+
+                if (!$entitie->business_id) {
+                    $_SESSION['error'] .= _TRANSFERRING_AGENCY_SIREN_COMPULSORY;
+                }
+
+                if (!$entitie->archival_agency) {
+                    $_SESSION['error'] .= _ARCHIVAL_AGENCY_SIREN_COMPULSORY;
+                }
+
+                $messageObject->archivalAgreement->value = $entitie->archival_agreement;
+            } else {
+                // TODO return error;
+            }
+        }
+        
+        $messageObject->dataObjectPackage = new stdClass();
+        $messageObject->dataObjectPackage->binaryDataObject = [];
+        $messageObject->dataObjectPackage->descriptiveMetadata = new stdClass();
+        $messageObject->dataObjectPackage->managementMetadata = new stdClass();
+        $messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit = [];
+
+        return $messageObject;
+    }
+
+    private function getArchiveUnit($object, $type, $attachments =null, $archiveUnitId = null, $dataObjectReferenceId = null, $relatedObjectReference =null)
+    {
+        $messageArchiveUnit = new stdClass();
+
+        if ($archiveUnitId) {
+            $messageArchiveUnit->id = $archiveUnitId;
+        } else {
+            $messageArchiveUnit->id = uniqid();
+        }
+        
+        if ($relatedObjectReference) {
+            $messageArchiveUnit->content = $this->getContent($object, $type, $relatedObjectReference);
+        } else {
+            $messageArchiveUnit->content = $this->getContent($object, $type);
+        }
+
+        if ($object->type_id != 0) {
+            $messageArchiveUnit->management = $this->getManagement($object);
+        }
+
+        if ($dataObjectReferenceId) {
+            $messageArchiveUnit->dataObjectReference = new stdClass();
+            $messageArchiveUnit->dataObjectReference->dataObjectReferenceId = "doc_".$dataObjectReferenceId;
+        }
+
+        
+        if ($attachments) {
+            $messageArchiveUnit->archiveUnit = [];
+            foreach ($attachments as $attachment) {
+                if ($attachment->res_id_master == $object->res_id) {
+                    if ($attachment->attachment_type == "simple_attachment") {
+                        $messageArchiveUnit->archiveUnit[] = $this->getArchiveUnit($attachment, "Item", null, null, "attachment_".$attachment->res_id);
+                    }
+                }
+            }
+        }
+
+        if (count($messageArchiveUnit->archiveUnit) == 0) {
+            unset($messageArchiveUnit->archiveUnit);
+        }
+        
+        return $messageArchiveUnit;
+    }
+
+    private function getContent($object, $type, $relatedObjectReference = null)
+    {
+        $content = new stdClass();
+
+        if ($type == "File") {
+            $content->descriptionLevel = $type;
+            $content->receivedDate = $object->admission_date;
+            $sentDate = new DateTime($object->doc_date);
+            $receivedDate = new DateTime($object->admission_date);
+            $content->sentDate = $sentDate->format(DateTime::ATOM);
+            $content->receivedDate = $receivedDate->format(DateTime::ATOM);
+
+            $content->addressee = [];
+            $content->keyword = [];
+
+            if ($object->exp_contact_id) {
+                
+                $contact = $this->db->getContact($object->exp_contact_id);
+                $entitie = $this->db->getEntitie($object->destination);
+
+                $content->keyword[] = $this->getKeyword($contact);
+                $content->addressee[] = $this->getAddresse($entitie,"entitie");
+            } else if ($object->dest_contact_id) {
+                $contact = $this->db->getContact($object->dest_contact_id);
+                $entitie = $this->db->getEntitie($object->destination);
+
+                $content->addressee[] = $this->getAddresse($contact);
+                $content->keyword[] = $this->getKeyword($entitie,"entitie");
+            } else if ($object->exp_user_id) {
+                $user = $this->db->getUserInformation($object->exp_user_id);
+                $entitie = $this->db->getEntitie($object->initiator);
+                //$entitie = $this->getEntitie($letterbox->destination);
+
+                $content->keyword[] = $this->getKeyword($user);
+                $content->addressee[] = $this->getAddresse($entitie,"entitie");
+            }
+            
+            $content->source = $_SESSION['mail_nature'][$object->nature_id];
+
+            $content->documentType = $object->type_label;
+            $content->originatingAgencyArchiveUnitIdentifier = $object->alt_identifier;
+            $content->originatingSystemId = $object->res_id;
+            $content->title = [];
+            $content->title[] = $object->subject;
+            $endDate = new DateTime($object->process_limit_date);
+            $content->endDate = $endDate->format(DateTime::ATOM);
+
+        } else {
+            $content->descriptionLevel = "Item";
+            $content->title = [];
+            $content->title[] = $object->title;
+            $content->originatingSystemId = $object->res_id;
+            $content->documentType = "Attachment";
+
+            if ($type == "Response") {
+                $reference = new stdClass();
+                $reference->repositoryArchiveUnitPID = $relatedObjectReference;
+
+                $content->relatedObjectReference = new stdClass();
+                $content->relatedObjectReference->references = [];
+
+                $repositoryArchiveUnitPID = new stdClass();
+                $repositoryArchiveUnitPID = $reference;
+                $content->relatedObjectReference->references[] = $repositoryArchiveUnitPID;
+            }
+        }
+
+        /*$notes = $this->getNotes($letterbox->res_id);
+        $content->custodialHistory = new stdClass();
+        $content->custodialHistory->custodialHistoryItem = [];
+
+        foreach ($notes as $note) {
+            $content->custodialHistory->custodialHistoryItem[] = $this->getCustodialHistoryItem($note);
+        }*/
+
+        return $content;
+    }
+
+    private function getManagement($letterbox) {
+        $management = new stdClass();
+
+        $docTypes = $this->db->getDocTypes($letterbox->type_id);
+
+        $management->appraisalRule = new stdClass();
+        $management->appraisalRule->rule = new stdClass();
+        $management->appraisalRule->rule->value = $docTypes->retention_rule;
+        if ($docTypes->retention_final_disposition == "preservation") {
+            $management->appraisalRule->finalAction = "Keep";
+        } else {
+            $management->appraisalRule->finalAction = "Destroy";
+        }
+        
+        
+        return $management;
+    }
+
+    private function getBinaryDataObject($object, $isAttachment = false)
+    {
+        $docServers = $this->db->getDocServer($object->docserver_id);
+
+        $binaryDataObject = new stdClass();
+
+        if ($isAttachment) {
+            $binaryDataObject->id = "attachment_".$object->res_id;
+        } else {
+            $binaryDataObject->id = $object->res_id;
+        }
+        
+        $binaryDataObject->messageDigest = new stdClass();
+        $binaryDataObject->messageDigest->value = $object->fingerprint;
+        $binaryDataObject->messageDigest->algorithm = "xxx";
+
+        $binaryDataObject->size = new stdClass();
+        $binaryDataObject->size->value = $object->filesize;
+
+        $uri = str_replace("##", DIRECTORY_SEPARATOR, $object->path);
+        $uri =  str_replace("#", DIRECTORY_SEPARATOR, $uri);
+        $uri .= $object->filename;
+        $binaryDataObject->uri = $docServers->path_template.$uri;
+
+        return $binaryDataObject;
+    }
+
+    private function getKeyword($informations, $type = null)
+    {
+        $keyword = new stdClass();
+        $keyword->keywordContent = new stdClass();
+
+        if ($type == "entitie") {
+            $keyword->keywordType = "corpname";
+            $keyword->keywordContent = $informations->business_id;
+        } else if ($informations->is_corporate_person == "Y") {
+            $keyword->keywordType = "corpname";
+            $keyword->keywordContent->value = $informations->society;
+        } else {
+            $keyword->keywordType = "personname";
+            $keyword->keywordContent->value = $informations->lastname . " " . $informations->firstname;
+        }
+
+        return $keyword;
+    }
+
+    private function getAddresse($informations, $type = null)
+    {
+        $addressee = new stdClass();
+        if ($type == "entitie") {
+            $addressee->corpname = $informations->entity_label;
+            $addressee->identifier = $informations->business_id;
+        } else if ($informations->is_corporate_person == "Y") {
+            $addressee->corpname = $informations->society;
+            $addressee->identifier = $informations->contact_id;
+        } else {
+            $addressee->firstName = $informations->firstname;
+            $addressee->birthName = $informations->lastname;
+        }
+            
+
+        return $addressee;
+    }
+
+    private function getCustodialHistoryItem($note) 
+    {
+        $custodialHistoryItem = new stdClass();
+
+        $custodialHistoryItem->value = $note->note_text;
+        $custodialHistoryItem->when = $note->date_note;
+
+        return $custodialHistoryItem;
+    }
 }
\ No newline at end of file
diff --git a/modules/export_seda/config.ini b/modules/export_seda/config.ini
index b9f948749899deff42dbe765f8b6c6febfb60231..206f47544c1daa5d50fb973883251ab74d3368cb 100644
--- a/modules/export_seda/config.ini
+++ b/modules/export_seda/config.ini
@@ -2,6 +2,8 @@
 SAE = "maarchRM"
 token = "LAABS-AUTH=RJpzB36bmR+iuz/aHN9Zl9PDn8tZEs4mzsz9OXMPOtvam2vklQBxWM18LiPAVFErhB/ugPqE1A=="
 urlSAE = "http://srv-maarchrm-ap/medona/Archivetransfer"
+#token = "ABjHAkI20y/RfLQ6YqkFhI4YnGDQ+ITnofYu5TFmNIVzuVb5Yqhf1PmgSw6A52HX6+1gpSBQZNE="
+#urlSAE = "http://demo-publique-rm.maarch.org/medona/Archivetransfer"
 
 [Suppression_data]
 deleteData = true
diff --git a/modules/export_seda/export_seda.php b/modules/export_seda/export_seda.php
index 9f358c9aa90474cc92cb1928ce3782d9a605f54a..aefd96be37acf71cacef8309b4f097dc423fb793 100644
--- a/modules/export_seda/export_seda.php
+++ b/modules/export_seda/export_seda.php
@@ -13,7 +13,6 @@
 * @ingroup export_seda
 */
 
-
 /**
 * $confirm  bool true
 */
@@ -28,22 +27,18 @@ $etapes = array('form');
 require_once __DIR__.'/ArchiveTransfer.php';
 //require_once __DIR__.'/StreamClient.php';
 
-function get_form_txt($values, $path_manage_action,  $id_action, $table, $module, $coll_id, $mode) {
+function get_form_txt($values, $path_manage_action, $id_action, $table, $module, $coll_id, $mode)
+{
     $archiveTransfer = new ArchiveTransfer();
 
     $result = $archiveTransfer->deleteMessage($values);
 
     $result = $archiveTransfer->receive($values);
-    
-    if ($_SESSION['error']) {
-        header("location: " . $_SESSION['config']['businessappurl'] . "index.php?page=view_baskets&module=basket&baskets=AExporterSeda#top");
-        exit();
-    }
 
     $db = new Database();
-    $stmt = $db->query("select message_id from unit_identifier where res_id = ?",array($values[0]));
+    $stmt = $db->query("select message_id from unit_identifier where res_id = ?", array($values[0]));
     $unitIdentifier = $stmt->fetchObject();
-    $stmt = $db->query("select data from seda where message_id = ?",array($unitIdentifier->message_id));
+    $stmt = $db->query("select data from seda where message_id = ?", array($unitIdentifier->message_id));
 
     $messageData = $stmt->fetchObject();
 
@@ -73,24 +68,28 @@ function get_form_txt($values, $path_manage_action,  $id_action, $table, $module
     $frm_str .= '</tr></tbody></table><hr />';
 
     //Information n Archive
-    
-    foreach ($messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit as $archiveUnit) {
-        $frm_str .= viewArchiveUnit($archiveUnit);
-    }
+    if (!$_SESSION['error']) {
+        foreach ($messageObject->dataObjectPackage->descriptiveMetadata->archiveUnit as $archiveUnit) {
+            $frm_str .= viewArchiveUnit($archiveUnit);
+        }
 
+        $path_to_script = $_SESSION['config']['businessappurl']."index.php?display=true&module=export_seda";
 
-    /*
-*/
+        $frm_str .= '</div>';
+        $frm_str .='<div align="center">';
+        $frm_str .='<input type="button" name="zip" id="zip" class="button"  value="'._ZIP.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_seda_zip&reference='.$messageObject->messageIdentifier->value.'\',\'zip\');"/>&nbsp&nbsp&nbsp';
+        $frm_str .='<input type="button" name="sendMessage" id="sendMessage" class="button"  value="'._SEND_MESSAGE.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_transfer_SAE&reference='.$messageObject->messageIdentifier->value.'\',\'sendMessage\');"/>';
+        $frm_str .='</div>';
+    } else {
+        $frm_str .='<div align="center" style="color:red">';
+        $frm_str .= $_SESSION['error'];
+        $frm_str .='</div>';
+    }
 
-    $path_to_script = $_SESSION['config']['businessappurl']."index.php?display=true&module=export_seda";
+    $config = parse_ini_file(__DIR__.'/config.ini');
+    $urlSAE = $config['urlSAE'];
 
-    $frm_str .= '</div>';
-    $frm_str .='<div align="center">';
-    $frm_str .='<input type="button" name="zip" id="zip" class="button"  value="'._ZIP.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_seda_zip&reference='.$messageObject->messageIdentifier->value.'\',\'zip\');"/>&nbsp&nbsp&nbsp';
-    $frm_str .='<input type="button" name="sendMessage" id="sendMessage" class="button"  value="'._SEND_MESSAGE.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_transfer_SAE&reference='.$messageObject->messageIdentifier->value.'\',\'sendMessage\');"/>';
-    $frm_str .='</div>';
-//
-    $frm_str .='<div align="center"  name="validSeda" id="validSeda" style="display: none ">"'._URL_SAE.'"<span name="nameSAE"></span><br><input type="button" class="button" name="validateMessage" id="validateMessage" value="'._VALIDATE.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_validate_message&reference='.$messageObject->messageIdentifier->value.'\',\'validateMessage\');"/></div>';
+    $frm_str .='<div align="center"  name="validSeda" id="validSeda" style="display: none ">"'.$urlSAE.'"<span name="nameSAE"></span><br><input type="button" class="button" name="validateMessage" id="validateMessage" value="'._VALIDATE.'" onclick="actionSeda(\''.$path_to_script.'&page=Ajax_validate_message&reference='.$messageObject->messageIdentifier->value.'\',\'validateMessage\');"/></div>';
     $frm_str .='<hr />';
     $frm_str .='<div align="center">';
     $frm_str .='<input type="button" name="cancel" id="cancel" class="button"  value="'._CANCEL.'" onclick="pile_actions.action_pop();destroyModal(\'modal_'.$id_action.'\');"/>';
@@ -105,11 +104,6 @@ function get_form_txt($values, $path_manage_action,  $id_action, $table, $module
 
 function manage_form($arr_id, $history, $id_action, $label_action, $status)
 {
-    
-
-    
-
-    
     // récupérer l'entité racine du courrier *
     // récupérer archival_agency et archival_agreement *
 
@@ -166,7 +160,5 @@ function viewArchiveUnit($archiveUnit, $archiveUnitChildren = false)
         }
     }
 
-    
-
     return $frm_str;
-}
\ No newline at end of file
+}
diff --git a/modules/export_seda/lang/en.php b/modules/export_seda/lang/en.php
index dffaef9acd37d8d79eb72f107da9ce9ec5a08c98..2a620540fe859ab7e025a8d3fd1f8f4eff516e13 100644
--- a/modules/export_seda/lang/en.php
+++ b/modules/export_seda/lang/en.php
@@ -55,7 +55,8 @@ if (!defined("_ACKNOWLEDGEMENT_REFERENCE"))
     define("_ACKNOWLEDGEMENT_REFERENCE", "Acknowledgement reference");
 
 if (!defined("_TRANSFERRING_AGENCY_SIREN_COMPULSORY"))
-    define("_TRANSFERRING_AGENCY_SIREN_COMPULSORY", "Transferring agency SIREN compulsory !");
+    define("_TRANSFERRING_AGENCY_SIREN_COMPULSORY", "Transferring agency SIREN compulsory");
 
-if (!defined("_ARCHIVE_AGENCY_SIREN_COMPULSORY"))
-    define("_ARCHIVE_AGENCY_SIREN_COMPULSORY", "Archive agency SIREN compulsory !");
\ No newline at end of file
+if (!defined("_ARCHIVAL_AGENCY_SIREN_COMPULSORY"))
+    define("_ARCHIVAL_AGENCY_SIREN_COMPULSORY", "Archive agency SIREN compulsory");
+    
\ No newline at end of file
diff --git a/modules/export_seda/lang/fr.php b/modules/export_seda/lang/fr.php
index 62d0d0229c9e3b52472001fc27294b83eb819c57..03e320f29f1daef682f1425ddd69643242573a0d 100644
--- a/modules/export_seda/lang/fr.php
+++ b/modules/export_seda/lang/fr.php
@@ -53,7 +53,8 @@ if (!defined("_ERROR_MESSAGE"))
     define("_ERROR_MESSAGE", "Bordereau non-reçu");
 
 if (!defined("_TRANSFERRING_AGENCY_SIREN_COMPULSORY"))
-    define("_TRANSFERRING_AGENCY_SIREN_COMPULSORY", "Numéro SIREN service versant obligatoire !");
+    define("_TRANSFERRING_AGENCY_SIREN_COMPULSORY", "Numéro SIREN service versant obligatoire");
 
-if (!defined("_ARCHIVE_AGENCY_SIREN_COMPULSORY"))
-    define("_ARCHIVE_AGENCY_SIREN_COMPULSORY", "Numéro SIREN service d'archive obligatoire !");
\ No newline at end of file
+if (!defined("_ARCHIVAL_AGENCY_SIREN_COMPULSORY"))
+    define("_ARCHIVAL_AGENCY_SIREN_COMPULSORY", "Numéro SIREN service d'archive obligatoire");
+    
\ No newline at end of file
diff --git a/sql/160_to_170.sql b/sql/160_to_170.sql
index aaf2798cc60342ccf0efe4bbe90dffc4ada421c9..cf61393b96b82dc135cb661d6a77a6525c218ff3 100644
--- a/sql/160_to_170.sql
+++ b/sql/160_to_170.sql
@@ -172,4 +172,122 @@ VALUES ('FASTHD_ATTACH', 'FASTHD', 'Fast internal disc bay for attachments', 'N'
 ALTER TABLE basket_persistent_mode ALTER COLUMN user_id TYPE character varying(128);
 ALTER TABLE res_mark_as_read ALTER COLUMN user_id TYPE character varying(128);
 
-UPDATE parameters SET param_value_int = '170' WHERE id = 'database_version';
\ No newline at end of file
+-- EXPORT SEDA
+DROP TABLE IF EXISTS seda;
+CREATE TABLE seda
+(
+  "message_id" text NOT NULL,
+  "schema" text,
+  "type" text NOT NULL,
+  "status" text NOT NULL,
+  
+  "date" timestamp NOT NULL,
+  "reference" text NOT NULL,
+  
+  "account_id" text,
+  "sender_org_identifier" text NOT NULL,
+  "sender_org_name" text,
+  "recipient_org_identifier" text NOT NULL,
+  "recipient_org_name" text,
+
+  "archival_agreement_reference" text,
+  "reply_code" text,
+  "operation_date" timestamp,
+  "reception_date" timestamp,
+  
+  "related_reference" text,
+  "request_reference" text,
+  "reply_reference" text,
+  "derogation" boolean,
+  
+  "data_object_count" integer,
+  "size" numeric,
+  
+  "data" text,
+  
+  "active" boolean,
+  "archived" boolean,
+
+  PRIMARY KEY ("message_id")
+)
+WITH (
+  OIDS=FALSE
+);
+
+DROP TABLE IF EXISTS unit_identifier;
+CREATE TABLE unit_identifier
+(
+  "message_id" text NOT NULL,
+  "tablename" text NOT NULL,
+  "res_id" text NOT NULL
+);
+
+--EXPORT SEDA DATAS
+DELETE FROM USERGROUPS WHERE GROUP_ID = 'ARCHIVISTE';
+INSERT INTO USERGROUPS VALUES ('ARCHIVISTE', 'Archiviste', 'N', 'N', 'N', 'N', 'N', 'Y');
+
+DELETE FROM USERGROUPS_SERVICES WHERE GROUP_ID = 'ARCHIVISTE';
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'add_thesaurus_to_res');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'adv_search_mlb');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'export_seda_view');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'fileplan');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'my_contacts_menu');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'put_doc_in_fileplan');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'sendmail');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'tag_view');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'view_baskets');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'view_doc_history');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'view_technical_infos');
+INSERT INTO USERGROUPS_SERVICES (group_id, service_id) Values ('ARCHIVISTE', 'avis_documents');
+
+DELETE FROM SECURITY WHERE GROUP_ID = 'ARCHIVISTE';
+INSERT INTO SECURITY (group_id, coll_id, where_clause, maarch_comment, can_insert, can_update, can_delete, rights_bitmask, mr_start_date, mr_stop_date, where_target) 
+VALUES ('ARCHIVISTE', 'letterbox_coll', '1=1', 'Tous les courriers','N','N','N', 24, NULL, NULL, 'DOC');
+
+DELETE FROM USERS WHERE USER_ID = 'aarc';
+INSERT INTO USERS (user_id, password, firstname, lastname, mail, enabled, change_password, status, loginmode) 
+VALUES ('aarc', '65d1d802c2c5e7e9035c5cef3cfc0902b6d0b591bfa85977055290736bbfcdd7e19cb7cfc9f980d0c815bbf7fe329a4efd8da880515ba520b22c0aa3a96514cc', 'Alfred', 'ARC', 'info@maarch.org', 'Y', 'N', 'OK', 'standard');
+
+DELETE FROM USERS_ENTITIES WHERE USER_ID = 'aarc';
+INSERT INTO USERS_ENTITIES (user_id, entity_id, user_role, primary_entity) 
+VALUES ('aarc', 'VILLE', '', 'Y');
+
+DELETE FROM USERGROUP_CONTENT WHERE USER_ID = 'aarc';
+INSERT INTO USERGROUP_CONTENT (user_id, group_id, primary_group, role) 
+VALUES ('aarc', 'ARCHIVISTE', 'Y','');
+
+DELETE FROM STATUS WHERE ID = 'EXP_SEDA';
+INSERT INTO STATUS (id, label_status, is_system, is_folder_status, img_filename, maarch_module, can_be_searched, can_be_modified) 
+VALUES ('EXP_SEDA', 'A exporter au format SEDA', 'Y', 'N', 'fm-letter-status-acla', 'apps', 'Y', 'Y');
+
+DELETE FROM ACTIONS WHERE id = 418;
+INSERT INTO ACTIONS (id, keyword, label_action, id_status, is_system, is_folder_action, enabled, action_page, history, origin, create_id, category_id) 
+VALUES (418, '', 'Exporter SEDA', '_NOSTATUS_', 'N', 'N', 'Y', 'export_seda', 'Y', 'export_seda', 'N', NULL);
+
+DELETE FROM ACTIONS WHERE id = 419;
+INSERT INTO ACTIONS (id, keyword, label_action, id_status, is_system, is_folder_action, enabled, action_page, history, origin, create_id, category_id) 
+VALUES (419, '', 'Proposer export SEDA', 'EXP_SEDA', 'N', 'N', 'Y', '', 'Y', 'apps', 'N', NULL);
+
+DELETE FROM BASKETS WHERE BASKET_ID = 'AExporterSeda';
+INSERT INTO BASKETS (basket_id, basket_name, basket_desc, basket_clause, coll_id, is_visible, is_folder_basket, enabled, basket_order) 
+VALUES ('AExporterSeda', 'Courriers à exporter SEDA', 'Courriers à exporter SEDA', 'status=''EXP_SEDA''', 'letterbox_coll', 'Y', 'N', 'Y',300);
+
+DELETE FROM GROUPBASKET WHERE BASKET_ID = 'AExporterSeda';
+INSERT INTO GROUPBASKET (group_id, basket_id, sequence, redirect_basketlist, redirect_grouplist, result_page, can_redirect, can_delete, can_insert, list_lock_clause, sublist_lock_clause) 
+VALUES ('ARCHIVISTE', 'AExporterSeda', 1, NULL, NULL, 'list_with_attachments','N', 'N', 'N', NULL, NULL);
+
+DELETE FROM ACTIONS_GROUPBASKETS WHERE id_action = 418;
+INSERT INTO ACTIONS_GROUPBASKETS (id_action, where_clause, group_id, basket_id, used_in_basketlist, used_in_action_page, default_action_list) 
+VALUES (418, '', 'ARCHIVISTE', 'AExporterSeda', 'Y', 'N', 'N');
+
+DELETE FROM ACTIONS_GROUPBASKETS WHERE id_action = 419;
+INSERT INTO ACTIONS_GROUPBASKETS (id_action, where_clause, group_id, basket_id, used_in_basketlist, used_in_action_page, default_action_list) 
+VALUES (419, '', 'RESP_COURRIER', 'MyBasket', 'N', 'Y', 'N');
+INSERT INTO ACTIONS_GROUPBASKETS (id_action, where_clause, group_id, basket_id, used_in_basketlist, used_in_action_page, default_action_list) 
+VALUES (419, '', 'RESPONSABLE', 'MyBasket', 'N', 'Y', 'N');
+
+UPDATE ENTITIES SET BUSINESS_ID = 'org_987654321_Versant';
+UPDATE ENTITIES SET ARCHIVAL_AGENCY = 'org_123456789_Archives';
+UPDATE ENTITIES SET ARCHIVAL_AGREEMENT = 'MAARCH_LES_BAINS_ACTES';
+
+UPDATE parameters SET param_value_int = '170' WHERE id = 'database_version';