Commit 40c7f5f5 authored by Florian Azizian's avatar Florian Azizian
Browse files

Merge 17.06 to 17.06_project_develop (export_seda)

parent 45125b21
......@@ -24,6 +24,7 @@ $error = $content = $res = '';
if ($_REQUEST['reference']) {
$resIds = explode(',',$_REQUEST['reference']);
arsort($resIds);
if ($_REQUEST['type'] == 'acknowledgement') {
require_once __DIR__.'/CheckAcknowledgement.php';
......
......@@ -66,7 +66,10 @@ Class Purge{
$this->db->deleteUnitIdentifier($resId);
$this->purgeResource($resId);
$this->purgeContact($letter->contact_id);
if ($letter->contact_id) {
$this->purgeContact($letter->contact_id);
}
$unitIdentifiers = $this->db->getUnitIdentifierByMessageId($message->message_id);
if (!$unitIdentifiers) {
......
......@@ -20,6 +20,12 @@ Class Reset{
$docServer = $this->db->getDocServer($reply->docserver_id);
$fileName = $docServer->path_template. DIRECTORY_SEPARATOR . $dir . $reply->filename;
if (!file_exists($fileName)) {
$_SESSION['error'] = _ERROR_REPLY_NOT_EXIST . $resId;
return;
}
$xml = simplexml_load_file($fileName);
if (strpos($xml->ReplyCode, '000') !== false) {
......
......@@ -10,18 +10,60 @@ if ($_SESSION['config']['app_id']) {
class AbstractMessage{
private $db;
private $xml;
private $directoryMessage;
public function __construct()
{
$this->db = new RequestSeda();
$getXml = false;
$path = '';
if (file_exists(
$_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR
. $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml'
)) {
$path = $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR
. $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml';
$getXml = true;
} elseif (file_exists(
$_SESSION['config']['corepath'] . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml'
)) {
$path = $_SESSION['config']['corepath'] . 'modules' . DIRECTORY_SEPARATOR . 'export_seda'
. DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'config.xml';
$getXml = true;
}
if ($getXml) {
$this->xml = simplexml_load_file($path);
$this->directoryMessage = (string) $this->xml->CONFIG->directoryMessage;
}
}
public function generatePackage($reference, $name)
{
$message = $this->db->getMessageByReference($reference);
$messageObject = json_decode($message->data);
$this->saveXml(json_decode($message->data), $name, ".xml");
if (!is_dir($this->directoryMessage)) {
umask(0);
mkdir($this->directoryMessage, 0777, true);
}
if (!is_dir($this->directoryMessage . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value)) {
umask(0);
mkdir($this->directoryMessage . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value, 0777, true);
}
$this->sendAttachment(json_decode($message->data));
$this->sendAttachment($messageObject);
$this->saveXml($messageObject, $name, ".xml");
}
public function saveXml($messageObject, $name, $extension)
......@@ -44,18 +86,18 @@ class AbstractMessage{
$DOMTemplateProcessor->removeEmptyNodes();
try {
if (!is_dir(__DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR.'message')) {
if (!is_dir($this->directoryMessage)) {
umask(0);
mkdir(__DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR.'message', 0777, true);
mkdir($this->directoryMessage, 0777, true);
}
if (!is_dir(__DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR.'message' . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value)) {
if (!is_dir($this->directoryMessage . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value)) {
umask(0);
mkdir(__DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR.'message' . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value, 0777, true);
mkdir($this->directoryMessage . DIRECTORY_SEPARATOR . $messageObject->MessageIdentifier->value, 0777, true);
}
if (!file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'. DIRECTORY_SEPARATOR.'message'.DIRECTORY_SEPARATOR.$messageObject->MessageIdentifier->value.DIRECTORY_SEPARATOR. $messageObject->MessageIdentifier->value . $extension)) {
$DOMTemplate->save(__DIR__.DIRECTORY_SEPARATOR.'..'. DIRECTORY_SEPARATOR.'message'.DIRECTORY_SEPARATOR.$messageObject->MessageIdentifier->value.DIRECTORY_SEPARATOR. $messageObject->MessageIdentifier->value . $extension);
if (!file_exists($this->directoryMessage . DIRECTORY_SEPARATOR.$messageObject->MessageIdentifier->value.DIRECTORY_SEPARATOR. $messageObject->MessageIdentifier->value . $extension)) {
$DOMTemplate->save($this->directoryMessage . DIRECTORY_SEPARATOR.$messageObject->MessageIdentifier->value.DIRECTORY_SEPARATOR. $messageObject->MessageIdentifier->value . $extension);
}
} catch (Exception $e) {
......@@ -66,7 +108,7 @@ class AbstractMessage{
public function addAttachment($reference, $resIdMaster, $fileName, $extension, $title, $type) {
$db = new RequestSeda();
$object = new stdClass();
$dir = __DIR__.DIRECTORY_SEPARATOR.'..'. DIRECTORY_SEPARATOR.'message'.DIRECTORY_SEPARATOR.$reference.DIRECTORY_SEPARATOR;
$dir = $this->directoryMessage . DIRECTORY_SEPARATOR . $reference . DIRECTORY_SEPARATOR;
$object->tmpDir = $dir;
$object->size = filesize($dir);
......@@ -84,11 +126,13 @@ class AbstractMessage{
$messageId = $messageObject->MessageIdentifier->value;
foreach ($messageObject->DataObjectPackage->BinaryDataObject as $binaryDataObject) {
$dest = __DIR__ . DIRECTORY_SEPARATOR . '..'. DIRECTORY_SEPARATOR.'message' . DIRECTORY_SEPARATOR . $messageId . DIRECTORY_SEPARATOR . $binaryDataObject->Attachment->filename;
$dest = $this->directoryMessage . DIRECTORY_SEPARATOR . $messageId . DIRECTORY_SEPARATOR . $binaryDataObject->Attachment->filename;
file_put_contents($dest, base64_decode($binaryDataObject->Attachment->value));
if (!file_exists($dest)) {
copy($binaryDataObject->Uri, $dest);
unset($binaryDataObject->Attachment->value);
unset($binaryDataObject->Uri);
}
}
$this->db->updateDataMessage($messageObject->MessageIdentifier->value, json_encode($messageObject));
......@@ -137,4 +181,4 @@ class AbstractMessage{
$dir = $_SESSION['config']['tmppath'] . $name . '.pdf';
$pdf->Output($dir, "F");
}
}
}
\ No newline at end of file
......@@ -43,14 +43,17 @@ class ArchiveTransfer
. $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml'
))
{
)) {
$path = $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR
. $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml';
$getXml = true;
} else if (file_exists($_SESSION['config']['corepath'] . 'modules' . DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'config.xml')) {
} elseif (file_exists(
$_SESSION['config']['corepath'] . 'modules'
. DIRECTORY_SEPARATOR . 'export_seda'. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'config.xml'
)) {
$path = $_SESSION['config']['corepath'] . 'modules' . DIRECTORY_SEPARATOR . 'export_seda'
. DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'config.xml';
$getXml = true;
......@@ -318,6 +321,14 @@ class ArchiveTransfer
private function initMessage($messageObject)
{
$this->directoryMessage = (string) $this->xml->CONFIG->directoryMessage;
if (!$this->directoryMessage || !is_dir($this->directoryMessage)) {
$_SESSION['error'] .= _DIRECTORY_MESSAGE_REQUIRED;
return;
}
$date = new DateTime;
$messageObject->Date = $date->format(DateTime::ATOM);
$messageObject->MessageIdentifier = new stdClass();
......@@ -390,11 +401,10 @@ class ArchiveTransfer
$archiveUnit->Content = $this->getContent($type, $object);
}
if ($object->type_id && $object->type_id != 0) {
$archiveUnit->Management = $this->getManagement($object);
}
$archiveUnit->Management = $this->getManagement($object);
} else {
$archiveUnit->Content = $this->getContent($type);
$archiveUnit->Management = $this->getManagement();
}
......@@ -617,21 +627,30 @@ class ArchiveTransfer
return $content;
}
private function getManagement($letterbox)
private function getManagement($letterbox = null)
{
$management = new stdClass();
$docTypes = $this->db->getDocTypes($letterbox->type_id);
if ($letterbox && $letterbox->type_id != 0) {
$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 == "conservation") {
$management->AppraisalRule->FinalAction = "Keep";
} else {
$management->AppraisalRule->FinalAction = "Destroy";
$management->AppraisalRule = new stdClass();
$management->AppraisalRule->Rule = new stdClass();
$management->AppraisalRule->Rule->value = $docTypes->retention_rule;
$management->AppraisalRule->StartDate = date("Y-m-d");
if ($docTypes->retention_final_disposition == "conservation") {
$management->AppraisalRule->FinalAction = "Keep";
} else {
$management->AppraisalRule->FinalAction = "Destroy";
}
}
if ((string) $this->xml->CONFIG->accessRuleCode) {
$management->AccessRule = new stdClass();
$management->AccessRule->Rule = new stdClass();
$management->AccessRule->Rule->value = (string)$this->xml->CONFIG->accessRuleCode;
$management->AccessRule->StartDate = date("Y-m-d");
}
return $management;
}
......@@ -640,21 +659,27 @@ class ArchiveTransfer
{
$binaryDataObject = new stdClass();
$data = file_get_contents($filePath);
$pathInfo = pathinfo($filePath);
if ($id && $id != $pathInfo['filename']) {
$filename = $pathInfo['filename'] . '_' . $id . '.' . $pathInfo['extension'];
} else {
$filename = $pathInfo['filename'] . '_' . rand() . '.' . $pathInfo['extension'];
}
$binaryDataObject->id = $id;
$binaryDataObject->Uri = $filePath;
$binaryDataObject->MessageDigest = new stdClass();
$binaryDataObject->MessageDigest->value = hash('sha256', $data);
$binaryDataObject->MessageDigest->value = hash_file('sha256', $filePath);
$binaryDataObject->MessageDigest->algorithm = "sha256";
$binaryDataObject->Size = filesize($filePath);
$binaryDataObject->Attachment = new stdClass();
$binaryDataObject->Attachment->value = base64_encode($data);
$binaryDataObject->Attachment->filename = basename($filePath);
$binaryDataObject->Attachment->filename = $filename;
$binaryDataObject->FileInfo = new stdClass();
$binaryDataObject->FileInfo->Filename = basename($filePath);
$binaryDataObject->FileInfo->Filename = $filename;
$binaryDataObject->FormatIdentification = new stdClass();
$binaryDataObject->FormatIdentification->MimeType = mime_content_type($filePath);
......@@ -812,4 +837,4 @@ class ArchiveTransfer
return $res;
}
}
}
\ No newline at end of file
......@@ -78,6 +78,9 @@ if (!defined("_RECEIVED_MESSAGE"))
if (!defined("_ERROR_MESSAGE"))
define("_RECEIVED_MESSAGE", "Message non-reçu");
if (!defined("_DIRECTORY_MESSAGE_REQUIRED"))
define("_DIRECTORY_MESSAGE_REQUIRED", "Directory message not configured");
if (!defined("_ACKNOWLEDGEMENT_REFERENCE"))
define("_ACKNOWLEDGEMENT_REFERENCE", "Acknowledgement reference");
......@@ -139,4 +142,7 @@ if (!defined("_ERROR_ORIGINATOR_EMPTY"))
define("_ERROR_ORIGINATOR_EMPTY", "At least one originator must be retained");
if (!defined("_ERROR_FILE_NOT_EXIST"))
define("_ERROR_FILE_NOT_EXIST", "All the documents must be present in the storage areas");
\ No newline at end of file
define("_ERROR_FILE_NOT_EXIST", "All the documents must be present in the storage areas");
if (!defined("_ERROR_REPLY_NOT_EXIST"))
define("_ERROR_REPLY_NOT_EXIST", "La réponse au transfert doit être présente pour effectuer une action. Numéro du courrier : ");
\ No newline at end of file
......@@ -92,6 +92,9 @@ if (!defined("_RECEIVED_MESSAGE"))
if (!defined("_ERROR_MESSAGE"))
define("_ERROR_MESSAGE", "Bordereau non-reçu");
if (!defined("_DIRECTORY_MESSAGE_REQUIRED"))
define("_DIRECTORY_MESSAGE_REQUIRED", "Répertoire des messages non configuré");
if (!defined("_TRANSFERRING_AGENCY_SIREN_REQUIRED"))
define("_TRANSFERRING_AGENCY_SIREN_REQUIRED", "Numéro SIREN service versant obligatoire");
......@@ -150,4 +153,7 @@ if (!defined("_ERROR_ORIGINATOR_EMPTY"))
define("_ERROR_ORIGINATOR_EMPTY", "Au moins un producteur doit être renseigné");
if (!defined("_ERROR_FILE_NOT_EXIST"))
define("_ERROR_FILE_NOT_EXIST", "Tous les documents doivent être présent dans les zones de stockage");
\ No newline at end of file
define("_ERROR_FILE_NOT_EXIST", "Tous les documents doivent être présent dans les zones de stockage");
if (!defined("_ERROR_REPLY_NOT_EXIST"))
define("_ERROR_REPLY_NOT_EXIST", "La réponse au transfert doit être présente pour effectuer une action. Numéro du courrier : ");
\ No newline at end of file
......@@ -9,7 +9,7 @@
<?merge .Management.StorageRule.bool() ?>
<StorageRule>
<?merge .Management.StorageRule.Rule.bool() ?><Rule><?merge .Management.StorageRule.Rule.value ?></Rule>
<?merge .Management.StorageRule.StartDate.bool() ?><StartDate><?merge .Management.StorageRule.StartDate.value ?></StartDate>
<?merge .Management.StorageRule.StartDate.bool() ?><StartDate><?merge .Management.StorageRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.StorageRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.StorageRule.RefNonRuleId ?></RefNonRuleId>
<FinalAction><?merge .Management.StorageRule.FinalAction ?></FinalAction>
......@@ -17,7 +17,7 @@
<?merge .Management.AppraisalRule.bool() ?>
<AppraisalRule>
<?merge .Management.AppraisalRule.Rule.bool() ?><Rule><?merge .Management.AppraisalRule.Rule.value ?></Rule>
<?merge .Management.AppraisalRule.StartDate.bool() ?><StartDate><?merge .Management.AppraisalRule.StartDate.value ?></StartDate>
<?merge .Management.AppraisalRule.StartDate.bool() ?><StartDate><?merge .Management.AppraisalRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.AppraisalRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.AppraisalRule.RefNonRuleId ?></RefNonRuleId>
<FinalAction><?merge .Management.AppraisalRule.FinalAction ?></FinalAction>
......@@ -25,28 +25,28 @@
<?merge .Management.AccessRule.bool() ?>
<AccessRule>
<?merge .Management.AccessRule.Rule.bool() ?><Rule><?merge .Management.AccessRule.Rule.value ?></Rule>
<?merge .Management.AccessRule.StartDate.bool() ?><StartDate><?merge .Management.AccessRule.StartDate.value ?></StartDate>
<?merge .Management.AccessRule.StartDate.bool() ?><StartDate><?merge .Management.AccessRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.AccessRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.AccessRule.RefNonRuleId ?></RefNonRuleId>
</AccessRule>
<?merge .Management.DisseminationRule.bool() ?>
<DisseminationRule>
<?merge .Management.DisseminationRule.Rule.bool() ?><Rule><?merge .Management.DisseminationRule.Rule.value ?></Rule>
<?merge .Management.DisseminationRule.StartDate.bool() ?><StartDate><?merge .Management.DisseminationRule.StartDate.value ?></StartDate>
<?merge .Management.DisseminationRule.StartDate.bool() ?><StartDate><?merge .Management.DisseminationRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.DisseminationRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.DisseminationRule.RefNonRuleId ?></RefNonRuleId>
</DisseminationRule>
<?merge .Management.ReuseRule.bool() ?>
<ReuseRule>
<?merge .Management.ReuseRule.Rule.bool() ?><Rule><?merge .Management.ReuseRule.Rule.value ?></Rule>
<?merge .Management.ReuseRule.StartDate.bool() ?><StartDate><?merge .Management.ReuseRule.StartDate.value ?></StartDate>
<?merge .Management.ReuseRule.StartDate.bool() ?><StartDate><?merge .Management.ReuseRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.ReuseRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.ReuseRule.RefNonRuleId ?></RefNonRuleId>
</ReuseRule>
<?merge .Management.ClassificationRule.bool() ?>
<ClassificationRule>
<?merge .Management.ClassificationRule.Rule.bool() ?><Rule><?merge .Management.ClassificationRule.Rule.value ?></Rule>
<?merge .Management.ClassificationRule.StartDate.bool() ?><StartDate><?merge .Management.ClassificationRule.StartDate.value ?></StartDate>
<?merge .Management.ClassificationRule.StartDate.bool() ?><StartDate><?merge .Management.ClassificationRule.StartDate ?></StartDate>
<PreventInheritance><?merge .Management.ClassificationRule.PreventInheritance ?></PreventInheritance>
<RefNonRuleId><?merge .Management.ClassificationRule.RefNonRuleId ?></RefNonRuleId>
<ClassificationLevel><?merge .Management.ClassificationRule.ClassificationLevel ?></ClassificationLevel>
......
......@@ -9,7 +9,9 @@
<token></token>
<urlSAEService>http://srv-maarchrm-ap</urlSAEService>
<urlSAE>http://maarchrm/transfer/sent</urlSAE>
<directoryMessage></directoryMessage>
<senderOrgRegNumber></senderOrgRegNumber>
<accessRuleCode></accessRuleCode>
<deleteData>true</deleteData>
</CONFIG>
<TABLENAME/>
......@@ -18,4 +20,4 @@
<sedaadd>true</sedaadd>
<sedadel>true</sedadel>
</HISTORY>
</root>
</root>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment