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

FEAT #12345 TIME 3:30 End mailing

parent c351905d
No related branches found
No related tags found
No related merge requests found
Showing
with 97 additions and 259 deletions
...@@ -202,8 +202,7 @@ function manage_form($arr_id, $history, $id_action, $label_action, $status, $col ...@@ -202,8 +202,7 @@ function manage_form($arr_id, $history, $id_action, $label_action, $status, $col
foreach ($arr_id as $res_id) { foreach ($arr_id as $res_id) {
$result .= $res_id.'#'; $result .= $res_id.'#';
\Attachment\controllers\AttachmentController::generateAttachForMailing(['resIdMaster' => $res_id, 'userId' => $_SESSION['user']['UserId']]);
if (!empty($config)) { if (!empty($config)) {
if ($config['id'] == 'ixbus') { if ($config['id'] == 'ixbus') {
include_once 'modules/visa/class/IxbusController.php'; include_once 'modules/visa/class/IxbusController.php';
......
...@@ -380,8 +380,6 @@ if (isset($_POST['add']) && $_POST['add']) { ...@@ -380,8 +380,6 @@ if (isset($_POST['add']) && $_POST['add']) {
'chronoAttachment' => $chronoPubli, 'chronoAttachment' => $chronoPubli,
]; ];
$filePathOnTmp = \Template\controllers\TemplateController::mergeDatasource($params);
$fileInfos = [ $fileInfos = [
'tmpDir' => $_SESSION['config']['tmppath'], 'tmpDir' => $_SESSION['config']['tmppath'],
'size' => $_SESSION['upfile'][$numAttach]['size'], 'size' => $_SESSION['upfile'][$numAttach]['size'],
...@@ -1086,8 +1084,6 @@ if (isset($_POST['add']) && $_POST['add']) { ...@@ -1086,8 +1084,6 @@ if (isset($_POST['add']) && $_POST['add']) {
'chronoAttachment' => $chronoPubli, 'chronoAttachment' => $chronoPubli,
]; ];
$filePathOnTmp = \Template\controllers\TemplateController::mergeDatasource($params);
$fileInfos = [ $fileInfos = [
'tmpDir' => $_SESSION['config']['tmppath'], 'tmpDir' => $_SESSION['config']['tmppath'],
'size' => filesize($filePathOnTmp), 'size' => filesize($filePathOnTmp),
......
...@@ -333,12 +333,6 @@ abstract class visa_Abstract extends Database ...@@ -333,12 +333,6 @@ abstract class visa_Abstract extends Database
// If there is only one step in the visa workflow, we set status to ESIG // If there is only one step in the visa workflow, we set status to ESIG
if ($resListDiffVisa->requested_signature) { if ($resListDiffVisa->requested_signature) {
$mailStatus = 'ESIG'; $mailStatus = 'ESIG';
if ($inDetails == false) {
\Attachment\controllers\AttachmentController::generateAttachForMailing([
'resIdMaster' => $res_id,
'userId' => $_SESSION['user']['UserId']
]);
}
} else { } else {
$mailStatus = 'EVIS'; $mailStatus = 'EVIS';
} }
......
...@@ -79,7 +79,7 @@ $app->put('/attachments/{id}/inSendAttachment', \Attachment\controllers\Attachme ...@@ -79,7 +79,7 @@ $app->put('/attachments/{id}/inSendAttachment', \Attachment\controllers\Attachme
$app->get('/attachments/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow'); $app->get('/attachments/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow');
$app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); $app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook');
$app->put('/attachments/{id}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignAttachment'); $app->put('/attachments/{id}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignAttachment');
$app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':generateMailingById'); $app->post('/attachments/{id}/mailing', \Attachment\controllers\AttachmentController::class . ':getMailingById');
$app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes'); $app->get('/attachmentsTypes', \Attachment\controllers\AttachmentController::class . ':getAttachmentsTypes');
//AutoComplete //AutoComplete
......
...@@ -16,6 +16,7 @@ use AcknowledgementReceipt\models\AcknowledgementReceiptModel; ...@@ -16,6 +16,7 @@ use AcknowledgementReceipt\models\AcknowledgementReceiptModel;
use Action\models\ActionModel; use Action\models\ActionModel;
use Action\models\BasketPersistenceModel; use Action\models\BasketPersistenceModel;
use Action\models\ResMarkAsReadModel; use Action\models\ResMarkAsReadModel;
use Attachment\controllers\AttachmentController;
use Attachment\models\AttachmentModel; use Attachment\models\AttachmentModel;
use Entity\controllers\ListInstanceController; use Entity\controllers\ListInstanceController;
use Entity\models\EntityModel; use Entity\models\EntityModel;
...@@ -310,11 +311,21 @@ class ActionMethodController ...@@ -310,11 +311,21 @@ class ActionMethodController
ValidatorModel::notEmpty($args, ['resId']); ValidatorModel::notEmpty($args, ['resId']);
ValidatorModel::intVal($args, ['resId']); ValidatorModel::intVal($args, ['resId']);
$circuit = ListInstanceModel::get(['select' => [1], 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], 'data' => [$args['resId'], 'VISA_CIRCUIT']]); $circuit = ListInstanceModel::get([
'select' => ['requested_signature'],
'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'],
'data' => [$args['resId'], 'VISA_CIRCUIT'],
'orderBy' => ['listinstance_id'],
'limit' => 1
]);
if (empty($circuit)) { if (empty($circuit)) {
return ['errors' => ['No available circuit']]; return ['errors' => ['No available circuit']];
} }
$resource = ResModel::getById(['select' => ['integrations'], 'resId' => $args['resId']]);
$integrations = json_decode($resource['integrations'], true);
$resourceIn = !empty($integrations['inSignatureBook']);
$signableAttachmentsTypes = []; $signableAttachmentsTypes = [];
$attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML();
foreach ($attachmentsTypes as $key => $type) { foreach ($attachmentsTypes as $key => $type) {
...@@ -323,21 +334,26 @@ class ActionMethodController ...@@ -323,21 +334,26 @@ class ActionMethodController
} }
} }
$resource = ResModel::getById(['select' => ['integrations'], 'resId' => $args['resId']]);
$integrations = json_decode($resource['integrations'], true);
if (!empty($integrations['inSignatureBook'])) {
return true;
}
$attachments = AttachmentModel::get([ $attachments = AttachmentModel::get([
'select' => [1], 'select' => ['res_id', 'status'],
'where' => ['res_id_master = ?', 'attachment_type in (?)', 'in_signature_book = ?', 'status not in (?)'], 'where' => ['res_id_master = ?', 'attachment_type in (?)', 'in_signature_book = ?', 'status not in (?)'],
'data' => [$args['resId'], $signableAttachmentsTypes, true, ['OBS', 'DEL', 'FRZ']] 'data' => [$args['resId'], $signableAttachmentsTypes, true, ['OBS', 'DEL', 'FRZ']]
]); ]);
if (empty($attachments)) { if (empty($attachments) && !$resourceIn) {
return ['errors' => ['No available attachments']]; return ['errors' => ['No available attachments']];
} }
if ($circuit[0]['requested_signature'] == true) {
foreach ($attachments as $attachment) {
if ($attachment['status'] == 'SEND_MASS') {
$generated = AttachmentController::generateMailing(['id' => $attachment['res_id'], 'userId' => $GLOBALS['id']]);
if (!empty($generated['errors'])) {
return ['errors' => $generated['errors']];
}
}
}
}
return true; return true;
} }
...@@ -353,7 +369,6 @@ class ActionMethodController ...@@ -353,7 +369,6 @@ class ActionMethodController
'orderBy' => ['listinstance_id'], 'orderBy' => ['listinstance_id'],
'limit' => 1 'limit' => 1
]); ]);
if (empty($listInstance[0])) { if (empty($listInstance[0])) {
return ['errors' => ['No available circuit']]; return ['errors' => ['No available circuit']];
} }
...@@ -366,6 +381,28 @@ class ActionMethodController ...@@ -366,6 +381,28 @@ class ActionMethodController
'data' => [$listInstance[0]['listinstance_id']] 'data' => [$listInstance[0]['listinstance_id']]
]); ]);
$circuit = ListInstanceModel::get([
'select' => ['requested_signature'],
'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'],
'data' => [$args['resId'], 'VISA_CIRCUIT'],
'orderBy' => ['listinstance_id'],
'limit' => 1
]);
if ($circuit[0]['requested_signature'] == true) {
$attachments = AttachmentModel::get([
'select' => ['res_id'],
'where' => ['res_id_master = ?', 'in_signature_book = ?', 'status = ?'],
'data' => [$args['resId'], true, 'SEND_MASS']
]);
foreach ($attachments as $attachment) {
$generated = AttachmentController::generateMailing(['id' => $attachment['res_id'], 'userId' => $GLOBALS['id']]);
if (!empty($generated['errors'])) {
return ['errors' => $generated['errors']];
}
}
}
return true; return true;
} }
......
...@@ -621,102 +621,14 @@ class AttachmentController ...@@ -621,102 +621,14 @@ class AttachmentController
return ['encodedDocument' => $encodedDocument, 'fileName' => $fileName]; return ['encodedDocument' => $encodedDocument, 'fileName' => $fileName];
} }
public static function generateAttachForMailing(array $aArgs) public function getMailingById(Request $request, Response $response, array $args)
{
$attachments = AttachmentModel::get([
'select' => ['*'],
'where' => ['res_id_master = ?', 'status = ?', 'in_signature_book = ?'],
'data' => [$aArgs['resIdMaster'], 'SEND_MASS', true]
]);
$contactsForMailing = DatabaseModel::select([
'select' => ['*'],
'table' => ['contacts_res'],
'where' => ['res_id = ?', 'address_id <> 0'],
'data' => [$aArgs['resIdMaster']]
]);
if (!empty($attachments[0])) {
foreach ($attachments as $attachment) {
$docserver = DocserverModel::getCurrentDocserver(['typeId' => 'DOC', 'collId' => 'letterbox_coll', 'select' => ['path_template']]);
$pathToAttachmentToCopy = $docserver['path_template'] . str_replace('#', '/', $attachment['path']) . $attachment['filename'];
foreach ($contactsForMailing as $keyContact => $contactForMailing) {
$chronoPubli = $attachment['identifier'].'-'.($keyContact+1);
$params = [
'userId' => $aArgs['userId'],
'res_id' => $aArgs['resIdMaster'],
'coll_id' => 'letterbox_coll',
'res_view' => 'res_attachments',
'res_table' => 'res_attachments',
'res_contact_id' => $contactForMailing['contact_id'],
'res_address_id' => $contactForMailing['address_id'],
'pathToAttachment' => $pathToAttachmentToCopy,
'chronoAttachment' => $chronoPubli,
];
$filePathOnTmp = TemplateController::mergeDatasource($params);
$allDatas = [
"encodedFile" => base64_encode(file_get_contents($filePathOnTmp)),
"format" => $attachment['format'],
'resIdMaster' => $aArgs['resIdMaster'],
'type' => $attachment['attachment_type'],
'chrono' => $chronoPubli,
'title' => $attachment['title'],
'inSignatureBook' => true,
];
StoreController::storeAttachment($allDatas);
}
AttachmentModel::update([
'set' => [
'status' => 'DEL',
],
'where' => ['res_id = ?'],
'data' => [$attachment['res_id']]
]);
}
}
return ['success' => 'success'];
}
public static function isMailingAttach(array $aArgs)
{
$user = UserModel::getByLogin(['login' => $aArgs['login'], 'select' => ['id']]);
if (!Validator::intVal()->validate($aArgs['resIdMaster']) || !ResController::hasRightByResId(['resId' => [$aArgs['resIdMaster']], 'userId' => $user['id']])) {
return ['errors' => 'Document out of perimeter'];
}
$attachments = AttachmentModel::get([
'select' => ['res_id'],
'where' => ['res_id_master = ?', 'status = ?'],
'data' => [$aArgs['resIdMaster'],'SEND_MASS']
]);
$return['nbAttach'] = count($attachments);
if ($return['nbAttach'] == 0) {
return false;
}
$return['nbContacts'] = ResModel::getNbContactsByResId(["resId" => $aArgs['resIdMaster']]);
return $return;
}
public static function generateMailingById(Request $request, Response $response, array $args)
{ {
if (!Validator::intVal()->validate($args['id'])) { if (!Validator::intVal()->validate($args['id'])) {
return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'Route id is not an integer']);
} }
$attachment = AttachmentModel::getById([ $attachment = AttachmentModel::getById([
'select' => ['status', 'res_id_master', 'title', 'identifier', 'docserver_id', 'path', 'filename', 'format', 'attachment_type'], 'select' => ['status', 'res_id_master'],
'id' => $args['id'] 'id' => $args['id']
]); ]);
if (empty($attachment)) { if (empty($attachment)) {
...@@ -727,22 +639,43 @@ class AttachmentController ...@@ -727,22 +639,43 @@ class AttachmentController
return $response->withStatus(403)->withJson(['errors' => 'Attachment is not candidate to mailing']); return $response->withStatus(403)->withJson(['errors' => 'Attachment is not candidate to mailing']);
} }
$generated = AttachmentController::generateMailing(['id' => $args['id'], 'userId' => $GLOBALS['id']]);
if (!empty($generated['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $generated['errors']]);
}
return $response->withStatus(204);
}
public static function generateMailing(array $args)
{
ValidatorModel::notEmpty($args, ['id', 'userId']);
ValidatorModel::intVal($args, ['id', 'userId']);
$attachment = AttachmentModel::getById([
'select' => ['res_id_master', 'title', 'identifier', 'docserver_id', 'path', 'filename', 'format', 'attachment_type'],
'id' => $args['id']
]);
$resource = ResModel::getById(['resId' => $attachment['res_id_master'], 'select' => ['category_id']]);
$mode = $resource['category_id'] == 'incoming' ? 'sender' : 'recipient';
$recipients = ResourceContactModel::get([ $recipients = ResourceContactModel::get([
'select' => ['item_id'], 'select' => ['item_id'],
'where' => ['res_id = ?', 'type = ?', 'mode = ?'], 'where' => ['res_id = ?', 'type = ?', 'mode = ?'],
'data' => [$attachment['res_id_master'], 'contact', 'sender'] 'data' => [$attachment['res_id_master'], 'contact', $mode]
]); ]);
if (empty($recipients)) { if (empty($recipients)) {
return $response->withStatus(400)->withJson(['errors' => 'No contacts available']); return ['errors' => 'No contacts available'];
} }
$docserver = DocserverModel::getByDocserverId(['docserverId' => $attachment['docserver_id'], 'select' => ['path_template']]); $docserver = DocserverModel::getByDocserverId(['docserverId' => $attachment['docserver_id'], 'select' => ['path_template']]);
if (empty($docserver['path_template']) || !is_dir($docserver['path_template'])) { if (empty($docserver['path_template']) || !is_dir($docserver['path_template'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']); return ['errors' => 'Docserver does not exist'];
} }
$pathToAttachment = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $attachment['path']) . $attachment['filename']; $pathToAttachment = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $attachment['path']) . $attachment['filename'];
if (!is_file($pathToAttachment)) { if (!is_file($pathToAttachment)) {
return $response->withStatus(400)->withJson(['errors' => 'Attachment not found on docserver']); return ['errors' => 'Attachment not found on docserver'];
} }
foreach ($recipients as $key => $recipient) { foreach ($recipients as $key => $recipient) {
...@@ -750,7 +683,7 @@ class AttachmentController ...@@ -750,7 +683,7 @@ class AttachmentController
$mergedDocument = MergeController::mergeDocument([ $mergedDocument = MergeController::mergeDocument([
'path' => $pathToAttachment, 'path' => $pathToAttachment,
'data' => ['userId' => $GLOBALS['id'], 'recipientId' => $recipient['item_id'], 'recipientType' => 'contact'] 'data' => ['userId' => $args['userId'], 'recipientId' => $recipient['item_id'], 'recipientType' => 'contact']
]); ]);
$data = [ $data = [
...@@ -761,10 +694,14 @@ class AttachmentController ...@@ -761,10 +694,14 @@ class AttachmentController
'chrono' => $chrono, 'chrono' => $chrono,
'type' => $attachment['attachment_type'], 'type' => $attachment['attachment_type'],
'recipientId' => $recipient['item_id'], 'recipientId' => $recipient['item_id'],
'recipientType' => 'contact' 'recipientType' => 'contact',
'inSignatureBook' => true
]; ];
StoreController::storeAttachment($data); $isStored = StoreController::storeAttachment($data);
if (!empty($isStored['errors'])) {
return ['errors' => $isStored['errors']];
}
} }
AttachmentModel::update([ AttachmentModel::update([
...@@ -775,7 +712,7 @@ class AttachmentController ...@@ -775,7 +712,7 @@ class AttachmentController
'data' => [$args['id']] 'data' => [$args['id']]
]); ]);
return $response->withStatus(204); return true;
} }
private static function controlAttachment(array $args) private static function controlAttachment(array $args)
......
...@@ -72,7 +72,7 @@ class MergeController ...@@ -72,7 +72,7 @@ class MergeController
if (!empty($dataToBeMerge[$contact]['postal_address'])) { if (!empty($dataToBeMerge[$contact]['postal_address'])) {
$dataToBeMerge[$contact]['postal_address'] = nl2br($dataToBeMerge[$contact]['postal_address']); $dataToBeMerge[$contact]['postal_address'] = nl2br($dataToBeMerge[$contact]['postal_address']);
$dataToBeMerge[$contact]['postal_address'] = str_replace('<br />', '</w:t><w:br/><w:t>', $dataToBeMerge[$contact]['postal_address']); $dataToBeMerge[$contact]['postal_address'] = str_replace('<br />', '</w:t><w:br/><w:t>', $dataToBeMerge[$contact]['postal_address']);
$dataToBeMerge[$contact]['postal_address'] = str_replace(array("\n\r", "\r\n", "\r", "\n"), "", $dataToBeMerge[$contact]['postal_address']); $dataToBeMerge[$contact]['postal_address'] = str_replace(["\n\r", "\r\n", "\r", "\n"], "", $dataToBeMerge[$contact]['postal_address']);
} }
} }
$tbs->LoadTemplate($args['path'], OPENTBS_ALREADY_UTF8); $tbs->LoadTemplate($args['path'], OPENTBS_ALREADY_UTF8);
...@@ -318,6 +318,7 @@ class MergeController ...@@ -318,6 +318,7 @@ class MergeController
$dataToBeMerge['destination'] = empty($destination) ? [] : $destination; $dataToBeMerge['destination'] = empty($destination) ? [] : $destination;
$dataToBeMerge['parentDestination'] = empty($parentDestination) ? [] : $parentDestination; $dataToBeMerge['parentDestination'] = empty($parentDestination) ? [] : $parentDestination;
$dataToBeMerge['attachment'] = $attachment; $dataToBeMerge['attachment'] = $attachment;
$dataToBeMerge['sender'] = $sender;
$dataToBeMerge['recipient'] = $recipient; $dataToBeMerge['recipient'] = $recipient;
$dataToBeMerge['user'] = $currentUser; $dataToBeMerge['user'] = $currentUser;
$dataToBeMerge['userPrimaryEntity'] = $currentUserPrimaryEntity; $dataToBeMerge['userPrimaryEntity'] = $currentUserPrimaryEntity;
...@@ -327,9 +328,8 @@ class MergeController ...@@ -327,9 +328,8 @@ class MergeController
$dataToBeMerge['contact'] = []; $dataToBeMerge['contact'] = [];
$dataToBeMerge['notes'] = $mergedNote; $dataToBeMerge['notes'] = $mergedNote;
$dataToBeMerge['datetime'] = $datetime; $dataToBeMerge['datetime'] = $datetime;
if (!empty($args['inMailing'])) { if (empty($args['inMailing'])) {
$dataToBeMerge['attachmentRecipient'] = $attachmentRecipient; $dataToBeMerge['attachmentRecipient'] = $attachmentRecipient;
$dataToBeMerge['sender'] = $sender;
} }
return $dataToBeMerge; return $dataToBeMerge;
......
...@@ -172,11 +172,10 @@ class StoreController ...@@ -172,11 +172,10 @@ class StoreController
$externalId = json_encode($args['externalId']); $externalId = json_encode($args['externalId']);
} }
$integrations = ['inSignatureBook' => false, 'inShipping' => false, 'inMailing' => false]; $integrations = ['inSignatureBook' => false, 'inShipping' => false];
if (!empty($args['integrations'])) { if (!empty($args['integrations'])) {
$integrations['inSignatureBook'] = !empty($args['integrations']['inSignatureBook']); $integrations['inSignatureBook'] = !empty($args['integrations']['inSignatureBook']);
$integrations['inShipping'] = !empty($args['integrations']['inShipping']); $integrations['inShipping'] = !empty($args['integrations']['inShipping']);
$integrations['inMailing'] = !empty($args['integrations']['inMailing']);
} }
if (!empty($args['customFields'])) { if (!empty($args['customFields'])) {
......
...@@ -152,26 +152,6 @@ abstract class ResModelAbstract ...@@ -152,26 +152,6 @@ abstract class ResModelAbstract
return $resources; return $resources;
} }
public static function getDocsByClause(array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['clause']);
if (!empty($aArgs['table'])) {
$table = $aArgs['table'];
} else {
$table = 'res_view_letterbox';
}
$aReturn = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => [$table],
'where' => [$aArgs['clause']],
'order_by' => ['res_id']
]);
return $aReturn;
}
public static function getByAltIdentifier(array $args) public static function getByAltIdentifier(array $args)
{ {
ValidatorModel::notEmpty($args, ['altIdentifier']); ValidatorModel::notEmpty($args, ['altIdentifier']);
...@@ -228,18 +208,4 @@ abstract class ResModelAbstract ...@@ -228,18 +208,4 @@ abstract class ResModelAbstract
return ''; return '';
} }
public static function getNbContactsByResId(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['resId']);
ValidatorModel::intVal($aArgs, ['resId']);
$aResources = DatabaseModel::select([
'select' => ['count(1) as nb_contacts'],
'table' => ['contacts_res'],
'where' => ['res_id = ?', 'mode = ?'],
'data' => [$aArgs['resId'], 'multi']
]);
return $aResources[0]['nb_contacts'];
}
} }
...@@ -526,94 +526,4 @@ class TemplateController ...@@ -526,94 +526,4 @@ class TemplateController
return $check; return $check;
} }
public static function mergeDatasource(array $aArgs)
{
include_once 'apps/maarch_entreprise/tools/tbs/tbs_class_php5.php';
include_once 'apps/maarch_entreprise/tools/tbs/tbs_plugin_opentbs.php';
$pathToTemplate = $aArgs['pathToAttachment'];
$pathToTemplateInfo = pathinfo($pathToTemplate);
$datasources = TemplateController::getDatas(["id" => 'letterbox_attachment', 'resId' => $aArgs['res_id'], 'contactId' => (int)$aArgs['res_contact_id'], 'addressId' => (int)$aArgs['res_address_id'], 'chronoAttachment' => $aArgs['chronoAttachment']]);
if (in_array($pathToTemplateInfo['extension'], ['odt', 'ods', 'odp', 'xlsx', 'pptx', 'docx', 'odf'])) {
$fileNameOnTmp = 'tmp_file_' . $aArgs['userId'] . '_' . rand() . '.' . $pathToTemplateInfo['extension'];
$tmpPath = CoreConfigModel::getTmpPath();
$myFile = $tmpPath . $fileNameOnTmp;
// Merge with TBS
$TBS = new \clsTinyButStrong;
$TBS->NoErr = true;
//LOAD PLUGIN FOR ODT/DOCX DOCUMENT
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate($pathToTemplate, OPENTBS_ALREADY_UTF8);
foreach ($datasources as $name => $datasource) {
if (!is_array($datasource)) {
$TBS->MergeField($name, $datasource);
} else {
$TBS->MergeBlock($name, 'array', $datasource);
}
}
if ($pathToTemplateInfo['extension'] == 'odt') {
$TBS->LoadTemplate('#styles.xml');
} elseif ($pathToTemplateInfo['extension'] == 'docx') {
// TODO : TEST AFTER REFACTORING of getDatas function
// foreach (['recipient', 'sender', 'attachmentRecipient'] as $contact) {
// if (!empty($dataToBeMerge[$contact]['postal_address'])) {
// $dataToBeMerge[$contact]['postal_address'] = nl2br($dataToBeMerge[$contact]['postal_address']);
// $dataToBeMerge[$contact]['postal_address'] = str_replace('<br />', '</w:t><w:br/><w:t>', $dataToBeMerge[$contact]['postal_address']);
// $dataToBeMerge[$contact]['postal_address'] = str_replace(array("\n\r", "\r\n", "\r", "\n"), "", $dataToBeMerge[$contact]['postal_address']);
// }
// }
$TBS->LoadTemplate('#word/header1.xml');
}
foreach ($datasources as $name => $datasource) {
if (!is_array($datasource)) {
$TBS->MergeField($name, $datasource);
} else {
$TBS->MergeBlock($name, 'array', $datasource);
}
}
if ($pathToTemplateInfo['extension'] == 'docx') {
$TBS->LoadTemplate('#word/footer1.xml');
foreach ($datasources as $name => $datasource) {
if (!is_array($datasource)) {
$TBS->MergeField($name, $datasource);
} else {
$TBS->MergeBlock($name, 'array', $datasource);
}
}
}
$TBS->Show(OPENTBS_FILE, $myFile);
} else {
$myFile = $pathToTemplate;
}
return $myFile;
}
private static function getDatas(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['id']);
$res_id = $aArgs['resId'];
$datasources['datetime'][0]['date'] = date('d-m-Y');
$datasources['datetime'][0]['time'] = date('H:i:s.u');
$datasources['datetime'][0]['timestamp'] = time();
$datasourceScript = TemplateModel::getDatasourceById(["id" => $aArgs['id']]);
$res_contact_id = $aArgs['contactId'];
$res_address_id = $aArgs['addressId'];
$chronoAttachment = $aArgs['chronoAttachment'];
include $datasourceScript['script'];
return $datasources;
}
} }
...@@ -18,13 +18,13 @@ use Respect\Validation\Validator; ...@@ -18,13 +18,13 @@ use Respect\Validation\Validator;
class ValidatorModel class ValidatorModel
{ {
public static function notEmpty(array $aArgs, $aKeys) public static function notEmpty(array $args, $keys)
{ {
if (!Validator::arrayType()->notEmpty()->validate($aArgs)) { if (!Validator::arrayType()->notEmpty()->validate($args)) {
throw new \Exception('First argument must be a non empty array'); throw new \Exception('First argument must be a non empty array');
} }
foreach ($aKeys as $key) { foreach ($keys as $key) {
if (!Validator::notEmpty()->validate($aArgs[$key])) { if (!Validator::notEmpty()->validate($args[$key])) {
throw new \Exception("Argument {$key} is empty"); throw new \Exception("Argument {$key} is empty");
} }
} }
......
...@@ -51,8 +51,8 @@ export class AttachmentPageComponent implements OnInit { ...@@ -51,8 +51,8 @@ export class AttachmentPageComponent implements OnInit {
public appService: AppService, public appService: AppService,
private notify: NotificationService, private notify: NotificationService,
private sortPipe: SortPipe, private sortPipe: SortPipe,
private headerService: HeaderService, public headerService: HeaderService,
private privilegeService: PrivilegeService) { public privilegeService: PrivilegeService) {
} }
ngOnInit(): void { ngOnInit(): void {
......
...@@ -73,5 +73,5 @@ ...@@ -73,5 +73,5 @@
}"></editor> }"></editor>
</mat-dialog-content> </mat-dialog-content>
<div mat-dialog-actions class="actions"> <div mat-dialog-actions class="actions">
<button mat-raised-button color="primary" (click)="onSubmit()">{{lang.validate}}</button> <!-- <button mat-raised-button color="primary" (click)="onSubmit()">{{lang.validate}}</button>-->
</div> </div>
\ No newline at end of file
...@@ -105,7 +105,7 @@ export class DocumentViewerComponent implements OnInit { ...@@ -105,7 +105,7 @@ export class DocumentViewerComponent implements OnInit {
constructor( constructor(
public http: HttpClient, public http: HttpClient,
private notify: NotificationService, private notify: NotificationService,
private headerService: HeaderService, public headerService: HeaderService,
public appService: AppService, public appService: AppService,
private dialog: MatDialog, private dialog: MatDialog,
private sortPipe: SortPipe, private sortPipe: SortPipe,
......
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