diff --git a/rest/index.php b/rest/index.php index 056eb58c0fb36b130fa594525b6bf01eee059bb7..688e4acf2ebc8d077d86e3f863253cd322884d91 100755 --- a/rest/index.php +++ b/rest/index.php @@ -55,7 +55,7 @@ $app->get('/documents', \Document\controllers\DocumentController::class . ':get' $app->get('/documents/{id}', \Document\controllers\DocumentController::class . ':getById'); $app->get('/documents/{id}/status', \Document\controllers\DocumentController::class . ':getStatusById'); $app->get('/documents/{id}/handwrittenDocument', \Document\controllers\DocumentController::class . ':getHandwrittenDocumentById'); -$app->put('/documents/{id}/action', \Document\controllers\DocumentController::class . ':makeAction'); +$app->put('/documents/{id}/actions/{actionId}', \Document\controllers\DocumentController::class . ':setAction'); //Password Rules $app->get('/passwordRules', \SrcCore\controllers\PasswordController::class . ':get'); diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index d311e7f3305f36a6c10df805139f59ca52173d4b..6682fed5d32096dbba7b405a0dd3437a4679206a 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -191,69 +191,62 @@ class DocumentController return $response->withJson(['documentId' => $id]); } - public function makeAction(Request $request, Response $response, array $args) + public function setAction(Request $request, Response $response, array $args) { - $data = $request->getParams(); - - ValidatorModel::notEmpty($data, ['action_id']); - ValidatorModel::intVal($data, ['action_id']); - - /*if (!empty($data['signatures'])) { - foreach ($data['signatures'] as $signature) { - foreach (['fullPath', 'width', 'positionX', 'positionY', 'page'] as $value) { - if (empty($signature[$value])) { - return $response->withStatus(400)->withJson(['errors' => $value . ' is empty']); - } - } - } - }*/ - if (!DocumentController::hasRightById(['id' => $args['id'], 'email' => $GLOBALS['email']])) { return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } - $action = ActionModel::getById(['select' => ['next_status_id', 'label'], 'id' => $data['action_id']]); + $action = ActionModel::getById(['select' => ['next_status_id'], 'id' => $args['actionId']]); if (empty($action)) { - return $response->withStatus(403)->withJson(['errors' => 'Action does not exist']); - } - - $adr = AdrModel::getDocumentsAdr([ - 'select' => ['path', 'filename'], - 'where' => ['main_document_id = ?', 'type = ?'], - 'data' => [$args['id'], 'DOC'] - ]); - if (empty($adr)) { - return $response->withStatus(400)->withJson(['errors' => 'Document does not exist in database']); + return $response->withStatus(400)->withJson(['errors' => 'Action does not exist']); } - $docserver = DocserverModel::getByType(['type' => 'DOC', 'select' => ['path']]); - if (empty($docserver['path']) || !file_exists($docserver['path'])) { - return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']); - } - - $pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename']; - if (!file_exists($pathToDocument)) { - return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']); - } + $data = $request->getParams(); + if (!empty($data['signatures'])) { + foreach ($data['signatures'] as $signature) { + foreach (['encodedImage', 'width', 'positionX', 'positionY', 'page', 'type'] as $value) { + if (!isset($signature[$value])) { + return $response->withStatus(400)->withJson(['errors' => $value . ' is empty']); + } + } + } - $tmpPath = CoreConfigModel::getTmpPath(); - $tmpFilename = $tmpPath . $GLOBALS['email'] . '_' . rand() . '_' . $adr[0]['filename']; - copy($pathToDocument, $tmpFilename); + $adr = AdrModel::getDocumentsAdr([ + 'select' => ['path', 'filename'], + 'where' => ['main_document_id = ?', 'type = ?'], + 'data' => [$args['id'], 'DOC'] + ]); + if (empty($adr)) { + return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']); + } - $pdf = new Fpdi('P'); - $nbPages = $pdf->setSourceFile($tmpFilename); - $pdf->setPrintHeader(false); + $docserver = DocserverModel::getByType(['type' => 'DOC', 'select' => ['path']]); + if (empty($docserver['path']) || !file_exists($docserver['path'])) { + return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']); + } + $pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename']; + if (!file_exists($pathToDocument)) { + return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']); + } - for ($i = 1; $i <= $nbPages; $i++) { - $page = $pdf->importPage($i); - $size = $pdf->getTemplateSize($page); - $pdf->AddPage($size['orientation'], $size); - $pdf->useImportedPage($page); - $pdf->SetAutoPageBreak(false, 0); - $pdf->SetMargins(0, 0, 0); - $pdf->SetAutoPageBreak(false, 0); - if (!empty($data['signatures'])) { + $tmpPath = CoreConfigModel::getTmpPath(); + $tmpFilename = $tmpPath . $GLOBALS['email'] . '_' . rand() . '_' . $adr[0]['filename']; + copy($pathToDocument, $tmpFilename); + + $pdf = new Fpdi('P'); + $nbPages = $pdf->setSourceFile($tmpFilename); + $pdf->setPrintHeader(false); + + for ($i = 1; $i <= $nbPages; $i++) { + $page = $pdf->importPage($i); + $size = $pdf->getTemplateSize($page); + $pdf->AddPage($size['orientation'], $size); + $pdf->useImportedPage($page); + $pdf->SetAutoPageBreak(false, 0); + $pdf->SetMargins(0, 0, 0); + $pdf->SetAutoPageBreak(false, 0); foreach ($data['signatures'] as $signature) { if ($signature['page'] == $i) { if ($signature['positionX'] == 0 && $signature['positionY'] == 0) { @@ -266,51 +259,44 @@ class DocumentController $signPosY = ($signature['positionY'] * $size['height']) / 100; } if ($signature['type'] == 'SVG') { - $data = str_replace('data:image/svg+xml;base64,', '', $signature['fullPath']); - - $image = base64_decode($data); - + $image = str_replace('data:image/svg+xml;base64,', '', $signature['encodedImage']); + $image = base64_decode($image); if ($image === false) { return $response->withStatus(400)->withJson(['errors' => 'base64_decode failed']); } $imageTmpPath = $tmpPath . $GLOBALS['email'] . '_' . rand() . '_writing.svg'; file_put_contents($imageTmpPath, $image); - $pdf->ImageSVG($imageTmpPath, $signPosX, $signPosY, $signWidth); } else { - $data = $signature['fullPath']; - - $image = base64_decode($data); - + $image = base64_decode($signature['encodedImage']); if ($image === false) { return $response->withStatus(400)->withJson(['errors' => 'base64_decode failed']); } $imageTmpPath = $tmpPath . $GLOBALS['email'] . '_' . rand() . '_writing.png'; file_put_contents($imageTmpPath, $image); - $pdf->Image($imageTmpPath, $signPosX, $signPosY, $signWidth); } } } } + $fileContent = $pdf->Output('', 'S'); + + $storeInfos = DocserverController::storeResourceOnDocServer([ + 'encodedFile' => base64_encode($fileContent), + 'format' => 'pdf', + 'docserverType' => 'HANDWRITTEN' + ]); + + AdrModel::createDocumentAdr([ + 'documentId' => $args['id'], + 'type' => 'HANDWRITTEN', + 'path' => $storeInfos['path'], + 'filename' => $storeInfos['filename'], + 'fingerprint' => $storeInfos['fingerprint'] + ]); } - $fileContent = $pdf->Output('', 'S'); - - $storeInfos = DocserverController::storeResourceOnDocServer([ - 'encodedFile' => base64_encode($fileContent), - 'format' => 'pdf', - 'docserverType' => 'HANDWRITTEN' - ]); - - AdrModel::createDocumentAdr([ - 'documentId' => $args['id'], - 'type' => 'HANDWRITTEN', - 'path' => $storeInfos['path'], - 'filename' => $storeInfos['filename'], - 'fingerprint' => $storeInfos['fingerprint'] - ]); DocumentModel::update([ 'set' => ['status' => $action['next_status_id']], @@ -322,7 +308,7 @@ class DocumentController 'tableName' => 'main_documents', 'recordId' => $args['id'], 'eventType' => 'UP', - 'info' => 'actionDone' . ' : ' . $action['label'] + 'info' => "actionDone : {$args['actionId']}" ]); return $response->withJson(['success' => 'success']); diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts index 1632d42478eab65f8c91d354811c0ee3f1a6ca2f..87e6e311f064615afe89eb04c1ff2838879da291 100755 --- a/src/frontend/app/document/document.component.ts +++ b/src/frontend/app/document/document.component.ts @@ -292,7 +292,6 @@ export class DocumentComponent implements OnInit { } this.signaturesService.notesContent[this.signaturesService.currentPage].push( { - // 'fullPath': this.signaturePad.toDataURL('image/npg'), 'fullPath': this.signaturePad.toDataURL('image/svg+xml'), 'positionX': (this.signaturePadPosX * 100) / this.annotationPadOptions.canvasWidth, 'positionY': (this.signaturePadPosY * 100) / this.annotationPadOptions.canvasHeight, @@ -300,7 +299,6 @@ export class DocumentComponent implements OnInit { 'width': 768, } ); - console.log(); this.signaturePad.clear(); this.scale = 1; this.signaturesService.annotationMode = false; @@ -466,13 +464,12 @@ export class WarnModalComponent { this.signaturesService.signaturesContent[index].forEach((signature: any) => { signatures.push( { - 'fullPath': signature.encodedSignature, - 'height': 'auto', - 'width': (this.signaturesService.signWidth * 100) / signature.pdfAreaX, - 'positionX': (signature.positionX * 100) / signature.pdfAreaX, - 'positionY': (signature.positionY * 100) / signature.pdfAreaY, - 'type': 'PNG', - 'page': index, + 'encodedImage' : signature.encodedSignature, + 'width' : (this.signaturesService.signWidth * 100) / signature.pdfAreaX, + 'positionX' : (signature.positionX * 100) / signature.pdfAreaX, + 'positionY' : (signature.positionY * 100) / signature.pdfAreaY, + 'type' : 'PNG', + 'page' : index } ); }); @@ -481,19 +478,18 @@ export class WarnModalComponent { this.signaturesService.notesContent[index].forEach((note: any) => { signatures.push( { - 'fullPath': note.fullPath, - 'height': note.height, - 'width': note.width, - 'positionX': note.positionX, - 'positionY': note.positionY, - 'type': 'SVG', - 'page': index, + 'encodedImage' : note.fullPath, + 'width' : note.width, + 'positionX' : note.positionX, + 'positionY' : note.positionY, + 'type' : 'SVG', + 'page' : index } ); }); } } - this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/action', {'action_id': this.signaturesService.currentAction, 'signatures': signatures}) + this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, {'signatures': signatures}) .subscribe(() => { this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1); this.signaturesService.documentsListCount--; @@ -523,13 +519,12 @@ export class ConfirmModalComponent { this.signaturesService.signaturesContent[index].forEach((signature: any) => { signatures.push( { - 'fullPath': signature.encodedSignature, - 'height': 'auto', - 'width': (this.signaturesService.signWidth * 100) / signature.pdfAreaX, - 'positionX': (signature.positionX * 100) / signature.pdfAreaX, - 'positionY': (signature.positionY * 100) / signature.pdfAreaY, - 'type': 'PNG', - 'page': index, + 'encodedImage' : signature.encodedSignature, + 'width' : (this.signaturesService.signWidth * 100) / signature.pdfAreaX, + 'positionX' : (signature.positionX * 100) / signature.pdfAreaX, + 'positionY' : (signature.positionY * 100) / signature.pdfAreaY, + 'type' : 'PNG', + 'page' : index, } ); }); @@ -538,19 +533,18 @@ export class ConfirmModalComponent { this.signaturesService.notesContent[index].forEach((note: any) => { signatures.push( { - 'fullPath': note.fullPath, - 'height': note.height, - 'width': note.width, - 'positionX': note.positionX, - 'positionY': note.positionY, - 'type': 'SVG', - 'page': index, + 'encodedImage' : note.fullPath, + 'width' : note.width, + 'positionX' : note.positionX, + 'positionY' : note.positionY, + 'type' : 'SVG', + 'page' : index, } ); }); } } - this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/action', {'action_id': this.signaturesService.currentAction, 'signatures': signatures}) + this.http.put('../rest/documents/' + this.signaturesService.mainDocumentId + '/actions/' + this.signaturesService.currentAction, {'signatures': signatures}) .subscribe(() => { this.dialogRef.close('sucess'); this.signaturesService.documentsList.splice(this.signaturesService.indexDocumentsList, 1);