diff --git a/rest/index.php b/rest/index.php index 1f5a9b0efad9c1210289cb33c65696fac7ba6626..63619db57a9971e691876dbe436341fbc4d463c5 100755 --- a/rest/index.php +++ b/rest/index.php @@ -86,6 +86,7 @@ $app->get('/connectors/{id}/currentVisa', \ExternalSignatoryBook\controllers\Ext //Customization $app->put('/customization', \Configuration\controllers\ConfigurationController::class . ':updateCustomization'); +$app->get('/customization/watermark', \Configuration\controllers\ConfigurationController::class . ':getWatermarkConfiguration'); //Documents $app->post('/documents', \Document\controllers\DocumentController::class . ':create'); diff --git a/src/app/configuration/controllers/ConfigurationController.php b/src/app/configuration/controllers/ConfigurationController.php index 2d468801b5e6b1ebc97e31eed36085a3a5c8cae8..988cf5d41f5484a4bf981f2cd256cb0e6490917b 100755 --- a/src/app/configuration/controllers/ConfigurationController.php +++ b/src/app/configuration/controllers/ConfigurationController.php @@ -386,21 +386,25 @@ class ConfigurationController $data['applicationUrl'] = $body['applicationUrl'] ?: null; if (!empty($body['watermark'])) { + $possibleAlign = ['left' => 'L', 'center' => 'C', 'right' => 'R']; + if (!Validator::notEmpty()->boolType()->validate($body['watermark']['enabled'])) { return $response->withStatus(400)->withJson(['errors' => 'Body watermark[enabled] is empty or not a boolean']); - } elseif (!Validator::notEmpty()->intVal()->validate($body['watermark']['posX'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body watermark[posX] is empty or not an integer']); } elseif (!Validator::notEmpty()->intVal()->validate($body['watermark']['posY'])) { return $response->withStatus(400)->withJson(['errors' => 'Body watermark[posY] is empty or not an integer']); } elseif (!Validator::notEmpty()->stringType()->validate($body['watermark']['text'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body watermark[label] is empty or not a string']); + return $response->withStatus(400)->withJson(['errors' => 'Body watermark[text] is empty or not a string']); + } elseif (!Validator::notEmpty()->stringType()->validate($body['watermark']['align'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body watermark[align] is empty or not a string']); + } elseif (!in_array($body['watermark']['align'], array_keys($possibleAlign))) { + return $response->withStatus(400)->withJson(['errors' => 'Body watermark[align] can only be "left", "right" or "center"']); } - $data['watermark'] += [ + $data['watermark'] = [ 'enabled' => $body['watermark']['enabled'], - 'posX' => $body['watermark']['posX'], 'posY' => $body['watermark']['posY'], - 'text' => $body['watermark']['text'] + 'text' => $body['watermark']['text'], + 'align' => $possibleAlign[$body['watermark']['align']] ]; } @@ -420,6 +424,21 @@ class ConfigurationController return $response->withStatus(204); } + public function getWatermarkConfiguration(Request $request, Response $response) + { + if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_customization'])) { + return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']); + } + + $configuration = ConfigurationModel::getByIdentifier(['identifier' => 'customization']); + if (empty($configuration[0])) { + return $response->withStatus(400)->withJson(['errors' => 'Configuration does not exist']); + } + $configuration = json_decode($configuration[0]['value'], true); + + return $response->withJson(['configuration' => $configuration['watermark'] ?? []]); + } + private static function checkMailer(array $args) { if (!Validator::stringType()->notEmpty()->validate($args['type'])) { diff --git a/src/app/document/controllers/WatermarkController.php b/src/app/document/controllers/WatermarkController.php index bdbb0497226284dc634b07d13614dd5e265ce6a0..8c8de05acc68a9fc7b45e34b5ff44ed22b29cfba 100644 --- a/src/app/document/controllers/WatermarkController.php +++ b/src/app/document/controllers/WatermarkController.php @@ -77,7 +77,7 @@ class WatermarkController $pdf->SetTextColor(0, 0, 0); // Color black $pdf->SetAlpha(0.5); // Opacity $pdf->Rotate(0); // No rotation - $pdf->Text($watermark['posX'], $watermark['posY'], $text, false, false, true, 0, 0, 'R'); + $pdf->Text(8, $watermark['posY'], $text, false, false, true, 0, 0, $watermark['align']); // Position X = 8 } $fileContent = $pdf->Output('', 'S'); } catch (\Exception $e) {