Skip to content
Snippets Groups Projects
Verified Commit 3bd93c32 authored by Damien's avatar Damien
Browse files

FIX #14565 TIME 0:00 Refactoring

parent 3c65ae4e
No related branches found
No related tags found
No related merge requests found
...@@ -25,9 +25,6 @@ class CertificateSignatureController ...@@ -25,9 +25,6 @@ class CertificateSignatureController
public static function getHashedCertificate(array $args) public static function getHashedCertificate(array $args)
{ {
$libDir = CoreConfigModel::getLibrariesDirectory();
require_once($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php');
$adr = AdrModel::getDocumentsAdr([ $adr = AdrModel::getDocumentsAdr([
'select' => ['path', 'filename'], 'select' => ['path', 'filename'],
'where' => ['main_document_id = ?', 'type = ?'], 'where' => ['main_document_id = ?', 'type = ?'],
...@@ -101,8 +98,6 @@ class CertificateSignatureController ...@@ -101,8 +98,6 @@ class CertificateSignatureController
public static function signDocument($args = []) public static function signDocument($args = [])
{ {
$libDir = CoreConfigModel::getLibrariesDirectory();
require_once($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php');
$certificateSignature = \SetaPDF_Core_Type_HexString::hex2str($args['hashSignature']); $certificateSignature = \SetaPDF_Core_Type_HexString::hex2str($args['hashSignature']);
$signatureContentLength = $args['signatureContentLength']; $signatureContentLength = $args['signatureContentLength'];
$certificate = $args['certificate']; $certificate = $args['certificate'];
......
...@@ -506,8 +506,12 @@ class DocumentController ...@@ -506,8 +506,12 @@ class DocumentController
$workflow = WorkflowModel::getCurrentStep(['select' => ['id', 'mode', 'user_id', 'signature_mode', 'digital_signature_id'], 'documentId' => $args['id']]); $workflow = WorkflowModel::getCurrentStep(['select' => ['id', 'mode', 'user_id', 'signature_mode', 'digital_signature_id'], 'documentId' => $args['id']]);
$libDir = CoreConfigModel::getLibrariesDirectory(); $libDir = CoreConfigModel::getLibrariesDirectory();
$loadedXml = CoreConfigModel::getConfig(); $loadedXml = CoreConfigModel::getConfig();
if ($loadedXml->docaposteSignature->enable == 'true' && $workflow['signature_mode'] == 'eidas' && (empty($libDir) || !is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php'))) {
return $response->withStatus(500)->withJson(['errors' => 'SetaPDF-Signer library is not installed', 'lang' => 'setAPdfSignerError']); if ($workflow['mode'] == 'sign' && $workflow['signature_mode'] != 'stamp') {
if (empty($libDir) || !is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php')) {
return $response->withStatus(500)->withJson(['errors' => 'SetaPDF-Signer library is not installed', 'lang' => 'setAPdfSignerError']);
}
require_once($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php');
} }
$body = $request->getParsedBody(); $body = $request->getParsedBody();
...@@ -695,68 +699,64 @@ class DocumentController ...@@ -695,68 +699,64 @@ class DocumentController
]); ]);
} elseif (DocumentController::ACTIONS[$args['actionId']] == 'VAL' && $workflow['mode'] == 'sign') { } elseif (DocumentController::ACTIONS[$args['actionId']] == 'VAL' && $workflow['mode'] == 'sign') {
$imageSignature = false; $imageSignature = false;
if (!empty($libDir) && is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php')) { $adr = AdrModel::getDocumentsAdr([
require_once($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php'); 'select' => ['path', 'filename'],
'where' => ['main_document_id = ?', 'type = ?'],
$adr = AdrModel::getDocumentsAdr([ 'data' => [$args['id'], 'ESIGN']
'select' => ['path', 'filename'], ]);
'where' => ['main_document_id = ?', 'type = ?'], $docserver = DocserverModel::getByType(['type' => 'ESIGN', 'select' => ['path']]);
'data' => [$args['id'], 'ESIGN'] $pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename'];
]); $tmpPath = CoreConfigModel::getTmpPath();
$docserver = DocserverModel::getByType(['type' => 'ESIGN', 'select' => ['path']]); $signedDocumentPath = $tmpPath . $GLOBALS['id'] . '_' . rand() . '_signedDocument.pdf';
$pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename']; $writer = new \SetaPDF_Core_Writer_File($signedDocumentPath);
$tmpPath = CoreConfigModel::getTmpPath(); $document = \SetaPDF_Core_Document::loadByFilename($pathToDocument, $writer);
$signedDocumentPath = $tmpPath . $GLOBALS['id'] . '_' . rand() . '_signedDocument.pdf';
$writer = new \SetaPDF_Core_Writer_File($signedDocumentPath); $pages = $document->getCatalog()->getPages();
$document = \SetaPDF_Core_Document::loadByFilename($pathToDocument, $writer); $pageCount = $pages->count();
$pages = $document->getCatalog()->getPages(); for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
$pageCount = $pages->count(); $page = $pages->getPage($pageNumber);
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) { $format = \SetaPDF_Core_PageFormats::getFormat($page->getWidthAndHeight(), \SetaPDF_Core_PageFormats::ORIENTATION_AUTO);
$page = $pages->getPage($pageNumber); foreach ($body['signatures'] as $key => $signature) {
if ($signature['page'] == $pageNumber) {
$format = \SetaPDF_Core_PageFormats::getFormat($page->getWidthAndHeight(), \SetaPDF_Core_PageFormats::ORIENTATION_AUTO); $image = base64_decode($signature['encodedImage']);
foreach ($body['signatures'] as $key => $signature) { if ($image === false) {
if ($signature['page'] == $pageNumber) { return $response->withStatus(400)->withJson(['errors' => 'base64_decode failed']);
$image = base64_decode($signature['encodedImage']); }
if ($image === false) {
return $response->withStatus(400)->withJson(['errors' => 'base64_decode failed']); $imageTmpPath = $tmpPath . $GLOBALS['id'] . '_' . rand() . '_writing.png';
} if ($signature['type'] == 'SVG') {
$Imagick = new \Imagick();
$imageTmpPath = $tmpPath . $GLOBALS['id'] . '_' . rand() . '_writing.png'; $Imagick->readImageBlob($image);
if ($signature['type'] == 'SVG') { $Imagick->setImageFormat("png24");
$Imagick = new \Imagick(); $Imagick->writeImage($imageTmpPath);
$Imagick->readImageBlob($image); $Imagick->clear();
$Imagick->setImageFormat("png24"); $Imagick->destroy();
$Imagick->writeImage($imageTmpPath); } else {
$Imagick->clear(); file_put_contents($imageTmpPath, $image);
$Imagick->destroy(); if ($signature['positionX'] == 0 && $signature['positionY'] == 0) {
$signWidth = $format['width'];
$signPosX = 0;
$signPosY = 0;
} else { } else {
file_put_contents($imageTmpPath, $image); $signWidth = ($signature['width'] * $format['width']) / 100;
if ($signature['positionX'] == 0 && $signature['positionY'] == 0) { $signPosX = ($signature['positionX'] * $format['width']) / 100;
$signWidth = $format['width']; $signPosY = ($signature['positionY'] * $format['height']) / 100;
$signPosX = 0;
$signPosY = 0;
} else {
$signWidth = ($signature['width'] * $format['width']) / 100;
$signPosX = ($signature['positionX'] * $format['width']) / 100;
$signPosY = ($signature['positionY'] * $format['height']) / 100;
}
DigitalSignatureController::signHashes([
'signatureId' => $workflow['digital_signature_id'],
'documentId' => $args['id'],
'signatureInfo' => [
'page' => $signature['page'],
'positionX' => $signPosX,
'positionY' => $signPosY,
'filePath' => $imageTmpPath,
'signWidth' => $signWidth
],
'isLastSignature' => !isset($body['signatures'][$key + 1])
]);
$imageSignature = true;
} }
DigitalSignatureController::signHashes([
'signatureId' => $workflow['digital_signature_id'],
'documentId' => $args['id'],
'signatureInfo' => [
'page' => $signature['page'],
'positionX' => $signPosX,
'positionY' => $signPosY,
'filePath' => $imageTmpPath,
'signWidth' => $signWidth
],
'isLastSignature' => !isset($body['signatures'][$key + 1])
]);
$imageSignature = true;
} }
} }
} }
......
...@@ -51,7 +51,7 @@ class SearchController ...@@ -51,7 +51,7 @@ class SearchController
$whereWorkflow = []; $whereWorkflow = [];
$dataWorkflow = []; $dataWorkflow = [];
if (Validator::arrayType()->notEmpty()->validate($body['workflowStates'])) { if (Validator::arrayType()->notEmpty()->validate($body['workflowStates'] ?? null)) {
$whereStatuses = []; $whereStatuses = [];
if (in_array('VAL', $body['workflowStates'])) { if (in_array('VAL', $body['workflowStates'])) {
$whereStatuses[] = "main_document_id not in (SELECT DISTINCT main_document_id FROM workflows WHERE status is null OR status in ('REF', 'END', 'STOP'))"; $whereStatuses[] = "main_document_id not in (SELECT DISTINCT main_document_id FROM workflows WHERE status is null OR status in ('REF', 'END', 'STOP'))";
...@@ -90,7 +90,7 @@ class SearchController ...@@ -90,7 +90,7 @@ class SearchController
$data[] = $documentIds; $data[] = $documentIds;
} }
if (Validator::stringType()->notEmpty()->validate($body['title'])) { if (Validator::stringType()->notEmpty()->validate($body['title'] ?? null)) {
$requestData = SearchController::getDataForRequest([ $requestData = SearchController::getDataForRequest([
'search' => $body['title'], 'search' => $body['title'],
'fields' => 'unaccent(title) ilike unaccent(?::text)', 'fields' => 'unaccent(title) ilike unaccent(?::text)',
...@@ -102,7 +102,7 @@ class SearchController ...@@ -102,7 +102,7 @@ class SearchController
$where[] = implode(' AND ', $requestData['where']); $where[] = implode(' AND ', $requestData['where']);
$data = array_merge($data, $requestData['data']); $data = array_merge($data, $requestData['data']);
} }
if (Validator::stringType()->notEmpty()->validate($body['reference'])) { if (Validator::stringType()->notEmpty()->validate($body['reference'] ?? null)) {
$where[] = 'reference ilike ?'; $where[] = 'reference ilike ?';
$data[] = "%{$body['reference']}%"; $data[] = "%{$body['reference']}%";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment