diff --git a/apps/maarch_entreprise/actions/sendDataWS.php b/apps/maarch_entreprise/actions/sendDataWS.php new file mode 100644 index 0000000000000000000000000000000000000000..6ac0aa0d4716d50a8ec3d0ef42abd06fb53f22c8 --- /dev/null +++ b/apps/maarch_entreprise/actions/sendDataWS.php @@ -0,0 +1,23 @@ +<?php + +$confirm = true; + +$etapes = ['send']; + +function manage_send($aId) +{ + $result = ''; + + foreach ($aId as $resId) { + $document = \Core\Models\ResModel::getById(['resId' => $aId[0], 'select' => ['custom_t1']]); + + $bodyParams = [ + 'custom_t1' => $document['custom_t1'], + ]; + \Core\Models\CurlModel::exec(['curlCallId' => 'sendData', 'bodyData' => $bodyParams]); + + $result .= $resId . '#'; + } + + return ['result' => $result, 'history_msg' => '']; +} diff --git a/apps/maarch_entreprise/actions/sendFileWS.php b/apps/maarch_entreprise/actions/sendFileWS.php new file mode 100644 index 0000000000000000000000000000000000000000..b9e11b9c2629c10b3374e6f992f7778e0e9b8f06 --- /dev/null +++ b/apps/maarch_entreprise/actions/sendFileWS.php @@ -0,0 +1,32 @@ +<?php + +$confirm = true; + +$etapes = ['send']; + +function manage_send($aId) +{ + $result = ''; + + foreach ($aId as $resId) { + $document = \Core\Models\ResModel::getById(['resId' => $resId, 'select' => ['res_id', 'format', 'path', 'filename']]); + $docserver = \Core\Models\DocserverModel::getByCollId(['collId' => 'letterbox_coll', 'priority' => true, 'select' => ['path_template']]); + + $file = file_get_contents($docserver['path_template'] . str_replace('#', '/', $document['path']) . $document['filename']); + $encodedFile = base64_encode($file); + + $bodyParams = [ + 'resId' => $document['res_id'], + 'encodedFile' => $encodedFile, + 'fileFormat' => $document['format'] + ]; + $response = \Core\Models\CurlModel::exec(['curlCallId' => 'sendFile', 'bodyData' => $bodyParams]); + + if (!empty($response['publikId'])) { + \Core\Models\ResModel::update(['res_id' => $document['res_id'], 'data' => ['custom_t1' => $response['publikId']]]); + } + $result .= $resId . '#'; + } + + return ['result' => $result, 'history_msg' => '']; +} diff --git a/apps/maarch_entreprise/lang/en.php b/apps/maarch_entreprise/lang/en.php index 7517b3afb19ff3660582618031b7bdc59eec8972..19586c6619beb9ef61372570ed207e6b0d0b2f3c 100755 --- a/apps/maarch_entreprise/lang/en.php +++ b/apps/maarch_entreprise/lang/en.php @@ -723,6 +723,8 @@ if (!defined("_CHOOSE_ONE_OBJECT")) define("_CHOOSE_ONE_OBJECT", "Choose an elem if (!defined("_CLICK_LINE_TO_CHECK_INVOICE")) define("_CLICK_LINE_TO_CHECK_INVOICE", "Click on a lign to check a bill"); if (!defined("_FOUND_INVOICES")) define("_FOUND_INVOICES", " Found bill(s)"); if (!defined("_SIMPLE_CONFIRM")) define("_SIMPLE_CONFIRM", "Simple confirmation"); +if (!defined("_SEND_FILE_WS")) define("_SEND_FILE_WS", "Send file via Web Service"); +if (!defined("_SEND_DATA_WS")) define("_SEND_DATA_WS", "Send data via Web Service"); if (!defined("_CHECK_INVOICE")) define("_CHECK_INVOICE", "Check bill"); if (!defined("_REDIRECT_TO")) define("_REDIRECT_TO", "Redirected to"); diff --git a/apps/maarch_entreprise/lang/fr.php b/apps/maarch_entreprise/lang/fr.php index a2839a0f8958bf5187ab26fbd335000cd7cc4ac1..aad8f3e39e0fc07ed73b4a4c6d212667bb865088 100755 --- a/apps/maarch_entreprise/lang/fr.php +++ b/apps/maarch_entreprise/lang/fr.php @@ -731,6 +731,8 @@ if (!defined("_CHOOSE_ONE_OBJECT")) define("_CHOOSE_ONE_OBJECT", "Choisissez au if (!defined("_CLICK_LINE_TO_CHECK_INVOICE")) define("_CLICK_LINE_TO_CHECK_INVOICE", "Cliquer sur une ligne pour vérifier une facture"); if (!defined("_FOUND_INVOICES")) define("_FOUND_INVOICES", " facture(s) trouvée(s)"); if (!defined("_SIMPLE_CONFIRM")) define("_SIMPLE_CONFIRM", "Confirmation simple"); +if (!defined("_SEND_FILE_WS")) define("_SEND_FILE_WS", "Envoi du document via Web Service"); +if (!defined("_SEND_DATA_WS")) define("_SEND_DATA_WS", "Envoi de données via Web Service"); if (!defined("_SIMPLE_CONFIRM_DESC")) define("_SIMPLE_CONFIRM_DESC", "Ouvre simplement une modal de confirmation de l'action à effetuer."); if (!defined("_CHECK_INVOICE")) define("_CHECK_INVOICE", "Vérifier facture"); diff --git a/apps/maarch_entreprise/xml/curlCall.xml b/apps/maarch_entreprise/xml/curlCall.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4ffc56fee84cb3b692cda59c1e2490623fca11d --- /dev/null +++ b/apps/maarch_entreprise/xml/curlCall.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<ROOT> + <call> + <id>sendFile</id> + <url></url> + <method>POST</method> + </call> + <call> + <id>sendData</id> + <url></url> + <method>PUT</method> + <data> + <key>publikId</key> + <value>custom_t1</value> + </data> + </call> +</ROOT> diff --git a/core/Models/CurlModel.php b/core/Models/CurlModel.php new file mode 100644 index 0000000000000000000000000000000000000000..607f22e106e4ff833660915a52aa0fc573f7535d --- /dev/null +++ b/core/Models/CurlModel.php @@ -0,0 +1,95 @@ +<?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 Curl Model + * @author dev@maarch.org + * @ingroup core + */ + +namespace Core\Models; + +class CurlModel +{ + public static function exec(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['curlCallId']); + ValidatorModel::stringType($aArgs, ['curlCallId']); + ValidatorModel::arrayType($aArgs, ['bodyData']); + + $curlConfig = CurlModel::getConfigByCallId(['curlCallId' => $aArgs['curlCallId']]); + if (empty($curlConfig)) { + return []; + } + + $opts = [ + CURLOPT_URL => $curlConfig['url'], + CURLOPT_HTTPHEADER => [ + 'accept:application/json', + 'content-type:application/json' + ], + CURLOPT_RETURNTRANSFER => true, + ]; + + if ($curlConfig['method'] == 'POST' || $curlConfig['method'] == 'PUT') { + if (!empty($curlConfig['data'])) { + $data = []; + foreach ($curlConfig['data'] as $key => $value) { + $data[$key] = $aArgs['bodyData'][$value]; + } + $opts[CURLOPT_POSTFIELDS] = json_encode($data); + } else { + $opts[CURLOPT_POSTFIELDS] = json_encode($aArgs['bodyData']); + } + } + if ($curlConfig['method'] == 'POST') { + $opts[CURLOPT_POST] = true; + } elseif ($curlConfig['method'] == 'PUT' || $curlConfig['method'] == 'DELETE') { + $opts[CURLOPT_CUSTOMREQUEST] = $curlConfig['method']; + } + + $curl = curl_init(); + curl_setopt_array($curl, $opts); + $rawResponse = curl_exec($curl); + + return json_decode($rawResponse, true); + } + + public static function getConfigByCallId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['curlCallId']); + ValidatorModel::stringType($aArgs, ['curlCallId']); + + $customId = CoreConfigModel::getCustomId(); + if (file_exists("custom/{$customId}/apps/maarch_entreprise/xml/curlCall.xml")) { + $path = "custom/{$customId}/apps/maarch_entreprise/xml/curlCall.xml"; + } else { + $path = 'apps/maarch_entreprise/xml/curlCall.xml'; + } + + $curlConfig = []; + if (file_exists($path)) { + $loadedXml = simplexml_load_file($path); + foreach ($loadedXml->call as $call) { + if ((string)$call->id == $aArgs['curlCallId']) { + $curlConfig['url'] = (string)$call->url; + $curlConfig['method'] = strtoupper((string)$call->method); + if (!empty($call->data)) { + $curlConfig['data'] = []; + foreach ($call->data as $data) { + $curlConfig['data'][(string)$data->key] = (string)$data->value; + } + } + } + } + } + + return $curlConfig; + } +} diff --git a/core/Models/DocserverModelAbstract.php b/core/Models/DocserverModelAbstract.php index 1cd7708984d2200b627fb16aff2f7faa43ee5442..e175e21e6151529e3cd803382ea6284a680d9f95 100755 --- a/core/Models/DocserverModelAbstract.php +++ b/core/Models/DocserverModelAbstract.php @@ -57,6 +57,30 @@ class DocserverModelAbstract return $aReturn[0]; } + public static function getByCollId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['collId']); + ValidatorModel::stringType($aArgs, ['collId']); + ValidatorModel::boolType($aArgs, ['priority']); + + $data = [ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['docservers'], + 'where' => ['coll_id = ?'], + 'data' => [$aArgs['collId']] + ]; + if (!empty($aArgs['priority'])) { + $data['order_by'] = ['priority_number']; + } + $aReturn = DatabaseModel::select($data); + + if (!empty($aArgs['priority'])) { + return $aReturn[0]; + } + + return $aReturn; + } + public static function create(array $aArgs = []) { ValidatorModel::notEmpty($aArgs, ['docserver_id']); diff --git a/core/xml/actions_pages.xml b/core/xml/actions_pages.xml index d502cb048867f7dcddeda521cd8b236c4eab47eb..c69bf5d1d0ceda13090602f9ec7630ff2b5fdc27 100755 --- a/core/xml/actions_pages.xml +++ b/core/xml/actions_pages.xml @@ -158,6 +158,28 @@ An action page is described in a ACTIONPAGE tag : <COLL_ID>letterbox_coll</COLL_ID> </COLLECTIONS> </ACTIONPAGE> + <ACTIONPAGE> + <ID>sendFileWS</ID> + <LABEL>_SEND_FILE_WS</LABEL> + <NAME>sendFileWS</NAME> + <ORIGIN>apps</ORIGIN> + <MODULE></MODULE> + <FLAG_CREATE>false</FLAG_CREATE> + <COLLECTIONS> + <COLL_ID>letterbox_coll</COLL_ID> + </COLLECTIONS> + </ACTIONPAGE> + <ACTIONPAGE> + <ID>sendDataWS</ID> + <LABEL>_SEND_DATA_WS</LABEL> + <NAME>sendDataWS</NAME> + <ORIGIN>apps</ORIGIN> + <MODULE></MODULE> + <FLAG_CREATE>false</FLAG_CREATE> + <COLLECTIONS> + <COLL_ID>letterbox_coll</COLL_ID> + </COLLECTIONS> + </ACTIONPAGE> <ACTIONPAGE> <ID>confirm_folder_status</ID> <LABEL>_CONFIRM_FOLDER_STATUS</LABEL>