diff --git a/rest/index.php b/rest/index.php index 7f2933b565134b1a1b9c57e8be00e7b9833a1008..38d60d1ee5c42ceeeeed29dc48dc0cb1a7c81b81 100755 --- a/rest/index.php +++ b/rest/index.php @@ -78,6 +78,7 @@ $app->get('/attachments/{id}/thumbnail', \Attachment\controllers\AttachmentContr $app->put('/attachments/{id}/inSendAttachment', \Attachment\controllers\AttachmentController::class . ':setInSendAttachment'); $app->get('/attachments/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow'); $app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); +$app->put('/attachments/{id}/sign', \SignatureBook\controllers\SignatureBookController::class . ':signAttachment'); $app->put('/attachments/{id}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignAttachment'); $app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById'); $app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes'); diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php index dd764e065af2ce2b11e5fd3e1c006fe80d530980..c55b7ee219af3e93a26fa05152ededabdfe89d89 100644 --- a/src/app/email/controllers/EmailController.php +++ b/src/app/email/controllers/EmailController.php @@ -214,7 +214,7 @@ class EmailController HistoryController::add([ 'tableName' => 'emails', - 'recordId' => $args['emailId'], + 'recordId' => $args['id'], 'eventType' => 'ADD', 'eventId' => 'emailCreation', 'info' => _EMAIL_ADDED @@ -232,7 +232,7 @@ class EmailController } else { HistoryController::add([ 'tableName' => 'emails', - 'recordId' => $args['emailId'], + 'recordId' => $args['id'], 'eventType' => 'UP', 'eventId' => 'emailModification', 'info' => _EMAIL_UPDATED diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php index 983ddb917e0d2418b67f0c1d582b549b3fce1753..200917cbf23819024a81aa85a866df6d7d6324ed 100755 --- a/src/app/signatureBook/controllers/SignatureBookController.php +++ b/src/app/signatureBook/controllers/SignatureBookController.php @@ -115,30 +115,30 @@ class SignatureBookController $incomingMail = ResModel::getById([ 'resId' => $resId, - 'select' => ['res_id', 'subject', 'alt_identifier', 'category_id'] + 'select' => ['res_id', 'subject', 'alt_identifier', 'category_id', 'filename', 'integrations'] ]); - if (empty($incomingMail)) { return ['error' => 'No Document Found']; } - $incomingMailAttachments = AttachmentModel::get([ - 'select' => ['res_id', 'title', 'format', 'attachment_type', 'path', 'filename'], - 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$resId, ['incoming_mail_attachment', 'converted_pdf']] - ]); - - $documents = [ - [ + $integrations = json_decode($incomingMail['integrations'], true); + $documents = []; + if (!empty($incomingMail['filename']) && empty($integrations['inSignatureBook'])) { + $documents[] = [ 'res_id' => $incomingMail['res_id'], 'alt_id' => $incomingMail['alt_identifier'], 'title' => $incomingMail['subject'], 'category_id' => $incomingMail['category_id'], 'viewerLink' => "../../rest/resources/{$resId}/content", 'thumbnailLink' => "rest/resources/{$resId}/thumbnail" - ] - ]; + ]; + } + $incomingMailAttachments = AttachmentModel::get([ + 'select' => ['res_id', 'title', 'format', 'attachment_type', 'path', 'filename'], + 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], + 'data' => [$resId, ['incoming_mail_attachment', 'converted_pdf']] + ]); foreach ($incomingMailAttachments as $value) { if ($value['attachment_type'] == 'converted_pdf') { continue; @@ -312,7 +312,18 @@ class SignatureBookController ); } - return array_values($attachments); + $attachments = array_values($attachments); + + $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['res_id', 'subject', 'alt_identifier', 'filename', 'integrations', 'format']]); + $integrations = json_decode($resource['integrations'], true); + if (!empty($resource['filename']) && !empty($integrations['inSignatureBook'])) { + array_unshift($attachments, $resource); + $attachments[0]['isResource'] = true; + $attachments[0]['sign'] = true; + $attachments[0]['viewerLink'] = "../../rest/resources/{$args['resId']}/content?".rand(); + } + + return $attachments; } public function getResources(Request $request, Response $response, array $aArgs) @@ -515,7 +526,7 @@ class SignatureBookController return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); } - $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['res_id_master']]); + $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['res_id_master', 'title', 'typist', 'identifier', 'recipient_id', 'recipient_type']]); if (empty($attachment)) { return $response->withStatus(403)->withJson(['errors' => 'Attachment out of perimeter']); } elseif (!SignatureBookController::isResourceInSignatureBook(['resId' => $attachment['res_id_master'], 'userId' => $GLOBALS['id']])) { @@ -576,59 +587,45 @@ class SignatureBookController } unlink($tmpPath.$convertedDocument['filename']); - $storeResult = DocserverController::storeResourceOnDocServer([ - 'collId' => 'attachments_coll', - 'docserverTypeId' => 'DOC', - 'encodedResource' => base64_encode($signedDocument), - 'format' => 'pdf' - ]); - if (!empty($storeResult['errors'])) { - return ['errors' => "[storeResourceOnDocServer] {$storeResult['errors']}"]; - } - $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['version']]); - AdrModel::createDocumentAdr([ - 'resId' => $args['resId'], - 'type' => 'SIGN', - 'docserverId' => $storeResult['docserver_id'], - 'path' => $storeResult['directory'], - 'filename' => $storeResult['file_destination_name'], - 'version' => $resource['version'], - 'fingerprint' => $storeResult['fingerPrint'] - ]); - $data = [ 'title' => $attachment['title'], 'encodedFile' => base64_encode($signedDocument), - 'format' => $attachment['format'], + 'format' => 'pdf', + 'typist' => $attachment['typist'], 'resIdMaster' => $attachment['res_id_master'], 'chrono' => $attachment['identifier'], 'type' => 'signed_response', + 'originId' => $args['id'], 'recipientId' => $attachment['recipient_id'], 'recipientType' => $attachment['recipient_type'], 'inSignatureBook' => true ]; - - $isStored = StoreController::storeAttachment($data); - if (!empty($isStored['errors'])) { - return ['errors' => $isStored['errors']]; + $id = StoreController::storeAttachment($data); + if (!empty($id['errors'])) { + return ['errors' => $id['errors']]; } + AttachmentModel::update([ + 'set' => ['status' => 'SIGN'], + 'where' => ['res_id = ?'], + 'data' => [$args['id']] + ]); ListInstanceModel::update([ 'set' => ['signatory' => 'true'], 'where' => ['res_id = ?', 'item_id = ?', 'difflist_type = ?'], - 'data' => [$args['resId'], $GLOBALS['userId'], 'VISA_CIRCUIT'] + 'data' => [$attachment['res_id_master'], $GLOBALS['userId'], 'VISA_CIRCUIT'] ]); HistoryController::add([ - 'tableName' => 'res_letterbox', - 'recordId' => $args['resId'], + 'tableName' => 'res_attachments', + 'recordId' => $args['id'], 'eventType' => 'SIGN', - 'eventId' => 'resourceSign', + 'eventId' => 'attachmentSign', 'info' => _DOCUMENT_SIGNED ]); - return $response->withStatus(204); + return $response->withJson(['id' => $id]); } public function unsignAttachment(Request $request, Response $response, array $args) diff --git a/src/frontend/app/signature-book.component.ts b/src/frontend/app/signature-book.component.ts index ca7263361652d74780d40f0b5899f635acfc016c..9af049d4cd2afc6c42dfe89dec8a17d9b81aded9 100755 --- a/src/frontend/app/signature-book.component.ts +++ b/src/frontend/app/signature-book.component.ts @@ -393,58 +393,42 @@ export class SignatureBookComponent implements OnInit { signFile(attachment: any, signature: any) { if (!this.loadingSign && this.signatureBook.canSign) { this.loadingSign = true; - var path = "index.php?display=true&module=visa&page=sign_file&collId=letterbox_coll&resIdMaster=" + this.resId + "&signatureId=" + signature.id; - - if (attachment.attachment_type == "outgoing_mail" && this.signatureBook.documents[0].category_id == "outgoing") { - path += "&isOutgoing&id=" + attachment.res_id; - } else { - path += "&id=" + attachment.res_id; - } - - this.http.get(path, signature) + var route = attachment.isResource ? '../../rest/resources/' + attachment.res_id + '/sign' : '../../rest/attachments/' + attachment.res_id + '/sign'; + this.http.put(route, {'signatureId' : signature.id}) .subscribe((data : any) => { - if (data.status == 0) { - this.rightViewerLink = "../../rest/attachments/" + data.new_id + "/content"; - this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink; + if (!attachment.isResource) { + this.rightViewerLink = "../../rest/attachments/" + data.id + "/content"; this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'SIGN'; this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = data.new_id; - var allSigned = true; - this.signatureBook.attachments.forEach((value: any) => { - if (value.sign && value.status != 'SIGN') { - allSigned = false; - } - }); - if (this.signatureBook.resList.length > 0) { - this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = allSigned; - } - - if(this.headerTab==3){ - this.changeSignatureBookLeftContent(0); - setTimeout(() => { - this.changeSignatureBookLeftContent(3); - }, 0); - } } else { - alert(data.error); + this.rightViewerLink += "?tsp=" + Math.floor(Math.random() * 100); + } + this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink; + var allSigned = true; + this.signatureBook.attachments.forEach((value: any) => { + if (value.sign && value.status != 'SIGN') { + allSigned = false; + } + }); + if (this.signatureBook.resList.length > 0) { + this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = allSigned; } this.showSignaturesPanel = false; this.loadingSign = false; + }, (error: any) => { + this.loadingSign = false; }); } } unsignFile(attachment: any) { - var resId: number; - - resId = attachment.res_id; - - this.http.put(this.coreUrl + 'rest/attachments/' + resId + '/unsign', {}) + this.http.put('../../rest/attachments/' + attachment.res_id + '/unsign', {}) .subscribe(() => { - this.rightViewerLink = "../../rest/attachments/" + resId + "/content"; + this.rightViewerLink = "../../rest/attachments/" + attachment.res_id + "/content"; this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink; this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'A_TRA'; - this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = resId; + this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = attachment.res_id; if (this.signatureBook.resList.length > 0) { this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = false; } @@ -456,7 +440,6 @@ export class SignatureBookComponent implements OnInit { } }); - } backToBasket() {