Newer
Older
<?php
/**
* 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.
*
*/
/**
* @brief Resource Data Export Controller
* @author dev@maarch.org
*/
namespace Resource\controllers;
use AcknowledgementReceipt\models\AcknowledgementReceiptModel;
use Attachment\models\AttachmentModel;
use Contact\controllers\ContactController;
use Contact\models\ContactModel;
use Convert\controllers\ConvertPdfController;
use Docserver\models\DocserverModel;
use Docserver\models\DocserverTypeModel;
Guillaume Heurtier
committed
use Doctype\models\DoctypeModel;
use Email\models\EmailModel;
Guillaume Heurtier
committed
use IndexingModel\models\IndexingModelFieldModel;
use Note\models\NoteModel;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use setasign\Fpdi\Tcpdf\Fpdi;
use Slim\Http\Request;
use Slim\Http\Response;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\ValidatorModel;
use Status\models\StatusModel;
use User\models\UserModel;
class ResourceDataExportController
{
Guillaume Heurtier
committed
public static function generateFile(Request $request, Response $response)
Guillaume Heurtier
committed
$body = $request->getParsedBody();
Guillaume Heurtier
committed
if (!Validator::notEmpty()->arrayType()->validate($body['resources'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body resources is empty']);
Guillaume Heurtier
committed
}
Guillaume Heurtier
committed
// Array containing all path to the pdf files to merge
$documentPaths = [];
Guillaume Heurtier
committed
$withSeparators = !empty($body['withSeparator']);
$unitsSummarySheet = [];
if (!empty($body['summarySheet'])) {
$unitsSummarySheet = $body['summarySheet'];
}
Guillaume Heurtier
committed
$forceSummarySheet = count($body['resources']) > 1;
$resIds = array_column($body['resources'], 'resId');
if (!ResController::hasRightByResId(['resId' => $resIds, 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
foreach ($body['resources'] as $resource) {
$withSummarySheet = $forceSummarySheet || !empty($unitsSummarySheet);
Guillaume Heurtier
committed
if (!$withSummarySheet) {
$withSummarySheet = !empty($resource['summarySheet']);
}
if ($withSummarySheet) {
if (!empty($resource['summarySheet']) && is_array($resource['summarySheet'])) {
$units = $resource['summarySheet'];
} else if (!empty($unitsSummarySheet)) {
$units = $unitsSummarySheet;
Guillaume Heurtier
committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
} else {
$units = [
[
"unit" => "qrcode",
"label" => ""
],
[
"unit" => "primaryInformations",
"label" => "Informations pricipales"
],
[
"unit" => "senderRecipientInformations",
"label" => "Informations de destination"
],
[
"unit" => "secondaryInformations",
"label" => "Informations secondaires"
],
[
"unit" => "diffusionList",
"label" => "Liste de diffusion"
],
[
"unit" => "opinionWorkflow",
"label" => "Circuit d'avis"
],
[
"unit" => "visaWorkflow",
"label" => "Circuit de visa"
]
];
}
$documentPaths[] = ResourceDataExportController::getSummarySheet(['units' => $units, 'resId' => $resource['resId']]);
}
Guillaume Heurtier
committed
if (!empty($resource['document'])) {
$document = ResModel::getById([
'select' => ['res_id', 'docserver_id', 'path', 'filename', 'fingerprint', 'category_id', 'alt_identifier'],
'resId' => $resource['resId']
]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
Guillaume Heurtier
committed
if (empty($document['filename'])) {
return $response->withStatus(400)->withJson(['errors' => 'Document has no file']);
}
Guillaume Heurtier
committed
$path = ResourceDataExportController::getDocumentFilePath(['document' => $document, 'collId' => 'letterbox_coll']);
if (!empty($path['errors'])) {
return $response->withStatus($path['code'])->withJson(['errors' => $path['errors']]);
}
$documentPaths[] = $path;
}
Guillaume Heurtier
committed
if (!empty($resource['attachments'])) {
if (is_array($resource['attachments'])) {
foreach ($resource['attachments'] as $note) {
if (!Validator::intVal()->validate($note)) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment id is not an integer']);
}
}
$attachments = AttachmentModel::get([
'select' => ['res_id', 'res_id_master', 'recipient_type', 'recipient_id', 'typist', 'status', 'attachment_type',
'creation_date', 'identifier', 'title', 'format', 'docserver_id'],
'where' => ['res_id in (?)', 'status not in (?)'],
'data' => [$resource['attachments'], ['DEL', 'OBS']],
'orderBy' => ['creation_date desc']
]);
if (count($attachments) < count($resource['attachments'])) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment(s) not found']);
Guillaume Heurtier
committed
}
} else {
$attachments = AttachmentModel::get([
'select' => ['res_id', 'res_id_master', 'recipient_type', 'recipient_id', 'typist', 'status', 'attachment_type',
'creation_date', 'identifier', 'title', 'format', 'docserver_id'],
'where' => ['res_id_master = ?', 'status not in (?)'],
'data' => [$resource['resId'], ['DEL', 'OBS']],
'orderBy' => ['creation_date desc']
]);
}
if (!empty($attachments)) {
$chronoResource = ResModel::getById(['select' => ['alt_identifier'], 'resId' => $resource['resId']]);
$chronoResource = $chronoResource['alt_identifier'];
foreach ($attachments as $attachment) {
if ($attachment['res_id_master'] != $resource['resId']) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment not linked to resource']);
}
Guillaume Heurtier
committed
if ($withSeparators) {
$documentPaths[] = ResourceDataExportController::getAttachmentSeparator([
'attachment' => $attachment,
'chronoResource' => $chronoResource
]);
}
Guillaume Heurtier
committed
$path = ResourceDataExportController::getDocumentFilePath(['document' => $attachment, 'collId' => 'attachments_coll']);
if (!empty($path['errors'])) {
return $response->withStatus($path['code'])->withJson(['errors' => $path['errors']]);
}
$documentPaths[] = $path;
}
Guillaume Heurtier
committed
}
}
Guillaume Heurtier
committed
if (!empty($resource['notes'])) {
if (is_array($resource['notes'])) {
foreach ($resource['notes'] as $note) {
if (!Validator::intVal()->validate($note)) {
return $response->withStatus(400)->withJson(['errors' => 'Note id is not an integer']);
}
}
Guillaume Heurtier
committed
$notes = NoteModel::get([
'where' => ['id in (?)'],
'data' => [$resource['notes']],
'orderBy' => ['creation_date desc']
]);
if (count($notes) < count($resource['notes'])) {
return $response->withStatus(400)->withJson(['errors' => 'Note(s) not found']);
}
Guillaume Heurtier
committed
} else {
Guillaume Heurtier
committed
$notes = NoteModel::get([
'select' => ['id', 'identifier', 'user_id', 'note_text', 'creation_date'],
'where' => ['identifier = ? '],
'data' => [$resource['resId']],
'orderBy' => ['creation_date desc']
Guillaume Heurtier
committed
]);
Guillaume Heurtier
committed
if (!empty($notes)) {
$noteFilePath = ResourceDataExportController::getNotesFilePath(['notes' => $notes, 'resId' => $resource['resId']]);
Guillaume Heurtier
committed
Guillaume Heurtier
committed
if (!empty($noteFilePath['errors'])) {
return $response->withStatus($noteFilePath['code'])->withJson(['errors' => $noteFilePath['errors']]);
}
Guillaume Heurtier
committed
if (file_exists($noteFilePath)) {
$documentPaths[] = $noteFilePath;
} else {
return $response->withStatus(500)->withJson(['errors' => 'Notes file not created']);
}
Guillaume Heurtier
committed
}
}
Guillaume Heurtier
committed
if (!empty($resource['acknowledgementReceipts'])) {
if (is_array($resource['acknowledgementReceipts'])) {
foreach ($resource['acknowledgementReceipts'] as $acknowledgementReceipt) {
if (!Validator::intVal()->validate($acknowledgementReceipt)) {
return $response->withStatus(400)->withJson(['errors' => 'Acknowledgement Receipt id is not an integer']);
}
}
Guillaume Heurtier
committed
$acknowledgementReceipts = AcknowledgementReceiptModel::getByIds([
'select' => ['id', 'res_id', 'format', 'contact_id', 'user_id', 'creation_date', 'send_date', 'docserver_id', 'path',
Guillaume Heurtier
committed
'filename', 'fingerprint'],
Guillaume Heurtier
committed
'ids' => $resource['acknowledgementReceipts']
Guillaume Heurtier
committed
]);
Guillaume Heurtier
committed
Guillaume Heurtier
committed
if (count($acknowledgementReceipts) < count($resource['acknowledgementReceipts'])) {
Guillaume Heurtier
committed
return $response->withStatus(400)->withJson(['errors' => 'Acknowledgement Receipt(s) not found']);
Guillaume Heurtier
committed
}
Guillaume Heurtier
committed
} else {
$acknowledgementReceipts = AcknowledgementReceiptModel::get([
'select' => ['id', 'res_id', 'format', 'contact_id', 'user_id', 'creation_date', 'send_date', 'docserver_id', 'path',
'filename', 'fingerprint'],
'where' => ['res_id = ?'],
'data' => [$resource['resId']]
]);
}
Guillaume Heurtier
committed
Guillaume Heurtier
committed
if (!empty($acknowledgementReceipts)) {
Guillaume Heurtier
committed
foreach ($acknowledgementReceipts as $acknowledgementReceipt) {
if ($acknowledgementReceipt['res_id'] != $resource['resId']) {
return $response->withStatus(400)->withJson(['errors' => 'Acknowledgement Receipt not linked to resource']);
}
Guillaume Heurtier
committed
Guillaume Heurtier
committed
if ($withSeparators) {
$documentPaths[] = ResourceDataExportController::getAcknowledgementReceiptSeparator(['acknowledgementReceipt' => $acknowledgementReceipt]);
}
$path = ResourceDataExportController::getDocumentFilePath(['document' => $acknowledgementReceipt]);
Guillaume Heurtier
committed
Guillaume Heurtier
committed
if ($acknowledgementReceipt['format'] == 'html') {
$path = ResourceDataExportController::getPathConvertedAcknowledgementReceipt([
'acknowledgementReceipt' => $acknowledgementReceipt,
'pathHtml' => $path
]);
}
Guillaume Heurtier
committed
Guillaume Heurtier
committed
$documentPaths[] = $path;
}
Guillaume Heurtier
committed
}
if (!empty($resource['emails'])) {
if (is_array($resource['emails'])) {
foreach ($resource['emails'] as $email) {
if (!Validator::intVal()->validate($email)) {
return $response->withStatus(400)->withJson(['errors' => 'Email id is not an integer']);
}
}
Guillaume Heurtier
committed
$emails = EmailModel::get([
'select' => ['id', 'user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'send_date'],
Guillaume Heurtier
committed
'where' => ['id in (?)'],
Guillaume Heurtier
committed
'data' => [$resource['emails']],
Guillaume Heurtier
committed
'orderBy' => ['creation_date desc']
]);
Guillaume Heurtier
committed
if (count($emails) < count($resource['emails'])) {
Guillaume Heurtier
committed
return $response->withStatus(400)->withJson(['errors' => 'Email(s) not found']);
Guillaume Heurtier
committed
} else {
$emails = EmailModel::get([
'select' => ['id', 'user_id', 'sender', 'recipients', 'cc', 'cci', 'object', 'body', 'document', 'send_date'],
'where' => ["cast(document->>'id' as INT) = ? "],
'data' => [$resource['resId']],
'orderBy' => ['creation_date desc']
]);
}
Guillaume Heurtier
committed
if (!empty($emails)) {
foreach ($emails as $email) {
Guillaume Heurtier
committed
$emailDocument = json_decode($email['document'], true);
if (!empty($emailDocument['id']) && $emailDocument['id'] != $resource['resId']) {
return $response->withStatus(400)->withJson(['errors' => 'Email not linked to resource']);
}
$emailFilePath = ResourceDataExportController::getEmailFilePath(['email' => $email, 'resId' => $resource['resId']]);
if (file_exists($emailFilePath)) {
$documentPaths[] = $emailFilePath;
} else {
return $response->withStatus(500)->withJson(['errors' => 'Email file not created']);
}
if (!empty($documentPaths)) {
$tmpDir = CoreConfigModel::getTmpPath();
Guillaume Heurtier
committed
$filePathOnTmp = $tmpDir . 'mergedFile.pdf';
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
$command = "pdfunite " . implode(" ", $documentPaths) . ' ' . $filePathOnTmp;
exec($command . ' 2>&1', $output, $return);
if (!file_exists($filePathOnTmp)) {
return $response->withStatus(500)->withJson(['errors' => 'Merged file not created']);
} else {
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$fileContent = file_get_contents($filePathOnTmp);
$mimeType = $finfo->buffer($fileContent);
$response->write($fileContent);
$response = $response->withAddedHeader('Content-Disposition', "inline; filename=maarch.pdf");
return $response->withHeader('Content-Type', $mimeType);
}
}
return $response->withStatus(400)->withJson(['errors' => 'No document to merge']);
}
private static function getDocumentFilePath(array $args)
{
ValidatorModel::notEmpty($args, ['document']);
ValidatorModel::arrayType($args, ['document']);
ValidatorModel::stringType($args, ['collId']);
$resourceDocument = $args['document'];
Guillaume Heurtier
committed
if (!empty($args['collId']) && in_array($args['collId'], ['letterbox_coll', 'attachments_coll'])) {
$document = ConvertPdfController::getConvertedPdfById(['resId' => $resourceDocument['res_id'], 'collId' => $args['collId']]);
if (!empty($document['errors'])) {
return ['errors' => 'Conversion error : ' . $document['errors'], 'code' => 400];
}
if ($document['docserver_id'] == $resourceDocument['docserver_id']) {
return ['errors' => 'Document can not be converted', 'code' => 400];
}
} else {
$document = $resourceDocument;
}
$docserver = DocserverModel::getByDocserverId([
'docserverId' => $document['docserver_id'], 'select' => ['path_template', 'docserver_type_id']
]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return ['errors' => 'Docserver does not exist', 'code' => 400];
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $document['path']) . $document['filename'];
if (!file_exists($pathToDocument)) {
return ['errors' => 'Document not found on docserver', 'code' => 404];
}
$docserverType = DocserverTypeModel::getById(['id' => $docserver['docserver_type_id'], 'select' => ['fingerprint_mode']]);
$fingerprint = StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType['fingerprint_mode']]);
if (!empty($document['fingerprint']) && $document['fingerprint'] != $fingerprint) {
return ['errors' => 'Fingerprints do not match', 'code' => 400];
}
return $pathToDocument;
}
private static function getNotesFilePath(array $args)
{
ValidatorModel::notEmpty($args, ['notes', 'resId']);
ValidatorModel::arrayType($args, ['notes']);
ValidatorModel::intVal($args, ['resId']);
$notes = [];
Guillaume Heurtier
committed
foreach ($args['notes'] as $note) {
if ($note['identifier'] != $args['resId']) {
return ['errors' => 'Note not linked to resource', 'code' => 400];
}
$user = UserModel::getById(['id' => $note['user_id'], 'select' => ['firstname', 'lastname']]);
$userName = $user['firstname'] . ' ' . $user['lastname'];
Guillaume Heurtier
committed
$noteText = str_replace('←', '<=', $note['note_text']);
$date = explode('-', date('d-m-Y', strtotime($note['creation_date'])));
$date = $date[0].'/'.$date[1].'/'.$date[2].' '.date('H:i', strtotime($note['creation_date']));
$notes[] = ['user' => $userName, 'note' => $noteText, 'date' => $date];
}
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
$pdf->AddPage();
$dimensions = $pdf->getPageDimensions();
$widthNoMargins = $dimensions['w'] - $dimensions['rm'] - $dimensions['lm'];
$bottomHeight = $dimensions['h'] - $dimensions['bm'];
$widthNotes = $widthNoMargins / 2;
$pdf->SetY($pdf->GetY() + 40);
if (($pdf->GetY() + 80) > $bottomHeight) {
$pdf->AddPage();
}
$pdf->SetFont('', 'B', 11);
$pdf->Cell(0, 15, _NOTES_COMMENT, 0, 2, 'L', false);
$pdf->SetY($pdf->GetY() + 2);
$pdf->SetFont('', '', 10);
foreach ($notes as $note) {
if (($pdf->GetY() + 65) > $bottomHeight) {
$pdf->AddPage();
}
$pdf->SetFont('', 'B', 10);
$pdf->Cell($widthNotes, 20, $note['user'], 1, 0, 'L', false);
$pdf->SetFont('', '', 10);
$pdf->Cell($widthNotes, 20, $note['date'], 1, 1, 'L', false);
$pdf->MultiCell(0, 40, $note['note'], 1, 'L', false);
$pdf->SetY($pdf->GetY() + 5);
}
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'listNotes_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}
private static function getAcknowledgementReceiptSeparator(array $args)
{
Guillaume Heurtier
committed
ValidatorModel::notEmpty($args, ['acknowledgementReceipt']);
ValidatorModel::arrayType($args, ['acknowledgementReceipt']);
$acknowledgementReceipt = $args['acknowledgementReceipt'];
$contact = ContactModel::getById([
'select' => ['id', 'firstname', 'lastname', 'email', 'address_number', 'address_street', 'address_postcode',
'address_town', 'address_country', 'company'],
'id' => $acknowledgementReceipt['contact_id']
]);
if ($acknowledgementReceipt['format'] == 'html') {
$displayContact = $contact['firstname'] . ' ' . $contact['lastname'] . ' (' . $contact['email'] . ')';
} else {
$displayContact = ContactController::getFormattedContactWithAddress([
'contact' => $contact
]);
$displayContact = $displayContact['contact']['otherInfo'];
}
$creator = UserModel::getById(['id' => $acknowledgementReceipt['user_id']]);
$creationDate = new \DateTime($acknowledgementReceipt['creation_date']);
$creationDate = $creationDate->format('d-m-Y H:i');
if (!empty($acknowledgementReceipt['send_date'])) {
$sendDate = new \DateTime($acknowledgementReceipt['send_date']);
$sendDate = $sendDate->format('d-m-Y H:i');
} else {
$sendDate = _UNDEFINED;
}
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
$pdf->AddPage();
$dimensions = $pdf->getPageDimensions();
$widthNoMargins = $dimensions['w'] - $dimensions['rm'] - $dimensions['lm'];
$width = $widthNoMargins / 2;
$pdf->SetFont('', 'B', 12);
$pdf->Cell($width, 15, _ACKNOWLEDGEMENT_RECEIPT, 0, 1, 'L', false);
$pdf->SetY($pdf->GetY() + 40);
$pdf->SetFont('', '', 10);
$pdf->MultiCell($width, 30, '<b>' . _CREATED_BY . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $creator['firstname'] . ' ' . $creator['lastname'] , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _CREATED . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $creationDate , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _SENT_DATE . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $sendDate, 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _FORMAT . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $acknowledgementReceipt['format'] , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _SENT_TO . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $displayContact , 1, 'L', false, 1, '', '', true, 0, true);
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'convertedAr_' . $acknowledgementReceipt['id'] . '_SEPARATOR_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}
private static function getPathConvertedAcknowledgementReceipt(array $args)
{
Guillaume Heurtier
committed
ValidatorModel::notEmpty($args, ['acknowledgementReceipt', 'pathHtml']);
ValidatorModel::arrayType($args, ['acknowledgementReceipt']);
ValidatorModel::stringType($args, ['pathHtml']);
$acknowledgementReceipt = $args['acknowledgementReceipt'];
$contentHtml = file_get_contents($args['pathHtml']);
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
$pdf->AddPage();
$pdf->writeHTML($contentHtml);
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'convertedAr_' . $acknowledgementReceipt['id'] . '_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}
private static function getAttachmentSeparator(array $args)
{
Guillaume Heurtier
committed
ValidatorModel::notEmpty($args, ['attachment', 'chronoResource']);
ValidatorModel::arrayType($args, ['attachment']);
ValidatorModel::stringType($args, ['chronoResource']);
$attachment = $args['attachment'];
$chronoResource = $args['chronoResource'];
if ($attachment['recipient_type'] == 'user') {
$displayContact = UserModel::getLabelledUserById(['id' => $attachment['recipient_id']]);
} else if ($attachment['recipient_type'] == 'contact') {
$contact = ContactModel::getById([
'select' => ['id', 'firstname', 'lastname', 'email', 'address_number', 'address_street', 'address_postcode',
'address_town', 'address_country', 'company'],
'id' => $attachment['recipient_id']
]);
$displayContact = ContactController::getFormattedContactWithAddress([
'contact' => $contact
]);
$displayContact = $displayContact['contact']['otherInfo'];
}
$creator = UserModel::getByLogin(['login' => $attachment['typist']]);
$status = StatusModel::getById(['id' => $attachment['status'], 'select' => ['label_status']]);
$status = $status['label_status'];
$attachmentTypes = AttachmentModel::getAttachmentsTypesByXML();
$attachmentType = $attachmentTypes[$attachment['attachment_type']]['label'];
$creationDate = new \DateTime($attachment['creation_date']);
$creationDate = $creationDate->format('d-m-Y H:i');
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
$pdf->AddPage();
$dimensions = $pdf->getPageDimensions();
$widthNoMargins = $dimensions['w'] - $dimensions['rm'] - $dimensions['lm'];
$width = $widthNoMargins / 2;
$pdf->SetFont('', 'B', 12);
$pdf->Cell($width, 15, _ATTACHMENT, 0, 0, 'L', false);
$pdf->Cell($width, 15, $attachment['identifier'], 0, 1, 'C', false);
$pdf->SetY($pdf->GetY() + 40);
$pdf->SetFont('', '', 10);
$pdf->MultiCell($width, 30, '<b>' . _CHRONO_NUMBER_MASTER . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $chronoResource , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _SUBJECT . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $attachment['title'], 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _CREATED_BY . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $creator['firstname'] . ' ' . $creator['lastname'] , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _CREATED . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $creationDate , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _FORMAT . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $attachment['format'] , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _STATUS . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $status , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _DOCTYPE . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $attachmentType , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, '<b>' . _CONTACT . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $displayContact , 1, 'L', false, 1, '', '', true, 0, true);
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'attachment_' . $attachment['res_id'] . '_SEPARATOR_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}
private static function getEmailFilePath(array $args)
{
ValidatorModel::notEmpty($args, ['email', 'resId']);
ValidatorModel::arrayType($args, ['email']);
ValidatorModel::intVal($args, ['resId']);
$email = $args['email'];
$date = new \DateTime($email['send_date']);
Guillaume Heurtier
committed
$date = $date->format('d-m-Y H:i');
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
$sentDate = _SENT_DATE . ' ' . $date;
$sentBy = UserModel::getLabelledUserById(['id' => $email['user_id']]);
$sender = json_decode($email['sender'], true);
$sender = $sender['email'] ?? _UNDEFINED;
$recipients = json_decode($email['recipients'], true);
$recipients = implode(", ", $recipients);
$recipients = !empty($recipients) ? $recipients : _UNDEFINED;
$recipientsCopy = json_decode($email['cc'], true);
$recipientsCopy = implode(", ", $recipientsCopy);
$recipientsCopy = !empty($recipientsCopy) ? $recipientsCopy : _UNDEFINED;
$recipientsCopyHidden = json_decode($email['cci'], true);
$recipientsCopyHidden = implode(", ", $recipientsCopyHidden);
$recipientsCopyHidden = !empty($recipientsCopyHidden) ? $recipientsCopyHidden : _UNDEFINED;
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
$pdf->AddPage();
$dimensions = $pdf->getPageDimensions();
$widthNoMargins = $dimensions['w'] - $dimensions['rm'] - $dimensions['lm'];
$width = $widthNoMargins / 2;
$widthQuarter = $widthNoMargins / 4;
$widthThreeQuarter = $widthQuarter * 3;
$pdf->SetFont('', 'B', 12);
$pdf->Cell($width, 15, _EMAIL, 0, 0, 'L', false);
$pdf->SetFont('', '', 11);
$pdf->Cell($width, 15, $sentDate, 0, 1, 'R', false);
$pdf->SetY($pdf->GetY() + 5);
$pdf->SetFont('', '', 10);
$pdf->MultiCell($width, 15, '<b>' . _SENT_BY.'</b>', 1, 'C', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 15, '<b>' . _SENDER.'</b>', 1, 'C', false, 1, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $sentBy, 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($width, 30, $sender, 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthQuarter, 30, '<b>' . _RECIPIENTS . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthThreeQuarter, 30, $recipients, 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthQuarter, 30, '<b>' . _TO_CC . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthThreeQuarter, 30, $recipientsCopy , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthQuarter, 30, '<b>' . _TO_CCI . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthThreeQuarter, 30, $recipientsCopyHidden , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->MultiCell($widthQuarter, 30, '<b>' . _SUBJECT . '</b>', 1, 'L', false, 0, '', '', true, 0, true);
$pdf->MultiCell($widthThreeQuarter, 30, $email['object'] , 1, 'L', false, 1, '', '', true, 0, true);
$pdf->SetY($pdf->GetY() + 5);
$pdf->writeHTML($email['body']);
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'email_' . $email['id'] . '_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}
Guillaume Heurtier
committed
private static function getSummarySheet(array $args)
{
ValidatorModel::notEmpty($args, ['units', 'resId']);
ValidatorModel::arrayType($args, ['units']);
ValidatorModel::intVal($args, ['resId']);
$units = $args['units'];
$resId = $args['resId'];
$resource = ResModel::getById([
'select' => ['res_id', 'alt_identifier', 'type_id', 'model_id', 'subject', 'admission_date', 'creation_date',
'doc_date', 'initiator', 'typist', 'category_id', 'status', 'priority', 'process_limit_date', 'destination'],
Guillaume Heurtier
committed
'resId' => $resId
]);
$doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $resource['type_id']]);
$resource['type_label'] = $doctype['description'];
$data = SummarySheetController::prepareData(['units' => $units, 'resourcesIds' => [$resId]]);
$indexingFields = IndexingModelFieldModel::get([
'select' => ['identifier', 'unit'],
'where' => ['model_id = ?'],
'data' => [$resource['model_id']]
]);
$fieldsIdentifier = array_column($indexingFields, 'identifier');
$pdf = new Fpdi('P', 'pt');
$pdf->setPrintHeader(false);
SummarySheetController::createSummarySheet($pdf, [ // TODO check missing border for date limite de traitement
Guillaume Heurtier
committed
'resource' => $resource,
'units' => $units,
'login' => $GLOBALS['userId'],
'data' => $data,
'fieldsIdentifier' => $fieldsIdentifier
]);
$tmpDir = CoreConfigModel::getTmpPath();
$filePathOnTmp = $tmpDir . 'summarySheet_' . $resId . '_' . $GLOBALS['id'] . '.pdf';
$pdf->Output($filePathOnTmp, 'F');
return $filePathOnTmp;
}