From 05dea33965b086d139aa3e57b8f96343fcac21e3 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 11 Oct 2018 15:35:33 +0200 Subject: [PATCH] Clean Back --- composer.json | 21 +- config/config.xml.default | 104 +-- rest/index.php | 348 ++-------- rest/schema.json | 275 -------- sql/data_fr.sql | 6 - sql/structure.sql | 15 +- .../action/controllers/ActionController.php | 233 ------- src/app/action/models/ActionModel.php | 21 - src/app/action/models/ActionModelAbstract.php | 266 -------- .../basket/controllers/BasketController.php | 537 ---------------- src/app/basket/models/BasketModel.php | 19 - src/app/basket/models/BasketModelAbstract.php | 608 ------------------ src/app/basket/models/GroupBasketModel.php | 26 - .../models/GroupBasketModelAbstract.php | 131 ---- .../contact/controllers/ContactController.php | 383 ----------- .../controllers/ContactGroupController.php | 330 ---------- .../controllers/ContactTypeController.php | 29 - .../contact/models/ContactFillingModel.php | 58 -- src/app/contact/models/ContactGroupModel.php | 19 - .../models/ContactGroupModelAbstract.php | 158 ----- src/app/contact/models/ContactModel.php | 21 - .../contact/models/ContactModelAbstract.php | 505 --------------- src/app/contact/models/ContactTypeModel.php | 19 - .../models/ContactTypeModelAbstract.php | 35 - .../controllers/JnlpController.php | 340 ---------- .../doctype/controllers/DoctypeController.php | 413 ------------ .../controllers/FirstLevelController.php | 294 --------- .../controllers/SecondLevelController.php | 205 ------ src/app/doctype/models/DoctypeExtModel.php | 21 - .../models/DoctypeExtModelAbstract.php | 84 --- .../doctype/models/DoctypeIndexesModel.php | 21 - .../models/DoctypeIndexesModelAbstract.php | 161 ----- src/app/doctype/models/DoctypeModel.php | 21 - .../doctype/models/DoctypeModelAbstract.php | 147 ----- src/app/doctype/models/FirstLevelModel.php | 21 - .../models/FirstLevelModelAbstract.php | 85 --- src/app/doctype/models/SecondLevelModel.php | 21 - .../models/SecondLevelModelAbstract.php | 98 --- .../doctype/models/TemplateDoctypeModel.php | 21 - .../models/TemplateDoctypeModelAbstract.php | 92 --- .../entity/controllers/EntityController.php | 456 ------------- .../controllers/ListInstanceController.php | 71 -- .../controllers/ListTemplateController.php | 396 ------------ src/app/entity/models/EntityModel.php | 19 - src/app/entity/models/EntityModelAbstract.php | 377 ----------- src/app/entity/models/ListInstanceModel.php | 19 - .../models/ListInstanceModelAbstract.php | 191 ------ src/app/entity/models/ListTemplateModel.php | 19 - .../models/ListTemplateModelAbstract.php | 146 ----- src/app/folder/models/FolderTypeModel.php | 21 - .../folder/models/FolderTypeModelAbstract.php | 71 -- src/app/group/controllers/GroupController.php | 265 -------- .../group/controllers/ServiceController.php | 27 - src/app/group/models/GroupModel.php | 19 - src/app/group/models/GroupModelAbstract.php | 366 ----------- src/app/group/models/ServiceModel.php | 19 - src/app/group/models/ServiceModelAbstract.php | 353 ---------- .../controllers/BatchHistoryController.php | 53 -- src/app/history/models/BatchHistoryModel.php | 19 - .../models/BatchHistoryModelAbstract.php | 39 -- src/app/home/controllers/HomeController.php | 111 ---- src/app/link/controllers/LinkController.php | 36 -- src/app/link/models/LinkModel.php | 21 - src/app/link/models/LinkModelAbstract.php | 36 -- src/app/note/controllers/NoteController.php | 36 -- src/app/note/models/NoteModel.php | 19 - src/app/note/models/NoteModelAbstract.php | 133 ---- .../controllers/NotificationController.php | 319 --------- .../NotificationScheduleController.php | 162 ----- .../NotificationsEventsController.php | 56 -- .../notification/models/NotificationModel.php | 21 - .../models/NotificationModelAbstract.php | 263 -------- .../models/NotificationScheduleModel.php | 21 - .../NotificationScheduleModelAbstract.php | 191 ------ .../models/NotificationsEventsModel.php | 21 - .../NotificationsEventsModelAbstract.php | 37 -- .../controllers/ParameterController.php | 152 ----- src/app/parameter/models/ParameterModel.php | 22 - .../models/ParameterModelAbstract.php | 112 ---- .../controllers/PriorityController.php | 176 ----- src/app/priority/models/PriorityModel.php | 19 - .../priority/models/PriorityModelAbstract.php | 151 ----- .../report/controllers/ReportController.php | 98 --- src/app/report/models/ReportModel.php | 19 - src/app/report/models/ReportModelAbstract.php | 98 --- src/app/resource/models/ChronoModel.php | 168 ----- .../controllers/TemplateController.php | 442 ------------- .../models/TemplateAssociationModel.php | 19 - .../TemplateAssociationModelAbstract.php | 84 --- src/app/template/models/TemplateModel.php | 19 - .../template/models/TemplateModelAbstract.php | 215 ------- src/app/user/controllers/UserController.php | 28 +- .../user/models/UserBasketPreferenceModel.php | 19 - .../UserBasketPreferenceModelAbstract.php | 85 --- src/app/user/models/UserEntityModel.php | 19 - .../user/models/UserEntityModelAbstract.php | 205 ------ src/app/user/models/UserModelAbstract.php | 388 ----------- .../controllers/VersionUpdateController.php | 73 --- .../controllers/AuthenticationController.php | 75 --- .../controllers/AutoCompleteController.php | 390 ----------- src/core/controllers/CoreController.php | 113 ---- src/core/controllers/LogsController.php | 186 ------ src/core/controllers/PasswordController.php | 103 --- src/core/lang/lang-en.php | 405 +----------- src/core/lang/lang-fr.php | 405 +----------- src/core/models/AuthenticationModel.php | 55 +- src/core/models/CoreConfigModel.php | 131 +--- src/core/models/DatabasePDO.php | 31 +- src/core/models/PasswordModel.php | 153 ----- vendor/composer/ClassLoader.php | 10 +- vendor/composer/LICENSE | 2 +- vendor/composer/autoload_psr4.php | 18 +- vendor/composer/autoload_static.php | 104 +-- 113 files changed, 129 insertions(+), 15304 deletions(-) delete mode 100755 rest/schema.json delete mode 100644 src/app/action/controllers/ActionController.php delete mode 100644 src/app/action/models/ActionModel.php delete mode 100644 src/app/action/models/ActionModelAbstract.php delete mode 100644 src/app/basket/controllers/BasketController.php delete mode 100644 src/app/basket/models/BasketModel.php delete mode 100644 src/app/basket/models/BasketModelAbstract.php delete mode 100644 src/app/basket/models/GroupBasketModel.php delete mode 100644 src/app/basket/models/GroupBasketModelAbstract.php delete mode 100644 src/app/contact/controllers/ContactController.php delete mode 100644 src/app/contact/controllers/ContactGroupController.php delete mode 100644 src/app/contact/controllers/ContactTypeController.php delete mode 100644 src/app/contact/models/ContactFillingModel.php delete mode 100644 src/app/contact/models/ContactGroupModel.php delete mode 100644 src/app/contact/models/ContactGroupModelAbstract.php delete mode 100644 src/app/contact/models/ContactModel.php delete mode 100644 src/app/contact/models/ContactModelAbstract.php delete mode 100644 src/app/contact/models/ContactTypeModel.php delete mode 100644 src/app/contact/models/ContactTypeModelAbstract.php delete mode 100644 src/app/contentManagement/controllers/JnlpController.php delete mode 100644 src/app/doctype/controllers/DoctypeController.php delete mode 100644 src/app/doctype/controllers/FirstLevelController.php delete mode 100644 src/app/doctype/controllers/SecondLevelController.php delete mode 100644 src/app/doctype/models/DoctypeExtModel.php delete mode 100644 src/app/doctype/models/DoctypeExtModelAbstract.php delete mode 100644 src/app/doctype/models/DoctypeIndexesModel.php delete mode 100644 src/app/doctype/models/DoctypeIndexesModelAbstract.php delete mode 100644 src/app/doctype/models/DoctypeModel.php delete mode 100644 src/app/doctype/models/DoctypeModelAbstract.php delete mode 100644 src/app/doctype/models/FirstLevelModel.php delete mode 100644 src/app/doctype/models/FirstLevelModelAbstract.php delete mode 100644 src/app/doctype/models/SecondLevelModel.php delete mode 100644 src/app/doctype/models/SecondLevelModelAbstract.php delete mode 100644 src/app/doctype/models/TemplateDoctypeModel.php delete mode 100644 src/app/doctype/models/TemplateDoctypeModelAbstract.php delete mode 100644 src/app/entity/controllers/EntityController.php delete mode 100644 src/app/entity/controllers/ListInstanceController.php delete mode 100644 src/app/entity/controllers/ListTemplateController.php delete mode 100644 src/app/entity/models/EntityModel.php delete mode 100644 src/app/entity/models/EntityModelAbstract.php delete mode 100644 src/app/entity/models/ListInstanceModel.php delete mode 100644 src/app/entity/models/ListInstanceModelAbstract.php delete mode 100644 src/app/entity/models/ListTemplateModel.php delete mode 100644 src/app/entity/models/ListTemplateModelAbstract.php delete mode 100644 src/app/folder/models/FolderTypeModel.php delete mode 100644 src/app/folder/models/FolderTypeModelAbstract.php delete mode 100644 src/app/group/controllers/GroupController.php delete mode 100644 src/app/group/controllers/ServiceController.php delete mode 100644 src/app/group/models/GroupModel.php delete mode 100644 src/app/group/models/GroupModelAbstract.php delete mode 100644 src/app/group/models/ServiceModel.php delete mode 100755 src/app/group/models/ServiceModelAbstract.php delete mode 100644 src/app/history/controllers/BatchHistoryController.php delete mode 100644 src/app/history/models/BatchHistoryModel.php delete mode 100644 src/app/history/models/BatchHistoryModelAbstract.php delete mode 100644 src/app/home/controllers/HomeController.php delete mode 100644 src/app/link/controllers/LinkController.php delete mode 100644 src/app/link/models/LinkModel.php delete mode 100644 src/app/link/models/LinkModelAbstract.php delete mode 100644 src/app/note/controllers/NoteController.php delete mode 100644 src/app/note/models/NoteModel.php delete mode 100644 src/app/note/models/NoteModelAbstract.php delete mode 100644 src/app/notification/controllers/NotificationController.php delete mode 100644 src/app/notification/controllers/NotificationScheduleController.php delete mode 100644 src/app/notification/controllers/NotificationsEventsController.php delete mode 100644 src/app/notification/models/NotificationModel.php delete mode 100644 src/app/notification/models/NotificationModelAbstract.php delete mode 100644 src/app/notification/models/NotificationScheduleModel.php delete mode 100644 src/app/notification/models/NotificationScheduleModelAbstract.php delete mode 100644 src/app/notification/models/NotificationsEventsModel.php delete mode 100644 src/app/notification/models/NotificationsEventsModelAbstract.php delete mode 100644 src/app/parameter/controllers/ParameterController.php delete mode 100644 src/app/parameter/models/ParameterModel.php delete mode 100644 src/app/parameter/models/ParameterModelAbstract.php delete mode 100644 src/app/priority/controllers/PriorityController.php delete mode 100644 src/app/priority/models/PriorityModel.php delete mode 100644 src/app/priority/models/PriorityModelAbstract.php delete mode 100644 src/app/report/controllers/ReportController.php delete mode 100644 src/app/report/models/ReportModel.php delete mode 100644 src/app/report/models/ReportModelAbstract.php delete mode 100644 src/app/resource/models/ChronoModel.php delete mode 100644 src/app/template/controllers/TemplateController.php delete mode 100644 src/app/template/models/TemplateAssociationModel.php delete mode 100644 src/app/template/models/TemplateAssociationModelAbstract.php delete mode 100644 src/app/template/models/TemplateModel.php delete mode 100644 src/app/template/models/TemplateModelAbstract.php delete mode 100644 src/app/user/models/UserBasketPreferenceModel.php delete mode 100644 src/app/user/models/UserBasketPreferenceModelAbstract.php delete mode 100644 src/app/user/models/UserEntityModel.php delete mode 100644 src/app/user/models/UserEntityModelAbstract.php delete mode 100644 src/app/versionUpdate/controllers/VersionUpdateController.php delete mode 100644 src/core/controllers/AutoCompleteController.php delete mode 100644 src/core/controllers/CoreController.php delete mode 100644 src/core/controllers/LogsController.php delete mode 100644 src/core/controllers/PasswordController.php delete mode 100644 src/core/models/PasswordModel.php diff --git a/composer.json b/composer.json index 403b1a64cd..f816571b3c 100755 --- a/composer.json +++ b/composer.json @@ -2,32 +2,15 @@ "autoload": { "psr-4": { "SrcCore\\" : "src/core/", - "Action\\" : "src/app/action/", "Attachment\\" : "src/app/attachment/", - "Basket\\" : "src/app/basket/", - "Contact\\" : "src/app/contact/", - "ContentManagement\\" : "src/app/contentManagement/", "Convert\\" : "src/app/convert/", "Docserver\\" : "src/app/docserver/", - "Doctype\\" : "src/app/doctype/", - "Entity\\" : "src/app/entity/", - "Folder\\" : "src/app/folder/", - "Group\\" : "src/app/group/", + "Document\\" : "src/app/document/", "History\\" : "src/app/history/", - "Home\\" : "src/app/home/", - "Link\\" : "src/app/link/", - "Note\\" : "src/app/note/", - "Notification\\" : "src/app/notification/", - "Parameter\\" : "src/app/parameter/", - "Priority\\" : "src/app/priority/", - "Report\\" : "src/app/report/", "Resource\\" : "src/app/resource/", "SignatureBook\\" : "src/app/signatureBook/", "Status\\" : "src/app/status/", - "Template\\" : "src/app/template/", - "User\\" : "src/app/user/", - "VersionUpdate\\" : "src/app/versionUpdate/" - + "User\\" : "src/app/user/" } }, "require": { diff --git a/config/config.xml.default b/config/config.xml.default index 14bce51163..0507aac820 100755 --- a/config/config.xml.default +++ b/config/config.xml.default @@ -1,99 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <ROOT> - <CONFIG> - <databaseserver>localhost</databaseserver> - <databaseserverport>5432</databaseserverport> - <databasetype>POSTGRESQL</databasetype> - <databasename>maarch</databasename> - <databaseuser>maarch</databaseuser> - <databasepassword>maarch</databasepassword> - <databasesearchlimit>500</databasesearchlimit> + <config> <lang>fr</lang> - <adminmail>dev@maarch.org</adminmail> - <adminname>maarch</adminname> - <debug>false</debug> - <applicationname>MAARCH 18.04</applicationname> - <exportdirectory/> + <name>Maarch Parapheur</name> <CookieTime>20</CookieTime> <!-- minutes --> <timezone>Europe/Paris</timezone> - <userdefaultpassword>maarch</userdefaultpassword> <!-- default user's password --> - </CONFIG> - <WORKBATCH> - <size>100</size> - </WORKBATCH> - <COLLECTION> - <id>letterbox_coll</id> - <label>_LETTERBOX</label> - <table>res_letterbox</table> - <view>res_view_letterbox</view> - <adr>adr_letterbox</adr> - <index_file>index_letterbox.xml</index_file> - <script_add>index_letterbox.php</script_add> - <script_search>search_letterbox.php</script_search> - <script_search_result>list_results_letterbox.php</script_search_result> - <script_details>details.php</script_details> - <extensions> - <table>mlb_coll_ext</table> - </extensions> - <path_to_lucene_index>/var/docservers/indexes/letterbox_coll/</path_to_lucene_index> - <categories> - <category> - <id>incoming</id> - <label>_INCOMING</label> - </category> - <category> - <id>outgoing</id> - <label>_OUTGOING</label> - </category> - <category> - <id>internal</id> - <label>_INTERNAL</label> - </category> - <category> - <id>ged_doc</id> - <label>_GED_DOC</label> - </category> - <category> - <id>attachment</id> - <label>_ATTACHMENT</label> - </category> - <default_category>incoming</default_category> - </categories> - </COLLECTION> - <KEYWORDS> - <id>ERR</id> - <label>_ERR</label> - </KEYWORDS> - <KEYWORDS> - <id>VIEW</id> - <label>_VIEW</label> - </KEYWORDS> - <KEYWORDS> - <id>ADD</id> - <label>_ADDITION</label> - </KEYWORDS> - <KEYWORDS> - <id>UP</id> - <label>_MODIFICATION</label> - </KEYWORDS> - <KEYWORDS> - <id>DEL</id> - <label>_DELETION</label> - </KEYWORDS> - <KEYWORDS> - <id>BAN</id> - <label>_SUSPENSION</label> - </KEYWORDS> - <KEYWORDS> - <id>VAL</id> - <label>_VALIDATION</label> - </KEYWORDS> - <KEYWORDS> - <id>LOGIN</id> - <label>_LOGIN</label> - </KEYWORDS> - <KEYWORDS> - <id>LOGOUT</id> - <label>_LOGOUT</label> - </KEYWORDS> + </config> + <database> + <server>localhost</server> + <port>5432</port> + <type>POSTGRESQL</type> + <name>maarch</name> + <user>maarch</user> + <password>maarch</password> + </database> </ROOT> diff --git a/rest/index.php b/rest/index.php index 8612f833a4..8904de7769 100755 --- a/rest/index.php +++ b/rest/index.php @@ -18,11 +18,7 @@ require '../vendor/autoload.php'; chdir('..'); date_default_timezone_set(\SrcCore\models\CoreConfigModel::getTimezone()); -$customId = \SrcCore\models\CoreConfigModel::getCustomId(); $language = \SrcCore\models\CoreConfigModel::getLanguage(); -if (file_exists("custom/{$customId}/src/core/lang/lang-{$language}.php")) { - require_once("custom/{$customId}/src/core/lang/lang-{$language}.php"); -} require_once("src/core/lang/lang-{$language}.php"); @@ -34,14 +30,6 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, if (!empty($userId)) { $GLOBALS['userId'] = $userId; - $route = $request->getAttribute('route'); - if (!empty($route)) { - $currentRoute = $route->getPattern(); - $r = \SrcCore\controllers\AuthenticationController::isRouteAvailable(['userId' => $userId, 'currentRoute' => $currentRoute]); - if (!$r['isRouteAvailable']) { - return $response->withStatus(405)->withJson(['errors' => $r['errors']]); - } - } $response = $next($request, $response); return $response; } else { @@ -50,275 +38,71 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, }); -//Initialize -$app->get('/initialize', \SrcCore\controllers\CoreController::class . ':initialize'); - -//Actions -$app->get('/actions', \Action\controllers\ActionController::class . ':get'); -$app->get('/initAction', \Action\controllers\ActionController::class . ':initAction'); -$app->get('/actions/{id}', \Action\controllers\ActionController::class . ':getById'); -$app->post('/actions', \Action\controllers\ActionController::class . ':create'); -$app->put('/actions/{id}', \Action\controllers\ActionController::class . ':update'); -$app->delete('/actions/{id}', \Action\controllers\ActionController::class . ':delete'); - -//Administration -$app->get('/administration', \SrcCore\controllers\CoreController::class . ':getAdministration'); - -//AutoComplete -$app->get('/autocomplete/contacts', \SrcCore\controllers\AutoCompleteController::class . ':getContacts'); -$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers'); -$app->get('/autocomplete/users/administration', \SrcCore\controllers\AutoCompleteController::class . ':getUsersForAdministration'); -$app->get('/autocomplete/users/visa', \SrcCore\controllers\AutoCompleteController::class . ':getUsersForVisa'); -$app->get('/autocomplete/entities', \SrcCore\controllers\AutoCompleteController::class . ':getEntities'); -$app->get('/autocomplete/statuses', \SrcCore\controllers\AutoCompleteController::class . ':getStatuses'); -$app->get('/autocomplete/banAddresses', \SrcCore\controllers\AutoCompleteController::class . ':getBanAddresses'); - -//Baskets -$app->get('/baskets', \Basket\controllers\BasketController::class . ':get'); -$app->post('/baskets', \Basket\controllers\BasketController::class . ':create'); -$app->get('/baskets/{id}', \Basket\controllers\BasketController::class . ':getById'); -$app->put('/baskets/{id}', \Basket\controllers\BasketController::class . ':update'); -$app->delete('/baskets/{id}', \Basket\controllers\BasketController::class . ':delete'); -$app->get('/baskets/{id}/groups', \Basket\controllers\BasketController::class . ':getGroups'); -$app->post('/baskets/{id}/groups', \Basket\controllers\BasketController::class . ':createGroup'); -$app->put('/baskets/{id}/groups/{groupId}', \Basket\controllers\BasketController::class . ':updateGroup'); -$app->delete('/baskets/{id}/groups/{groupId}', \Basket\controllers\BasketController::class . ':deleteGroup'); -$app->get('/baskets/{id}/groups/data', \Basket\controllers\BasketController::class . ':getDataForGroupById'); -$app->get('/sortedBaskets', \Basket\controllers\BasketController::class . ':getSorted'); -$app->put('/sortedBaskets/{id}', \Basket\controllers\BasketController::class . ':updateSort'); - -//BatchHistories -$app->get('/batchHistories', \History\controllers\BatchHistoryController::class . ':get'); - -//Contacts -$app->post('/contacts', \Contact\controllers\ContactController::class . ':create'); -$app->put('/contacts/{id}', \Contact\controllers\ContactController::class . ':update'); -$app->post('/contacts/{id}/addresses', \Contact\controllers\ContactController::class . ':createAddress'); -$app->put('/contacts/{id}/addresses/{addressId}', \Contact\controllers\ContactController::class . ':updateAddress'); -$app->get('/contacts/{contactId}/communication', \Contact\controllers\ContactController::class . ':getCommunicationByContactId'); -$app->get('/contactsGroups', \Contact\controllers\ContactGroupController::class . ':get'); -$app->post('/contactsGroups', \Contact\controllers\ContactGroupController::class . ':create'); -$app->get('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':getById'); -$app->put('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':update'); -$app->delete('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':delete'); -$app->post('/contactsGroups/{id}/contacts', \Contact\controllers\ContactGroupController::class . ':addContacts'); -$app->delete('/contactsGroups/{id}/contacts/{addressId}', \Contact\controllers\ContactGroupController::class . ':deleteContact'); -$app->get('/contactsTypes', \Contact\controllers\ContactTypeController::class . ':get'); -$app->get('/contactsFilling', \Contact\controllers\ContactController::class . ':getFilling'); -$app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling'); - -//Docservers -$app->get('/docservers', \Docserver\controllers\DocserverController::class . ':get'); -$app->post('/docservers', \Docserver\controllers\DocserverController::class . ':create'); -$app->get('/docservers/{id}', \Docserver\controllers\DocserverController::class . ':getById'); -$app->put('/docservers/{id}', \Docserver\controllers\DocserverController::class . ':update'); -$app->delete('/docservers/{id}', \Docserver\controllers\DocserverController::class . ':delete'); - -//DocserverTypes -$app->get('/docserverTypes', \Docserver\controllers\DocserverTypeController::class . ':get'); -$app->get('/docserverTypes/{id}', \Docserver\controllers\DocserverTypeController::class . ':getById'); - -//doctypes -$app->get('/doctypes', \Doctype\controllers\FirstLevelController::class . ':getTree'); -$app->post('/doctypes/firstLevel', \Doctype\controllers\FirstLevelController::class . ':create'); -$app->get('/doctypes/firstLevel/{id}', \Doctype\controllers\FirstLevelController::class . ':getById'); -$app->put('/doctypes/firstLevel/{id}', \Doctype\controllers\FirstLevelController::class . ':update'); -$app->delete('/doctypes/firstLevel/{id}', \Doctype\controllers\FirstLevelController::class . ':delete'); -$app->post('/doctypes/secondLevel', \Doctype\controllers\SecondLevelController::class . ':create'); -$app->get('/doctypes/secondLevel/{id}', \Doctype\controllers\SecondLevelController::class . ':getById'); -$app->put('/doctypes/secondLevel/{id}', \Doctype\controllers\SecondLevelController::class . ':update'); -$app->delete('/doctypes/secondLevel/{id}', \Doctype\controllers\SecondLevelController::class . ':delete'); -$app->get('/doctypes/types', \Doctype\controllers\DoctypeController::class . ':get'); -$app->post('/doctypes/types', \Doctype\controllers\DoctypeController::class . ':create'); -$app->get('/doctypes/types/{id}', \Doctype\controllers\DoctypeController::class . ':getById'); -$app->put('/doctypes/types/{id}', \Doctype\controllers\DoctypeController::class . ':update'); -$app->delete('/doctypes/types/{id}', \Doctype\controllers\DoctypeController::class . ':delete'); -$app->put('/doctypes/types/{id}/redirect', \Doctype\controllers\DoctypeController::class . ':deleteRedirect'); -$app->get('/administration/doctypes/new', \Doctype\controllers\FirstLevelController::class . ':initDoctypes'); - -//Entities -$app->get('/entities', \Entity\controllers\EntityController::class . ':get'); -$app->post('/entities', \Entity\controllers\EntityController::class . ':create'); -$app->get('/entities/{id}', \Entity\controllers\EntityController::class . ':getById'); -$app->put('/entities/{id}', \Entity\controllers\EntityController::class . ':update'); -$app->delete('/entities/{id}', \Entity\controllers\EntityController::class . ':delete'); -$app->get('/entities/{id}/details', \Entity\controllers\EntityController::class . ':getDetailledById'); -$app->put('/entities/{id}/reassign/{newEntityId}', \Entity\controllers\EntityController::class . ':reassignEntity'); -$app->put('/entities/{id}/status', \Entity\controllers\EntityController::class . ':updateStatus'); -$app->get('/entityTypes', \Entity\controllers\EntityController::class . ':getTypes'); - -//Groups -$app->get('/groups', \Group\controllers\GroupController::class . ':get'); -$app->post('/groups', \Group\controllers\GroupController::class . ':create'); -$app->get('/groups/{id}', \Group\controllers\GroupController::class . ':getById'); -$app->put('/groups/{id}', \Group\controllers\GroupController::class . ':update'); -$app->delete('/groups/{id}', \Group\controllers\GroupController::class . ':delete'); -$app->get('/groups/{id}/details', \Group\controllers\GroupController::class . ':getDetailledById'); -$app->put('/groups/{id}/services/{serviceId}', \Group\controllers\GroupController::class . ':updateService'); -$app->put('/groups/{id}/reassign/{newGroupId}', \Group\controllers\GroupController::class . ':reassignUsers'); - -//Histories -$app->get('/histories', \History\controllers\HistoryController::class . ':get'); -$app->get('/histories/users/{userSerialId}', \History\controllers\HistoryController::class . ':getByUserId'); - -//Header -$app->get('/header', \SrcCore\controllers\CoreController::class . ':getHeader'); - -//Home -$app->get('/home', \Home\controllers\HomeController::class . ':get'); -$app->get('/home/lastRessources', \Home\controllers\HomeController::class . ':getLastRessources'); - -//Jnlp -$app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp'); -$app->get('/jnlp', \ContentManagement\controllers\JnlpController::class . ':renderJnlp'); -$app->post('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp'); -$app->get('/jnlp/lock/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':isLockFileExisting'); - -//Links -$app->get('/links/resId/{resId}', \Link\controllers\LinkController::class . ':getByResId'); - -//Listinstance -$app->get('/listinstance/{id}', \Entity\controllers\ListInstanceController::class . ':getById'); -$app->get('/res/{resId}/listinstance', \Entity\controllers\ListInstanceController::class . ':getListByResId'); -$app->get('/res/{resId}/visaCircuit', \Entity\controllers\ListInstanceController::class . ':getVisaCircuitByResId'); -$app->get('/res/{resId}/avisCircuit', \Entity\controllers\ListInstanceController::class . ':getAvisCircuitByResId'); - -//ListTemplates -$app->get('/listTemplates', \Entity\controllers\ListTemplateController::class . ':get'); -$app->post('/listTemplates', \Entity\controllers\ListTemplateController::class . ':create'); -$app->get('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':getById'); -$app->put('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':update'); -$app->delete('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':delete'); -$app->get('/listTemplates/entityDest/itemId/{itemId}', \Entity\controllers\ListTemplateController::class . ':getByUserWithEntityDest'); -$app->put('/listTemplates/entityDest/itemId/{itemId}', \Entity\controllers\ListTemplateController::class . ':updateByUserWithEntityDest'); -$app->get('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':getTypeRoles'); -$app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':updateTypeRoles'); - -//Notes -$app->get('/res/{resId}/notes', \Note\controllers\NoteController::class . ':getByResId'); - -//Parameters -$app->get('/parameters', \Parameter\controllers\ParameterController::class . ':get'); -$app->post('/parameters', \Parameter\controllers\ParameterController::class . ':create'); -$app->get('/parameters/{id}', \Parameter\controllers\ParameterController::class . ':getById'); -$app->put('/parameters/{id}', \Parameter\controllers\ParameterController::class . ':update'); -$app->delete('/parameters/{id}', \Parameter\controllers\ParameterController::class . ':delete'); - -//PasswordRules -$app->get('/passwordRules', \SrcCore\controllers\PasswordController::class . ':getRules'); -$app->put('/passwordRules', \SrcCore\controllers\PasswordController::class . ':updateRules'); - -//Priorities -$app->get('/priorities', \Priority\controllers\PriorityController::class . ':get'); -$app->post('/priorities', \Priority\controllers\PriorityController::class . ':create'); -$app->get('/priorities/{id}', \Priority\controllers\PriorityController::class . ':getById'); -$app->put('/priorities/{id}', \Priority\controllers\PriorityController::class . ':update'); -$app->delete('/priorities/{id}', \Priority\controllers\PriorityController::class . ':delete'); -$app->get('/sortedPriorities', \Priority\controllers\PriorityController::class . ':getSorted'); -$app->put('/sortedPriorities', \Priority\controllers\PriorityController::class . ':updateSort'); - -//Reports -$app->get('/reports/groups', \Report\controllers\ReportController::class . ':getGroups'); -$app->get('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':getByGroupId'); -$app->put('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':updateForGroupId'); - -//Ressources -$app->post('/res', \Resource\controllers\ResController::class . ':create'); -$app->post('/resExt', \Resource\controllers\ResController::class . ':createExt'); -$app->get('/res/{resId}/content', \Resource\controllers\ResController::class . ':getFileContent'); -$app->get('/res/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent'); -$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus'); -$app->post('/res/list', \Resource\controllers\ResController::class . ':getList'); -$app->get('/res/{resId}/lock', \Resource\controllers\ResController::class . ':isLock'); -$app->get('/res/{resId}/notes/count', \Resource\controllers\ResController::class . ':getNotesCountForCurrentUserById'); -$app->put('/res/externalInfos', \Resource\controllers\ResController::class . ':updateExternalInfos'); -$app->get('/categories', \Resource\controllers\ResController::class . ':getCategories'); -$app->get('/natures', \Resource\controllers\ResController::class . ':getNatures'); -$app->get('/resources/groups/{groupSerialId}/baskets/{basketId}', \Resource\controllers\ResController::class . ':getResourcesByBasket'); - -//Attachments -$app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create'); -$app->get('/res/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getAttachmentsListById'); -$app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent'); -$app->get('/res/{resIdMaster}/attachments/{resId}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent'); - -//SignatureBook -$app->get('/{basketId}/signatureBook/resList', \SignatureBook\controllers\SignatureBookController::class . ':getResList'); -$app->get('/{basketId}/signatureBook/resList/details', \SignatureBook\controllers\SignatureBookController::class . ':getDetailledResList'); -$app->get('/groups/{groupId}/baskets/{basketId}/signatureBook/{resId}', \SignatureBook\controllers\SignatureBookController::class . ':getSignatureBook'); -$app->get('/signatureBook/{resId}/attachments', \SignatureBook\controllers\SignatureBookController::class . ':getAttachmentsById'); -$app->get('/signatureBook/{resId}/incomingMailAttachments', \SignatureBook\controllers\SignatureBookController::class . ':getIncomingMailAndAttachmentsById'); -$app->put('/signatureBook/{resId}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignFile'); -$app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); - -//statuses -$app->get('/statuses', \Status\controllers\StatusController::class . ':get'); -$app->post('/statuses', \Status\controllers\StatusController::class . ':create'); -$app->get('/statuses/{identifier}', \Status\controllers\StatusController::class . ':getByIdentifier'); -$app->get('/status/{id}', \Status\controllers\StatusController::class . ':getById'); -$app->put('/statuses/{identifier}', \Status\controllers\StatusController::class . ':update'); -$app->delete('/statuses/{identifier}', \Status\controllers\StatusController::class . ':delete'); -$app->get('/administration/statuses/new', \Status\controllers\StatusController::class . ':getNewInformations'); - -//Templates -$app->get('/templates', \Template\controllers\TemplateController::class . ':get'); -$app->post('/templates', \Template\controllers\TemplateController::class . ':create'); -$app->get('/templates/{id}/details', \Template\controllers\TemplateController::class . ':getDetailledById'); -$app->put('/templates/{id}', \Template\controllers\TemplateController::class . ':update'); -$app->delete('/templates/{id}', \Template\controllers\TemplateController::class . ':delete'); -$app->post('/templates/{id}/duplicate', \Template\controllers\TemplateController::class . ':duplicate'); -$app->get('/administration/templates/new', \Template\controllers\TemplateController::class . ':initTemplates'); - -//Users -$app->get('/users', \User\controllers\UserController::class . ':get'); -$app->post('/users', \User\controllers\UserController::class . ':create'); -$app->get('/users/{id}/details', \User\controllers\UserController::class . ':getDetailledById'); -$app->put('/users/{id}', \User\controllers\UserController::class . ':update'); -$app->put('/users/{id}/password', \User\controllers\UserController::class . ':resetPassword'); -$app->get('/users/{userId}/status', \User\controllers\UserController::class . ':getStatusByUserId'); -$app->put('/users/{id}/status', \User\controllers\UserController::class . ':updateStatus'); -$app->delete('/users/{id}', \User\controllers\UserController::class . ':delete'); -$app->post('/users/{id}/groups', \User\controllers\UserController::class . ':addGroup'); -$app->put('/users/{id}/groups/{groupId}', \User\controllers\UserController::class . ':updateGroup'); -$app->delete('/users/{id}/groups/{groupId}', \User\controllers\UserController::class . ':deleteGroup'); -$app->post('/users/{id}/entities', \User\controllers\UserController::class . ':addEntity'); -$app->put('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':updateEntity'); -$app->put('/users/{id}/entities/{entityId}/primaryEntity', \User\controllers\UserController::class . ':updatePrimaryEntity'); -$app->get('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':isEntityDeletable'); -$app->delete('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':deleteEntity'); -$app->post('/users/{id}/signatures', \User\controllers\UserController::class . ':addSignature'); -$app->get('/users/{id}/signatures/{signatureId}/content', \User\controllers\UserController::class . ':getImageContent'); -$app->put('/users/{id}/signatures/{signatureId}', \User\controllers\UserController::class . ':updateSignature'); -$app->delete('/users/{id}/signatures/{signatureId}', \User\controllers\UserController::class . ':deleteSignature'); -$app->post('/users/{id}/redirectedBaskets', \User\controllers\UserController::class . ':setRedirectedBaskets'); -$app->delete('/users/{id}/redirectedBaskets/{basketId}', \User\controllers\UserController::class . ':deleteRedirectedBaskets'); -$app->put('/users/{id}/baskets', \User\controllers\UserController::class . ':updateBasketsDisplay'); - -//VersionsUpdate -$app->get('/versionsUpdate', \VersionUpdate\controllers\VersionUpdateController::class . ':get'); - -//CurrentUser -$app->get('/currentUser/profile', \User\controllers\UserController::class . ':getProfile'); -$app->put('/currentUser/profile', \User\controllers\UserController::class . ':updateProfile'); -$app->put('/currentUser/password', \User\controllers\UserController::class . ':updateCurrentUserPassword'); -$app->post('/currentUser/emailSignature', \User\controllers\UserController::class . ':createCurrentUserEmailSignature'); -$app->put('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':updateCurrentUserEmailSignature'); -$app->delete('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':deleteCurrentUserEmailSignature'); -$app->put('/currentUser/groups/{groupId}/baskets/{basketId}', \User\controllers\UserController::class . ':updateCurrentUserBasketPreferences'); - -//Notifications -$app->get('/notifications', \Notification\controllers\NotificationController::class . ':get'); -$app->post('/notifications', \Notification\controllers\NotificationController::class . ':create'); -$app->get('/notifications/schedule', \Notification\controllers\NotificationScheduleController::class . ':get'); -$app->post('/notifications/schedule', \Notification\controllers\NotificationScheduleController::class . ':create'); -$app->put('/notifications/{id}', \Notification\controllers\NotificationController::class . ':update'); -$app->delete('/notifications/{id}', \Notification\controllers\NotificationController::class . ':delete'); -$app->get('/administration/notifications/new', \Notification\controllers\NotificationController::class . ':initNotification'); -$app->get('/notifications/{id}', \Notification\controllers\NotificationController::class . ':getBySid'); -$app->post('/scriptNotification', \Notification\controllers\NotificationScheduleController::class . ':createScriptNotification'); - -$app->post('/saveNumericPackage', \Sendmail\Controllers\ReceiveMessageExchangeController::class . ':saveMessageExchange'); -$app->post('/saveMessageExchangeReturn', \Sendmail\Controllers\ReceiveMessageExchangeController::class . ':saveMessageExchangeReturn'); -$app->post('/saveMessageExchangeReview', \Sendmail\Controllers\MessageExchangeReviewController::class . ':saveMessageExchangeReview'); +//Documents +$app->get('/documents', \Document\controllers\DocumentController::class . ':get'); + + +////Ressources +//$app->post('/res', \Resource\controllers\ResController::class . ':create'); +//$app->post('/resExt', \Resource\controllers\ResController::class . ':createExt'); +//$app->get('/res/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent'); +//$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus'); +//$app->post('/res/list', \Resource\controllers\ResController::class . ':getList'); +//$app->get('/res/{resId}/lock', \Resource\controllers\ResController::class . ':isLock'); +//$app->get('/res/{resId}/notes/count', \Resource\controllers\ResController::class . ':getNotesCountForCurrentUserById'); +//$app->put('/res/externalInfos', \Resource\controllers\ResController::class . ':updateExternalInfos'); +//$app->get('/categories', \Resource\controllers\ResController::class . ':getCategories'); +//$app->get('/natures', \Resource\controllers\ResController::class . ':getNatures'); +//$app->get('/resources/groups/{groupSerialId}/baskets/{basketId}', \Resource\controllers\ResController::class . ':getResourcesByBasket'); +// +////Attachments +//$app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create'); +//$app->get('/res/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getAttachmentsListById'); +//$app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent'); +//$app->get('/res/{resIdMaster}/attachments/{resId}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent'); +// +////SignatureBook +//$app->get('/{basketId}/signatureBook/resList', \SignatureBook\controllers\SignatureBookController::class . ':getResList'); +//$app->get('/{basketId}/signatureBook/resList/details', \SignatureBook\controllers\SignatureBookController::class . ':getDetailledResList'); +//$app->get('/groups/{groupId}/baskets/{basketId}/signatureBook/{resId}', \SignatureBook\controllers\SignatureBookController::class . ':getSignatureBook'); +//$app->get('/signatureBook/{resId}/attachments', \SignatureBook\controllers\SignatureBookController::class . ':getAttachmentsById'); +//$app->get('/signatureBook/{resId}/incomingMailAttachments', \SignatureBook\controllers\SignatureBookController::class . ':getIncomingMailAndAttachmentsById'); +//$app->put('/signatureBook/{resId}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignFile'); +//$app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); +// +// +////Users +//$app->get('/users', \User\controllers\UserController::class . ':get'); +//$app->post('/users', \User\controllers\UserController::class . ':create'); +//$app->get('/users/{id}/details', \User\controllers\UserController::class . ':getDetailledById'); +//$app->put('/users/{id}', \User\controllers\UserController::class . ':update'); +//$app->put('/users/{id}/password', \User\controllers\UserController::class . ':resetPassword'); +//$app->get('/users/{userId}/status', \User\controllers\UserController::class . ':getStatusByUserId'); +//$app->put('/users/{id}/status', \User\controllers\UserController::class . ':updateStatus'); +//$app->delete('/users/{id}', \User\controllers\UserController::class . ':delete'); +//$app->post('/users/{id}/groups', \User\controllers\UserController::class . ':addGroup'); +//$app->put('/users/{id}/groups/{groupId}', \User\controllers\UserController::class . ':updateGroup'); +//$app->delete('/users/{id}/groups/{groupId}', \User\controllers\UserController::class . ':deleteGroup'); +//$app->post('/users/{id}/entities', \User\controllers\UserController::class . ':addEntity'); +//$app->put('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':updateEntity'); +//$app->put('/users/{id}/entities/{entityId}/primaryEntity', \User\controllers\UserController::class . ':updatePrimaryEntity'); +//$app->get('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':isEntityDeletable'); +//$app->delete('/users/{id}/entities/{entityId}', \User\controllers\UserController::class . ':deleteEntity'); +//$app->post('/users/{id}/signatures', \User\controllers\UserController::class . ':addSignature'); +//$app->get('/users/{id}/signatures/{signatureId}/content', \User\controllers\UserController::class . ':getImageContent'); +//$app->put('/users/{id}/signatures/{signatureId}', \User\controllers\UserController::class . ':updateSignature'); +//$app->delete('/users/{id}/signatures/{signatureId}', \User\controllers\UserController::class . ':deleteSignature'); +//$app->post('/users/{id}/redirectedBaskets', \User\controllers\UserController::class . ':setRedirectedBaskets'); +//$app->delete('/users/{id}/redirectedBaskets/{basketId}', \User\controllers\UserController::class . ':deleteRedirectedBaskets'); +//$app->put('/users/{id}/baskets', \User\controllers\UserController::class . ':updateBasketsDisplay'); +// +////CurrentUser +//$app->get('/currentUser/profile', \User\controllers\UserController::class . ':getProfile'); +//$app->put('/currentUser/profile', \User\controllers\UserController::class . ':updateProfile'); +//$app->put('/currentUser/password', \User\controllers\UserController::class . ':updateCurrentUserPassword'); +//$app->post('/currentUser/emailSignature', \User\controllers\UserController::class . ':createCurrentUserEmailSignature'); +//$app->put('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':updateCurrentUserEmailSignature'); +//$app->delete('/currentUser/emailSignature/{id}', \User\controllers\UserController::class . ':deleteCurrentUserEmailSignature'); +//$app->put('/currentUser/groups/{groupId}/baskets/{basketId}', \User\controllers\UserController::class . ':updateCurrentUserBasketPreferences'); $app->run(); diff --git a/rest/schema.json b/rest/schema.json deleted file mode 100755 index 2b2d85041c..0000000000 --- a/rest/schema.json +++ /dev/null @@ -1,275 +0,0 @@ -{ - "swagger" : "2.0", - "info" : { - "title" : "Maarch Courrier", - "version" : "18.10", - "description" : "Documentation de l'API Maarch Courrier V18.10", - "contact" : { - "name" : "Maarch", - "email" : "info@maarch.org" - } - }, - "basePath" : "/rest", - "paths" : { - "/res/resource/status" : { - "put" : { - "description" : "Update documents status", - "operationId" : "Resource/controllers/ResController::updateStatus", - "parameters" : [ - { - "name" : "body", - "in" : "body", - "schema": { - "type": "object", - "properties": { - "resId": { - "type": "array", - "description" : "Documents identifier", - "items": { - "type": "integer", - "minimum": 1, - "example" : 101 - } - }, - "chrono": { - "type": "array", - "description" : "Documents chrono number", - "items": { - "type": "string", - "maxLength": 255, - "example" : "MAARCH/2017A/91" - } - }, - "status": { - "type": "string", - "description" : "New status", - "maxLength": 10, - "default": "COU", - "example" : "NEW" - - }, - "historyMessage": { - "type": "string", - "description" : "Message in history table", - "default": "status update", - "example" : "Document is reopen" - } - } - } - } - ], - "responses" : { - "200" : { - "description" : "Status updated", - "schema": { - "type" : "object", - "properties" : { - "success" : { - "type" : "string" - } - } - }, - "examples" : { - "application/json": { - "success": "success" - } - } - }, - "400" : { - "description" : "Status or document not found", - "schema": { - "type" : "object", - "properties" : { - "errors" : { - "type" : "string" - } - } - }, - "examples" : { - "application/json": { - "errors": "Status not found" - } - } - }, - "403" : { - "description" : "Document is out of perimeter", - "schema": { - "type" : "object", - "properties" : { - "errors" : { - "type" : "string" - } - } - }, - "examples" : { - "application/json": { - "errors": "Document out of perimeter" - } - } - } - } - } - }, - "/entities/{id}" : { - "get" : { - "description" : "Get entity informations", - "operationId" : "Entity/controllers/EntityController::getById", - "parameters" : [ - { - "name" : "id", - "description" : "Entity identifier", - "in" : "path", - "required" : true, - "type" : "string", - "maxLength" : 32 - } - ], - "responses" : { - "200" : { - "description" : "Return entity informations", - "schema" : { - "$ref": "#/definitions/EntityRead" - }, - "examples" : { - "application/json": { - "entity": { - "entity_id" : "VILLE", - "entity_label" : "Ville de Maarch-Les-Bains", - "short_label" : "Ville de Maarch-Les-Bains", - "enabled" : "Y", - "adrs_1" : "11 Bd du sud-est", - "adrs_2" : "", - "adrs_3" : "", - "zipcode" : "92000", - "city" : "Nanterre", - "country" : "FRANCE", - "email" : "info@maarchlesbains.org", - "business_id" : "", - "parent_entity_id" : "", - "entity_type" : "Direction", - "entity_path" : "", - "ldap_id" : "", - "archival_agency" : "", - "archival_agreement" : "", - "entity_full_name" : "" - } - } - } - }, - "400" : { - "description" : "Entity not found", - "schema": { - "type" : "object", - "properties" : { - "errors" : { - "type" : "string" - } - } - }, - "examples" : { - "application/json": { - "errors": "Entity not found" - } - } - } - } - } - } - }, - "definitions" : { - "EntityRead" : { - "type" : "object", - "required" : [ - "entity" - ], - "properties": { - "entity" : { - "required" : [ - "entity_id", - "entity_label", - "short_label", - "entity_type", - "enabled" - ], - "properties" : { - "entity_id" : { - "type" : "string", - "maxLength" : 32 - }, - "entity_label" : { - "type" : "string", - "maxLength" : 255 - }, - "short_label" : { - "type" : "string", - "maxLength" : 50 - }, - "enabled" : { - "type" : "string", - "maxLength" : 1 - }, - "adrs_1" : { - "type" : "string", - "maxLength" : 255 - }, - "adrs_2" : { - "type" : "string", - "maxLength" : 255 - }, - "adrs_3" : { - "type" : "string", - "maxLength" : 255 - }, - "zipcode" : { - "type" : "string", - "maxLength" : 32 - }, - "city" : { - "type" : "string", - "maxLength" : 255 - }, - "country" : { - "type" : "string", - "maxLength" : 255 - }, - "email" : { - "type" : "string", - "maxLength" : 255 - }, - "business_id" : { - "type" : "string", - "maxLength" : 32 - }, - "parent_entity_id" : { - "type" : "string", - "maxLength" : 32 - }, - "entity_type" : { - "type" : "string", - "maxLength" : 64 - }, - "entity_path" : { - "type" : "string", - "maxLength" : 2048 - }, - "ldap_id" : { - "type" : "string", - "maxLength" : 255 - }, - "archival_agency" : { - "type" : "string", - "maxLength" : 255 - }, - "archival_agreement" : { - "type" : "string", - "maxLength" : 255 - }, - "entity_full_name" : { - "type" : "string" - } - } - } - } - } - } -} diff --git a/sql/data_fr.sql b/sql/data_fr.sql index a7fa8d790a..9227de406d 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -17,12 +17,6 @@ DELETE FROM users WHERE user_id = 'mmanfred'; INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (17, 'mmanfred', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Martin', 'MANFRED', 'info@maarch.org', 'Y', 'OK', 'standard'); DELETE FROM users WHERE user_id = 'ddaull'; INSERT INTO users (id, user_id, password, firstname, lastname, mail, enabled, status, loginmode) VALUES (18, 'ddaull', '$2y$10$C.QSslBKD3yNMfRPuZfcaubFwPKiCkqqOUyAdOr5FSGKPaePwuEjG', 'Denis', 'DAULL', 'info@maarch.org', 'Y', 'OK', 'standard'); -select setval('users_id_seq', (select max(id)+1 from users), false); - --- Create BASKETS -TRUNCATE TABLE baskets; -DELETE FROM baskets WHERE basket_id = 'MyBasket'; -INSERT INTO baskets (basket_id, basket_name, basket_desc, basket_clause, enabled) VALUES ('MyBasket', 'Courriers à traiter', 'Bannette des courriers à traiter', 'status in (''ANNOT'', ''SIGN'')', 'Y'); -- Donnees manuelles ------------ diff --git a/sql/structure.sql b/sql/structure.sql index 6e8a8748e0..7328c3ab2f 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -57,7 +57,7 @@ WITH (OIDS=FALSE); CREATE TABLE users ( id serial NOT NULL, - user_id character varying(128) NOT NULL, + login character varying(128) NOT NULL, "password" character varying(255) DEFAULT NULL::character varying, firstname character varying(255) DEFAULT NULL::character varying, lastname character varying(255) DEFAULT NULL::character varying, @@ -112,17 +112,6 @@ CREATE TABLE attachments ) WITH (OIDS=FALSE); -CREATE TABLE baskets -( - id serial NOT NULL, - name character varying(255) NOT NULL, - description character varying(255) NOT NULL, - clause text NOT NULL, - documents_order character varying(255) NOT NULL DEFAULT 'creation_date DESC', - CONSTRAINT baskets_pkey PRIMARY KEY (id) -) -WITH (OIDS=FALSE); - CREATE TABLE adr_main_documents ( id serial NOT NULL, @@ -149,7 +138,7 @@ CREATE TABLE adr_attachments ) WITH (OIDS=FALSE); -CREATE TABLE user_signatures +CREATE TABLE users_signatures ( id serial NOT NULL, user_serial_id integer NOT NULL, diff --git a/src/app/action/controllers/ActionController.php b/src/app/action/controllers/ActionController.php deleted file mode 100644 index 64c75b8c28..0000000000 --- a/src/app/action/controllers/ActionController.php +++ /dev/null @@ -1,233 +0,0 @@ -<?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 ActionController -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Action\controllers; - -use History\controllers\HistoryController; -use Resource\models\ResModel; -use Respect\Validation\Validator; -use Action\models\ActionModel; -use SrcCore\models\CoreConfigModel; -use Status\models\StatusModel; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class ActionController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['actions' => ActionModel::get()]); - } - - public function getById(Request $request, Response $response, $aArgs) - { - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - $obj['action'] = ActionModel::getById(['id' => $aArgs['id']]); - - if (!empty($obj['action'])) { - $obj['action']['history'] = ($obj['action']['history'] == 'Y'); - $obj['action']['is_system'] = ($obj['action']['is_system'] == 'Y'); - $obj['action']['create_id'] = ($obj['action']['create_id'] == 'Y'); - - $actionCategories = []; - foreach ($obj['action']['actionCategories'] as $key => $category) { - $actionCategories[] = $category['category_id']; - } - $obj['action']['actionCategories'] = $actionCategories; - - $obj['categoriesList'] = ResModel::getCategories(); - if (empty($obj['action']['actionCategories'])) { - $categoriesList = []; - foreach ($obj['categoriesList'] as $key => $category) { - $categoriesList[] = $category['id']; - } - $obj['action']['actionCategories'] = $categoriesList; - } - - - $obj['statuses'] = StatusModel::get(); - array_unshift($obj['statuses'], ['id'=>'_NOSTATUS_', 'label_status'=> _UNCHANGED]); - $obj['action_pagesList'] = ActionModel::getActionPages(); - array_unshift($obj['action_pagesList']['actionsPageList'], ['id' => '', 'label' => _NO_PAGE, 'name' => '', 'origin' => '']); - $obj['keywordsList'] = ActionModel::getKeywords(); - } - - return $response->withJson($obj); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data = $this->manageValue($data); - - $errors = $this->control($data, 'create'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $id = ActionModel::create($data); - - HistoryController::add([ - 'tableName' => 'actions', - 'recordId' => $id, - 'eventType' => 'ADD', - 'eventId' => 'actionadd', - 'info' => _ACTION_ADDED . ' : ' . $data['label_action'] - ]); - - return $response->withJson(['actionId' => $id]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data['id'] = $aArgs['id']; - - $data = $this->manageValue($data); - $errors = $this->control($data, 'update'); - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - ActionModel::update($data); - - HistoryController::add([ - 'tableName' => 'actions', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'eventId' => 'actionup', - 'info' => _ACTION_UPDATED. ' : ' . $data['label_action'] - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_actions', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - $action = ActionModel::getById(['id' => $aArgs['id']]); - ActionModel::delete(['id' => $aArgs['id']]); - - HistoryController::add([ - 'tableName' => 'actions', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'eventId' => 'actiondel', - 'info' => _ACTION_DELETED. ' : ' . $action['label_action'] - ]); - - return $response->withJson(['actions' => ActionModel::get()]); - } - - protected function control($aArgs, $mode) - { - $errors = []; - - $objs = StatusModel::get(); - - foreach ($objs as $obj) { - $status[] = $obj['id']; - } - array_unshift($status, '_NOSTATUS_'); - - if (!(in_array($aArgs['id_status'], $status))) { - $errors[]= 'Invalid Status'; - } - - if ($mode == 'update') { - if (!Validator::intVal()->validate($aArgs['id'])) { - $errors[] = 'Id is not a numeric'; - } else { - $obj = ActionModel::getById(['id' => $aArgs['id']]); - } - - if (empty($obj)) { - $errors[] = 'Id ' .$aArgs['id']. ' does not exists'; - } - } - - if (!Validator::notEmpty()->validate($aArgs['label_action']) || - !Validator::length(1, 255)->validate($aArgs['label_action'])) { - $errors[] = 'Invalid label action'; - } - - if (!Validator::notEmpty()->validate($aArgs['id_status'])) { - $errors[] = 'id_status is empty'; - } - - if (!Validator::notEmpty()->validate($aArgs['history']) || ($aArgs['history'] != 'Y' && $aArgs['history'] != 'N')) { - $errors[]= 'Invalid history value'; - } - - return $errors; - } - - public function initAction(Request $request, Response $response) - { - //default data - $obj['action']['history'] = true; - $obj['action']['keyword'] = ''; - $obj['action']['action_page'] = ''; - $obj['action']['id_status'] = '_NOSTATUS_'; - $obj['categoriesList'] = ResModel::getCategories(); - - foreach ($obj['categoriesList'] as $key => $value) { - $obj['categoriesList'][$key]['selected'] = true; - } - - $obj['statuses'] = StatusModel::get(); - array_unshift($obj['statuses'], ['id'=>'_NOSTATUS_','label_status'=> _UNCHANGED]); - $obj['action_pagesList'] = ActionModel::getActionPages(); - array_unshift($obj['action_pagesList']['actionsPageList'], ['id'=>'','label'=> _NO_PAGE, 'name'=>'', 'origin'=>'']); - $obj['keywordsList'] = ActionModel::getKeywords(); - - return $response->withJson($obj); - } - - protected function manageValue($request) - { - foreach ($request as $key => $value) { - if (in_array($key, ['history'])) { - if (empty($value)) { - $request[$key] = 'N'; - } else { - $request[$key] = 'Y'; - } - } - } - return $request; - } -} diff --git a/src/app/action/models/ActionModel.php b/src/app/action/models/ActionModel.php deleted file mode 100644 index 6bc554bbab..0000000000 --- a/src/app/action/models/ActionModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Action Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Action\models; - -class ActionModel extends ActionModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/action/models/ActionModelAbstract.php b/src/app/action/models/ActionModelAbstract.php deleted file mode 100644 index 30342f49d0..0000000000 --- a/src/app/action/models/ActionModelAbstract.php +++ /dev/null @@ -1,266 +0,0 @@ -<?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 Action Model Abstract -* @author dev@maarch.org -*/ - -namespace Action\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -abstract class ActionModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $actions = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['actions'] - ]); - - return $actions; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['actions'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aReturn[0])) { - return []; - } - - $aReturn = $aReturn[0]; - $aReturn['actionCategories'] = DatabaseModel::select([ - 'select' => ['category_id'], - 'table' => ['actions_categories'], - 'where' => ['action_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aReturn; - } - - public static function create(array $aArgs) - { - $actionCategories = empty($aArgs['actionCategories']) ? [] : $aArgs['actionCategories']; - unset($aArgs['actionCategories']); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'actions_id_seq']); - $aArgs['id'] = $nextSequenceId; - - DatabaseModel::insert([ - 'table' => 'actions', - 'columnsValues' => $aArgs - ]); - - $data = []; - $data['action_id'] = $nextSequenceId; - foreach ($actionCategories as $actionCategory) { - $data['category_id'] = $actionCategory; - DatabaseModel::insert([ - 'table' => 'actions_categories', - 'columnsValues' => $data - ]); - } - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::update([ - 'table' => 'actions', - 'set' => [ - 'keyword' => $aArgs['keyword'], - 'label_action' => $aArgs['label_action'], - 'id_status' => $aArgs['id_status'], - 'action_page' => $aArgs['action_page'], - 'history' => $aArgs['history'], - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - DatabaseModel::delete([ - 'table' => 'actions_categories', - 'where' => ['action_id = ?'], - 'data' => [$aArgs['id']] - ]); - - $tab['action_id'] = $aArgs['id']; - - if (!empty($aArgs['actionCategories'])) { - foreach ($aArgs['actionCategories'] as $actionCategory) { - $tab['category_id'] = $actionCategory; - DatabaseModel::insert([ - 'table' => 'actions_categories', - 'columnsValues' => $tab - ]); - } - } - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'actions', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'actions_categories', - 'where' => ['action_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'actions_groupbaskets', - 'where' => ['id_action = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function getActionPages() - { - $actionsPages = []; - $actionsPages['modules'][] = 'Apps'; - - $paths = ['core/xml/actions_pages.xml', 'modules/avis/xml/actions_pages.xml', 'modules/export_seda/xml/actions_pages.xml']; - - foreach ($paths as $path) { - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => $path]); - if ($loadedXml) { - foreach ($loadedXml->ACTIONPAGE as $actionPage) { - if (!defined((string) $actionPage->LABEL)) { - $label = $actionPage->LABEL; - } else { - $label = constant((string) $actionPage->LABEL); - } - if (!empty((string) $actionPage->MODULE)) { - $origin = (string) $actionPage->MODULE; - } else { - $origin = 'apps'; - } - if (!empty((string) $actionPage->DESC)) { - $desc = constant((string) $actionPage->DESC); - } else { - $desc = 'No description'; - } - $actionsPages['actionsPageList'][] = [ - 'id' => (string) $actionPage->ID, - 'label' => $label, - 'name' => (string) $actionPage->NAME, - 'desc' => $desc, - 'origin' => ucfirst($origin) - ]; - } - } - } - - array_multisort( - array_map( - function ($element) { - return $element['label']; - }, $actionsPages['actionsPageList'] - ), - SORT_ASC, $actionsPages['actionsPageList'] - ); - - $actionsPages['modules'] = array_unique($actionsPages['modules']); - sort($actionsPages['modules']); - - return $actionsPages; - } - - public static function getKeywords() - { - $tabKeyword = []; - $tabKeyword[] = ['value' => '', 'label' => _NO_KEYWORD]; - $tabKeyword[] = ['value' => 'redirect', 'label' => _REDIRECTION, 'desc' => _KEYWORD_REDIRECT_DESC]; - $tabKeyword[] = ['value' => 'indexing', 'label' => _INDEXING, 'desc' => _KEYWORD_INDEXING_DESC]; - - return $tabKeyword; - } - - public static function getActionPageById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $action = DatabaseModel::select([ - 'select' => ['action_page'], - 'table' => ['actions'], - 'where' => ['id = ? AND enabled = ?'], - 'data' => [$aArgs['id'], 'Y'] - ]); - - if (empty($action[0])) { - return ''; - } - - return $action[0]['action_page']; - } - - public static function getDefaultActionByGroupBasketId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'basketId']); - ValidatorModel::stringType($aArgs, ['groupId', 'basketId']); - - $action = DatabaseModel::select([ - 'select' => ['id_action'], - 'table' => ['actions_groupbaskets'], - 'where' => ['group_id = ?', 'basket_id = ?', 'default_action_list = ?'], - 'data' => [$aArgs['groupId'], $aArgs['basketId'], 'Y'] - ]); - - if (empty($action[0])) { - return ''; - } - - return $action[0]['id_action']; - } - - public static function getForBasketPage(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['basketId', 'groupId']); - ValidatorModel::stringType($aArgs, ['basketId', 'groupId']); - - $actions = DatabaseModel::select([ - 'select' => ['id_action', 'where_clause', 'default_action_list', 'actions.label_action'], - 'table' => ['actions_groupbaskets, actions'], - 'where' => ['basket_id = ?', 'group_id = ?', 'used_in_action_page = ?', 'actions_groupbaskets.id_action = actions.id'], - 'data' => [$aArgs['basketId'], $aArgs['groupId'], 'Y'], - 'order_by' => ['default_action_list DESC'] - ]); - - return $actions; - } -} diff --git a/src/app/basket/controllers/BasketController.php b/src/app/basket/controllers/BasketController.php deleted file mode 100644 index 67046bfdc4..0000000000 --- a/src/app/basket/controllers/BasketController.php +++ /dev/null @@ -1,537 +0,0 @@ -<?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 Basket Controller - * - * @author dev@maarch.org - */ - -namespace Basket\controllers; - -use Basket\models\BasketModel; -use Action\models\ActionModel; -use Basket\models\GroupBasketModel; -use Group\models\ServiceModel; -use SrcCore\models\ValidatorModel; -use Group\models\GroupModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\controllers\PreparedClauseController; -use User\models\UserBasketPreferenceModel; - -class BasketController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['baskets' => BasketModel::get()]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id']]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - return $response->withJson(['basket' => $basket]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['id']) && preg_match("/^[\w-]*$/", $data['id']) && (strlen($data['id']) <= 32); - $check = $check && Validator::stringType()->notEmpty()->validate($data['basket_name']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['basket_desc']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['clause']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $existingBasket = BasketModel::getById(['id' => $data['id'], 'select' => ['1']]); - if (!empty($existingBasket)) { - return $response->withStatus(400)->withJson(['errors' => _ID. ' ' . _ALREADY_EXISTS]); - } - - if (!PreparedClauseController::isRequestValid(['clause' => $data['clause'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(400)->withJson(['errors' => _INVALID_CLAUSE]); - } - - $data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N'; - $data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y'; - BasketModel::create($data); - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $data['id'], - 'eventType' => 'ADD', - 'info' => _BASKET_CREATION . " : {$data['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketCreation', - ]); - - return $response->withJson(['basket' => $data['id']]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['basket_name']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['basket_desc']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['clause']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if (!PreparedClauseController::isRequestValid(['clause' => $data['clause'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(400)->withJson(['errors' => _INVALID_CLAUSE]); - } - - $data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N'; - $data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y'; - $data['id'] = $aArgs['id']; - BasketModel::update($data); - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _BASKET_MODIFICATION . " : {$aArgs['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket does not exist']); - } - - BasketModel::delete(['id' => $aArgs['id']]); - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _BASKET_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketSuppression', - ]); - - return $response->withJson(['baskets' => BasketModel::get()]); - } - - public function getSorted(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $baskets = BasketModel::get([ - 'select' => ['basket_id', 'basket_name', 'basket_desc', 'basket_order'], - 'where' => ['is_visible = ?'], - 'data' => ['Y'], - 'orderBy' => ['basket_order'] - ]); - - return $response->withJson(['baskets' => $baskets]); - } - - public function updateSort(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - foreach ($data as $key => $basketToUpdate) { - if ($key != $basketToUpdate['basket_order']) { - BasketModel::updateOrder(['id' => $basketToUpdate['basket_id'], 'order' => $key]); - } - } - - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _BASKETS_SORT_MODIFICATION, - 'moduleId' => 'basket', - 'eventId' => 'basketModification', - ]); - - $baskets = BasketModel::get([ - 'select' => ['basket_id', 'basket_name', 'basket_desc', 'basket_order'], - 'where' => ['is_visible = ?'], - 'data' => ['Y'], - 'orderBy' => ['basket_order'] - ]); - - return $response->withJson(['baskets' => $baskets]); - } - - public function getGroups(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - $allGroups = GroupModel::get(['select' => ['group_id', 'group_desc']]); - - $groups = GroupBasketModel::get(['where' => ['basket_id = ?'], 'data' => [$aArgs['id']], 'orderBy' => ['group_id']]); - $allActions = ActionModel::get(); - - foreach ($groups as $key => $group) { - foreach ($allGroups as $value) { - if ($value['group_id'] == $group['group_id']) { - $groups[$key]['group_desc'] = $value['group_desc']; - } - } - $actionsForGroup = $allActions; - $actions = BasketModel::getActionsForGroupById([ - 'id' => $aArgs['id'], - 'groupId' => $group['group_id'], - 'select' => ['id_action', 'where_clause', 'used_in_basketlist', 'used_in_action_page', 'default_action_list'] - ]); - $actionIds = []; - foreach ($actions as $action) { - $actionIds[] = $action['id_action']; - } - $statuses = []; - $redirects = []; - if (!empty($actionIds)) { - $statuses = BasketModel::getGroupActionStatus([ - 'select' => ['status_id', 'action_id'], - 'where' => ['basket_id = ?', 'group_id = ?', 'action_id in (?)'], - 'data' => [$aArgs['id'], $group['group_id'], $actionIds], - 'orderBy' => ['"order"'] - ]); - $redirects = BasketModel::getGroupActionRedirect([ - 'select' => ['entity_id', 'action_id', 'keyword', 'redirect_mode'], - 'where' => ['basket_id = ?', 'group_id = ?', 'action_id in (?)'], - 'data' => [$aArgs['id'], $group['group_id'], $actionIds] - ]); - } - foreach ($actions as $actionKey => $action) { - $actions[$actionKey]['statuses'] = []; - $actions[$actionKey]['redirects'] = []; - foreach ($statuses as $status) { - if ($status['action_id'] == $action['id_action']) { - $actions[$actionKey]['statuses'][] = $status['status_id']; - } - } - foreach ($redirects as $redirect) { - if ($redirect['action_id'] == $action['id_action']) { - $actions[$actionKey]['redirects'][] = $redirect; - } - } - } - - foreach ($actionsForGroup as $actionKey => $actionForGroup) { - foreach ($actions as $action) { - if ($actionForGroup['id'] == $action['id_action']) { - $actionsForGroup[$actionKey] = array_merge($actionForGroup, $action); - $actionsForGroup[$actionKey]['checked'] = true; - unset($actionsForGroup[$actionKey]['id_action']); - } - } - if (empty($actionsForGroup[$actionKey]['checked'])) { - $actionsForGroup[$actionKey]['where_clause'] = ''; - $actionsForGroup[$actionKey]['used_in_basketlist'] = 'N'; - $actionsForGroup[$actionKey]['used_in_action_page'] = 'Y'; - $actionsForGroup[$actionKey]['default_action_list'] = 'N'; - $actionsForGroup[$actionKey]['statuses'] = []; - $actionsForGroup[$actionKey]['redirects'] = []; - $actionsForGroup[$actionKey]['checked'] = false; - } - } - $groups[$key]['groupActions'] = $actionsForGroup; - } - - if ($aArgs['id'] == 'IndexingBasket') { - $basketPages = BasketModel::getBasketPages(); - } else { - $basketPages = BasketModel::getBasketPages(['unneeded' => ['redirect_to_action']]); - } - - return $response->withJson(['groups' => $groups, 'allGroups' => $allGroups, 'pages' => $basketPages]); - } - - public function createGroup(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['group_id']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['result_page']); - $check = $check && Validator::arrayType()->notEmpty()->validate($data['groupActions']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - $data['groupActions'] = BasketController::checkGroupActions(['groupActions' => $data['groupActions'], 'userId' => $GLOBALS['userId']]); - if (!empty($data['groupActions']['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $data['groupActions']['errors']]); - } - - if (BasketModel::hasGroup(['id' => $aArgs['id'], 'groupId' => $data['group_id']])) { - return $response->withStatus(400)->withJson(['errors' => 'Group already exist for this basket']); - } - - GroupBasketModel::createGroupBasket(['basketId' => $aArgs['id'], 'groupId' => $data['group_id'], 'resultPage' => $data['result_page']]); - foreach ($data['groupActions'] as $groupAction) { - if ($groupAction['checked']) { - BasketModel::createGroupAction([ - 'id' => $aArgs['id'], - 'groupId' => $data['group_id'], - 'actionId' => $groupAction['id'], - 'whereClause' => $groupAction['where_clause'], - 'usedInBasketlist' => $groupAction['used_in_basketlist'], - 'usedInActionPage' => $groupAction['used_in_action_page'], - 'defaultActionList' => $groupAction['default_action_list'] - ]); - - if (!empty($groupAction['statuses'])) { - foreach ($groupAction['statuses'] as $key => $status) { - BasketModel::createGroupActionStatus([ - 'id' => $aArgs['id'], - 'groupId' => $data['group_id'], - 'actionId' => $groupAction['id'], - 'statusId' => $status, - 'order' => $key - ]); - } - } - if (!empty($groupAction['redirects'])) { - foreach ($groupAction['redirects'] as $redirect) { - BasketModel::createGroupActionRedirect([ - 'id' => $aArgs['id'], - 'groupId' => $data['group_id'], - 'actionId' => $groupAction['id'], - 'entityId' => $redirect['entity_id'], - 'keyword' => $redirect['keyword'], - 'redirectMode' => $redirect['redirect_mode'] - ]); - } - } - } - } - - $users = GroupModel::getUsersByGroupId(['select' => ['id'], 'groupId' => $data['group_id']]); - $group = GroupModel::getByGroupId(['select' => ['id'], 'groupId' => $data['group_id']]); - foreach ($users as $user) { - UserBasketPreferenceModel::create([ - 'userSerialId' => $user['id'], - 'groupSerialId' => $group['id'], - 'basketId' => $aArgs['id'], - 'display' => 'true', - ]); - } - - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _BASKET_GROUP_CREATION . " : {$aArgs['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function updateGroup(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['result_page']); - $check = $check && Validator::arrayType()->notEmpty()->validate($data['groupActions']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - $data['groupActions'] = BasketController::checkGroupActions(['groupActions' => $data['groupActions'], 'userId' => $GLOBALS['userId']]); - if (!empty($data['groupActions']['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $data['groupActions']['errors']]); - } - - if (!BasketModel::hasGroup(['id' => $aArgs['id'], 'groupId' => $aArgs['groupId']])) { - return $response->withStatus(400)->withJson(['errors' => 'Group does not exist for this basket']); - } - - GroupBasketModel::deleteGroupBasket(['basketId' => $aArgs['id'], 'groupId' => $aArgs['groupId'], 'preferences' => false]); - - GroupBasketModel::createGroupBasket(['basketId' => $aArgs['id'], 'groupId' => $aArgs['groupId'], 'resultPage' => $data['result_page']]); - foreach ($data['groupActions'] as $groupAction) { - if ($groupAction['checked']) { - BasketModel::createGroupAction([ - 'id' => $aArgs['id'], - 'groupId' => $aArgs['groupId'], - 'actionId' => $groupAction['id'], - 'whereClause' => $groupAction['where_clause'], - 'usedInBasketlist' => $groupAction['used_in_basketlist'], - 'usedInActionPage' => $groupAction['used_in_action_page'], - 'defaultActionList' => $groupAction['default_action_list'] - ]); - - if (!empty($groupAction['statuses'])) { - foreach ($groupAction['statuses'] as $key => $status) { - BasketModel::createGroupActionStatus([ - 'id' => $aArgs['id'], - 'groupId' => $aArgs['groupId'], - 'actionId' => $groupAction['id'], - 'statusId' => $status, - 'order' => $key - ]); - } - } - if (!empty($groupAction['redirects'])) { - foreach ($groupAction['redirects'] as $redirect) { - BasketModel::createGroupActionRedirect([ - 'id' => $aArgs['id'], - 'groupId' => $aArgs['groupId'], - 'actionId' => $groupAction['id'], - 'entityId' => $redirect['entity_id'], - 'keyword' => $redirect['keyword'], - 'redirectMode' => $redirect['redirect_mode'] - ]); - } - } - } - } - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _BASKET_GROUP_MODIFICATION . " : {$aArgs['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function deleteGroup(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $basket = BasketModel::getById(['id' => $aArgs['id']]); - if (empty($basket)) { - return $response->withStatus(400)->withJson(['errors' => 'Basket not found']); - } - - GroupBasketModel::deleteGroupBasket(['basketId' => $aArgs['id'], 'groupId' => $aArgs['groupId'], 'preferences' => true]); - HistoryController::add([ - 'tableName' => 'baskets', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _BASKET_GROUP_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'basket', - 'eventId' => 'basketModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - private static function checkGroupActions(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupActions', 'userId']); - ValidatorModel::arrayType($aArgs, ['groupActions']); - ValidatorModel::stringType($aArgs, ['userId']); - - $defaultAction = false; - $actions = ActionModel::get(['select' => ['id']]); - - foreach ($aArgs['groupActions'] as $key => $groupAction) { - if ($groupAction['checked']) { - $actionExists = false; - foreach ($actions as $action) { - if ($action['id'] == $groupAction['id']) { - $actionExists = true; - } - } - if (!$actionExists) { - return ['errors' => 'Action does not exist']; - } - if ($groupAction['default_action_list'] === true) { - $defaultAction = true; - } - - $aArgs['groupActions'][$key]['where_clause'] = empty($groupAction['where_clause']) ? '' : $groupAction['where_clause']; - $aArgs['groupActions'][$key]['used_in_basketlist'] = empty($groupAction['used_in_basketlist']) ? 'N' : 'Y'; - $aArgs['groupActions'][$key]['used_in_action_page'] = empty($groupAction['used_in_action_page']) ? 'N' : 'Y'; - $aArgs['groupActions'][$key]['default_action_list'] = empty($groupAction['default_action_list']) ? 'N' : 'Y'; - - if ($aArgs['groupActions'][$key]['checked'] && $aArgs['groupActions'][$key]['used_in_basketlist'] == 'N' && $aArgs['groupActions'][$key]['used_in_action_page'] == 'N') { - return ['errors' => 'Action must be present in action page or in action list']; - } - if (!empty($aArgs['groupActions'][$key]['where_clause'])) { - if (!PreparedClauseController::isRequestValid(['clause' => $aArgs['groupActions'][$key]['where_clause'], 'userId' => $aArgs['userId']])) { - return ['errors' => _INVALID_CLAUSE]; - } - } - } - } - if (!$defaultAction) { - return ['errors' => 'Default action needed']; - } - - return $aArgs['groupActions']; - } -} diff --git a/src/app/basket/models/BasketModel.php b/src/app/basket/models/BasketModel.php deleted file mode 100644 index d898739db8..0000000000 --- a/src/app/basket/models/BasketModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Basket Model - * @author <dev@maarch.org> - */ - -namespace Basket\models; - -class BasketModel extends BasketModelAbstract -{ -} diff --git a/src/app/basket/models/BasketModelAbstract.php b/src/app/basket/models/BasketModelAbstract.php deleted file mode 100644 index d6164f4263..0000000000 --- a/src/app/basket/models/BasketModelAbstract.php +++ /dev/null @@ -1,608 +0,0 @@ -<?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 Basket Model Abstract -* @author dev@maarch.org -*/ - -namespace Basket\models; - -use SrcCore\models\ValidatorModel; -use Resource\models\ResModel; -use SrcCore\controllers\PreparedClauseController; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; -use User\models\UserBasketPreferenceModel; -use User\models\UserModel; - -abstract class BasketModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - - $aBaskets = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['baskets'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'] - ]); - - return $aBaskets; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aBasket = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['baskets'], - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aBasket[0])) { - return []; - } - - return $aBasket[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'basket_name', 'basket_desc', 'clause', 'isVisible', 'flagNotif']); - ValidatorModel::stringType($aArgs, ['id', 'basket_name', 'color', 'basket_desc', 'clause', 'isVisible', 'flagNotif']); - - DatabaseModel::insert([ - 'table' => 'baskets', - 'columnsValues' => [ - 'basket_id' => $aArgs['id'], - 'basket_name' => $aArgs['basket_name'], - 'basket_desc' => $aArgs['basket_desc'], - 'basket_clause' => $aArgs['clause'], - 'is_visible' => $aArgs['isVisible'], - 'flag_notif' => $aArgs['flagNotif'], - 'color' => $aArgs['color'], - 'coll_id' => 'letterbox_coll', - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'basket_name', 'basket_desc', 'clause', 'isVisible', 'flagNotif']); - ValidatorModel::stringType($aArgs, ['id', 'basket_name', 'color', 'basket_desc', 'clause', 'isVisible', 'flagNotif', 'basket_res_order']); - - DatabaseModel::update([ - 'table' => 'baskets', - 'set' => [ - 'basket_name' => $aArgs['basket_name'], - 'basket_desc' => $aArgs['basket_desc'], - 'basket_clause' => $aArgs['clause'], - 'basket_res_order' => empty($aArgs['basket_res_order']) ? 'res_id DESC' : $aArgs['basket_res_order'], - 'is_visible' => $aArgs['isVisible'], - 'flag_notif' => $aArgs['flagNotif'], - 'color' => $aArgs['color'], - 'coll_id' => 'letterbox_coll', - ], - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function updateOrder(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['order']); - - DatabaseModel::update([ - 'table' => 'baskets', - 'set' => [ - 'basket_order' => $aArgs['order'] - ], - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'baskets', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_redirect', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_status', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'actions_groupbaskets', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'users_baskets_preferences', - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function createGroupAction(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId', 'actionId', 'usedInBasketlist', 'usedInActionPage', 'defaultActionList']); - ValidatorModel::stringType($aArgs, ['id', 'groupId', 'whereClause', 'usedInBasketlist', 'usedInActionPage', 'defaultActionList']); - ValidatorModel::intVal($aArgs, ['actionId']); - - DatabaseModel::insert([ - 'table' => 'actions_groupbaskets', - 'columnsValues' => [ - 'id_action' => $aArgs['actionId'], - 'where_clause' => $aArgs['whereClause'], - 'group_id' => $aArgs['groupId'], - 'basket_id' => $aArgs['id'], - 'used_in_basketlist' => $aArgs['usedInBasketlist'], - 'used_in_action_page' => $aArgs['usedInActionPage'], - 'default_action_list' => $aArgs['defaultActionList'], - ] - ]); - - return true; - } - - public static function getGroupActionRedirect(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $aRedirects = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['groupbasket_redirect'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $aRedirects; - } - - public static function createGroupActionRedirect(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId', 'actionId', 'redirectMode']); - ValidatorModel::stringType($aArgs, ['id', 'groupId', 'entityId', 'keyword', 'redirectMode']); - ValidatorModel::intVal($aArgs, ['actionId']); - - DatabaseModel::insert([ - 'table' => 'groupbasket_redirect', - 'columnsValues' => [ - 'action_id' => $aArgs['actionId'], - 'group_id' => $aArgs['groupId'], - 'basket_id' => $aArgs['id'], - 'entity_id' => $aArgs['entityId'], - 'keyword' => $aArgs['keyword'], - 'redirect_mode' => $aArgs['redirectMode'] - ] - ]); - - return true; - } - - public static function updateGroupActionRedirect(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'groupbasket_redirect', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getGroupActionStatus(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - - $aStatuses = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['groupbasket_status'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'] - ]); - - return $aStatuses; - } - - public static function createGroupActionStatus(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId', 'actionId', 'statusId']); - ValidatorModel::stringType($aArgs, ['id', 'groupId', 'statusId']); - ValidatorModel::intVal($aArgs, ['actionId']); - ValidatorModel::intType($aArgs, ['order']); - - DatabaseModel::insert([ - 'table' => 'groupbasket_status', - 'columnsValues' => [ - 'action_id' => $aArgs['actionId'], - 'group_id' => $aArgs['groupId'], - 'basket_id' => $aArgs['id'], - 'status_id' => $aArgs['statusId'], - '"order"' => $aArgs['order'] - ] - ]); - - return true; - } - - public static function getActionsForGroupById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::stringType($aArgs, ['id', 'groupId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aGroups = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['actions_groupbaskets'], - 'where' => ['basket_id = ?', 'group_id = ?'], - 'data' => [$aArgs['id'], $aArgs['groupId']] - ]); - - return $aGroups; - } - - public static function hasGroup(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::stringType($aArgs, ['id', 'groupId']); - - return !empty(GroupBasketModel::get(['where' => ['basket_id = ?', 'group_id = ?'], 'data' => [$aArgs['id'], $aArgs['groupId']]])); - } - - public static function getResListById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['basketId', 'userId']); - ValidatorModel::stringType($aArgs, ['basketId', 'userId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aBasket = DatabaseModel::select([ - 'select' => ['basket_clause', 'basket_res_order'], - 'table' => ['baskets'], - 'where' => ['basket_id = ?'], - 'data' => [$aArgs['basketId']] - ]); - - if (empty($aBasket[0]) || empty($aBasket[0]['basket_clause'])) { - return []; - } - - $where = PreparedClauseController::getPreparedClause(['clause' => $aBasket[0]['basket_clause'], 'userId' => $aArgs['userId']]); - - $aResList = ResModel::getOnView([ - 'select' => $aArgs['select'], - 'where' => [$where], - 'orderBy' => empty($aBasket[0]['basket_res_order']) ? ['creation_date DESC'] : [$aBasket[0]['basket_res_order']], - ]); - - return $aResList; - } - - public static function getBasketsByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - ValidatorModel::arrayType($aArgs, ['unneededBasketId']); - ValidatorModel::boolType($aArgs, ['absenceUneeded']); - - $userGroups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); - $groupIds = []; - foreach ($userGroups as $value) { - $groupIds[] = $value['group_id']; - } - - $aBaskets = []; - if (!empty($groupIds)) { - $where = ['groupbasket.group_id in (?)', 'groupbasket.basket_id = baskets.basket_id', 'groupbasket.group_id = usergroups.group_id']; - $data = [$groupIds]; - if (!empty($aArgs['unneededBasketId'])) { - $where[] = 'groupbasket.basket_id not in (?)'; - $data[] = $aArgs['unneededBasketId']; - } - $aBaskets = DatabaseModel::select([ - 'select' => ['usergroups.id as groupSerialId', 'groupbasket.basket_id', 'groupbasket.group_id', 'basket_name', 'basket_desc', 'basket_clause', 'usergroups.group_desc'], - 'table' => ['groupbasket, baskets, usergroups'], - 'where' => $where, - 'data' => $data, - 'order_by' => ['groupbasket.group_id, basket_order, basket_name'] - ]); - - $user = UserModel::getByUserId(['userId' => $aArgs['userId'], 'select' => ['id']]); - $userPrefs = UserBasketPreferenceModel::get([ - 'select' => ['group_serial_id', 'basket_id'], - 'where' => ['user_serial_id = ?'], - 'data' => [$user['id']] - ]); - - foreach ($aBaskets as $key => $value) { - unset($aBaskets[$key]['groupserialid']); - $aBaskets[$key]['groupSerialId'] = $value['groupserialid']; - $aBaskets[$key]['is_virtual'] = 'N'; - $aBaskets[$key]['basket_owner'] = $aArgs['userId']; - $aBaskets2 = DatabaseModel::select([ - 'select' => ['new_user'], - 'table' => ['user_abs'], - 'where' => ['user_abs = ?', 'basket_id = ?'], - 'data' => [$aArgs['userId'], $value['basket_id']], - ]); - $aBaskets[$key]['userToDisplay'] = UserModel::getLabelledUserById(['userId' => $aBaskets2[0]['new_user']]); - $aBaskets[$key]['enabled'] = true; - $aBaskets[$key]['allowed'] = false; - foreach ($userPrefs as $userPref) { - if ($userPref['group_serial_id'] == $value['groupserialid'] && $userPref['basket_id'] == $value['basket_id']) { - $aBaskets[$key]['allowed'] = true; - } - } - } - if (empty($aArgs['absenceUneeded'])) { - $aBaskets = array_merge($aBaskets, BasketModel::getAbsBasketsByUserId(['userId' => $aArgs['userId']])); - } - } - - return $aBaskets; - } - - public static function getAbsBasketsByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aBaskets = DatabaseModel::select([ - 'select' => ['ba.basket_id', 'ba.basket_name', 'ba.basket_desc', 'ua.user_abs', 'ua.basket_owner', 'ua.is_virtual'], - 'table' => ['baskets ba, user_abs ua'], - 'where' => ['ua.new_user = ?', 'ua.basket_id = ba.basket_id'], - 'data' => [$aArgs['userId']], - 'order_by' => ['ba.basket_order, ba.basket_name'] - ]); - - foreach ($aBaskets as $key => $value) { - $aBaskets[$key]['userToDisplay'] = UserModel::getLabelledUserById(['userId' => $value['user_abs']]); - } - - return $aBaskets; - } - - public static function setRedirectedBaskets(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userAbs', 'newUser', 'basketId', 'basketOwner', 'isVirtual']); - ValidatorModel::stringType($aArgs, ['userAbs', 'newUser', 'basketId', 'basketOwner', 'isVirtual']); - - DatabaseModel::insert([ - 'table' => 'user_abs', - 'columnsValues' => [ - 'user_abs' => $aArgs['userAbs'], - 'new_user' => $aArgs['newUser'], - 'basket_id' => $aArgs['basketId'], - 'basket_owner' => $aArgs['basketOwner'], - 'is_virtual' => $aArgs['isVirtual'] - ] - ]); - - return true; - } - - public static function updateRedirectedBaskets(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'basketOwner', 'basketId', 'userAbs', 'newUser']); - ValidatorModel::stringType($aArgs, ['userId']); - - DatabaseModel::update([ - 'table' => 'user_abs', - 'set' => [ - 'new_user' => $aArgs['newUser'] - ], - 'where' => ['basket_id = ?', 'basket_owner = ?', 'user_abs = ?', 'new_user = ?'], - 'data' => [$aArgs['basketId'], $aArgs['basketOwner'], $aArgs['userAbs'], $aArgs['userId']] - ]); - - return true; - } - - public static function deleteBasketRedirection(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'basketId']); - ValidatorModel::stringType($aArgs, ['userId', 'basketId']); - - DatabaseModel::delete([ - 'table' => 'user_abs', - 'where' => ['(user_abs = ? OR basket_owner = ?)', 'basket_id = ?'], - 'data' => [$aArgs['userId'], $aArgs['userId'], $aArgs['basketId']] - ]); - - return true; - } - - public static function getRedirectedBasketsByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aBaskets = DatabaseModel::select([ - 'select' => ['ba.basket_id', 'ba.basket_name', 'ua.new_user', 'ua.basket_owner'], - 'table' => ['baskets ba, user_abs ua'], - 'where' => ['ua.user_abs = ?', 'ua.basket_id = ba.basket_id'], - 'data' => [$aArgs['userId']], - 'order_by' => ['ua.system_id'] - ]); - - foreach ($aBaskets as $key => $value) { - $user = UserModel::getByUserId(['userId' => $value['new_user'], 'select' => ['firstname', 'lastname']]); - $aBaskets[$key]['userToDisplay'] = "{$user['firstname']} {$user['lastname']}"; - $aBaskets[$key]['userIdRedirection'] = $value['new_user']; - $aBaskets[$key]['user'] = "{$user['firstname']} {$user['lastname']}" ; - } - - return $aBaskets; - } - - public static function getRegroupedBasketsByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $regroupedBaskets = []; - - $user = UserModel::getByUserId(['userId' => $aArgs['userId'], 'select' => ['id']]); - - $groups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); - foreach ($groups as $group) { - $baskets = BasketModel::getAvailableBasketsByGroupUser([ - 'select' => ['baskets.basket_id', 'baskets.basket_name', 'baskets.basket_desc', 'baskets.color', 'users_baskets_preferences.color as pcolor'], - 'userSerialId' => $user['id'], - 'groupId' => $group['group_id'], - 'groupSerialId' => $group['id'] - ]); - - foreach ($baskets as $kBasket => $basket) { - if (!empty($basket['pcolor'])) { - $baskets[$kBasket]['color'] = $basket['pcolor']; - } - if (empty($baskets[$kBasket]['color'])) { - $baskets[$kBasket]['color'] = '#666666'; - } - unset($baskets[$kBasket]['pcolor']); - } - - $regroupedBaskets[] = [ - 'groupSerialId' => $group['id'], - 'groupId' => $group['group_id'], - 'groupDesc' => $group['group_desc'], - 'baskets' => $baskets - ]; - } - - return $regroupedBaskets; - } - - public static function getAvailableBasketsByGroupUser(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userSerialId', 'groupId', 'groupSerialId', 'select']); - ValidatorModel::intVal($aArgs, ['userSerialId', 'groupSerialId']); - ValidatorModel::stringType($aArgs, ['groupId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $baskets = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['groupbasket, baskets, users_baskets_preferences'], - 'where' => [ - 'groupbasket.basket_id = baskets.basket_id', - 'baskets.basket_id = users_baskets_preferences.basket_id', - 'groupbasket.group_id = ?', - 'users_baskets_preferences.group_serial_id = ?', - 'users_baskets_preferences.user_serial_id = ?', - 'baskets.is_visible = ?', - 'baskets.basket_id != ?' - ], - 'data' => [$aArgs['groupId'], $aArgs['groupSerialId'], $aArgs['userSerialId'], 'Y', 'IndexingBasket'], - 'order_by' => ['baskets.basket_order', 'baskets.basket_name'] - ]); - - return $baskets; - } - - public static function getBasketPages(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['unneeded']); - - $basketPages = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/basket/xml/basketpage.xml']); - if ($loadedXml) { - foreach ($loadedXml->BASKETPAGE as $value) { - if (empty($aArgs['unneeded']) || !in_array((string)$value->ID, $aArgs['unneeded'])) { - $basketPages[] = [ - 'id' => (string)$value->ID, - 'label' => constant((string)$value->LABEL), - 'name' => (string)$value->NAME - ]; - } - } - } - - return $basketPages; - } - - public static function getDefaultActionIdByBasketId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['basketId', 'groupId']); - ValidatorModel::stringType($aArgs, ['basketId', 'groupId']); - - $aAction = DatabaseModel::select( - [ - 'select' => ['id_action'], - 'table' => ['actions_groupbaskets'], - 'where' => ['basket_id = ?', 'group_id = ?', 'default_action_list = \'Y\''], - 'data' => [$aArgs['basketId'], $aArgs['groupId']] - ] - ); - - if (empty($aAction[0])) { - return ''; - } - - return $aAction[0]['id_action']; - } - - public static function getResourceNumberByClause(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'clause']); - ValidatorModel::stringType($aArgs, ['userId', 'clause']); - - $count = ResModel::getOnView([ - 'select' => ['COUNT(1)'], - 'where' => [PreparedClauseController::getPreparedClause(['userId' => $aArgs['userId'], 'clause' => $aArgs['clause']])] - ]); - - if (empty($count[0]['count'])) { - return 0; - } - - return $count[0]['count']; - } -} diff --git a/src/app/basket/models/GroupBasketModel.php b/src/app/basket/models/GroupBasketModel.php deleted file mode 100644 index b776169409..0000000000 --- a/src/app/basket/models/GroupBasketModel.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/* -* Copyright 2015 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -namespace Basket\models; - -class GroupBasketModel extends GroupBasketModelAbstract -{ -} diff --git a/src/app/basket/models/GroupBasketModelAbstract.php b/src/app/basket/models/GroupBasketModelAbstract.php deleted file mode 100644 index 01e8d1ac75..0000000000 --- a/src/app/basket/models/GroupBasketModelAbstract.php +++ /dev/null @@ -1,131 +0,0 @@ -<?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 GroupBasket Model Abstract - * @author dev@maarch.org - */ - -namespace Basket\models; - -use Group\models\GroupModel; -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class GroupBasketModelAbstract -{ - public static function get(array $aArgs) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aGroupsBaskets = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['groupbasket'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aGroupsBaskets; - } - - public static function createGroupBasket(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['basketId', 'groupId', 'resultPage']); - ValidatorModel::stringType($aArgs, ['basketId', 'groupId', 'resultPage']); - - DatabaseModel::insert([ - 'table' => 'groupbasket', - 'columnsValues' => [ - 'basket_id' => $aArgs['basketId'], - 'group_id' => $aArgs['groupId'], - 'result_page' => $aArgs['resultPage'] - ] - ]); - - return true; - } - - public static function deleteGroupBasket(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['basketId', 'groupId']); - ValidatorModel::stringType($aArgs, ['basketId', 'groupId']); - ValidatorModel::boolType($aArgs, ['preferences']); - - $group = GroupModel::getByGroupId(['select' => ['id'], 'groupId' => $aArgs['groupId']]); - - DatabaseModel::delete([ - 'table' => 'groupbasket', - 'where' => ['basket_id = ?', 'group_id = ?'], - 'data' => [$aArgs['basketId'], $aArgs['groupId']] - ]); - DatabaseModel::delete([ - 'table' => 'actions_groupbaskets', - 'where' => ['basket_id = ?', 'group_id = ?'], - 'data' => [$aArgs['basketId'], $aArgs['groupId']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_redirect', - 'where' => ['basket_id = ?', 'group_id = ?'], - 'data' => [$aArgs['basketId'], $aArgs['groupId']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_status', - 'where' => ['basket_id = ?', 'group_id = ?'], - 'data' => [$aArgs['basketId'], $aArgs['groupId']] - ]); - - if (!empty($aArgs['preferences'])) { - DatabaseModel::delete([ - 'table' => 'users_baskets_preferences', - 'where' => ['basket_id = ?', 'group_serial_id = ?'], - 'data' => [$aArgs['basketId'], $group['id']] - ]); - } - - return true; - } - - public static function getBasketsByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aGroupsBaskets = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['groupbasket, baskets'], - 'where' => ['groupbasket.group_id = ?', 'groupbasket.basket_id = baskets.basket_id'], - 'data' => [$aArgs['groupId']] - ]); - - return $aGroupsBaskets; - } - - public static function hasBasketByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'basketId']); - ValidatorModel::stringType($aArgs, ['groupId', 'basketId']); - - $aGroupBasket = DatabaseModel::select([ - 'select' => [1], - 'table' => ['groupbasket'], - 'where' => ['group_id = ?', 'basket_id = ?'], - 'data' => [$aArgs['groupId'], $aArgs['basketId']] - ]); - - if (empty($aGroupBasket)) { - return false; - } - - return true; - } -} diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php deleted file mode 100644 index 8140738e39..0000000000 --- a/src/app/contact/controllers/ContactController.php +++ /dev/null @@ -1,383 +0,0 @@ -<?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 Contact Controller - * - * @author dev@maarch.org - */ - -namespace Contact\controllers; - -use Contact\models\ContactFillingModel; -use Contact\models\ContactModel; -use Group\models\ServiceModel; -use SrcCore\models\CoreConfigModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\TextFormatModel; -use SrcCore\models\ValidatorModel; - -class ContactController -{ - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']) && - !ServiceModel::hasService(['id' => 'my_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'use']) && - !ServiceModel::hasService(['id' => 'my_contacts_menu', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu']) && - !ServiceModel::hasService(['id' => 'create_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::notEmpty()->validate($data['firstname']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['lastname']); - $check = $check && Validator::intVal()->notEmpty()->validate($data['contactType']); - $check = $check && Validator::intVal()->notEmpty()->validate($data['contactPurposeId']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['isCorporatePerson']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['email']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if (empty($data['userId'])) { - $data['userId'] = 'superadmin'; - } - if (empty($data['entityId'])) { - $data['entityId'] = 'SUPERADMIN'; - } - if ($data['isCorporatePerson'] != 'Y') { - $data['isCorporatePerson'] = 'N'; - } else { - $data['addressFirstname'] = $data['firstname']; - $data['addressLastname'] = $data['lastname']; - $data['addressTitle'] = $data['title']; - $data['addressFunction'] = $data['function']; - unset($data['firstname'], $data['lastname'], $data['title'], $data['function']); - } - - if (empty($data['isPrivate'])) { - $data['isPrivate'] = 'N'; - } elseif ($data['isPrivate'] != 'N') { - $data['isPrivate'] = 'Y'; - } - - $contact = ContactModel::getByEmail(['email' => $data['email'], 'select' => ['contacts_v2.contact_id', 'contact_addresses.id']]); - if (!empty($contact['id'])) { - return $response->withJson(['contactId' => $contact['contact_id'], 'addressId' => $contact['id']]); - } - - $contactId = ContactModel::create($data); - - $data['contactId'] = $contactId; - $addressId = ContactModel::createAddress($data); - - if (empty($contactId) || empty($addressId)) { - return $response->withStatus(500)->withJson(['errors' => '[ContactController create] Contact creation has failed']); - } - - return $response->withJson(['contactId' => $contactId, 'addressId' => $addressId]); - } - - public function createAddress(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']) && - !ServiceModel::hasService(['id' => 'my_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'use']) && - !ServiceModel::hasService(['id' => 'update_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'use']) && - !ServiceModel::hasService(['id' => 'my_contacts_menu', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu']) && - !ServiceModel::hasService(['id' => 'create_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $contact = ContactModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($contact)) { - return $response->withStatus(400)->withJson(['errors' => 'Contact does not exist']); - } - - $data = $request->getParams(); - - $check = Validator::intVal()->notEmpty()->validate($data['contactPurposeId']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['email']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if (empty($data['userId'])) { - $data['userId'] = 'superadmin'; - } - if (empty($data['entityId'])) { - $data['entityId'] = 'SUPERADMIN'; - } - $data['addressFirstname'] = $data['firstname']; - $data['addressLastname'] = $data['lastname']; - $data['addressTitle'] = $data['title']; - $data['addressFunction'] = $data['function']; - unset($data['firstname'], $data['lastname'], $data['title'], $data['function']); - - if (empty($data['isPrivate'])) { - $data['isPrivate'] = 'N'; - } elseif ($data['isPrivate'] != 'N') { - $data['isPrivate'] = 'Y'; - } - - $data['contactId'] = $aArgs['id']; - $addressId = ContactModel::createAddress($data); - - return $response->withJson(['addressId' => $addressId]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']) && - !ServiceModel::hasService(['id' => 'update_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'use']) && - !ServiceModel::hasService(['id' => 'my_contacts_menu', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu']) && - !ServiceModel::hasService(['id' => 'create_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $contact = ContactModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - if (empty($contact)) { - return $response->withStatus(400)->withJson(['errors' => 'Contact does not exist']); - } - - $data = $request->getParams(); - unset($data['contact_id'], $data['user_id']); - - ContactModel::update(['set' => $data, 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']]]); - - return $response->withJson(['success' => 'success']); - } - - public function updateAddress(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']) && - !ServiceModel::hasService(['id' => 'update_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'use']) && - !ServiceModel::hasService(['id' => 'my_contacts_menu', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu']) && - !ServiceModel::hasService(['id' => 'create_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $contact = ContactModel::getById(['id' => $aArgs['id'], 'select' => [1]]); - $address = ContactModel::getByAddressId(['addressId' => $aArgs['addressId'], 'select' => [1]]); - if (empty($contact) || empty($address)) { - return $response->withStatus(400)->withJson(['errors' => 'Contact or address do not exist']); - } - - $data = $request->getParams(); - unset($data['contact_id'], $data['id'], $data['user_id']); - - ContactModel::updateAddress(['set' => $data, 'where' => ['contact_id = ?', 'id = ?'], 'data' => [$aArgs['id'], $aArgs['addressId']]]); - - return $response->withJson(['success' => 'success']); - } - - public function getCommunicationByContactId(Request $request, Response $response, array $aArgs) - { - $contact = ContactModel::getCommunicationByContactId([ - 'contactId' => $aArgs['contactId'], - ]); - - return $response->withJson([$contact]); - } - - public function getFilling(Request $request, Response $response) - { - $contactsFilling = ContactFillingModel::get(); - $contactsFilling['rating_columns'] = json_decode($contactsFilling['rating_columns']); - - return $response->withJson(['contactsFilling' => $contactsFilling]); - } - - public function updateFilling(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::boolType()->notEmpty()->validate($data['enable']); - $check = $check && Validator::arrayType()->notEmpty()->validate($data['rating_columns']); - $check = $check && Validator::intVal()->notEmpty()->validate($data['first_threshold']) && $data['first_threshold'] > 0 && $data['first_threshold'] < 99; - $check = $check && Validator::intVal()->notEmpty()->validate($data['second_threshold']) && $data['second_threshold'] > 1 && $data['second_threshold'] < 100; - $check = $check && $data['first_threshold'] < $data['second_threshold']; - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $data['rating_columns'] = json_encode($data['rating_columns']); - - ContactFillingModel::update($data); - - return $response->withJson(['success' => 'success']); - } - - public static function getFillingRate(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contact']); - ValidatorModel::arrayType($aArgs, ['contact']); - - $contactsFilling = ContactFillingModel::get(); - $contactsFilling['rating_columns'] = json_decode($contactsFilling['rating_columns']); - - if ($contactsFilling['enable'] && !empty($contactsFilling['rating_columns'])) { - $percent = 0; - foreach ($contactsFilling['rating_columns'] as $ratingColumn) { - if (!empty($aArgs['contact'][$ratingColumn])) { - $percent++; - } - } - $percent = $percent * 100 / count($contactsFilling['rating_columns']); - if ($percent <= $contactsFilling['first_threshold']) { - $color = '#f87474'; - } elseif ($percent <= $contactsFilling['second_threshold']) { - $color = '#f6cd81'; - } else { - $color = '#ccffcc'; - } - - return ['rate' => $percent, 'color' => $color]; - } - - return []; - } - - public static function formatContactAddressAfnor(array $aArgs) - { - $formattedAddress = ''; - - // Entete pour societe - if ($aArgs['is_corporate_person'] == 'Y') { - // Ligne 1 - $formattedAddress .= substr($aArgs['society'], 0, 38)."\n"; - - // Ligne 2 - if (!empty($aArgs['title']) || !empty($aArgs['firstname']) || !empty($aArgs['lastname'])) { - $formattedAddress .= ContactController::controlLengthNameAfnor([ - 'title' => $aArgs['title'], - 'fullName' => $aArgs['firstname'].' '.$aArgs['lastname'], - 'strMaxLength' => 38, ])."\n"; - } - - // Ligne 3 - if (!empty($aArgs['address_complement'])) { - $formattedAddress .= substr($aArgs['address_complement'], 0, 38)."\n"; - } - } else { - // Ligne 1 - $formattedAddress .= ContactController::controlLengthNameAfnor([ - 'title' => $aArgs['contact_title'], - 'fullName' => $aArgs['contact_firstname'].' '.$aArgs['contact_lastname'], - 'strMaxLength' => 38, ])."\n"; - - // Ligne 2 - if (!empty($aArgs['occupancy'])) { - $formattedAddress .= substr($aArgs['occupancy'], 0, 38)."\n"; - } - - // Ligne 3 - if (!empty($aArgs['address_complement'])) { - $formattedAddress .= substr($aArgs['address_complement'], 0, 38)."\n"; - } - } - // Ligne 4 - if (!empty($aArgs['address_num'])) { - $aArgs['address_num'] = TextFormatModel::normalize(['string' => $aArgs['address_num']]); - $aArgs['address_num'] = preg_replace('/[^\w]/s', ' ', $aArgs['address_num']); - $aArgs['address_num'] = strtoupper($aArgs['address_num']); - } - - if (!empty($aArgs['address_street'])) { - $aArgs['address_street'] = TextFormatModel::normalize(['string' => $aArgs['address_street']]); - $aArgs['address_street'] = preg_replace('/[^\w]/s', ' ', $aArgs['address_street']); - $aArgs['address_street'] = strtoupper($aArgs['address_street']); - } - - $formattedAddress .= substr($aArgs['address_num'].' '.$aArgs['address_street'], 0, 38)."\n"; - - // Ligne 5 - // $formattedAddress .= "\n"; - - // Ligne 6 - $aArgs['address_postal_code'] = strtoupper($aArgs['address_postal_code']); - $aArgs['address_town'] = strtoupper($aArgs['address_town']); - $formattedAddress .= substr($aArgs['address_postal_code'].' '.$aArgs['address_town'], 0, 38); - - return $formattedAddress; - } - - public static function controlLengthNameAfnor(array $aArgs) - { - $aCivility = ContactController::getContactCivility(); - if (strlen($aArgs['title'].' '.$aArgs['fullName']) > $aArgs['strMaxLength']) { - $aArgs['title'] = $aCivility[$aArgs['title']]['abbreviation']; - } else { - $aArgs['title'] = $aCivility[$aArgs['title']]['label']; - } - - return substr($aArgs['title'].' '.$aArgs['fullName'], 0, $aArgs['strMaxLength']); - } - - public static function getContactCivility() - { - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/entreprise.xml']); - - $aCivility = []; - if ($loadedXml != false) { - $result = $loadedXml->xpath('/ROOT/titles'); - foreach ($result as $title) { - foreach ($title as $value) { - $aCivility[(string) $value->id] = [ - 'label' => (string) $value->label, - 'abbreviation' => (string) $value->abbreviation, - ]; - } - } - } - - return $aCivility; - } - - public function availableReferential() - { - $customId = CoreConfigModel::getCustomId(); - - $referentialDirectory = 'referential/ban/indexes'; - if (is_dir("custom/{$customId}/".$referentialDirectory)) { - $customFilesDepartments = scandir("custom/{$customId}/".$referentialDirectory); - } - if (is_dir($referentialDirectory)) { - $filesDepartments = scandir($referentialDirectory); - } - - $departments = []; - if (!empty($customFilesDepartments)) { - foreach ($customFilesDepartments as $value) { - if ($value != '.' && $value != '..' && is_writable("custom/{$customId}/".$referentialDirectory.'/'.$value)) { - $departments[] = $value; - } - } - } - if (!empty($filesDepartments)) { - foreach ($filesDepartments as $value) { - if ($value != '.' && $value != '..' && !in_array($value, $departments) && is_writable($referentialDirectory.'/'.$value)) { - $departments[] = $value; - } - } - } - - if (!empty($departments)) { - sort($departments, SORT_NUMERIC); - - return $departments; - } else { - return false; - } - } -} diff --git a/src/app/contact/controllers/ContactGroupController.php b/src/app/contact/controllers/ContactGroupController.php deleted file mode 100644 index d20c86ad1e..0000000000 --- a/src/app/contact/controllers/ContactGroupController.php +++ /dev/null @@ -1,330 +0,0 @@ -<?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 Contact Group Controller - * @author dev@maarch.org - */ - -namespace Contact\controllers; - -use Contact\models\ContactGroupModel; -use Contact\models\ContactModel; -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\ValidatorModel; -use User\models\UserModel; - -class ContactGroupController -{ - public function get(Request $request, Response $response) - { - $hasService = ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - - $contactsGroups = ContactGroupModel::get(); - foreach ($contactsGroups as $key => $contactsGroup) { - if (!$contactsGroup['public'] && $user['id'] != $contactsGroup['owner'] && !$hasService) { - unset($contactsGroups[$key]); - continue; - } - $contactsGroups[$key]['position'] = $key; - $contactsGroups[$key]['labelledOwner'] = UserModel::getLabelledUserById(['id' => $contactsGroup['owner']]); - $contactsGroups[$key]['nbContacts'] = ContactGroupModel::getListById(['id' => $contactsGroup['id'], 'select' => ['COUNT(1)']])[0]['count']; - } - - return $response->withJson(['contactsGroups' => array_values($contactsGroups)]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - $contactsGroup = ContactGroupModel::getById(['id' => $aArgs['id']]); - if (empty($contactsGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Contacts group not found']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - if ($contactsGroup['owner'] != $user['id'] && !ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $contactsGroup['labelledOwner'] = UserModel::getLabelledUserById(['id' => $contactsGroup['owner']]); - $contactsGroup['contacts'] = ContactGroupController::getFormattedListById(['id' => $aArgs['id']])['list']; - $contactsGroup['nbContacts'] = count($contactsGroup['contacts']); - - return $response->withJson(['contactsGroup' => $contactsGroup]); - } - - public function create(Request $request, Response $response) - { - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['description']); - $check = $check && Validator::boolType()->validate($data['public']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - $existingGroup = ContactGroupModel::get(['select' => [1], 'where' => ['label = ?', 'owner = ?'], 'data' => [$data['label'], $user['id']]]); - if (!empty($existingGroup)) { - return $response->withStatus(400)->withJson(['errors' => _CONTACTS_GROUP_LABEL_ALREADY_EXISTS]); - } - - $data['public'] = $data['public'] ? 'true' : 'false'; - $data['owner'] = $user['id']; - $data['entity_owner'] = ($GLOBALS['userId'] == 'superadmin' ? 'superadmin' : UserModel::getPrimaryEntityByUserId(['userId' => $GLOBALS['userId']])['entity_id']); - - $id = ContactGroupModel::create($data); - - HistoryController::add([ - 'tableName' => 'contacts_groups', - 'recordId' => $id, - 'eventType' => 'ADD', - 'info' => _CONTACTS_GROUP_ADDED . " : {$data['label']}", - 'moduleId' => 'contact', - 'eventId' => 'contactsGroupCreation', - ]); - - return $response->withJson(['contactsGroup' => $id]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - $contactsGroup = ContactGroupModel::getById(['select' => ['owner'], 'id' => $aArgs['id']]); - if (empty($contactsGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Contacts Group does not exist']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - if ($contactsGroup['owner'] != $user['id'] && !ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['description']); - $check = $check && Validator::boolType()->validate($data['public']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $existingGroup = ContactGroupModel::get(['select' => [1], 'where' => ['label = ?', 'owner = ?', 'id != ?'], 'data' => [$data['label'], $user['id'], $aArgs['id']]]); - if (!empty($existingGroup)) { - return $response->withStatus(400)->withJson(['errors' => _CONTACTS_GROUP_LABEL_ALREADY_EXISTS]); - } - - $data['id'] = $aArgs['id']; - $data['public'] = $data['public'] ? 'true' : 'false'; - - ContactGroupModel::update($data); - - HistoryController::add([ - 'tableName' => 'contacts_groups', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _CONTACTS_GROUP_UPDATED . " : {$data['label']}", - 'moduleId' => 'contact', - 'eventId' => 'contactsGroupModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - $contactsGroup = ContactGroupModel::getById(['select' => ['owner'], 'id' => $aArgs['id']]); - if (empty($contactsGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Contacts Group does not exist']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - if ($contactsGroup['owner'] != $user['id'] && !ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - ContactGroupModel::delete(['id' => $aArgs['id']]); - - HistoryController::add([ - 'tableName' => 'contacts_groups', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _CONTACTS_GROUP_DELETED . " : {$aArgs['id']}", - 'moduleId' => 'contact', - 'eventId' => 'contactsGroupSuppression', - ]); - - $contactsGroups = ContactGroupModel::get(); - foreach ($contactsGroups as $key => $contactsGroup) { - $contactsGroups[$key]['labelledOwner'] = UserModel::getLabelledUserById(['id' => $contactsGroup['owner']]); - } - - return $response->withJson(['success' => 'success']); - } - - public function addContacts(Request $request, Response $response, array $aArgs) - { - $contactsGroup = ContactGroupModel::getById(['select' => ['owner', 'label'], 'id' => $aArgs['id']]); - if (empty($contactsGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Contacts Group does not exist']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - if ($contactsGroup['owner'] != $user['id'] && !ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::arrayType()->notEmpty()->validate($data['contacts']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $rawList = ContactGroupModel::getListById(['select' => ['contact_addresses_id'], 'id' => $aArgs['id']]); - $list = []; - foreach ($rawList as $rawListItem) { - $list[] = $rawListItem['contact_addresses_id']; - } - - foreach ($data['contacts'] as $addressId) { - if (!in_array($addressId, $list)) { - ContactGroupModel::addContact(['id' => $aArgs['id'], 'addressId' => $addressId]); - } - } - - HistoryController::add([ - 'tableName' => 'contacts_groups_lists', - 'recordId' => $aArgs['id'], - 'eventType' => 'ADD', - 'info' => _CONTACTS_GROUP_LIST_ADDED . " : {$contactsGroup['label']}", - 'moduleId' => 'contact', - 'eventId' => 'contactsGroupListCreation', - ]); - - $contactsGroup = ContactGroupModel::getById(['id' => $aArgs['id']]); - $contactsGroup['labelledOwner'] = UserModel::getLabelledUserById(['id' => $contactsGroup['owner']]); - $contactsGroup['contacts'] = ContactGroupController::getFormattedListById(['id' => $aArgs['id']])['list']; - - return $response->withJson(['contactsGroup' => $contactsGroup]); - } - - public function deleteContact(Request $request, Response $response, array $aArgs) - { - $contactsGroup = ContactGroupModel::getById(['select' => ['owner', 'label'], 'id' => $aArgs['id']]); - if (empty($contactsGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Contacts Group does not exist']); - } - - $user = UserModel::getByUserId(['select' => ['id'], 'userId' => $GLOBALS['userId']]); - if ($contactsGroup['owner'] != $user['id'] && !ServiceModel::hasService(['id' => 'admin_contacts', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - ContactGroupModel::deleteContact(['id' => $aArgs['id'], 'addressId' => $aArgs['addressId']]); - - HistoryController::add([ - 'tableName' => 'contacts_groups_lists', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _CONTACTS_GROUP_LIST_DELETED . " : {$contactsGroup['label']}", - 'moduleId' => 'contact', - 'eventId' => 'contactsGroupListSuppression', - ]); - - return $response->withJson(['success' => 'success']); - } - - public static function getFormattedListById(array $aArgs) - { - $list = ContactGroupModel::getListById(['select' => ['contact_addresses_id'], 'id' => $aArgs['id']]); - - $contacts = []; - $position = 0; - foreach ($list as $listItem) { - $contact = ContactModel::getOnView([ - 'select' => [ - 'ca_id', 'firstname', 'lastname', 'contact_lastname', 'contact_firstname', 'society', 'address_num', - 'address_street', 'address_town', 'address_postal_code', 'is_corporate_person' - ], - 'where' => ['ca_id = ?'], - 'data' => [$listItem['contact_addresses_id']] - ]); - - if (!empty($contact[0])) { - $contacts[] = ContactGroupController::getFormattedContact(['contact' => $contact[0], 'position' => $position])['contact']; - ++$position; - } - } - - return ['list' => $contacts]; - } - - public static function getFormattedContact(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contact']); - ValidatorModel::arrayType($aArgs, ['contact']); - ValidatorModel::intType($aArgs, ['position']); - - $address = ''; - if (empty($aArgs['position'])) { - $aArgs['position'] = 0; - } - if ($aArgs['contact']['is_corporate_person'] == 'Y') { - $address.= $aArgs['contact']['firstname']; - $address.= (empty($address) ? $aArgs['contact']['lastname'] : " {$aArgs['contact']['lastname']}"); - if (!empty($address)) { - $address.= ', '; - } - if (!empty($aArgs['contact']['address_num'])) { - $address.= $aArgs['contact']['address_num'] . ' '; - } - if (!empty($aArgs['contact']['address_street'])) { - $address.= $aArgs['contact']['address_street'] . ' '; - } - if (!empty($aArgs['contact']['address_town'])) { - $address.= $aArgs['contact']['address_town'] . ' '; - } - if (!empty($aArgs['contact']['address_postal_code'])) { - $address.= $aArgs['contact']['address_postal_code'] . ' '; - } - $contact = [ - 'position' => $aArgs['position'], - 'addressId' => $aArgs['contact']['ca_id'], - 'contact' => $aArgs['contact']['society'], - 'address' => $address - ]; - } else { - if (!empty($aArgs['contact']['address_num'])) { - $address.= $aArgs['contact']['address_num'] . ' '; - } - if (!empty($aArgs['contact']['address_street'])) { - $address.= $aArgs['contact']['address_street'] . ' '; - } - if (!empty($aArgs['contact']['address_town'])) { - $address.= $aArgs['contact']['address_town'] . ' '; - } - if (!empty($aArgs['contact']['address_postal_code'])) { - $address.= $aArgs['contact']['address_postal_code'] . ' '; - } - - $contact = [ - 'position' => $aArgs['position'], - 'addressId' => $aArgs['contact']['ca_id'], - 'contact' => "{$aArgs['contact']['contact_firstname']} {$aArgs['contact']['contact_lastname']} {$aArgs['contact']['society']}", - 'address' => $address - ]; - } - - return ['contact' => $contact]; - } -} diff --git a/src/app/contact/controllers/ContactTypeController.php b/src/app/contact/controllers/ContactTypeController.php deleted file mode 100644 index 11a7e7940c..0000000000 --- a/src/app/contact/controllers/ContactTypeController.php +++ /dev/null @@ -1,29 +0,0 @@ -<?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 Contact Type Controller - * @author dev@maarch.org - */ - -namespace Contact\controllers; - -use Contact\models\ContactTypeModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class ContactTypeController -{ - public function get(Request $request, Response $response) - { - $contactsTypes = ContactTypeModel::get(); - - return $response->withJson(['contactsTypes' => $contactsTypes]); - } -} diff --git a/src/app/contact/models/ContactFillingModel.php b/src/app/contact/models/ContactFillingModel.php deleted file mode 100644 index 58614e9d2c..0000000000 --- a/src/app/contact/models/ContactFillingModel.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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 Contact Filling Model -* @author dev@maarch.org -*/ - -namespace Contact\models; - - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -class ContactFillingModel -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $rule = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contacts_filling'] - ]); - - return $rule[0]; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['rating_columns']); - ValidatorModel::boolType($aArgs, ['enable']); - ValidatorModel::stringType($aArgs, ['rating_columns']); - ValidatorModel::intVal($aArgs, ['first_threshold', 'second_threshold']); - - $aArgs['enable'] = $aArgs['enable'] ? 'true' : 'false'; - - DatabaseModel::update([ - 'table' => 'contacts_filling', - 'set' => [ - 'enable' => $aArgs['enable'], - 'rating_columns' => $aArgs['rating_columns'], - 'first_threshold' => $aArgs['first_threshold'], - 'second_threshold' => $aArgs['second_threshold'] - ], - 'where' => ['1 = 1'] - ]); - - return true; - } -} diff --git a/src/app/contact/models/ContactGroupModel.php b/src/app/contact/models/ContactGroupModel.php deleted file mode 100644 index fd3ec0639f..0000000000 --- a/src/app/contact/models/ContactGroupModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Contact Group Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -class ContactGroupModel extends ContactGroupModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/contact/models/ContactGroupModelAbstract.php b/src/app/contact/models/ContactGroupModelAbstract.php deleted file mode 100644 index a5d4d3a468..0000000000 --- a/src/app/contact/models/ContactGroupModelAbstract.php +++ /dev/null @@ -1,158 +0,0 @@ -<?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 Contact Group Abstract Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ContactGroupModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contacts_groups'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'] - ]); - - return $aReturn; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aContactGroup = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contacts_groups'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aContactGroup[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['label', 'description', 'public', 'owner', 'entity_owner']); - ValidatorModel::stringType($aArgs, ['label', 'description', 'public', 'entity_owner']); - ValidatorModel::intVal($aArgs, ['owner']); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'contacts_groups_id_seq']); - DatabaseModel::insert([ - 'table' => 'contacts_groups', - 'columnsValues' => [ - 'id' => $nextSequenceId, - 'label' => $aArgs['label'], - 'description' => $aArgs['description'], - 'public' => $aArgs['public'], - 'owner' => $aArgs['owner'], - 'entity_owner' => $aArgs['entity_owner'], - ] - ]); - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'label', 'description', 'public']); - ValidatorModel::stringType($aArgs, ['label', 'description', 'public']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::update([ - 'table' => 'contacts_groups', - 'set' => [ - 'label' => $aArgs['label'], - 'description' => $aArgs['description'], - 'public' => $aArgs['public'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'contacts_groups', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'contacts_groups_lists', - 'where' => ['contacts_groups_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function getListById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aList = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contacts_groups_lists'], - 'where' => ['contacts_groups_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aList; - } - - public static function addContact(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'addressId']); - ValidatorModel::intVal($aArgs, ['id', 'addressId']); - - DatabaseModel::insert([ - 'table' => 'contacts_groups_lists', - 'columnsValues' => [ - 'contacts_groups_id' => $aArgs['id'], - 'contact_addresses_id' => $aArgs['addressId'] - ] - ]); - - return true; - } - - public static function deleteContact(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'addressId']); - ValidatorModel::intVal($aArgs, ['id', 'addressId']); - - DatabaseModel::delete([ - 'table' => 'contacts_groups_lists', - 'where' => ['contacts_groups_id = ?', 'contact_addresses_id = ?'], - 'data' => [$aArgs['id'], $aArgs['addressId']] - ]); - - return true; - } -} diff --git a/src/app/contact/models/ContactModel.php b/src/app/contact/models/ContactModel.php deleted file mode 100644 index 5c898c4bb6..0000000000 --- a/src/app/contact/models/ContactModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Contact Model -* @author dev@maarch.org -*/ - -namespace Contact\models; - - -class ContactModel extends ContactModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/contact/models/ContactModelAbstract.php b/src/app/contact/models/ContactModelAbstract.php deleted file mode 100644 index d0b6e58f2d..0000000000 --- a/src/app/contact/models/ContactModelAbstract.php +++ /dev/null @@ -1,505 +0,0 @@ -<?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 Contact Model -* @author dev@maarch.org -*/ - -namespace Contact\models; - -use Resource\models\ResModel; -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class ContactModelAbstract -{ - public static function getOnView(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aContacts = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['view_contacts'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aContacts; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aContact = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contacts_v2'], - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['id']], - ]); - - if (empty($aContact[0])) { - return []; - } - - return $aContact[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactType', 'isCorporatePerson', 'userId', 'entityId']); - ValidatorModel::intVal($aArgs, ['contactType']); - ValidatorModel::stringType($aArgs, [ - 'firstname', 'lastname', 'isCorporatePerson', 'society', - 'societyShort', 'title', 'function', 'otherData', 'userId', 'entityId' - ]); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'contact_v2_id_seq']); - - DatabaseModel::insert([ - 'table' => 'contacts_v2', - 'columnsValues' => [ - 'contact_id' => $nextSequenceId, - 'contact_type' => $aArgs['contactType'], - 'is_corporate_person' => $aArgs['isCorporatePerson'], - 'society' => $aArgs['society'], - 'society_short' => $aArgs['societyShort'], - 'firstname' => $aArgs['firstname'], - 'lastname' => $aArgs['lastname'], - 'title' => $aArgs['title'], - 'function' => $aArgs['function'], - 'other_data' => $aArgs['otherData'], - 'user_id' => $aArgs['userId'], - 'entity_id' => $aArgs['entityId'], - 'creation_date' => 'CURRENT_TIMESTAMP', - 'enabled' => 'Y' - - ] - ]); - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'contacts_v2', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function createAddress(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactId', 'contactPurposeId', 'userId', 'entityId', 'isPrivate', 'email']); - ValidatorModel::intVal($aArgs, ['contactId', 'contactPurposeId']); - ValidatorModel::stringType($aArgs, [ - 'departement', 'addressFirstname', 'addressLastname', 'addressTitle', 'addressFunction', 'occupancy', 'addressNum', 'addressStreet', 'addressComplement', - 'addressTown', 'addressZip', 'addressCountry', 'phone', 'email', 'website', 'salutationHeader', 'salutationFooter', 'addressOtherData', - 'userId', 'entityId', 'isPrivate', 'external_contact_id' - ]); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'contact_addresses_id_seq']); - - DatabaseModel::insert([ - 'table' => 'contact_addresses', - 'columnsValues' => [ - 'id' => $nextSequenceId, - 'contact_id' => $aArgs['contactId'], - 'contact_purpose_id' => $aArgs['contactPurposeId'], - 'departement' => $aArgs['departement'], - 'firstname' => $aArgs['addressFirstname'], - 'lastname' => $aArgs['addressLastname'], - 'title' => $aArgs['addressTitle'], - 'function' => $aArgs['addressFunction'], - 'occupancy' => $aArgs['occupancy'], - 'address_num' => $aArgs['addressNum'], - 'address_street' => $aArgs['addressStreet'], - 'address_complement' => $aArgs['addressComplement'], - 'address_town' => $aArgs['addressTown'], - 'address_postal_code' => $aArgs['addressZip'], - 'address_country' => $aArgs['addressCountry'], - 'phone' => $aArgs['phone'], - 'email' => $aArgs['email'], - 'website' => $aArgs['website'], - 'salutation_header' => $aArgs['salutationHeader'], - 'salutation_footer' => $aArgs['salutationFooter'], - 'other_data' => $aArgs['otherData'], - 'user_id' => $aArgs['userId'], - 'entity_id' => $aArgs['entityId'], - 'external_contact_id' => $aArgs['external_contact_id'], - 'is_private' => $aArgs['isPrivate'], - 'enabled' => 'Y' - ] - ]); - - return $nextSequenceId; - } - - public static function updateAddress(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'contact_addresses', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getFullAddressById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['addressId']); - ValidatorModel::intVal($aArgs, ['addressId']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['view_contacts'], - 'where' => ['ca_id = ?'], - 'data' => [$aArgs['addressId']], - ]); - - return $aReturn; - } - - public static function getContactFullLabel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['addressId']); - ValidatorModel::intVal($aArgs, ['addressId']); - - $fullAddress = ContactModel::getFullAddressById($aArgs); - $fullAddress = $fullAddress[0]; - - if ($fullAddress['is_corporate_person'] == 'Y') { - $contactName = strtoupper($fullAddress['society']) . ' ' ; - if (!empty($fullAddress['society_short'])) { - $contactName .= '('.$fullAddress['society_short'].') '; - } - } else { - $contactName = strtoupper($fullAddress['contact_lastname']) . ' ' . $fullAddress['contact_firstname'] . ' '; - if (!empty($fullAddress['society'])) { - $contactName .= '(' . $fullAddress['society'] . ') '; - } - } - if (!empty($fullAddress['external_contact_id'])) { - $contactName .= ' - <b>' . $fullAddress['external_contact_id'] . '</b> '; - } - if ($fullAddress['is_private'] == 'Y') { - $contactName .= '('._CONFIDENTIAL_ADDRESS.')'; - } else { - $contactName .= '- ' . $fullAddress['contact_purpose_label'] . ' : '; - if (!empty($fullAddress['lastname']) || !empty($fullAddress['firstname'])) { - $contactName .= $fullAddress['lastname'] . ' ' . $fullAddress['firstname'] . ' '; - } - if (!empty($fullAddress['address_num']) || !empty($fullAddress['address_street']) || !empty($fullAddress['address_postal_code']) || !empty($fullAddress['address_town'])) { - $contactName .= ', '.$fullAddress['address_num'] .' ' . $fullAddress['address_street'] .' ' . $fullAddress['address_postal_code'] .' ' . strtoupper($fullAddress['address_town']); - } - } - - return $contactName; - } - - public static function getContactCommunication(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactId']); - ValidatorModel::intVal($aArgs, ['contactId']); - - $aReturn = DatabaseModel::select([ - 'select' => ['*'], - 'table' => ['contact_communication'], - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['contactId']], - ]); - - if (empty($aReturn)) { - return ""; - } else { - $aReturn[0]['value'] = trim(trim($aReturn[0]['value']), '/'); - return $aReturn[0]; - } - } - - public static function getContactIdByCommunicationValue(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['communicationValue']); - - $aReturn = DatabaseModel::select([ - 'select' => ['*'], - 'table' => ['contact_communication'], - 'where' => ['value = ?'], - 'data' => [$aArgs['communicationValue']], - ]); - - if (empty($aReturn)) { - return ''; - } else { - return $aReturn[0]; - } - } - - public static function createContactCommunication(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactId', 'type', 'value']); - ValidatorModel::intVal($aArgs, ['contactId']); - - DatabaseModel::insert([ - 'table' => 'contact_communication', - 'columnsValues' => [ - 'contact_id' => $aArgs['contactId'], - 'type' => $aArgs['type'], - 'value' => trim(trim($aArgs['value']), '/') - ] - ]); - - return true; - } - - public static function getLabelledContactWithAddress(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactId', 'addressId']); - ValidatorModel::intVal($aArgs, ['contactId', 'addressId']); - - $rawContact = ContactModel::getByAddressId(['addressId' => $aArgs['addressId'], 'select' => ['firstname', 'lastname']]); - - $labelledContact = ''; - if (!empty($rawContact)) { - if (empty($rawContact['firstname']) && empty($rawContact['lastname'])) { - $rawContact = ContactModel::getById(['id' => $aArgs['contactId'], 'select' => ['firstname', 'lastname']]); - } - $labelledContact = $rawContact['firstname']. ' ' .$rawContact['lastname']; - } - - return $labelledContact; - } - - public static function getByEmail(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['email']); - ValidatorModel::stringType($aArgs, ['email']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aContacts = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contact_addresses, contacts_v2'], - 'where' => ['email = ?', 'contact_addresses.enabled = ?', 'contact_addresses.contact_id = contacts_v2.contact_id'], - 'data' => [$aArgs['email'], 'Y'], - 'order_by' => ['creation_date'], - ]); - - if (empty($aContacts[0])) { - return []; - } - - return $aContacts[0]; - } - - public static function purgeContact($aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $firstCount = ResModel::getOnView([ - 'select' => ['count(*) as count'], - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['id']], - ]); - - $secondCount = DatabaseModel::select([ - 'select' => ['count(*) as count'], - 'table' => ['contacts_res'], - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['id']], - ]); - - if ($firstCount[0]['count'] < 1 && $secondCount[0]['count'] < 1) { - DatabaseModel::delete([ - 'table' => 'contact_addresses', - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'contacts_v2', - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['id']] - ]); - } - } - - public static function getByAddressId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['addressId']); - ValidatorModel::intVal($aArgs, ['addressId']); - - $aContact = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contact_addresses'], - 'where' => ['id = ?'], - 'data' => [$aArgs['addressId']], - ]); - - if (empty($aContact[0])) { - return []; - } - - return $aContact[0]; - } - - public static function getCommunicationByContactId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['contactId']); - ValidatorModel::stringType($aArgs, ['contactId']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contact_communication'], - 'where' => ['contact_id = ?'], - 'data' => [$aArgs['contactId']], - ]); - - return $aReturn[0]; - } - - public static function CreateContactM2M(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['data', 'contactCommunication']); - - $currentContactId = "0"; - $currentAddressId = "0"; - $formatedDataContact = []; - $formatedDataAddress = []; - - foreach ($aArgs['data'] as $key => $value) { - // On regarde si le contact existe déjà - if (strtoupper($value['column']) == strtoupper('external_contact_id') && ($value['value'] <> "" || $value['value'] <> null)) { - try { - $res = DatabaseModel::select([ - 'select' => ['contact_id', 'ca_id'], - 'table' => ['view_contacts'], - 'where' => ['external_contact_id = ?', 'enabled = ?'], - 'data' => [$value['value'], 'Y'], - ]); - - $res = $res[0]; - if (!empty($res['ca_id'])) { - $contact_exists = true; - $currentContactId = $res['contact_id']; - $currentAddressId = $res['ca_id']; - } else { - $contact_exists = false; - } - } catch (\Exception $e) { - $returnResArray = [ - 'returnCode' => (int) -1, - 'contactId' => '', - 'addressId' => '', - 'contactInfo' => '', - 'error' => 'unknown error: ' . $e->getMessage() - ]; - return $returnResArray; - } - } - - $aArgs['data'][$key]['column'] = strtolower($value['column']); - - if ($value['table'] == "contacts_v2") { - $formatedDataContact[$value['column']] = $value['value']; - } elseif ($value['table'] == "contact_addresses") { - $formatedDataAddress[$value['column']] = $value['value']; - } - } - - // Si le contact n'existe pas, on le créé - if (!$contact_exists) { - $contactInfo = ContactModel::getContactIdByCommunicationValue(['communicationValue' => $aArgs['contactCommunication']]); - if (!empty($contactInfo)) { - $currentContactId = $contactInfo['contact_id']; - } else { - try { - $currentContactId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'contact_v2_id_seq']); - $formatedDataContact['user_id'] = 'superadmin'; - $formatedDataContact['entity_id'] = 'SUPERADMIN'; - $formatedDataContact['creation_date'] = 'CURRENT_TIMESTAMP'; - $formatedDataContact['contact_id'] = $currentContactId; - - DatabaseModel::insert([ - 'table' => 'contacts_v2', - 'columnsValues' => $formatedDataContact - ]); - } catch (\Exception $e) { - $returnResArray = [ - 'returnCode' => (int) -1, - 'contactId' => 'ERROR', - 'addressId' => 'ERROR', - 'contactInfo' => '', - 'error' => 'contact creation error : '. $e->getMessage(), - ]; - - return $returnResArray; - } - } - try { - $currentAddressId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'contact_addresses_id_seq']); - $formatedDataAddress['user_id'] = 'superadmin'; - $formatedDataAddress['entity_id'] = 'SUPERADMIN'; - $formatedDataAddress['contact_id'] = $currentContactId; - $formatedDataAddress['id'] = $currentAddressId; - - DatabaseModel::insert([ - 'table' => 'contact_addresses', - 'columnsValues' => $formatedDataAddress - ]); - } catch (\Exception $e) { - $returnResArray = [ - 'returnCode' => (int) -1, - 'contactId' => $currentContactId, - 'addressId' => 'ERROR', - 'contactInfo' => '', - 'error' => 'address creation error : '. $e->getMessage(), - ]; - - return $returnResArray; - } - $returnResArray = [ - 'returnCode' => (int) 0, - 'contactId' => $currentContactId, - 'addressId' => $currentAddressId, - 'contactInfo' => 'contact created and attached to doc ... ', - 'error' => '' - ]; - - return $returnResArray; - } else { - $returnResArray = [ - 'returnCode' => (int) 0, - 'contactId' => $currentContactId, - 'addressId' => $currentAddressId, - 'contactInfo' => 'contact already exist, attached to doc ... ', - 'error' => '' - ]; - - return $returnResArray; - } - } -} diff --git a/src/app/contact/models/ContactTypeModel.php b/src/app/contact/models/ContactTypeModel.php deleted file mode 100644 index 0fce1031d0..0000000000 --- a/src/app/contact/models/ContactTypeModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Contact Type Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -class ContactTypeModel extends ContactTypeModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/contact/models/ContactTypeModelAbstract.php b/src/app/contact/models/ContactTypeModelAbstract.php deleted file mode 100644 index b904810b1c..0000000000 --- a/src/app/contact/models/ContactTypeModelAbstract.php +++ /dev/null @@ -1,35 +0,0 @@ -<?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 Contact Type Abstract Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ContactTypeModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - - $aTypes = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contact_types'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'] - ]); - - return $aTypes; - } -} diff --git a/src/app/contentManagement/controllers/JnlpController.php b/src/app/contentManagement/controllers/JnlpController.php deleted file mode 100644 index 6e9992c007..0000000000 --- a/src/app/contentManagement/controllers/JnlpController.php +++ /dev/null @@ -1,340 +0,0 @@ -<?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 Jnlp Controller - * - * @author dev@maarch.org - */ - -namespace ContentManagement\controllers; - -use Docserver\models\DocserverModel; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; -use Template\models\TemplateModel; - -require_once 'core/class/Url.php'; - -class JnlpController -{ - public function generateJnlp(Request $request, Response $response) - { - $data = $request->getParams(); - - $coreUrl = str_replace('rest/', '', \Url::coreurl()); - $tmpPath = CoreConfigModel::getTmpPath(); - $jnlpUniqueId = DatabaseModel::uniqueId(); - $jnlpFileName = $GLOBALS['userId'] . '_maarchCM_' . $jnlpUniqueId; - $jnlpFileNameExt = $jnlpFileName . '.jnlp'; - - $allCookies = ''; - foreach($_COOKIE as $key => $value) { - if (!empty($allCookies)) { - $allCookies .= '; '; - } - $allCookies .= $key . '=' . str_replace(' ', '+', $value); - } - if (!empty($data['cookies'])) { - if (!empty($allCookies)) { - $allCookies .= '; '; - } - $allCookies .= $data['cookies']; - } - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/content_management/xml/config.xml']); - $jarPath = $coreUrl; - if ($loadedXml && !empty((string)$loadedXml->CONFIG[0]->jar_path)) { - $jarPath = (string)$loadedXml->CONFIG[0]->jar_path; - } - - $jnlpDocument = new \DomDocument('1.0', 'UTF-8'); - - $tagJnlp = $jnlpDocument->createElement('jnlp'); - - $newAttribute = $jnlpDocument->createAttribute('spec'); - $newAttribute->value = '6.0+'; - $tagJnlp->appendChild($newAttribute); - - $newAttribute = $jnlpDocument->createAttribute('codebase'); - $newAttribute->value = $tmpPath; - $tagJnlp->appendChild($newAttribute); - - $tagInformation = $jnlpDocument->createElement('information'); - $tagTitle = $jnlpDocument->createElement('title', 'Editeur de modèle de document'); - $tagVendor = $jnlpDocument->createElement('vendor', 'MAARCH'); - $tagOffline = $jnlpDocument->createElement('offline-allowed'); - $tagSecurity = $jnlpDocument->createElement('security'); - $tagPermissions = $jnlpDocument->createElement('all-permissions'); - $tagResources = $jnlpDocument->createElement('resources'); - $tagJ2se = $jnlpDocument->createElement('j2se'); - - $newAttribute = $jnlpDocument->createAttribute('version'); - $newAttribute->value = '1.6+'; - $tagJ2se->appendChild($newAttribute); - - $tagJar1 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $coreUrl . '/modules/content_management/dist/maarchCM.jar'; - $tagJar1->appendChild($newAttribute); - $newAttribute = $jnlpDocument->createAttribute('main'); - $newAttribute->value = 'true'; - $tagJar1->appendChild($newAttribute); - - $tagJar2 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/httpclient-4.5.2.jar'; - $tagJar2->appendChild($newAttribute); - - $tagJar3 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/httpclient-cache-4.5.2.jar'; - $tagJar3->appendChild($newAttribute); - - $tagJar4 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/httpclient-win-4.5.2.jar'; - $tagJar4->appendChild($newAttribute); - - $tagJar5 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/httpcore-4.4.4.jar'; - $tagJar5->appendChild($newAttribute); - - $tagJar6 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/plugin.jar'; - $tagJar6->appendChild($newAttribute); - - $tagJar7 = $jnlpDocument->createElement('jar'); - $newAttribute = $jnlpDocument->createAttribute('href'); - $newAttribute->value = $jarPath . '/modules/content_management/dist/lib/commons-logging-1.2.jar'; - $tagJar7->appendChild($newAttribute); - - - $tagApplication = $jnlpDocument->createElement('application-desc'); - $newAttribute = $jnlpDocument->createAttribute('main-class'); - $newAttribute->value = 'com.maarch.MaarchCM'; - $tagApplication->appendChild($newAttribute); - - $tagArg1 = $jnlpDocument->createElement('argument', $coreUrl . 'rest/jnlp/' . $jnlpUniqueId); //ProcessJnlp - $tagArg2 = $jnlpDocument->createElement('argument', $data['objectType']); //Type - $tagArg3 = $jnlpDocument->createElement('argument', $data['table']); //Table - $tagArg4 = $jnlpDocument->createElement('argument', $data['objectId']); //ObjectId - $tagArg5 = $jnlpDocument->createElement('argument', $data['uniqueId']); - $tagArg6 = $jnlpDocument->createElement('argument', "maarchCourrierAuth={$_COOKIE['maarchCourrierAuth']}"); //MaarchCookie - $tagArg7 = $jnlpDocument->createElement('argument', htmlentities($allCookies)); //AllCookies - $tagArg8 = $jnlpDocument->createElement('argument', $jnlpFileName); //JnlpFileName - $tagArg9 = $jnlpDocument->createElement('argument', $GLOBALS['userId']); //CurrentUser - $tagArg10 = $jnlpDocument->createElement('argument', 'false'); //ConvertPdf - $tagArg11 = $jnlpDocument->createElement('argument', 'false'); //OnlyConvert - $tagArg12 = $jnlpDocument->createElement('argument', 0); //HashFile - - - $tagJnlp->appendChild($tagInformation); - $tagInformation->appendChild($tagTitle); - $tagInformation->appendChild($tagVendor); - $tagInformation->appendChild($tagOffline); - - $tagJnlp->appendChild($tagSecurity); - $tagSecurity->appendChild($tagPermissions); - - $tagJnlp->appendChild($tagResources); - $tagResources->appendChild($tagJ2se); - $tagResources->appendChild($tagJar1); - $tagResources->appendChild($tagJar2); - $tagResources->appendChild($tagJar3); - $tagResources->appendChild($tagJar4); - $tagResources->appendChild($tagJar5); - $tagResources->appendChild($tagJar6); - $tagResources->appendChild($tagJar7); - - $tagJnlp->appendChild($tagApplication); - $tagApplication->appendChild($tagArg1); - $tagApplication->appendChild($tagArg2); - $tagApplication->appendChild($tagArg3); - $tagApplication->appendChild($tagArg4); - $tagApplication->appendChild($tagArg5); - $tagApplication->appendChild($tagArg6); - $tagApplication->appendChild($tagArg7); - $tagApplication->appendChild($tagArg8); - $tagApplication->appendChild($tagArg9); - $tagApplication->appendChild($tagArg10); - $tagApplication->appendChild($tagArg11); - $tagApplication->appendChild($tagArg12); - - $jnlpDocument->appendChild($tagJnlp); - - $jnlpDocument->save($tmpPath . $jnlpFileNameExt); - - fopen($tmpPath . $jnlpFileName . '.lck', 'w+'); - - return $response->withJson(['generatedJnlp' => $jnlpFileNameExt, 'jnlpUniqueId' => $jnlpUniqueId]); - } - - public function renderJnlp(Request $request, Response $response) - { - $data = $request->getQueryParams(); - - if (explode('.', $data['fileName'])[1] != 'jnlp') { - return $response->withStatus(403)->withJson(['errors' => 'File extension forbidden']); - } elseif (strpos($data['fileName'], "{$GLOBALS['userId']}_maarchCM_") === false) { - return $response->withStatus(403)->withJson(['errors' => 'File name forbidden']); - } - - $tmpPath = CoreConfigModel::getTmpPath(); - $jnlp = file_get_contents($tmpPath . $data['fileName']); - if ($jnlp === false) { - return $response->withStatus(404)->withJson(['errors' => 'Jnlp file not found on ' . $tmpPath]); - } - - $response->write($jnlp); - - return $response->withHeader('Content-Type', 'application/x-java-jnlp-file'); - } - - public function processJnlp(Request $request, Response $response, array $aArgs) - { - $data = $request->getParams(); - - $tmpPath = CoreConfigModel::getTmpPath(); - - if ($data['action'] == 'editObject') { - if ($data['objectType'] == 'templateCreation') { - $explodeFile = explode('.', $data['objectId']); - $ext = $explodeFile[count($explodeFile) - 1]; - $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; - - $pathToCopy = $data['objectId']; - } elseif ($data['objectType'] == 'templateModification') { - $docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]); - $template = TemplateModel::getById(['id' => $data['objectId'], 'select' => ['template_path', 'template_file_name']]); - if (empty($template)) { - $xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Template does not exist"]]); - $response->write($xmlResponse); - return $response->withHeader('Content-Type', 'application/xml'); - } - - $explodeFile = explode('.', $template['template_file_name']); - $ext = $explodeFile[count($explodeFile) - 1]; - $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; - - $pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name']; - } else { - $xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => 'Wrong objectType']]); - $response->write($xmlResponse); - return $response->withHeader('Content-Type', 'application/xml'); - } - - if (!file_exists($pathToCopy) || !copy($pathToCopy, $tmpPath . $newFileOnTmp)) { - $xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => "Failed to copy on {$tmpPath} : {$pathToCopy}"]]); - $response->write($xmlResponse); - return $response->withHeader('Content-Type', 'application/xml'); - } - - $fileContent = file_get_contents($tmpPath . $newFileOnTmp, FILE_BINARY); - - $result = [ - 'STATUS' => 'ok', - 'OBJECT_TYPE' => $data['objectType'], - 'OBJECT_TABLE' => $data['objectTable'], - 'OBJECT_ID' => $data['objectId'], - 'UNIQUE_ID' => $data['uniqueId'], - 'APP_PATH' => 'start', - 'FILE_CONTENT' => base64_encode($fileContent), - 'FILE_EXTENSION' => $ext, - 'ERROR' => '', - 'END_MESSAGE' => '' - ]; - $xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => $result]); - - } elseif ($data['action'] == 'saveObject') { - if (empty($data['fileContent']) || empty($data['fileExtension'])) { - $xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => ['ERROR' => 'File content or file extension empty']]); - $response->write($xmlResponse); - return $response->withHeader('Content-Type', 'application/xml'); - } - - $encodedFileContent = str_replace(' ', '+', $data['fileContent']); - $ext = str_replace(["\\", "/", '..'], '', $data['fileExtension']); - $fileContent = base64_decode($encodedFileContent); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; - - $file = fopen($tmpPath . $fileOnTmp, 'w'); - fwrite($file, $fileContent); - fclose($file); - - if (!empty($data['step']) && $data['step'] == 'end') { - if (file_exists("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck")) { - unlink("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck"); - } - } - - $xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => ['END_MESSAGE' => 'Update ok']]); - } elseif ($data['action'] == 'terminate') { - if (file_exists("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck")) { - unlink("{$tmpPath}{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck"); - } - - $xmlResponse = JnlpController::generateResponse(['type' => 'SUCCESS', 'data' => ['END_MESSAGE' => 'Terminate ok']]); - } else { - $result = [ - 'STATUS' => 'ko', - 'OBJECT_TYPE' => $data['objectType'], - 'OBJECT_TABLE' => $data['objectTable'], - 'OBJECT_ID' => $data['objectId'], - 'UNIQUE_ID' => $data['uniqueId'], - 'APP_PATH' => 'start', - 'FILE_CONTENT' => '', - 'FILE_EXTENSION' => '', - 'ERROR' => 'Missing parameters', - 'END_MESSAGE' => '' - ]; - $xmlResponse = JnlpController::generateResponse(['type' => 'ERROR', 'data' => $result]); - } - - $response->write($xmlResponse); - - return $response->withHeader('Content-Type', 'application/xml'); - } - - public function isLockFileExisting(Request $request, Response $response, array $aArgs) - { - $tmpPath = CoreConfigModel::getTmpPath(); - $lockFileName = "{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck"; - - $fileFound = false; - if (file_exists($tmpPath . $lockFileName)) { - $fileFound = true; - } - - return $response->withJson(['lockFileFound' => $fileFound]); - } - - private static function generateResponse(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type', 'data']); - ValidatorModel::stringType($aArgs, ['type']); - ValidatorModel::arrayType($aArgs, ['data']); - - $response = new \DomDocument('1.0', 'UTF-8'); - - $tagRoot = $response->createElement($aArgs['type']); - $response->appendChild($tagRoot); - - foreach ($aArgs['data'] as $key => $value) { - $tag = $response->createElement($key, $value); - $tagRoot->appendChild($tag); - } - - return $response->saveXML(); - } -} diff --git a/src/app/doctype/controllers/DoctypeController.php b/src/app/doctype/controllers/DoctypeController.php deleted file mode 100644 index ee1b892b03..0000000000 --- a/src/app/doctype/controllers/DoctypeController.php +++ /dev/null @@ -1,413 +0,0 @@ -<?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 DoctypeController -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\controllers; - -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Doctype\models\SecondLevelModel; -use Doctype\models\DoctypeModel; -use Doctype\models\DoctypeExtModel; -use Doctype\models\DoctypeIndexesModel; -use Doctype\models\TemplateDoctypeModel; -use Group\models\ServiceModel; -use Template\models\TemplateModel; -use Slim\Http\Request; -use Slim\Http\Response; -use Resource\models\ResModel; - -class DoctypeController -{ - public function get(Request $request, Response $response) - { - $doctypes = DoctypeModel::get([ - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['description asc'] - ]); - - return $response->withJson(['doctypes' => $doctypes]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - if (!Validator::intVal()->validate($aArgs['id']) || !Validator::notEmpty()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'wrong format for id']); - } - - $obj['doctype'] = DoctypeModel::getById(['id' => $aArgs['id']]); - - if (!empty($obj['doctype'])) { - if ($obj['doctype']['enabled'] == 'Y') { - $obj['doctype']['enabled'] = true; - } else { - $obj['doctype']['enabled'] = false; - } - } - - $doctypeExt = DoctypeExtModel::getById(['id' => $obj['doctype']['type_id']]); - $template = TemplateDoctypeModel::getById(["id" => $obj['doctype']['type_id']]); - - if (empty($template)) { - $template["template_id"] = null; - $template["is_generated"] = 'N'; - } - - $indexes = DoctypeIndexesModel::getAllIndexes(); - $indexesSelected = DoctypeIndexesModel::getById(['id' => $obj['doctype']['type_id']]); - foreach ($indexes as $key => $value) { - foreach ($indexesSelected as $valueSelected) { - if ($value['column'] == $valueSelected['field_name']) { - $indexes[$key]['use'] = true; - if ($valueSelected['mandatory'] == 'Y') { - $valueSelected['mandatory'] = true; - } else { - $valueSelected['mandatory'] = false; - } - $indexes[$key]['mandatory'] = $valueSelected['mandatory']; - break; - } - } - } - - $obj['doctype'] = array_merge($obj['doctype'], $doctypeExt, $template, ['indexes' => $indexes]); - $obj['secondLevel'] = SecondLevelModel::get([ - 'select' => ['doctypes_second_level_id', 'doctypes_second_level_label'], - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['doctypes_second_level_label asc'] - ]); - $obj['processModes'] = DoctypeModel::getProcessMode(); - $obj['models'] = TemplateModel::getByTarget(['select' => ['template_id', 'template_label', 'template_comment'], 'template_target' => 'doctypes']); - - return $response->withJson($obj); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $errors = DoctypeController::control($data, 'create'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - if (empty($data['duration_current_use'])) { - $data['duration_current_use'] = null; - } - - $data = DoctypeController::manageValue($data); - $secondLevelInfo = SecondLevelModel::getById(['select' => ['doctypes_first_level_id'], 'id' => $data['doctypes_second_level_id']]); - - if (empty($secondLevelInfo)) { - return $response->withStatus(500)->withJson(['errors' => 'doctypes_second_level_id does not exists']); - } - - $data['doctypes_first_level_id'] = $secondLevelInfo['doctypes_first_level_id']; - - $doctypeId = DoctypeModel::create([ - 'coll_id' => 'letterbox_coll', - 'description' => $data['description'], - 'doctypes_first_level_id' => $data['doctypes_first_level_id'], - 'doctypes_second_level_id' => $data['doctypes_second_level_id'], - 'retention_final_disposition' => $data['retention_final_disposition'], - 'retention_rule' => $data['retention_rule'], - 'duration_current_use' => $data['duration_current_use'] - ]); - - DoctypeExtModel::create([ - "type_id" => $doctypeId, - "process_delay" => $data['process_delay'], - "delay1" => $data['delay1'], - "delay2" => $data['delay2'], - "process_mode" => $data['process_mode'], - ]); - - TemplateDoctypeModel::create([ - "template_id" => $data["template_id"], - "type_id" => $doctypeId, - "is_generated" => $data["is_generated"] - ]); - - if (!empty($data['indexes'])) { - foreach ($data['indexes'] as $value) { - if (!empty($value['use'])) { - DoctypeIndexesModel::create([ - "type_id" => $doctypeId, - "coll_id" => 'letterbox_coll', - "field_name" => $value['column'], - "mandatory" => $value['mandatory'] - ]); - } - } - } - - HistoryController::add([ - 'tableName' => 'doctypes', - 'recordId' => $doctypeId, - 'eventType' => 'ADD', - 'eventId' => 'typesadd', - 'info' => _DOCTYPE_ADDED . ' : ' . $data['description'] - ]); - - return $response->withJson( - [ - 'doctypeId' => $doctypeId, - 'doctypeTree' => FirstLevelController::getTreeFunction(), - ] - ); - } - - public function update(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data['type_id'] = $aArgs['id']; - - $errors = DoctypeController::control($data, 'update'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - if (empty($data['duration_current_use'])) { - $data['duration_current_use'] = null; - } - $data = DoctypeController::manageValue($data); - $secondLevelInfo = SecondLevelModel::getById(['select' => ['doctypes_first_level_id'], 'id' => $data['doctypes_second_level_id']]); - if (empty($secondLevelInfo)) { - return $response->withStatus(500)->withJson(['errors' => 'doctypes_second_level_id does not exists']); - } - $data['doctypes_first_level_id'] = $secondLevelInfo['doctypes_first_level_id']; - - DoctypeModel::update([ - 'type_id' => $data['type_id'], - 'coll_id' => 'letterbox_coll', - 'description' => $data['description'], - 'doctypes_first_level_id' => $data['doctypes_first_level_id'], - 'doctypes_second_level_id' => $data['doctypes_second_level_id'], - 'retention_final_disposition' => $data['retention_final_disposition'], - 'retention_rule' => $data['retention_rule'], - 'duration_current_use' => $data['duration_current_use'] - ]); - - DoctypeExtModel::update([ - "type_id" => $data['type_id'], - "process_delay" => $data['process_delay'], - "delay1" => $data['delay1'], - "delay2" => $data['delay2'], - "process_mode" => $data['process_mode'], - ]); - - TemplateDoctypeModel::update([ - "template_id" => $data["template_id"], - "type_id" => $data['type_id'], - "is_generated" => $data["is_generated"] - ]); - - DoctypeIndexesModel::delete(["type_id" => $data['type_id']]); - - if (!empty($data['indexes'])) { - foreach ($data['indexes'] as $value) { - if (!empty($value['use'])) { - DoctypeIndexesModel::create([ - "type_id" => $data['type_id'], - "coll_id" => 'letterbox_coll', - "field_name" => $value['column'], - "mandatory" => $value['mandatory'] - ]); - } - } - } - - HistoryController::add([ - 'tableName' => 'doctypes', - 'recordId' => $data['type_id'], - 'eventType' => 'UP', - 'eventId' => 'typesadd', - 'info' => _DOCTYPE_UPDATED . ' : ' . $data['description'] - ]); - - return $response->withJson( - [ - 'doctype' => $data, - 'doctypeTree' => FirstLevelController::getTreeFunction(), - ] - ); - } - - public function delete(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - $count = ResModel::get([ - 'select' => ['count(1)'], - 'where' => ['type_id = ?'], - 'data' => [$aArgs['id']] - ]); - - if ($count[0]['count'] == 0) { - DoctypeController::deleteAllDoctypeData(['type_id' => $aArgs['id']]); - $deleted = 0; - $doctypeTree = FirstLevelController::getTreeFunction(); - } else { - $deleted = $count[0]['count']; - $doctypes = DoctypeModel::get([ - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['description asc'] - ]); - foreach ($doctypes as $key => $value) { - if ($value['type_id'] == $aArgs['id']) { - $doctypes[$key]['disabled'] = true; - } - } - } - - return $response->withJson([ - 'deleted' => $deleted, - 'doctypeTree' => $doctypeTree, - 'doctypes' => $doctypes - ]); - } - - public function deleteRedirect(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data['type_id'] = $aArgs['id']; - - if (!Validator::intVal()->validate($data['type_id'])) { - return $response - ->withStatus(500) - ->withJson(['errors' => 'Id is not a numeric']); - } - - if (!Validator::intVal()->validate($data['new_type_id']) || !Validator::notEmpty()->validate($data['new_type_id'])) { - return $response - ->withStatus(500) - ->withJson(['errors' => 'wrong format for new_type_id']); - } - - if (empty(DoctypeModel::getById(['id' => $data['new_type_id']]))) { - return $response - ->withStatus(500) - ->withJson(['errors' => 'new_type_id does not exists']); - } - - if ($data['type_id'] == $data['new_type_id']) { - return $response - ->withStatus(500) - ->withJson(['errors' => 'new_type_id is the same as type_id']); - } - - ResModel::update([ - 'set' => ['type_id' => $data['new_type_id']], - 'where' => ['type_id = ?'], - 'data' => [$data['type_id']] - ]); - DoctypeController::deleteAllDoctypeData(['type_id' => $data['type_id']]); - - return $response->withJson( - [ - 'doctypeTree' => FirstLevelController::getTreeFunction() - ] - ); - } - - protected function deleteAllDoctypeData(array $aArgs = []) - { - $doctypeInfo = DoctypeModel::getById(['id' => $aArgs['type_id']]); - DoctypeModel::delete(['type_id' => $aArgs['type_id']]); - DoctypeExtModel::delete(["type_id" => $aArgs['type_id']]); - TemplateDoctypeModel::delete(["type_id" => $aArgs['type_id']]); - DoctypeIndexesModel::delete(["type_id" => $aArgs['type_id']]); - - HistoryController::add([ - 'tableName' => 'doctypes', - 'recordId' => $doctypeInfo['type_id'], - 'eventType' => 'DEL', - 'eventId' => 'typesdel', - 'info' => _DOCTYPE_DELETED. ' : ' . $doctypeInfo['description'] - ]); - } - - protected static function control($aArgs, $mode) - { - $errors = []; - - if ($mode == 'update') { - if (!Validator::intVal()->validate($aArgs['type_id'])) { - $errors[] = 'type_id is not a numeric'; - } else { - $obj = DoctypeModel::getById(['id' => $aArgs['type_id']]); - } - - if (empty($obj)) { - $errors[] = 'Id ' .$aArgs['type_id']. ' does not exists'; - } - } - - if (!Validator::notEmpty()->validate($aArgs['description']) || - !Validator::length(1, 255)->validate($aArgs['description'])) { - $errors[] = 'Invalid description'; - } - - if (!Validator::notEmpty()->validate($aArgs['doctypes_second_level_id']) || - !Validator::intVal()->validate($aArgs['doctypes_second_level_id'])) { - $errors[]= 'Invalid doctypes_second_level_id value'; - } - if (!Validator::notEmpty()->validate($aArgs['process_delay']) && - (!Validator::intVal()->validate($aArgs['process_delay']) || $aArgs['process_delay'] < 0)) { - $errors[]= 'Invalid process_delay value'; - } - if (!Validator::notEmpty()->validate($aArgs['delay1']) && - (!Validator::intVal()->validate($aArgs['delay1']) || $aArgs['delay1'] < 0)) { - $errors[]= 'Invalid delay1 value'; - } - if (!Validator::notEmpty()->validate($aArgs['delay2']) && - (!Validator::intVal()->validate($aArgs['delay2']) || $aArgs['delay2'] < 0)) { - $errors[]= 'Invalid delay2 value'; - } - if (Validator::notEmpty()->validate($aArgs['duration_current_use']) && - (!Validator::intVal()->validate($aArgs['duration_current_use']) || - $aArgs['duration_current_use'] < 0)) { - $errors[]= 'Invalid duration_current_use value'; - } - - return $errors; - } - - protected static function manageValue($request) - { - foreach ($request['indexes'] as $key => $value) { - if (!empty($value['mandatory'])) { - $request['indexes'][$key]['mandatory'] = 'Y'; - } else { - $request['indexes'][$key]['mandatory'] = 'N'; - } - } - return $request; - } -} diff --git a/src/app/doctype/controllers/FirstLevelController.php b/src/app/doctype/controllers/FirstLevelController.php deleted file mode 100644 index 796d16ea5f..0000000000 --- a/src/app/doctype/controllers/FirstLevelController.php +++ /dev/null @@ -1,294 +0,0 @@ -<?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 FirstLevelController -* -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\controllers; - -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Doctype\models\FirstLevelModel; -use Doctype\models\SecondLevelModel; -use Doctype\models\DoctypeModel; -use Folder\models\FolderTypeModel; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; -use Template\models\TemplateModel; -use Doctype\models\DoctypeIndexesModel; - -class FirstLevelController -{ - public function getTree(Request $request, Response $response) - { - return $response->withJson(['structure' => FirstLevelController::getTreeFunction()]); - } - - public static function getTreeFunction() - { - $firstLevels = FirstLevelModel::get(['where' => ['enabled = ?'], 'data' => ['Y'], 'order_by' => ['doctypes_first_level_id asc']]); - $secondLevels = SecondLevelModel::get([ - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['doctypes_second_level_label asc'] - ]); - $docTypes = DoctypeModel::get([ - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['description asc'] - ]); - - $structure = []; - foreach ($firstLevels as $firstLevelValue) { - $firstLevelValue['id'] = 'firstlevel_'.$firstLevelValue['doctypes_first_level_id']; - $firstLevelValue['text'] = $firstLevelValue['doctypes_first_level_label']; - $firstLevelValue['parent'] = '#'; - $firstLevelValue['state']['opened'] = true; - array_push($structure, $firstLevelValue); - } - foreach ($secondLevels as $secondLevelValue) { - $secondLevelValue['id'] = 'secondlevel_'.$secondLevelValue['doctypes_second_level_id']; - $secondLevelValue['text'] = $secondLevelValue['doctypes_second_level_label']; - $secondLevelValue['parent'] = 'firstlevel_'.$secondLevelValue['doctypes_first_level_id']; - array_push($structure, $secondLevelValue); - } - foreach ($docTypes as $doctypeValue) { - $doctypeValue['id'] = $doctypeValue['type_id']; - $doctypeValue['text'] = $doctypeValue['description']; - $doctypeValue['parent'] = 'secondlevel_'.$doctypeValue['doctypes_second_level_id']; - $doctypeValue['icon'] = 'fa fa-copy'; - array_push($structure, $doctypeValue); - } - - return $structure; - } - - public function getById(Request $request, Response $response, $aArgs) - { - if (!Validator::notEmpty()->validate($aArgs['id']) || !Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'wrong format for id']); - } - - $obj = []; - $obj['firstLevel'] = FirstLevelModel::getById(['id' => $aArgs['id']]); - - $hasChildren = SecondLevelModel::get([ - 'select' => [1], - 'where' => ['doctypes_first_level_id = ?', 'enabled = ?'], - 'data' => [$aArgs['id'], 'Y'] - ]); - $obj['firstLevel']['hasChildren'] = empty($hasChildren) ? false : true; - - - if (!empty($obj)) { - if ($obj['firstLevel']['enabled'] == 'Y') { - $obj['firstLevel']['enabled'] = true; - } else { - $obj['firstLevel']['enabled'] = false; - } - - $folderTypesSelected = FolderTypeModel::getFolderTypeDocTypeFirstLevel(['doctypes_first_level_id' => $aArgs['id']]); - $aFolderTypesSelected = []; - foreach ($folderTypesSelected as $folderType) { - $aFolderTypesSelected[] = $folderType['foldertype_id']; - } - $obj['firstLevel']['foldertype_id'] = $aFolderTypesSelected; - } - - $obj['folderTypes'] = FolderTypeModel::get(['select' => ['foldertype_id', 'foldertype_label']]); - - return $response->withJson($obj); - } - - public function initDoctypes(Request $request, Response $response) - { - $obj['folderTypes'] = FolderTypeModel::get(['select' => ['foldertype_id', 'foldertype_label']]); - $obj['firstLevel'] = FirstLevelModel::get([ - 'select' => ['doctypes_first_level_id', 'doctypes_first_level_label'], - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['doctypes_first_level_id asc'] - ]); - $obj['secondLevel'] = SecondLevelModel::get([ - 'select' => ['doctypes_second_level_id', 'doctypes_second_level_label'], - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['doctypes_second_level_label asc'] - ]); - $obj['processModes'] = DoctypeModel::getProcessMode(); - $obj['models'] = TemplateModel::getByTarget(['select' => ['template_id', 'template_label', 'template_comment'], 'template_target' => 'doctypes']); - $obj['indexes'] = DoctypeIndexesModel::getAllIndexes(); - - return $response->withJson($obj); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data = $this->manageValue($data); - - $errors = $this->control($data, 'create'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $folderTypeId = $data['foldertype_id']; - unset($data['foldertype_id']); - $firstLevelId = FirstLevelModel::create($data); - - foreach ($folderTypeId as $value) { - FolderTypeModel::createFolderTypeDocTypeFirstLevel([ - 'doctypes_first_level_id' => $firstLevelId, - 'foldertype_id' => $value, - ]); - } - - HistoryController::add([ - 'tableName' => 'doctypes_first_level', - 'recordId' => $firstLevelId, - 'eventType' => 'ADD', - 'eventId' => 'structureadd', - 'info' => _DOCTYPE_FIRSTLEVEL_ADDED.' : '.$data['doctypes_first_level_label'], - ]); - - return $response->withJson([ - 'firstLevelId' => $firstLevelId, - 'doctypeTree' => FirstLevelController::getTreeFunction() - ]); - } - - public function update(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $obj = $request->getParams(); - $obj['doctypes_first_level_id'] = $aArgs['id']; - - $obj = $this->manageValue($obj); - $errors = $this->control($obj, 'update'); - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $folderTypeId = $obj['foldertype_id']; - unset($obj['foldertype_id']); - FirstLevelModel::update($obj); - - FolderTypeModel::deleteFolderTypeDocTypeFirstLevel(['doctypes_first_level_id' => $obj['doctypes_first_level_id']]); - foreach ($folderTypeId as $value) { - FolderTypeModel::createFolderTypeDocTypeFirstLevel([ - 'doctypes_first_level_id' => $obj['doctypes_first_level_id'], - 'foldertype_id' => $value, - ]); - } - - HistoryController::add([ - 'tableName' => 'doctypes_first_level', - 'recordId' => $obj['doctypes_first_level_id'], - 'eventType' => 'UP', - 'eventId' => 'structureup', - 'info' => _DOCTYPE_FIRSTLEVEL_UPDATED.' : '.$obj['doctypes_first_level_label'], - ]); - - return $response->withJson([ - 'firstLevelId' => $obj, - 'doctypeTree' => FirstLevelController::getTreeFunction() - ]); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - FirstLevelModel::update(['doctypes_first_level_id' => $aArgs['id'], 'enabled' => 'N']); - SecondLevelModel::disabledFirstLevel(['doctypes_first_level_id' => $aArgs['id'], 'enabled' => 'N']); - DoctypeModel::disabledFirstLevel(['doctypes_first_level_id' => $aArgs['id'], 'enabled' => 'N']); - FolderTypeModel::deleteFolderTypeDocTypeFirstLevel(['doctypes_first_level_id' => $aArgs['id']]); - $firstLevel = FirstLevelModel::getById(['id' => $aArgs['id']]); - - HistoryController::add([ - 'tableName' => 'doctypes_first_level', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'eventId' => 'structuredel', - 'info' => _DOCTYPE_FIRSTLEVEL_DELETED.' : '.$firstLevel['doctypes_first_level_label'], - ]); - - return $response->withJson([ - 'firstLevelDeleted' => $firstLevel, - 'doctypeTree' => FirstLevelController::getTreeFunction() - ]); - } - - protected function control($aArgs, $mode) - { - $errors = []; - - if ($mode == 'update') { - if (!Validator::intVal()->validate($aArgs['doctypes_first_level_id'])) { - $errors[] = 'Id is not a numeric'; - } else { - $obj = FirstLevelModel::getById(['id' => $aArgs['doctypes_first_level_id']]); - } - - if (empty($obj)) { - $errors[] = 'Id '.$aArgs['doctypes_first_level_id'].' does not exists'; - } - } - - if (!Validator::notEmpty()->validate($aArgs['doctypes_first_level_label']) || - !Validator::length(1, 255)->validate($aArgs['doctypes_first_level_label'])) { - $errors[] = 'Invalid doctypes_first_level_label'; - } - - if (!Validator::notEmpty()->validate($aArgs['foldertype_id'])) { - $errors[] = 'Invalid foldertype_id'; - } - - if (empty($aArgs['enabled'])) { - $aArgs['enabled'] = 'Y'; - } - - if ($aArgs['enabled'] != 'Y' && $aArgs['enabled'] != 'N') { - $errors[] = 'Invalid enabled value'; - } - - return $errors; - } - - protected function manageValue($request) - { - foreach ($request as $key => $value) { - if (in_array($key, ['enabled'])) { - if (empty($value)) { - $request[$key] = 'N'; - } else { - $request[$key] = 'Y'; - } - } - } - - return $request; - } -} diff --git a/src/app/doctype/controllers/SecondLevelController.php b/src/app/doctype/controllers/SecondLevelController.php deleted file mode 100644 index 470c9e7387..0000000000 --- a/src/app/doctype/controllers/SecondLevelController.php +++ /dev/null @@ -1,205 +0,0 @@ -<?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 SecondLevelController -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\controllers; - -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Doctype\models\FirstLevelModel; -use Doctype\models\SecondLevelModel; -use Doctype\models\DoctypeModel; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class SecondLevelController -{ - public function getById(Request $request, Response $response, array $aArgs) - { - if (!Validator::notEmpty()->validate($aArgs['id']) || !Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'wrong format for id']); - } - - $doctype = []; - $doctype['secondLevel'] = SecondLevelModel::getById(['id' => $aArgs['id']]); - - $hasChildren = DoctypeModel::get([ - 'select' => [1], - 'where' => ['doctypes_second_level_id = ?'], - 'data' => [$aArgs['id']] - ]); - $doctype['secondLevel']['hasChildren'] = empty($hasChildren) ? false : true; - - if (!empty($doctype['secondLevel'])) { - if ($doctype['secondLevel']['enabled'] == 'Y') { - $doctype['secondLevel']['enabled'] = true; - } else { - $doctype['secondLevel']['enabled'] = false; - } - } - - $doctype['firstLevel'] = FirstLevelModel::get([ - 'select' => ['doctypes_first_level_id', 'doctypes_first_level_label'], - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['doctypes_first_level_id asc'] - ]); - - return $response->withJson($doctype); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data = $this->manageValue($data); - - $errors = $this->control($data, 'create'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $secondLevelId = SecondLevelModel::create($data); - - HistoryController::add([ - 'tableName' => 'doctypes_second_level', - 'recordId' => $secondLevelId, - 'eventType' => 'ADD', - 'eventId' => 'subfolderadd', - 'info' => _DOCTYPE_SECONDLEVEL_ADDED . ' : ' . $data['doctypes_second_level_label'] - ]); - - return $response->withJson( - [ - 'secondLevelId' => $secondLevelId, - 'doctypeTree' => FirstLevelController::getTreeFunction(), - ] - ); - } - - public function update(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data['doctypes_second_level_id'] = $aArgs['id']; - - $data = $this->manageValue($data); - $errors = $this->control($data, 'update'); - - if (!empty($errors)) { - return $response - ->withStatus(500) - ->withJson(['errors' => $errors]); - } - - SecondLevelModel::update($data); - - HistoryController::add([ - 'tableName' => 'doctypes_second_level', - 'recordId' => $data['doctypes_second_level_id'], - 'eventType' => 'UP', - 'eventId' => 'subfolderup', - 'info' => _DOCTYPE_SECONDLEVEL_UPDATED. ' : ' . $data['doctypes_second_level_label'] - ]); - - return $response->withJson( - [ - 'secondLevelId' => $data, - 'doctypeTree' => FirstLevelController::getTreeFunction(), - ] - ); - } - - public function delete(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_architecture', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - SecondLevelModel::update(['doctypes_second_level_id' => $aArgs['id'], 'enabled' => 'N']); - DoctypeModel::disabledSecondLevel(['doctypes_second_level_id' => $aArgs['id'], 'enabled' => 'N']); - $secondLevel = SecondLevelModel::getById(['id' => $aArgs['id']]); - - HistoryController::add([ - 'tableName' => 'doctypes_second_level', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'eventId' => 'subfolderdel', - 'info' => _DOCTYPE_SECONDLEVEL_DELETED. ' : ' . $secondLevel['doctypes_second_level_label'] - ]); - - return $response->withJson([ - 'secondLevelDeleted' => $secondLevel, - 'doctypeTree' => FirstLevelController::getTreeFunction() - ]); - } - - protected function control($aArgs, $mode) - { - $errors = []; - - if ($mode == 'update') { - if (!Validator::intVal()->validate($aArgs['doctypes_second_level_id'])) { - $errors[] = 'Id is not a numeric'; - } else { - $obj = SecondLevelModel::getById(['id' => $aArgs['doctypes_second_level_id']]); - } - - if (empty($obj)) { - $errors[] = 'Id ' .$aArgs['doctypes_second_level_id']. ' does not exists'; - } - } - - if (!Validator::notEmpty()->validate($aArgs['doctypes_second_level_label']) || - !Validator::length(1, 255)->validate($aArgs['doctypes_second_level_label'])) { - $errors[] = 'Invalid doctypes_second_level_label'; - } - - if (!Validator::notEmpty()->validate($aArgs['doctypes_first_level_id']) || - !Validator::intVal()->validate($aArgs['doctypes_first_level_id'])) { - $errors[] = 'Invalid doctypes_first_level_id'; - } - - if (empty($aArgs['enabled'])) { - $aArgs['enabled'] = 'Y'; - } - - if ($aArgs['enabled'] != 'Y' && $aArgs['enabled'] != 'N') { - $errors[]= 'Invalid enabled value'; - } - - return $errors; - } - - protected function manageValue($request) - { - foreach ($request as $key => $value) { - if (in_array($key, ['enabled'])) { - if (empty($value)) { - $request[$key] = 'N'; - } else { - $request[$key] = 'Y'; - } - } - } - return $request; - } -} diff --git a/src/app/doctype/models/DoctypeExtModel.php b/src/app/doctype/models/DoctypeExtModel.php deleted file mode 100644 index c437373b8f..0000000000 --- a/src/app/doctype/models/DoctypeExtModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 DoctypeExt Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class DoctypeExtModel extends DoctypeExtModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/DoctypeExtModelAbstract.php b/src/app/doctype/models/DoctypeExtModelAbstract.php deleted file mode 100644 index 03b108d365..0000000000 --- a/src/app/doctype/models/DoctypeExtModelAbstract.php +++ /dev/null @@ -1,84 +0,0 @@ -<?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 DoctypeExtModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -class DoctypeExtModelAbstract -{ - public static function getById(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select( - [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['mlb_doctype_ext'], - 'where' => ['type_id = ?'], - 'data' => [$aArgs['id']] - ] - ); - - if (empty($aReturn[0])) { - return []; - } - - $aReturn = $aReturn[0]; - - return $aReturn; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id', 'process_mode']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::insert([ - 'table' => 'mlb_doctype_ext', - 'columnsValues' => $aArgs - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id', 'process_mode']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::update([ - 'table' => 'mlb_doctype_ext', - 'set' => $aArgs, - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::delete([ - 'table' => 'mlb_doctype_ext', - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } -} diff --git a/src/app/doctype/models/DoctypeIndexesModel.php b/src/app/doctype/models/DoctypeIndexesModel.php deleted file mode 100644 index 22721d330c..0000000000 --- a/src/app/doctype/models/DoctypeIndexesModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 DoctypeIndexes Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class DoctypeIndexesModel extends DoctypeIndexesModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/DoctypeIndexesModelAbstract.php b/src/app/doctype/models/DoctypeIndexesModelAbstract.php deleted file mode 100644 index cead9f1e02..0000000000 --- a/src/app/doctype/models/DoctypeIndexesModelAbstract.php +++ /dev/null @@ -1,161 +0,0 @@ -<?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 DoctypeIndexesModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -class DoctypeIndexesModelAbstract -{ - public static function getById(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select( - [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes_indexes'], - 'where' => ['type_id = ?'], - 'data' => [$aArgs['id']] - ] - ); - - if (empty($aReturn[0])) { - return []; - } - - return $aReturn; - } - - - public static function getAllIndexes() - { - $indexes = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/index_letterbox.xml']); - if ($loadedXml) { - foreach ($loadedXml->INDEX as $item) { - $label = (string) $item->label; - if (!empty($label) && defined($label) && constant($label) <> null) { - $label = constant($label); - } - $img = (string) $item->img; - if (!empty($item->default_value)) { - $default = (string) $item->default_value; - if (!empty($default) && defined($default) && constant($default) <> null) { - $default = constant($default); - } - } else { - $default = false; - } - if (isset($item->values_list)) { - $values = []; - $list = $item->values_list; - foreach ($list->value as $val) { - $labelVal = (string) $val->label; - if (!empty($labelVal) && defined($labelVal) && constant($labelVal) <> null) { - $labelVal = constant($labelVal); - } - - $values[] = [ - 'id' => (string) $val->id, - 'label' => $labelVal - ]; - } - $tmpArr = [ - 'column' => (string) $item->column, - 'label' => $label, - 'type' => (string) $item->type, - 'img' => $img, - 'type_field' => 'select', - 'values' => $values, - 'default_value' => $default - ]; - } elseif (isset($item->table)) { - $values = []; - $tableXml = $item->table; - $tableName = (string) $tableXml->table_name; - $foreignKey = (string) $tableXml->foreign_key; - $foreignLabel = (string) $tableXml->foreign_label; - $whereClause = (string) $tableXml->where_clause; - $order = (string) $tableXml->order; - - - $res = DatabaseModel::select([ - 'select' => [$foreignKey, $foreignLabel], - 'table' => [$tableName], - 'where' => [$whereClause], - 'order_by' => [str_ireplace("order by", "", $order)] - ]); - - foreach ($res as $value) { - $values[] = [ - 'id' => (string) $value[0], - 'label' => (string) $value[1] - ]; - } - - $tmpArr = [ - 'column' => (string) $item->column, - 'label' => $label, - 'type' => (string) $item->type, - 'img' => $img, - 'type_field' => 'select', - 'values' => $values, - 'default_value' => $default - ]; - } else { - $tmpArr = [ - 'column' => (string) $item->column, - 'label' => $label, - 'type' => (string) $item->type, - 'img' => $img, - 'type_field' => 'input', - 'default_value' => $default - ]; - } - array_push($indexes, $tmpArr); - } - } - - return $indexes; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id', 'field_name', 'mandatory', 'coll_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::insert([ - 'table' => 'doctypes_indexes', - 'columnsValues' => $aArgs - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::delete([ - 'table' => 'doctypes_indexes', - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } -} diff --git a/src/app/doctype/models/DoctypeModel.php b/src/app/doctype/models/DoctypeModel.php deleted file mode 100644 index ad571181a1..0000000000 --- a/src/app/doctype/models/DoctypeModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Doctype Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class DoctypeModel extends DoctypeModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/DoctypeModelAbstract.php b/src/app/doctype/models/DoctypeModelAbstract.php deleted file mode 100644 index 7d4361d84e..0000000000 --- a/src/app/doctype/models/DoctypeModelAbstract.php +++ /dev/null @@ -1,147 +0,0 @@ -<?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 DoctypeModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -class DoctypeModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $doctypes = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $doctypes; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes'], - 'where' => ['type_id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aReturn[0])) { - return []; - } - - return $aReturn[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['description', 'doctypes_first_level_id', 'doctypes_second_level_id', 'coll_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id', 'doctypes_second_level_id']); - - $aArgs['type_id'] = DatabaseModel::getNextSequenceValue(['sequenceId' => 'doctypes_type_id_seq']); - DatabaseModel::insert([ - 'table' => 'doctypes', - 'columnsValues' => $aArgs - ]); - - return $aArgs['type_id']; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::update([ - 'table' => 'doctypes', - 'set' => $aArgs, - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } - - public static function disabledFirstLevel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id']); - - DatabaseModel::update([ - 'table' => 'doctypes', - 'set' => $aArgs, - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['doctypes_first_level_id']] - ]); - - return true; - } - - public static function disabledSecondLevel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_second_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_second_level_id']); - - DatabaseModel::update([ - 'table' => 'doctypes', - 'set' => $aArgs, - 'where' => ['doctypes_second_level_id = ?'], - 'data' => [$aArgs['doctypes_second_level_id']] - ]); - - return true; - } - - public static function getProcessMode() - { - $return['processing_modes'] = []; - $return['process_mode_priority'] = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/entreprise.xml']); - if ($loadedXml) { - $processingModes = $loadedXml->process_modes; - if (count($processingModes) > 0) { - foreach ($processingModes->process_mode as $process) { - $return['processing_modes'][] = (string) $process->label; - $return['process_mode_priority'][] = (string) $process->process_mode_priority; - } - } - } - - return $return; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::delete([ - 'table' => 'doctypes', - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } -} diff --git a/src/app/doctype/models/FirstLevelModel.php b/src/app/doctype/models/FirstLevelModel.php deleted file mode 100644 index 5179adafcf..0000000000 --- a/src/app/doctype/models/FirstLevelModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 FirstLevel Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class FirstLevelModel extends FirstLevelModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/FirstLevelModelAbstract.php b/src/app/doctype/models/FirstLevelModelAbstract.php deleted file mode 100644 index aaa87f7fd3..0000000000 --- a/src/app/doctype/models/FirstLevelModelAbstract.php +++ /dev/null @@ -1,85 +0,0 @@ -<?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 FirstLevelModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -class FirstLevelModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $firstLevel = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes_first_level'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $firstLevel; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select( - [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes_first_level'], - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['id']] - ] - ); - - if (empty($aReturn[0])) { - return []; - } - - return $aReturn[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_first_level_label']); - - $aArgs['doctypes_first_level_id'] = DatabaseModel::getNextSequenceValue(['sequenceId' => 'doctypes_first_level_id_seq']); - DatabaseModel::insert([ - 'table' => 'doctypes_first_level', - 'columnsValues' => $aArgs - ]); - - return $aArgs['doctypes_first_level_id']; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id']); - - DatabaseModel::update([ - 'table' => 'doctypes_first_level', - 'set' => $aArgs, - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['doctypes_first_level_id']] - ]); - - return true; - } -} diff --git a/src/app/doctype/models/SecondLevelModel.php b/src/app/doctype/models/SecondLevelModel.php deleted file mode 100644 index e8430f6ebf..0000000000 --- a/src/app/doctype/models/SecondLevelModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 SecondLevel Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class SecondLevelModel extends SecondLevelModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/SecondLevelModelAbstract.php b/src/app/doctype/models/SecondLevelModelAbstract.php deleted file mode 100644 index f3f840eee6..0000000000 --- a/src/app/doctype/models/SecondLevelModelAbstract.php +++ /dev/null @@ -1,98 +0,0 @@ -<?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 SecondLevelModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -class SecondLevelModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $secondLevel = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes_second_level'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $secondLevel; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['doctypes_second_level'], - 'where' => ['doctypes_second_level_id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aReturn[0])) { - return []; - } - - return $aReturn[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_second_level_label', 'doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id']); - - $aArgs['doctypes_second_level_id'] = DatabaseModel::getNextSequenceValue(['sequenceId' => 'doctypes_second_level_id_seq']); - DatabaseModel::insert([ - 'table' => 'doctypes_second_level', - 'columnsValues' => $aArgs - ]); - - return $aArgs['doctypes_second_level_id']; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_second_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_second_level_id']); - - DatabaseModel::update([ - 'table' => 'doctypes_second_level', - 'set' => $aArgs, - 'where' => ['doctypes_second_level_id = ?'], - 'data' => [$aArgs['doctypes_second_level_id']] - ]); - - return true; - } - - public static function disabledFirstLevel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id']); - - DatabaseModel::update([ - 'table' => 'doctypes_second_level', - 'set' => $aArgs, - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['doctypes_first_level_id']] - ]); - - return true; - } -} diff --git a/src/app/doctype/models/TemplateDoctypeModel.php b/src/app/doctype/models/TemplateDoctypeModel.php deleted file mode 100644 index 00da0d201a..0000000000 --- a/src/app/doctype/models/TemplateDoctypeModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 TemplateDoctype Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Doctype\models; - -class TemplateDoctypeModel extends TemplateDoctypeModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/doctype/models/TemplateDoctypeModelAbstract.php b/src/app/doctype/models/TemplateDoctypeModelAbstract.php deleted file mode 100644 index 939ce55730..0000000000 --- a/src/app/doctype/models/TemplateDoctypeModelAbstract.php +++ /dev/null @@ -1,92 +0,0 @@ -<?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 TemplateDoctypeModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Doctype\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -class TemplateDoctypeModelAbstract -{ - public static function getById(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aReturn = DatabaseModel::select( - [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates_doctype_ext'], - 'where' => ['type_id = ?'], - 'data' => [$aArgs['id']] - ] - ); - - if (empty($aReturn[0])) { - return []; - } - - $aReturn = $aReturn[0]; - - return $aReturn; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['template_id', 'type_id']); - - if (empty($aArgs['template_id'])) { - $aArgs['template_id'] = null; - } - - DatabaseModel::insert([ - 'table' => 'templates_doctype_ext', - 'columnsValues' => $aArgs - ]); - - return $aArgs; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['template_id', 'type_id']); - - if (empty($aArgs['template_id'])) { - $aArgs['template_id'] = null; - } - - DatabaseModel::update([ - 'table' => 'templates_doctype_ext', - 'set' => $aArgs, - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type_id']); - ValidatorModel::intVal($aArgs, ['type_id']); - - DatabaseModel::delete([ - 'table' => 'templates_doctype_ext', - 'where' => ['type_id = ?'], - 'data' => [$aArgs['type_id']] - ]); - - return true; - } -} diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php deleted file mode 100644 index 8288b2e8d7..0000000000 --- a/src/app/entity/controllers/EntityController.php +++ /dev/null @@ -1,456 +0,0 @@ -<?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 Entity Controller -* @author dev@maarch.org -*/ - -namespace Entity\controllers; - -use Basket\models\BasketModel; -use Entity\models\EntityModel; -use Entity\models\ListInstanceModel; -use Entity\models\ListTemplateModel; -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Resource\models\ResModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use Template\models\TemplateAssociationModel; -use User\models\UserEntityModel; -use User\models\UserModel; - -class EntityController -{ - public function get(Request $request, Response $response) - { - return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - $entity = EntityModel::getById(['entityId' => $aArgs['id']]); - if (empty($entity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); - } - - return $response->withJson(['entity' => $entity]); - } - - public function getDetailledById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $entity = EntityModel::getById(['entityId' => $aArgs['id']]); - if (empty($entity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); - } - - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - - $unneededRoles = ['visa', 'sign']; - $entity['types'] = EntityModel::getTypes(); - $entity['roles'] = EntityModel::getRoles(); - $listTemplateTypes = ListTemplateModel::getTypes(['select' => ['difflist_type_roles'], 'where' => ['difflist_type_id = ?'], 'data' => ['entity_id']]); - $rolesForService = empty($listTemplateTypes[0]['difflist_type_roles']) ? [] : explode(' ', $listTemplateTypes[0]['difflist_type_roles']); - foreach ($entity['roles'] as $key => $role) { - if (in_array($role['id'], $unneededRoles)) { - unset($entity['roles'][$key]); - continue; - } - if (in_array($role['id'], $rolesForService)) { - $entity['roles'][$key]['available'] = true; - } else { - $entity['roles'][$key]['available'] = false; - } - if ($role['id'] == 'copy') { - $entity['roles'][$key]['id'] = 'cc'; - } - } - - $listTemplates = ListTemplateModel::get([ - 'select' => ['id', 'object_type', 'item_id', 'item_type', 'item_mode', 'title', 'description', 'sequence'], - 'where' => ['object_id = ?'], - 'data' => [$aArgs['id']] - ]); - - $entity['listTemplate'] = []; - foreach ($rolesForService as $role) { - $role == 'copy' ? $entity['listTemplate']['cc'] = [] : $entity['listTemplate'][$role] = []; - } - $entity['visaTemplate'] = []; - foreach ($listTemplates as $listTemplate) { - if ($listTemplate['object_type'] == 'entity_id' && !empty($listTemplate['item_id'])) { - $entity['listTemplate']['id'] = $listTemplate['id']; - if ($listTemplate['item_type'] == 'user_id') { - $statusUser = UserModel::getByUserId(['select' => ['status', 'firstname', 'lastname'], 'userId' => $listTemplate['item_id']]); - if ($statusUser['status'] != 'DEL') { - $entity['listTemplate'][$listTemplate['item_mode']][] = [ - 'item_type' => $listTemplate['item_type'], - 'item_id' => $listTemplate['item_id'], - 'sequence' => $listTemplate['sequence'], - 'title' => $listTemplate['title'], - 'description' => $listTemplate['description'], - 'labelToDisplay' => $statusUser['firstname']. ' ' .$statusUser['lastname'], - 'descriptionToDisplay' => UserModel::getPrimaryEntityByUserId(['userId' => $listTemplate['item_id']])['entity_label'] - ]; - } - } elseif ($listTemplate['item_type'] == 'entity_id') { - $entity['listTemplate'][$listTemplate['item_mode']][] = [ - 'item_type' => $listTemplate['item_type'], - 'item_id' => $listTemplate['item_id'], - 'sequence' => $listTemplate['sequence'], - 'title' => $listTemplate['title'], - 'description' => $listTemplate['description'], - 'labelToDisplay' => EntityModel::getById(['entityId' => $listTemplate['item_id'], 'select' => ['entity_label']])['entity_label'], - 'descriptionToDisplay' => '' - ]; - } - } - if ($listTemplate['object_type'] == 'VISA_CIRCUIT' && !empty($listTemplate['item_id'])) { - $entity['visaTemplate'][] = [ - 'id' => $listTemplate['id'], - 'item_type' => $listTemplate['item_type'], - 'item_id' => $listTemplate['item_id'], - 'item_mode' => $listTemplate['item_mode'], - 'sequence' => $listTemplate['sequence'], - 'title' => $listTemplate['title'], - 'description' => $listTemplate['description'], - 'idToDisplay' => UserModel::getLabelledUserById(['userId' => $listTemplate['item_id']]), - 'descriptionToDisplay' => UserModel::getPrimaryEntityByUserId(['userId' => $listTemplate['item_id']])['entity_label'] - ]; - } - } - - $entity['users'] = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); - $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]); - $entity['hasChildren'] = count($children) > 0; - $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$aArgs['id']]]); - $entity['documents'] = count($documents); - $templates = TemplateAssociationModel::get(['select' => [1], 'where' => ['value_field = ?'], 'data' => [$aArgs['id']]]); - $entity['templates'] = count($templates); - $instances = ListInstanceModel::get(['select' => [1], 'where' => ['item_id = ?', 'item_type = ?'], 'data' => [$aArgs['id'], 'entity_id']]); - $entity['instances'] = count($instances); - $redirects = BasketModel::getGroupActionRedirect(['select' => [1], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - $entity['redirects'] = count($redirects); - $entity['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); - - return $response->withJson(['entity' => $entity]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['entity_id']) && preg_match("/^[\w-]*$/", $data['entity_id']) && (strlen($data['entity_id']) < 33); - $check = $check && Validator::stringType()->notEmpty()->validate($data['entity_label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['short_label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['entity_type']); - if (!empty($data['email'])) { - $check = $check && preg_match("/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/", $data['email']); - } - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $existingEntity = EntityModel::getById(['entityId' => $data['entity_id'], 'select' => [1]]); - if (!empty($existingEntity)) { - return $response->withStatus(400)->withJson(['errors' => _ENTITY_ID_ALREADY_EXISTS]); - } - - EntityModel::create($data); - HistoryController::add([ - 'tableName' => 'entities', - 'recordId' => $data['entity_id'], - 'eventType' => 'ADD', - 'info' => _ENTITY_CREATION . " : {$data['entity_id']}", - 'moduleId' => 'entity', - 'eventId' => 'entityCreation', - ]); - - if (empty($data['parent_entity_id']) && $GLOBALS['userId'] != 'superadmin') { - $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - $primaryEntity = UserModel::getPrimaryEntityByUserId(['userId' => $GLOBALS['userId']]); - $pEntity = 'N'; - if (empty($primaryEntity)) { - $pEntity = 'Y'; - } - - UserEntityModel::addUserEntity(['id' => $user['id'], 'entityId' => $data['entity_id'], 'role' => '', 'primaryEntity' => $pEntity]); - HistoryController::add([ - 'tableName' => 'users', - 'recordId' => $GLOBALS['userId'], - 'eventType' => 'UP', - 'info' => _USER_ENTITY_CREATION . " : {$GLOBALS['userId']} {$data['entity_id']}", - 'moduleId' => 'user', - 'eventId' => 'userModification', - ]); - } - - return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); - if (empty($entity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); - } - - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['entity_label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['short_label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['entity_type']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $fatherAndSons = EntityModel::getEntityChildren(['entityId' => $aArgs['id']]); - if (in_array($data['parent_entity_id'], $fatherAndSons)) { - return $response->withStatus(400)->withJson(['errors' => _CAN_NOT_MOVE_IN_CHILD_ENTITY]); - } - - $neededData = [ - 'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3', - 'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id', - 'entity_path', 'ldap_id', 'archival_agreement', 'archival_agency', 'entity_full_name' - ]; - foreach ($data as $key => $value) { - if (!in_array($key, $neededData)) { - unset($data[$key]); - } - } - EntityModel::update(['set' => $data, 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - HistoryController::add([ - 'tableName' => 'entities', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _ENTITY_MODIFICATION . " : {$aArgs['id']}", - 'moduleId' => 'entity', - 'eventId' => 'entityModification', - ]); - - if (empty($data['parent_entity_id']) && $GLOBALS['userId'] != 'superadmin') { - $hasEntity = UserEntityModel::get(['select' => [1], 'where' => ['user_id = ?', 'entity_id = ?'], 'data' => [$GLOBALS['userId'], $aArgs['id']]]); - if (empty($hasEntity)) { - $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - $primaryEntity = UserModel::getPrimaryEntityByUserId(['userId' => $GLOBALS['userId']]); - $pEntity = 'N'; - if (empty($primaryEntity)) { - $pEntity = 'Y'; - } - - UserEntityModel::addUserEntity(['id' => $user['id'], 'entityId' => $aArgs['id'], 'role' => '', 'primaryEntity' => $pEntity]); - HistoryController::add([ - 'tableName' => 'users', - 'recordId' => $GLOBALS['userId'], - 'eventType' => 'UP', - 'info' => _USER_ENTITY_CREATION . " : {$GLOBALS['userId']} {$aArgs['id']}", - 'moduleId' => 'user', - 'eventId' => 'userModification', - ]); - } - } - - return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); - if (empty($entity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); - } - - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - - $listTemplates = ListTemplateModel::get(['select' => [1], 'where' => ['object_id = ?'], 'data' => [$aArgs['id']]]); - $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]); - $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$aArgs['id']]]); - $users = EntityModel::getUsersById(['select' => [1], 'id' => $aArgs['id']]); - $templates = TemplateAssociationModel::get(['select' => [1], 'where' => ['value_field = ?'], 'data' => [$aArgs['id']]]); - $instances = ListInstanceModel::get(['select' => [1], 'where' => ['item_id = ?', 'item_type = ?'], 'data' => [$aArgs['id'], 'entity_id']]); - $redirects = BasketModel::getGroupActionRedirect(['select' => [1], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - - $allowedCount = count($listTemplates) + count($children) + count($documents) + count($users) + count($templates) + count($instances) + count($redirects); - if ($allowedCount > 0) { - return $response->withStatus(400)->withJson(['errors' => 'Entity is still used']); - } - - EntityModel::delete(['where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - HistoryController::add([ - 'tableName' => 'entities', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _ENTITY_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'entity', - 'eventId' => 'entitySuppression', - ]); - - return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]); - } - - public function reassignEntity(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $dyingEntity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => ['parent_entity_id']]); - $successorEntity = EntityModel::getById(['entityId' => $aArgs['newEntityId'], 'select' => [1]]); - if (empty($dyingEntity) || empty($successorEntity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity does not exist']); - } - $entities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($entities as $entity) { - if (($entity['entity_id'] == $aArgs['id'] && $entity['allowed'] == false) || ($entity['entity_id'] == $aArgs['newEntityId'] && $entity['allowed'] == false)) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - - //Documents - ResModel::update(['set' => ['destination' => $aArgs['newEntityId']], 'where' => ['destination = ?', 'status != ?'], 'data' => [$aArgs['id'], 'DEL']]); - - //Users - $users = UserEntityModel::get(['select' => ['user_id', 'entity_id', 'primary_entity'], 'where' => ['entity_id = ? OR entity_id = ?'], 'data' => [$aArgs['id'], $aArgs['newEntityId']]]); - $tmpUsers = []; - $doubleUsers = []; - foreach ($users as $user) { - if (in_array($user['user_id'], $tmpUsers)) { - $doubleUsers[] = $user['user_id']; - } - $tmpUsers[] = $user['user_id']; - } - foreach ($users as $user) { - if (in_array($user['user_id'], $doubleUsers)) { - if ($user['entity_id'] == $aArgs['id'] && $user['primary_entity'] == 'N') { - UserEntityModel::delete(['where' => ['user_id = ?', 'entity_id = ?'], 'data' => [$user['user_id'], $aArgs['id']]]); - } elseif ($user['entity_id'] == $aArgs['id'] && $user['primary_entity'] == 'Y') { - UserEntityModel::delete(['where' => ['user_id = ?', 'entity_id = ?'], 'data' => [$user['user_id'], $aArgs['newEntityId']]]); - } - } - } - UserEntityModel::update(['set' => ['entity_id' => $aArgs['newEntityId']], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - - //Entities - $entities = EntityModel::get(['select' => ['entity_id', 'parent_entity_id'], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]); - foreach ($entities as $entity) { - if ($entity['entity_id'] = $aArgs['newEntityId']) { - EntityModel::update(['set' => ['parent_entity_id' => $dyingEntity['parent_entity_id']], 'where' => ['entity_id = ?'], 'data' => [$aArgs['newEntityId']]]); - } else { - EntityModel::update(['set' => ['parent_entity_id' => $aArgs['newEntityId']], 'where' => ['entity_id = ?'], 'data' => [$entity['entity_id']]]); - } - } - - //Baskets - BasketModel::updateGroupActionRedirect(['set' => ['entity_id' => $aArgs['newEntityId']], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - //ListInstances - ListInstanceModel::update(['set' => ['item_id' => $aArgs['newEntityId']], 'where' => ['item_id = ?', 'item_type = ?'], 'data' => [$aArgs['id'], 'entity_id']]); - //ListTemplates - ListTemplateModel::delete(['where' => ['object_id = ?'], 'data' => [$aArgs['id']]]); - //Templates - TemplateAssociationModel::update(['set' => ['value_field' => $aArgs['newEntityId']], 'where' => ['value_field = ?'], 'data' => [$aArgs['id']]]); - - - EntityModel::delete(['where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); - HistoryController::add([ - 'tableName' => 'entities', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _ENTITY_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'entity', - 'eventId' => 'entitySuppression', - ]); - - return $response->withJson(['entities' => EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']])]); - } - - public function updateStatus(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); - if (empty($entity)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); - } - - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $aArgs['id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['method']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if ($data['method'] == 'disable') { - $status = 'N'; - } else { - $status = 'Y'; - } - $fatherAndSons = EntityModel::getEntityChildren(['entityId' => $aArgs['id']]); - - EntityModel::update(['set' => ['enabled' => $status], 'where' => ['entity_id in (?)'], 'data' => [$fatherAndSons]]); - HistoryController::add([ - 'tableName' => 'entities', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _ENTITY_MODIFICATION . " : {$aArgs['id']}", - 'moduleId' => 'entity', - 'eventId' => 'entityModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function getTypes(Request $request, Response $response) - { - return $response->withJson(['types' => EntityModel::getTypes()]); - } -} diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php deleted file mode 100644 index 71701e9638..0000000000 --- a/src/app/entity/controllers/ListInstanceController.php +++ /dev/null @@ -1,71 +0,0 @@ -<?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 List Instance Controller - * @author dev@maarch.org - */ - -namespace Entity\controllers; - -use Entity\models\ListInstanceModel; -use Slim\Http\Request; -use Slim\Http\Response; -use Respect\Validation\Validator; -use Resource\controllers\ResController; -use Entity\models\EntityModel; - -class ListInstanceController -{ - public function getById(Request $request, Response $response, array $aArgs) - { - $listinstance = ListInstanceModel::getById(['id' => $aArgs['id']]); - - return $response->withJson($listinstance); - } - - public function getListByResId(Request $request, Response $response, array $aArgs) - { - if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - $listinstances = ListInstanceModel::getListByResId(['select' => ['listinstance_id', 'sequence', 'CASE WHEN item_mode=\'cc\' THEN \'copy\' ELSE item_mode END', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]); - - $roles = EntityModel::getRoles(); - - foreach ($listinstances as $key2 => $listinstance) { - foreach ($roles as $key => $role) { - if ($role['id'] == $listinstance['item_mode']) { - $listinstancesFormat[$role['label']][] = $listinstance; - } - } - } - return $response->withJson($listinstancesFormat); - } - - public function getVisaCircuitByResId(Request $request, Response $response, array $aArgs) - { - if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - $listinstances = ListInstanceModel::getVisaCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]); - - return $response->withJson($listinstances); - } - - public function getAvisCircuitByResId(Request $request, Response $response, array $aArgs) - { - if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); - } - $listinstances = ListInstanceModel::getAvisCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment'], 'id' => $aArgs['resId']]); - - return $response->withJson($listinstances); - } -} diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php deleted file mode 100644 index f03bf17226..0000000000 --- a/src/app/entity/controllers/ListTemplateController.php +++ /dev/null @@ -1,396 +0,0 @@ -<?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 List Template Controller - * @author dev@maarch.org - */ - -namespace Entity\controllers; - -use Group\models\ServiceModel; -use SrcCore\models\ValidatorModel; -use Entity\models\EntityModel; -use Entity\models\ListTemplateModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\DatabaseModel; -use User\models\UserModel; - -class ListTemplateController -{ - public function get(Request $request, Response $response) - { - $rawListTemplates = ListTemplateModel::get(['select' => ['id', 'object_id', 'object_type', 'title', 'description']]); - - $listTemplates = []; - $tmpTemplates = []; - foreach ($rawListTemplates as $rawListTemplate) { - if (empty($tmpTemplates[$rawListTemplate['object_type']][$rawListTemplate['object_id']])) { - $listTemplates[] = $rawListTemplate; - $tmpTemplates[$rawListTemplate['object_type']][$rawListTemplate['object_id']] = 1; - } - } - - return $response->withJson(['listTemplates' => $listTemplates]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - $listTemplates = ListTemplateModel::getById(['id' => $aArgs['id']]); - if (empty($listTemplates)) { - return $response->withStatus(400)->withJson(['errors' => 'List template not found']); - } - - foreach ($listTemplates as $key => $value) { - if ($value['item_type'] == 'entity_id') { - $listTemplates[$key]['idToDisplay'] = EntityModel::getById(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; - $listTemplates[$key]['descriptionToDisplay'] = ''; - } else { - $listTemplates[$key]['idToDisplay'] = UserModel::getLabelledUserById(['userId' => $value['item_id']]); - $listTemplates[$key]['descriptionToDisplay'] = UserModel::getPrimaryEntityByUserId(['userId' => $value['item_id']])['entity_label']; - } - } - - $roles = EntityModel::getRoles(); - $listTemplateTypes = ListTemplateModel::getTypes(['select' => ['difflist_type_roles'], 'where' => ['difflist_type_id = ?'], 'data' => [$listTemplates[0]['object_type']]]); - $rolesForService = empty($listTemplateTypes[0]['difflist_type_roles']) ? [] : explode(' ', $listTemplateTypes[0]['difflist_type_roles']); - foreach ($roles as $key => $role) { - if (!in_array($role['id'], $rolesForService)) { - unset($roles[$key]); - } elseif ($role['id'] == 'copy') { - $entity['roles'][$key]['id'] = 'cc'; - } - } - - $listTemplate = [ - 'object_id' => $listTemplates[0]['object_id'], - 'object_type' => $listTemplates[0]['object_type'], - 'title' => $listTemplates[0]['title'], - 'description' => $listTemplates[0]['description'], - 'diffusionList' => $listTemplates, - 'roles' => array_values($roles) - ]; - - return $response->withJson(['listTemplate' => $listTemplate]); - } - - public function create(Request $request, Response $response) - { - $data = $request->getParams(); - - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && !strstr($data['object_id'], 'VISA_CIRCUIT_') && !strstr($data['object_id'], 'AVIS_CIRCUIT_')) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!ServiceModel::hasService(['id' => 'admin_listmodels', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && (strstr($data['object_id'], 'VISA_CIRCUIT_') || strstr($data['object_id'], 'AVIS_CIRCUIT_'))) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $allowedObjectTypes = ['entity_id', 'VISA_CIRCUIT', 'AVIS_CIRCUIT']; - $check = Validator::stringType()->notEmpty()->validate($data['object_type']) && in_array($data['object_type'], $allowedObjectTypes); - $check = $check && (Validator::stringType()->notEmpty()->validate($data['object_id']) || $data['object_type'] != 'entity_id'); - $check = $check && Validator::arrayType()->notEmpty()->validate($data['items']); - $check = $check && (Validator::stringType()->notEmpty()->validate($data['title']) || Validator::stringType()->notEmpty()->validate($data['description'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if (!empty($data['object_id']) && $data['object_type'] != 'AVIS_CIRCUIT') { - $listTemplate = ListTemplateModel::get(['select' => [1], 'where' => ['object_id = ?', 'object_type = ?'], 'data' => [$data['object_id'], $data['object_type']]]); - if (!empty($listTemplate)) { - return $response->withStatus(400)->withJson(['errors' => 'Entity is already linked to this type of template']); - } - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $data['object_id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - } else { - $data['object_id'] = $data['object_type'] . '_' . DatabaseModel::uniqueId(); - } - - $checkItems = ListTemplateController::checkItems(['items' => $data['items']]); - if (!empty($checkItems['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $checkItems['errors']]); - } - - $listTemplateId = null; - foreach ($data['items'] as $item) { - $listTemplateId = ListTemplateModel::create([ - 'object_id' => $data['object_id'], - 'object_type' => $data['object_type'], - 'title' => $data['title'], - 'description' => $data['description'], - 'sequence' => $item['sequence'], - 'item_id' => $item['item_id'], - 'item_type' => $item['item_type'], - 'item_mode' => $item['item_mode'], - ]); - } - - HistoryController::add([ - 'tableName' => 'listmodels', - 'recordId' => $data['object_id'], - 'eventType' => 'ADD', - 'info' => _LIST_TEMPLATE_CREATION . " : {$data['title']} {$data['description']}", - 'moduleId' => 'listTemplate', - 'eventId' => 'listTemplateCreation', - ]); - - return $response->withJson(['id' => $listTemplateId]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - $data = $request->getParams(); - $check = Validator::arrayType()->notEmpty()->validate($data['items']); - $check = $check && (Validator::stringType()->notEmpty()->validate($data['title']) || Validator::stringType()->notEmpty()->validate($data['description'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $listTemplates = ListTemplateModel::getById(['id' => $aArgs['id'], 'select' => ['object_id', 'object_type']]); - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && !strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') && !strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_')) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!ServiceModel::hasService(['id' => 'admin_listmodels', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && (strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') || strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_'))) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - if (empty($listTemplates)) { - return $response->withStatus(400)->withJson(['errors' => 'List template not found']); - } - - if (!strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') && !strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_')) { - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $listTemplates[0]['object_id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - } - - $checkItems = ListTemplateController::checkItems(['items' => $data['items']]); - if (!empty($checkItems['errors'])) { - return $response->withStatus(400)->withJson(['errors' => $checkItems['errors']]); - } - - ListTemplateModel::delete([ - 'where' => ['object_id = ?', 'object_type = ?'], - 'data' => [$listTemplates[0]['object_id'], $listTemplates[0]['object_type']] - ]); - - $listTemplateId = null; - foreach ($data['items'] as $item) { - $listTemplateId = ListTemplateModel::create([ - 'object_id' => $listTemplates[0]['object_id'], - 'object_type' => $listTemplates[0]['object_type'], - 'title' => $data['title'], - 'description' => $data['description'], - 'sequence' => $item['sequence'], - 'item_id' => $item['item_id'], - 'item_type' => $item['item_type'], - 'item_mode' => $item['item_mode'], - ]); - } - - HistoryController::add([ - 'tableName' => 'listmodels', - 'recordId' => $listTemplates[0]['object_id'], - 'eventType' => 'UP', - 'info' => _LIST_TEMPLATE_MODIFICATION . " : {$data['title']} {$data['description']}", - 'moduleId' => 'listTemplate', - 'eventId' => 'listTemplateModification', - ]); - - return $response->withJson(['id' => $listTemplateId]); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - - $listTemplates = ListTemplateModel::getById(['id' => $aArgs['id'], 'select' => ['object_id', 'object_type']]); - - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && !strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') && !strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_')) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!ServiceModel::hasService(['id' => 'admin_listmodels', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin']) && (strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') || strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_'))) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (empty($listTemplates)) { - return $response->withStatus(400)->withJson(['errors' => 'List template not found']); - } - - if (!strstr($listTemplates[0]['object_id'], 'VISA_CIRCUIT_') && !strstr($listTemplates[0]['object_id'], 'AVIS_CIRCUIT_')) { - $aEntities = EntityModel::getAllowedEntitiesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($aEntities as $aEntity) { - if ($aEntity['entity_id'] == $listTemplates[0]['object_id'] && $aEntity['allowed'] == false) { - return $response->withStatus(403)->withJson(['errors' => 'Entity out of perimeter']); - } - } - } - - ListTemplateModel::delete([ - 'where' => ['object_id = ?', 'object_type = ?'], - 'data' => [$listTemplates[0]['object_id'], $listTemplates[0]['object_type']] - ]); - HistoryController::add([ - 'tableName' => 'listmodels', - 'recordId' => $listTemplates[0]['object_id'], - 'eventType' => 'DEL', - 'info' => _LIST_TEMPLATE_SUPPRESSION . " : {$listTemplates[0]['object_id']} {$listTemplates[0]['object_type']}", - 'moduleId' => 'listTemplate', - 'eventId' => 'listTemplateSuppression', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function getByUserWithEntityDest(Request $request, Response $response, array $aArgs) - { - $listTemplates = ListTemplateModel::get([ - 'select' => ['object_id', 'title'], - 'where' => ['item_id = ?', 'object_type = ?', 'item_mode = ?'], - 'data' => [$aArgs['itemId'], 'entity_id', 'dest'] - ]); - - return $response->withJson(['listTemplates' => $listTemplates]); - } - - public function updateByUserWithEntityDest(Request $request, Response $response) - { - $data = $request->getParams(); - - foreach ($data['redirectListModels'] as $listModel) { - $user = UserModel::getByUserId(['userId' => $listModel['redirectUserId']]); - if (empty($user)) { - return $response->withStatus(400)->withJson(['errors' => 'User not found']); - } - - ListTemplateModel::update([ - 'set' => ['item_id' => $listModel['redirectUserId']], - 'where' => ['item_id = ?', 'object_id = ?', 'object_type = ?', 'item_mode = ?'], - 'data' => [$data['user_id'], $listModel['object_id'], 'entity_id', 'dest'] - ]); - } - - return $response->withJson(['success' => 'success']); - } - - public function getTypeRoles(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $unneededRoles = []; - if ($aArgs['typeId'] == 'entity_id') { - $unneededRoles = ['visa', 'sign']; - } - $roles = EntityModel::getRoles(); - $listTemplateTypes = ListTemplateModel::getTypes(['select' => ['difflist_type_roles'], 'where' => ['difflist_type_id = ?'], 'data' => [$aArgs['typeId']]]); - $rolesForType = empty($listTemplateTypes[0]['difflist_type_roles']) ? [] : explode(' ', $listTemplateTypes[0]['difflist_type_roles']); - foreach ($roles as $key => $role) { - if (in_array($role['id'], $unneededRoles)) { - unset($roles[$key]); - continue; - } - if (in_array($role['id'], $rolesForType)) { - $roles[$key]['available'] = true; - } else { - $roles[$key]['available'] = false; - } - if ($role['id'] == 'copy') { - $roles[$key]['id'] = 'cc'; - } - - $roles[$key]['usedIn'] = []; - $listTemplates = ListTemplateModel::get(['select' => ['object_id'], 'where' => ['object_type = ?', 'item_mode = ?'], 'data' => [$aArgs['typeId'], $roles[$key]['id']]]); - foreach ($listTemplates as $listTemplate) { - $entity = EntityModel::getById(['select' => ['short_label'], 'entityId' => $listTemplate['object_id']]); - $roles[$key]['usedIn'][] = $entity['short_label']; - } - } - - return $response->withJson(['roles' => array_values($roles)]); - } - - public function updateTypeRoles(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'manage_entities', 'userId' => $GLOBALS['userId'], 'location' => 'entities', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::arrayType()->notEmpty()->validate($data['roles']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $roles = ''; - foreach ($data['roles'] as $role) { - if ($role['available'] === true) { - if ($role['id'] == 'cc') { - $role['id'] = 'copy'; - } - - if (!empty($roles)) { - $roles .= ' '; - } - $roles .= $role['id']; - } - } - - ListTemplateModel::updateTypes([ - 'set' => ['difflist_type_roles' => $roles], - 'where' => ['difflist_type_id = ?'], - 'data' => [$aArgs['typeId']] - ]); - if (empty($roles)) { - ListTemplateModel::delete([ - 'where' => ['object_type = ?'], - 'data' => [$aArgs['typeId']] - ]); - } else { - ListTemplateModel::delete([ - 'where' => ['object_type = ?', 'item_mode not in (?)'], - 'data' => [$aArgs['typeId'], explode(' ', $roles)] - ]); - } - - return $response->withJson(['success' => 'success']); - } - - private static function checkItems(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['items']); - ValidatorModel::arrayType($aArgs, ['items']); - - foreach ($aArgs['items'] as $item) { - if (empty($item['item_id'])) { - return ['errors' => 'Item_id is empty']; - } - if (empty($item['item_type'])) { - return ['errors' => 'Item_type is empty']; - } - if (empty($item['item_mode'])) { - return ['errors' => 'Item_mode is empty']; - } - } - - return ['success' => 'success']; - } -} diff --git a/src/app/entity/models/EntityModel.php b/src/app/entity/models/EntityModel.php deleted file mode 100644 index ba83247577..0000000000 --- a/src/app/entity/models/EntityModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Entity Model -* @author dev@maarch.org -*/ - -namespace Entity\models; - -class EntityModel extends EntityModelAbstract -{ -} diff --git a/src/app/entity/models/EntityModelAbstract.php b/src/app/entity/models/EntityModelAbstract.php deleted file mode 100644 index a226b14325..0000000000 --- a/src/app/entity/models/EntityModelAbstract.php +++ /dev/null @@ -1,377 +0,0 @@ -<?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 Entity Model Abstract -* @author dev@maarch.org -*/ - -namespace Entity\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; -use User\models\UserModel; - -abstract class EntityModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aEntities = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['entities'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aEntities; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entityId']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $aEntity = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['entities'], - 'where' => ['entity_id = ?'], - 'data' => [$aArgs['entityId']] - ]); - - return $aEntity[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entity_id', 'entity_label', 'short_label', 'entity_type']); - ValidatorModel::stringType($aArgs, [ - 'entity_id', 'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3', - 'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id', - 'entity_path', 'ldap_id', 'transferring_agency', 'archival_agreement', 'archival_agency', 'entity_full_name' - ]); - - DatabaseModel::insert([ - 'table' => 'entities', - 'columnsValues' => [ - 'entity_id' => $aArgs['entity_id'], - 'entity_label' => $aArgs['entity_label'], - 'short_label' => $aArgs['short_label'], - 'adrs_1' => $aArgs['adrs_1'], - 'adrs_2' => $aArgs['adrs_2'], - 'adrs_3' => $aArgs['adrs_3'], - 'zipcode' => $aArgs['zipcode'], - 'city' => $aArgs['city'], - 'country' => $aArgs['country'], - 'email' => $aArgs['email'], - 'business_id' => $aArgs['business_id'], - 'parent_entity_id' => $aArgs['parent_entity_id'], - 'entity_type' => $aArgs['entity_type'], - 'entity_path' => $aArgs['entity_path'], - 'ldap_id' => $aArgs['ldap_id'], - 'archival_agreement' => $aArgs['archival_agreement'], - 'archival_agency' => $aArgs['archival_agency'], - 'entity_full_name' => $aArgs['entity_full_name'], - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - ValidatorModel::stringType($aArgs['set'], [ - 'entity_label', 'short_label', 'entity_type', 'adrs_1', 'adrs_2', 'adrs_3', - 'zipcode', 'city', 'country', 'email', 'business_id', 'parent_entity_id', - 'entity_path', 'ldap_id', 'transferring_agency', 'archival_agreement', 'archival_agency', 'entity_full_name' - ]); - - DatabaseModel::update([ - 'table' => 'entities', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'entities', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getByEmail(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['email']); - ValidatorModel::stringType($aArgs, ['email']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['entities'], - 'where' => ['email = ?', 'enabled = ?'], - 'data' => [$aArgs['email'], 'Y'], - 'limit' => 1, - ]); - - return $aReturn; - } - - public static function getByBusinessId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['businessId']); - ValidatorModel::stringType($aArgs, ['businessId']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['entities'], - 'where' => ['business_id = ? and enabled = ?'], - 'data' => [$aArgs['businessId'], 'Y'], - 'limit' => 1, - ]); - - return $aReturn; - } - - public static function getByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aEntities = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_entities'], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - return $aEntities; - } - - public static function getEntitiesByUserId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['user_id']); - ValidatorModel::stringType($aArgs, ['user_id']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_entities', 'entities'], - 'left_join' => ['users_entities.entity_id = entities.entity_id'], - 'where' => ['user_id = ?', 'business_id <> \'\''], - 'data' => [$aArgs['user_id']] - ]); - - return $aReturn; - } - - public static function getEntityRootById(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['entityId']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $aReturn = EntityModel::getById([ - 'select' => ['entity_id', 'entity_label', 'parent_entity_id'], - 'entityId' => $aArgs['entityId'] - ]); - - if (!empty($aReturn['parent_entity_id'])) { - $aReturn = EntityModel::getEntityRootById(['entityId' => $aReturn['parent_entity_id']]); - } - - return $aReturn; - } - - public static function getEntityChildren(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entityId']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $aReturn = DatabaseModel::select([ - 'select' => ['entity_id'], - 'table' => ['entities'], - 'where' => ['parent_entity_id = ?'], - 'data' => [$aArgs['entityId']] - ]); - - $entities = [$aArgs['entityId']]; - foreach ($aReturn as $value) { - $entities = array_merge($entities, EntityModel::getEntityChildren(['entityId' => $value['entity_id']])); - } - - return $entities; - } - - public static function getAllEntitiesByUserId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aReturn = UserModel::getEntitiesById(['userId' => $aArgs['userId']]); - - $entities = []; - foreach ($aReturn as $value) { - $entities = array_merge($entities, EntityModel::getEntityChildren(['entityId' => $value['entity_id']])); - } - - return array_unique($entities); - } - - public static function getAvailableEntitiesForAdministratorByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'administratorUserId']); - ValidatorModel::stringType($aArgs, ['userId', 'administratorUserId']); - - if ($aArgs['administratorUserId'] == 'superadmin') { - $rawEntitiesAllowedForAdministrator = EntityModel::get(['select' => ['entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['entity_label']]); - $entitiesAllowedForAdministrator = []; - foreach ($rawEntitiesAllowedForAdministrator as $value) { - $entitiesAllowedForAdministrator[] = $value['entity_id']; - } - } else { - $entitiesAllowedForAdministrator = EntityModel::getAllEntitiesByUserId(['userId' => $aArgs['administratorUserId']]); - } - - $rawUserEntities = EntityModel::getByUserId(['userId' => $aArgs['userId'], 'select' => ['entity_id']]); - - $userEntities = []; - foreach ($rawUserEntities as $value) { - $userEntities[] = $value['entity_id']; - } - - $allEntities = EntityModel::get(['select' => ['entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['entity_label']]); - - foreach ($allEntities as $key => $value) { - $allEntities[$key]['id'] = $value['entity_id']; - if (empty($value['parent_entity_id'])) { - $allEntities[$key]['parent'] = '#'; - $allEntities[$key]['icon'] = "fa fa-building"; - } else { - $allEntities[$key]['parent'] = $value['parent_entity_id']; - $allEntities[$key]['icon'] = "fa fa-sitemap"; - } - $allEntities[$key]['text'] = $value['entity_label']; - if (in_array($value['entity_id'], $userEntities)) { - $allEntities[$key]['state']['opened'] = true; - $allEntities[$key]['state']['selected'] = true; - } - if (!in_array($value['entity_id'], $entitiesAllowedForAdministrator)) { - $allEntities[$key]['state']['disabled'] = true; - } - } - - return $allEntities; - } - - public static function getAllowedEntitiesByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - if ($aArgs['userId'] == 'superadmin') { - $rawEntitiesAllowed = EntityModel::get(['select' => ['entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['entity_label']]); - $entitiesAllowed = []; - foreach ($rawEntitiesAllowed as $value) { - $entitiesAllowed[] = $value['entity_id']; - } - } else { - $entitiesAllowed = EntityModel::getAllEntitiesByUserId(['userId' => $aArgs['userId']]); - } - - $allEntities = EntityModel::get(['select' => ['entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['parent_entity_id']]); - - foreach ($allEntities as $key => $value) { - $allEntities[$key]['id'] = $value['entity_id']; - if (empty($value['parent_entity_id'])) { - $allEntities[$key]['parent'] = '#'; - $allEntities[$key]['icon'] = "fa fa-building"; - } else { - $allEntities[$key]['parent'] = $value['parent_entity_id']; - $allEntities[$key]['icon'] = "fa fa-sitemap"; - } - if (in_array($value['entity_id'], $entitiesAllowed)) { - $allEntities[$key]['allowed'] = true; - } else { - $allEntities[$key]['allowed'] = false; - $allEntities[$key]['state']['disabled'] = true; - } - $allEntities[$key]['state']['opened'] = true; - $allEntities[$key]['text'] = $value['entity_label']; - } - - return $allEntities; - } - - public static function getUsersById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aUsers = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_entities, users'], - 'where' => ['users_entities.entity_id = ?', 'users_entities.user_id = users.user_id', 'users.status != ?'], - 'data' => [$aArgs['id'], 'DEL'] - ]); - - return $aUsers; - } - - public static function getTypes() - { - $types = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/entities/xml/typentity.xml']); - if ($loadedXml) { - foreach ($loadedXml->TYPE as $value) { - $types[] = [ - 'id' => (string)$value->id, - 'label' => (string)$value->label, - 'typelevel' => (string)$value->typelevel - ]; - } - } - - return $types; - } - - public static function getRoles() - { - $roles = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/entities/xml/roles.xml']); - if ($loadedXml) { - foreach ($loadedXml->ROLES->ROLE as $value) { - $roles[] = [ - 'id' => (string)$value->id, - 'label' => defined((string)$value->label) ? constant((string)$value->label) : (string)$value->label - ]; - } - } - - return $roles; - } -} diff --git a/src/app/entity/models/ListInstanceModel.php b/src/app/entity/models/ListInstanceModel.php deleted file mode 100644 index b5564bd6f7..0000000000 --- a/src/app/entity/models/ListInstanceModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 List Instance Model - * @author dev@maarch.org - */ - -namespace Entity\models; - -class ListInstanceModel extends ListInstanceModelAbstract -{ -} diff --git a/src/app/entity/models/ListInstanceModelAbstract.php b/src/app/entity/models/ListInstanceModelAbstract.php deleted file mode 100644 index b02aa57006..0000000000 --- a/src/app/entity/models/ListInstanceModelAbstract.php +++ /dev/null @@ -1,191 +0,0 @@ -<?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 List Instance Model Abstract - * @author dev@maarch.org - */ - -namespace Entity\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ListInstanceModelAbstract -{ - public static function get(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aListInstances = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['listinstance'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'], - 'limit' => $aArgs['limit'] - ]); - - return $aListInstances; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance'], - 'where' => ['listinstance_id = ?'], - 'data' => [$aArgs['id']], - ]); - - if (empty($aListinstance[0])) { - return []; - } - - return $aListinstance[0]; - } - - public static function getListByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'users', 'users_entities', 'entities'], - 'left_join' => ['listinstance.item_id = users.user_id', 'users_entities.user_id = users.user_id', 'entities.entity_id = users_entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?', 'primary_entity = ?'], - 'data' => [$aArgs['id'], 'user_id', 'entity_id', 'Y'], - 'order_by' => ['listinstance_id ASC'], - ]); - - unset($aArgs['select'][5]); - unset($aArgs['select'][6]); - - $aListinstance2 = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'entities'], - 'left_join' => ['listinstance.item_id = entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?'], - 'data' => [$aArgs['id'], 'entity_id', 'entity_id'], - 'order_by' => ['listinstance_id ASC'], - ]); - - return array_merge($aListinstance, $aListinstance2); - } - - public static function getVisaCircuitByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'users', 'users_entities', 'entities'], - 'left_join' => ['listinstance.item_id = users.user_id', 'users_entities.user_id = users.user_id', 'entities.entity_id = users_entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?', 'primary_entity = ?'], - 'data' => [$aArgs['id'], 'user_id', 'VISA_CIRCUIT', 'Y'], - 'order_by' => ['listinstance_id ASC'], - ]); - - return $aListinstance; - } - - public static function getAvisCircuitByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'users', 'users_entities', 'entities'], - 'left_join' => ['listinstance.item_id = users.user_id', 'users_entities.user_id = users.user_id', 'entities.entity_id = users_entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?', 'primary_entity = ?'], - 'data' => [$aArgs['id'], 'user_id', 'AVIS_CIRCUIT', 'Y'], - 'order_by' => ['listinstance_id ASC'], - ]); - - return $aListinstance; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['res_id']); - ValidatorModel::intVal($aArgs, ['res_id']); - - DatabaseModel::insert([ - 'table' => 'listinstance', - 'columnsValues' => $aArgs - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'listinstance', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getCurrentStepByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance'], - 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], - 'data' => [$aArgs['resId'], 'VISA_CIRCUIT'], - 'order_by' => ['listinstance_id ASC'], - 'limit' => 1 - ]); - - if (empty($aListinstance[0])) { - return []; - } - - return $aListinstance[0]; - } - - public static function getWithConfidentiality(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entityId', 'userId']); - ValidatorModel::stringType($aArgs, ['entityId', 'userId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListInstances = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance, res_letterbox, mlb_coll_ext'], - 'where' => ['listinstance.res_id = res_letterbox.res_id', 'mlb_coll_ext.res_id = res_letterbox.res_id', 'confidentiality = ?', 'destination = ?', 'item_id = ?', 'closing_date is null'], - 'data' => ['Y', $aArgs['entityId'], $aArgs['userId']] - ]); - - return $aListInstances; - } -} diff --git a/src/app/entity/models/ListTemplateModel.php b/src/app/entity/models/ListTemplateModel.php deleted file mode 100644 index dfae0e2356..0000000000 --- a/src/app/entity/models/ListTemplateModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 List Template Model - * @author dev@maarch.org - */ - -namespace Entity\models; - -class ListTemplateModel extends ListTemplateModelAbstract -{ -} diff --git a/src/app/entity/models/ListTemplateModelAbstract.php b/src/app/entity/models/ListTemplateModelAbstract.php deleted file mode 100644 index 8e7a5dba1c..0000000000 --- a/src/app/entity/models/ListTemplateModelAbstract.php +++ /dev/null @@ -1,146 +0,0 @@ -<?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 List Template Model Abstract - * @author dev@maarch.org - */ - -namespace Entity\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ListTemplateModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $aListTemplates = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listmodels'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $aListTemplates; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $basicTemplate = DatabaseModel::select([ - 'select' => ['object_id', 'object_type'], - 'table' => ['listmodels'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - if (empty($basicTemplate)) { - return []; - } - - $aListTemplates = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listmodels'], - 'where' => ['object_id = ?', 'object_type = ?'], - 'data' => [$basicTemplate[0]['object_id'], $basicTemplate[0]['object_type']] - ]); - - return $aListTemplates; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['object_id', 'object_type', 'item_id', 'item_type', 'item_mode']); - ValidatorModel::stringType($aArgs, ['object_id', 'object_type', 'item_id', 'item_type', 'title', 'description']); - ValidatorModel::intVal($aArgs, ['sequence']); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'listmodels_id_seq']); - - DatabaseModel::insert([ - 'table' => 'listmodels', - 'columnsValues' => [ - 'id' => $nextSequenceId, - 'object_id' => $aArgs['object_id'], - 'object_type' => $aArgs['object_type'], - 'sequence' => $aArgs['sequence'], - 'item_id' => $aArgs['item_id'], - 'item_type' => $aArgs['item_type'], - 'item_mode' => $aArgs['item_mode'], - 'title' => $aArgs['title'], - 'description' => $aArgs['description'], - 'visible' => 'Y' - ] - ]); - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'listmodels', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'listmodels', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getTypes(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $aListTemplatesTypes = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['difflist_types'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $aListTemplatesTypes; - } - - public static function updateTypes(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'difflist_types', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } -} diff --git a/src/app/folder/models/FolderTypeModel.php b/src/app/folder/models/FolderTypeModel.php deleted file mode 100644 index 4d86e5fa64..0000000000 --- a/src/app/folder/models/FolderTypeModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 FolderType Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Folder\models; - -class FolderTypeModel extends FolderTypeModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/folder/models/FolderTypeModelAbstract.php b/src/app/folder/models/FolderTypeModelAbstract.php deleted file mode 100644 index b76308bf04..0000000000 --- a/src/app/folder/models/FolderTypeModelAbstract.php +++ /dev/null @@ -1,71 +0,0 @@ -<?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 FolderTypeModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -namespace Folder\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -class FolderTypeModelAbstract -{ - public static function get(array $aArgs) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $folderType = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['foldertypes'] - ]); - - return $folderType; - } - - public static function getFolderTypeDocTypeFirstLevel(array $aArgs) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $folderType = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['foldertypes_doctypes_level1'], - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['doctypes_first_level_id']] - ]); - - return $folderType; - } - - public static function createFolderTypeDocTypeFirstLevel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['foldertype_id', 'doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['foldertype_id', 'doctypes_first_level_id']); - - DatabaseModel::insert([ - 'table' => 'foldertypes_doctypes_level1', - 'columnsValues' => $aArgs - ]); - - return true; - } - - public static function deleteFolderTypeDocTypeFirstLevel(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['doctypes_first_level_id']); - ValidatorModel::intVal($aArgs, ['doctypes_first_level_id']); - - DatabaseModel::delete([ - 'table' => 'foldertypes_doctypes_level1', - 'where' => ['doctypes_first_level_id = ?'], - 'data' => [$aArgs['doctypes_first_level_id']] - ]); - - return true; - } -} diff --git a/src/app/group/controllers/GroupController.php b/src/app/group/controllers/GroupController.php deleted file mode 100644 index 69f9815e00..0000000000 --- a/src/app/group/controllers/GroupController.php +++ /dev/null @@ -1,265 +0,0 @@ -<?php - -namespace Group\controllers; - -use Basket\models\GroupBasketModel; -use Group\models\ServiceModel; -use Group\models\GroupModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\controllers\PreparedClauseController; -use SrcCore\models\ValidatorModel; -use User\models\UserModel; - -class GroupController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $groups = GroupModel::get(); - foreach ($groups as $key => $value) { - $groups[$key]['users'] = GroupModel::getUsersByGroupId(['groupId' => $value['group_id'], 'select' => ['users.user_id', 'users.firstname', 'users.lastname']]); - } - - return $response->withJson(['groups' => $groups]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getById(['id' => $aArgs['id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - return $response->withJson(['group' => $group]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['group_id']) && preg_match("/^[\w-]*$/", $data['group_id']) && (strlen($data['group_id']) < 33); - $check = $check && Validator::stringType()->notEmpty()->validate($data['group_desc']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['security']['where_clause']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $existingGroup = GroupModel::getByGroupId(['groupId' => $data['group_id'], 'select' => ['1']]); - if (!empty($existingGroup)) { - return $response->withStatus(400)->withJson(['errors' => _ID. ' ' . _ALREADY_EXISTS]); - } - - if (!PreparedClauseController::isRequestValid(['clause' => $data['security']['where_clause'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(400)->withJson(['errors' => _INVALID_CLAUSE]); - } - - GroupModel::create(['groupId' => $data['group_id'], 'description' => $data['group_desc'], 'clause' => $data['security']['where_clause'], 'comment' => $data['security']['maarch_comment']]); - - $group = GroupModel::getByGroupId(['groupId' => $data['group_id'], 'select' => ['id']]); - if (empty($group)) { - return $response->withStatus(500)->withJson(['errors' => 'Group Creation Error']); - } - - return $response->withJson(['group' => $group['id']]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getById(['id' => $aArgs['id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['description']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['security']['where_clause']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if (!PreparedClauseController::isRequestValid(['clause' => $data['security']['where_clause'], 'userId' => $GLOBALS['userId']])) { - return $response->withStatus(400)->withJson(['errors' => _INVALID_CLAUSE]); - } - - GroupModel::update(['id' => $aArgs['id'], 'description' => $data['description'], 'clause' => $data['security']['where_clause'], 'comment' => $data['security']['maarch_comment']]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getById(['id' => $aArgs['id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - GroupModel::delete(['id' => $aArgs['id']]); - - $groups = GroupModel::get(); - foreach ($groups as $key => $value) { - $groups[$key]['users'] = GroupModel::getUsersByGroupId(['groupId' => $value['group_id'], 'select' => ['users.user_id']]); - } - - return $response->withJson(['groups' => $groups]); - } - - public function getDetailledById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getById(['id' => $aArgs['id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - $group['security'] = GroupModel::getSecurityByGroupId(['groupId' => $group['group_id']]); - $group['services'] = GroupModel::getAllServicesByGroupId(['groupId' => $group['group_id']]); - $group['users'] = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); - $group['baskets'] = GroupBasketModel::getBasketsByGroupId(['select' => ['baskets.basket_id', 'baskets.basket_name', 'baskets.basket_desc'], 'groupId' => $group['group_id']]); - $group['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); - $group['canAdminBaskets'] = ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin']); - - return $response->withJson(['group' => $group]); - } - - public function updateService(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $group = GroupModel::getById(['id' => $aArgs['id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - if ($data['checked'] === true && !empty(GroupModel::getServiceById(['groupId' => $group['group_id'], 'serviceId' => $aArgs['serviceId']]))) { - return $response->withStatus(400)->withJson(['errors' => 'Service is already linked to this group']); - } - - GroupModel::updateServiceById(['groupId' => $group['group_id'], 'serviceId' => $aArgs['serviceId'], 'checked' => $data['checked']]); - - return $response->withJson(['success' => 'success']); - } - - public function reassignUsers(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_groups', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getById(['id' => $aArgs['id'], 'select' => ['group_id']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - $newGroup = GroupModel::getById(['id' => $aArgs['newGroupId'], 'select' => ['group_id']]); - if (empty($newGroup)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - $oldGroupUsers = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.user_id']]); - $newGroupUsers = GroupModel::getUsersByGroupId(['groupId' => $newGroup['group_id'], 'select' => ['users.user_id']]); - - //Mapped array to have only user_id - $oldGroupUsers = array_map(function ($entry) { - return $entry['user_id']; - }, $oldGroupUsers); - - $newGroupUsers = array_map(function ($entry) { - return $entry['user_id']; - }, $newGroupUsers); - - $ignoredUsers = []; - foreach ($oldGroupUsers as $user) { - if (in_array($user, $newGroupUsers)) { - $ignoredUsers[] = $user; - } - } - - GroupModel::reassignUsers(['groupId' => $group['group_id'], 'newGroupId' => $newGroup['group_id'], 'ignoredUsers' => $ignoredUsers]); - - return $response->withJson(['success' => 'success']); - } - - public static function getGroupsClause(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $groups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); - $groupsClause = ''; - foreach ($groups as $key => $group) { - if (!empty($group['where_clause'])) { - $groupClause = PreparedClauseController::getPreparedClause(['clause' => $group['where_clause'], 'userId' => $aArgs['userId']]); - if ($key > 0) { - $groupsClause .= ' or '; - } - $groupsClause .= "({$groupClause})"; - } - } - - return $groupsClause; - } - - public static function arraySort($aArgs) - { - ValidatorModel::notEmpty($aArgs, ['data', 'on']); - ValidatorModel::arrayType($aArgs, ['data']); - ValidatorModel::stringType($aArgs, ['on']); - - $order = SORT_ASC; - $sortableArray = []; - - foreach ($aArgs['data'] as $k => $v) { - if (is_array($v)) { - foreach ($v as $k2 => $v2) { - if ($k2 == $aArgs['on']) { - $sortableArray[$k] = $v2; - } - } - } else { - $sortableArray[$k] = $v; - } - } - - switch ($order) { - case SORT_ASC: - asort($sortableArray); - break; - case SORT_DESC: - arsort($sortableArray); - break; - } - - $newArray = []; - foreach ($sortableArray as $k => $v) { - $newArray[] = $aArgs['data'][$k]; - } - - return $newArray; - } -} diff --git a/src/app/group/controllers/ServiceController.php b/src/app/group/controllers/ServiceController.php deleted file mode 100644 index 02e37ebe97..0000000000 --- a/src/app/group/controllers/ServiceController.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -namespace Group\controllers; - -use Group\models\ServiceModel; -use SrcCore\models\ValidatorModel; - -class ServiceController -{ - public static function getMenuServicesByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $rawServicesStoredInDB = ServiceModel::getByUserId(['userId' => $aArgs['userId']]); - $servicesStoredInDB = []; - foreach ($rawServicesStoredInDB as $value) { - $servicesStoredInDB[] = $value['service_id']; - } - - $menu = ServiceModel::getApplicationServicesByUserServices(['userServices' => $servicesStoredInDB, 'type' => 'menu']); - $menuModules = ServiceModel::getModulesServicesByUserServices(['userServices' => $servicesStoredInDB, 'type' => 'menu']); - $menu = array_merge($menu, $menuModules); - - return $menu; - } -} diff --git a/src/app/group/models/GroupModel.php b/src/app/group/models/GroupModel.php deleted file mode 100644 index 43d868d7a1..0000000000 --- a/src/app/group/models/GroupModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Group Model -* @author dev@maarch.org -*/ - -namespace Group\models; - -class GroupModel extends GroupModelAbstract -{ -} diff --git a/src/app/group/models/GroupModelAbstract.php b/src/app/group/models/GroupModelAbstract.php deleted file mode 100644 index d9ff93ae1b..0000000000 --- a/src/app/group/models/GroupModelAbstract.php +++ /dev/null @@ -1,366 +0,0 @@ -<?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 Group Model -* @author dev@maarch.org -*/ - -namespace Group\models; - -use Group\controllers\GroupController; -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; -use User\models\UserModel; - -abstract class GroupModelAbstract -{ - public static function get(array $aArgs = []) - { - $aGroups = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['usergroups'], - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'order_by' => ['group_desc'] - ]); - - return $aGroups; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - $aGroups = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['usergroups'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aGroups[0]; - } - - public static function getByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $aGroups = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['usergroups'], - 'where' => ['group_id = ?'], - 'data' => [$aArgs['groupId']] - ]); - - return $aGroups[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'description', 'clause']); - ValidatorModel::stringType($aArgs, ['groupId', 'description', 'clause', 'comment']); - - DatabaseModel::insert([ - 'table' => 'usergroups', - 'columnsValues' => [ - 'group_id' => $aArgs['groupId'], - 'group_desc' => $aArgs['description'] - ] - ]); - - DatabaseModel::insert([ - 'table' => 'security', - 'columnsValues' => [ - 'group_id' => $aArgs['groupId'], - 'coll_id' => 'letterbox_coll', - 'where_clause' => $aArgs['clause'], - 'maarch_comment' => $aArgs['comment'], - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'description', 'clause']); - ValidatorModel::stringType($aArgs, ['id', 'description', 'clause', 'comment']); - - DatabaseModel::update([ - 'table' => 'usergroups', - 'set' => [ - 'group_desc' => $aArgs['description'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - $group = GroupModel::getById(['id' => $aArgs['id'], 'select' => ['group_id']]); - - DatabaseModel::update([ - 'table' => 'security', - 'set' => [ - 'where_clause' => $aArgs['clause'], - 'maarch_comment' => $aArgs['comment'], - ], - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - $group = GroupModel::getById(['id' => $aArgs['id'], 'select' => ['group_id']]); - - DatabaseModel::delete([ - 'table' => 'usergroups', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - DatabaseModel::delete([ - 'table' => 'usergroup_content', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'usergroups_reports', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'usergroups_services', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'security', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_redirect', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'groupbasket_status', - 'where' => ['group_id = ?'], - 'data' => [$group['group_id']] - ]); - DatabaseModel::delete([ - 'table' => 'users_baskets_preferences', - 'where' => ['group_serial_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function getUsersByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aUsers = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['usergroup_content, users'], - 'where' => ['group_id = ?', 'usergroup_content.user_id = users.user_id', 'users.status != ?'], - 'data' => [$aArgs['groupId'], 'DEL'] - ]); - - return $aUsers; - } - - public static function getAvailableGroupsByUserId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $rawUserGroups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); - - $userGroups = []; - foreach ($rawUserGroups as $value) { - $userGroups[] = $value['group_id']; - } - - $allGroups = GroupModel::get(['select' => ['group_id', 'group_desc']]); - - foreach ($allGroups as $key => $value) { - if (in_array($value['group_id'], $userGroups)) { - $allGroups[$key]['disabled'] = true; - } else { - $allGroups[$key]['disabled'] = false; - } - } - - return $allGroups; - } - - public static function getSecurityByGroupId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $aData = DatabaseModel::select([ - 'select' => ['where_clause', 'maarch_comment'], - 'table' => ['security'], - 'where' => ['group_id = ?'], - 'data' => [$aArgs['groupId']] - ]); - - return $aData[0]; - } - - public static function getServiceById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'serviceId']); - ValidatorModel::stringType($aArgs, ['groupId', 'serviceId']); - - $service = DatabaseModel::select([ - 'select' => ['group_id', 'service_id'], - 'table' => ['usergroups_services'], - 'where' => ['group_id = ?', 'service_id = ?'], - 'data' => [$aArgs['groupId'], $aArgs['serviceId']] - ]); - - return $service; - } - - public static function getServicesById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $aServices = DatabaseModel::select([ - 'select' => ['service_id'], - 'table' => ['usergroups_services'], - 'where' => ['group_id = ?'], - 'data' => [$aArgs['groupId']] - ]); - - return $aServices; - } - - public static function getAllServicesByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $rawCheckedServices = GroupModel::getServicesById(['groupId' => $aArgs['groupId']]); - $checkedServices = []; - foreach ($rawCheckedServices as $value) { - $checkedServices[] = $value['service_id']; - } - - $allServices = ServiceModel::getServicesByXML(); - - $services = []; - foreach ($allServices as $key => $value) { - $menu = []; - $use = []; - foreach ($value as $value2) { - if (!$value2['system_service']) { - if (in_array($value2['id'], $checkedServices)) { - $value2['checked'] = true; - } else { - $value2['checked'] = false; - } - $value2['location'] = $key; - if ($value2['servicetype'] == 'menu') { - $menu[] = $value2; - } elseif ($value2['servicetype'] == 'admin') { - $services['administration'][] = $value2; - } elseif ($value2['servicetype'] == 'use') { - $use[] = $value2; - } - } - } - if (!empty($menu)) { - $services['menu'][] = $menu; - } - if (!empty($use)) { - $services['use'][] = $use; - } - } - - foreach ($services['menu'] as $key => $menu) { - $services['menu'][$key] = GroupController::arraySort(['data' => $menu, 'on' => 'name']); - } - foreach ($services['use'] as $key => $use) { - $services['use'][$key] = GroupController::arraySort(['data' => $use, 'on' => 'name']); - } - $services['administration'] = GroupController::arraySort(['data' => $services['administration'], 'on' => 'name']); - - return $services; - } - - public static function updateServiceById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'serviceId']); - ValidatorModel::stringType($aArgs, ['groupId', 'serviceId']); - ValidatorModel::boolType($aArgs, ['checked']); - - if ($aArgs['checked']) { - DatabaseModel::insert([ - 'table' => 'usergroups_services', - 'columnsValues' => [ - 'group_id' => $aArgs['groupId'], - 'service_id' => $aArgs['serviceId'] - ] - ]); - } else { - DatabaseModel::delete([ - 'table' => 'usergroups_services', - 'where' => ['group_id = ?', 'service_id = ?'], - 'data' => [$aArgs['groupId'], $aArgs['serviceId']] - ]); - } - - return true; - } - - public static function reassignUsers(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'newGroupId']); - ValidatorModel::stringType($aArgs, ['groupId', 'newGroupId']); - ValidatorModel::arrayType($aArgs, ['ignoredUsers']); - - $where = ['group_id = ?']; - $data = [$aArgs['groupId']]; - if (!empty($aArgs['ignoredUsers'])) { - $where[] = 'user_id NOT IN (?)'; - $data[] = $aArgs['ignoredUsers']; - } - - DatabaseModel::update([ - 'table' => 'usergroup_content', - 'set' => [ - 'group_id' => $aArgs['newGroupId'] - ], - 'where' => $where, - 'data' => $data - ]); - - return true; - } -} diff --git a/src/app/group/models/ServiceModel.php b/src/app/group/models/ServiceModel.php deleted file mode 100644 index fcb29eb9d7..0000000000 --- a/src/app/group/models/ServiceModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Service Model -* @author dev@maarch.org -*/ - -namespace Group\models; - -class ServiceModel extends ServiceModelAbstract -{ -} diff --git a/src/app/group/models/ServiceModelAbstract.php b/src/app/group/models/ServiceModelAbstract.php deleted file mode 100755 index a47ade4924..0000000000 --- a/src/app/group/models/ServiceModelAbstract.php +++ /dev/null @@ -1,353 +0,0 @@ -<?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 Service Model Abstract - * @author dev@maarch.org - */ - -namespace Group\models; - -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class ServiceModelAbstract -{ - public static function getServicesByXML() - { - $xmlfile = ServiceModel::getLoadedXml(['location' => 'apps']); - $services = []; - - if ($xmlfile) { - foreach ($xmlfile->SERVICE as $value) { - if ((string) $value->enabled === 'true') { - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - $services['application'][] = [ - 'id' => (string) $value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'style' => (string) $value->style, - 'system_service' => (string) $value->system_service == 'true' ? true : false, - 'servicetype' => (string) $value->servicetype, - ]; - } - } - } - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - - foreach ($loadedXml->MODULES as $mod) { - $module = (string) $mod->moduleid; - $xmlModuleFile = ServiceModel::getLoadedXml(['location' => $module]); - - if ($xmlModuleFile) { - foreach ($xmlModuleFile->SERVICE as $value) { - if ((string) $value->enabled === 'true') { - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - $services[$module][] = [ - 'id' => (string) $value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'style' => (string) $value->style, - 'system_service' => (string) $value->system_service == 'true' ? true : false, - 'servicetype' => (string) $value->servicetype, - ]; - } - } - } - } - - return $services; - } - - public static function getApplicationServicesByXML(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type']); - - $xmlfile = ServiceModel::getLoadedXml(['location' => 'apps']); - $applicationServices = []; - - if ($xmlfile) { - foreach ($xmlfile->SERVICE as $value) { - if ((string)$value->servicetype == $aArgs['type'] && (string)$value->enabled === 'true' && (string)$value->id != 'view_history_batch') { - $category = (string) $value->category; - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - if (empty($category)) { - $applicationServices[] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } else { - $applicationServices[$category][] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } - } - } - } - - return $applicationServices; - } - - public static function getApplicationServicesByUserServices(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userServices', 'type']); - ValidatorModel::arrayType($aArgs, ['userServices']); - ValidatorModel::stringType($aArgs, ['type']); - - $xmlfile = ServiceModel::getLoadedXml(['location' => 'apps']); - $applicationServices = []; - - if ($xmlfile) { - $hasHistory = false; - foreach ($xmlfile->SERVICE as $value) { - if ((string) $value->servicetype == $aArgs['type'] && (string) $value->enabled === 'true' && ((string) $value->system_service == 'true' || in_array((string) $value->id, $aArgs['userServices']))) { - if ((string)$value->id == 'view_history' || (string)$value->id == 'view_history_batch') { - $hasHistory = true; - } - } - } - foreach ($xmlfile->SERVICE as $value) { - $historyByPass = (string)$value->id == 'view_history' && $hasHistory; - if ($historyByPass || ((string) $value->servicetype == $aArgs['type'] && (string) $value->enabled === 'true' && ((string) $value->system_service == 'true' || in_array((string) $value->id, $aArgs['userServices'])))) { - if ((string)$value->id != 'view_history_batch') { - $category = (string)$value->category; - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - if (empty($category)) { - $applicationServices[] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string)$value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string)$value->style, - 'angular' => empty((string)$value->angular) ? 'false' : (string)$value->angular, - ]; - } else { - $applicationServices[$category][] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string)$value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string)$value->style, - 'angular' => empty((string)$value->angular) ? 'false' : (string)$value->angular, - ]; - } - } - } - } - } - - return $applicationServices; - } - - public static function getModulesServicesByXML(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['type']); - - $modulesServices = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - foreach ($loadedXml->MODULES as $mod) { - $module = (string) $mod->moduleid; - $xmlModuleFile = ServiceModel::getLoadedXml(['location' => $module]); - - if ($xmlModuleFile) { - foreach ($xmlModuleFile->SERVICE as $value) { - if ((string) $value->servicetype == $aArgs['type'] && (string) $value->enabled === 'true') { - $category = (string) $value->category; - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - if (empty($category)) { - $modulesServices[] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } else { - $modulesServices[$category][] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } - } - } - } - } - - return $modulesServices; - } - - public static function getModulesServicesByUserServices(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userServices', 'type']); - ValidatorModel::arrayType($aArgs, ['userServices']); - ValidatorModel::stringType($aArgs, ['type']); - - $modulesServices = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - foreach ($loadedXml->MODULES as $mod) { - $module = (string) $mod->moduleid; - $xmlModuleFile = ServiceModel::getLoadedXml(['location' => $module]); - - if ($xmlModuleFile) { - foreach ($xmlModuleFile->SERVICE as $value) { - if ((string) $value->servicetype == $aArgs['type'] && (string) $value->enabled === 'true' && ((string) $value->system_service == 'true' || in_array((string) $value->id, $aArgs['userServices']))) { - $category = (string) $value->category; - $name = defined((string) $value->name) ? constant((string) $value->name) : (string) $value->name; - $comment = defined((string) $value->comment) ? constant((string) $value->comment) : (string) $value->comment; - if (empty($category)) { - $modulesServices[] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } else { - $modulesServices[$category][] = [ - 'id' => (string)$value->id, - 'name' => $name, - 'comment' => $comment, - 'servicepage' => (string) $value->servicepage, - 'shortcut' => empty((string)$value->shortcut) ? 'false' : (string)$value->shortcut, - 'style' => (string) $value->style, - 'angular' => empty((string) $value->angular) ? 'false' : (string) $value->angular, - ]; - } - } - } - } - } - - return $modulesServices; - } - - public static function getAdministrationServicesByUserId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $rawServicesStoredInDB = ServiceModel::getByUserId(['userId' => $aArgs['userId']]); - $servicesStoredInDB = []; - foreach ($rawServicesStoredInDB as $value) { - $servicesStoredInDB[] = $value['service_id']; - } - - $administration = []; - $administrationApplication = ServiceModel::getApplicationServicesByUserServices(['userServices' => $servicesStoredInDB, 'type' => 'admin']); - $administrationModule = ServiceModel::getModulesServicesByUserServices(['userServices' => $servicesStoredInDB, 'type' => 'admin']); - $administration['administrations'] = array_merge_recursive($administrationApplication, $administrationModule); - - return $administration; - } - - public static function getByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aServices = DatabaseModel::select([ - 'select' => ['usergroups_services.service_id'], - 'table' => ['usergroup_content, usergroups_services'], - 'where' => ['usergroup_content.group_id = usergroups_services.group_id', 'usergroup_content.user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - return $aServices; - } - - public static function hasService(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'userId', 'location', 'type']); - ValidatorModel::stringType($aArgs, ['id', 'userId', 'location', 'type']); - - if ($aArgs['userId'] == 'superadmin') { - return true; - } - $rawServicesStoredInDB = ServiceModel::getByUserId(['userId' => $aArgs['userId']]); - $servicesStoredInDB = []; - foreach ($rawServicesStoredInDB as $value) { - $servicesStoredInDB[] = $value['service_id']; - } - - $xmlfile = ServiceModel::getLoadedXml(['location' => $aArgs['location']]); - - if ($xmlfile) { - foreach ($xmlfile->SERVICE as $value) { - if ((string) $value->servicetype == $aArgs['type'] && (string) $value->id == $aArgs['id'] && (string) $value->enabled === 'true' - && ((string) $value->system_service == 'true' || in_array((string) $value->id, $servicesStoredInDB))) { - return true; - } - } - } - - return false; - } - - protected static function getLoadedXml(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['location']); - ValidatorModel::stringType($aArgs, ['location']); - - $customId = CoreConfigModel::getCustomId(); - - if ($aArgs['location'] == 'apps') { - if (file_exists("custom/{$customId}/apps/maarch_entreprise/xml/services.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/services.xml"; - } else { - $path = 'apps/maarch_entreprise/xml/services.xml'; - } - } else { - if (file_exists("custom/{$customId}/modules/{$aArgs['location']}/xml/services.xml")) { - $path = "custom/{$customId}/modules/{$aArgs['location']}/xml/services.xml"; - } else { - $path = "modules/{$aArgs['location']}/xml/services.xml"; - } - } - - if (!file_exists($path)) { - return false; - } - - $loadedXml = simplexml_load_file($path); - - return $loadedXml; - } -} diff --git a/src/app/history/controllers/BatchHistoryController.php b/src/app/history/controllers/BatchHistoryController.php deleted file mode 100644 index e875fa8faa..0000000000 --- a/src/app/history/controllers/BatchHistoryController.php +++ /dev/null @@ -1,53 +0,0 @@ -<?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 Batch History Controller -* @author dev@maarch.org -*/ - -namespace History\controllers; - -use Group\models\ServiceModel; -use History\models\BatchHistoryModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class BatchHistoryController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'view_history_batch', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getQueryParams(); - - $check = Validator::floatVal()->notEmpty()->validate($data['startDate']); - $check = $check && Validator::floatVal()->notEmpty()->validate($data['endDate']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $maxRequestSize = 25000; - - $batchHistories = BatchHistoryModel::get([ - 'select' => ['event_date', 'module_name', 'total_processed', 'total_errors', 'info'], - 'where' => ['event_date > ?', 'event_date < ?'], - 'data' => [date('Y-m-d H:i:s', $data['startDate']), date('Y-m-d H:i:s', $data['endDate'])], - 'orderBy' => ['event_date DESC'], - 'limit' => $maxRequestSize - ]); - - $limitExceeded = (count($batchHistories) == $maxRequestSize); - - return $response->withJson(['batchHistories' => $batchHistories, 'limitExceeded' => $limitExceeded]); - } -} diff --git a/src/app/history/models/BatchHistoryModel.php b/src/app/history/models/BatchHistoryModel.php deleted file mode 100644 index 1161d3c64b..0000000000 --- a/src/app/history/models/BatchHistoryModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Batch History Model -* @author dev@maarch.org -*/ - -namespace History\models; - -class BatchHistoryModel extends BatchHistoryModelAbstract -{ -} diff --git a/src/app/history/models/BatchHistoryModelAbstract.php b/src/app/history/models/BatchHistoryModelAbstract.php deleted file mode 100644 index 2d665a34c5..0000000000 --- a/src/app/history/models/BatchHistoryModelAbstract.php +++ /dev/null @@ -1,39 +0,0 @@ -<?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 Batch History Model Abstract -* @author dev@maarch.org -*/ - -namespace History\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class BatchHistoryModelAbstract -{ - public static function get(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intVal($aArgs, ['limit']); - - $aHistories = DatabaseModel::select([ - 'select' => $aArgs['select'], - 'table' => ['history_batch'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'], - 'limit' => $aArgs['limit'] - ]); - - return $aHistories; - } -} diff --git a/src/app/home/controllers/HomeController.php b/src/app/home/controllers/HomeController.php deleted file mode 100644 index d7f69a9b6e..0000000000 --- a/src/app/home/controllers/HomeController.php +++ /dev/null @@ -1,111 +0,0 @@ -<?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 Home Controller - * @author dev@maarch.org - */ - -namespace Home\controllers; - -use Basket\models\BasketModel; -use Resource\models\ResModel; -use Slim\Http\Request; -use Slim\Http\Response; -use User\models\UserModel; -use Parameter\models\ParameterModel; - -class HomeController -{ - public function get(Request $request, Response $response) - { - $regroupedBaskets = []; - - $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - $homeMessage = ParameterModel::getById(['select' => ['param_value_string'], 'id'=> 'homepage_message']); - $homeMessage = trim($homeMessage['param_value_string']); - - $redirectedBaskets = BasketModel::getRedirectedBasketsByUserId(['userId' => $GLOBALS['userId']]); - $groups = UserModel::getGroupsByUserId(['userId' => $GLOBALS['userId']]); - foreach ($groups as $group) { - $baskets = BasketModel::getAvailableBasketsByGroupUser([ - 'select' => ['baskets.basket_id', 'baskets.basket_name', 'baskets.basket_desc', 'baskets.basket_clause', 'baskets.color', 'users_baskets_preferences.color as pcolor'], - 'userSerialId' => $user['id'], - 'groupId' => $group['group_id'], - 'groupSerialId' => $group['id'] - ]); - - foreach ($baskets as $kBasket => $basket) { - if (!empty($basket['pcolor'])) { - $baskets[$kBasket]['color'] = $basket['pcolor']; - } - if (empty($baskets[$kBasket]['color'])) { - $baskets[$kBasket]['color'] = '#666666'; - } - - $baskets[$kBasket]['redirected'] = false; - foreach ($redirectedBaskets as $redirectedBasket) { - if ($redirectedBasket['basket_id'] == $basket['basket_id']) { - $baskets[$kBasket]['redirected'] = true; - $baskets[$kBasket]['redirectedUser'] = $redirectedBasket['userToDisplay']; - } - } - - $baskets[$kBasket]['resourceNumber'] = BasketModel::getResourceNumberByClause(['userId' => $GLOBALS['userId'], 'clause' => $basket['basket_clause']]); - - unset($baskets[$kBasket]['pcolor'], $baskets[$kBasket]['basket_clause']); - } - - if (!empty($baskets)) { - $regroupedBaskets[] = [ - 'groupSerialId' => $group['id'], - 'groupId' => $group['group_id'], - 'groupDesc' => $group['group_desc'], - 'baskets' => $baskets - ]; - } - } - - $assignedBaskets = BasketModel::getAbsBasketsByUserId(['userId' => $GLOBALS['userId']]); - foreach ($assignedBaskets as $key => $assignedBasket) { - $basket = BasketModel::getById(['select' => ['basket_clause'], 'id' => $assignedBasket['basket_id']]); - $assignedBaskets[$key]['resourceNumber'] = BasketModel::getResourceNumberByClause(['userId' => $assignedBasket['user_abs'], 'clause' => $basket['basket_clause']]); - } - - return $response->withJson([ - 'regroupedBaskets' => $regroupedBaskets, - 'assignedBaskets' => $assignedBaskets, - 'homeMessage' => $homeMessage, - ]); - } - - public function getLastRessources(Request $request, Response $response) - { - $lastResources = ResModel::getLastResources([ - 'select' => [ - 'mlb.alt_identifier', - 'mlb.closing_date', - 'r.creation_date', - 'priorities.color as priority_color', - 'mlb.process_limit_date', - 'r.res_id', - 'status.img_filename as status_icon', - 'status.label_status as status_label', - 'status.id as status_id', - 'r.subject', - ], - 'limit' => 5, - 'userId' => $GLOBALS['userId'] - ]); - - return $response->withJson([ - 'lastResources' => $lastResources, - ]); - } -} diff --git a/src/app/link/controllers/LinkController.php b/src/app/link/controllers/LinkController.php deleted file mode 100644 index 84951b64b0..0000000000 --- a/src/app/link/controllers/LinkController.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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 Link Controller - * @author dev@maarch.org - * @ingroup core - */ - -namespace Link\controllers; - -use Link\models\LinkModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class LinkController -{ - public function getByResId(Request $request, Response $response, $aArgs) - { - $check = Validator::intVal()->validate($aArgs['resId']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $aLinks = LinkModel::getByResId(['resId' => $aArgs['resId']]); - - return $response->withJson($aLinks); - } -} diff --git a/src/app/link/models/LinkModel.php b/src/app/link/models/LinkModel.php deleted file mode 100644 index f161bb97a1..0000000000 --- a/src/app/link/models/LinkModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Link Model - * @author dev@maarch.org - * @ingroup link - */ - -namespace Link\models; - -class LinkModel extends LinkModelAbstract -{ - -} diff --git a/src/app/link/models/LinkModelAbstract.php b/src/app/link/models/LinkModelAbstract.php deleted file mode 100644 index 51c5773843..0000000000 --- a/src/app/link/models/LinkModelAbstract.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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 Link Model - * @author dev@maarch.org - */ - -namespace Link\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class LinkModelAbstract -{ - public static function getByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId']); - ValidatorModel::intVal($aArgs, ['resId']); - - $aLinks = DatabaseModel::select([ - 'select' => ['*'], - 'table' => ['res_linked'], - 'where' => ['res_parent = ? OR res_child = ?'], - 'data' => [$aArgs['resId'], $aArgs['resId']] - ]); - - return $aLinks; - } -} diff --git a/src/app/note/controllers/NoteController.php b/src/app/note/controllers/NoteController.php deleted file mode 100644 index a911257c49..0000000000 --- a/src/app/note/controllers/NoteController.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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 Note Controller - * @author dev@maarch.org - * @ingroup core - */ - -namespace Note\controllers; - -use Note\models\NoteModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class NoteController -{ - public function getByResId(Request $request, Response $response, $aArgs) - { - $check = Validator::intVal()->validate($aArgs['resId']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $aNotes = NoteModel::getByResId(['select' => ['notes.id', 'firstname', 'lastname', 'entity_label', 'note_text', 'date_note'], 'resId' => $aArgs['resId'], 'orderBy' => ['date_note DESC']]); - - return $response->withJson($aNotes); - } -} diff --git a/src/app/note/models/NoteModel.php b/src/app/note/models/NoteModel.php deleted file mode 100644 index 4a1a882160..0000000000 --- a/src/app/note/models/NoteModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Note Model - * @author dev@maarch.org - */ - -namespace Note\models; - -class NoteModel extends NoteModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/note/models/NoteModelAbstract.php b/src/app/note/models/NoteModelAbstract.php deleted file mode 100644 index ebb726630e..0000000000 --- a/src/app/note/models/NoteModelAbstract.php +++ /dev/null @@ -1,133 +0,0 @@ -<?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 Note Model - * @author dev@maarch.org - */ - -namespace Note\models; - -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class NoteModelAbstract -{ - public static function countByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId', 'userId']); - ValidatorModel::intVal($aArgs, ['resId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $nb = 0; - $countedNotes = []; - $entities = []; - - $aEntities = DatabaseModel::select([ - 'select' => ['entity_id'], - 'table' => ['users_entities'], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - foreach ($aEntities as $value) { - $entities[] = $value['entity_id']; - } - - $aNotes = DatabaseModel::select([ - 'select' => ['notes.id', 'user_id', 'item_id'], - 'table' => ['notes', 'note_entities'], - 'left_join' => ['notes.id = note_entities.note_id'], - 'where' => ['identifier = ?'], - 'data' => [$aArgs['resId']] - ]); - - foreach ($aNotes as $value) { - if (empty($value['item_id']) && !in_array($value['id'], $countedNotes)) { - ++$nb; - $countedNotes[] = $value['id']; - } elseif (!empty($value['item_id'])) { - if ($value['user_id'] == $aArgs['userId'] && !in_array($value['id'], $countedNotes)) { - ++$nb; - $countedNotes[] = $value['id']; - } elseif (in_array($value['item_id'], $entities) && !in_array($value['id'], $countedNotes)) { - ++$nb; - $countedNotes[] = $value['id']; - } - } - } - - return $nb; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['identifier', 'tablename', 'user_id', 'coll_id', 'note_text']); - ValidatorModel::intVal($aArgs, ['identifier']); - - DatabaseModel::insert([ - 'table' => 'notes', - 'columnsValues' => [ - 'identifier' => $aArgs['identifier'], - 'tablename' => $aArgs['tablename'], - 'user_id' => $aArgs['user_id'], - 'date_note' => 'CURRENT_TIMESTAMP', - 'note_text' => $aArgs['note_text'], - 'coll_id' => $aArgs['coll_id'], - ] - ]); - - return true; - } - - public static function getByResId(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['resId']); - ValidatorModel::intVal($aArgs, ['resId']); - - //get notes - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notes', 'users', 'users_entities', 'entities'], - 'left_join' => ['notes.user_id = users.user_id', 'users.user_id = users_entities.user_id', 'users_entities.entity_id = entities.entity_id'], - 'where' => ['notes.identifier = ?', 'users_entities.primary_entity=\'Y\''], - 'data' => [$aArgs['resId']], - 'order_by' => empty($aArgs['orderBy']) ? ['date_note'] : $aArgs['orderBy'] - ]); - $tmpNoteId = []; - foreach ($aReturn as $value) { - $tmpNoteId[] = $value['id']; - } - //get entities - - if (!empty($tmpNoteId)) { - $tmpEntitiesRestriction = []; - $entities = DatabaseModel::select([ - 'select' => ['note_id', 'item_id', 'short_label'], - 'table' => ['note_entities', 'entities'], - 'left_join' => ['note_entities.item_id = entities.entity_id'], - 'where' => ['note_id in (?)'], - 'data' => [$tmpNoteId], - 'order_by' => ['short_label'] - ]); - - foreach ($entities as $key => $value) { - $tmpEntitiesRestriction[$value['note_id']][] = $value['short_label']; - } - } - - foreach ($aReturn as $key => $value) { - if (!empty($tmpEntitiesRestriction[$value['id']])) { - $aReturn[$key]['entities_restriction'] = $tmpEntitiesRestriction[$value['id']]; - } - } - - return $aReturn; - } -} diff --git a/src/app/notification/controllers/NotificationController.php b/src/app/notification/controllers/NotificationController.php deleted file mode 100644 index ab21cc1566..0000000000 --- a/src/app/notification/controllers/NotificationController.php +++ /dev/null @@ -1,319 +0,0 @@ -<?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 Notifications Controller - * - * @author dev@maarch.org - * @ingroup notifications - */ - -namespace Notification\controllers; - -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Notification\models\NotificationModel; -use Notification\models\NotificationScheduleModel; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\CoreConfigModel; - -class NotificationController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['notifications' => NotificationModel::get()]); - } - - public function getBySid(Request $request, Response $response, $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response - ->withStatus(500) - ->withJson(['errors' => 'Id is not a numeric']); - } - - $notification = NotificationModel::getById(['notification_sid' => $aArgs['id']]); - if (empty($notification)) { - return $response->withStatus(400)->withJson(['errors' => 'Notification not found']); - } - - $notification['diffusion_properties'] = explode(',', $notification['diffusion_properties']); - - $notification['attachfor_properties'] = explode(',', $notification['attachfor_properties']); - - foreach ($notification['attachfor_properties'] as $key => $value) { - $notification['attachfor_properties'][$value] = $value; - unset($notification['attachfor_properties'][$key]); - } - - $data = []; - - $data['event'] = NotificationModel::getEvent(); - $data['template'] = NotificationModel::getTemplate(); - $data['diffusionType'] = NotificationModel::getDiffusionType(); - $data['groups'] = NotificationModel::getDiffusionTypeGroups(); - $data['users'] = NotificationModel::getDiffusionTypesUsers(); - $data['entities'] = NotificationModel::getDiffusionTypeEntities(); - $data['status'] = NotificationModel::getDiffusionTypeStatus(); - - $notification['data'] = $data; - - $filename = 'notification'; - $customId = CoreConfigModel::getCustomId(); - if ($customId != '') { - $filename .= '_'.str_replace(' ', '', $customId); - } - $filename .= '_'.$notification['notification_id'].'.sh'; - - $corePath = str_replace('custom/'.$customId.'/src/app/notification/controllers', '', __DIR__); - $corePath = str_replace('src/app/notification/controllers', '', $corePath); - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - } else { - $pathToFolow = $corePath; - } - - $notification['scriptcreated'] = false; - - if (file_exists($pathToFolow.'modules/notifications/batch/scripts/'.$filename)) { - $notification['scriptcreated'] = true; - } - - return $response->withJson(['notification' => $notification]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $errors = $this->control($data, 'create'); - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $notificationInDb = NotificationModel::getByNotificationId(['notificationId' => $data['notification_id'], 'select' => ['notification_sid']]); - - if (Validator::notEmpty()->validate($notificationInDb)) { - return $response->withStatus(400)->withJson(['errors' => _NOTIFICATION_ALREADY_EXIST]); - } - - $data['notification_mode'] = 'EMAIL'; - - if ($data['diffusion_properties']) { - $data['diffusion_properties'] = implode(',', $data['diffusion_properties']); - } else { - $data['diffusion_properties'] = ''; - } - - if ($data['attachfor_properties']) { - $data['attachfor_properties'] = implode(',', $data['attachfor_properties']); - } else { - $data['attachfor_properties'] = ''; - } - - if (NotificationModel::create($data)) { - if (PHP_OS == 'Linux') { - $notificationAdded = NotificationModel::getByNotificationId(['notificationId' => $data['notification_id'], 'select' => ['notification_sid']]); - NotificationScheduleModel::createScriptNotification(['notification_sid' => $notificationAdded['notification_sid'], 'notification_id' => $data['notification_id']]); - } - - HistoryController::add([ - 'tableName' => 'notifications', - 'recordId' => $data['notification_id'], - 'eventType' => 'ADD', - 'eventId' => 'notificationsadd', - 'info' => _ADD_NOTIFICATIONS.' : '.$data['notification_id'], - ]); - - return $response->withJson(NotificationModel::getByNotificationId(['notificationId' => $data['notification_id']])); - } else { - return $response->withStatus(400)->withJson(['errors' => 'Notification Create Error']); - } - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $data['notification_sid'] = $aArgs['id']; - unset($data['scriptcreated']); - - $errors = $this->control($data, 'update'); - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $data['diffusion_properties'] = implode(',', $data['diffusion_properties']); - $data['attachfor_properties'] = implode(',', $data['attachfor_properties']); - - NotificationModel::update($data); - - $notification = NotificationModel::getById(['notification_sid' => $data['notification_sid']]); - - if (PHP_OS == 'Linux') { - NotificationScheduleModel::createScriptNotification(['notification_sid' => $data['notification_sid'], 'notification_id' => $notification['notification_id']]); - } - - HistoryController::add([ - 'tableName' => 'notifications', - 'recordId' => $data['notification_sid'], - 'eventType' => 'UP', - 'eventId' => 'notificationsup', - 'info' => _MODIFY_NOTIFICATIONS.' : '.$data['notification_sid'], - ]); - - return $response->withJson(['notification' => $notification]); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if (!Validator::intVal()->validate($aArgs['id'])) { - return $response->withStatus(500)->withJson(['errors' => 'Id is not a numeric']); - } - - $notification = NotificationModel::getById(['notification_sid' => $aArgs['id']]); - - NotificationModel::delete(['notification_sid' => $aArgs['id']]); - - HistoryController::add([ - 'tableName' => 'notifications', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'eventId' => 'notificationsdel', - 'info' => _DELETE_NOTIFICATIONS.' : '.$aArgs['id'], - ]); - - if (PHP_OS == 'Linux') { - // delete scheduled notification - $filename = 'notification'; - - $customId = CoreConfigModel::getCustomId(); - if ($customId != '') { - $filename .= '_'.str_replace(' ', '', $customId); - } - $filename .= '_'.$notification['notification_id'].'.sh'; - - $cronTab = NotificationScheduleModel::getCrontab(); - - $flagCron = false; - - $corePath = str_replace('custom/'.$customId.'/src/app/notification/controllers', '', __DIR__); - $corePath = str_replace('src/app/notification/controllers', '', $corePath); - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - } else { - $pathToFolow = $corePath; - } - - foreach ($cronTab as $key => $value) { - if ($value['cmd'] == $pathToFolow.'modules/notifications/batch/scripts/'.$filename) { - $cronTab[$key]['state'] = 'deleted'; - $flagCron = true; - break; - } - } - - if ($flagCron) { - NotificationScheduleModel::saveCrontab($cronTab); - } - - $filePath = $pathToFolow.'modules/notifications/batch/scripts/'.$filename; - if (file_exists($filePath)) { - unlink($filePath); - } - } - - return $response->withJson([ - 'notifications' => NotificationModel::get(), - ]); - } - - protected function control($aArgs, $mode) - { - $errors = []; - - if ($mode == 'update') { - if (!Validator::intVal()->validate($aArgs['notification_sid'])) { - $errors[] = 'notification_sid is not a numeric'; - } else { - $obj = NotificationModel::getById(['notification_sid' => $aArgs['notification_sid']]); - } - - if (empty($obj)) { - $errors[] = 'notification does not exists'; - } - } - - if (!Validator::notEmpty()->validate($aArgs['notification_id'])) { - $errors[] = 'notification_id is empty'; - } - if (!Validator::length(1, 254)->notEmpty()->validate($aArgs['description'])) { - $errors[] = 'wrong format for description'; - } - if (!Validator::length(0, 254)->validate($aArgs['event_id'])) { - $errors[] = 'event_id is too long'; - } - if (!Validator::length(0, 30)->validate($aArgs['notification_mode'])) { - $errors[] = 'notification_mode is too long'; - } - if (!Validator::intType()->notEmpty()->validate($aArgs['template_id'])) { - $errors[] = 'wrong format for template_id'; - } - if (!Validator::notEmpty()->validate($aArgs['is_enabled']) || ($aArgs['is_enabled'] != 'Y' && $aArgs['is_enabled'] != 'N')) { - $errors[] = 'Invalid is_enabled value'; - } - - return $errors; - } - - public function initNotification(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $notification = []; - $notification['diffusion_properties'] = []; - $notification['attachfor_properties'] = []; - $data = []; - - $data['event'] = NotificationModel::getEvent(); - $data['template'] = NotificationModel::getTemplate(); - $data['diffusionType'] = NotificationModel::getDiffusionType(); - $data['groups'] = NotificationModel::getDiffusionTypeGroups(); - $data['users'] = NotificationModel::getDiffusionTypesUsers(); - $data['entities'] = NotificationModel::getDiffusionTypeEntities(); - $data['status'] = NotificationModel::getDiffusionTypeStatus(); - - $notification['data'] = $data; - - return $response->withJson(['notification' => $notification]); - } -} diff --git a/src/app/notification/controllers/NotificationScheduleController.php b/src/app/notification/controllers/NotificationScheduleController.php deleted file mode 100644 index 69189e0d39..0000000000 --- a/src/app/notification/controllers/NotificationScheduleController.php +++ /dev/null @@ -1,162 +0,0 @@ -<?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 Notifications Schedule Controller - * - * @author dev@maarch.org - */ - -namespace Notification\controllers; - -use Respect\Validation\Validator; -use Notification\models\NotificationModel; -use Notification\models\NotificationScheduleModel; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\CoreConfigModel; - -class NotificationScheduleController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson([ - 'crontab' => NotificationScheduleModel::getCrontab(), - 'authorizedNotification' => NotificationScheduleController::getAuthorizedNotifications(), - ]); - } - - // Save Crontab - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - if (!NotificationScheduleController::checkCrontab($data)) { - return $response->withStatus(500)->withJson(['errors' => 'Problem with crontab']); - } - - foreach ($data as $cronValue) { - foreach ($cronValue as $key => $value) { - if (($key == 'cmd' || $key == 'state') && !Validator::notEmpty()->validate($value)) { - $errors[] = $key.' is empty'; - } - if ($key != 'cmd' && $key != 'state' && $key != 'description' && !Validator::intVal()->validate($value) && $value != '*') { - $errors[] = 'wrong format for '.$key; - } - } - } - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - NotificationScheduleModel::saveCrontab(['crontab' => $data]); - - return $response->withJson(true); - } - - protected static function getAuthorizedNotifications() - { - $aNotification = NotificationModel::getEnableNotifications(['select' => ['notification_id', 'notification_sid', 'description']]); - $notificationsArray = []; - $customId = CoreConfigModel::getCustomId(); - $corePath = str_replace('custom/'.$customId.'/src/app/notification/controllers', '', __DIR__); - $corePath = str_replace('src/app/notification/controllers', '', $corePath); - - foreach ($aNotification as $result) { - $filename = 'notification'; - if (isset($customId) && $customId != '') { - $filename .= '_'.str_replace(' ', '', $customId); - } - $filename .= '_'.$result['notification_id'].'.sh'; - - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - } else { - $pathToFolow = $corePath; - } - - $path = $pathToFolow.'modules/notifications/batch/scripts/'.$filename; - - if (file_exists($path)) { - $notificationsArray[] = ['description' => $result['description'], 'path' => $path]; - } - } - - return $notificationsArray; - } - - protected static function checkCrontab($crontabToSave) - { - $customId = CoreConfigModel::getCustomId(); - $crontabBeforeSave = NotificationScheduleModel::getCrontab(); - $corePath = str_replace('custom/'.$customId.'/src/app/notification/controllers', '', __DIR__); - $corePath = str_replace('src/app/notification/controllers', '', $corePath); - - $returnValue = false; - foreach ($crontabToSave as $id => $cronValue) { - if ($cronValue['state'] != 'hidden' && $crontabBeforeSave[$id]['state'] == 'hidden') { - $returnValue = false; - break; - } elseif ($cronValue['state'] == 'hidden' && $crontabBeforeSave[$id]['state'] != 'hidden') { - $returnValue = false; - break; - } elseif ($cronValue['state'] == 'new' || $cronValue['state'] == 'normal') { - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - } else { - $pathToFolow = $corePath; - } - $returnValue = true; - if (strpos($crontabToSave[$id]['cmd'], $pathToFolow.'modules/notifications/batch/scripts/') !== 0) { - $returnValue = false; - break; - } - } else { - $returnValue = true; - } - } - - return $returnValue; - } - - public function createScriptNotification(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_notif', 'userId' => $GLOBALS['userId'], 'location' => 'notifications', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $errors = []; - $data = $request->getParams(); - if (!Validator::intVal()->validate($data['notification_sid'])) { - $errors[] = 'notification_sid is not a numeric'; - } - if (!Validator::notEmpty()->validate($data['notification_sid']) || - !Validator::notEmpty()->validate($data['notification_id'])) { - $errors[] = 'one of arguments is empty'; - } - - if (!empty($errors)) { - return $response->withStatus(500)->withJson(['errors' => $errors]); - } - - $notification_sid = $data['notification_sid']; - $notification_id = $data['notification_id']; - - NotificationScheduleModel::createScriptNotification(['notification_sid' => $notification_sid, 'notification_id' => $notification_id]); - - return $response->withJson(true); - } -} diff --git a/src/app/notification/controllers/NotificationsEventsController.php b/src/app/notification/controllers/NotificationsEventsController.php deleted file mode 100644 index 7139bbe30f..0000000000 --- a/src/app/notification/controllers/NotificationsEventsController.php +++ /dev/null @@ -1,56 +0,0 @@ -<?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 Notifications Events Controller -* @author dev@maarch.org -*/ - -namespace Notification\controllers; - -use Notification\models\NotificationsEventsModel; -use Notification\models\NotificationModel; - -class NotificationsEventsController -{ - public static function fillEventStack(array $aArgs) - { - if ($aArgs['recordId'] == '') { - return; - } - - $aNotifications = NotificationModel::getEnableNotifications(); - if (empty($aNotifications)) { - return; - } - - foreach ($aNotifications as $notification) { - $event_ids = explode(',', $notification['event_id']); - - if ($aArgs['eventId'] == $notification['event_id'] - || NotificationsEventsController::wildcardMatch(["pattern" => $notification['event_id'], "str" => $aArgs['eventId']]) - || in_array($aArgs['eventId'], $event_ids)) { - NotificationsEventsModel::create([ - 'notification_sid' => $notification['notification_sid'], - 'table_name' => $aArgs['tableName'], - 'record_id' => $aArgs['recordId'], - 'user_id' => $aArgs['userId'], - 'event_info' => $aArgs['info'] - ]); - } - } - } - - public static function wildcardMatch(array $aArgs) - { - $pattern = '/^' . str_replace(array('%', '\*', '\?', '\[', '\]'), array('.*', '.*', '.', '[', ']+'), preg_quote($aArgs['pattern'])) . '$/is'; - $result = preg_match($pattern, $aArgs['str']); - return $result; - } -} diff --git a/src/app/notification/models/NotificationModel.php b/src/app/notification/models/NotificationModel.php deleted file mode 100644 index 6cd12078f3..0000000000 --- a/src/app/notification/models/NotificationModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Notifications Model -* @author dev@maarch.org -* @ingroup Module -*/ - -namespace Notification\models; - -class NotificationModel extends NotificationModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/notification/models/NotificationModelAbstract.php b/src/app/notification/models/NotificationModelAbstract.php deleted file mode 100644 index 3a9e0c8596..0000000000 --- a/src/app/notification/models/NotificationModelAbstract.php +++ /dev/null @@ -1,263 +0,0 @@ -<?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 Notifications Model - * - * @author dev@maarch.org - */ - -namespace Notification\models; - -use SrcCore\models\ValidatorModel; -use Entity\models\EntityModel; -use Group\models\GroupModel; -use SrcCore\models\DatabaseModel; -use Status\models\StatusModel; -use SrcCore\models\CoreConfigModel; - -abstract class NotificationModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $aNotifications = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notifications'], - ]); - - return $aNotifications; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_sid']); - - $aNotification = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notifications'], - 'where' => ['notification_sid = ?'], - 'data' => [$aArgs['notification_sid']], - ]); - - if (empty($aNotification[0])) { - return []; - } - - return $aNotification[0]; - } - - public static function getByNotificationId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notificationId']); - - $aNotification = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notifications'], - 'where' => ['notification_id = ?'], - 'data' => [$aArgs['notificationId']], - ]); - - if (empty($aNotification[0])) { - return []; - } - - return $aNotification[0]; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_sid']); - ValidatorModel::intVal($aArgs, ['notification_sid']); - - DatabaseModel::delete([ - 'table' => 'notifications', - 'where' => ['notification_sid = ?'], - 'data' => [$aArgs['notification_sid']], - ]); - - return true; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_id', 'description', 'is_enabled', 'event_id', 'notification_mode', 'template_id', 'diffusion_type']); - ValidatorModel::intVal($aArgs, ['template_id']); - ValidatorModel::stringType($aArgs, ['notification_id', 'description', 'is_enabled', 'notification_mode']); - - DatabaseModel::insert([ - 'table' => 'notifications', - 'columnsValues' => [ - 'notification_id' => $aArgs['notification_id'], - 'description' => $aArgs['description'], - 'is_enabled' => $aArgs['is_enabled'], - 'event_id' => $aArgs['event_id'], - 'notification_mode' => $aArgs['notification_mode'], - 'template_id' => $aArgs['template_id'], - 'diffusion_type' => $aArgs['diffusion_type'], - 'diffusion_properties' => $aArgs['diffusion_properties'], - 'attachfor_type' => $aArgs['attachfor_type'], - 'attachfor_properties' => $aArgs['attachfor_properties'], - ], - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_sid']); - ValidatorModel::intVal($aArgs, ['notification_sid']); - - $notification_sid = $aArgs['notification_sid']; - unset($aArgs['data']); - unset($aArgs['notification_sid']); - - $aReturn = DatabaseModel::update([ - 'table' => 'notifications', - 'set' => $aArgs, - 'where' => ['notification_sid = ?'], - 'data' => [$notification_sid], - ]); - - return $aReturn; - } - - public static function getEvent() - { - $tabEvent_Type = DatabaseModel::select([ - 'select' => ['id, label_action'], - 'table' => ['actions'], - ]); - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/notifications/xml/event_type.xml']); - if ($loadedXml) { - foreach ($loadedXml->event_type as $eventType) { - $tabEvent_Type[] = [ - 'id' => (string) $eventType->id, - 'label_action' => (string) $eventType->label - ]; - } - } - - return $tabEvent_Type; - } - - public static function getTemplate() - { - $tabTemplate = DatabaseModel::select([ - 'select' => ['template_id, template_label'], - 'table' => ['templates'], - 'where' => ['template_target = ?'], - 'data' => ['notifications'], - ]); - - return $tabTemplate; - } - - public static function getDiffusionType() - { - $diffusionTypes = []; - - $diffusionTypes[] = array( - 'id' => 'group', - 'label' => 'Groupe', - 'add_attachment' => 'true', - ); - $diffusionTypes[] = array( - 'id' => 'entity', - 'label' => 'Entité', - 'add_attachment' => 'true', - ); - $diffusionTypes[] = array( - 'id' => 'dest_entity', - 'label' => 'Service de l\'utilisateur destinataire', - 'add_attachment' => 'false', - ); - $diffusionTypes[] = array( - 'id' => 'dest_user', - 'label' => 'Liste de diffusion du document', - 'add_attachment' => 'false', - ); - $diffusionTypes[] = array( - 'id' => 'dest_user_visa', - 'label' => 'Viseur actuel du document', - 'add_attachment' => 'true', - ); - $diffusionTypes[] = array( - 'id' => 'dest_user_sign', - 'label' => 'Signataire actuel du document', - 'add_attachment' => 'true', - ); - $diffusionTypes[] = array( - 'id' => 'user', - 'label' => 'Utilisateur désigné', - 'add_attachment' => 'true', - ); - - $diffusionTypes[] = array( - 'id' => 'copy_list', - 'label' => 'Liste de diffusion du document', - 'add_attachment' => 'false', - ); - - $diffusionTypes[] = array( - 'id' => 'contact', - 'label' => 'Contact du document', - 'add_attachment' => 'true' - ); - - return $diffusionTypes; - } - - public static function getDiffusionTypeGroups() - { - $groups = GroupModel::get(); - - return $groups; - } - - public static function getDiffusionTypesUsers() - { - $users = DatabaseModel::select([ - 'select' => ["user_id as id, concat(firstname,' ',lastname) as label"], - 'table' => ['users'], - ]); - - return $users; - } - - public static function getDiffusionTypeEntities() - { - $entities = EntityModel::get(); - - return $entities; - } - - public static function getDiffusionTypeStatus() - { - $status = StatusModel::get(); - - return $status; - } - - public static function getEnableNotifications(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notifications'], - 'where' => ['is_enabled = ?'], - 'data' => ['Y'], - ]); - - return $aReturn; - } -} diff --git a/src/app/notification/models/NotificationScheduleModel.php b/src/app/notification/models/NotificationScheduleModel.php deleted file mode 100644 index 6b05d36412..0000000000 --- a/src/app/notification/models/NotificationScheduleModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Notifications Schedule Model -* @author dev@maarch.org -* @ingroup Module -*/ - -namespace Notification\models; - -class NotificationScheduleModel extends NotificationScheduleModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/notification/models/NotificationScheduleModelAbstract.php b/src/app/notification/models/NotificationScheduleModelAbstract.php deleted file mode 100644 index 2f80de27ca..0000000000 --- a/src/app/notification/models/NotificationScheduleModelAbstract.php +++ /dev/null @@ -1,191 +0,0 @@ -<?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 Notifications Model - * - * @author dev@maarch.org - */ - -namespace Notification\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use History\controllers\HistoryController; - -abstract class NotificationScheduleModelAbstract -{ - public static function saveCrontab(array $aArgs = []) - { - $aCrontab = NotificationScheduleModel::getCrontab(['setHiddenValue' => false]); - - $file = []; - foreach ($aArgs['crontab'] as $id => $cronValue) { - if ($cronValue['state'] == 'hidden') { - $file[$id] = "{$aCrontab[$id]['m']}\t{$aCrontab[$id]['h']}\t{$aCrontab[$id]['dom']}\t{$aCrontab[$id]['mon']}\t{$aCrontab[$id]['dow']}\t{$aCrontab[$id]['cmd']}"; - } elseif ($cronValue['state'] != 'deleted') { - $file[$id] = "{$cronValue['m']}\t{$cronValue['h']}\t{$cronValue['dom']}\t{$cronValue['mon']}\t{$cronValue['dow']}\t{$cronValue['cmd']}"; - } - } - - $output = ''; - - if (isset($file)) { - foreach ($file as $l) { - $output .= "$l\n"; - } - } - - $output = preg_replace("!\n+$!", "\n", $output); - file_put_contents('/tmp/crontab.plain', print_r($file, true)); - file_put_contents('/tmp/crontab.txt', $output); - - exec('crontab /tmp/crontab.txt'); - - HistoryController::add([ - 'tableName' => 'notifications', - 'recordId' => $GLOBALS['userId'], - 'eventType' => 'UP', - 'eventId' => 'notificationadd', - 'info' => _NOTIFICATION_SCHEDULE_UPDATED, - ]); - - return true; - } - - public static function getCrontab(array $aArgs = []) - { - if (!isset($aArgs['setHiddenValue'])) { - $aArgs['setHiddenValue'] = true; - } - - $crontab = shell_exec('crontab -l'); - $lines = explode("\n", $crontab); - $data = []; - $customId = CoreConfigModel::getCustomId(); - $corePath = str_replace('custom/'.$customId.'/src/app/notification/models', '', __DIR__); - $corePath = str_replace('src/app/notification/models', '', $corePath); - - foreach ($lines as $cronLine) { - $cronLine = trim($cronLine); - if (strpos($cronLine, '#') !== false) { - $cronLine = substr($cronLine, 0, strpos($cronLine, '#')); - } - if (empty($cronLine)) { - continue; - } - $cronLine = preg_replace('![ \t]+!', ' ', $cronLine); - if ($cronLine[0] == '@') { - $explodeCronLine = explode(' ', $cronLine, 2); - $cmd = $explodeCronLine[1]; - } else { - list($m, $h, $dom, $mon, $dow, $cmd) = explode(' ', $cronLine, 6); - } - - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - } else { - $pathToFolow = $corePath; - } - - $state = 'normal'; - if (strpos($cmd, $pathToFolow.'modules/notifications/batch/scripts/') !== 0 && $aArgs['setHiddenValue']) { - $cmd = 'hidden'; - $state = 'hidden'; - } - - $filename = explode('/', $cmd); - - $data[] = [ - 'm' => $m, - 'h' => $h, - 'dom' => $dom, - 'mon' => $mon, - 'dow' => $dow, - 'cmd' => $cmd, - 'description' => end($filename), - 'state' => $state, - ]; - } - - return $data; - } - - public static function createScriptNotification(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_sid', 'notification_id']); - ValidatorModel::intVal($aArgs, ['notification_sid']); - - $notification_id = $aArgs['notification_id']; - - //Creer le script sh pour les notifications - $filename = 'notification'; - $customId = CoreConfigModel::getCustomId(); - if (isset($customId) && $customId != '') { - $filename .= '_'.str_replace(' ', '', $customId); - } - $filename .= '_'.$notification_id.'.sh'; - - $corePath = str_replace('custom/'.$customId.'/src/app/notification/models', '', __DIR__); - $corePath = str_replace('src/app/notification/models', '', $corePath); - - if (file_exists($corePath.'custom/'.$customId.'/modules/notifications/batch/config/config.xml')) { - $ConfigNotif = $corePath.'custom/'.$customId.'/modules/notifications/batch/config/config.xml'; - } elseif (file_exists($corePath.'custom/'.$customId.'/modules/notifications/batch/config/config_'.$customId.'.xml')) { - $ConfigNotif = $corePath.'custom/'.$customId.'/modules/notifications/batch/config/config_'.$customId.'.xml'; - } elseif (file_exists($corePath.'modules/notifications/batch/config/config_'.$customId.'.xml')) { - $ConfigNotif = $corePath.'modules/notifications/batch/config/config_'.$customId.'.xml'; - } else { - $ConfigNotif = $corePath.'modules/notifications/batch/config/config.xml'; - } - - if ($customId != '') { - $pathToFolow = $corePath.'custom/'.$customId.'/'; - if (!file_exists($pathToFolow.'modules/notifications/batch/scripts/')) { - mkdir($pathToFolow.'modules/notifications/batch/scripts/', 0777, true); - } - $file_open = fopen($pathToFolow.'modules/notifications/batch/scripts/'.$filename, 'w+'); - } else { - $pathToFolow = $corePath; - $file_open = fopen($pathToFolow.'modules/notifications/batch/scripts/'.$filename, 'w+'); - } - - fwrite($file_open, '#!/bin/sh'); - fwrite($file_open, "\n"); - fwrite($file_open, 'path=\''.$corePath.'modules/notifications/batch/\''); - fwrite($file_open, "\n"); - fwrite($file_open, 'cd $path'); - fwrite($file_open, "\n"); - if ($notification_id == 'BASKETS') { - fwrite($file_open, 'php \'basket_event_stack.php\' -c '.$ConfigNotif.' -n '.$notification_id); - } elseif ($notification_id == 'RELANCE1' || $notification_id == 'RELANCE2' || $notification_id == 'RET1' || $notification_id == 'RET2') { - fwrite($file_open, 'php \'stack_letterbox_alerts.php\' -c '.$ConfigNotif); - fwrite($file_open, "\n"); - fwrite($file_open, 'php \'process_event_stack.php\' -c '.$ConfigNotif.' -n '.$notification_id); - } else { - fwrite($file_open, 'php \'process_event_stack.php\' -c '.$ConfigNotif.' -n '.$notification_id); - } - fwrite($file_open, "\n"); - fwrite($file_open, 'cd $path'); - fwrite($file_open, "\n"); - fwrite($file_open, 'php \'process_email_stack.php\' -c '.$ConfigNotif); - fwrite($file_open, "\n"); - fclose($file_open); - shell_exec('chmod +x '.escapeshellarg($pathToFolow.'modules/notifications/batch/scripts/'.$filename)); - - HistoryController::add([ - 'tableName' => 'notifications', - 'recordId' => $notification_id, - 'eventType' => 'ADD', - 'eventId' => 'notificationadd', - 'info' => _NOTIFICATION_SCRIPT_ADDED, - ]); - - return true; - } -} diff --git a/src/app/notification/models/NotificationsEventsModel.php b/src/app/notification/models/NotificationsEventsModel.php deleted file mode 100644 index be53cfb3d7..0000000000 --- a/src/app/notification/models/NotificationsEventsModel.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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 Notifications Events Model -* @author dev@maarch.org -* @ingroup core -*/ - -namespace Notification\models; - -class NotificationsEventsModel extends NotificationsEventsModelAbstract -{ - // Do your stuff in this class -} diff --git a/src/app/notification/models/NotificationsEventsModelAbstract.php b/src/app/notification/models/NotificationsEventsModelAbstract.php deleted file mode 100644 index 8a4e783a36..0000000000 --- a/src/app/notification/models/NotificationsEventsModelAbstract.php +++ /dev/null @@ -1,37 +0,0 @@ -<?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 Notifications Events Model -* @author dev@maarch.org -*/ - -namespace Notification\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class NotificationsEventsModelAbstract -{ - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['notification_sid', 'table_name', 'record_id', 'user_id', 'event_info']); - ValidatorModel::stringType($aArgs, ['table_name', 'user_id', 'event_info']); - ValidatorModel::intval($aArgs, ['notification_sid']); - - $aArgs['event_date'] = 'CURRENT_TIMESTAMP'; - - $aReturn = DatabaseModel::insert([ - 'table' => 'notif_event_stack', - 'columnsValues' => $aArgs - ]); - - return $aReturn; - } -} diff --git a/src/app/parameter/controllers/ParameterController.php b/src/app/parameter/controllers/ParameterController.php deleted file mode 100644 index 343831523d..0000000000 --- a/src/app/parameter/controllers/ParameterController.php +++ /dev/null @@ -1,152 +0,0 @@ -<?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 ParametersController -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -/** - * @brief Parameter Controller - * @author dev@maarch.org - */ - -namespace Parameter\controllers; - -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Parameter\models\ParameterModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class ParameterController -{ - public function get(Request $request, Response $response) - { - $parameters = ParameterModel::get(); - - foreach ($parameters as $key => $parameter) { - if (!empty($parameter['param_value_string'])) { - $parameters[$key]['value'] = $parameter['param_value_string']; - } elseif (is_int($parameter['param_value_int'])) { - $parameters[$key]['value'] = $parameter['param_value_int']; - } elseif (!empty($parameter['param_value_date'])) { - $parameters[$key]['value'] = $parameter['param_value_date']; - } - } - - return $response->withJson(['parameters' => $parameters]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - $parameter = ParameterModel::getById(['id' => $aArgs['id']]); - - if (empty($parameter)) { - return $response->withStatus(400)->withJson(['errors' => 'Parameter not found']); - } - - return $response->withJson(['parameter' => $parameter]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_parameters', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['id']) && preg_match("/^[\w-]*$/", $data['id']); - $check = $check && (empty($data['param_value_int']) || Validator::intVal()->validate($data['param_value_int'])); - $check = $check && (empty($data['param_value_string']) || Validator::stringType()->validate($data['param_value_string'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $parameter = ParameterModel::getById(['id' => $data['id']]); - if (!empty($parameter)) { - return $response->withStatus(400)->withJson(['errors' => _PARAMETER_ID_ALREADY_EXISTS]); - } - - ParameterModel::create($data); - HistoryController::add([ - 'tableName' => 'parameters', - 'recordId' => $data['id'], - 'eventType' => 'ADD', - 'info' => _PARAMETER_CREATION . " : {$data['id']}", - 'moduleId' => 'parameter', - 'eventId' => 'parameterCreation', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_parameters', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $parameter = ParameterModel::getById(['id' => $aArgs['id']]); - if (empty($parameter)) { - return $response->withStatus(400)->withJson(['errors' => 'Parameter not found']); - } - - $data = $request->getParams(); - - $check = (empty($data['param_value_int']) || Validator::intVal()->validate($data['param_value_int'])); - $check = $check && (empty($data['param_value_string']) || Validator::stringType()->validate($data['param_value_string'])); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $data['id'] = $aArgs['id']; - ParameterModel::update($data); - HistoryController::add([ - 'tableName' => 'parameters', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _PARAMETER_MODIFICATION . " : {$aArgs['id']}", - 'moduleId' => 'parameter', - 'eventId' => 'parameterModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_parameters', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - ParameterModel::delete(['id' => $aArgs['id']]); - HistoryController::add([ - 'tableName' => 'parameters', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _PARAMETER_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'parameter', - 'eventId' => 'parameterSuppression', - ]); - - $parameters = ParameterModel::get(); - foreach ($parameters as $key => $parameter) { - if (!empty($parameter['param_value_string'])) { - $parameters[$key]['value'] = $parameter['param_value_string']; - } elseif (!empty($parameter['param_value_int'])) { - $parameters[$key]['value'] = $parameter['param_value_int']; - } elseif (!empty($parameter['param_value_date'])) { - $parameters[$key]['value'] = $parameter['param_value_date']; - } - } - - return $response->withJson(['parameters' => $parameters]); - } -} diff --git a/src/app/parameter/models/ParameterModel.php b/src/app/parameter/models/ParameterModel.php deleted file mode 100644 index e48c2da5e3..0000000000 --- a/src/app/parameter/models/ParameterModel.php +++ /dev/null @@ -1,22 +0,0 @@ -<?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 ParametersModel -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -/** - * @brief Parameter Model - * @author dev@maarch.org - */ - -namespace Parameter\models; - -class ParameterModel extends ParameterModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/parameter/models/ParameterModelAbstract.php b/src/app/parameter/models/ParameterModelAbstract.php deleted file mode 100644 index e33c18e327..0000000000 --- a/src/app/parameter/models/ParameterModelAbstract.php +++ /dev/null @@ -1,112 +0,0 @@ -<?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 ParametersModelAbstract -* @author dev <dev@maarch.org> -* @ingroup core -*/ - -/** - * @brief Parameter Model Abstract - * @author dev@maarch.org - */ - -namespace Parameter\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ParameterModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['parameters'], - ]); - - return $aReturn; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $parameter = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['parameters'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($parameter[0])) { - return []; - } - - return $parameter[0]; - } - - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id', 'description', 'param_value_string']); - ValidatorModel::intVal($aArgs, ['param_value_int']); - - DatabaseModel::insert([ - 'table' => 'parameters', - 'columnsValues' => [ - 'id' => $aArgs['id'], - 'description' => $aArgs['description'], - 'param_value_string' => $aArgs['param_value_string'], - 'param_value_int' => $aArgs['param_value_int'], - 'param_value_date' => $aArgs['param_value_date'] - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id', 'description', 'param_value_string']); - ValidatorModel::intVal($aArgs, ['param_value_int']); - - DatabaseModel::update([ - 'table' => 'parameters', - 'set' => [ - 'description' => $aArgs['description'], - 'param_value_string' => $aArgs['param_value_string'], - 'param_value_int' => $aArgs['param_value_int'], - 'param_value_date' => $aArgs['param_value_date'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'parameters', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } -} diff --git a/src/app/priority/controllers/PriorityController.php b/src/app/priority/controllers/PriorityController.php deleted file mode 100644 index 6aee379ed0..0000000000 --- a/src/app/priority/controllers/PriorityController.php +++ /dev/null @@ -1,176 +0,0 @@ -<?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 Priority Controller - * @author dev@maarch.org - */ - -namespace Priority\controllers; - -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Priority\models\PriorityModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; - -class PriorityController -{ - public function get(Request $request, Response $response) - { - return $response->withJson(['priorities' => PriorityModel::get()]); - } - - public function getById(Request $request, Response $response, array $aArgs) - { - $priotity = PriorityModel::getById(['id' => $aArgs['id']]); - - if (empty($priotity)) { - return $response->withStatus(400)->withJson(['errors' => 'Priority not found']); - } - - return $response->withJson(['priority' => $priotity]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_priorities', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['color']); - $check = $check && (Validator::intVal()->notEmpty()->validate($data['delays']) || $data['delays'] == null || $data['delays'] == 0); - $check = $check && Validator::boolType()->validate($data['working_days']); - $check = $check && Validator::boolType()->validate($data['default_priority']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if ($data['default_priority']) { - PriorityModel::resetDefaultPriority(); - } - $data['working_days'] = $data['working_days'] ? 'true' : 'false'; - $data['default_priority'] = $data['default_priority'] ? 'true' : 'false'; - - $id = PriorityModel::create($data); - HistoryController::add([ - 'tableName' => 'priorities', - 'recordId' => $id, - 'eventType' => 'ADD', - 'info' => _PRIORITY_CREATION . " : {$data['label']}", - 'moduleId' => 'priority', - 'eventId' => 'priorityCreation', - ]); - - return $response->withJson(['priority' => $id]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_priorities', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::stringType()->notEmpty()->validate($data['label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['color']); - $check = $check && (Validator::intVal()->notEmpty()->validate($data['delays']) || $data['delays'] == null); - $check = $check && Validator::boolType()->validate($data['working_days']); - $check = $check && Validator::boolType()->validate($data['default_priority']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if ($data['default_priority']) { - PriorityModel::resetDefaultPriority(); - } - $data['id'] = $aArgs['id']; - $data['working_days'] = empty($data['working_days']) ? 'false' : 'true'; - $data['default_priority'] = empty($data['default_priority']) ? 'false' : 'true'; - - PriorityModel::update($data); - HistoryController::add([ - 'tableName' => 'priorities', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _PRIORITY_MODIFICATION . " : {$data['label']}", - 'moduleId' => 'priority', - 'eventId' => 'priorityModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_priorities', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - PriorityModel::delete(['id' => $aArgs['id']]); - HistoryController::add([ - 'tableName' => 'priorities', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _PRIORITY_SUPPRESSION . " : {$aArgs['id']}", - 'moduleId' => 'priority', - 'eventId' => 'prioritySuppression', - ]); - - return $response->withJson(['priorities' => PriorityModel::get()]); - } - - public function getSorted(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_priorities', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $priorities = PriorityModel::get([ - 'select' => ['id', 'label', '"order"'], - 'orderBy' => ['"order" NULLS LAST'] - ]); - - return $response->withJson(['priotities' => $priorities]); - } - - public function updateSort(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_priorities', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - - foreach ($data as $key => $priorityToUpdate) { - if ($key != $priorityToUpdate['order']) { - PriorityModel::updateOrder(['id' => $priorityToUpdate['id'], 'order' => $key]); - } - } - - HistoryController::add([ - 'tableName' => 'priorities', - 'recordId' => $GLOBALS['userId'], - 'eventType' => 'UP', - 'info' => _PRIORITY_SORT_MODIFICATION, - 'moduleId' => 'priority', - 'eventId' => 'priorityModification', - ]); - - $priorities = PriorityModel::get([ - 'select' => ['id', 'label', '"order"'], - 'orderBy' => ['"order" NULLS LAST'] - ]); - - return $response->withJson(['priorities' => $priorities]); - } -} diff --git a/src/app/priority/models/PriorityModel.php b/src/app/priority/models/PriorityModel.php deleted file mode 100644 index 3ae29faf4e..0000000000 --- a/src/app/priority/models/PriorityModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Priority Model - * @author dev@maarch.org - */ - -namespace Priority\models; - -class PriorityModel extends PriorityModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/priority/models/PriorityModelAbstract.php b/src/app/priority/models/PriorityModelAbstract.php deleted file mode 100644 index 3442bbf451..0000000000 --- a/src/app/priority/models/PriorityModelAbstract.php +++ /dev/null @@ -1,151 +0,0 @@ -<?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 Priority Abstract Model - * @author dev@maarch.org - */ - -namespace Priority\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class PriorityModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit', 'offset']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['priorities'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'offset' => empty($aArgs['offset']) ? 0 : $aArgs['offset'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aReturn; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aPriority = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['priorities'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - if (empty($aPriority[0])) { - return []; - } - - return $aPriority[0]; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['label', 'color', 'working_days', 'default_priority']); - ValidatorModel::stringType($aArgs, ['label', 'color', 'working_days', 'default_priority']); - ValidatorModel::intVal($aArgs, ['delays']); - - //working_days => true (monday to friday) => false (monday to sunday) - $id = DatabaseModel::uniqueId(); - DatabaseModel::insert([ - 'table' => 'priorities', - 'columnsValues' => [ - 'id' => $id, - 'label' => $aArgs['label'], - 'color' => $aArgs['color'], - 'working_days' => $aArgs['working_days'], - 'delays' => $aArgs['delays'], - 'default_priority' => $aArgs['default_priority'], - ] - ]); - - return $id; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'label', 'color', 'working_days', 'default_priority']); - ValidatorModel::stringType($aArgs, ['id', 'label', 'color', 'working_days', 'default_priority']); - ValidatorModel::intVal($aArgs, ['delays']); - - //working_days => true (monday to friday) => false (monday to sunday) - DatabaseModel::update([ - 'table' => 'priorities', - 'set' => [ - 'label' => $aArgs['label'], - 'color' => $aArgs['color'], - 'working_days' => $aArgs['working_days'], - 'delays' => $aArgs['delays'], - 'default_priority' => $aArgs['default_priority'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function updateOrder(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['order']); - - DatabaseModel::update([ - 'table' => 'priorities', - 'set' => [ - '"order"' => $aArgs['order'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function resetDefaultPriority() - { - DatabaseModel::update([ - 'table' => 'priorities', - 'set' => [ - 'default_priority' => 'false' - ], - 'where' => ['default_priority = ?'], - 'data' => ['true'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id']); - - DatabaseModel::delete([ - 'table' => 'priorities', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } -} - diff --git a/src/app/report/controllers/ReportController.php b/src/app/report/controllers/ReportController.php deleted file mode 100644 index 0186a466a6..0000000000 --- a/src/app/report/controllers/ReportController.php +++ /dev/null @@ -1,98 +0,0 @@ -<?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 Report Controller -* @author dev@maarch.org -*/ - -namespace Report\controllers; - -use Group\models\ServiceModel; -use Group\models\GroupModel; -use History\controllers\HistoryController; -use Report\models\ReportModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class ReportController -{ - public function getGroups(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - return $response->withJson(['groups' => GroupModel::get()]); - } - - public function getByGroupId(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getByGroupId(['groupId' => $aArgs['groupId']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - $reports = ReportModel::getByGroupId(['groupId' => $aArgs['groupId']]); - - return $response->withJson(['reports' => $reports]); - } - - public function updateForGroupId(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $group = GroupModel::getByGroupId(['groupId' => $aArgs['groupId']]); - if (empty($group)) { - return $response->withStatus(400)->withJson(['errors' => 'Group not found']); - } - - $data = $request->getParams(); - - $reports = ReportModel::getByGroupId(['groupId' => $aArgs['groupId']]); - - $selectedReports = []; - foreach ($data as $value) { - if (!empty($value['checked'])) { - $selectedReports[] = $value['id']; - } - } - - $reportIdsToDelete = []; - foreach ($reports as $value) { - if (!$value['checked'] && in_array($value['id'], $selectedReports)) { - ReportModel::addForGroupId(['groupId' => $aArgs['groupId'], 'reportId' => $value['id']]); - } elseif ($value['checked'] && !in_array($value['id'], $selectedReports)) { - $reportIdsToDelete[] = $value['id']; - } - } - - if (!empty($reportIdsToDelete)) { - ReportModel::deleteForGroupId(['groupId' => $aArgs['groupId'], 'reportIds' => $reportIdsToDelete]); - } - - HistoryController::add([ - 'tableName' => 'usergroups_reports', - 'recordId' => $aArgs['groupId'], - 'eventType' => 'UP', - 'info' => _REPORT_MODIFICATION, - 'moduleId' => 'report', - 'eventId' => 'reportModification', - ]); - - return $response->withJson(['success' => 'success']); - } -} - diff --git a/src/app/report/models/ReportModel.php b/src/app/report/models/ReportModel.php deleted file mode 100644 index bfb7bed039..0000000000 --- a/src/app/report/models/ReportModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Report Model -* @author dev@maarch.org -*/ - -namespace Report\models; - -class ReportModel extends ReportModelAbstract -{ -} diff --git a/src/app/report/models/ReportModelAbstract.php b/src/app/report/models/ReportModelAbstract.php deleted file mode 100644 index 2dbe49ebdd..0000000000 --- a/src/app/report/models/ReportModelAbstract.php +++ /dev/null @@ -1,98 +0,0 @@ -<?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 Report Model Abstract -* @author dev@maarch.org -*/ - -namespace Report\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; - -abstract class ReportModelAbstract -{ - public static function getByGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $reports = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/reports/xml/reports.xml']); - if ($loadedXml) { - foreach ($loadedXml->REPORT as $value) { - if ((string)$value->ENABLED == "true") { - $reports[] = [ - 'id' => (string)$value->ID, - 'label' => constant((string)$value->LABEL), - 'desc' => constant((string)$value->DESCRIPTION), - 'url' => (string)$value->URL, - 'in_menu_reports' => (string)$value->IN_MENU_REPORTS, - 'origin' => (string)$value->ORIGIN, - 'module' => (string)$value->MODULE, - 'module_label' => (string)$value->MODULE_LABEL, - 'checked' => false - ]; - } - } - - $aReturn = DatabaseModel::select([ - 'select' => ['*'], - 'table' => ['usergroups_reports'], - 'where' => ['group_id = ?'], - 'data' => [$aArgs['groupId']] - ]); - - $selectedReports = []; - foreach ($aReturn as $value) { - $selectedReports[] = $value['report_id']; - } - - foreach ($reports as $key => $value) { - $reports[$key]['checked'] = in_array($value['id'], $selectedReports); - } - } - - return $reports; - } - - public static function addForGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'reportId']); - ValidatorModel::stringType($aArgs, ['groupId', 'reportId']); - - DatabaseModel::insert([ - 'table' => 'usergroups_reports', - 'columnsValues' => [ - 'group_id' => $aArgs['groupId'], - 'report_id' => $aArgs['reportId'] - ] - ]); - - return true; - } - - public static function deleteForGroupId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['groupId', 'reportIds']); - ValidatorModel::stringType($aArgs, ['groupId']); - ValidatorModel::arrayType($aArgs, ['reportIds']); - - DatabaseModel::delete([ - 'table' => 'usergroups_reports', - 'where' => ['group_id = ?', 'report_id in (?)'], - 'data' => [$aArgs['groupId'], $aArgs['reportIds']] - ]); - - return true; - } -} diff --git a/src/app/resource/models/ChronoModel.php b/src/app/resource/models/ChronoModel.php deleted file mode 100644 index bd40a0507b..0000000000 --- a/src/app/resource/models/ChronoModel.php +++ /dev/null @@ -1,168 +0,0 @@ -<?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 Chrono Model - * @author dev@maarch.org - */ - -namespace Resource\models; - -use Parameter\models\ParameterModel; -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; - -class ChronoModel -{ - public static function getChrono(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['id', 'entityId']); - ValidatorModel::intVal($aArgs, ['typeId', 'resId']); - - $elements = []; - $chronoNumber = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/chrono.xml']); - if ($loadedXml) { - foreach ($loadedXml->CHRONO as $chrono) { - if ($chrono->id == $aArgs['id']) { - foreach ($chrono->ELEMENT as $chronoElement) { - $elements[] = [ - 'type' => (string)$chronoElement->type, - 'value' => (string)$chronoElement->value - ]; - } - } - } - } - - foreach ($elements as $value) { - if (!empty($value['type'])) { - if ($value['type'] == 'date') { - if ($value['value'] == 'year') { - $value['value'] = date('Y'); - } elseif ($value['value'] == 'month') { - $value['value'] = date('m'); - } elseif ($value['value'] == 'day') { - $value['value'] = date('d'); - } elseif ($value['value'] == 'full_date') { - $value['value'] = date('dmY'); - } - } elseif ($value['type'] == 'maarch_var') { - if ($value['value'] == "entity_id") { - $value['value'] = $aArgs['entityId']; - } elseif ($value['value'] == 'type_id') { - $value['value'] = $aArgs['typeId']; - } - } elseif ($value['type'] == 'maarch_functions') { - if ($value['value'] == 'chr_global') { - $value['value'] = ChronoModel::getChronoGlobal(); - } elseif ($value['value'] == 'chr_by_entity') { - $value['value'] = ChronoModel::getChronoEntity($aArgs['entityId']); - } elseif ($value['value'] == 'chr_by_category') { - $value['value'] = ChronoModel::getChronoCategory($aArgs['id']); - } elseif ($value['value'] == 'category_char') { - $value['value'] = ChronoModel::getChronoCategoryChar($aArgs['id']); - } elseif ($value['value'] == 'chr_by_folder') { - $value['value'] = ChronoModel::getChronoFolder($aArgs['folderId']); - } elseif ($value['value'] == 'chr_by_res_id') { - $value['value'] = $aArgs['resId']; - } - } - } - $chronoNumber[] = $value['value']; - } - - return implode('', $chronoNumber); - } - - public static function getChronoGlobal() - { - $chronoId = 'chrono_global_' . date('Y'); - - $parameter = ParameterModel::getById(['id' => $chronoId, 'select' => ['param_value_int']]); - - if (empty($parameter)) { - ParameterModel::create(['id' => $chronoId, 'param_value_int' => 1]); - $chrono = 1; - } else { - $chrono = $parameter['param_value_int']; - } - - ParameterModel::update(['id' => $chronoId, 'param_value_int' => $chrono + 1]); - - return $chrono; - } - - public static function getChronoEntity($entityId) - { - $chronoId = "chrono_{$entityId}_" . date('Y'); - - $parameter = ParameterModel::getById(['id' => $chronoId, 'select' => ['param_value_int']]); - - if (empty($parameter)) { - ParameterModel::create(['id' => $chronoId, 'param_value_int' => 1]); - $chrono = 1; - } else { - $chrono = $parameter['param_value_int']; - } - - ParameterModel::update(['id' => $chronoId, 'param_value_int' => $chrono + 1]); - - return $entityId . "/" . $chrono; - } - - public static function getChronoFolder($folderId) - { - $chronoId = "chrono_folder_{$folderId}"; - - $parameter = ParameterModel::getById(['id' => $chronoId, 'select' => ['param_value_int']]); - - if (empty($parameter)) { - ParameterModel::create(['id' => $chronoId, 'param_value_int' => 1]); - $chrono = 1; - } else { - $chrono = $parameter['param_value_int']; - } - - ParameterModel::update(['id' => $chronoId, 'param_value_int' => $chrono + 1]); - - return $chrono; - } - - public static function getChronoCategory($categoryId) - { - $chronoId = "chrono_{$categoryId}_" . date('Y'); - - $parameter = ParameterModel::getById(['id' => $chronoId, 'select' => ['param_value_int']]); - - if (empty($parameter)) { - ParameterModel::create(['id' => $chronoId, 'param_value_int' => 1]); - $chrono = 1; - } else { - $chrono = $parameter['param_value_int']; - } - - ParameterModel::update(['id' => $chronoId, 'param_value_int' => $chrono + 1]); - - return "/" . $chrono; - } - - public static function getChronoCategoryChar($categoryId) - { - if ($categoryId == 'incoming') { - return 'A'; - } elseif ($categoryId == 'outgoing') { - return 'D'; - } else { - return ''; - } - } -} diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php deleted file mode 100644 index 0d0b984bbc..0000000000 --- a/src/app/template/controllers/TemplateController.php +++ /dev/null @@ -1,442 +0,0 @@ -<?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 Template Controller - * @author dev@maarch.org - */ - -namespace Template\controllers; - -use Docserver\controllers\DocserverController; -use Docserver\models\DocserverModel; -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\ValidatorModel; -use Template\models\TemplateAssociationModel; -use Template\models\TemplateModel; -use Attachment\models\AttachmentModel; -use Entity\models\EntityModel; - -class TemplateController -{ - const AUTHORIZED_MIMETYPES = [ - 'application/msword', - 'application/vnd.openxmlformats-officedocument.wordprocessing‌ml.document', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'application/vnd.ms-excel', - 'application/vnd.ms-powerpoint', - 'application/vnd.openxmlformats-officedocument.presentationml‌.slideshow', - 'application/vnd.oasis.opendocument.text', - 'application/vnd.oasis.opendocument.presentation', - 'application/vnd.oasis.opendocument.spreadsheet' - ]; - - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $templates = TemplateModel::get(); - - return $response->withJson(['templates' => $templates]); - } - - public function getDetailledById(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $template = TemplateModel::getById(['id' => $aArgs['id']]); - if (empty($template)) { - return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']); - } - - $rawLinkedEntities = TemplateAssociationModel::get(['select' => ['value_field'], 'where' => ['template_id = ?'], 'data' => [$template['template_id']]]); - $linkedEntities = []; - foreach ($rawLinkedEntities as $rawLinkedEntity) { - $linkedEntities[] = $rawLinkedEntity['value_field']; - } - $entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']); - foreach ($entities as $key => $entity) { - $entities[$key]['state']['selected'] = false; - if (in_array($entity['id'], $linkedEntities)) { - $entities[$key]['state']['selected'] = true; - } - } - - $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); - $attachmentTypes = []; - foreach ($attachmentModelsTmp as $key => $value) { - $attachmentTypes[] = [ - 'label' => $value['label'], - 'id' => $key - ]; - } - - return $response->withJson([ - 'template' => $template, - 'templatesModels' => TemplateModel::getModels(), - 'attachmentTypes' => $attachmentTypes, - 'datasources' => TemplateModel::getDatasources(), - 'entities' => $entities - ]); - } - - public function create(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - if (!TemplateController::checkData(['data' => $data])) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if ($data['template_type'] == 'OFFICE') { - if (empty($data['jnlpUniqueId']) && empty($data['uploadedFile'])) { - return $response->withStatus(400)->withJson(['errors' => 'Template file is missing']); - } - if (!empty($data['jnlpUniqueId'])) { - if (!Validator::stringType()->notEmpty()->validate($data['template_style'])) { - return $response->withStatus(400)->withJson(['errors' => 'Template style is missing']); - } - $explodeStyle = explode(':', $data['template_style']); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[0]); - } else { - if (empty($data['uploadedFile']['base64']) || empty($data['uploadedFile']['name'])) { - return $response->withStatus(400)->withJson(['errors' => 'Uploaded file is missing']); - } - $fileContent = base64_decode($data['uploadedFile']['base64']); - $finfo = new \finfo(FILEINFO_MIME_TYPE); - $mimeType = $finfo->buffer($fileContent); - if (!in_array($mimeType, self::AUTHORIZED_MIMETYPES)) { - return $response->withStatus(400)->withJson(['errors' => _WRONG_FILE_TYPE]); - } - - $fileOnTmp = rand() . $data['uploadedFile']['name']; - $file = fopen(CoreConfigModel::getTmpPath() . $fileOnTmp, 'w'); - fwrite($file, $fileContent); - fclose($file); - } - - $storeResult = DocserverController::storeResourceOnDocServer([ - 'collId' => 'templates', - 'docserverTypeId' => 'TEMPLATES', - 'fileInfos' => [ - 'tmpDir' => CoreConfigModel::getTmpPath(), - 'tmpFileName' => $fileOnTmp, - ] - ]); - if (!empty($storeResult['errors'])) { - return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]); - } - - $data['template_path'] = $storeResult['destination_dir']; - $data['template_file_name'] = $storeResult['file_destination_name']; - } - - $id = TemplateModel::create($data); - if (!empty($data['entities']) && is_array($data['entities'])) { - foreach ($data['entities'] as $entity) { - TemplateAssociationModel::create(['templateId' => $id, 'entityId' => $entity]); - } - } - - HistoryController::add([ - 'tableName' => 'templates', - 'recordId' => $id, - 'eventType' => 'ADD', - 'info' => _TEMPLATE_ADDED . " : {$data['template_label']}", - 'moduleId' => 'template', - 'eventId' => 'templateCreation', - ]); - - return $response->withJson(['template' => $id]); - } - - public function update(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $template = TemplateModel::getById(['select' => ['template_style', 'template_file_name', 'template_type', 'template_target'], 'id' => $aArgs['id']]); - if (empty($template)) { - return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']); - } - - $data = $request->getParams(); - $data['template_type'] = $template['template_type']; - $data['template_target'] = $template['template_target']; - if (!TemplateController::checkData(['data' => $data])) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - if ($data['template_type'] == 'OFFICE' && (!empty($data['jnlpUniqueId']) || !empty($data['uploadedFile']))) { - if (!empty($data['jnlpUniqueId'])) { - if (!empty($template['template_style']) && !Validator::stringType()->notEmpty()->validate($data['template_style'])) { - return $response->withStatus(400)->withJson(['errors' => 'Template style is missing']); - } - $explodeStyle = explode('.', $data['template_file_name']); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[count($explodeStyle) - 1]); - } else { - if (empty($data['uploadedFile']['base64']) || empty($data['uploadedFile']['name'])) { - return $response->withStatus(400)->withJson(['errors' => 'Uploaded file is missing']); - } - $fileContent = base64_decode($data['uploadedFile']['base64']); - $finfo = new \finfo(FILEINFO_MIME_TYPE); - $mimeType = $finfo->buffer($fileContent); - if (!in_array($mimeType, self::AUTHORIZED_MIMETYPES)) { - return $response->withStatus(400)->withJson(['errors' => _WRONG_FILE_TYPE]); - } - - $fileOnTmp = rand() . $data['uploadedFile']['name']; - $file = fopen(CoreConfigModel::getTmpPath() . $fileOnTmp, 'w'); - fwrite($file, $fileContent); - fclose($file); - } - - $storeResult = DocserverController::storeResourceOnDocServer([ - 'collId' => 'templates', - 'docserverTypeId' => 'TEMPLATES', - 'fileInfos' => [ - 'tmpDir' => CoreConfigModel::getTmpPath(), - 'tmpFileName' => $fileOnTmp, - ] - ]); - if (!empty($storeResult['errors'])) { - return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]); - } - - $data['template_path'] = $storeResult['destination_dir']; - $data['template_file_name'] = $storeResult['file_destination_name']; - } - - TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); - if (!empty($data['entities']) && is_array($data['entities'])) { - foreach ($data['entities'] as $entity) { - TemplateAssociationModel::create(['templateId' => $aArgs['id'], 'entityId' => $entity]); - } - } - unset($data['uploadedFile']); - unset($data['jnlpUniqueId']); - unset($data['entities']); - TemplateModel::update(['set' => $data, 'where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); - - HistoryController::add([ - 'tableName' => 'templates', - 'recordId' => $aArgs['id'], - 'eventType' => 'UP', - 'info' => _TEMPLATE_UPDATED . " : {$data['template_label']}", - 'moduleId' => 'template', - 'eventId' => 'templateModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function delete(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $template = TemplateModel::getById(['select' => ['template_label'], 'id' => $aArgs['id']]); - if (empty($template)) { - return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']); - } - - TemplateModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); - TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); - - HistoryController::add([ - 'tableName' => 'templates', - 'recordId' => $aArgs['id'], - 'eventType' => 'DEL', - 'info' => _TEMPLATE_DELETED . " : {$template['template_label']}", - 'moduleId' => 'template', - 'eventId' => 'templateSuppression', - ]); - - return $response->withJson(['success' => 'success']); - } - - public function duplicate(Request $request, Response $response, array $aArgs) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $template = TemplateModel::getById(['id' => $aArgs['id']]); - - if (empty($template)) { - return $response->withStatus(400)->withJson(['errors' => 'Template not found']); - } - - if ($template['template_type'] == 'OFFICE') { - $docserver = DocserverModel::getCurrentDocserver(['typeId' => 'TEMPLATES', 'collId' => 'templates', 'select' => ['path_template']]); - - $pathOnDocserver = DocserverController::createPathOnDocServer(['path' => $docserver['path_template']]); - $docinfo = DocserverController::getNextFileNameInDocServer(['pathOnDocserver' => $pathOnDocserver['pathToDocServer']]); - $docinfo['fileDestinationName'] .= '.' . explode('.', $template['template_file_name'])[1]; - - $pathToDocumentToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name']; - $copyResult = DocserverController::copyOnDocServer([ - 'sourceFilePath' => $pathToDocumentToCopy, - 'destinationDir' => $docinfo['destinationDir'], - 'fileDestinationName' => $docinfo['fileDestinationName'] - ]); - if (!empty($copyResult['errors'])) { - return $response->withStatus(500)->withJson(['errors' => 'Template duplication failed : ' . $copyResult['errors']]); - } - $template['template_path'] = str_replace(str_replace(DIRECTORY_SEPARATOR, '#', $docserver['path_template']), '', $copyResult['copyOnDocserver']['destinationDir']); - $template['template_file_name'] = $copyResult['copyOnDocserver']['fileDestinationName']; - } - - $template['template_label'] = 'Copie de ' . $template['template_label']; - - $templateId = TemplateModel::create($template); - - return $response->withJson(['id' => $templateId]); - } - - public function initTemplates(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_templates', 'userId' => $GLOBALS['userId'], 'location' => 'templates', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); - $attachmentTypes = []; - foreach ($attachmentModelsTmp as $key => $value) { - $attachmentTypes[] = [ - 'label' => $value['label'], - 'id' => $key - ]; - } - - $entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']); - foreach ($entities as $key => $entity) { - $entities[$key]['state']['selected'] = false; - } - - return $response->withJson([ - 'templatesModels' => TemplateModel::getModels(), - 'attachmentTypes' => $attachmentTypes, - 'datasources' => TemplateModel::getDatasources(), - 'entities' => $entities, - ]); - } - - private static function checkData(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['data']); - ValidatorModel::arrayType($aArgs, ['data']); - - $availableTypes = ['HTML', 'TXT', 'OFFICE']; - $data = $aArgs['data']; - - $check = Validator::stringType()->notEmpty()->validate($data['template_label']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['template_comment']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['template_type']) && in_array($data['template_type'], $availableTypes); - - if ($data['template_type'] == 'HTML' || $data['template_type'] == 'TXT') { - $check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']); - } - - 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']]); - - - // 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') { - $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); - } - } - } - - $fileNameOnTmp = 'tmp_file_' . $aArgs['userId'] . '_' . rand() . '.' . $pathToTemplateInfo['extension']; - $tmpPath = CoreConfigModel::getTmpPath(); - $myFile = $tmpPath . $fileNameOnTmp; - - $TBS->Show(OPENTBS_FILE, $myFile); - - 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; - } -} diff --git a/src/app/template/models/TemplateAssociationModel.php b/src/app/template/models/TemplateAssociationModel.php deleted file mode 100644 index 8e965038dc..0000000000 --- a/src/app/template/models/TemplateAssociationModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Template Association Model - * @author dev@maarch.org - */ - -namespace Template\models; - -class TemplateAssociationModel extends TemplateAssociationModelAbstract -{ -} diff --git a/src/app/template/models/TemplateAssociationModelAbstract.php b/src/app/template/models/TemplateAssociationModelAbstract.php deleted file mode 100644 index 402b8c3d72..0000000000 --- a/src/app/template/models/TemplateAssociationModelAbstract.php +++ /dev/null @@ -1,84 +0,0 @@ -<?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 Template Association Model Abstract - * @author dev@maarch.org - */ - -namespace Template\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class TemplateAssociationModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aTemplates = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates_association'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aTemplates; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entityId', 'templateId']); - ValidatorModel::stringType($aArgs, ['entityId']); - ValidatorModel::intVal($aArgs, ['templateId']); - - DatabaseModel::insert([ - 'table' => 'templates_association', - 'columnsValues' => [ - 'template_id' => $aArgs['templateId'], - 'value_field' => $aArgs['entityId'] - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'templates_association', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'templates_association', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } -} diff --git a/src/app/template/models/TemplateModel.php b/src/app/template/models/TemplateModel.php deleted file mode 100644 index 83fd89bec8..0000000000 --- a/src/app/template/models/TemplateModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 Template Model - * @author dev@maarch.org - */ - -namespace Template\models; - -class TemplateModel extends TemplateModelAbstract -{ -} diff --git a/src/app/template/models/TemplateModelAbstract.php b/src/app/template/models/TemplateModelAbstract.php deleted file mode 100644 index d81d92bc55..0000000000 --- a/src/app/template/models/TemplateModelAbstract.php +++ /dev/null @@ -1,215 +0,0 @@ -<?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 Template Model Abstract - * @author dev@maarch.org - */ - -namespace Template\models; - -use SrcCore\models\CoreConfigModel; -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class TemplateModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - ValidatorModel::intType($aArgs, ['limit']); - - $aTemplates = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates'], - 'where' => empty($aArgs['where']) ? [] : $aArgs['where'], - 'data' => empty($aArgs['data']) ? [] : $aArgs['data'], - 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'], - 'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit'] - ]); - - return $aTemplates; - } - - public static function getById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aTemplate = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates'], - 'where' => ['template_id = ?'], - 'data' => [$aArgs['id']], - ]); - - if (empty($aTemplate[0])) { - return []; - } - - return $aTemplate[0]; - } - - public static function getByTarget(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['template_target']); - - $aTemplate = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates'], - 'where' => ['template_target = ?'], - 'data' => [$aArgs['template_target']], - ]); - - return $aTemplate; - } - - public static function getByEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entities']); - ValidatorModel::arrayType($aArgs, ['select', 'entities']); - - $aTemplate = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['templates t, templates_association ta'], - 'where' => ['t.template_id = ta.template_id', 'ta.value_field in (?)'], - 'data' => [$aArgs['entities']], - ]); - - return $aTemplate; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['template_label']); - ValidatorModel::stringType($aArgs, ['template_label']); - - $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'templates_seq']); - - DatabaseModel::insert([ - 'table' => 'templates', - 'columnsValues' => [ - 'template_id' => $nextSequenceId, - 'template_label' => $aArgs['template_label'], - 'template_comment' => $aArgs['template_comment'], - 'template_content' => $aArgs['template_content'], - 'template_type' => $aArgs['template_type'], - 'template_style' => $aArgs['template_style'], - 'template_datasource' => $aArgs['template_datasource'], - 'template_target' => $aArgs['template_target'], - 'template_attachment_type' => $aArgs['template_attachment_type'], - 'template_path' => $aArgs['template_path'], - 'template_file_name' => $aArgs['template_file_name'], - ] - ]); - - return $nextSequenceId; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'templates', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'templates', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getDatasources() - { - $datasources = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/templates/xml/datasources.xml']); - if ($loadedXml) { - foreach ($loadedXml->datasource as $value) { - $value = (array)$value; - $datasources[] = [ - 'id' => (string)$value['id'], - 'label' => (string)$value['label'], - 'script' => (string)$value['script'], - 'target' => (string)$value['target'], - ]; - } - } - - return $datasources; - } - - public static function getDatasourceById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - - $datasources = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/templates/xml/datasources.xml']); - if ($loadedXml) { - foreach ($loadedXml->datasource as $value) { - $value = (array)$value; - if ($value['id'] == $aArgs['id']) { - $datasource = [ - 'id' => (string)$value['id'], - 'label' => (string)$value['label'], - 'script' => (string)$value['script'], - 'target' => (string)$value['target'], - ]; - } - } - } - - return $datasource; - } - - public static function getModels() - { - $customId = CoreConfigModel::getCustomId(); - - if (is_dir("custom/{$customId}/modules/templates/templates/styles/")) { - $path = "custom/{$customId}/modules/templates/templates/styles/"; - } else { - $path = 'modules/templates/templates/styles/'; - } - - $templateModels = scandir($path); - $models = []; - foreach ($templateModels as $value) { - if ($value != '.' && $value != '..') { - $file = implode('.', explode('.', $value, -1)); - $ext = explode('.', $value); - $models[] = [ - 'fileName' => $file, - 'fileExt' => strtoupper($ext[count($ext) - 1]), - 'filePath' => $path . $value, - ]; - } - } - - return $models; - } -} diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 0298ee9f82..88c14050ab 100644 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -246,20 +246,20 @@ class UserController public function getProfile(Request $request, Response $response) { $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id', 'user_id', 'firstname', 'lastname', 'phone', 'mail', 'initials', 'thumbprint']]); - $user['signatures'] = UserSignatureModel::getByUserSerialId(['userSerialid' => $user['id']]); - $user['emailSignatures'] = UserModel::getEmailSignaturesById(['userId' => $user['user_id']]); - $user['groups'] = UserModel::getGroupsByUserId(['userId' => $user['user_id']]); - $user['entities'] = UserModel::getEntitiesById(['userId' => $user['user_id']]); - $user['baskets'] = BasketModel::getBasketsByUserId(['userId' => $user['user_id'], 'unneededBasketId' => ['IndexingBasket']]); - $user['redirectedBaskets'] = BasketModel::getRedirectedBasketsByUserId(['userId' => $user['user_id']]); - $user['regroupedBaskets'] = BasketModel::getRegroupedBasketsByUserId(['userId' => $user['user_id']]); - $user['passwordRules'] = PasswordModel::getEnabledRules(); - $user['canModifyPassword'] = true; - - $loggingMethod = CoreConfigModel::getLoggingMethod(); - if (in_array($loggingMethod['id'], self::ALTERNATIVES_CONNECTIONS_METHODS)) { - $user['canModifyPassword'] = false; - } +// $user['signatures'] = UserSignatureModel::getByUserSerialId(['userSerialid' => $user['id']]); +// $user['emailSignatures'] = UserModel::getEmailSignaturesById(['userId' => $user['user_id']]); +// $user['groups'] = UserModel::getGroupsByUserId(['userId' => $user['user_id']]); +// $user['entities'] = UserModel::getEntitiesById(['userId' => $user['user_id']]); +// $user['baskets'] = BasketModel::getBasketsByUserId(['userId' => $user['user_id'], 'unneededBasketId' => ['IndexingBasket']]); +// $user['redirectedBaskets'] = BasketModel::getRedirectedBasketsByUserId(['userId' => $user['user_id']]); +// $user['regroupedBaskets'] = BasketModel::getRegroupedBasketsByUserId(['userId' => $user['user_id']]); +// $user['passwordRules'] = PasswordModel::getEnabledRules(); +// $user['canModifyPassword'] = true; +// +// $loggingMethod = CoreConfigModel::getLoggingMethod(); +// if (in_array($loggingMethod['id'], self::ALTERNATIVES_CONNECTIONS_METHODS)) { +// $user['canModifyPassword'] = false; +// } return $response->withJson($user); } diff --git a/src/app/user/models/UserBasketPreferenceModel.php b/src/app/user/models/UserBasketPreferenceModel.php deleted file mode 100644 index 232c186ebc..0000000000 --- a/src/app/user/models/UserBasketPreferenceModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 User Basket Preference Model - * @author dev@maarch.org - */ - -namespace User\models; - -class UserBasketPreferenceModel extends UserBasketPreferenceModelAbstract -{ -} diff --git a/src/app/user/models/UserBasketPreferenceModelAbstract.php b/src/app/user/models/UserBasketPreferenceModelAbstract.php deleted file mode 100644 index 41bdf4d469..0000000000 --- a/src/app/user/models/UserBasketPreferenceModelAbstract.php +++ /dev/null @@ -1,85 +0,0 @@ -<?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 User Basket Preference Model Abstract - * @author dev@maarch.org - */ - -namespace User\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class UserBasketPreferenceModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $aBasketPreferences = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_baskets_preferences'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $aBasketPreferences; - } - - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userSerialId', 'groupSerialId', 'basketId', 'display']); - ValidatorModel::stringType($aArgs, ['basketId', 'display', 'color']); - ValidatorModel::intVal($aArgs, ['userSerialId', 'groupSerialId']); - - DatabaseModel::insert([ - 'table' => 'users_baskets_preferences', - 'columnsValues' => [ - 'user_serial_id' => $aArgs['userSerialId'], - 'group_serial_id' => $aArgs['groupSerialId'], - 'basket_id' => $aArgs['basketId'], - 'display' => $aArgs['display'], - 'color' => $aArgs['color'] - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - ValidatorModel::stringType($aArgs['set'], ['display', 'color']); - - DatabaseModel::update([ - 'table' => 'users_baskets_preferences', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'users_baskets_preferences', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } -} diff --git a/src/app/user/models/UserEntityModel.php b/src/app/user/models/UserEntityModel.php deleted file mode 100644 index 9e2dbc2901..0000000000 --- a/src/app/user/models/UserEntityModel.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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 User Entity Model -* @author dev@maarch.org -*/ - -namespace User\models; - -class UserEntityModel extends UserEntityModelAbstract -{ -} diff --git a/src/app/user/models/UserEntityModelAbstract.php b/src/app/user/models/UserEntityModelAbstract.php deleted file mode 100644 index 05fc09d3fe..0000000000 --- a/src/app/user/models/UserEntityModelAbstract.php +++ /dev/null @@ -1,205 +0,0 @@ -<?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 User Entity Model Abstract - * @author dev@maarch.org - */ - -namespace User\models; - -use Entity\models\EntityModel; -use SrcCore\models\DatabaseModel; -use SrcCore\models\ValidatorModel; - -abstract class UserEntityModelAbstract -{ - public static function get(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['select', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $users = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_entities'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $users; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); - ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - - DatabaseModel::update([ - 'table' => 'users_entities', - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - - DatabaseModel::delete([ - 'table' => 'users_entities', - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return true; - } - - public static function getUsersWithoutEntities(array $aArgs) - { - ValidatorModel::arrayType($aArgs, ['select']); - - $excludedUsers = ['superadmin']; - $aUsersEntities = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users', 'users_entities'], - 'left_join' => ['users.user_id = users_entities.user_id'], - 'where' => ['users_entities IS NULL', 'users.user_id not in (?)', 'status != ?'], - 'data' => [$excludedUsers, 'DEL'] - ]); - - return $aUsersEntities; - } - - public static function addUserEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'entityId', 'primaryEntity']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['entityId', 'role', 'primaryEntity']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::insert([ - 'table' => 'users_entities', - 'columnsValues' => [ - 'user_id' => $user['user_id'], - 'entity_id' => $aArgs['entityId'], - 'user_role' => $aArgs['role'], - 'primary_entity' => $aArgs['primaryEntity'] - ] - ]); - - return true; - } - - public static function updateUserEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'entityId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['entityId', 'role']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::update([ - 'table' => 'users_entities', - 'set' => [ - 'user_role' => $aArgs['role'] - ], - 'where' => ['user_id = ?', 'entity_id = ?'], - 'data' => [$user['user_id'], $aArgs['entityId']] - ]); - - return true; - } - - public static function updateUserPrimaryEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'entityId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - $entities = EntityModel::getByUserId(['userId' => $user['user_id']]); - foreach ($entities as $entity) { - if ($entity['primary_entity'] == 'Y') { - DatabaseModel::update([ - 'table' => 'users_entities', - 'set' => [ - 'primary_entity' => 'N' - ], - 'where' => ['user_id = ?', 'entity_id = ?'], - 'data' => [$user['user_id'], $entity['entity_id']] - ]); - } - } - - DatabaseModel::update([ - 'table' => 'users_entities', - 'set' => [ - 'primary_entity' => 'Y' - ], - 'where' => ['user_id = ?', 'entity_id = ?'], - 'data' => [$user['user_id'], $aArgs['entityId']] - ]); - - return true; - } - - public static function reassignUserPrimaryEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $entities = EntityModel::getByUserId(['userId' => $aArgs['userId']]); - if (!empty($entities[0])) { - DatabaseModel::update([ - 'table' => 'users_entities', - 'set' => [ - 'primary_entity' => 'Y' - ], - 'where' => ['user_id = ?', 'entity_id = ?'], - 'data' => [$aArgs['userId'], $entities[0]['entity_id']] - ]); - } - - return true; - } - - public static function deleteUserEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'entityId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::delete([ - 'table' => 'users_entities', - 'where' => ['entity_id = ?', 'user_id = ?'], - 'data' => [$aArgs['entityId'], $user['user_id']] - ]); - - return true; - } - - public static function getUsersByEntities(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['entities']); - ValidatorModel::arrayType($aArgs, ['entities', 'select']); - - $aUsers = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users, users_entities'], - 'where' => ['users.user_id = users_entities.user_id', 'users_entities.entity_id in (?)', 'status != ?'], - 'data' => [$aArgs['entities'], 'DEL'] - ]); - - return $aUsers; - } -} diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index dcb5f77fa6..4ecea3b8c0 100644 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -14,11 +14,9 @@ namespace User\models; -use SrcCore\models\AuthenticationModel; use SrcCore\models\DatabaseModel; use SrcCore\models\ValidatorModel; -require_once 'core/class/Url.php'; abstract class UserModelAbstract { @@ -58,77 +56,6 @@ abstract class UserModelAbstract return $aUser[0]; } - public static function create(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['user']); - ValidatorModel::notEmpty($aArgs['user'], ['userId', 'firstname', 'lastname']); - ValidatorModel::stringType($aArgs['user'], ['userId', 'firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone', 'changePassword', 'loginmode']); - - DatabaseModel::insert([ - 'table' => 'users', - 'columnsValues' => [ - 'user_id' => $aArgs['user']['userId'], - 'firstname' => $aArgs['user']['firstname'], - 'lastname' => $aArgs['user']['lastname'], - 'mail' => $aArgs['user']['mail'], - 'phone' => $aArgs['user']['phone'], - 'initials' => $aArgs['user']['initials'], - 'thumbprint' => $aArgs['user']['thumbprint'], - 'enabled' => 'Y', - 'status' => 'OK', - 'change_password' => empty($aArgs['user']['changePassword']) ? 'Y' : $aArgs['user']['changePassword'], - 'loginmode' => empty($aArgs['user']['loginmode']) ? 'standard' : $aArgs['user']['loginmode'], - 'password' => AuthenticationModel::getPasswordHash('maarch'), - 'password_modification_date' => 'CURRENT_TIMESTAMP' - ] - ]); - - return true; - } - - public static function update(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'user']); - ValidatorModel::notEmpty($aArgs['user'], ['firstname', 'lastname']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs['user'], ['firstname', 'lastname', 'mail', 'initials', 'thumbprint', 'phone', 'enabled', 'loginmode']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'firstname' => $aArgs['user']['firstname'], - 'lastname' => $aArgs['user']['lastname'], - 'mail' => $aArgs['user']['mail'], - 'phone' => $aArgs['user']['phone'], - 'initials' => $aArgs['user']['initials'], - 'enabled' => $aArgs['user']['enabled'], - 'thumbprint' => $aArgs['user']['thumbprint'], - 'loginmode' => empty($aArgs['user']['loginmode']) ? 'standard' : $aArgs['user']['loginmode'], - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function delete(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'status' => 'DEL', - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - public static function getByUserId(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['userId']); @@ -148,143 +75,6 @@ abstract class UserModelAbstract return $aUser[0]; } - public static function getByEmail(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['mail']); - ValidatorModel::stringType($aArgs, ['mail']); - - $aUser = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users'], - 'where' => ['mail = ? and status = ?'], - 'data' => [$aArgs['mail'], 'OK'], - 'limit' => 1 - ]); - - return $aUser; - } - - public static function updatePassword(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'password']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['password']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'password' => AuthenticationModel::getPasswordHash($aArgs['password']), - 'password_modification_date' => 'CURRENT_TIMESTAMP', - 'change_password' => 'N', - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function resetPassword(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'password' => AuthenticationModel::getPasswordHash('maarch'), - 'change_password' => 'Y', - 'password_modification_date' => 'CURRENT_TIMESTAMP' - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function createEmailSignature(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'title', 'htmlBody']); - ValidatorModel::stringType($aArgs, ['userId', 'title', 'htmlBody']); - - DatabaseModel::insert([ - 'table' => 'users_email_signatures', - 'columnsValues' => [ - 'user_id' => $aArgs['userId'], - 'title' => $aArgs['title'], - 'html_body' => $aArgs['htmlBody'] - ] - ]); - - return true; - } - - public static function updateEmailSignature(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id','userId', 'title', 'htmlBody']); - ValidatorModel::stringType($aArgs, ['userId', 'title', 'htmlBody']); - ValidatorModel::intVal($aArgs, ['id']); - - DatabaseModel::update([ - 'table' => 'users_email_signatures', - 'set' => [ - 'title' => $aArgs['title'], - 'html_body' => $aArgs['htmlBody'], - ], - 'where' => ['user_id = ?', 'id = ?'], - 'data' => [$aArgs['userId'], $aArgs['id']] - ]); - - return true; - } - - public static function deleteEmailSignature(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - DatabaseModel::delete([ - 'table' => 'users_email_signatures', - 'where' => ['user_id = ?', 'id = ?'], - 'data' => [$aArgs['userId'], $aArgs['id']] - ]); - - return true; - } - - public static function getEmailSignaturesById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_email_signatures'], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']], - 'order_by' => ['id'] - ]); - - return $aReturn; - } - - public static function getEmailSignatureWithSignatureIdById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'signatureId']); - ValidatorModel::stringType($aArgs, ['userId']); - ValidatorModel::intVal($aArgs, ['signatureId']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['users_email_signatures'], - 'where' => ['user_id = ?', 'id = ?'], - 'data' => [$aArgs['userId'], $aArgs['signatureId']], - ]); - - return $aReturn[0]; - } - public static function getLabelledUserById(array $aArgs) { ValidatorModel::intVal($aArgs, ['id']); @@ -303,182 +93,4 @@ abstract class UserModelAbstract return $labelledUser; } - - public static function getCurrentConsigneById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['resId']); - ValidatorModel::intVal($aArgs, ['resId']); - - $aReturn = DatabaseModel::select([ - 'select' => ['process_comment'], - 'table' => ['listinstance'], - 'where' => ['res_id = ?', 'process_date is null', 'item_mode in (?)'], - 'data' => [$aArgs['resId'], ['visa', 'sign']], - 'order_by' => ['listinstance_id ASC'], - 'limit' => 1 - ]); - - if (empty($aReturn[0])) { - return ''; - } - - return $aReturn[0]['process_comment']; - } - - public static function getPrimaryEntityByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aEntity = DatabaseModel::select([ - 'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'], - 'table' => ['users_entities, entities'], - 'where' => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?', 'users_entities.primary_entity = ?'], - 'data' => [$aArgs['userId'], 'Y'] - ]); - - if (empty($aEntity[0])) { - return []; - } - - return $aEntity[0]; - } - - public static function getGroupsByUserId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aGroups = DatabaseModel::select([ - 'select' => ['usergroups.id', 'usergroup_content.group_id', 'usergroups.group_desc', 'usergroup_content.primary_group', 'usergroup_content.role', 'security.maarch_comment', 'security.where_clause'], - 'table' => ['usergroup_content, usergroups, security'], - 'where' => ['usergroup_content.group_id = usergroups.group_id', 'usergroup_content.user_id = ?','usergroups.group_id = security.group_id'], - 'data' => [$aArgs['userId']] - ]); - - return $aGroups; - } - - public static function getEntitiesById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $aEntities = DatabaseModel::select([ - 'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'], - 'table' => ['users_entities, entities'], - 'where' => ['users_entities.entity_id = entities.entity_id', 'users_entities.user_id = ?'], - 'data' => [$aArgs['userId']], - 'order_by' => ['users_entities.primary_entity DESC'] - ]); - - return $aEntities; - } - - public static function updateStatus(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'status']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['status']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'status' => $aArgs['status'] - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function hasGroup(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - $groups = UserModel::getGroupsByUserId(['userId' => $user['user_id']]); - foreach ($groups as $value) { - if ($value['group_id'] == $aArgs['groupId']) { - return true; - } - } - - return false; - } - - public static function addGroup(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['groupId', 'role']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::insert([ - 'table' => 'usergroup_content', - 'columnsValues' => [ - 'user_id' => $user['user_id'], - 'group_id' => $aArgs['groupId'], - 'role' => $aArgs['role'], - 'primary_group' => 'Y' - ] - ]); - - return true; - } - - public static function updateGroup(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['groupId', 'role']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::update([ - 'table' => 'usergroup_content', - 'set' => [ - 'role' => $aArgs['role'] - ], - 'where' => ['user_id = ?', 'group_id = ?'], - 'data' => [$user['user_id'], $aArgs['groupId']] - ]); - - return true; - } - - public static function deleteGroup(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'groupId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['groupId']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - DatabaseModel::delete([ - 'table' => 'usergroup_content', - 'where' => ['group_id = ?', 'user_id = ?'], - 'data' => [$aArgs['groupId'], $user['user_id']] - ]); - - return true; - } - - public static function hasEntity(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id', 'entityId']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::stringType($aArgs, ['entityId']); - - $user = UserModel::getById(['id' => $aArgs['id'], 'select' => ['user_id']]); - $entities = UserModel::getEntitiesById(['userId' => $user['user_id']]); - foreach ($entities as $value) { - if ($value['entity_id'] == $aArgs['entityId']) { - return true; - } - } - - return false; - } } diff --git a/src/app/versionUpdate/controllers/VersionUpdateController.php b/src/app/versionUpdate/controllers/VersionUpdateController.php deleted file mode 100644 index 801e9d5912..0000000000 --- a/src/app/versionUpdate/controllers/VersionUpdateController.php +++ /dev/null @@ -1,73 +0,0 @@ -<?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 Version Update Controller - * @author dev@maarch.org - */ - -namespace VersionUpdate\controllers; - -use Gitlab\Client; -use Group\models\ServiceModel; -use Parameter\models\ParameterModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class VersionUpdateController -{ - public function get(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_update_control', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $client = Client::create('https://labs.maarch.org/api/v4/'); - try { - $tags = $client->api('tags')->all('12'); - } catch (\Exception $e) { - return $response->withJson(['errors' => $e->getMessage()]); - } - - $parameter = ParameterModel::getById(['select' => ['param_value_string'], 'id' => 'database_version']); - - $currentVersionBranch = substr($parameter['param_value_string'], 0, 5); - $currentVersionBranchYear = substr($parameter['param_value_string'], 0, 2); - $currentVersionBranchMonth = substr($parameter['param_value_string'], 3, 2); - $currentVersionTag = substr($parameter['param_value_string'], 6); - - $currentMinorVersions = []; - $availableMajorVersions = []; - - foreach ($tags as $value) { - if (!preg_match("/^\d{2}\.\d{2}\.\d+$/", $value['name'])) { - continue; - } - $tag = substr($value['name'], 6); - $pos = strpos($value['name'], $currentVersionBranch); - if ($pos === false) { - $year = substr($value['name'], 0, 2); - $month = substr($value['name'], 3, 2); - if (($year == $currentVersionBranchYear && $month > $currentVersionBranchMonth) || $year > $currentVersionBranchYear) { - $availableMajorVersions[] = $value['name']; - } - } else { - if ($tag > $currentVersionTag) { - $currentMinorVersions[] = $value['name']; - } - } - } - - return $response->withJson([ - 'currentMinorVersions' => $currentMinorVersions, - 'availableMajorVersions' => $availableMajorVersions, - 'currentVersion' => $parameter['param_value_string'] - ]); - } -} diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 5104f2d351..e715de515b 100644 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -15,10 +15,6 @@ namespace SrcCore\controllers; use SrcCore\models\AuthenticationModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\PasswordModel; -use SrcCore\models\ValidatorModel; -use User\models\UserModel; class AuthenticationController { @@ -39,75 +35,4 @@ class AuthenticationController return $userId; } - - public static function isRouteAvailable(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'currentRoute']); - ValidatorModel::stringType($aArgs, ['userId', 'currentRoute']); - - if ($aArgs['currentRoute'] != '/initialize') { - $user = UserModel::getByUserId(['select' => ['status', 'change_password'], 'userId' => $aArgs['userId']]); - - if ($user['status'] == 'ABS' && $aArgs['currentRoute'] != "/users/{id}/status") { - return ['isRouteAvailable' => false, 'errors' => 'User is ABS and must be activated']; - } - - if (!in_array($aArgs['currentRoute'], ['/passwordRules', '/currentUser/password'])) { - $loggingMethod = CoreConfigModel::getLoggingMethod(); - - if (!in_array($loggingMethod['id'], ['sso', 'cas', 'ldap', 'ozwillo'])) { - - $passwordRules = PasswordModel::getEnabledRules(); - if ($user['change_password'] == 'Y') { - return ['isRouteAvailable' => false, 'errors' => 'User must change his password']; - } elseif (!empty($passwordRules['renewal'])) { - $currentDate = new \DateTime(); - $lastModificationDate = new \DateTime($user['password_modification_date']); - $lastModificationDate->add(new \DateInterval("P{$passwordRules['renewal']}D")); - - if ($currentDate > $lastModificationDate) { - return ['isRouteAvailable' => false, 'errors' => 'User must change his password']; - } - } - } - } - } - - return ['isRouteAvailable' => true]; - } - - public static function handleFailedAuthentication(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - $passwordRules = PasswordModel::getEnabledRules(); - - if (!empty($passwordRules['lockAttempts'])) { - $user = UserModel::getByUserId(['select' => ['failed_authentication', 'locked_until'], 'userId' => $aArgs['userId']]); - - if (!empty($user)) { - if (!empty($user['locked_until'])) { - $lockedDate = new \DateTime($user['locked_until']); - $currentDate = new \DateTime(); - if ($currentDate > $lockedDate) { - AuthenticationModel::resetFailedAuthentication(['userId' => $aArgs['userId']]); - $user['failed_authentication'] = 0; - } else { - return _ACCOUNT_LOCKED_UNTIL . " {$lockedDate->format('d/m/Y H:i')}"; - } - } - - AuthenticationModel::increaseFailedAuthentication(['userId' => $aArgs['userId'], 'tentatives' => $user['failed_authentication'] + 1]); - - if (!empty($user['failed_authentication']) && ($user['failed_authentication'] + 1) >= $passwordRules['lockAttempts'] && !empty($passwordRules['lockTime'])) { - $lockedUntil = time() + 60 * $passwordRules['lockTime']; - AuthenticationModel::lockUser(['userId' => $aArgs['userId'], 'lockedUntil' => $lockedUntil]); - return _ACCOUNT_LOCKED_FOR . " {$passwordRules['lockTime']} mn"; - } - } - } - - return _BAD_LOGIN_OR_PSW; - } } diff --git a/src/core/controllers/AutoCompleteController.php b/src/core/controllers/AutoCompleteController.php deleted file mode 100644 index feacf761f8..0000000000 --- a/src/core/controllers/AutoCompleteController.php +++ /dev/null @@ -1,390 +0,0 @@ -<?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 Auto Complete Controller -* @author dev@maarch.org -*/ - -namespace SrcCore\controllers; - -use Contact\controllers\ContactGroupController; -use Contact\models\ContactModel; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use Entity\models\EntityModel; -use SrcCore\models\CoreConfigModel; -use SrcCore\models\DatabaseModel; -use SrcCore\models\TextFormatModel; -use SrcCore\models\ValidatorModel; -use Status\models\StatusModel; -use User\models\UserModel; - -class AutoCompleteController -{ - const LIMIT = 50; - - public static function getContacts(Request $request, Response $response) - { - $data = $request->getQueryParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['search']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['type']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $searchItems = explode(' ', $data['search']); - - $fields = '(contact_firstname ilike ? OR contact_lastname ilike ? OR firstname ilike ? OR lastname ilike ? OR society ilike ? - OR address_num ilike ? OR address_street ilike ? OR address_town ilike ? OR address_postal_code ilike ?)'; - $where = []; - $requestData = []; - if ($data['type'] != 'all') { - $where = ['contact_type = ?']; - $requestData = [$data['type']]; - } - foreach ($searchItems as $item) { - if (strlen($item) >= 2) { - $where[] = $fields; - for ($i = 0; $i < 9; $i++) { - $requestData[] = "%{$item}%"; - } - } - } - - $contacts = ContactModel::getOnView([ - 'select' => [ - 'ca_id', 'firstname', 'lastname', 'contact_lastname', 'contact_firstname', 'society', 'address_num', - 'address_street', 'address_town', 'address_postal_code', 'is_corporate_person' - ], - 'where' => $where, - 'data' => $requestData, - 'limit' => 1000 - ]); - - $data = []; - foreach ($contacts as $contact) { - $data[] = ContactGroupController::getFormattedContact(['contact' => $contact])['contact']; - } - - return $response->withJson($data); - } - - public static function getUsers(Request $request, Response $response) - { - $data = $request->getQueryParams(); - $check = Validator::stringType()->notEmpty()->validate($data['search']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $excludedUsers = ['superadmin']; - - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(firstname ilike ? OR lastname ilike ?)', - 'where' => ['enabled = ?', 'status != ?', 'user_id not in (?)'], - 'data' => ['Y', 'DEL', $excludedUsers], - 'fieldsNumber' => 2, - ]); - - $users = UserModel::get([ - 'select' => ['user_id', 'firstname', 'lastname'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'orderBy' => ['lastname'], - 'limit' => self::LIMIT - ]); - - $data = []; - foreach ($users as $value) { - $data[] = [ - 'type' => 'user', - 'id' => $value['user_id'], - 'idToDisplay' => "{$value['firstname']} {$value['lastname']}", - 'otherInfo' => '' - ]; - } - - return $response->withJson($data); - } - - public static function getUsersForAdministration(Request $request, Response $response) - { - $data = $request->getQueryParams(); - $check = Validator::stringType()->notEmpty()->validate($data['search']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $excludedUsers = ['superadmin']; - - if ($GLOBALS['userId'] != 'superadmin') { - $entities = EntityModel::getAllEntitiesByUserId(['userId' => $GLOBALS['userId']]); - - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(users.firstname ilike ? OR users.lastname ilike ?)', - 'where' => [ - 'users.user_id = users_entities.user_id', - 'users_entities.entity_id in (?)', - 'users.status != ?', - 'users.enabled = ?' - ], - 'data' => [$entities, 'DEL', 'Y'], - 'fieldsNumber' => 2, - ]); - - $users = DatabaseModel::select([ - 'select' => ['DISTINCT users.user_id', 'users.id', 'users.firstname', 'users.lastname'], - 'table' => ['users, users_entities'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'limit' => self::LIMIT - ]); - - if (count($users) < self::LIMIT) { - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(users.firstname ilike ? OR users.lastname ilike ?)', - 'where' => [ - 'users_entities IS NULL', - 'users.user_id not in (?)', - 'users.status != ?', - 'users.enabled = ?' - ], - 'data' => [$excludedUsers, 'DEL', 'Y'], - 'fieldsNumber' => 2, - ]); - - $usersNoEntities = DatabaseModel::select([ - 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname'], - 'table' => ['users', 'users_entities'], - 'left_join' => ['users.user_id = users_entities.user_id'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'limit' => (self::LIMIT - count($users)) - ]); - - $users = array_merge($users, $usersNoEntities); - } - } else { - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(firstname ilike ? OR lastname ilike ?)', - 'where' => ['enabled = ?', 'status != ?', 'user_id not in (?)'], - 'data' => ['Y', 'DEL', $excludedUsers], - 'fieldsNumber' => 2, - ]); - - $users = UserModel::get([ - 'select' => ['id', 'user_id', 'firstname', 'lastname'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'orderBy' => ['lastname'], - 'limit' => self::LIMIT - ]); - } - - $data = []; - foreach ($users as $value) { - $data[] = [ - 'type' => 'user', - 'id' => $value['id'], - 'idToDisplay' => "{$value['firstname']} {$value['lastname']}", - 'otherInfo' => $value['user_id'] - ]; - } - - return $response->withJson($data); - } - - public static function getUsersForVisa(Request $request, Response $response) - { - $data = $request->getQueryParams(); - $check = Validator::stringType()->notEmpty()->validate($data['search']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $excludedUsers = ['superadmin']; - - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(users.firstname ilike ? OR users.lastname ilike ?)', - 'where' => [ - 'usergroup_content.group_id = usergroups_services.group_id', - 'usergroup_content.user_id = users.user_id', - 'usergroups_services.service_id in (?)', - 'users.user_id not in (?)', - 'users.enabled = ?', - 'users.status != ?' - ], - 'data' => [['visa_documents', 'sign_document'], $excludedUsers, 'Y', 'DEL'], - 'fieldsNumber' => 2, - ]); - - $users = DatabaseModel::select([ - 'select' => ['DISTINCT users.user_id', 'users.firstname', 'users.lastname'], - 'table' => ['users, usergroup_content, usergroups_services'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'order_by' => ['users.lastname'], - 'limit' => self::LIMIT - ]); - - $data = []; - foreach ($users as $key => $value) { - $data[] = [ - 'type' => 'user', - 'id' => $value['user_id'], - 'idToDisplay' => "{$value['firstname']} {$value['lastname']}", - 'otherInfo' => '' - ]; - } - - return $response->withJson($data); - } - - public static function getEntities(Request $request, Response $response) - { - $data = $request->getQueryParams(); - $check = Validator::stringType()->notEmpty()->validate($data['search']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - $requestData = AutoCompleteController::getDataForRequest([ - 'search' => $data['search'], - 'fields' => '(entity_label ilike ?)', - 'where' => ['enabled = ?'], - 'data' => ['Y'], - 'fieldsNumber' => 1, - ]); - - $entities = EntityModel::get([ - 'select' => ['entity_id', 'entity_label', 'short_label'], - 'where' => $requestData['where'], - 'data' => $requestData['data'], - 'orderBy' => ['entity_label'], - 'limit' => self::LIMIT - ]); - - $data = []; - foreach ($entities as $value) { - $data[] = [ - 'type' => 'entity', - 'id' => $value['entity_id'], - 'idToDisplay' => $value['entity_label'], - 'otherInfo' => $value['short_label'] - ]; - } - - return $response->withJson($data); - } - - public static function getStatuses(Request $request, Response $response) - { - $statuses = StatusModel::get(['select' => ['id', 'label_status', 'img_filename']]); - - $data = []; - foreach ($statuses as $value) { - $data[] = [ - 'type' => 'status', - 'id' => $value['id'], - 'idToDisplay' => $value['label_status'], - 'otherInfo' => $value['img_filename'] - ]; - } - - return $response->withJson($data); - } - - public static function getBanAddresses(Request $request, Response $response) - { - $data = $request->getQueryParams(); - - $check = Validator::stringType()->notEmpty()->validate($data['address']); - $check = $check && Validator::stringType()->notEmpty()->validate($data['department']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - $customId = CoreConfigModel::getCustomId(); - - if (is_dir("custom/{$customId}/referential/ban/indexes/{$data['department']}")) { - $path = "custom/{$customId}/referential/ban/indexes/{$data['department']}"; - } elseif (is_dir('referential/ban/indexes/' . $data['department'])) { - $path = 'referential/ban/indexes/' . $data['department']; - } else { - return $response->withStatus(400)->withJson(['errors' => 'Department indexes do not exist']); - } - - \Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); - \Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(\Zend_Search_Lucene_Search_QueryParser::B_AND); - \Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); - - $index = \Zend_Search_Lucene::open($path); - \Zend_Search_Lucene::setResultSetLimit(100); - - $data['address'] = str_replace(['*', '~', '-', '\''], ' ', $data['address']); - $aAddress = explode(' ', $data['address']); - foreach ($aAddress as $key => $value) { - if (strlen($value) <= 2 && !is_numeric($value)) { - unset($aAddress[$key]); - continue; - } - if (strlen($value) >= 3 && $value != 'rue' && $value != 'avenue' && $value != 'boulevard') { - $aAddress[$key] .= '*'; - } - } - $data['address'] = implode(' ', $aAddress); - if (empty($data['address'])) { - return $response->withJson([]); - } - - $hits = $index->find(TextFormatModel::normalize(['string' => $data['address']])); - - $addresses = []; - foreach ($hits as $key => $hit) { - $addresses[] = [ - 'banId' => $hit->banId, - 'number' => $hit->streetNumber, - 'afnorName' => $hit->afnorName, - 'postalCode' => $hit->postalCode, - 'city' => $hit->city, - 'address' => "{$hit->streetNumber} {$hit->afnorName}, {$hit->city} ({$hit->postalCode})" - ]; - } - - return $response->withJson($addresses); - } - - private static function getDataForRequest(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['search', 'fields', 'where', 'data', 'fieldsNumber']); - ValidatorModel::stringType($aArgs, ['search', 'fields']); - ValidatorModel::arrayType($aArgs, ['where', 'data']); - ValidatorModel::intType($aArgs, ['fieldsNumber']); - - $searchItems = explode(' ', $aArgs['search']); - - foreach ($searchItems as $item) { - if (strlen($item) >= 2) { - $aArgs['where'][] = $aArgs['fields']; - for ($i = 0; $i < $aArgs['fieldsNumber']; $i++) { - $aArgs['data'][] = "%{$item}%"; - } - } - } - - return ['where' => $aArgs['where'], 'data' => $aArgs['data']]; - } -} diff --git a/src/core/controllers/CoreController.php b/src/core/controllers/CoreController.php deleted file mode 100644 index 8abaf92169..0000000000 --- a/src/core/controllers/CoreController.php +++ /dev/null @@ -1,113 +0,0 @@ -<?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 Core Controller - * - * @author dev@maarch.org - */ - -namespace SrcCore\controllers; - -use Basket\models\GroupBasketModel; -use Group\controllers\ServiceController; -use Group\models\ServiceModel; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\CoreConfigModel; -use User\models\UserModel; - -require_once 'core/class/Url.php'; - -class CoreController -{ - public function initialize(Request $request, Response $response) - { - $aInit = []; - $aInit['coreUrl'] = str_replace('rest/', '', \Url::coreurl()); - $aInit['applicationName'] = CoreConfigModel::getApplicationName(); - $aInit['applicationMinorVersion'] = CoreConfigModel::getApplicationVersion()['applicationMinorVersion']; - $aInit['lang'] = CoreConfigModel::getLanguage(); - $aInit['user'] = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]); - - $aInit['scriptsToinject'] = []; - $scriptsToInject = []; - $scripts = scandir('dist'); - foreach ($scripts as $value) { - if (strstr($value, 'runtime.') !== false || strstr($value, 'main.') !== false || strstr($value, 'vendor.') !== false || strstr($value, 'scripts.') !== false) { - if (strstr($value, '.js.map') === false) { - $scriptsToInject[] = $value; - } - } - } - - for ($i = 0; $i < count($scriptsToInject); $i++) { - foreach ($scriptsToInject as $value) { - if ($i == 0 && strstr($value, 'scripts.') !== false) { - $aInit['scriptsToinject'][] = $value; - } elseif ($i == 1 && strstr($value, 'main.') !== false) { - $aInit['scriptsToinject'][] = $value; - } elseif ($i == 2 && strstr($value, 'runtime.') !== false) { - $aInit['scriptsToinject'][] = $value; - } elseif ($i == 3 && strstr($value, 'vendor.') !== false) { - $aInit['scriptsToinject'][] = $value; - } - } - } - - return $response->withJson($aInit); - } - - public function getHeader(Request $request, Response $response) - { - $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id', 'user_id', 'firstname', 'lastname']]); - $user['groups'] = UserModel::getGroupsByUserId(['userId' => $GLOBALS['userId']]); - $user['entities'] = UserModel::getEntitiesById(['userId' => $GLOBALS['userId']]); - $user['indexingGroups'] = []; - - if ($GLOBALS['userId'] == 'superadmin') { - $menu = ServiceModel::getApplicationServicesByXML(['type' => 'menu']); - $menuModules = ServiceModel::getModulesServicesByXML(['type' => 'menu']); - $menu = array_merge($menu, $menuModules); - } else { - $menu = ServiceController::getMenuServicesByUserId(['userId' => $GLOBALS['userId']]); - foreach ($menu as $value) { - if ($value['id'] == 'index_mlb') { - foreach ($user['groups'] as $group) { - if (GroupBasketModel::hasBasketByGroupId(['groupId' => $group['group_id'], 'basketId' => 'IndexingBasket'])) { - $user['indexingGroups'][] = ['groupId' => $group['group_id'], 'label' => $group['group_desc']]; - } - } - } - } - } - - return $response->withJson([ - 'user' => $user, - 'menu' => $menu - ]); - } - - public static function getAdministration(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - if ($GLOBALS['userId'] == 'superadmin') { - $administration = []; - $administrationApplication = ServiceModel::getApplicationServicesByXML(['type' => 'admin']); - $administrationModule = ServiceModel::getModulesServicesByXML(['type' => 'admin']); - $administration['administrations'] = array_merge_recursive($administrationApplication, $administrationModule); - } else { - $administration = ServiceModel::getAdministrationServicesByUserId(['userId' => $GLOBALS['userId']]); - } - - return $response->withJson($administration); - } -} diff --git a/src/core/controllers/LogsController.php b/src/core/controllers/LogsController.php deleted file mode 100644 index 373b6151cc..0000000000 --- a/src/core/controllers/LogsController.php +++ /dev/null @@ -1,186 +0,0 @@ -<?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 Logs Controller -* @author dev@maarch.org -* @ingroup core -*/ - -namespace SrcCore\controllers; - -use SrcCore\models\TextFormatModel; -use SrcCore\models\ValidatorModel; -use SrcCore\models\CoreConfigModel; - -require_once 'apps/maarch_entreprise/tools/log4php/Logger.php'; //TODO composer - -class LogsController -{ - /* - timestart : timestamp Debut - timeend : timestamp Fin - level : level log4php - message : message dans les logs - */ - public function executionTimeLog($timestart, $timeend, $level, $message) - { - if (empty($timeend)) { - $timeend = microtime(true); - } - $time = $timeend - $timestart; - - //TODO : USE NEW METHOD - // self::$level( - // ['message' => $message.'. Done in ' . number_format($time, 3) . ' secondes.'] - // ); - } - - public static function buildLoggingMethod() - { - $loggingMethods = []; - - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/logging_method.xml']); - if ($loadedXml) { - foreach ($loadedXml->METHOD as $METHOD) { - $loggingMethods[] = [ - 'ID' => (string)$METHOD->ID, - 'ACTIVATED' => (boolean)$METHOD->ENABLED, - 'LOGGER_NAME_TECH' => (string)$METHOD->LOGGER_NAME_TECH, - 'LOGGER_NAME_FUNC' => (string)$METHOD->LOGGER_NAME_FUNC, - 'LOG_FORMAT' => (string)$METHOD->APPLI_LOG_FORMAT, - 'CODE_METIER' => (string)$METHOD->CODE_METIER - ]; - } - } else { - $loggingMethods[0]['ID'] = 'database'; - $loggingMethods[0]['ACTIVATED'] = true; - $loggingMethods[1]['ID'] = 'log4php'; - $loggingMethods[1]['ACTIVATED'] = true; - $loggingMethods[1]['LOGGER_NAME_TECH'] = 'loggerTechnique'; - $loggingMethods[1]['LOGGER_NAME_FUNC'] = 'loggerFonctionnel'; - $loggingMethods[1]['LOG_FORMAT'] = '[%RESULT%][%CODE_METIER%][%WHERE%][%ID%][%HOW%][%USER%][%WHAT%][%ID_MODULE%][%REMOTE_IP%]'; - $loggingMethods[1]['CODE_METIER'] = 'MAARCH'; - } - - return $loggingMethods; - } - - public static function writeLog(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['logLine', 'level', 'loggerName']); - ValidatorModel::stringType($aArgs, ['logLine', 'level', 'loggerName']); - - $customId = CoreConfigModel::getCustomId(); - if (file_exists("custom/{$customId}/apps/maarch_entreprise/xml/log4php.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/log4php.xml"; - } elseif (file_exists('apps/maarch_entreprise/xml/log4php.xml')) { - $path = 'apps/maarch_entreprise/xml/log4php.xml'; - } else { - $path = 'apps/maarch_entreprise/xml/log4php.default.xml'; - } - - \Logger::configure($path); - $logger = \Logger::getLogger($aArgs['loggerName']); - - switch ($aArgs['level']) { - case 'DEBUG': - $logger->debug($aArgs['logLine']); - break; - case 'INFO': - $logger->info($aArgs['logLine']); - break; - case 'WARN': - $logger->warn($aArgs['logLine']); - break; - case 'ERROR': - $logger->error($aArgs['logLine']); - break; - case 'FATAL': - $logger->fatal($aArgs['logLine']); - break; - } - } - - protected static function addToLog4php(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['traceInformations', 'loggingMethod']); - ValidatorModel::arrayType($aArgs, ['traceInformations', 'loggingMethod']); - - $logLine = str_replace( - [ - '%RESULT%', - '%CODE_METIER%', - '%WHERE%', - '%ID%', - '%HOW%', - '%USER%', - '%WHAT%', - '%ID_MODULE%', - '%REMOTE_IP%' - ], - [ - 'OK', - $aArgs['loggingMethod']['CODE_METIER'], - $aArgs['traceInformations']['WHERE'], - $aArgs['traceInformations']['ID'], - $aArgs['traceInformations']['HOW'], - $aArgs['traceInformations']['USER'], - $aArgs['traceInformations']['WHAT'], - $aArgs['traceInformations']['ID_MODULE'], - $aArgs['traceInformations']['REMOTE_IP'] - ], - $aArgs['loggingMethod']['LOG_FORMAT'] - ); - - $loggerName = (empty($aArgs['isTech']) ? $aArgs['loggingMethod']['LOGGER_NAME_FUNC'] : $aArgs['loggingMethod']['LOGGER_NAME_TECH']); - $logLine = TextFormatModel::htmlWasher($logLine); - $logLine = TextFormatModel::removeAccent(['string' => $logLine]); - - LogsController::writeLog([ - 'loggerName' => $loggerName, - 'logLine' => $logLine, - 'level' => $aArgs['traceInformations']['LEVEL'] - ]); - } - - public static function add(array $aArgs) - { - $traceInformations = [ - 'WHERE' => $aArgs['tableName'], - 'ID' => $aArgs['recordId'], - 'HOW' => $aArgs['eventType'], - 'USER' => $GLOBALS['userId'], - 'WHAT' => $aArgs['eventId'], - 'ID_MODULE' => $aArgs['moduleId'], - 'REMOTE_IP' => $_SERVER['REMOTE_ADDR'], - 'LEVEL' => $aArgs['level'] - ]; - - $loggingMethods = LogsController::buildLoggingMethod(); - - foreach ($loggingMethods as $loggingMethod) { - if ($loggingMethod['ACTIVATED'] == true) { - if ($loggingMethod['ID'] == 'log4php') { - if (empty($loggingMethod['LOGGER_NAME_TECH'])) { - $loggingMethod['LOGGER_NAME_TECH'] = 'loggerTechnique'; - } - if (empty($loggingMethod['LOGGER_NAME_FUNC'])) { - $loggingMethod['LOGGER_NAME_FUNC'] = 'loggerFonctionnel'; - } - LogsController::addToLog4php([ - 'traceInformations' => $traceInformations, - 'loggingMethod' => $loggingMethod, - 'isTech' => $aArgs['isTech'], - ]); - } - } - } - } -} diff --git a/src/core/controllers/PasswordController.php b/src/core/controllers/PasswordController.php deleted file mode 100644 index 6f713c3441..0000000000 --- a/src/core/controllers/PasswordController.php +++ /dev/null @@ -1,103 +0,0 @@ -<?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 Password Controller - * - * @author dev@maarch.org - */ - -namespace SrcCore\controllers; - -use Group\models\ServiceModel; -use History\controllers\HistoryController; -use Respect\Validation\Validator; -use Slim\Http\Request; -use Slim\Http\Response; -use SrcCore\models\PasswordModel; -use SrcCore\models\ValidatorModel; - -class PasswordController -{ - public function getRules(Request $request, Response $response) - { - return $response->withJson(['rules' => PasswordModel::getRules()]); - } - - public function updateRules(Request $request, Response $response) - { - if (!ServiceModel::hasService(['id' => 'admin_password_rules', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $data = $request->getParams(); - $check = Validator::arrayType()->notEmpty()->validate($data['rules']); - if (!$check) { - return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); - } - - foreach ($data['rules'] as $rule) { - $check = Validator::intVal()->validate($rule['value']); - $check = $check && Validator::stringType()->validate($rule['label']); - $check = $check && Validator::boolType()->validate($rule['enabled']); - if (!$check) { - continue; - } - - $existingRule = PasswordModel::getRuleById(['id' => $rule['id'], 'select' => ['label']]); - if (empty($existingRule) || $existingRule['label'] != $rule['label']) { - continue; - } - - $rule['enabled'] = empty($rule['enabled']) ? 'false' : 'true'; - PasswordModel::updateRuleById($rule); - } - - HistoryController::add([ - 'tableName' => 'password_rules', - 'recordId' => 'rules', - 'eventType' => 'UP', - 'info' => _PASSWORD_RULES_UPDATED, - 'moduleId' => 'core', - 'eventId' => 'passwordRulesModification', - ]); - - return $response->withJson(['success' => 'success']); - } - - public static function isPasswordValid(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['password']); - ValidatorModel::stringType($aArgs, ['password']); - - $passwordRules = PasswordModel::getEnabledRules(); - - if (!empty($passwordRules['minLength'])) { - if (strlen($aArgs['password']) < $passwordRules['minLength']) { - return false; - } - } - if (!empty($passwordRules['complexityUpper'])) { - if (!preg_match('/[A-Z]/', $aArgs['password'])) { - return false; - } - } - if (!empty($passwordRules['complexityNumber'])) { - if (!preg_match('/[0-9]/', $aArgs['password'])) { - return false; - } - } - if (!empty($passwordRules['complexitySpecial'])) { - if (!preg_match('/[^a-zA-Z0-9]/', $aArgs['password'])) { - return false; - } - } - - return true; - } -} diff --git a/src/core/lang/lang-en.php b/src/core/lang/lang-en.php index 836f46f211..756a3e644a 100644 --- a/src/core/lang/lang-en.php +++ b/src/core/lang/lang-en.php @@ -12,407 +12,4 @@ * @author dev@maarch.org */ -define('_ACTION_ADDED', 'Action added'); -define('_ACTION_DELETED', 'Action deleted'); -define('_ACTION_UPDATED', 'Action updated'); -define('_ADD_NOTIFICATIONS', 'Notification created'); -define('_ALREADY_EXISTS', 'already exists'); -define('_AVIS_USER', 'For recommendation'); -define('_AVIS_USER_COPY', 'On copy (recommendation)'); -define('_AVIS_USER_INFO', 'For information (recommendation)'); -define('_BASKET_CREATION', 'Basket creation'); -define('_BASKET_GROUP_CREATION', 'Group added for basket'); -define('_BASKET_GROUP_MODIFICATION', 'Group updated for basket'); -define('_BASKET_GROUP_SUPPRESSION', 'Group deleted for basket'); -define('_BASKET_MODIFICATION', 'Basket modification'); -define('_BASKET_SUPPRESSION', 'Basket suppression'); -define('_BASKET_REDIRECTION', 'Basket redirection'); -define('_BASKET_REDIRECTION_SUPPRESSION', 'Basket redirection'); -define('_BASKETS_SORT_MODIFICATION', 'Baskets order modification'); -define('_BY_DEFAULT', 'by default'); -define('_CONTACTS_GROUP_ADDED', 'Contacts group added'); -define('_CONTACTS_GROUP_UPDATED', 'Contacts group updated'); -define('_CONTACTS_GROUP_DELETED', 'Contacts group deleted'); -define('_CONTACTS_GROUP_LIST_ADDED', 'Add contacts for group'); -define('_CONTACTS_GROUP_LIST_DELETED', 'Delete contacts for group'); -define('_CONTACTS_GROUP_LABEL_ALREADY_EXISTS', 'Group with this label already exists'); -define('_DELETE_NOTIFICATIONS', 'Notification deleted'); -define('_DEST_USER', 'Recipient'); -define('_DOCSERVER_ADDED', 'Docserver added'); -define('_DOCSERVER_UPDATED', 'Docserver updated'); -define('_DOCSERVER_DELETED', 'Docserver deleted'); -define('_DOCSERVER_ACTIVATED_EXISTS', 'A docserver with this type and this collection is already activated'); -define('_DOCTYPE_FIRSTLEVEL_ADDED', 'Doctype first level added'); -define('_DOCTYPE_FIRSTLEVEL_DELETED', 'Doctype first level deleted'); -define('_DOCTYPE_FIRSTLEVEL_UPDATED', 'Doctype first level edited'); -define('_DOCTYPE_SECONDLEVEL_ADDED', 'Doctype second level added'); -define('_DOCTYPE_SECONDLEVEL_DELETED', 'Doctype second level deleted'); -define('_DOCTYPE_SECONDLEVEL_UPDATED', 'Doctype second level edited'); -define('_DOCUMENT_NOT_FOUND', 'Document not found'); -define('_ENTITY_CREATION', 'Entity creation'); -define('_ENTITY_MODIFICATION', 'Entity modification'); -define('_ENTITY_SUPPRESSION', 'Entity suppression'); -define('_ENTITY_ID_ALREADY_EXISTS', 'Entity already exists'); -define('_ID', 'Identifier'); -define('_ID_TO_DISPLAY', 'res_id'); -define('_INVALID_CLAUSE', 'Clause is not valid'); -define('_INVALID_REQUEST', 'Request is not valid'); -define('_LIST_TEMPLATE_CREATION', 'List model creation'); -define('_LIST_TEMPLATE_MODIFICATION', 'List model modification'); -define('_LIST_TEMPLATE_SUPPRESSION', 'List model suppression'); -define('_MODIFY_NOTIFICATIONS', 'Notification updated'); -define('_MODIFY_STATUS', 'Statut updated'); -define('_NOTIFICATION_SCHEDULE_UPDATED', 'Notification scheduled updated'); -define('_NOTIFICATION_SCRIPT_ADDED', 'Script created'); -define('_PARAMETER_CREATION', 'Parameter creation'); -define('_PARAMETER_MODIFICATION', 'Parameter modification'); -define('_PARAMETER_SUPPRESSION', 'Parameter suppression'); -define('_PARAMETER_ID_ALREADY_EXISTS', 'Parameter already exists'); -define('_PASSWORD_RULES_UPDATED', 'Password rules updated'); -define('_PRIORITY_CREATION', 'Priority creation'); -define('_PRIORITY_MODIFICATION', 'Priority modification'); -define('_PRIORITY_SUPPRESSION', 'Priority suppression'); -define('_PRIORITY_SORT_MODIFICATION', 'Priorities order modification'); -define('_QUOTA_EXCEEDED', 'Quota exceeded'); -define('_REPORT_MODIFICATION', 'Report modification'); -define('_STATUS_ADDED', 'Statut added'); -define('_STATUS_DELETED', 'Statut deleted'); -define('_STATUS_NOT_FOUND', 'Status not found'); -define('_TEMPLATE_ADDED', 'Template added'); -define('_TEMPLATE_UPDATED', 'Template updated'); -define('_TEMPLATE_DELETED', 'Template deleted'); -define('_TO_CC', 'On copy'); -define('_TO_SIGN', 'For signature'); -define('_UPDATE_STATUS', 'Status update'); -define('_USER_ID_ALREADY_EXISTS', 'The user id already exists'); -define('_USER_CREATED', 'User added'); -define('_USER_UPDATED', 'User updated'); -define('_USER_DELETED', 'User deleted'); -define('_USER_GROUP_CREATION', 'Group added for user'); -define('_USER_GROUP_MODIFICATION', 'Group updated for user'); -define('_USER_GROUP_SUPPRESSION', 'Group deleted for user'); -define('_USER_ENTITY_CREATION', 'Entity added for user'); -define('_USER_ENTITY_MODIFICATION', 'Entity updated for user'); -define('_USER_ENTITY_SUPPRESSION', 'Entity deleted for user'); -define('_USER_ALREADY_LINK_GROUP', 'User is already linked to this group'); -define('_USER_ALREADY_LINK_ENTITY', 'User is already linked to this entity'); -define('_VISA_USER', 'For visa'); -define('_WRONG_FILE_TYPE', 'This type of file is not allowed'); -define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'Parent entity must not be a subentity'); -define('_UNREACHABLE_DOCSERVER', 'Unreachable docserver path'); -define('_INCOMING', 'Arrival mail'); -define('_OUTGOING', 'Departure mail'); -define('_INTERNAL', 'Internal Mail'); -define('_ATTACHMENT', 'Attachment'); -define('_GED_DOC', 'GED Document'); -define('_UNCHANGED', 'Unchanged'); -define('_NO_PAGE', 'No page'); -define('_NO_KEYWORD', 'No keyword'); -define('_INDEXING', 'Indexing'); -define('_KEYWORD_REDIRECT_DESC', 'Permet de définir les options disponibles sur l\'action depuis la bannette, notamment les services et / ou les utilisateurs disponibles pour la redirection.'); -define('_KEYWORD_INDEXING_DESC', 'Permet de définir les options disponibles sur l\'action depuis la bannette, notamment les services traitant disponibles et le/les statut(s) potentiels pour un enregistrement / modification de document.'); -define('_SIMPLE_MAIL', 'Simple mail'); -define('_EMAIL', 'Email'); -define('_FAX', 'Fax'); -define('_CHRONOPOST', 'Chronopost'); -define('_FEDEX', 'Fedex'); -define('_REGISTERED_MAIL', 'registered letter with recorded delivery'); -define('_COURIER', 'Courier'); -define('_NUMERIC_PACKAGE', 'Numeric package'); -define('_OTHER', 'Other'); -define('_NOTIFICATION_ALREADY_EXIST', 'Notification already exists'); -define('_WRONG_PSW', 'Wrong password'); -define('_ALREADY_USED_PSW', 'The password has already been used'); -define('_BAD_LOGIN_OR_PSW', 'Wrong user name or wrong password'); -define('_ACCOUNT_LOCKED_FOR', 'Too many connections attemps. Your account is locked for'); -define('_ACCOUNT_LOCKED_UNTIL', 'Too many connections attemps. Account locked until'); -define('_MAX_SIZE_UPLOAD_REACHED', 'File maximum size is exceeded'); -define('_PATH_OF_DOCSERVER_UNAPPROACHABLE', 'Inaccessible Docserver path'); -define('_BACK_FROM_VACATION', 'back from vacation'); -define('_DOC_DISPLAYING', 'Displaying document'); -define('_DOC_ADDED', 'Document added'); -define('_ATTACH_DISPLAYING', 'Displaying attachment'); - -// LISTS -define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'List with filters and responses'); -define('_DOCUMENTS_LIST_WITH_AVIS', 'List of documents with recommendation'); -define('_DOCUMENTS_LIST_COPIES', 'List of copies'); -define('_CASES_LIST', 'Cases list'); -define('_DOCUMENTS_LIST_WITH_SIGNATORY', 'Documents list with signatory'); -define('_FOLDERS_LIST', 'folders list'); -define('_DOCTYPE_UPDATED', 'Document type updated'); -define('_DOCTYPE_ADDED', 'Document type added'); -define('_DOCTYPE_DELETED', 'Document type deleted'); - -// ADMINISTRATION -define('_USERS', 'Users'); -define('_ADMIN_USERS_DESC', 'Add, suspend or modify users profiles. Place the users in their affiliation groups and define their primary group.'); -define('_GROUPS', 'users groups'); -define('_ADMIN_GROUPS_DESC', "Ajouter, suspendre, ou modifier des groupes d'utilisateurs. Attribuer des privilèges ou des autorisations d'accès aux ressources."); -define('_ENTITIES', 'Entities'); -define('_MANAGE_ENTITIES_DESC', 'Manage your organization (poles,services, etc.). Also diffusion models and visa circuit linked to services.'); -define('_LISTMODELS_WORKFLOW', 'Workflow models'); -define('_MANAGE_LISTMODELS_WORKFLOW_DESC', "Manage avis and visa circuit models, which can be used in document."); -define('_DOCTYPES', 'File plan'); -define('_ADMIN_DOCTYPES_DESC', 'Define the intern layout of a file (file/ sub-file/ document type). For each, define the index list to enter, and their mandatory character for the file completeness.'); -define('_FILEPLANS', 'organizational file plan'); -define('_ADMIN_FILEPLANS_DESC', 'organizational file plan management (Allows to manage specific file plans to an entity).'); -define('_FOLDERTYPES', 'Types of folders'); -define('_ADMIN_FOLDERTYPES_DESC', "Administrate folder's types. For each type, define the linked qualifiers and the mandatory folder's types for the folder completeness."); -define('_TAGS', 'Tags'); -define('_ADMIN_TAGS_DESC', 'Allows to modify, erase, add or merge tags'); -define('_THESAURUS', 'Thesaurus (keywords)'); -define('_ADMIN_THESAURUS_DESC', "The thesaurus is a linguistic tool which allows to connect users' natural language and the language contained in the resources."); -define('_HISTORY', 'History'); -define('_ADMIN_HISTORY_DESC', 'Read batch history'); -define('_HISTORY_BATCH', 'Batch history'); -define('_ADMIN_HISTORY_BATCH_DESC', 'Read the events history linked to the utilisation of Maarch.'); -define('_UPDATE_STATUS_MAIL', 'Document status modification'); -define('_DOCSERVERS', 'Storage zones'); -define('_ADMIN_DOCSERVERS_DESC', 'Add, suspend or modify storage zones. Put the storage zones by kind of affiliations and define their primary group.'); -define('_PARAMETERS', 'Parameters'); -define('_UPDATE_CONTROL', 'Verify update'); -define('_ADMIN_UPDATE_CONTROL_DESC', 'Check new tags of Maarch Courrier and update application in latest tag.'); -define('_REPORTS', 'Statistiques'); -define('_ADMIN_REPORTS_DESC', 'States and editions administration'); -define('_STATUSES', 'Statuses'); -define('_ADMIN_STATUSES_DESC', 'Create or modify status.'); -define('_ACTIONS', 'Actions'); -define('_ADMIN_ACTIONS_DESC', 'Create or modify actions.'); -define('_CONTACTS', 'Contacts'); -define('_ADMIN_CONTACTS_DESC', 'Administration of contacts'); -define('_PRIORITIES', 'Priorities'); -define('_BASKETS', 'Baskets'); -define('_ADMIN_BASKETS_DESC', 'Define the baskets content and associate them to users groups.'); -define('_NOTIFICATIONS', 'Notifications'); -define('_ADMIN_NOTIFICATIONS_DESC', " Create and manage users' notifications based on application events"); -define('_TEMPLATES', 'Templates'); -define('_ADMIN_TEMPLATES_DESC', 'Manage templates for attachments, notifications, document generation, sendmail and notes'); -define('_SECURITIES', 'Securities'); - -//SERVICES -define('_REDIRECT_TO_ACTION', 'Redirect to an action'); -define('_ADMIN', 'Administration'); -define('_ADV_SEARCH_MLB', 'Search'); -define('_INDEXING_MLB', 'Save a mail/document'); -define('_SEARCH_CONTACTS', 'Search a contact'); -define('_PARAM_MLB_DOCTYPES', 'Documents types configuration '); -define('_PARAM_MLB_DOCTYPES_DESC', 'Doctypes configuration '); -define('_WELCOME_TEXT_LOAD', 'Text loading of the home page'); -define('_QUICKLAUNCH', 'Short cut'); -define('_MY_CONTACTS', 'Create contacts from indexation/title'); -define('_MY_CONTACTS_MENU', 'My contacts'); -define('_CREATE_CONTACTS', 'All the contacts'); -define('_UPDATE_CONTACTS', 'Contact update from indexation/ title'); -define('_VIEW_TECHNICAL_INFORMATIONS', 'See technical information'); -define('_VIEW_DOC_HISTORY', 'See global document history'); -define('_VIEW_HISTORY_DESC', 'Read the events history linked to the utilisation of Maarch.'); -define('_VIEW_FULL_HISTORY', 'See Full document history'); -define('_VIEW_FULL_HISTORY_DESC', 'Read the full events history linked to the utilisation of Maarch.'); -define('_DELETE_DOCUMENT_IN_DETAIL', 'Delete a document in detail page'); -define('_EDIT_DOCUMENT_IN_DETAIL', 'Edit a document in detail page'); -define('_EDIT_DOCUMENT_IN_DETAIL_DESC', 'Edit a document in detail page. Il will also depend on status setting (Index modification)'); -define('_PUT_DOC_ON_VALIDATION_FROM_DETAILS', 'Send the document for validation from the detailed page'); -define('_LOAD_STATUSES_SESSION', 'Load Status session'); -define('_PARAM_AVAILABLE_STATUS_ON_GROUP_BASKETS', 'Indexation status configuration'); -define('_ADD_LINKS', 'Add connection'); -define('_PRINT_DETAILS_SERVICE', 'Print the liaison sheet from the detail sheet'); -define('_PRINT_DOC_DETAILS_FROM_LIST', 'Print the liaison sheets from the results lists'); -define('_ATTACHMENTS_COMMENT', 'Attachments management'); -define('_BASKETS_COMMENT', 'Baskets'); -define('_CASES_COMMENT', 'Cases'); -define('_ENTITIES_COMMENT', 'Departments'); -define('_FILEPLAN_COMMENT', 'Organizational file plan'); -define('_FOLDERS_COMMENT', 'Folders'); -define('_FULL_TEXT', 'Full text'); -define('_NOTES_COMMENT', 'Notes'); -define('_NOTIFICATIONS_COMMENT', 'Notifications'); -define('_TEMPLATES_COMMENT', 'Templates'); -define('_REPORTS_COMMENT', 'States and editions'); -define('_LIFE_CYCLE_COMMENT', 'Life cycle management'); -define('_CONTENT_MANAGEMENT_COMMENT', 'Management of document versions'); -define('_TAGS_COMMENT', 'Tags'); -define('_SENDMAIL_COMMENT', 'Send emails'); -define('_THUMBNAILS_COMMENT', 'Unit of thumbnails'); -define('_VISA_WORKFLOW_COMMENT', 'Visa workflow management'); -define('_AVIS_WORKFLOW_COMMENT', 'recommendation workflow management'); -define('_THESAURUS_COMMENT', 'Thesaurus management'); -define('_EXPORT_SEDA_COMMENT', 'Export'); -define('_CONVERT_COMMENT', 'Conversions module'); -define('_VIEW_BASKETS', 'My baskets'); -define('_PRINT_SEPS', 'Limiters printing'); -define('_FILEPLAN_SHORT', 'File plan'); -define('_CREATE_FOLDER', 'Create a folder'); -define('_FOLDER_SEARCH', 'Search a folder'); -define('_VIEW_FOLDER_TREE', 'Read a folder'); -define('_SAVE_NUMERIC_PACKAGE', 'Save numeric package'); -define("_SELECT_FOLDER", "Folder selection"); -define("_FOLDER_HISTORY", "Folder's history"); -define("_MODIFY_FOLDER", "Modify folder's index"); -define("_ATTACH_DOC_TO_FOLDER", "Attach a document to a folder"); -define("_DELETE_FOLDER", "Delete a folder"); -define("_FREEZE_FOLDER", "Freeze the folder"); -define("_CLOSE_FOLDER", "Close the folder"); -define("_NOTES_RESTRICTION", "By default, limit the notes to your department"); -define('_MANAGE_NOTES', 'Manage notes'); -define('_REPORTS_DESC', 'States editions'); -define('_GRAPHICS_REPORTS', 'Graphics mode enabled'); -define('_GRAPHICS_REPORTS_DESC', 'Display graphical mode in reports'); -define("_USE_MAIL_SERVICES", "Use emails services as sender"); -define("_USE_MAIL_SERVICES_DESC", "Use emails services as sender"); -define("_TAG_DEFAULT", "Tag"); -define("_TAG_VIEW", "View the Tag of the documents"); -define("_TAG_VIEW_DESC", "Allows to view Tag"); -define("_CREATE_TAG", "Create Tag"); -define("_CREATE_TAG_DESC", "Allows to create Tag not existing in database"); -define("_ADD_TAG_TO_RES", "Associate the available Tag to a document"); -define("_ADD_TAG_TO_RES_DESC", "Allows to add Tag to a resource"); -define("_PRIVATE_TAGS", "Associate Tag to the user's entity (Direction level)"); -define("_PRIVATE_TAGS_DESC", "User will only see Tag restricted to user's direction (adding / updating will automatically associate the word to user's direction)."); -define("_THESAURUS_VIEW", "Display the thesaurus in the process pages"); -define("_THESAURUS_VIEW_DESC", "Be able to see the term(s) which are associated to different documents"); -define("_ADD_THESAURUS_TO_RES", "Be able to associate terms to different documents"); -define("_ADD_THESAURUS_TO_RES_DESC", "Allow to use thesaurus 's available terms to refer documents"); -define('_CONFIG_VISA_WORKFLOW', 'Visa workflow setting'); -define('_CONFIG_VISA_WORKFLOW_DESC', 'Allows to set up visa flow which the mail will have to follow'); -define('_CONFIG_VISA_WORKFLOW_IN_DETAIL', 'Visa workflow setting from detailed card'); -define('_CONFIG_VISA_WORKFLOW_IN_DETAIL_DESC', 'Allows to set up visa flow in detail'); -define('_VISA_ANSWERS', 'Aim the responses projects'); -define('_VISA_ANSWERS_DESC', 'Allows to aim response projects'); -define('_SIGN_DOCS', 'Sign the documents'); -define('_MODIFY_VISA_IN_SIGNATUREBOOK', 'Modify current visa user from signature book'); -define('_MODIFY_VISA_IN_SIGNATUREBOOK_DESC', 'Useful if signature book is used as a supervision signature book'); -define('_PRINT_FOLDER_DOC', 'Print the entire folder'); -define('_USE_DATE_IN_SIGNBLOCK', 'Add current date in sign block'); -define('_USE_DATE_IN_SIGNBLOCK_DESC', 'The current date is added in top of sign block (with the town if it wrote in parent entity of application).'); - -// ACTIONS -define('_REDIRECTION', 'Redirection'); -define('_REDIRECTION_DESC', 'Opens a modal to choose a new user processing OR to redefine the processing service with a new mailing list.'); -define('_REDIRECTION_VISA_SIGN', 'Redirection for signature'); -define('_PUT_IN_COPY', 'Add on copy'); -define('_PUT_IN_COPY_DESC', 'Opens a modal ONLY to add or delete COPY people from the mailing list.'); -define('_SIMPLE_CONFIRM', 'Simple confirmation'); -define('_SIMPLE_CONFIRM_DESC', "Simply open a modal of confirmation of the action to be performed."); -define('_PROCESS_ACTION', 'Traiter'); -define('_PROCESS_DESC', 'Opens the page for processing a document (metadata can not be modfied from this page).'); -define('_INDEX_FILE', 'Index a file'); -define('_INDEX_FILE_DESC', 'Opens the index page to create a document.'); -define('_VALIDATE_QUALIF', 'Validation / certification'); -define('_VALIDATE_QUALIF_DESC', 'Opens the edit page of a previously saved document (metadata can be edited from this page).'); -define('_VIEW_DOC', 'See the document'); -define('_VIEW_DOC_DESC', 'Opens a modal with the document in view. Also increments the \'viewed\' data of the listinstance table (useful if used in the bib clauses).'); -define('_CLOSE_MAIL', 'Close a mail'); -define('_CLOSE_MAIL_DESC', 'Allows you to update the closing date of a document (\'closing_date\' of the mlb_coll_ext table). ESSENTIAL in order to complete your document workflow.'); -define('_SET_PERSISTENT_MODE_ON', 'Activate the persistence'); -define('_SET_PERSISTENT_MODE_ON_DESC', 'Keeps a document in a basket regardless of its state. Insert data in the \'basket_persistent_mode\' table.'); -define('_SET_PERSISTENT_MODE_OFF', 'Deactivate the persistence'); -define('_SET_PERSISTENT_MODE_OFF_DESC', 'Resets the viewing behavior of the document in the basket. Remove data from the \'basket_persistent_mode\' table.'); -define('_MARK_AS_READ', 'Marked as read'); -define('_MARK_AS_READ_DESC', 'Mark the document as \'read\' in the basket. Insert the data in the \'res_mark_as_read\' table (useful if used in the basket clauses).'); -define('_SEND_FILE_WS', 'Send file via Web Service'); -define('_SEND_DATA_WS', 'Send data via Web Service'); -define('_SEND_TO_EXTERNAL_SB', 'Send data to external signature book'); -define('_CONFIRM_FOLDER_STATUS', '[folder] Confirm the folder status'); -define('_REDIRECT_FOLDER', '[folder] Redirect the folder'); -define('_CLOSE_MAIL_AND_INDEX', 'Close a mail and launch the indexation'); -define('_CLOSE_MAIL_AND_INDEX_DESC', 'Allows you to update the closing date of a document (\'closing_date\' of the mlb_coll_ext table) AND opens the indexing page to save a new document.'); -define('_CLOSE_MAIL_WITH_ATTACHMENT', 'Closing with attachment'); -define('_CLOSE_MAIL_WITH_ATTACHMENT_DESC', 'Allows you to update the closing date of a document (\'closing_date\' of the table mlb_coll_ext) with MANDATORY presence of attachment (s) / note (s).'); -define('_SEND_SIGNED_DOCS', 'Pass signed responses'); -define('_SEND_SIGNED_DOCS_DESC', 'Check if response project are signed.'); -define('_SEND_TO_VISA', 'send for visa'); -define('_SEND_TO_VISA_DESC', 'Check if visa circuit is setup AND if one or several responses project are linked to document.'); -define('_REJECTION_WORKFLOW_PREVIOUS', 'Visa rejection - back to the previous author'); -define('_REJECTION_WORKFLOW_PREVIOUS_DESC', 'Reset visa date of previous supervisor in visa circuit of document (\'process_date\' of listinstance table).'); -define('_REJECTION_WORKFLOW_REDACTOR', 'Visa rejection - back to the author'); -define('_REJECTION_WORKFLOW_REDACTOR_DESC', 'Reset visa date of all supervisor in visa circuit of document (\'process_date\' of listinstance table).'); -define('_REJECTION_WORKFLOW_ENTITY', 'Visa rejection - back to the initiator entity'); -define('_REJECTION_WORKFLOW_ENTITY_DESC', 'Reset visa date of all supervisor in visa circuit of document (\'process_date\' of listinstance table) and send it to the initiator entity.'); -define('_INTERRUPT_WORKFLOW', 'Break the visa flow'); -define('_INTERRUPT_WORKFLOW_DESC', 'Update visa date of current supervisor / signatory and all next supervisors in visa circuit of document (\'process_date\' of listinstance table). Insère également un message d\'interruption sur le viseur actuel (\'process_comment\' de la table listinstance).'); -define('_PROCEED_WORKFLOW', 'continue the visa flow'); -define('_PROCEED_WORKFLOW_DESC', 'Update visa date of current supervisor / signatory in visa circuit of document (\'process_date\' of listinstance table).'); -define('_VISA_MAIL', 'Aim the mail'); -define('_VISA_MAIL_DESC', 'Open signatory book to visa / sign the document.'); -define('_SEND_TO_CONTACT_WITH_MANDATORY_ATTACHMENT', 'Send to the contact with a mandatory attachment'); -define('_SEND_TO_CONTACT_WITH_MANDATORY_ATTACHMENT_DESC', 'Open sendmail modal with email of contact linked to document in recipient, attachment is MANDATORY.'); -define('_SEND_ATTACHMENTS_TO_CONTACT', 'Send to the contact'); -define('_SEND_ATTACHMENTS_TO_CONTACT_DESC', 'Open sendmail modal with email of contact linked to document in recipient.'); -define("_VIEW_ATTACHMENTS", "View attachments"); -define("_VIEW_ATTACHMENTS_DESC", "View attachments"); -define("_MANAGE_ATTACHMENTS", "Manage the attachments"); -define("_INDEX_ATTACHMENT", "Index an attachment"); -define("_INDEX_ATTACHMENT_DESC", "Index an attachment"); -define("_CREATE_ATTACHMENTS_FROM_DETAILS", "Create attachments from details card"); -define("_MODIFY_ATTACHMENTS", "Modify attachments"); -define("_DELETE_ATTACHMENTS", "Delete attachments"); -define('_CONFIG_AVIS_WORKFLOW', 'Recommendation flow configuration'); -define('_CONFIG_AVIS_WORKFLOW_DESC', 'Allow to set the mail recommendation flow up'); -define("_CONFIG_AVIS_WORKFLOW_IN_DETAIL", "Recommendation workflow setting from the detailed form"); -define("_CONFIG_AVIS_WORKFLOW_IN_DETAIL_DESC", "Allows to define the workflow directly from the mail detailed form"); -define("_AVIS_ANSWERS", "Give oneself's opinion"); -define("_AVIS_ANSWERS_DESC", "Allows to this group to appear in the counsellor's list (recommendation workflow)"); -define("_VIEW_BASKETS_DESC", "My baskets"); -define("_UPDATE_CASE", "Cases updates"); -define("_JOIN_RES_CASE", "Attach mails to cases"); -define("_JOIN_RES_CASE_IN_PROCESS", "Link mails to cases (handling basket)"); -define("_CLOSE_CASE", "Enclose cases"); -define("_ADD_CASES", "Create cases"); -define('_CHOOSE_ENTITY', 'Choose a department'); -define('_ADD_COPY_IN_PROCESS', 'Add persons on copy in the handling'); -define('_ADD_COPY_IN_INDEXING_VALIDATION', 'Forbid recipient modification on the diffusion list'); -define('_UPDATE_LIST_DIFF_IN_DETAILS', 'Update diffusion list from the detailed page'); -define('_ENTITIES_PRINT_SEP_MLB', 'Print limiters by department/services'); -define("_EXPORT_SEDA_VIEW", "See message export"); -define("_PUT_DOC_IN_FILEPLAN", "Classify documents"); -define("_PUT_DOC_IN_FILEPLAN_COMMENT", "Classify documents in the organizational file plan"); -define("_PERSONNAL_FILEPLAN", "Personal file plan"); -define("_SEND_DOCS_TO_RECOMMENDATION", "Sent a recommendation request (parallel)"); -define("_SEND_DOCS_TO_RECOMMENDATION_DESC", "Opens a modal to add or remove people to the opinion diffusion list."); -define("_VALIDATE_RECOMMENDATION", 'Validate the recommendation request (parallel)'); -define("_VALIDATE_RECOMMENDATION_DESC", "Allows you to add the person who checked the request to the application notice."); -define("_SEND_TO_AVIS_WF", 'Request for a recommendation (sequential)'); -define("_SEND_TO_AVIS_WF_DESC", "Opens a modal to configure a notification workflow for the document"); -define("_PROCEED_WORKFLOW_AVIS", 'Issue an opinion (sequential)'); -define("_PROCEED_WORKFLOW_AVIS_DESC", "Updates the date of issuance of advice from the current advisor of the advisory workflow ('process_date' of listinstance table)."); -define("_PROCEED_WORKFLOW_AVIS_SIMPLE", 'Issue an opinion (parallel)'); -define("_PROCEED_WORKFLOW_AVIS_SIMPLE_DESC", "Updates the notification date of the user present in the diffusion list of the document ('process_date' of listinstance table)."); -define('_EXPORT_SEDA', 'Transfer your mails'); -define('_CHECK_ACKNOWLEDGEMENT', 'Check acknowledgement'); -define('_CHECK_REPLY', 'Check reply'); -define('_PURGE_LETTER', 'Purge the mail after archiving'); -define('_RESET_LETTER', 'Reset workflow'); -define('_SIMPLE_CONFIRM_WITH_UPDATE_DATE', 'Confirm and update departure date'); - -// REPORTS -define('_FOLDER_VIEW_STAT', 'Number of read folders'); -define('_ENTITY_VOL_STAT', 'Mails volume by department'); -define('_ENTITY_VOL_STAT_DESC', 'Mails volume by department'); -define('_RESPONSE_RATE_BY_ENTITIES', 'Response rate by entity'); -define('_RESPONSE_RATE_BY_ENTITIES_DESC', 'Displays the percentage of mail that has been answered. This statistic is based on the number of letters from which a departure date has been entered (use the field departure_date)'); -define('_ENTITY_LATE_MAIL', 'Late mail volume by department'); -define('_ENTITY_PROCESS_DELAY', 'Medium handling time by department'); -define('_USERS_LOGS', 'Access list to the application by agent'); -define('_PROCESS_DELAY_REPORT', 'Average process period by mail type'); -define('_PROCESS_DELAY_REPORT_DESC', 'Average process period by mail type'); -define('_PROCESS_DELAY_GENERIC_EVALUATION_REPORT', 'Handling medium time'); -define('_PROCESS_DELAY_GENERIC_EVALUATION_REPORT_DESC', 'Displays the time (in days) of the creation until the closing of a mail.'); -define('_MAIL_TYPOLOGY_REPORT', 'Mails typology by period'); -define('_MAIL_TYPOLOGY_REPORT_DESC', 'Mails typology by period'); -define('_MAIL_VOL_BY_CAT_REPORT', 'Mails volume by category, by period'); -define('_MAIL_VOL_BY_CAT_REPORT_DESC', 'Mails volume by category, by period'); - -//ATTACHMENT TYPES -define("_RESPONSE_PROJECT", "Response project"); -define("_SIGNED_RESPONSE", "Signed response"); -define("_OUTGOING_MAIL_SIGNED", "Signed start date"); -define("_A_PJ", "Attachment"); -define("_INCOMING_PJ", "Incoming attachment"); -define("_WAYBILL", "Mailing slip"); -define("_ROUTING", "Flow slip"); -define("_OUTGOING_MAIL", "Spontaneous start mail"); -define("_CONVERTED_PDF", "Converted PDF by the solution"); -define('_PRINT_FOLDER', 'Folder'); -define('_SVA', 'SVA'); -define('_SVR', 'SVR'); +define('_EX', 'Ex'); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index 1740ef5df8..68ada70212 100644 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -12,407 +12,4 @@ * @author dev@maarch.org */ -define('_ACTION_ADDED', 'Action ajoutée'); -define('_ACTION_DELETED', 'Action supprimée'); -define('_ACTION_UPDATED', 'Action modifiée'); -define('_ADD_NOTIFICATIONS', 'Notification créée'); -define('_ALREADY_EXISTS', 'existe déjà '); -define('_AVIS_USER', 'Pour avis'); -define('_AVIS_USER_COPY', 'En copie (avis)'); -define('_AVIS_USER_INFO', 'Pour information (avis)'); -define('_BASKET_CREATION', 'Création bannette'); -define('_BASKET_GROUP_CREATION', 'Groupe ajouté pour bannette'); -define('_BASKET_GROUP_MODIFICATION', 'Groupe modifié pour bannette'); -define('_BASKET_GROUP_SUPPRESSION', 'Groupe supprimé pour bannette'); -define('_BASKET_MODIFICATION', 'Modification bannette'); -define('_BASKET_SUPPRESSION', 'Suppression bannette'); -define('_BASKET_REDIRECTION', 'Redirection bannette'); -define('_BASKET_REDIRECTION_SUPPRESSION', 'Suppression redirection bannette'); -define('_BASKETS_SORT_MODIFICATION', 'Modification ordre bannettes'); -define('_BY_DEFAULT', 'par défaut'); -define('_CONTACTS_GROUP_ADDED', 'Groupe de contacts ajouté'); -define('_CONTACTS_GROUP_UPDATED', 'Groupe de contacts modifié'); -define('_CONTACTS_GROUP_DELETED', 'Groupe de contacts supprimé'); -define('_CONTACTS_GROUP_LIST_ADDED', 'Ajout de contacts dans le groupe'); -define('_CONTACTS_GROUP_LIST_DELETED', 'Suppression de contacts dans le groupe'); -define('_CONTACTS_GROUP_LABEL_ALREADY_EXISTS', 'Un groupe avec ce libellé existe déjà '); -define('_DELETE_NOTIFICATIONS', 'Notification supprimée'); -define('_DEST_USER', 'Destinataire'); -define('_DOCSERVER_ADDED', 'Zone de stockage ajoutée'); -define('_DOCSERVER_UPDATED', 'Zone de stockage modifiée'); -define('_DOCSERVER_DELETED', 'Zone de stockage supprimée'); -define('_DOCSERVER_ACTIVATED_EXISTS', 'Une zone de stockage avec le même type et la même collection est déjà activée'); -define('_DOCTYPE_FIRSTLEVEL_ADDED', 'Chemise ajoutée'); -define('_DOCTYPE_FIRSTLEVEL_DELETED', 'Chemise supprimée'); -define('_DOCTYPE_FIRSTLEVEL_UPDATED', 'Chemise modifiée'); -define('_DOCTYPE_SECONDLEVEL_ADDED', 'Sous-chemise ajoutée'); -define('_DOCTYPE_SECONDLEVEL_DELETED', 'Sous-chemise supprimée'); -define('_DOCTYPE_SECONDLEVEL_UPDATED', 'Sous-chemise modifiée'); -define('_DOCUMENT_NOT_FOUND', 'Document introuvable'); -define('_ENTITY_CREATION', 'Création entité'); -define('_ENTITY_MODIFICATION', 'Modification entité'); -define('_ENTITY_SUPPRESSION', 'Suppression entité'); -define('_ENTITY_ID_ALREADY_EXISTS', 'Cette entité existe déjà '); -define('_ID', 'Identifiant'); -define('_ID_TO_DISPLAY', 'res_id'); -define('_INVALID_CLAUSE', 'Clause non valide'); -define('_INVALID_REQUEST', 'Requête non valide'); -define('_LIST_TEMPLATE_CREATION', 'Création liste de diffusion'); -define('_LIST_TEMPLATE_MODIFICATION', 'Modification liste de diffusion'); -define('_LIST_TEMPLATE_SUPPRESSION', 'Suppression liste de diffusion'); -define('_MODIFY_NOTIFICATIONS', 'Notification modifiée'); -define('_MODIFY_STATUS', 'Statut modifié'); -define('_NOTIFICATION_SCHEDULE_UPDATED', 'La planification des notifications a été mise à jour'); -define('_NOTIFICATION_SCRIPT_ADDED', 'Le script de la notification a été créé'); -define('_PARAMETER_CREATION', 'Création paramètre'); -define('_PARAMETER_MODIFICATION', 'Modification paramètre'); -define('_PARAMETER_SUPPRESSION', 'Suppression paramètre'); -define('_PARAMETER_ID_ALREADY_EXISTS', 'Ce paramètre existe déjà '); -define('_PASSWORD_RULES_UPDATED', 'Règles de mot de passe modifiées'); -define('_PRIORITY_CREATION', 'Création priorité'); -define('_PRIORITY_MODIFICATION', 'Modification priorité'); -define('_PRIORITY_SUPPRESSION', 'Suppression priorité'); -define('_PRIORITY_SORT_MODIFICATION', 'Modification ordre priorités'); -define('_QUOTA_EXCEEDED', 'Quota dépassé'); -define('_REPORT_MODIFICATION', 'Modification états et édition'); -define('_STATUS_ADDED', 'Statut ajouté'); -define('_STATUS_DELETED', 'Statut supprimé'); -define('_STATUS_NOT_FOUND', 'Statut introuvable'); -define('_TEMPLATE_ADDED', 'Modèle de document ajouté'); -define('_TEMPLATE_UPDATED', 'Modèle de document modifié'); -define('_TEMPLATE_DELETED', 'Modèle de document supprimé'); -define('_TO_CC', 'En copie'); -define('_TO_SIGN', 'Pour signature'); -define('_UPDATE_STATUS', 'Modification du statut'); -define('_USER_ID_ALREADY_EXISTS', 'L\'identifiant utilisateur existe déjà '); -define('_USER_CREATED', 'Utilisateur ajouté'); -define('_USER_UPDATED', 'Utilisateur modifié'); -define('_USER_DELETED', 'Utilisateur supprimé'); -define('_USER_GROUP_CREATION', 'Groupe ajouté pour utilisateur'); -define('_USER_GROUP_MODIFICATION', 'Groupe modifié pour utilisateur'); -define('_USER_GROUP_SUPPRESSION', 'Groupe supprimé pour utilisateur'); -define('_USER_ENTITY_CREATION', 'Entité ajoutée pour utilisateur'); -define('_USER_ENTITY_MODIFICATION', 'Entité modifiée pour utilisateur'); -define('_USER_ENTITY_SUPPRESSION', 'Entité supprimée pour utilisateur'); -define('_USER_ALREADY_LINK_GROUP', 'L\'utilisateur est déjà lié à ce groupe'); -define('_USER_ALREADY_LINK_ENTITY', 'L\'utilisateur est déjà lié à cette entité'); -define('_VISA_USER', 'Pour visa'); -define('_WRONG_FILE_TYPE', 'Ce type de fichier n\'est pas permis'); -define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'L\'entité parente ne doit pas être dans une entité fille'); -define('_UNREACHABLE_DOCSERVER', 'Chemin docserver inatteignable'); -define('_INCOMING', 'Courrier Arrivée'); -define('_OUTGOING', 'Courrier Départ'); -define('_INTERNAL', 'Courrier Interne'); -define('_ATTACHMENT', 'Pièce jointe'); -define('_GED_DOC', 'Document GED'); -define('_UNCHANGED', 'Inchangé'); -define('_NO_PAGE', 'Aucune page'); -define('_NO_KEYWORD', 'Aucun mot clé'); -define('_INDEXING', 'Indexation'); -define('_KEYWORD_REDIRECT_DESC', 'Permet de définir les options disponibles sur l\'action depuis la bannette, notamment les services et / ou les utilisateurs disponibles pour la redirection.'); -define('_KEYWORD_INDEXING_DESC', 'Permet de définir les options disponibles sur l\'action depuis la bannette, notamment les services traitant disponibles et le/les statut(s) potentiels pour un enregistrement / modification de document.'); -define('_SIMPLE_MAIL', 'Courrier simple'); -define('_EMAIL', 'Courriel'); -define('_FAX', 'Fax'); -define('_CHRONOPOST', 'Chronopost'); -define('_FEDEX', 'Fedex'); -define('_REGISTERED_MAIL', 'Courrier AR'); -define('_COURIER', 'Coursier'); -define('_NUMERIC_PACKAGE', 'Pli numérique'); -define('_OTHER', 'Autre'); -define('_NOTIFICATION_ALREADY_EXIST', 'Notification déjà existante'); -define('_WRONG_PSW', 'Le mot de passe actuel n\'est pas correct'); -define('_ALREADY_USED_PSW', 'Le mot de passe a déjà été utilisé'); -define('_BAD_LOGIN_OR_PSW', 'Mauvais nom d\'utilisateur ou mauvais mot de passe'); -define('_ACCOUNT_LOCKED_FOR', 'Nombre de tentatives de connexion dépassée. Votre compte est vérouillé pendant'); -define('_ACCOUNT_LOCKED_UNTIL', 'Nombre de tentatives de connexion dépassée. Compte vérouillé jusqu\'au'); -define('_MAX_SIZE_UPLOAD_REACHED', 'Taille maximum de fichier dépassée'); -define('_PATH_OF_DOCSERVER_UNAPPROACHABLE', 'Chemin de la zone de stockage inaccessible'); -define('_BACK_FROM_VACATION', 'de retour de son absence'); -define('_DOC_DISPLAYING', 'Visualisation du document'); -define('_DOC_ADDED', 'Document ajouté'); -define('_ATTACH_DISPLAYING', 'Visualisation de la pièce jointe'); - -// LISTS -define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'Liste avec filtres et réponses'); -define('_DOCUMENTS_LIST_WITH_AVIS', 'Liste des documents avec avis'); -define('_DOCUMENTS_LIST_COPIES', 'Liste des copies'); -define('_CASES_LIST', 'Liste des affaires'); -define('_DOCUMENTS_LIST_WITH_SIGNATORY', 'Liste des documents avec signataire'); -define('_FOLDERS_LIST', 'Liste de dossiers'); -define('_DOCTYPE_UPDATED', 'Type de document modifié'); -define('_DOCTYPE_ADDED', 'Type de document ajouté'); -define('_DOCTYPE_DELETED', 'Type de document supprimé'); - -// ADMINISTRATION -define('_USERS', 'Utilisateurs'); -define('_ADMIN_USERS_DESC', "Ajouter, suspendre, ou modifier des profils utilisateurs. Placer les utilisateurs dans leurs groupes d'appartenance et définir leur groupe primaire."); -define('_GROUPS', 'Groupes d\'utilisateurs'); -define('_ADMIN_GROUPS_DESC', "Ajouter, suspendre, ou modifier des groupes d'utilisateurs. Attribuer des privilèges ou des autorisations d'accès aux ressources."); -define('_ENTITIES', 'Entités'); -define('_MANAGE_ENTITIES_DESC', 'Gérer la structure de votre organisation (pôles, services et bureaux). Ainsi que les modèles de diffusion et circuits de visa associés aux entités.'); -define('_LISTMODELS_WORKFLOW', 'Modèles de circuit'); -define('_MANAGE_LISTMODELS_WORKFLOW_DESC', "Gérer les modèles de circuits d'avis et de visa pouvant être utilisés dans un courrier."); -define('_DOCTYPES', 'Typologies documentaires'); -define('_ADMIN_DOCTYPES_DESC', "Définir la structure interne d'un dossier (chemise / sous-chemise / type de document). Définir pour chaque pièce la liste des index à saisir, et leur caractère obligatoire pour la complétude du dossier."); -define('_FILEPLANS', 'Plans de classement organisationnel'); -define('_ADMIN_FILEPLANS_DESC', 'Gestions du plan de classement organisationnel (Permet de gérer des plans spécifiques à une entité).'); -define('_FOLDERTYPES', 'Types de dossier'); -define('_ADMIN_FOLDERTYPES_DESC', 'Administrer les types de dossier. Définir pour chaque type les qualificateurs liés et les types de documents obligatoires pour la complétude du dossier.'); -define('_TAGS', 'Mots-clés'); -define('_ADMIN_TAGS_DESC', "Permet de modifier, supprimer, ajouter ou fusionner des mots-clés depuis l'interface d'administration"); -define('_THESAURUS', 'Thesaurus (Mots-clés)'); -define('_ADMIN_THESAURUS_DESC', 'Le thésaurus est un outil linguistique qui permet de mettre en relation le langage naturel des utilisateurs et celui contenu dans les ressources.'); -define('_HISTORY', 'Historique'); -define('_ADMIN_HISTORY_DESC', "Consulter l'historique des événements relatifs à l'utilisation de Maarch Courrier."); -define('_HISTORY_BATCH', 'Historique des batchs'); -define('_ADMIN_HISTORY_BATCH_DESC', "Consulter l'historique des batchs"); -define('_UPDATE_STATUS_MAIL', 'Changement de statut de courrier'); -define('_DOCSERVERS', 'Zones de stockage'); -define('_ADMIN_DOCSERVERS_DESC', "Ajouter, suspendre, ou modifier des zones de stockage. Placer les zones de stockages par type d'appartenance et définir leur groupe primaire."); -define('_PARAMETERS', 'Paramètres'); -define('_UPDATE_CONTROL', 'Vérification de mise à jour'); -define('_ADMIN_UPDATE_CONTROL_DESC', 'Voir les nouveaux tags de Maarch Courrier et mettre à jour l\'application au dernier tag si besoin.'); -define('_REPORTS', 'Statistiques'); -define('_ADMIN_REPORTS_DESC', 'Administration des statistiques'); -define('_STATUSES', 'Statuts'); -define('_ADMIN_STATUSES_DESC', 'Créer ou modifier des statuts.'); -define('_ACTIONS', 'Actions'); -define('_ADMIN_ACTIONS_DESC', 'Créer ou modifier des actions.'); -define('_CONTACTS', 'Contacts'); -define('_ADMIN_CONTACTS_DESC', 'Administration des contacts'); -define('_PRIORITIES', 'Priorités'); -define('_BASKETS', 'Bannettes'); -define('_ADMIN_BASKETS_DESC', "Définir le contenu des bannettes et les affecter à des groupes d'utilisateurs. Enumérer les redirections possibles lors de l'utilisation de la bannette par un groupe donné. Attribuer un format d'affichage de la bannette par ce groupe."); -define('_NOTIFICATIONS', 'Notifications'); -define('_ADMIN_NOTIFICATIONS_DESC', "Créer et gérer des notifications aux utilisateurs basées sur des événements de l'application"); -define('_TEMPLATES', 'Modèles de documents'); -define('_ADMIN_TEMPLATES_DESC', "Gérer les modèles utilisés pour les pièces jointes, les notifications, la génération de courriers, l'envoi de courriels et les annotations"); -define('_SECURITIES', 'Sécurités'); - -//SERVICES -define('_REDIRECT_TO_ACTION', 'Rediriger vers une action'); -define('_ADMIN', 'Administration'); -define('_ADV_SEARCH_MLB', 'Rechercher'); -define('_INDEXING_MLB', 'Enregistrer un courrier/doc'); -define('_SEARCH_CONTACTS', 'Rechercher un contact'); -define('_PARAM_MLB_DOCTYPES', 'Paramétrage des types de document '); -define('_PARAM_MLB_DOCTYPES_DESC', 'Paramétrage des types de document '); -define('_WELCOME_TEXT_LOAD', "Chargement texte page d'accueil"); -define('_QUICKLAUNCH', 'Raccourcis'); -define('_MY_CONTACTS', 'Créer des contacts depuis indexation/qualification'); -define('_MY_CONTACTS_MENU', 'Mes contacts'); -define('_CREATE_CONTACTS', 'Tous les contacts'); -define('_UPDATE_CONTACTS', 'Mise à jour contact depuis indexation/qualification'); -define('_VIEW_TECHNICAL_INFORMATIONS', 'Voir les informations techniques'); -define('_VIEW_DOC_HISTORY', "Voir l'historique des actions sur le document"); -define('_VIEW_HISTORY_DESC', "Consulter l'historique des événements relatifs à l'utilisation de Maarch Courrier."); -define('_VIEW_FULL_HISTORY', "Voir l'historique complet du document"); -define('_VIEW_FULL_HISTORY_DESC', "Consulter l'historique complet des événements relatifs à l'utilisation de la GED Maarch."); -define('_DELETE_DOCUMENT_IN_DETAIL', 'Supprimer un document dans la fiche détaillée'); -define('_EDIT_DOCUMENT_IN_DETAIL', 'Modifier un document dans la fiche détaillée'); -define('_EDIT_DOCUMENT_IN_DETAIL_DESC', 'Modifier un document dans la fiche détaillée. Cela dépendra aussi du paramétrage du statut (Modification des index)'); -define('_PUT_DOC_ON_VALIDATION_FROM_DETAILS', 'Envoyer le document en validation depuis la page détails'); -define('_LOAD_STATUSES_SESSION', 'Chargement des status en session'); -define('_PARAM_AVAILABLE_STATUS_ON_GROUP_BASKETS', "Paramétrage des status d'indexation"); -define('_ADD_LINKS', 'Ajouter des liaisons'); -define('_PRINT_DETAILS_SERVICE', 'Imprimer la fiche de liaison depuis la fiche détail'); -define('_PRINT_DOC_DETAILS_FROM_LIST', 'Imprimer les fiches de liaison depuis les listes de résultats'); -define('_ATTACHMENTS_COMMENT', 'Gestion des pièces jointes'); -define('_BASKETS_COMMENT', 'Bannettes'); -define('_CASES_COMMENT', 'Affaires'); -define('_ENTITIES_COMMENT', 'Entités'); -define('_FILEPLAN_COMMENT', 'Plan de classement organisationnel'); -define('_FOLDERS_COMMENT', 'Dossiers'); -define('_FULL_TEXT', 'Plein texte'); -define('_NOTES_COMMENT', 'Annotations'); -define('_NOTIFICATIONS_COMMENT', 'Notifications'); -define('_TEMPLATES_COMMENT', 'Modèles de document'); -define('_REPORTS_COMMENT', 'Statistiques'); -define('_LIFE_CYCLE_COMMENT', 'Gestion du cycle de vie'); -define('_CONTENT_MANAGEMENT_COMMENT', 'Gestion des Versions de document'); -define('_TAGS_COMMENT', 'Mots-clés'); -define('_SENDMAIL_COMMENT', 'Envoi de courriels'); -define('_THUMBNAILS_COMMENT', 'Module des miniatures'); -define('_VISA_WORKFLOW_COMMENT', 'Gestion du circuit de visa'); -define('_AVIS_WORKFLOW_COMMENT', "Gestion du circuit d'avis"); -define('_THESAURUS_COMMENT', 'Gestion du thesaurus'); -define('_EXPORT_SEDA_COMMENT', 'Export'); -define('_CONVERT_COMMENT', 'Module de conversions'); -define('_VIEW_BASKETS', 'Mes bannettes'); -define('_PRINT_SEPS', 'Impression des séparateurs'); -define('_FILEPLAN_SHORT', 'Plan de classement'); -define('_CREATE_FOLDER', 'Créer un dossier'); -define('_FOLDER_SEARCH', 'Rechercher un dossier'); -define('_VIEW_FOLDER_TREE', 'Consulter un dossier'); -define('_SAVE_NUMERIC_PACKAGE', 'Enregistrer un pli numérique'); -define("_SELECT_FOLDER", "Sélection Dossier"); -define("_FOLDER_HISTORY", "Historique dossier"); -define("_MODIFY_FOLDER", "Modifier les index d'un dossier"); -define("_ATTACH_DOC_TO_FOLDER", "Rattacher un document à un dossier"); -define("_DELETE_FOLDER", "Supprimer un dossier"); -define("_FREEZE_FOLDER", "Geler le dossier"); -define("_CLOSE_FOLDER", "Clôturer le dossier"); -define("_NOTES_RESTRICTION", "Restreindre par défaut les annotations à votre entité"); -define("_MANAGE_NOTES", "Gérer les annotations"); -define('_REPORTS_DESC', 'Editions des états'); -define('_GRAPHICS_REPORTS', 'Activer l\'affichage graphique'); -define('_GRAPHICS_REPORTS_DESC', 'Voir le graphique sur l\'écran de statistique'); -define("_USE_MAIL_SERVICES", "Utiliser les courriels de ses services en tant qu'expéditeur"); -define("_USE_MAIL_SERVICES_DESC", "Utiliser les courriels de ses services en tant qu'expéditeur"); -define("_TAG_DEFAULT", "Mot-clé"); -define("_TAG_VIEW", "Voir les Mots-clé des documents"); -define("_TAG_VIEW_DESC", "Permet d'afficher le champ Mot-clé depuis les pages d'actions et fiche détaillée."); -define("_CREATE_TAG", "Créer des Mots-clé depuis les pages d'actions"); -define("_CREATE_TAG_DESC", "Permet d'enregistrer à la volée des Mots-clé inexistants dans la base de données"); -define("_ADD_TAG_TO_RES", "Associer des Mots-clé disponibles pour un document"); -define("_ADD_TAG_TO_RES_DESC", "Permet d'associer des Mots-clé à un document grâce au champ Mot-clé depuis les pages d'actions et fiche détaillée"); -define("_PRIVATE_TAGS", "Lier les Mots-clé à l'entité de l'utilisateur (Niveau direction)"); -define("_PRIVATE_TAGS_DESC", "L'utilisateur ne verra que les Mots-clé qui ont été restreints à sa direction (l'ajout / modification associera le mot clé automatiquement à sa direction)."); -define("_THESAURUS_VIEW", "Afficher le thésaurus dans les pages de traitement"); -define("_THESAURUS_VIEW_DESC", "Permet de voir le(s) terme(s) qui sont associés aux différents documents"); -define("_ADD_THESAURUS_TO_RES", "Pouvoir associer des termes aux différents documents"); -define("_ADD_THESAURUS_TO_RES_DESC", "Permet de pouvoir utiliser les termes disponibles du thésaurus afin de référencer les documents"); -define('_CONFIG_VISA_WORKFLOW', 'Configuration du circuit de visa'); -define('_CONFIG_VISA_WORKFLOW_DESC', 'Permet de configurer le circuit de visa que devra prendre le courrier'); -define('_CONFIG_VISA_WORKFLOW_IN_DETAIL', 'Configuration du circuit de visa depuis la fiche détaillée'); -define('_CONFIG_VISA_WORKFLOW_IN_DETAIL_DESC', 'Permet de configurer le circuit de visa depuis la fiche détaillée'); -define('_VISA_ANSWERS', 'Viser les projets de réponse'); -define('_VISA_ANSWERS_DESC', 'Permet de viser les projets de réponse'); -define('_SIGN_DOCS', 'Signer les documents'); -define('_MODIFY_VISA_IN_SIGNATUREBOOK', 'Modifier le viseur en cours depuis le parapheur'); -define('_MODIFY_VISA_IN_SIGNATUREBOOK_DESC', 'Utile si le parahpeur sert en tant que parapheur de supervision'); -define('_PRINT_FOLDER_DOC', 'Imprimer le dossier complet'); -define('_USE_DATE_IN_SIGNBLOCK', 'Inclure la date dans la griffe de signature'); -define('_USE_DATE_IN_SIGNBLOCK_DESC', "La date de signature aparaîtra en haut de la griffe de signature (avec la ville si celle-ci a été inscrite dans le service racine de l'application)."); - -// ACTIONS -define('_REDIRECTION', 'Rediriger'); -define('_REDIRECTION_DESC', 'Ouvre une modal permettant de choisir un nouvel utilisateur traitant OU de redéfinir le service traitant avec une nouvelle liste de diffusion.'); -define('_REDIRECTION_VISA_SIGN', 'Rediriger pour signature'); -define('_PUT_IN_COPY', 'Ajouter en copie'); -define('_PUT_IN_COPY_DESC', "Ouvre une modal permettant UNIQUEMENT d'ajouter ou de supprimer des personne en COPIE de la liste de diffusion."); -define('_SIMPLE_CONFIRM', 'Confirmation simple'); -define('_SIMPLE_CONFIRM_DESC', "Ouvre simplement une modal de confirmation de l'action à effetuer."); -define('_PROCESS_ACTION', 'Traiter'); -define('_PROCESS_DESC', 'Ouvre la page de traitement d\'un document (les métas-données ne peuvent être modfiées depuis cette page).'); -define('_INDEX_FILE', 'Indexer un fichier'); -define('_INDEX_FILE_DESC', 'Ouvre la page d\'indexation afin d\'enregistrer un document.'); -define('_VALIDATE_QUALIF', 'Valider/Qualifier'); -define('_VALIDATE_QUALIF_DESC', 'Ouvre la page de modification d\'un document déjà enregistré (les métas-données peuvent être modifiées depuis cette page).'); -define('_VIEW_DOC', 'Voir le document'); -define('_VIEW_DOC_DESC', 'Ouvre une modal avec le document en visualisation. Incrémente également la donnée \'viewed\' de la table listinstance (utile si utilisée dans les clauses de bannettes).'); -define('_CLOSE_MAIL', 'Clôturer un courrier'); -define('_CLOSE_MAIL_DESC', 'Permet de mettre à jour la date de clôture d\'un document (\'closing_date\' de la table mlb_coll_ext). ESSENTIEL afin de terminer votre workflow de document.'); -define('_SET_PERSISTENT_MODE_ON', 'Activer la persistance'); -define('_SET_PERSISTENT_MODE_ON_DESC', 'Permet de conserver un document dans une bannette quelque soit son état. Insère la donnée dans la table \'basket_persistent_mode\'.'); -define('_SET_PERSISTENT_MODE_OFF', 'Désactiver la persistance'); -define('_SET_PERSISTENT_MODE_OFF_DESC', 'Réinitialise le comportement de visualisation du document dans la bannette. Supprime la donnée dans la table \'basket_persistent_mode\'.'); -define('_MARK_AS_READ', 'Marquer comme lu'); -define('_MARK_AS_READ_DESC', 'Marque le document comme \'lu\' dans la bannette. Insère la donnée dans la table \'res_mark_as_read\' (utile si utilisée dans les clauses de bannettes).'); -define('_SEND_FILE_WS', 'Envoyer le document via Web Service'); -define('_SEND_DATA_WS', 'Envoyer des données via Web Service'); -define('_SEND_TO_EXTERNAL_SB', 'Envoyer des données vers un parapheur externe'); -define('_CONFIRM_FOLDER_STATUS', '[dossier] Confirmer le statut du dossier'); -define('_REDIRECT_FOLDER', '[dossier] Rediriger le dossier'); -define('_CLOSE_MAIL_AND_INDEX', 'Clôturer un courrier et lancer l\'indexation'); -define('_CLOSE_MAIL_AND_INDEX_DESC', 'Permet de mettre à jour la date de clôture d\'un document (\'closing_date\' de la table mlb_coll_ext) ET ouvre la page d\'indexation afin d\'enregistrer un nouveau document.'); -define('_CLOSE_MAIL_WITH_ATTACHMENT', 'Clôturer un courrier avec pièce jointe'); -define('_CLOSE_MAIL_WITH_ATTACHMENT_DESC', 'Permet de mettre à jour la date de clôture d\'un document (\'closing_date\' de la table mlb_coll_ext) avec présence OBLIGATOIRE de pièce(s) jointe(s) / annotation(s).'); -define('_SEND_SIGNED_DOCS', 'Transmettre réponses signées'); -define('_SEND_SIGNED_DOCS_DESC', 'Vérifie si les projets de réponse ont été signés.'); -define('_SEND_TO_VISA', 'Envoyer pour visa'); -define('_SEND_TO_VISA_DESC', 'Contrôle si un circuit de visa est configuré ET si un ou plusieurs projets de réponses sont associés au document.'); -define('_REJECTION_WORKFLOW_PREVIOUS', 'Refuser le visa - retour au précédent viseur'); -define('_REJECTION_WORKFLOW_PREVIOUS_DESC', 'Réinitialise la date de visa du précédent viseur présent dans le circuit de visa du document (\'process_date\' de la table listinstance).'); -define('_REJECTION_WORKFLOW_REDACTOR', 'Refuser le visa - retour rédacteur'); -define('_REJECTION_WORKFLOW_REDACTOR_DESC', 'Réinitialise la date de visa de tous les viseurs présents dans le circuit de visa du document (\'process_date\' de la table listinstance).'); -define('_REJECTION_WORKFLOW_ENTITY', 'Refuser le visa - retour à l\'entité initiatrice'); -define('_REJECTION_WORKFLOW_ENTITY_DESC', 'Réinitialise la date de visa de tous les viseurs présents dans le circuit de visa du document (\'process_date\' de la table listinstance) et le renvoit à l\'entité initiatrice.'); -define('_INTERRUPT_WORKFLOW', 'Interrompre le circuit de visa'); -define('_INTERRUPT_WORKFLOW_DESC', 'Met à jour la date du visa de l\'actuel viseur / signataire et de tous les viseurs suivant présents dans le circuit de visa du document (\'process_date\' de la table listinstance). Insère également un message d\'interruption sur le viseur actuel (\'process_comment\' de la table listinstance).'); -define('_PROCEED_WORKFLOW', 'Poursuivre le circuit de visa'); -define('_PROCEED_WORKFLOW_DESC', 'Met à jour la date du visa de l\'actuel viseur / signataire présent dans le circuit de visa du document (\'process_date\' de la table listinstance).'); -define('_VISA_MAIL', 'Viser le courrier'); -define('_VISA_MAIL_DESC', 'Ouvre la page du parapheur afin de pouvoir viser / signer le document.'); -define('_SEND_TO_CONTACT_WITH_MANDATORY_ATTACHMENT', 'Envoyer au contact avec une pièce jointe obligatoire'); -define('_SEND_TO_CONTACT_WITH_MANDATORY_ATTACHMENT_DESC', "Ouvre une modal d'envoi de mail avec l'email du contact associé au document en tant que destinataire, présence OBLIGATOIRE de pièce(s) jointe(s) à l'envoi."); -define('_SEND_ATTACHMENTS_TO_CONTACT', 'Envoyer au contact'); -define('_SEND_ATTACHMENTS_TO_CONTACT_DESC', "Ouvre une modal d'envoi de mail avec l'email du contact associé au document en tant que destinataire."); -define("_VIEW_ATTACHMENTS", "Voir les pièces jointes"); -define("_VIEW_ATTACHMENTS_DESC", "Voir les pièces jointes"); -define("_MANAGE_ATTACHMENTS", "Gérer les pièces jointes"); -define("_INDEX_ATTACHMENT", "Indexer une pièce jointe"); -define("_INDEX_ATTACHMENT_DESC", "Indexer une pièce jointe"); -define("_CREATE_ATTACHMENTS_FROM_DETAILS", "Créer des pièces jointes depuis la fiche détail"); -define("_MODIFY_ATTACHMENTS", "Modifier les pièces jointes"); -define("_DELETE_ATTACHMENTS", "Supprimer les pièces jointes"); -define('_CONFIG_AVIS_WORKFLOW', "Configuration du circuit d'avis"); -define('_CONFIG_AVIS_WORKFLOW_DESC', "Permet de configurer le circuit d'avis du courrier"); -define("_CONFIG_AVIS_WORKFLOW_IN_DETAIL", "Configuration du circuit d'avis depuis la fiche détaillée"); -define("_CONFIG_AVIS_WORKFLOW_IN_DETAIL_DESC", "Permet de définir le circuit directement depuis la fiche détaillée du courrier"); -define("_AVIS_ANSWERS", "Donner son avis"); -define("_AVIS_ANSWERS_DESC", "Permet à ce groupe d'apparaître dans la liste des personnes Conseillers (circuit d'avis)"); -define("_VIEW_BASKETS_DESC", "Mes bannettes"); -define("_UPDATE_CASE", "Mise à jour d'affaires"); -define("_JOIN_RES_CASE", "Attacher des courriers aux affaires"); -define("_JOIN_RES_CASE_IN_PROCESS", "Attacher des courriers aux affaires (bannette de traitement)"); -define("_CLOSE_CASE", "Clôturer des affaires"); -define("_ADD_CASES", "Créer des affaires"); -define('_CHOOSE_ENTITY', 'Choisissez une entité'); -define('_ADD_COPY_IN_PROCESS', 'Ajouter des personnes en copie dans le traitement'); -define('_ADD_COPY_IN_INDEXING_VALIDATION', 'Interdire la modification du destinataire dans la liste de diffusion'); -define('_UPDATE_LIST_DIFF_IN_DETAILS', 'Mettre à jour la liste de diffusion depuis la page de détails'); -define('_ENTITIES_PRINT_SEP_MLB', 'Imprimer des séparateurs par service'); -define('_EXPORT_SEDA_VIEW', 'Voir le bordereau'); -define('_PUT_DOC_IN_FILEPLAN', 'Classer des documents'); -define('_PUT_DOC_IN_FILEPLAN_COMMENT', 'Classer des documents dans le plan de classement organisationnel'); -define('_PERSONNAL_FILEPLAN', 'Plan de classement personnel'); -define('_SEND_DOCS_TO_RECOMMENDATION', 'Envoyer une demande d\'avis (parallèle)'); -define('_SEND_DOCS_TO_RECOMMENDATION_DESC', 'Ouvre une modal permettant d\'ajouter ou de supprimer des personnes en avis dans la liste de diffusion.'); -define('_VALIDATE_RECOMMENDATION', 'Valider la demande d\'avis (parallèle)'); -define('_VALIDATE_RECOMMENDATION_DESC', 'Permet d\'ajouter dans l\'annotation de demande avis la personne qui a contrôlé la demande.'); -define('_SEND_TO_AVIS_WF', 'Envoyer une demande d\'avis (séquentiel)'); -define('_SEND_TO_AVIS_WF_DESC', 'Ouvre une modal permettant de configurer un circuit d\'avis pour le document.'); -define('_PROCEED_WORKFLOW_AVIS', 'Émettre un avis (séquentiel)'); -define('_PROCEED_WORKFLOW_AVIS_DESC', 'Met à jour la date d\'émission d\'avis du conseiller actuel du circuit d\'avis ("process_date" de la table listinstance).'); -define('_PROCEED_WORKFLOW_AVIS_SIMPLE', 'Émettre un avis (parallèle)'); -define('_PROCEED_WORKFLOW_AVIS_SIMPLE_DESC', 'Met à jour la date d\'émission d\'avis de l\'utilisateur présent en avis dans la liste de diffusion du document ("process_date" de la table listinstance).'); -define('_EXPORT_SEDA', 'Transférer vos courriers'); -define('_CHECK_ACKNOWLEDGEMENT', 'Vérification de l\'accusé de reception'); -define('_CHECK_REPLY', 'Vérification de la réponse au transfert'); -define('_PURGE_LETTER', 'Purger le courrier apres l\'archivage'); -define('_RESET_LETTER', 'Remise à zéro du circuit de traitement'); -define('_SIMPLE_CONFIRM_WITH_UPDATE_DATE', 'Confirmation et mise à jour de la date de départ'); - -// REPORTS -define('_FOLDER_VIEW_STAT', 'Nombre de dossiers consultés'); -define('_ENTITY_VOL_STAT', 'Volume des courriers par entité'); -define('_ENTITY_VOL_STAT_DESC', 'Permet d\'afficher le nombre de courriers enregistrés par service.'); -define('_RESPONSE_RATE_BY_ENTITIES', 'Taux de réponse par entité'); -define('_RESPONSE_RATE_BY_ENTITIES_DESC', 'Permet d\'afficher le pourcentage de courrier dont une réponse a été effectuée. Cette statistique se base sur le nombre de courriers dont une date de départ a été inscrite (utilise le champ departure_date)'); -define('_ENTITY_LATE_MAIL', 'Volume de courriers en retard par entité'); -define('_ENTITY_PROCESS_DELAY', 'Délai moyen de traitement par entité'); -define('_USERS_LOGS', 'Liste des accès à l\'application par agent'); -define('_PROCESS_DELAY_REPORT', 'Délai moyen de traitement par typologie'); -define('_PROCESS_DELAY_REPORT_DESC', 'Permet d\'afficher le délai (en jour) de la création jusqu\'à la clôture d\'un courrier.'); -define('_PROCESS_DELAY_GENERIC_EVALUATION_REPORT', 'Délai moyen de traitement par période'); -define('_PROCESS_DELAY_GENERIC_EVALUATION_REPORT_DESC', 'Permet d\'afficher le délai (en jour) de la création jusqu\'à la clôture d\'un courrier.'); -define('_MAIL_TYPOLOGY_REPORT', 'Volume de courriers par typologie'); -define('_MAIL_TYPOLOGY_REPORT_DESC', 'Permet d\'afficher le nombre de courriers enregistrés par type de document.'); -define('_MAIL_VOL_BY_CAT_REPORT', 'Volume de courriers par catégorie'); -define('_MAIL_VOL_BY_CAT_REPORT_DESC', 'Permet d\'afficher le nombre de courriers enregistrés par catégorie (arrivé, départ, etc.).'); - -//ATTACHMENT TYPES -define("_RESPONSE_PROJECT", "Projet de réponse"); -define("_SIGNED_RESPONSE", "Réponse signée"); -define("_OUTGOING_MAIL_SIGNED", "Courrier départ signé"); -define("_A_PJ", "Pièce jointe"); -define("_INCOMING_PJ", "Pièce jointe capturée"); -define("_WAYBILL", "Bordereau d'envoi"); -define("_ROUTING", "Fiche de circulation"); -define("_OUTGOING_MAIL", "Courrier départ spontané"); -define("_CONVERTED_PDF", "PDF converti par la solution"); -define('_PRINT_FOLDER', 'Dossier'); -define('_SVA', 'SVA'); -define('_SVR', 'SVR'); +define('_EX', 'Ex'); diff --git a/src/core/models/AuthenticationModel.php b/src/core/models/AuthenticationModel.php index ffd96cf0b2..0318103b1a 100644 --- a/src/core/models/AuthenticationModel.php +++ b/src/core/models/AuthenticationModel.php @@ -29,7 +29,7 @@ class AuthenticationModel $aReturn = DatabaseModel::select([ 'select' => ['password'], 'table' => ['users'], - 'where' => ['user_id = ?', 'status != ?', '(locked_until is null OR locked_until < CURRENT_TIMESTAMP)'], + 'where' => ['user_id = ?', 'status != ?'], 'data' => [$args['userId'], 'DEL'] ]); @@ -126,57 +126,4 @@ class AuthenticationModel return true; } - - public static function resetFailedAuthentication(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId']); - ValidatorModel::stringType($aArgs, ['userId']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'failed_authentication' => 0, - 'locked_until' => null, - ], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - return true; - } - - public static function increaseFailedAuthentication(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'tentatives']); - ValidatorModel::stringType($aArgs, ['userId']); - ValidatorModel::intVal($aArgs, ['tentatives']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'failed_authentication' => $aArgs['tentatives'] - ], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - return true; - } - - public static function lockUser(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['userId', 'lockedUntil']); - ValidatorModel::stringType($aArgs, ['userId']); - - DatabaseModel::update([ - 'table' => 'users', - 'set' => [ - 'locked_until' => date('Y-m-d H:i:s', $aArgs['lockedUntil']) - ], - 'where' => ['user_id = ?'], - 'data' => [$aArgs['userId']] - ]); - - return true; - } } diff --git a/src/core/models/CoreConfigModel.php b/src/core/models/CoreConfigModel.php index 4c501b43a0..42eaccd729 100644 --- a/src/core/models/CoreConfigModel.php +++ b/src/core/models/CoreConfigModel.php @@ -15,80 +15,33 @@ namespace SrcCore\models; -//This model is not customizable class CoreConfigModel { - public static function getCustomId() + public static function getName() { - if (!file_exists('custom/custom.xml') || empty($_SERVER['SCRIPT_NAME']) || empty($_SERVER['SERVER_ADDR'])) { - return ''; - } - - $explodeUrl = explode('/', $_SERVER['SCRIPT_NAME']); - - if (strpos($_SERVER['SCRIPT_NAME'], 'ws_server') !== false) { - $path = $explodeUrl[count($explodeUrl) - 2]; - } elseif (strpos($_SERVER['SCRIPT_NAME'], 'apps/maarch_entreprise/smartphone') !== false) { - $path = $explodeUrl[count($explodeUrl) - 5]; - } elseif (strpos($_SERVER['SCRIPT_NAME'], 'apps/maarch_entreprise') === false) { - $path = $explodeUrl[count($explodeUrl) - 3]; - } else { - $path = $explodeUrl[count($explodeUrl) - 4]; - } - - $xmlfile = simplexml_load_file('custom/custom.xml'); - foreach ($xmlfile->custom as $value) { - if (!empty($value->path) && $value->path == $path) { - return (string)$value->custom_id; - } elseif ($value->ip == $_SERVER['SERVER_ADDR']) { - return (string)$value->custom_id; - } elseif ($value->external_domain == $_SERVER['HTTP_HOST'] || $value->domain == $_SERVER['HTTP_HOST']) { - return (string)$value->custom_id; - } - } - - return ''; - } - - public static function getApplicationName() - { - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => $_SERVER['CONFIG_DIR'] . 'config.xml']); if ($loadedXml) { - return (string)$loadedXml->CONFIG->applicationname; + return (string)$loadedXml->config->name; } - return 'Maarch Courrier'; - } - - public static function getApplicationVersion() - { - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/applicationVersion.xml']); - - if ($loadedXml) { - return [ - 'applicationVersion' => (string) $loadedXml->majorVersion, - 'applicationMinorVersion' => (string) $loadedXml->minorVersion, - ]; - } - - return []; + return 'Maarch Parapheur'; } public static function getLanguage() { $availableLanguages = ['en', 'fr']; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => $_SERVER['CONFIG_DIR'] . 'config.xml']); if ($loadedXml) { - $lang = (string)$loadedXml->CONFIG->lang; + $lang = (string)$loadedXml->config->lang; if (in_array($lang, $availableLanguages)) { return $lang; } } - return 'en'; + return 'fr'; } /** @@ -100,11 +53,11 @@ class CoreConfigModel { $timezone = 'Europe/Paris'; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $loadedXml = CoreConfigModel::getXmlLoaded(['path' => $_SERVER['CONFIG_DIR'] . 'config.xml']); if ($loadedXml) { - if (!empty((string)$loadedXml->CONFIG->timezone)) { - $timezone = (string)$loadedXml->CONFIG->timezone; + if (!empty((string)$loadedXml->config->timezone)) { + $timezone = (string)$loadedXml->config->timezone; } } @@ -131,74 +84,14 @@ class CoreConfigModel return $tmpDir . '/'; } - public static function getLoggingMethod() - { - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/login_method.xml']); - - $loggingMethod = []; - if ($loadedXml) { - foreach ($loadedXml->METHOD as $value) { - if ((string)$value->ENABLED == 'true') { - $loggingMethod['id'] = (string)$value->ID; - $loggingMethod['name'] = (string)$value->NAME; - $loggingMethod['script'] = (string)$value->SCRIPT; - } - } - } - - return $loggingMethod; - } - - public static function getOzwilloConfiguration(array $aArgs = []) - { - ValidatorModel::stringType($aArgs, ['customId']); - - if (empty($aArgs['customId'])) { - $customId = CoreConfigModel::getCustomId(); - } else { - $customId = $aArgs['customId']; - } - - if (file_exists("custom/{$customId}/apps/maarch_entreprise/xml/ozwilloConfig.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/ozwilloConfig.xml"; - } else { - $path = 'apps/maarch_entreprise/xml/ozwilloConfig.xml'; - } - - $ozwilloConfig = []; - if (file_exists($path)) { - $loadedXml = simplexml_load_file($path); - if ($loadedXml) { - $ozwilloConfig['instanceUri'] = (string)$loadedXml->INSTANCE_URI; - $ozwilloConfig['instantiationSecret'] = (string)$loadedXml->INSTANTIATION_SECRET; - $ozwilloConfig['destructionSecret'] = (string)$loadedXml->DESTRUCTION_SECRET; - $ozwilloConfig['uri'] = (string)$loadedXml->URI; - $ozwilloConfig['clientId'] = (string)$loadedXml->CLIENT_ID; - $ozwilloConfig['clientSecret'] = (string)$loadedXml->CLIENT_SECRET; - $ozwilloConfig['groupId'] = (string)$loadedXml->GROUP_ID; - $ozwilloConfig['entityId'] = (string)$loadedXml->ENTITY_ID; - } - } - - return $ozwilloConfig; - } - public static function getXmlLoaded(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['path']); ValidatorModel::stringType($aArgs, ['path']); - $customId = CoreConfigModel::getCustomId(); - - if (file_exists("custom/{$customId}/{$aArgs['path']}")) { - $path = "custom/{$customId}/{$aArgs['path']}"; - } else { - $path = $aArgs['path']; - } - $xmlfile = null; - if (file_exists($path)) { - $xmlfile = simplexml_load_file($path); + if (file_exists($aArgs['path'])) { + $xmlfile = simplexml_load_file($aArgs['path']); } return $xmlfile; diff --git a/src/core/models/DatabasePDO.php b/src/core/models/DatabasePDO.php index 4841a4598d..03b3b5c93f 100755 --- a/src/core/models/DatabasePDO.php +++ b/src/core/models/DatabasePDO.php @@ -42,35 +42,18 @@ class DatabasePDO $password = $args['password']; self::$type = $args['type']; } else { - if (!empty($args['customId'])) { - $customId = $args['customId']; - } else { - $customId = CoreConfigModel::getCustomId(); - } - - if (file_exists("custom/{$customId}/apps/maarch_entreprise/xml/config.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; - } else { - $path = 'apps/maarch_entreprise/xml/config.xml'; - } - if (!file_exists($path)) { - if (file_exists("{$GLOBALS['MaarchDirectory']}custom/{$customId}/apps/maarch_entreprise/xml/config.xml")) { - $path = "{$GLOBALS['MaarchDirectory']}custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; - } else { - $path = "{$GLOBALS['MaarchDirectory']}apps/maarch_entreprise/xml/config.xml"; - } - } + $path = $_SERVER['CONFIG_DIR'] . 'config.xml'; if (file_exists($path)) { $loadedXml = simplexml_load_file($path); if ($loadedXml) { - $server = (string)$loadedXml->CONFIG->databaseserver; - $port = (string)$loadedXml->CONFIG->databaseserverport; - $name = (string)$loadedXml->CONFIG->databasename; - $user = (string)$loadedXml->CONFIG->databaseuser; - $password = (string)$loadedXml->CONFIG->databasepassword; - self::$type = (string)$loadedXml->CONFIG->databasetype; + $server = (string)$loadedXml->database->server; + $port = (string)$loadedXml->database->port; + $name = (string)$loadedXml->database->name; + $user = (string)$loadedXml->database->user; + $password = (string)$loadedXml->database->password; + self::$type = (string)$loadedXml->database->type; } } } diff --git a/src/core/models/PasswordModel.php b/src/core/models/PasswordModel.php deleted file mode 100644 index 7d5dd9484c..0000000000 --- a/src/core/models/PasswordModel.php +++ /dev/null @@ -1,153 +0,0 @@ -<?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 Password Model -* @author dev@maarch.org -*/ - -namespace SrcCore\models; - -class PasswordModel -{ - public static function getRules(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data']); - - $aRules = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['password_rules'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - ]); - - return $aRules; - } - - public static function getEnabledRules() - { - $aRules = DatabaseModel::select([ - 'select' => ['label', 'value'], - 'table' => ['password_rules'], - 'where' => ['enabled = ?'], - 'data' => [true], - ]); - - $formattedRules = []; - foreach ($aRules as $rule) { - if (strpos($rule['label'], 'complexity') === false) { - $formattedRules[$rule['label']] = $rule['value']; - } else { - $formattedRules[$rule['label']] = true; - } - } - - return $formattedRules; - } - - public static function getRuleById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $rules = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['password_rules'], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']], - ]); - - if (empty($rules[0])) { - return []; - } - - return $rules[0]; - } - - public static function updateRuleById(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id', 'value']); - ValidatorModel::stringType($aArgs, ['enabled']); - - DatabaseModel::update([ - 'table' => 'password_rules', - 'set' => [ - '"value"' => $aArgs['value'], - 'enabled' => $aArgs['enabled'], - ], - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return true; - } - - public static function isPasswordHistoryValid(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['password', 'userSerialId']); - ValidatorModel::stringType($aArgs, ['password']); - ValidatorModel::intVal($aArgs, ['userSerialId']); - - $passwordRules = PasswordModel::getEnabledRules(); - - if (!empty($passwordRules['historyLastUse'])) { - $passwordHistory = DatabaseModel::select([ - 'select' => ['password'], - 'table' => ['password_history'], - 'where' => ['user_serial_id = ?'], - 'data' => [$aArgs['userSerialId']], - 'order_by' => ['id DESC'], - 'limit' => $passwordRules['historyLastUse'] - ]); - - foreach ($passwordHistory as $value) { - if (password_verify($aArgs['password'], $value['password'])) { - return false; - } - } - } - - return true; - } - - public static function setHistoryPassword(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['password', 'userSerialId']); - ValidatorModel::stringType($aArgs, ['password']); - ValidatorModel::intVal($aArgs, ['userSerialId']); - - $passwordHistory = DatabaseModel::select([ - 'select' => ['id'], - 'table' => ['password_history'], - 'where' => ['user_serial_id = ?'], - 'data' => [$aArgs['userSerialId']], - 'order_by' => ['id DESC'] - ]); - - if (count($passwordHistory) >= 10) { - DatabaseModel::delete([ - 'table' => 'password_history', - 'where' => ['id < ?', 'user_serial_id = ?'], - 'data' => [$passwordHistory[8]['id'], $aArgs['userSerialId']] - ]); - } - - DatabaseModel::insert([ - 'table' => 'password_history', - 'columnsValues' => [ - 'user_serial_id' => $aArgs['userSerialId'], - 'password' => AuthenticationModel::getPasswordHash($aArgs['password']) - ], - ]); - - return true; - } -} diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index 4626994fd4..2c72175e77 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -374,9 +374,13 @@ class ClassLoader $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath.'\\'; + if (isset($this->prefixDirsPsr4[$search])) { + foreach ($this->prefixDirsPsr4[$search] as $dir) { + $length = $this->prefixLengthsPsr4[$first][$search]; if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { return $file; } diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE index 1a28124886..f27399a042 100644 --- a/vendor/composer/LICENSE +++ b/vendor/composer/LICENSE @@ -1,5 +1,5 @@ -Copyright (c) 2016 Nils Adermann, Jordi Boggiano +Copyright (c) Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 0d23664e9f..b9d22c33d5 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -8,9 +8,7 @@ $baseDir = dirname($vendorDir); return array( 'setasign\\Fpdi\\' => array($vendorDir . '/setasign/fpdi/src'), 'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'), - 'VersionUpdate\\' => array($baseDir . '/src/app/versionUpdate'), 'User\\' => array($baseDir . '/src/app/user'), - 'Template\\' => array($baseDir . '/src/app/template'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Component\\OptionsResolver\\' => array($vendorDir . '/symfony/options-resolver'), 'Status\\' => array($baseDir . '/src/app/status'), @@ -19,14 +17,8 @@ return array( 'SignatureBook\\' => array($baseDir . '/src/app/signatureBook'), 'Respect\\Validation\\' => array($vendorDir . '/respect/validation/library'), 'Resource\\' => array($baseDir . '/src/app/resource'), - 'Report\\' => array($baseDir . '/src/app/report'), 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'), 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), - 'Priority\\' => array($baseDir . '/src/app/priority'), - 'Parameter\\' => array($baseDir . '/src/app/parameter'), - 'Notification\\' => array($baseDir . '/src/app/notification'), - 'Note\\' => array($baseDir . '/src/app/note'), - 'Link\\' => array($baseDir . '/src/app/link'), 'Interop\\Container\\' => array($vendorDir . '/container-interop/container-interop/src/Interop/Container'), 'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'), 'Http\\Message\\MultipartStream\\' => array($vendorDir . '/php-http/multipart-stream-builder/src'), @@ -36,23 +28,15 @@ return array( 'Http\\Client\\Common\\' => array($vendorDir . '/php-http/client-common/src'), 'Http\\Client\\' => array($vendorDir . '/php-http/httplug/src'), 'Http\\Adapter\\Guzzle6\\' => array($vendorDir . '/php-http/guzzle6-adapter/src'), - 'Home\\' => array($baseDir . '/src/app/home'), 'History\\' => array($baseDir . '/src/app/history'), 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), - 'Group\\' => array($baseDir . '/src/app/group'), 'Gitlab\\' => array($vendorDir . '/m4tthumphrey/php-gitlab-api/lib/Gitlab'), - 'Folder\\' => array($baseDir . '/src/app/folder'), 'FastRoute\\' => array($vendorDir . '/nikic/fast-route/src'), - 'Entity\\' => array($baseDir . '/src/app/entity'), - 'Doctype\\' => array($baseDir . '/src/app/doctype'), + 'Document\\' => array($baseDir . '/src/app/document'), 'Docserver\\' => array($baseDir . '/src/app/docserver'), 'Convert\\' => array($baseDir . '/src/app/convert'), - 'ContentManagement\\' => array($baseDir . '/src/app/contentManagement'), - 'Contact\\' => array($baseDir . '/src/app/contact'), 'Clue\\StreamFilter\\' => array($vendorDir . '/clue/stream-filter/src'), - 'Basket\\' => array($baseDir . '/src/app/basket'), 'Attachment\\' => array($baseDir . '/src/app/attachment'), - 'Action\\' => array($baseDir . '/src/app/action'), ); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index dd28d8f1a5..327b0d0000 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -25,18 +25,10 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 'phpseclib\\' => 10, ), - 'V' => - array ( - 'VersionUpdate\\' => 14, - ), 'U' => array ( 'User\\' => 5, ), - 'T' => - array ( - 'Template\\' => 9, - ), 'S' => array ( 'Symfony\\Polyfill\\Mbstring\\' => 26, @@ -50,23 +42,11 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 'Respect\\Validation\\' => 19, 'Resource\\' => 9, - 'Report\\' => 7, ), 'P' => array ( 'Psr\\Http\\Message\\' => 17, 'Psr\\Container\\' => 14, - 'Priority\\' => 9, - 'Parameter\\' => 10, - ), - 'N' => - array ( - 'Notification\\' => 13, - 'Note\\' => 5, - ), - 'L' => - array ( - 'Link\\' => 5, ), 'I' => array ( @@ -82,7 +62,6 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd 'Http\\Client\\Common\\' => 19, 'Http\\Client\\' => 12, 'Http\\Adapter\\Guzzle6\\' => 21, - 'Home\\' => 5, 'History\\' => 8, ), 'G' => @@ -90,38 +69,25 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd 'GuzzleHttp\\Psr7\\' => 16, 'GuzzleHttp\\Promise\\' => 19, 'GuzzleHttp\\' => 11, - 'Group\\' => 6, 'Gitlab\\' => 7, ), 'F' => array ( - 'Folder\\' => 7, 'FastRoute\\' => 10, ), - 'E' => - array ( - 'Entity\\' => 7, - ), 'D' => array ( - 'Doctype\\' => 8, + 'Document\\' => 9, 'Docserver\\' => 10, ), 'C' => array ( 'Convert\\' => 8, - 'ContentManagement\\' => 18, - 'Contact\\' => 8, 'Clue\\StreamFilter\\' => 18, ), - 'B' => - array ( - 'Basket\\' => 7, - ), 'A' => array ( 'Attachment\\' => 11, - 'Action\\' => 7, ), ); @@ -134,18 +100,10 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib', ), - 'VersionUpdate\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/versionUpdate', - ), 'User\\' => array ( 0 => __DIR__ . '/../..' . '/src/app/user', ), - 'Template\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/template', - ), 'Symfony\\Polyfill\\Mbstring\\' => array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring', @@ -178,10 +136,6 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/../..' . '/src/app/resource', ), - 'Report\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/report', - ), 'Psr\\Http\\Message\\' => array ( 0 => __DIR__ . '/..' . '/psr/http-message/src', @@ -190,26 +144,6 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/..' . '/psr/container/src', ), - 'Priority\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/priority', - ), - 'Parameter\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/parameter', - ), - 'Notification\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/notification', - ), - 'Note\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/note', - ), - 'Link\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/link', - ), 'Interop\\Container\\' => array ( 0 => __DIR__ . '/..' . '/container-interop/container-interop/src/Interop/Container', @@ -247,10 +181,6 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/..' . '/php-http/guzzle6-adapter/src', ), - 'Home\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/home', - ), 'History\\' => array ( 0 => __DIR__ . '/../..' . '/src/app/history', @@ -267,29 +197,17 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src', ), - 'Group\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/group', - ), 'Gitlab\\' => array ( 0 => __DIR__ . '/..' . '/m4tthumphrey/php-gitlab-api/lib/Gitlab', ), - 'Folder\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/folder', - ), 'FastRoute\\' => array ( 0 => __DIR__ . '/..' . '/nikic/fast-route/src', ), - 'Entity\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/entity', - ), - 'Doctype\\' => + 'Document\\' => array ( - 0 => __DIR__ . '/../..' . '/src/app/doctype', + 0 => __DIR__ . '/../..' . '/src/app/document', ), 'Docserver\\' => array ( @@ -299,30 +217,14 @@ class ComposerStaticInitf21aebccfa6df888200dcb099aa69fbd array ( 0 => __DIR__ . '/../..' . '/src/app/convert', ), - 'ContentManagement\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/contentManagement', - ), - 'Contact\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/contact', - ), 'Clue\\StreamFilter\\' => array ( 0 => __DIR__ . '/..' . '/clue/stream-filter/src', ), - 'Basket\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/basket', - ), 'Attachment\\' => array ( 0 => __DIR__ . '/../..' . '/src/app/attachment', ), - 'Action\\' => - array ( - 0 => __DIR__ . '/../..' . '/src/app/action', - ), ); public static $prefixesPsr0 = array ( -- GitLab