diff --git a/apps/maarch_entreprise/Models/ContactsModel.php b/apps/maarch_entreprise/Models/ActionModel.php similarity index 58% rename from apps/maarch_entreprise/Models/ContactsModel.php rename to apps/maarch_entreprise/Models/ActionModel.php index 93b766324580072d5ee4450be3432b3c28afbb59..cadc2192fcf281b48a442a91c302f643d5916b8e 100644 --- a/apps/maarch_entreprise/Models/ContactsModel.php +++ b/apps/maarch_entreprise/Models/ActionModel.php @@ -9,16 +9,14 @@ */ /** -* @brief Contacts Model +* @brief Action Model * @author dev@maarch.org * @ingroup apps */ -//namespace Apps\Models\Contacts; +namespace Apps\Models; -require_once 'apps/maarch_entreprise/Models/ContactsModelAbstract.php'; - -class ContactsModel extends ContactsModelAbstract +class ActionModel extends ActionModelAbstract { // Do your stuff in this class } \ No newline at end of file diff --git a/apps/maarch_entreprise/Models/ActionModelAbstract.php b/apps/maarch_entreprise/Models/ActionModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..07680b1905607d4167363c22e27fa59ad546f012 --- /dev/null +++ b/apps/maarch_entreprise/Models/ActionModelAbstract.php @@ -0,0 +1,41 @@ +<?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 apps +*/ + +namespace Apps\Models; + +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; + +class ActionModelAbstract +{ + 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']; + } + +} diff --git a/apps/maarch_entreprise/Models/ContactModel.php b/apps/maarch_entreprise/Models/ContactModel.php new file mode 100644 index 0000000000000000000000000000000000000000..858e69488050e363c840cc7b8c12484cdc9da7f4 --- /dev/null +++ b/apps/maarch_entreprise/Models/ContactModel.php @@ -0,0 +1,22 @@ +<?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 +* @ingroup apps +*/ + +namespace Apps\Models; + +class ContactModel extends ContactModelAbstract +{ + // Do your stuff in this class +} \ No newline at end of file diff --git a/apps/maarch_entreprise/Models/ContactsModelAbstract.php b/apps/maarch_entreprise/Models/ContactModelAbstract.php similarity index 51% rename from apps/maarch_entreprise/Models/ContactsModelAbstract.php rename to apps/maarch_entreprise/Models/ContactModelAbstract.php index 008cd7f498150bdea7238953636716978e9613b2..7d08f2e71d7ced908964245ace454b9810ce18d5 100644 --- a/apps/maarch_entreprise/Models/ContactsModelAbstract.php +++ b/apps/maarch_entreprise/Models/ContactModelAbstract.php @@ -8,62 +8,69 @@ */ /** -* @brief Contacts Model +* @brief Contact Model * @author dev@maarch.org * @ingroup apps */ -//namespace Apps\Models\Contacts; +namespace Apps\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; -class ContactsModelAbstract extends Apps_Table_Service +class ContactModelAbstract { public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); - $aReturn = static::select([ + $aContact = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['contacts_v2'], 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']], ]); - return $aReturn; + if (empty($aContact[0])) { + return []; + } + + return $aContact[0]; } - public static function getWithAddress(array $aArgs = []) + public static function getByAddressId(array $aArgs = []) { - static::checkRequired($aArgs, ['contactId', 'addressId']); - static::checkNumeric($aArgs, ['contactId', 'addressId']); - + ValidatorModel::notEmpty($aArgs, ['contactId', 'addressId']); + ValidatorModel::intVal($aArgs, ['contactId', 'addressId']); - $aReturn = static::select([ + $aContact = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['contact_addresses'], 'where' => ['id = ?', 'contact_id = ?'], 'data' => [$aArgs['addressId'], $aArgs['contactId']], ]); - return $aReturn; + if (empty($aContact[0])) { + return []; + } + + return $aContact[0]; } public static function getLabelledContactWithAddress(array $aArgs = []) { - static::checkRequired($aArgs, ['contactId', 'addressId']); - static::checkNumeric($aArgs, ['contactId', 'addressId']); - + ValidatorModel::notEmpty($aArgs, ['contactId', 'addressId']); + ValidatorModel::intVal($aArgs, ['contactId', 'addressId']); - $rawContact = self::getWithAddress(['contactId' => $aArgs['contactId'], 'addressId' => $aArgs['addressId'], 'select' => ['firstname', 'lastname']]); + $rawContact = ContactModel::getByAddressId(['contactId' => $aArgs['contactId'], 'addressId' => $aArgs['addressId'], 'select' => ['firstname', 'lastname']]); $labelledContact = ''; - if (!empty($rawContact[0])) { - if (empty($rawContact[0]['firstname']) && empty($rawContact[0]['lastname'])) { - $rawContact = self::getById(['id' => $aArgs['contactId'], 'select' => ['firstname', 'lastname']]); + if (!empty($rawContact)) { + if (empty($rawContact['firstname']) && empty($rawContact['lastname'])) { + $rawContact = ContactModel::getById(['id' => $aArgs['contactId'], 'select' => ['firstname', 'lastname']]); } - $labelledContact = $rawContact[0]['firstname']. ' ' .$rawContact[0]['lastname']; + $labelledContact = $rawContact['firstname']. ' ' .$rawContact['lastname']; } return $labelledContact; @@ -71,46 +78,46 @@ class ContactsModelAbstract extends Apps_Table_Service public static function getByEmail(array $aArgs = []) { - static::checkRequired($aArgs, ['email']); - static::checkString($aArgs, ['email']); + ValidatorModel::notEmpty($aArgs, ['email']); + ValidatorModel::stringType($aArgs, ['email']); - $aReturn = static::select([ + $aContacts = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['view_contacts'], 'where' => ['email = ? and enabled = ?'], 'data' => [$aArgs['email'], 'Y'], - 'order_by' => ['creation_date'], + 'order_by' => ['creation_date'], ]); - return $aReturn; + return $aContacts; } public static function purgeContact($aArgs) { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); - $aReturn = static::select([ - 'select' => ['count(*)'], + $aReturn = DatabaseModel::select([ + 'select' => ['count(*) as count'], 'table' => ['res_view_letterbox'], 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']], ]); - $aReturnBis = static::select([ - 'select' => ['count(*)'], + $aReturnBis = DatabaseModel::select([ + 'select' => ['count(*) as count'], 'table' => ['contacts_res'], 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']], ]); if ($aReturn[0]['count'] < 1 && $aReturnBis[0]['count'] < 1) { - $aDelete = static::deleteFrom([ + DatabaseModel::delete([ 'table' => 'contact_addresses', 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']] ]); - $aDelete = static::deleteFrom([ + DatabaseModel::delete([ 'table' => 'contacts_v2', 'where' => ['contact_id = ?'], 'data' => [$aArgs['id']] diff --git a/apps/maarch_entreprise/Models/HistoryModel.php b/apps/maarch_entreprise/Models/HistoryModel.php deleted file mode 100644 index 2c8efa0c595145b6fdd70081664414c140c367db..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/Models/HistoryModel.php +++ /dev/null @@ -1,27 +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/>. -*/ - -require_once 'apps/maarch_entreprise/Models/HistoryModelAbstract.php'; - -class HistoryModel extends HistoryModelAbstract -{ - // Do your stuff in this class -} \ No newline at end of file diff --git a/apps/maarch_entreprise/Models/HistoryModelAbstract.php b/apps/maarch_entreprise/Models/HistoryModelAbstract.php deleted file mode 100644 index da17969cbcfcbb088b6f4a34859e38e0dc663009..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/Models/HistoryModelAbstract.php +++ /dev/null @@ -1,45 +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/>. -*/ - -require_once 'apps/maarch_entreprise/services/Table.php'; - -class HistoryModelAbstract extends Apps_Table_Service -{ - - public static function getByIdForActions(array $aArgs = []) - { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); - - - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['history', 'users'], - 'left_join' => ['history.user_id = users.user_id'], - 'where' => ['history.record_id = ?', 'history.event_type like ?', 'history.event_id NOT LIKE ?'], - 'data' => [$aArgs['id'], 'ACTION#%', '^[0-9]+$'], - 'order_by' => empty($aArgs['orderBy']) ? ['event_date'] : $aArgs['orderBy'] - ]); - - return $aReturn; - } - -} \ No newline at end of file diff --git a/apps/maarch_entreprise/Models/ResModel.php b/apps/maarch_entreprise/Models/ResModel.php deleted file mode 100644 index c62a8ec507a83b341def480d78efe41fa261ae9c..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/Models/ResModel.php +++ /dev/null @@ -1,27 +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/>. -*/ - -require_once 'apps/maarch_entreprise/Models/ResModelAbstract.php'; - -class ResModel extends ResModelAbstract -{ - // Do your stuff in this class -} \ No newline at end of file diff --git a/apps/maarch_entreprise/Models/ResModelAbstract.php b/apps/maarch_entreprise/Models/ResModelAbstract.php deleted file mode 100644 index a7b645ae71fc64eebb56f231fb44b66fa41051b8..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/Models/ResModelAbstract.php +++ /dev/null @@ -1,141 +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/>. -*/ - -require_once 'apps/maarch_entreprise/services/Table.php'; - -class ResModelAbstract extends Apps_Table_Service -{ - - public static function getById(array $aArgs = []) - { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); - - - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_letterbox'], - 'where' => ['res_id = ?'], - 'data' => [$aArgs['resId']] - ]); - - return $aReturn[0]; - } - - public static function put(array $aArgs = []) - { - // TODO collId stands for table in DB => à Changer pour aller récupérer la table lié à collId - static::checkRequired($aArgs, ['collId', 'set', 'where', 'data']); - static::checkString($aArgs, ['collId']); - static::checkArray($aArgs, ['set', 'where', 'data']); - - $bReturn = static::update([ - 'table' => $aArgs['collId'], - 'set' => $aArgs['set'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'] - ]); - - return $bReturn; - } - - public static function getAvailableLinkedAttachmentsIn(array $aArgs = []) - { - static::checkRequired($aArgs, ['resIdMaster', 'in']); - static::checkNumeric($aArgs, ['resIdMaster']); - static::checkArray($aArgs, ['in']); - - - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$aArgs['resIdMaster'], $aArgs['in']] - ]); - - return $aReturn; - } - - public static function getAvailableLinkedAttachmentsNotIn(array $aArgs = []) - { - static::checkRequired($aArgs, ['resIdMaster', 'notIn']); - static::checkNumeric($aArgs, ['resIdMaster']); - static::checkArray($aArgs, ['notIn']); - - - $select = [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$aArgs['resIdMaster'], $aArgs['notIn']], - ]; - if (!empty($aArgs['orderBy'])) { - $select['order_by'] = $aArgs['orderBy']; - } - - $aReturn = static::select($select); - - return $aReturn; - } - - public static function getAvailableAndTemporaryLinkedAttachmentsNotIn(array $aArgs = []) - { - static::checkRequired($aArgs, ['resIdMaster', 'notIn']); - static::checkNumeric($aArgs, ['resIdMaster']); - static::checkArray($aArgs, ['notIn']); - - - $select = [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', "status not in ('DEL', 'OBS')"], - 'data' => [$aArgs['resIdMaster'], $aArgs['notIn']], - ]; - if (!empty($aArgs['orderBy'])) { - $select['order_by'] = $aArgs['orderBy']; - } - - $aReturn = static::select($select); - - return $aReturn; - } - - public static function getObsLinkedAttachmentsNotIn(array $aArgs = []) - { - static::checkRequired($aArgs, ['resIdMaster', 'notIn']); - static::checkNumeric($aArgs, ['resIdMaster']); - static::checkArray($aArgs, ['notIn']); - - - $select = [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status = ?'], - 'data' => [$aArgs['resIdMaster'], $aArgs['notIn'], 'OBS'], - 'order_by' => 'relation ASC' - ]; - - $aReturn = static::select($select); - - return $aReturn; - } - -} \ No newline at end of file diff --git a/apps/maarch_entreprise/class/class_lists_Abstract.php b/apps/maarch_entreprise/class/class_lists_Abstract.php index 31fbad2f1931d85584ecc6d4b1ddbe73450c0358..5400347de8cab5c26eea2bf80d8b87e53f3634fe 100644 --- a/apps/maarch_entreprise/class/class_lists_Abstract.php +++ b/apps/maarch_entreprise/class/class_lists_Abstract.php @@ -1465,8 +1465,8 @@ abstract class lists_Abstract extends Database $keyValue = $resultTheLine[$i]['value']; } } - $aService = Basket_Baskets_Service::getServiceFromActionId(['id' => $this->params['defaultAction']]); - if ($aService['actionPage'] == 'visa_mail') { + $sAction = \Apps\Models\ActionModel::getActionPageById(['id' => $this->params['defaultAction']]); + if ($sAction == 'visa_mail') { if (PROD_MODE) { $return = 'onmouseover="this.style.cursor=\'pointer\';" onClick="islockForSignatureBook(\'' .$keyValue. '\', \'' .$_SESSION['current_basket']['id']. '\', true)"'; } else { @@ -3332,8 +3332,8 @@ abstract class lists_Abstract extends Database !empty($this->params['defaultAction']) && $lineIsDisabled === false ) { - $aService = Basket_Baskets_Service::getServiceFromActionId(['id' => $this->params['defaultAction']]); - if ($aService['actionPage'] == 'visa_mail') { + $sAction = \Apps\Models\ActionModel::getActionPageById(['id' => $this->params['defaultAction']]); + if ($sAction == 'visa_mail') { if (PROD_MODE) { $content .= '<td'.$columnStyle.' onmouseover="this.style.cursor=\'pointer\';" ' .'onClick="islockForSignatureBook(\'' .$keyValue. '\', \'' .$_SESSION['current_basket']['id']. '\', true);" width="'.$resultTheLine[$column]['size'].'%" ' diff --git a/apps/maarch_entreprise/js/angular/app/signature-book.component.js b/apps/maarch_entreprise/js/angular/app/signature-book.component.js index 5ca23f20aa7e55d0b9ccf6e1ef958705332e80d3..ab653ebe5a45697512b15eda5f5e5a52072b7a8f 100644 --- a/apps/maarch_entreprise/js/angular/app/signature-book.component.js +++ b/apps/maarch_entreprise/js/angular/app/signature-book.component.js @@ -40,7 +40,6 @@ var SignatureBookComponent = (function () { consigne: "", documents: [], attachments: [], - //histories : [], resList: [], resListIndex: 0, lang: {} @@ -415,20 +414,15 @@ var SignatureBookComponent = (function () { collId = "res_attachments"; isVersion = "false"; } - this.http.put(this.coreUrl + 'rest/' + collId + '/' + resId + '/unsign', {}, {}) + this.http.put(this.coreUrl + 'rest/' + collId + '/' + resId + '/unsign', {}) .map(function (res) { return res.json(); }) - .subscribe(function (data) { - if (data.status == "OK") { - _this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + _this.resId + "&id=" + attachment.viewerNoSignId + "&isVersion=" + isVersion; - _this.signatureBook.attachments[_this.rightSelectedThumbnail].viewerLink = _this.rightViewerLink; - _this.signatureBook.attachments[_this.rightSelectedThumbnail].status = 'A_TRA'; - _this.signatureBook.attachments[_this.rightSelectedThumbnail].idToDl = resId; - if (_this.signatureBook.resList.length > 0) { - _this.signatureBook.resList[_this.signatureBook.resListIndex].allSigned = false; - } - } - else { - alert(data.error); + .subscribe(function () { + _this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + _this.resId + "&id=" + attachment.viewerNoSignId + "&isVersion=" + isVersion; + _this.signatureBook.attachments[_this.rightSelectedThumbnail].viewerLink = _this.rightViewerLink; + _this.signatureBook.attachments[_this.rightSelectedThumbnail].status = 'A_TRA'; + _this.signatureBook.attachments[_this.rightSelectedThumbnail].idToDl = resId; + if (_this.signatureBook.resList.length > 0) { + _this.signatureBook.resList[_this.signatureBook.resListIndex].allSigned = false; } }); }; diff --git a/apps/maarch_entreprise/js/angular/app/signature-book.component.ts b/apps/maarch_entreprise/js/angular/app/signature-book.component.ts index a7e263fb1f1c00716c4e7754077db409a864e4c6..66e4cad83910de175ec082a7c60f259bdc146d67 100644 --- a/apps/maarch_entreprise/js/angular/app/signature-book.component.ts +++ b/apps/maarch_entreprise/js/angular/app/signature-book.component.ts @@ -36,7 +36,6 @@ export class SignatureBookComponent implements OnInit { consigne : "", documents : [], attachments : [], - //histories : [], resList : [], resListIndex : 0, lang : {} @@ -423,19 +422,15 @@ export class SignatureBookComponent implements OnInit { isVersion = "false"; } - this.http.put(this.coreUrl + 'rest/' + collId + '/' + resId + '/unsign', {}, {}) + this.http.put(this.coreUrl + 'rest/' + collId + '/' + resId + '/unsign', {}) .map(res => res.json()) - .subscribe((data) => { - if (data.status == "OK") { - this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + this.resId + "&id=" + attachment.viewerNoSignId + "&isVersion=" + isVersion; - this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink; - this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'A_TRA'; - this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = resId; - if (this.signatureBook.resList.length > 0) { - this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = false; - } - } else { - alert(data.error); + .subscribe(() => { + this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + this.resId + "&id=" + attachment.viewerNoSignId + "&isVersion=" + isVersion; + this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink; + this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'A_TRA'; + this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = resId; + if (this.signatureBook.resList.length > 0) { + this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = false; } }); diff --git a/apps/maarch_entreprise/lang/en.php b/apps/maarch_entreprise/lang/en.php index aaaac7b89de9a0d1069ccc362f9039076ec92251..de8c0959a7d5e8d5eb34d1005dc375f67d2ef425 100644 --- a/apps/maarch_entreprise/lang/en.php +++ b/apps/maarch_entreprise/lang/en.php @@ -1831,6 +1831,11 @@ if (!defined("_DURATION_CURRENT_USE")) define("_DURATION_CURRENT_USE","Duration if (!defined("_UNSELECT_ALL")) define("_UNSELECT_ALL","Unselect all"); +/***** Global ******/ +if (!defined('_UNREACHABLE_DOCSERVER')) + define('_UNREACHABLE_DOCSERVER', 'Unreachable docserver path'); +/***** Global ******/ + /***** Profile *****/ if (!defined('_MANAGE_MY_SIGNATURES')) define('_MANAGE_MY_SIGNATURES', 'Manage my signatures'); diff --git a/apps/maarch_entreprise/lang/fr.php b/apps/maarch_entreprise/lang/fr.php index aa020ad524254666b063cf39b5c4475aa333b48f..ca60703bd7adc7926499f6ca092811eb0fad5492 100755 --- a/apps/maarch_entreprise/lang/fr.php +++ b/apps/maarch_entreprise/lang/fr.php @@ -1843,6 +1843,11 @@ if (!defined("_DURATION_CURRENT_USE")) define("_DURATION_CURRENT_USE","Durée d' if (!defined("_UNSELECT_ALL")) define("_UNSELECT_ALL","Tout désélectionner"); +/***** Global ******/ +if (!defined('_UNREACHABLE_DOCSERVER')) + define('_UNREACHABLE_DOCSERVER', 'Chemin docserver inatteignable'); +/***** Global ******/ + /***** Profile *****/ if (!defined('_MANAGE_MY_SIGNATURES')) define('_MANAGE_MY_SIGNATURES', 'Gérer mes signatures'); diff --git a/apps/maarch_entreprise/services/Table.php b/apps/maarch_entreprise/services/Table.php deleted file mode 100644 index 502c0663c0ff8a50859e080532d41beaa3846056..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/services/Table.php +++ /dev/null @@ -1,346 +0,0 @@ -<?php -/* -* Copyright 2017 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/>. -*/ - -require_once 'core/services/Abstract.php'; - -// Prés-requis BDD : -require_once 'core/core_tables.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_db_pdo.php'; - -/** - * Fonctions pour réaliser le CRUD sur la base de donnees - */ -class Apps_Table_Service extends Core_Abstract_Service { - /** - * Récupération de la liste des méthodes disponibles via api - * - * @return string[] La liste des méthodes - */ - public static function getApiMethod() { - $aApiMethod = parent::getApiMethod(); - return $aApiMethod; - } - - /** - * Permet de faire un select en BDD - * @api apiurl - * @param array $args donnée sur l'attachement - * - from/table : FROM [table] - * - string/array select : SELECT [select] - * - string/array where : WHERE [where] - * - data : for remplace ? on query - * - array conditions : [condition => valeur] - * @return array [description] - */ - public static function select(array $args=[]){ - // Table : - if ( !empty($args['from']) ) { - $args['table'] = $args['from']; - } - if ( empty($args['table']) ) { - throw new Core_MaarchException_Service('table empty'); - } - if ( is_array($args['table']) ) { - if (empty($args['table'][0])) { - $args['table'] = array_values($args['table']); - } - $tmpTable = $args['table']; - if (!empty($args['left_join'])) { - $keywordJoin = ' LEFT JOIN '; - $args['table'] = $args['table'][0]; - $args['join'] = $args['left_join']; - } else { - $keywordJoin = ' JOIN '; - $args['table'] = $args['table'][0]; - } - - // Join : - if ( ! empty($args['join']) ) { - if ( ! is_array($args['join']) ) { - throw new Core_MaarchException_Service('where must be an array'); - } else if (count($tmpTable) - 1 != count($args['join'])) { - throw new Core_MaarchException_Service('Number of tables doesn\'t match with number of joins'); - } - $z = 1; - foreach ($args['join'] as $cond) { - if ( empty($args['where']) ) { - $args['where'] = []; - } - $args['table'] .= $keywordJoin . $tmpTable[$z] . ' ON '. $cond; - $z++; - } - - } - } - if ( defined(strtoupper($args['table']).'_TABLE')) { - $tablename = constant(strtoupper($args['table']).'_TABLE'); - } else { - $tablename = $args['table']; - } - // Select : - if ( ! empty($args['select']) ) { - if ( is_array($args['select']) ) - $args['select'] = implode(',', $args['select']); - if ( ! is_string($args['select']) ) { - throw new Core_MaarchException_Service('select must be : string or array'); - } - } - $select = empty($args['select']) ? '*' : $args['select']; - // Where : - if ( empty($args['where']) ) { - $args['where'] = []; - } - if ( is_string($args['where']) ) { - $args['where'] = [$args['where']]; - } - $aWhere = $args['where']; - if ( ! is_array($aWhere) ) { - throw new Core_MaarchException_Service('where must be : string or array'); - } - // Data : - if ( empty($args['data']) ) { - $args['data'] = []; - } - if ( ! is_array($args['data']) ) { - throw new Core_MaarchException_Service('data must be an array'); - } - $data = $args['data']; - // Conditions : - if ( ! empty($args['conditions']) ) { - if ( ! is_array($args['conditions']) ) { - throw new Core_MaarchException_Service('where must be an array'); - } - foreach ($args['conditions'] as $cond => $value) { - $aWhere[] = $cond; - $data[] = $value; - } - } - // Fusion des données de recherche : - $where = empty($aWhere) ? '' : ' WHERE '.implode(' AND ', $aWhere); - - // GroupBy : - if ( empty($args['group_by']) ) { - $group_by = ''; - } else { - if ( is_array($args['group_by']) ) - $args['group_by'] = implode(',', $args['group_by']); - if ( ! is_string($args['group_by']) ) { - throw new Core_MaarchException_Service('group_by must be : string or array'); - } - $group_by = ' GROUP BY '.$args['group_by']; - } - // OrderBy : - if ( empty($args['order_by']) ) { - $order_by = ''; - } else { - if ( is_array($args['order_by']) ) - $args['order_by'] = implode(',', $args['order_by']); - if ( ! is_string($args['order_by']) ) { - throw new Core_MaarchException_Service('order_by must be : string or array'); - } - $order_by = ' ORDER BY '.$args['order_by']; - } - // Limit : - if (empty($args['limit'])) { - $limit = ''; - } else { - if (!is_numeric($args['limit'])) { - throw new Core_MaarchException_Service('limit must be : numeric'); - } - $limit = $args['limit']; - } - - if (!isset($GLOBALS['configFile'])) { - $GLOBALS['configFile'] = null; - } - $db = new Database($GLOBALS['configFile']); - - // Query : - if (!empty($limit)) { - $where = empty($aWhere) ? '' : ' '.implode(' AND ', $aWhere); - - $queryExt = $db->limit_select(0, $limit, $select, $tablename, $where, $group_by, '', $order_by); - } else { - $where = empty($aWhere) ? '' : ' WHERE '.implode(' AND ', $aWhere); - - $queryExt = "SELECT {$select} FROM {$tablename} {$where} {$group_by} {$order_by}"; - } - - $stmt = empty($data) ? $db->query($queryExt) : $db->query($queryExt, $data); - - $rowset = []; - while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $rowset[] = $row; - } - return $rowset; - } - - /** - * Ajoute un row dans la base de données - * @param array $aData donnée a ajouter - * @param array $table table de l'ajout - * @param string $getLastId - * @return type [description] - */ - public static function insertInto(array $aData, $table, $getLastId = null){ - if ( ! is_string($table) ) { - throw new Core_MaarchException_Service('$table is not a string'); - } - $queryExtFields = []; - $queryExtJokers = []; - $queryExtValues = []; - foreach ($aData as $key => $value) { - if ($value == 'SYSDATE' || - $value == 'CURRENT_TIMESTAMP') { - $queryExtJokers[] = $value; - } else { - $queryExtJokers[] = '?'; - $queryExtValues[] = $value; - } - $queryExtFields[] = $key; - } - $queryExt = 'INSERT INTO '.$table.'('.implode(',', $queryExtFields).')values('.implode(',', $queryExtJokers).')'; - //echo "the query " . $queryExt . PHP_EOL;var_export($queryExtFields). PHP_EOL;var_export($queryExtValues). PHP_EOL; - $db = new Database(); - $return = $db->query($queryExt, $queryExtValues); - if (!empty($getLastId)) { - return $db->lastInsertId($getLastId); - } - return $return; - } - - /** - * [updateTable description] - * @param array $aData [description] - * @param string $table [description] - * @param array $aWhere [description] - * @return type [description] - */ - public static function updateTable(array $aData, $table, $aWhere = []){ - // Prés-requis : - if ( ! is_string($table) ) { - throw new Core_MaarchException_Service('$table not a string'); - } - if ( ! is_array($aData) ) { - throw new Core_MaarchException_Service('$aData not an array'); - } - if ( empty($aData) ) { - throw new Core_MaarchException_Service('$aData empty'); - } - // Initialisation : - $queryExtUpdate = []; - $queryExtWhere = []; - $queryExtValues = []; - // SET : - foreach ($aData as $key => $value) { - $queryExtUpdate[$key] = "{$key}=?"; - $queryExtValues[] = $value; - } - // Where : - foreach ($aWhere as $key => $value) { - if ( strpos($key, '?')===false ) - $key = "{$key}=?"; - $queryExtWhere[$key] = $key; - $queryExtValues[] = $value; - } - - $sWhere = empty($aWhere)?'': ' WHERE '.implode(' AND ', $queryExtWhere); - $queryExt = 'UPDATE '.$table.' SET '.implode(',', $queryExtUpdate).$sWhere; - $db = new Database(); - return $db->query($queryExt, $queryExtValues); - } - - /** - * Fonction de suppression dans la base de données - * @param array $args - * @throws Core_MaarchException_Service if table Argument is empty or is not a string - * @throws Core_MaarchException_Service if where Argument is empty or is not an array - * @throws Core_MaarchException_Service if set Argument is empty or is not an array - * @throws Core_MaarchException_Service if data Argument is not an array - * - * @return bool - */ - public static function update(array $args = []){ - if (empty($args['table']) || !is_string($args['table'])) { - throw new Core_MaarchException_Service('Table Argument is empty or is not a string.'); - } - if (empty($args['set']) || !is_array($args['set'])) { - throw new Core_MaarchException_Service('Set Argument is empty or is not an array.'); - } - if (empty($args['where']) || !is_array($args['where'])) { - throw new Core_MaarchException_Service('Where Argument is empty or is not an array.'); - } - - if (empty($args['data'])) { - $args['data'] = []; - } - if (!is_array($args['data'])) { - throw new Core_MaarchException_Service('Data Argument is not an array.'); - } - - $querySet = []; - $setData = []; - foreach ($args['set'] as $key => $value) { - $querySet[] = "{$key} = ?"; - $setData[] = $value; - } - $args['data'] = array_merge($setData, $args['data']); - - $queryExt = 'UPDATE ' .$args['table']. ' SET '.implode(',', $querySet). ' WHERE ' . implode(' AND ', $args['where']); - - $db = new Database(); - $db->query($queryExt, $args['data']); - - return true; - } - - /** - * Fonction de suppression dans la base de données - * @param array $args - * @throws Core_MaarchException_Service if Table Argument is empty or is not a string - * @throws Core_MaarchException_Service if Where Argument is empty or is not an array - * @throws Core_MaarchException_Service if Data Argument is not an array - * - * @return bool - */ - public static function deleteFrom(array $args = []){ - if (empty($args['table']) || !is_string($args['table'])) { - throw new Core_MaarchException_Service('Table Argument is empty or is not a string.'); - } - if (empty($args['where']) || !is_array($args['where'])) { - throw new Core_MaarchException_Service('Where Argument is empty or is not an array.'); - } - - if (empty($args['data'])) { - $args['data'] = []; - } - if (!is_array($args['data'])) { - throw new Core_MaarchException_Service('Data Argument is not an array.'); - } - - $queryExt = 'DELETE FROM ' .$args['table']. ' WHERE ' . implode(' AND ', $args['where']); - - $db = new Database(); - $db->query($queryExt, $args['data']); - - return true; - } -} diff --git a/composer.json b/composer.json index 572f0c1e082384c4ac67309fc0034e77873c2d44..7c04c632fd4e78ae9db74544504edf333b30789c 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "Attachments\\": "modules/attachments/", "Baskets\\": "modules/basket/", "Entities\\": "modules/entities/", + "Notes\\": "modules/notes/", "Notifications\\": "modules/notifications/", "Visa\\": "modules/visa/" } diff --git a/core/Controllers/ResController.php b/core/Controllers/ResController.php index f6ff7641a248a72203ce34fdf26d41308416f042..6b6bffd32181dd5ffaaa3f838777979b46207cd7 100644 --- a/core/Controllers/ResController.php +++ b/core/Controllers/ResController.php @@ -22,12 +22,12 @@ use Core\Models\DocserverModel; use Core\Models\DocserverTypeModel; use Core\Models\UserModel; use Core\Models\ResModel; +use Notes\Models\NoteModel; use Entities\Models\EntitiesModel; use Core\Controllers\DocserverController; use Core\Controllers\DocserverToolsController; require_once 'core/class/class_db_pdo.php'; -require_once 'modules/notes/Models/NotesModel.php'; class ResController { @@ -85,7 +85,7 @@ class ResController public function getNotesCountForCurrentUserById(RequestInterface $request, ResponseInterface $response, $aArgs) { - return $response->withJson(\NotesModel::countForCurrentUserByResId(['resId' => $aArgs['resId']])); + return $response->withJson(NoteModel::countForCurrentUserByResId(['resId' => $aArgs['resId']])); } /** @@ -251,8 +251,7 @@ class ResController if ($return) { $id = $aArgs['res_id']; $obj = ResModel::getById([ - 'resId' => $id, - 'orderBy' => 'res_id' + 'resId' => $id ]); } else { return $response @@ -289,8 +288,7 @@ class ResController if ($return) { $id = $aArgs['res_id']; $obj = ResModel::getById([ - 'resId' => $id, - 'orderBy' => 'res_id' + 'resId' => $id ]); } else { return $response diff --git a/core/Controllers/ResExtController.php b/core/Controllers/ResExtController.php index b63720bade170512d08a5564a955c9022a72b270..6fd422ebc8a81fb219219eaa43b92d093101b246 100644 --- a/core/Controllers/ResExtController.php +++ b/core/Controllers/ResExtController.php @@ -15,6 +15,7 @@ namespace Core\Controllers; +use Apps\Models\ContactModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Respect\Validation\Validator; @@ -242,8 +243,6 @@ class ResExtController } require_once 'apps/maarch_entreprise/class/class_chrono.php'; $chronoX = new \chrono(); - require_once 'apps/maarch_entreprise/Models/ContactsModel.php'; - $contacts = new \ContactsModel(); for ($i=0; $i<count($data); $i++) { if (strtoupper($data[$i]['type']) == 'INTEGER' || strtoupper($data[$i]['type']) == 'FLOAT' @@ -281,7 +280,7 @@ class ResExtController ) { $theString = str_replace(">", "", $data[$i]['value']); $mail = explode("<", $theString); - $contactDetails =$contacts->getByEmail([ + $contactDetails = ContactModel::getByEmail([ 'email' => $mail[count($mail) -1], 'select' => ['contact_id'] ]); @@ -298,7 +297,7 @@ class ResExtController ) { $theString = str_replace(">", "", $data[$i]['value']); $mail = explode("<", $theString); - $contactDetails =$contacts->getByEmail([ + $contactDetails = ContactModel::getByEmail([ 'email' => $mail[count($mail) -1], 'select' => ['ca_id'] ]); diff --git a/core/Models/DocserverModelAbstract.php b/core/Models/DocserverModelAbstract.php index d70f08e98e4adb88a2562cd57f00de8f04aff9c2..1cd7708984d2200b627fb16aff2f7faa43ee5442 100644 --- a/core/Models/DocserverModelAbstract.php +++ b/core/Models/DocserverModelAbstract.php @@ -15,13 +15,11 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class DocserverModelAbstract extends \Apps_Table_Service +class DocserverModelAbstract { public static function getList() { - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['docservers'], ]); @@ -31,10 +29,10 @@ class DocserverModelAbstract extends \Apps_Table_Service public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_id']); - static::checkString($aArgs, ['docserver_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_id']); + ValidatorModel::stringType($aArgs, ['docserver_id']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['docservers'], 'where' => ['docserver_id = ?'], @@ -46,65 +44,67 @@ class DocserverModelAbstract extends \Apps_Table_Service public static function getByTypeId(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_type_id']); - static::checkString($aArgs, ['docserver_type_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_type_id']); + ValidatorModel::stringType($aArgs, ['docserver_type_id']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['docservers'], 'where' => ['docserver_type_id = ?'], 'data' => [$aArgs['docserver_type_id']] ]); - return $aReturn; + return $aReturn[0]; } public static function create(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_id']); - static::checkString($aArgs, ['docserver_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_id']); + ValidatorModel::stringType($aArgs, ['docserver_id']); - $aReturn = static::insertInto($aArgs, 'docservers'); + DatabaseModel::insert([ + 'table' => 'docservers', + 'columnsValues' => $aArgs + ]); - return $aReturn; + return true; } public static function update(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_id']); - static::checkString($aArgs, ['docserver_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_id']); + ValidatorModel::stringType($aArgs, ['docserver_id']); - $where['docserver_id'] = $aArgs['docserver_id']; - - $aReturn = static::updateTable( - $aArgs, - 'docservers', - $where - ); + DatabaseModel::update([ + 'table' => 'docservers', + 'set' => $aArgs, + 'where' => ['docserver_id = ?'], + 'data' => [$aArgs['docserver_id']] + ]); - return $aReturn; + return true; } public static function delete(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_id']); - static::checkString($aArgs, ['docserver_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_id']); + ValidatorModel::stringType($aArgs, ['docserver_id']); - $aReturn = static::deleteFrom([ - 'table' => 'docservers', - 'where' => ['docserver_id = ?'], - 'data' => [$aArgs['id']] - ]); + DatabaseModel::delete([ + 'table' => 'docservers', + 'where' => ['docserver_id = ?'], + 'data' => [$aArgs['docserver_id']] + ]); - return $aReturn; + return true; } public static function getDocserverToInsert(array $aArgs = []) { - static::checkRequired($aArgs, ['collId']); - static::checkString($aArgs, ['collId']); + ValidatorModel::notEmpty($aArgs, ['collId']); + ValidatorModel::stringType($aArgs, ['collId']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => ['*'], 'table' => ['docservers'], 'where' => ["is_readonly = 'N' and enabled = 'Y' and coll_id = ?"], diff --git a/core/Models/DocserverTypeModelAbstract.php b/core/Models/DocserverTypeModelAbstract.php index 2dd223fede41605836d5b61dc600b73c6955fe2c..2ef070edb0cae9727bd962c85592f7184d42fe8a 100644 --- a/core/Models/DocserverTypeModelAbstract.php +++ b/core/Models/DocserverTypeModelAbstract.php @@ -15,13 +15,11 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class DocserverTypeModelAbstract extends \Apps_Table_Service +class DocserverTypeModelAbstract { public static function getList() { - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['docserver_types'], ]); @@ -31,10 +29,11 @@ class DocserverTypeModelAbstract extends \Apps_Table_Service public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_type_id']); - static::checkString($aArgs, ['docserver_type_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_type_id']); + ValidatorModel::stringType($aArgs, ['docserver_type_id']); + - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['docserver_types'], 'where' => ['docserver_type_id = ?'], @@ -46,41 +45,43 @@ class DocserverTypeModelAbstract extends \Apps_Table_Service public static function create(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_type_id']); - static::checkString($aArgs, ['docserver_type_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_type_id']); + ValidatorModel::stringType($aArgs, ['docserver_type_id']); - $aReturn = static::insertInto($aArgs, 'docserver_types'); + DatabaseModel::insert([ + 'table' => 'docserver_types', + 'columnsValues' => $aArgs + ]); - return $aReturn; + return true; } public static function update(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_type_id']); - static::checkString($aArgs, ['docserver_type_id']); - - $where['docserver_type_id'] = $aArgs['docserver_type_id']; + ValidatorModel::notEmpty($aArgs, ['docserver_type_id']); + ValidatorModel::stringType($aArgs, ['docserver_type_id']); - $aReturn = static::updateTable( - $aArgs, - 'docserver_types', - $where - ); + DatabaseModel::update([ + 'table' => 'docserver_types', + 'set' => $aArgs, + 'where' => ['docserver_type_id = ?'], + 'data' => [$aArgs['docserver_type_id']] + ]); - return $aReturn; + return true; } public static function delete(array $aArgs = []) { - static::checkRequired($aArgs, ['docserver_type_id']); - static::checkString($aArgs, ['docserver_type_id']); + ValidatorModel::notEmpty($aArgs, ['docserver_type_id']); + ValidatorModel::stringType($aArgs, ['docserver_type_id']); - $aReturn = static::deleteFrom([ + DatabaseModel::delete([ 'table' => 'docserver_types', 'where' => ['docserver_type_id = ?'], 'data' => [$aArgs['docserver_type_id']] - ]); + ]); - return $aReturn; + return true; } } diff --git a/core/Models/GroupModelAbstract.php b/core/Models/GroupModelAbstract.php index 199fafcfa79eee8bad633503169736104b67041d..5c6f4148f166a02cf8e19c303ecae9ef3fb73d71 100644 --- a/core/Models/GroupModelAbstract.php +++ b/core/Models/GroupModelAbstract.php @@ -15,13 +15,11 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class GroupModelAbstract extends \Apps_Table_Service +class GroupModelAbstract { public static function get(array $aArgs = []) { - $aGroups = static::select([ + $aGroups = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['usergroups'], 'where' => ['enabled = ?'], @@ -33,10 +31,10 @@ class GroupModelAbstract extends \Apps_Table_Service public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['groupId']); - static::checkString($aArgs, ['groupId']); + ValidatorModel::notEmpty($aArgs, ['groupId']); + ValidatorModel::stringType($aArgs, ['groupId']); - $aGroups = static::select([ + $aGroups = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['usergroups'], 'where' => ['group_id = ?'], @@ -52,8 +50,8 @@ class GroupModelAbstract extends \Apps_Table_Service public static function getAvailableGroupsByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId']); - static::checkString($aArgs, ['userId']); + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); $rawUserGroups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); @@ -62,7 +60,7 @@ class GroupModelAbstract extends \Apps_Table_Service $userGroups[] = $value['group_id']; } - $allGroups = self::get(['select' => ['group_id', 'group_desc']]); + $allGroups = GroupModel::get(['select' => ['group_id', 'group_desc']]); foreach ($allGroups as $key => $value) { if (in_array($value['group_id'], $userGroups)) { diff --git a/core/Models/HistoryModelAbstract.php b/core/Models/HistoryModelAbstract.php index 2351e84a4cc8b40abf8f0db6a21892e2449e95e0..bebc0ea94ebed96711f4b9ce7792ef48e06d42b0 100644 --- a/core/Models/HistoryModelAbstract.php +++ b/core/Models/HistoryModelAbstract.php @@ -18,9 +18,8 @@ namespace Core\Models; use Core\Controllers\HistoryController; require_once('apps/maarch_entreprise/tools/log4php/Logger.php'); -require_once 'apps/maarch_entreprise/services/Table.php'; -class HistoryModelAbstract extends \Apps_Table_Service +class HistoryModelAbstract { /** diff --git a/core/Models/ResExtModelAbstract.php b/core/Models/ResExtModelAbstract.php index d673194e041979b4d99cb612356e3fd5039cc4d2..adad157864a882f89b376a7775577307e88e4ba3 100644 --- a/core/Models/ResExtModelAbstract.php +++ b/core/Models/ResExtModelAbstract.php @@ -15,21 +15,18 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class ResExtModelAbstract extends \Apps_Table_Service +class ResExtModelAbstract { /** * Retrieve info of resId - * @param $resId integer - * @param $table string - * @param $select string - * @return array $res + * @param $aArgs array + * + * @return array */ - public static function getById(array $aArgs = []) + public static function getById(array $aArgs) { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); if (!empty($aArgs['table'])) { $table = $aArgs['table']; @@ -37,7 +34,7 @@ class ResExtModelAbstract extends \Apps_Table_Service $table = 'mlb_coll_ext'; } - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => [$table], 'where' => ['res_id = ?'], @@ -49,9 +46,9 @@ class ResExtModelAbstract extends \Apps_Table_Service /** * Retrieve info of last resId - * @param $table string - * @param $select string - * @return array $res + * @param $aArgs array + * + * @return array */ public static function getLastId(array $aArgs = []) { @@ -61,10 +58,9 @@ class ResExtModelAbstract extends \Apps_Table_Service $table = 'mlb_coll_ext'; } - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => [$table], - 'data' => [$aArgs['resId']], 'order_by' => ['res_id desc'], 'limit' => 1, ]); @@ -74,23 +70,22 @@ class ResExtModelAbstract extends \Apps_Table_Service /** * Retrieve process_limit_date for resource in extension table if mlb - * @param $resId integer - * @param $defaultDelay integer - * @param $calendarType sring => calendar or workingDay + * @param $aArgs array + * * @return integer $processLimitDate */ - public function retrieveProcessLimitDate($aArgs) + public function retrieveProcessLimitDate(array $aArgs) { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + if (!empty($aArgs['table'])) { $table = $aArgs['table']; } else { $table = 'res_view_letterbox'; } - $processLimitDate = ''; $aArgs['select'] = ['creation_date, admission_date, type_id']; - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => [$table], 'where' => ['res_id = ?'], @@ -104,7 +99,7 @@ class ResExtModelAbstract extends \Apps_Table_Service $admissionDate = $aReturn[0]['admission_date']; $creationDate = $aReturn[0]['creation_date']; $aArgs['select'] = ['process_delay']; - $aReturnT = static::select([ + $aReturnT = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['mlb_doctype_ext'], 'where' => ['type_id = ?'], @@ -156,9 +151,9 @@ class ResExtModelAbstract extends \Apps_Table_Service /** * insert into a resTable - * @param $resId integer - * @param $table string - * @return boolean $status + * @param $aArgs array + * + * @return boolean */ public static function create(array $aArgs = []) { @@ -166,32 +161,35 @@ class ResExtModelAbstract extends \Apps_Table_Service $aArgs['table'] = 'mlb_coll_ext'; } - $aReturn = static::insertInto($aArgs['data'], $aArgs['table']); + DatabaseModel::insert([ + 'table' => $aArgs['table'], + 'columnsValues' => $aArgs['data'] + ]); - return $aReturn; + return true; } /** * deletes into a resTable - * @param $resId integer - * @param $table string - * @return boolean $status + * @param $aArgs array + * + * @return boolean */ - public static function delete(array $aArgs = []) + public static function delete(array $aArgs) { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); if (empty($aArgs['table'])) { $aArgs['table'] = 'mlb_coll_ext'; } - $aReturn = static::deleteFrom([ + DatabaseModel::delete([ 'table' => $aArgs['table'], 'where' => ['res_id = ?'], 'data' => [$aArgs['id']] - ]); + ]); - return $aReturn; + return true; } } diff --git a/core/Models/ResModelAbstract.php b/core/Models/ResModelAbstract.php index ae7bc624cf37c3382947abb3f0b2ea8e529a9796..aa9c2de3c140b8a5053a4a0161781f082027ef3c 100644 --- a/core/Models/ResModelAbstract.php +++ b/core/Models/ResModelAbstract.php @@ -15,43 +15,42 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class ResModelAbstract extends \Apps_Table_Service +class ResModelAbstract { /** * Retrieve info of resId - * @param $resId integer - * @param $table string - * @param $select string + * @param $aArgs array + * * @return array $res */ public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + ValidatorModel::stringType($aArgs, ['table']); - if (!empty($aArgs['table'])) { - $table = $aArgs['table']; - } else { - $table = 'res_letterbox'; + if (empty($aArgs['table'])) { + $aArgs['table'] = 'res_letterbox'; } - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => [$table], + 'table' => [$aArgs['table']], 'where' => ['res_id = ?'], - 'data' => [$aArgs['resId']], - 'order_by' => [$aArgs['orderBy']] + 'data' => [$aArgs['resId']] ]); - return $aReturn; + if (empty($aReturn[0])) { + return []; + } + + return $aReturn[0]; } /** * Retrieve info of last resId - * @param $table string - * @param $select string + * @param $aArgs array + * @return array $res */ public static function getLastId(array $aArgs = []) @@ -62,7 +61,7 @@ class ResModelAbstract extends \Apps_Table_Service $table = 'res_letterbox'; } - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => [$table], 'data' => [$aArgs['resId']], @@ -75,18 +74,15 @@ class ResModelAbstract extends \Apps_Table_Service /** * Retrieve info of resId by path - * @param $docserverId string - * @param $path string - * @param $filename string - * @param $table string - * @param $select string + * @param $aArgs array + * * @return array $res */ public static function getByPath(array $aArgs = []) { - static::checkRequired($aArgs, ['docserverId']); - static::checkRequired($aArgs, ['path']); - static::checkRequired($aArgs, ['filename']); + ValidatorModel::notEmpty($aArgs, ['docserverId', 'path', 'filename']); + ValidatorModel::stringType($aArgs, ['docserverId', 'path', 'filename', 'table']); + if (!empty($aArgs['table'])) { $table = $aArgs['table']; @@ -94,7 +90,7 @@ class ResModelAbstract extends \Apps_Table_Service $table = 'res_letterbox'; } - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => [$table], 'where' => ['docserver_id = ? and path = ? and filename = ?'], @@ -107,80 +103,87 @@ class ResModelAbstract extends \Apps_Table_Service /** * insert into a resTable - * @param $resId integer - * @param $table string - * @param $data array - * @return boolean $status + * @param $aArgs array + * + * @return boolean */ public static function create(array $aArgs = []) { + ValidatorModel::notEmpty($aArgs, ['data']); + ValidatorModel::arrayType($aArgs, ['data']); + ValidatorModel::stringType($aArgs, ['table']); + if (empty($aArgs['table'])) { $aArgs['table'] = 'res_letterbox'; } - $aReturn = static::insertInto($aArgs['data'], $aArgs['table']); + DatabaseModel::insert([ + 'table' => $aArgs['table'], + 'columnsValues' => $aArgs['data'] - return $aReturn; + ]); + + return true; } /** * deletes into a resTable - * @param $resId integer - * @param $table string - * @return boolean $status + * @param $aArgs array + * + * @return boolean */ public static function delete(array $aArgs = []) { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); + ValidatorModel::stringType($aArgs, ['table']); if (empty($aArgs['table'])) { $aArgs['table'] = 'res_letterbox'; } - $aReturn = static::deleteFrom([ - 'table' => $aArgs['table'], - 'where' => ['res_id = ?'], - 'data' => [$aArgs['id']] - ]); + DatabaseModel::delete([ + 'table' => $aArgs['table'], + 'where' => ['res_id = ?'], + 'data' => [$aArgs['id']] + ]); - return $aReturn; + return true; } /** * update a resTable - * @param $resId integer - * @param $table string - * @param $data array - * @return boolean $status + * @param $aArgs array + * + * @return boolean */ public static function update(array $aArgs = []) { - static::checkRequired($aArgs, ['res_id']); - static::checkNumeric($aArgs, ['res_id']); - - $where['res_id'] = $aArgs['res_id']; + ValidatorModel::notEmpty($aArgs, ['res_id']); + ValidatorModel::intVal($aArgs, ['res_id']); + ValidatorModel::stringType($aArgs, ['table']); + ValidatorModel::arrayType($aArgs, ['data']); if (empty($aArgs['table'])) { $aArgs['table'] = 'res_letterbox'; } - $aReturn = static::updateTable( - $aArgs['data'], - $aArgs['table'], - $where - ); + DatabaseModel::update([ + 'table' => $aArgs['table'], + 'set' => $aArgs['data'], + 'where' => ['res_id = ?'], + 'data' => [$aArgs['res_id']] + ]); - return $aReturn; + return true; } public static function isLockForCurrentUser(array $aArgs = []) { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); - + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => ['locker_user_id', 'locker_time'], 'table' => ['res_letterbox'], 'where' => ['res_id = ?'], diff --git a/core/Models/ServiceModelAbstract.php b/core/Models/ServiceModelAbstract.php index 3b1eb00c952cac950cdb70cb097d82b7dc2a4265..a19022811a04efd2bf56119552a2b0b5bc4b6a5a 100644 --- a/core/Models/ServiceModelAbstract.php +++ b/core/Models/ServiceModelAbstract.php @@ -15,13 +15,11 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class ServiceModelAbstract extends \Apps_Table_Service +class ServiceModelAbstract { public static function getApplicationAdministrationServicesByXML() { - $xmlfile = static::getLoadedXml(['location' => 'apps']); + $xmlfile = ServiceModel::getLoadedXml(['location' => 'apps']); $applicationServices = []; if ($xmlfile) { @@ -45,10 +43,10 @@ class ServiceModelAbstract extends \Apps_Table_Service public static function getApplicationAdministrationServicesByUserServices(array $aArgs = []) { - static::checkRequired($aArgs, ['userServices']); - static::checkArray($aArgs, ['userServices']); + ValidatorModel::notEmpty($aArgs, ['userServices']); + ValidatorModel::arrayType($aArgs, ['userServices']); - $xmlfile = static::getLoadedXml(['location' => 'apps']); + $xmlfile = ServiceModel::getLoadedXml(['location' => 'apps']); $applicationServices = []; if ($xmlfile) { @@ -83,7 +81,7 @@ class ServiceModelAbstract extends \Apps_Table_Service $xmlfile = simplexml_load_file($path); foreach ($xmlfile->MODULES as $mod) { $module = (string)$mod->moduleid; - $xmlModuleFile = static::getLoadedXml(['location' => $module]); + $xmlModuleFile = ServiceModel::getLoadedXml(['location' => $module]); if ($xmlModuleFile) { foreach ($xmlModuleFile->SERVICE as $value) { @@ -107,8 +105,8 @@ class ServiceModelAbstract extends \Apps_Table_Service public static function getModulesAdministrationServicesByUserServices(array $aArgs = []) { - static::checkRequired($aArgs, ['userServices']); - static::checkArray($aArgs, ['userServices']); + ValidatorModel::notEmpty($aArgs, ['userServices']); + ValidatorModel::arrayType($aArgs, ['userServices']); if (file_exists("custom/{$_SESSION['custom_override_id']}/apps/maarch_entreprise/xml/config.xml")) { //Todo No Session $path = "custom/{$_SESSION['custom_override_id']}/apps/maarch_entreprise/xml/config.xml"; @@ -121,7 +119,7 @@ class ServiceModelAbstract extends \Apps_Table_Service $xmlfile = simplexml_load_file($path); foreach ($xmlfile->MODULES as $mod) { $module = (string)$mod->moduleid; - $xmlModuleFile = static::getLoadedXml(['location' => $module]); + $xmlModuleFile = ServiceModel::getLoadedXml(['location' => $module]); if ($xmlModuleFile) { foreach ($xmlModuleFile->SERVICE as $value) { @@ -145,8 +143,8 @@ class ServiceModelAbstract extends \Apps_Table_Service public static function getAdministrationServicesByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId']); - static::checkString($aArgs, ['userId']); + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); $rawServicesStoredInDB = UserModel::getServicesById(['userId' => $aArgs['userId']]); $servicesStoredInDB = []; @@ -155,16 +153,16 @@ class ServiceModelAbstract extends \Apps_Table_Service } $administration = []; - $administration['application'] = static::getApplicationAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); - $administration['modules'] = static::getModulesAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); + $administration['application'] = ServiceModel::getApplicationAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); + $administration['modules'] = ServiceModel::getModulesAdministrationServicesByUserServices(['userServices' => $servicesStoredInDB]); return $administration; } public static function hasService(array $aArgs = []) { - static::checkRequired($aArgs, ['id', 'userId', 'location', 'type']); - static::checkString($aArgs, ['id', 'userId', 'location', 'type']); + ValidatorModel::notEmpty($aArgs, ['id', 'userId', 'location', 'type']); + ValidatorModel::stringType($aArgs, ['id', 'userId', 'location', 'type']); if ($aArgs['userId'] == 'superadmin') { return true; @@ -175,8 +173,7 @@ class ServiceModelAbstract extends \Apps_Table_Service $servicesStoredInDB[] = $value['service_id']; } - - $xmlfile = static::getLoadedXml(['location' => $aArgs['location']]); + $xmlfile = ServiceModel::getLoadedXml(['location' => $aArgs['location']]); if ($xmlfile) { foreach ($xmlfile->SERVICE as $value) { @@ -192,8 +189,8 @@ class ServiceModelAbstract extends \Apps_Table_Service protected static function getLoadedXml(array $aArgs = []) { - static::checkRequired($aArgs, ['location']); - static::checkString($aArgs, ['location']); + ValidatorModel::notEmpty($aArgs, ['location']); + ValidatorModel::stringType($aArgs, ['location']); if ($aArgs['location'] == 'apps') { if (file_exists("custom/{$_SESSION['custom_override_id']}/apps/maarch_entreprise/xml/services.xml")) { //Todo No Session diff --git a/core/Models/StatusImagesModelAbstract.php b/core/Models/StatusImagesModelAbstract.php index 943a44d5fd51ca384a27d3c178288159ddeb29b7..3ddfdac8f6700d959b2d67b84b7be3e15b652874 100644 --- a/core/Models/StatusImagesModelAbstract.php +++ b/core/Models/StatusImagesModelAbstract.php @@ -15,16 +15,14 @@ namespace Core\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class StatusImagesModelAbstract extends \Apps_Table_Service +class StatusImagesModelAbstract { public static function getStatusImages(array $aArgs = []) { - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['status_images'], - 'order_by' => 'id' + 'order_by' => ['id'] ]); return $aReturn; diff --git a/core/Models/UserModelAbstract.php b/core/Models/UserModelAbstract.php index cba24f81405a0ae466781a30fff2000bb50ef372..87e31e8c798b952beb22009995c455a9ec6116eb 100644 --- a/core/Models/UserModelAbstract.php +++ b/core/Models/UserModelAbstract.php @@ -345,8 +345,11 @@ class UserModelAbstract $docserver = DocserverModel::getByTypeId(['docserver_type_id' => 'TEMPLATES', 'select' => ['path_template']]); } + if (!file_exists($docserver['path_template'])) { + return []; + } foreach($aReturn as $key => $value) { - $pathToSignature = $docserver[0]['path_template'] . str_replace('#', '/', $value['signature_path']) . $value['signature_file_name']; + $pathToSignature = $docserver['path_template'] . str_replace('#', '/', $value['signature_path']) . $value['signature_file_name']; $extension = explode('.', $pathToSignature); $extension = $extension[count($extension) - 1]; diff --git a/core/services/Abstract.php b/core/services/Abstract.php deleted file mode 100644 index 8f7a8270bd9a05a877afaa07b1072b6995c3735a..0000000000000000000000000000000000000000 --- a/core/services/Abstract.php +++ /dev/null @@ -1,337 +0,0 @@ -<?php - -/** -* @copyright 2017 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/>. -*/ - -require_once 'core/class/class_core_tools.php'; -require_once 'core/services/MaarchException.php'; - -/** - * - */ -abstract class Core_Abstract_Service { - /** - * Récupération de la liste des méthodes disponibles via api - * - * @return string[] La liste des méthodes - */ - public static function getApiMethod() { - return [ - 'getApiMethod' => 'getApiMethod', - ]; - } - - /** - * Vérifie que l'user est bien les droits requis - * @param array $aRequired - * @return boolean true - * @throws Exception denied - **/ - protected static function checkAllow(array $aRequired) { - $core = new core_tools(); - foreach ($aRequired as $permission) { - if ( ! $core->test_service($permission, 'apps', false) ) { - throw new Core_MaarchException_Service('missing permission required : '.$permission); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien existant - * @param array $aArgs - * @param array $aRequired - * @param string $sErrorTxt - **/ - protected static function checkIsset(array $aArgs, $aRequired, $sErrorTxt='$required is not set') { - if ( is_string($aRequired) ) { - $aRequired = [$aRequired]; - } - if ( ! is_array($aRequired) ) { - throw new Core_MaarchException_Service("aRequired is not a array", 1); - } - foreach ($aRequired as $required) { - if ( !isset($aArgs[$required]) ) { - throw new Core_MaarchException_Service(str_replace('$required', $required, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien rempli - * @param array $aArgs - * @param array $aRequired - * @param string $sErrorTxt - **/ - protected static function checkRequired(array $aArgs, $aRequired, $sErrorTxt='$required is required') { - if ( is_string($aRequired) ) { - $aRequired = [$aRequired]; - } - if ( ! is_array($aRequired) ) { - throw new Core_MaarchException_Service("aRequired is not a array", 1); - } - foreach ($aRequired as $required) { - if ( !isset($aArgs[$required]) ) { - throw new Core_MaarchException_Service(str_replace('$required', $required, $sErrorTxt)); - } - if ( empty($aArgs[$required]) ) { - throw new Core_MaarchException_Service(str_replace('$required', $required, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un string - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkString(array $aArgs, $aTry, $sErrorTxt='$try must be a string') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_string($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un nombre - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkNumeric(array $aArgs, $aTry, $sErrorTxt='$try must be a number') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_numeric($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un tableau - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkArray(array $aArgs, $aTry, $sErrorTxt='$try must be a array') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_array($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou une instance - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkObject(array $aArgs, $aTry, $sErrorTxt='$try must be an instance') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_object($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - return true; - } - protected static function formatDatestring($sDate) { - $sDate = trim($sDate); - $sDate = preg_replace('#^(\w{2})/(\w{2})/(\w{4})\s(\d{2}):(\d{2})#', '$3-$2-$1 $4:$5:00', $sDate); - $sDate = preg_replace('#^(\w{2})/(\w{2})/(\w{4})$#', '$3-$2-$1', $sDate); - return $sDate; - } - - /** - * Vérifie que l'argument est bien inexistant ou un string representant une date - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkDatestring(array $aArgs, $aTry, $sErrorTxt='$try must be a date (string) : $value') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - self::checkString($aArgs, $aTry, $sErrorTxt); - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - $aArgs[$try] = trim($aArgs[$try]); - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! strtotime($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace(['$try','$value',], [$try,$aArgs[$try],], $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un objet Date - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkDateobject(array $aArgs, $aTry, $sErrorTxt='$try must be a date (instance)') { - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - self::checkObject($aArgs, $aTry, $sErrorTxt); - foreach ($aTry as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( $aArgs[$try] instanceof \Date || $aArgs[$try] instanceof \DateTime ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un tableau de string - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkArrayString(array $aArgs, $aTry, $sErrorTxt='$try must be a array of string') { - self::checkArray($aArgs, $aTry, $sErrorTxt); // Je testerai que la sous partie des tableaux, et je délégue la vérification du typage tableau - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $array) { - if ( empty($aArgs[$array]) ) { - continue; - } - foreach ($aArgs[$array] as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_string($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - } - return true; - } - - /** - * Vérifie que l'argument est bien inexistant ou un tableau de numeric - * @param array $aArgs - * @param array $aTry - * @param string $sErrorTxt - **/ - protected static function checkArrayNumeric(array $aArgs, $aTry, $sErrorTxt='$try must be a array of numeric') { - self::checkArray($aArgs, $aTry, $sErrorTxt); // Je testerai que la sous partie des tableaux, et je délégue la vérification du typage tableau - if ( is_string($aTry) ) { - $aTry = [$aTry]; - } - if ( ! is_array($aTry) ) { - throw new Core_MaarchException_Service("aTry is not a array", 1); - } - foreach ($aTry as $array) { - if ( empty($aArgs[$array]) ) { - continue; - } - foreach ($aArgs[$array] as $try) { - if ( !isset($aArgs[$try]) ) { - continue; - } - if ( empty($aArgs[$try]) ) { - continue; - } - if ( ! is_numeric($aArgs[$try]) ) { - throw new Core_MaarchException_Service(str_replace('$try', $try, $sErrorTxt)); - } - } - } - return true; - } -} diff --git a/core/services/CoreConfig.php b/core/services/CoreConfig.php deleted file mode 100644 index 449b67d10095285b0f713d6f2b28ee2432568f40..0000000000000000000000000000000000000000 --- a/core/services/CoreConfig.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** -* @copyright 2017 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/>. -*/ - -require_once 'core/services/CoreConfigAbstract.php'; - -/** - * Service de configuration du core - */ -class Core_CoreConfig_Service extends Core_CoreConfigAbstract_Service{ - // Do your stuff -} diff --git a/core/services/CoreConfigAbstract.php b/core/services/CoreConfigAbstract.php deleted file mode 100644 index 9517c87a361a5eee88c684c0761dbc0d2ccefd06..0000000000000000000000000000000000000000 --- a/core/services/CoreConfigAbstract.php +++ /dev/null @@ -1,905 +0,0 @@ -<?php - -/** -* @copyright 2017 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/>. -*/ - -require_once 'core' . DIRECTORY_SEPARATOR . 'services' . DIRECTORY_SEPARATOR . 'Abstract.php'; -require_once 'core' . DIRECTORY_SEPARATOR . 'services' . DIRECTORY_SEPARATOR . 'CoreConfig.php'; -require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_core_tools.php'; - -/** - * Service de configuration du core - */ -class Core_CoreConfigAbstract_Service extends Core_Abstract_Service { - /** - * Get TableName from the core/xml/config.xml file to load Maarch core configuration into session - * @param string $pathtoxmlcore path to the xml core config file - * @return array the list of TableName - */ - private static function getTableName($pathtoxmlcore) - { - $xmlconfig = simplexml_load_file($pathtoxmlcore); - $TABLENAME = $xmlconfig->TABLENAME ; - return $TABLENAME; - } - - /** - * Load Maarch core configuration into sessions vars from the core/xml/config.xml file - * @param string $pathtoxmlcore path to the xml core config file - */ - public static function buildCoreConfig($pathtoxmlcore) - { - // Get TableName from xml file - $TABLENAME = SELF::getTableName($pathtoxmlcore); - - // Loads core tables into session ($_SESSION['tablename'] array) - $_SESSION['tablename']['actions'] = (string) $TABLENAME->actions; - $_SESSION['tablename']['authors'] = (string) $TABLENAME->authors; - $_SESSION['tablename']['docservers'] = (string) $TABLENAME->docservers; - $_SESSION['tablename']['doctypes'] = (string) $TABLENAME->doctypes; - $_SESSION['tablename']['history'] = (string) $TABLENAME->history; - $_SESSION['tablename']['history_batch'] = (string) $TABLENAME->history_batch; - $_SESSION['tablename']['param'] = (string) $TABLENAME->param; - $_SESSION['tablename']['security'] = (string) $TABLENAME->security; - $_SESSION['tablename']['status'] = (string) $TABLENAME->status; - $_SESSION['tablename']['usergroups'] = (string) $TABLENAME->usergroups; - $_SESSION['tablename']['usergroup_content'] = (string) $TABLENAME->usergroupcontent; - $_SESSION['tablename']['usergroup_services'] = (string) $TABLENAME->usergroups_services; - $_SESSION['tablename']['users'] = (string) $TABLENAME->users; - } - - /** - * Build Maarch business app configuration into sessions vars with a xml - * configuration file - */ - public static function buildBusinessAppConfig() - { - // build Maarch business app configuration into sessions vars - - $core = new core_tools(); - - // $_SESSION['config']['app_id']='maarch_entreprise'; - require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_business_app_tools.php'; - $businessAppTools = new business_app_tools(); - - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'apps' - . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'config.xml' - ) - ) { - $path = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR - . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'xml' - . DIRECTORY_SEPARATOR . 'config.xml'; - } else { - $path = 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR - . 'config.xml'; - } - $xmlconfig = @simplexml_load_file($path); - if ( ! $xmlconfig ) { - throw new \Exception('conf not-found : '.$path); - } - if ($xmlconfig <> false) { - $config = $xmlconfig->CONFIG; - $uriBeginning = strpos($_SERVER['SCRIPT_NAME'], 'apps'); - if (empty($uriBeginning)) { - $_SESSION['config']['businessappurl'] = $_SESSION['config']['coreurl'] - . 'apps/maarch_entreprise/'; - } else { - $url = $_SESSION['config']['coreurl'] - .substr($_SERVER['SCRIPT_NAME'], $uriBeginning); - $_SESSION['config']['businessappurl'] = str_replace( - 'index.php', '', $url - ); - } - - //echo $_SESSION['config']['businessappurl'];exit; - - $_SESSION['config']['databaseserver'] = - (string) $config->databaseserver; - $_SESSION['config']['databaseserverport'] = - (string) $config->databaseserverport; - $_SESSION['config']['databasetype'] = - (string) $config->databasetype; - $_SESSION['config']['databasename'] = - (string) $config->databasename; - $_SESSION['config']['databaseschema'] = - (string) $config->databaseschema; - $_SESSION['config']['databaseuser'] = - (string) $config->databaseuser; - $_SESSION['config']['databasepassword'] = - (string) $config->databasepassword; - $_SESSION['config']['databasesearchlimit'] = - (string) $config->databasesearchlimit; - $_SESSION['config']['nblinetoshow'] = - (string) $config->nblinetoshow; - $_SESSION['config']['limitcharsearch'] = - (string) $config->limitcharsearch; - $_SESSION['config']['lang'] = (string) $config->lang; - $_SESSION['config']['adminmail'] = (string) $config->adminmail; - $_SESSION['config']['adminname'] = (string) $config->adminname; - $_SESSION['config']['debug'] = (string) $config->debug; - $_SESSION['config']['applicationname'] = (string) $config->applicationname; - $_SESSION['config']['defaultPage'] = (string) $config->defaultPage; - $_SESSION['config']['exportdirectory'] = (string) $config->exportdirectory; - $_SESSION['config']['cookietime'] = (string) $config->CookieTime; - $_SESSION['config']['ldap'] = (string) $config->ldap; - $_SESSION['config']['userdefaultpassword'] = (string) $config->userdefaultpassword; - $_SESSION['config']['usePDO'] = (string) $config->usePDO; - $_SESSION['config']['usePHPIDS'] = (string) $config->usePHPIDS; - if (isset($config->showfooter)) { - $_SESSION['config']['showfooter'] = (string) $config->showfooter; - } else { - $_SESSION['config']['showfooter'] = 'true'; - } - //$_SESSION['config']['databaseworkspace'] = (string) $config->databaseworkspace; - - $tablename = $xmlconfig->TABLENAME; - $_SESSION['tablename']['doctypes_first_level'] = (string) $tablename->doctypes_first_level; - $_SESSION['tablename']['doctypes_second_level'] = (string) $tablename->doctypes_second_level; - $_SESSION['tablename']['mlb_doctype_ext'] = (string) $tablename->mlb_doctype_ext; - $_SESSION['tablename']['doctypes_indexes'] = (string) $tablename->doctypes_indexes; - $_SESSION['tablename']['saved_queries'] = (string) $tablename->saved_queries; - $_SESSION['tablename']['contacts_v2'] = (string) $tablename->contacts_v2; - $_SESSION['tablename']['contact_types'] = (string) $tablename->contact_types; - $_SESSION['tablename']['contact_purposes'] = (string) $tablename->contact_purposes; - $_SESSION['tablename']['contact_addresses'] = (string) $tablename->contact_addresses; - $_SESSION['tablename']['tags'] = (string) $tablename->tags; - - $_SESSION['config']['tmppath'] = $_SESSION['config']['corepath'] . 'apps' - . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; - - $i = 0; - - if ( isset($_SESSION['custom_override_id']) && file_exists( - 'custom/' . $_SESSION['custom_override_id'] . '/' - . $_SESSION['config']['lang'] . '.php' - ) - ) { - include_once 'custom/' . $_SESSION['custom_override_id'] . '/' - . $_SESSION['config']['lang'] . '.php'; - } - include_once 'apps' . DIRECTORY_SEPARATOR - . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR - . 'lang' . DIRECTORY_SEPARATOR . $_SESSION['config']['lang'] - . '.php'; - $_SESSION['collections'] = array(); - $_SESSION['coll_categories'] = array(); - foreach ($xmlconfig->COLLECTION as $col) { - $tmp = (string) $col->label; - if (!empty($tmp) && defined($tmp) && constant($tmp) <> NULL) { - $tmp = constant($tmp); - } - $extensions = $col->extensions; - $collId = (string) $col->id; - $tab = array(); - - if ($extensions->count()) { - $extensionTables = $extensions->table; - if ($extensionTables->count() > 0) { - foreach ($extensions->table as $table) { - if (strlen($extensionTables) > 0) { - array_push($tab, (string) $table); - } - } - } - } - if (isset($col->table) && ! empty($col->table)) { - $_SESSION['collections'][$i] = array( - 'id' => (string) $col->id, - 'label' => (string) $tmp, - 'table' => (string) $col->table, - 'version_table' => (string) $col->version_table, - 'view' => (string) $col->view, - 'adr' => (string) $col->adr, - 'index_file' => (string) $col->index_file, - 'script_add' => (string) $col->script_add, - 'script_search' => (string) $col->script_search, - 'script_search_result' => (string) $col->script_search_result, - 'script_details' => (string) $col->script_details, - 'path_to_lucene_index' => (string) $col->path_to_lucene_index, - 'extensions' => $tab, - ); - - $categories = $col->categories; - - if (count($categories) > 0) { - foreach ($categories->category as $cat) { - $label = (string) $cat->label; - if (!empty($label) && defined($label) - && constant($label) <> NULL - ) { - $label = constant($label); - } - $_SESSION['coll_categories'][$collId][(string) $cat->id] = $label; - } - $_SESSION['coll_categories'][$collId]['default_category'] = (string) $categories->default_category; - } - $i++; - } else { - $_SESSION['collections'][$i] = array( - 'id' => (string) $col->id, - 'label' => (string) $tmp, - 'view' => (string) $col->view, - 'adr' => (string) $col->adr, - 'index_file' => (string) $col->index_file, - 'script_add' => (string) $col->script_add, - 'script_search' => (string) $col->script_search, - 'script_search_result' => (string) $col->script_search_result, - 'script_details' => (string) $col->script_details, - 'path_to_lucene_index' => (string) $col->path_to_lucene_index, - 'extensions' => $tab, - ); - } - } - $history = $xmlconfig->HISTORY; - $_SESSION['history']['usersdel'] = (string) $history->usersdel; - $_SESSION['history']['usersban'] = (string) $history->usersban; - $_SESSION['history']['usersadd'] = (string) $history->usersadd; - $_SESSION['history']['usersup'] = (string) $history->usersup; - $_SESSION['history']['usersval'] = (string) $history->usersval; - $_SESSION['history']['doctypesdel'] = (string) $history->doctypesdel; - $_SESSION['history']['doctypesadd'] = (string) $history->doctypesadd; - $_SESSION['history']['doctypesup'] = (string) $history->doctypesup; - $_SESSION['history']['doctypesval'] = (string) $history->doctypesval; - $_SESSION['history']['doctypesprop'] = (string) $history->doctypesprop; - $_SESSION['history']['usergroupsdel'] = (string) $history->usergroupsdel; - $_SESSION['history']['usergroupsban'] = (string) $history->usergroupsban; - $_SESSION['history']['usergroupsadd'] = (string) $history->usergroupsadd; - $_SESSION['history']['usergroupsup'] = (string) $history->usergroupsup; - $_SESSION['history']['usergroupsval'] = (string) $history->usergroupsval; - $_SESSION['history']['structuredel'] = (string) $history->structuredel; - $_SESSION['history']['structureadd'] = (string) $history->structureadd; - $_SESSION['history']['structureup'] = (string) $history->structureup; - $_SESSION['history']['subfolderdel'] = (string) $history->subfolderdel; - $_SESSION['history']['subfolderadd'] = (string) $history->subfolderadd; - $_SESSION['history']['subfolderup'] = (string) $history->subfolderup; - $_SESSION['history']['resadd'] = (string) $history->resadd; - $_SESSION['history']['resup'] = (string) $history->resup; - $_SESSION['history']['resdel'] = (string) $history->resdel; - $_SESSION['history']['resview'] = (string) $history->resview; - $_SESSION['history']['userlogin'] = (string) $history->userlogin; - $_SESSION['history']['userlogout'] = (string) $history->userlogout; - $_SESSION['history']['actionadd'] = (string) $history->actionadd; - $_SESSION['history']['actionup'] = (string) $history->actionup; - $_SESSION['history']['actiondel'] = (string) $history->actiondel; - $_SESSION['history']['contactadd'] = (string) $history->contactadd; - $_SESSION['history']['contactup'] = (string) $history->contactup; - $_SESSION['history']['contactdel'] = (string) $history->contactdel; - $_SESSION['history']['statusadd'] = (string) $history->statusadd; - $_SESSION['history']['statusup'] = (string) $history->statusup; - $_SESSION['history']['statusdel'] = (string) $history->statusdel; - $_SESSION['history']['docserversadd'] = (string) $history->docserversadd; - $_SESSION['history']['docserversdel'] = (string) $history->docserversdel; - $_SESSION['history']['docserversallow'] = (string) $history->docserversallow; - $_SESSION['history']['docserversban'] = (string) $history->docserversban; - //$_SESSION['history']['docserversclose'] = (string) $history->docserversclose; - $_SESSION['history']['docserverslocationsadd'] = (string) $history->docserverslocationsadd; - $_SESSION['history']['docserverslocationsdel'] = (string) $history->docserverslocationsdel; - $_SESSION['history']['docserverslocationsallow'] = (string) $history->docserverslocationsallow; - $_SESSION['history']['docserverslocationsban'] = (string) $history->docserverslocationsban; - $_SESSION['history']['docserverstypesadd'] = (string) $history->docserverstypesadd; - $_SESSION['history']['docserverstypesdel'] = (string) $history->docserverstypesdel; - $_SESSION['history']['docserverstypesallow'] = (string) $history->docserverstypesallow; - $_SESSION['history']['docserverstypesban'] = (string) $history->docserverstypesban; - $_SESSION['history']['contact_types_del'] = (string) $history->contact_types_del; - $_SESSION['history']['contact_types_add'] = (string) $history->contact_types_add; - $_SESSION['history']['contact_types_up'] = (string) $history->contact_types_up; - $_SESSION['history']['contact_purposes_del'] = (string) $history->contact_purposes_del; - $_SESSION['history']['contact_purposes_add'] = (string) $history->contact_purposes_add; - $_SESSION['history']['contact_purposes_up'] = (string) $history->contact_purposes_up; - $_SESSION['history']['contact_addresses_del'] = (string) $history->contact_addresses_del; - $_SESSION['history']['contact_addresses_add'] = (string) $history->contact_addresses_add; - $_SESSION['history']['contact_addresses_up'] = (string) $history->contact_addresses_up; - $_SESSION['history_keywords'] = array(); - foreach ($xmlconfig->KEYWORDS as $keyword) { - $tmp = (string) $keyword->label; - if (!empty($tmp) && defined($tmp) && constant($tmp) <> NULL) { - $tmp = constant($tmp); - } - - array_push( - $_SESSION['history_keywords'], - array( - 'id' => (string) $keyword->id, - 'label' => $tmp, - ) - ); - } - - $i = 0; - foreach ($xmlconfig->MODULES as $modules) { - - $_SESSION['modules'][$i] = array( - 'moduleid' => (string) $modules->moduleid, - //,"comment" => (string) $MODULES->comment - ); - $i ++; - } - $businessAppTools->_loadActionsPages(); - } - - if ($_SESSION['config']['usePHPIDS'] == 'true') { - $businessAppTools->_loadPHPIDSExludes(); - } - } - - /** - * Load Maarch modules configuration into sessions vars from modules/module_name/xml/config.xml files - * @param array $modules Enabled modules of the application - * @param boolean $mode_batch [description] - */ - public static function loadModulesConfig($modules, $mode_batch=false) - { - require_once "core/class/class_request.php"; - $coreTools = new core_tools(); - - // Browses enabled modules - for ($i = 0; $i < count($modules); $i ++) { - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR - . 'modules' . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR - . "config.xml" - ) - ) { - $configPath = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "config.xml"; - } else { - $configPath = 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "config.xml"; - } - - if (file_exists('modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php')) { - include_once 'modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php'; - } - - // Reads the config.xml file of the current module - if ( ! file_exists($configPath) ) { - throw new \Exception($configPath.' not-found'); - } - - $xmlconfig = simplexml_load_file($configPath); - // Loads into $_SESSION['modules_loaded'] module's informations - foreach ($xmlconfig->CONFIG as $CONFIG) { - $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['name'] = - (string) $CONFIG->name; - $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['path'] = - 'modules' . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR; - $comment = (string) $CONFIG->comment; - if ( !empty($comment) && defined($comment) - && constant($comment) <> NULL - ) { - $comment = constant($comment); - } - $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['comment'] = - $comment; - - $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['fileprefix'] = (string) $CONFIG->fileprefix; - $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['loaded'] = (string) $CONFIG->loaded; - } - - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php" - ) - ) { - $path_module_tools = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php"; - } else { - $path_module_tools = 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php"; - } - - if (file_exists($path_module_tools)) { - require_once($path_module_tools); - $modules_tools = new $modules[$i]['moduleid']; - //Loads the tables of the module into session - $modules_tools->build_modules_tables(); - //Loads log keywords of the module - } - - foreach ($xmlconfig->KEYWORDS as $keyword) { - $tmp = (string) $keyword->label; - if ( !empty($tmp) && defined($tmp) && constant($tmp) <> NULL ) { - $tmp = constant($tmp); - } - - $id = (string) $keyword->id; - - if (!$coreTools->is_var_in_history_keywords_tab($id)) { - array_push( - $_SESSION['history_keywords'], - array( - 'id' => $id, - 'label' => $tmp - ) - ); - } - } - } - -// if (!$mode_batch) { -// //Loads logs keywords of the actions -// $db = new Database(); -// $stmt = $db->query( -// "select id, label_action from " -// . $_SESSION['tablename']['actions'] -// . " where enabled = 'Y' and history = 'Y'" -// ); -// while ($res = $stmt->fetchObject()) { -// array_push( -// $_SESSION['history_keywords'], -// array( -// 'id' =>'ACTION#' . $res->id, -// 'label' => $coreTools->show_string($res->label_action) -// ) -// ); -// } -// } - } - - /** - * Loads the modules specific vars into session - * @param array $modules Enabled modules of the application - * @param array $userData [description] - */ - public static function loadVarSession($modules, $userData) - { - for ($i = 0; $i < count($modules); $i ++) { - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php" - ) - ) { - $path_module_tools = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php"; - } else { - $path_module_tools = 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "class" - . DIRECTORY_SEPARATOR . "class_modules_tools.php"; - } - if (file_exists($path_module_tools)) { - require_once $path_module_tools; - $modules_tools = new $modules[$i]['moduleid']; - if (method_exists( - $modules[$i]['moduleid'], 'load_module_var_session' - ) - ) { - $modules_tools->load_module_var_session($userData); - } - } - //$coreTools = new core_tools(); - //$coreTools->show_array($_SESSION['user']['baskets']); - } - } - - /** - * Loads menu items of each module and the application into session from menu.xml files - * @param array $modules Enabled modules of the application - * @return string [description] - */ - public static function loadMenu($modules) - { - $k = 0; - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'apps' - . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'menu.xml' - ) - ) { - $path = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR - . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'xml' - . DIRECTORY_SEPARATOR . 'menu.xml'; - } else { - $path = 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'menu.xml'; - } - // Reads the apps/apps_name/xml/menu.xml file and loads into session - $xmlconfig = simplexml_load_file($path); - foreach ($xmlconfig->MENU as $MENU2) { - $_SESSION['menu'][$k]['id'] = (string) $MENU2->id; - if (isset($_SESSION['menu'][$k]['id']) - && isset($_SESSION['user']['services'][$_SESSION['menu'][$k]['id']]) - && $_SESSION['user']['services'][$_SESSION['menu'][$k]['id']] == true - ) { // Menu Identifier must be equal to the Service identifier - $libmenu = (string) $MENU2->libconst; - if ( !empty($libmenu) && defined($libmenu) - && constant($libmenu) <> NULL - ) { - $libmenu = constant($libmenu); - } - $_SESSION['menu'][$k]['libconst'] = $libmenu; - $_SESSION['menu'][$k]['url'] = $_SESSION['config']['businessappurl'] - . (string) $MENU2->url; - if (trim((string) $MENU2->target) <> "") { - $tmp = preg_replace( - '/\/core\/$/', '/', $_SESSION['urltocore'] - ); - $_SESSION['menu'][$k]['url'] = $tmp. (string) $MENU2->url; - $_SESSION['menu'][$k]['target'] = (string) $MENU2->target; - } - $_SESSION['menu'][$k]['style'] = (string) $MENU2->style; - $_SESSION['menu'][$k]['show'] = true; - } else { - $_SESSION['menu'][$k]['libconst'] =''; - $_SESSION['menu'][$k]['url'] =''; - $_SESSION['menu'][$k]['style'] = ''; - $_SESSION['menu'][$k]['show'] = false; - } - $k ++; - } - // Browses the enabled modules array - for ($i = 0; $i < count($modules); $i ++) { - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR - . 'modules' . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR . "menu.xml" - ) - ) { - $menuPath = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "menu.xml"; - } else { - $menuPath = 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "menu.xml"; - } - - if (file_exists( - $_SESSION['config']['corepath'] . 'modules' - . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR . "menu.xml" - ) || file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR - . 'modules' . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR . "menu.xml" - ) - ) { - $xmlconfig = simplexml_load_file($menuPath); - foreach ($xmlconfig->MENU as $MENU) { - $_SESSION['menu'][$k]['id'] = (string) $MENU->id; - if (isset( - $_SESSION['user']['services'][$_SESSION['menu'][$k]['id']] - ) - && $_SESSION['user']['services'][$_SESSION['menu'][$k]['id']] == true - ) { - $libmenu = (string) $MENU->libconst; - if ( !empty($libmenu) && defined($libmenu) - && constant($libmenu) <> NULL - ) { - $libmenu = constant($libmenu); - } - $_SESSION['menu'][$k]['libconst'] = $libmenu; - $_SESSION['menu'][$k]['url'] = $_SESSION['config']['businessappurl'] - . (string) $MENU->url; - if (trim((string) $MENU->target) <> "") { - $tmp = preg_replace( - '/\/core\/$/', '/', $_SESSION['urltocore'] - ); - $_SESSION['menu'][$k]['url'] = $tmp - . (string) $MENU->url; - $_SESSION['menu'][$k]['target'] = (string) $MENU->target; - } - $_SESSION['menu'][$k]['style'] = (string) $MENU->style; - $_SESSION['menu'][$k]['show'] = true; - } else { - $_SESSION['menu'][$k]['libconst'] = ''; - $_SESSION['menu'][$k]['url'] = ''; - $_SESSION['menu'][$k]['style'] = ''; - $_SESSION['menu'][$k]['show'] = false; - } - $k ++; - } - } - } - - $coreTools = new core_tools(); - $coreTools->load_quicklaunch($modules); - } - - /** - * Loads application services into session - */ - public static function loadAppServices() - { - // Reads the application config.xml file - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'apps' - . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'services.xml' - ) - ) { - $path = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR - . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'xml' - . DIRECTORY_SEPARATOR . 'services.xml'; - } else { - $path = 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] - . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR - . 'services.xml'; - } - $xmlconfig = simplexml_load_file($path); - $k = 0; - $m = 0; - include_once 'apps/' .$_SESSION['config']['app_id']. '/lang/' . $_SESSION['config']['lang'].'.php' ; - // Browses the services in that file and loads $_SESSION['app_services'] - foreach ($xmlconfig->SERVICE as $service) { - $_SESSION['app_services'][$k] = array(); - $_SESSION['app_services'][$k]['id'] = (string) $service->id; - $name = (string) $service->name; - if ( !empty($name) && defined($name) && constant($name) <> NULL ) { - $name = constant($name); - } - $_SESSION['app_services'][$k]['name'] = $name; - $comment = (string) $service->comment; - if ( !empty($comment) && defined($comment) - && constant($comment) <> NULL - ) { - $comment = constant($comment); - } - $_SESSION['app_services'][$k]['comment'] = $comment; - if (isset($service->servicepage)) { - $_SESSION['app_services'][$k]['servicepage'] = (string) $service->servicepage; - $_SESSION['app_services'][$k]['servicepage'] = preg_replace( - '/&admin/', '&admin', - $_SESSION['app_services'][$k]['servicepage'] - ); - $_SESSION['app_services'][$k]['servicepage'] = preg_replace( - '/&module/', '&module', - $_SESSION['app_services'][$k]['servicepage'] - ); - } - $_SESSION['app_services'][$k]['servicetype'] = (string) $service->servicetype; - - if (isset($service->style)) { - $_SESSION['app_services'][$k]['style'] = (string) $service->style; - } - - $systemService = (string) $service->system_service; - if ($systemService == "false") { - $_SESSION['app_services'][$k]['system_service'] = false; - } else { - $_SESSION['app_services'][$k]['system_service'] = true; - } - $_SESSION['app_services'][$k]['enabled'] = (string) $service->enabled; - $l = 0; - foreach ($service->WHEREAMIUSED as $whereAmIUsed) { - if (isset($whereAmIUsed)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['page'] = (string) $whereAmIUsed->page; - $_SESSION['app_services'][$k]['whereamiused'][$l]['nature'] = (string) $whereAmIUsed->nature; - if (isset($whereAmIUsed->button_label)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['button_label'] = (string) $whereAmIUsed->button_label; - } - if (isset($whereAmIUsed->tab_label)) { - $label = (string) $whereAmIUsed->tab_label; - if ( !empty($label) && defined($label) - && constant($label) <> NULL - ) { - $label = constant($label); - } - $_SESSION['app_services'][$k]['whereamiused'][$l]['tab_label'] = $label; - } - if (isset($whereAmIUsed->tab_order)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['tab_order'] = (string) $whereAmIUsed->tab_order; - } - if (isset($whereAmIUsed->width)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['width'] = (string) $whereAmIUsed->width; - } - if (isset($whereAmIUsed->frame_id)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['frame_id'] = (string) $whereAmIUsed->frame_id; - } - if (isset($whereAmIUsed->height)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['height'] = (string) $whereAmIUsed->height; - } - if (isset($whereAmIUsed->scrolling)){ - $_SESSION['app_services'][$k]['whereamiused'][$l]['scrolling'] = (string) $whereAmIUsed->scrolling; - } - if (isset($whereAmIUsed->style)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['style'] = (string) $whereAmIUsed->style; - } - if (isset($whereAmIUsed->border)) { - $_SESSION['app_services'][$k]['whereamiused'][$l]['border'] = (string) $whereAmIUsed->border; - } - $l ++; - } - } - $m = 0; - // Loads preprocess and postprocess - foreach ($service->PROCESSINBACKGROUND as $processInBackground) { - $_SESSION['app_services'][$k]['processinbackground'][$m]['page'] = (string) $processInBackground->page; - if ((string) $processInBackground->preprocess <> "") { - $_SESSION['app_services'][$k]['processinbackground'][$m]['preprocess'] = (string) $processInBackground->preprocess; - } - if ((string) $processInBackground->postprocess <> "") { - $_SESSION['app_services'][$k]['processinbackground'][$m]['postprocess'] = (string) $processInBackground->postprocess; - } - $_SESSION['app_services'][$k]['processinbackground'][$m]['processorder'] = (string) $processInBackground->processorder; - $m++; - } - $k ++; - } - } - - /** - * Loads the services of each module into session - * - * @param array $modules Enabled modules of the application - */ - public static function loadModulesServices($modules) - { - // Browses the enabled modules array - for ($i = 0; $i < count($modules); $i ++) { - // Reads the module config.xml file - if (file_exists( - $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR - . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR - . 'modules' . DIRECTORY_SEPARATOR . $modules[$i]['moduleid'] - . DIRECTORY_SEPARATOR . "xml" . DIRECTORY_SEPARATOR - . "services.xml" - ) - ) { - $path = $_SESSION['config']['corepath'] . 'custom' - . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] - . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "services.xml"; - } else { - $path = 'modules' . DIRECTORY_SEPARATOR - . $modules[$i]['moduleid'] . DIRECTORY_SEPARATOR . "xml" - . DIRECTORY_SEPARATOR . "services.xml"; - } - $xmlconfig = simplexml_load_file($path); - $k = 0; - $m = 0; - foreach ($xmlconfig->SERVICE as $service) { - if ((string) $service->enabled == "true") { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['id'] = (string) $service->id; - $name = (string) $service->name; - if ( !empty($name) && defined($name) - && constant($name) <> NULL - ) { - $name = constant($name); - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['name'] = - $name; - - $comment = (string) $service->comment; - if ( !empty($comment) && defined($comment) - && constant($comment) <> NULL - ) { - $comment = constant($comment); - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['comment'] = - $comment; - - if (isset($service->servicepage)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['servicepage'] = (string) $service->servicepage; - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['servicetype'] = (string) $service->servicetype; - - if (isset($service->style)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['style'] = (string) $service->style; - } - $systemService = (string) $service->system_service; - if ($systemService == "false") { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['system_service'] = false; - } else { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['system_service'] = true; - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['enabled'] = (string) $service->enabled; - - $l = 0; - foreach ($service->WHEREAMIUSED as $whereAmIUsed) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['page'] = (string) $whereAmIUsed->page; - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['nature'] = (string) $whereAmIUsed->nature; - if (isset($whereAmIUsed->button_label)) { - $label = (string) $whereAmIUsed->button_label; - if ( !empty($label) && defined($label) - && constant($label) <> NULL - ) { - $label = constant($label); - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['button_label'] = - $label; - } - if (isset($whereAmIUsed->tab_label)) { - $label = (string) $whereAmIUsed->tab_label; - if ( !empty($label) && defined($label) - && constant($label) <> NULL - ) { - $label = constant($label); - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['tab_label'] = - $label; - } - if (isset($whereAmIUsed->tab_order)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['tab_order'] = (string) $whereAmIUsed->tab_order; - } - if (isset($whereAmIUsed->frame_id)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['frame_id'] = (string) $whereAmIUsed->frame_id; - } - if (isset($whereAmIUsed->width)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['width'] = (string) $whereAmIUsed->width; - } - if (isset($whereAmIUsed->height)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['height'] = (string) $whereAmIUsed->height; - } - if (isset($whereAmIUsed->scrolling)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['scrolling'] = (string) $whereAmIUsed->scrolling; - } - if (isset($whereAmIUsed->style)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['style'] = (string) $whereAmIUsed->style; - } - if (isset($whereAmIUsed->border)) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['border'] = (string) $whereAmIUsed->border; - } - $l ++; - } - $m = 0; - foreach ($service->PROCESSINBACKGROUND as $processInBackground) { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['page'] = (string) $processInBackground->page; - if ((string) $processInBackground->preprocess <> "") { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['preprocess'] = (string) $processInBackground->preprocess; - } - if ((string) $processInBackground->postprocess <> "") { - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['postprocess'] = (string) $processInBackground->postprocess; - } - $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['processorder'] = (string) $processInBackground->processorder; - $m ++; - } - $k ++; - } - } - } - } -} \ No newline at end of file diff --git a/core/services/MaarchException.php b/core/services/MaarchException.php deleted file mode 100644 index 04f2e57fd2ace818b9dbb4a06841fd0f1d6d44ea..0000000000000000000000000000000000000000 --- a/core/services/MaarchException.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -/** -* @copyright 2016 capgemini -* -* 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/>. -*/ - -require_once 'core/services/MaarchExceptionAbstract.php'; - -class Core_MaarchException_Service extends Core_MaarchExceptionAbstract_Service{ -} diff --git a/core/services/MaarchExceptionAbstract.php b/core/services/MaarchExceptionAbstract.php deleted file mode 100644 index c030fa1c93a84d1a66ff699e71d6f146fbc68e8b..0000000000000000000000000000000000000000 --- a/core/services/MaarchExceptionAbstract.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -/** -* @copyright 2016 capgemini -* -* 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/>. -*/ - -/** - * Service de gestion des données en session - */ -class Core_MaarchExceptionAbstract_Service extends Exception { - - // Redéfinissez l'exception ainsi le message n'est pas facultatif - public function __construct($message, $code = 0, Exception $previous = null) { - - // assurez-vous que tout a été assigné proprement - parent::__construct($message, $code, $previous); - } - - // chaîne personnalisée représentant l'objet - public function __toString() { - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; - } -} diff --git a/core/services/Session.php b/core/services/Session.php deleted file mode 100644 index b8f6c7d638cba357a6d06dd783586b75f202a28c..0000000000000000000000000000000000000000 --- a/core/services/Session.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/** -* @copyright 2017 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/>. -*/ - -require_once 'core/services/SessionAbstract.php'; - -class Core_Session_Service extends Core_SessionAbstract_Service{ - // Do your stuff -} diff --git a/core/services/SessionAbstract.php b/core/services/SessionAbstract.php deleted file mode 100644 index dc1ae329d767ee0418f08e55919b026c317f1d98..0000000000000000000000000000000000000000 --- a/core/services/SessionAbstract.php +++ /dev/null @@ -1,287 +0,0 @@ -<?php - -/** -* @copyright 2017 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/>. -*/ - -require_once 'core/services/Abstract.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_security.php'; - -/** - * Service de gestion des données en session - */ -class Core_SessionAbstract_Service extends Core_Abstract_Service { - - /** - * Récupération de la liste des méthodes disponibles via api - * - * @return string[] La liste des méthodes - */ - public static function getApiMethod() { - $aApiMethod = parent::getApiMethod(); - $aApiMethod['getUserId'] = 'getUserId'; - $aApiMethod['getUserEntitiesLst'] = 'getUserEntitiesLst'; - $aApiMethod['InitializeAntiXss'] = 'InitializeAntiXss'; - return $aApiMethod; - } - - /** - * Renvoie les informations de l'utilisateur courant dans la session - * @api rest.php?module=core&service=Core_Session_Service&method=getUser - * @throw \Exception $e - * @param array $args - * @return array $aUser - **/ - public static function getUser(array $args = []) { - return empty($_SESSION['user'])?null:$_SESSION['user']; - } - - /** - * Renvoie la valeur de la session anti_xss. on la définie si elle n'existe pas - * @api rest.php?module=core&service=Core_Session_Service&method=InitializeAntiXss - * @throw \Exception $e - * @param array $args - * @return array $aUser - **/ - public static function InitializeAntiXss(array $args = []){ - if(empty($_SESSION['anti_xss'])){ - $_SESSION['anti_xss'] = uniqid(); - } - return $_SESSION['anti_xss']; - } - - /** - * Renvoie le userid courant dans la session - * @throw \Exception $e - * @param array $args - * - none - * @return string $sUserId - **/ - public static function getUserId(array $args = []) { - $aUser = self::getUser(); - if ( !empty($aUser['UserId']) ){ - return $aUser['UserId']; - } - - $userSSOHeader = ''; - if (!empty($_SERVER['HTTP_'.HEADER_USER_UID])) { - $userSSOHeader = $_SERVER['HTTP_' .HEADER_USER_UID]; - } else if (!empty($_SERVER['HTTP_' .HEADER_USER_NIGEND])) { - $userSSOHeader = $_SERVER['HTTP_' .HEADER_USER_NIGEND]; - } - return $userSSOHeader; - } - - /** - * Renvoie les entité de l'utilisateur en session - * @throw \Exception $e - * @param array $args - * @return array $aEntities [aEntitie] - **/ - public static function getUserEntities(array $args = []) { - return $_SESSION['user']['entities']; - } - - /** - * Renvoie la liste des entités de l'utilisateur en session (juste leur name) - * @throw \Exception $e - * @param array $args - * @return array $aEntities [string ENTITY_ID,string ENTITY_ID,...] - **/ - public static function getUserEntitiesLst(array $args = []) { - $aUserEntities = self::getUserEntities(); - $aLst = []; - foreach ($aUserEntities as $aEntitie) { - $aLst[] = $aEntitie['ENTITY_ID']; - } - return $aLst; - } - - /** - * Renvoie les entité de l'utilisateur en session - * @throw \Exception $e - * @param array $args - * @return string $sEntities - **/ - public static function getUserPrimaryentity(array $args = []) { - return $_SESSION['user']['primaryentity']; - } - - /** - * Authentification d'un utilisateur - * - Vérifie que l'utilisateur existe (pas son code) - * - Charge l'utilisateur en session (le connecte) - * @param string $userId identifiant de l'utilisateur - * @return false|array false en cas d'echec, un tableau avec l'utilisateur sinon - */ - public function authentication($userId) { - if ( empty($userId) ) { - return false; - } - if ( ! is_string($userId) ) { - return false; - } - $authenticated = false; - $func = new functions(); - - $connexion = new Database(); - - $_SESSION['user']['UserId'] = $userId; - $userID = str_replace('\'', '', $_SESSION['user']['UserId']); - $userID = str_replace('=', '', $userID); - $userID = str_replace('"', '', $userID); - $userID = str_replace('*', '', $userID); - $userID = str_replace(';', '', $userID); - $userID = str_replace('--', '', $userID); - $userID = str_replace(',', '', $userID); - $userID = str_replace('$', '', $userID); - $userID = str_replace('>', '', $userID); - $userID = str_replace('<', '', $userID); - - $sec = new security(); - $query = "SELECT * FROM users WHERE user_id = ? AND STATUS <> 'DEL'"; - - $stmt = $connexion->query( - $query, - [$userID] - ); - - if ($stmt->rowCount() <= 0) { - return false; - } - $array = array(); - $error = ''; - $uc = new users_controler(); - - $database = new Database(); - $comp = " and STATUS <>:status"; - $params = array('status' => 'DEL'); - $s_login = $userId; - $user = $uc->getWithComp($s_login, $comp, $params); - if (empty($user)) { - return false; - } - if ($user->__get('enabled') != 'Y') { - return false; - } - $ugc = new usergroups_controler(); - $sec_controler = new SecurityControler(); - $serv_controler = new ServiceControler(); - if (isset($_SESSION['modules_loaded']['visa'])) { - if ($user->__get('signature_path') <> '' - && $user->__get('signature_file_name') <> '' - ) { - $_SESSION['user']['signature_path'] = $user->__get('signature_path'); - $_SESSION['user']['signature_file_name'] = $user->__get('signature_file_name'); - $db = new Database(); - $query = "select path_template from " - . _DOCSERVERS_TABLE_NAME - . " where docserver_id = 'TEMPLATES'"; - $stmt = $db->query($query); - $resDs = $stmt->fetchObject(); - $pathToDs = $resDs->path_template; - $_SESSION['user']['pathToSignature'] = $pathToDs . str_replace( - "#", - DIRECTORY_SEPARATOR, - $_SESSION['user']['signature_path'] - ) - . $_SESSION['user']['signature_file_name']; - } - } - - $array = array( - 'change_pass' => $user->__get('change_password'), - 'UserId' => $user->__get('user_id'), - 'FirstName' => $user->__get('firstname'), - 'LastName' => $user->__get('lastname'), - 'Phone' => $user->__get('phone'), - 'Mail' => $user->__get('mail'), - 'department' => $user->__get('department'), - 'thumbprint' => $user->__get('thumbprint'), - 'signature_path' => $user->__get('signature_path'), - 'signature_file_name' => $user->__get('signature_file_name'), - 'pathToSignature' => empty($_SESSION['user']['pathToSignature'])?'':$_SESSION['user']['pathToSignature'], - 'Status' => $user->__get('status'), - 'cookie_date' => $user->__get('cookie_date'), - ); - - $array['primarygroup'] = $ugc ->getPrimaryGroup( - $array['UserId'] - ); - $tmp = $sec_controler->load_security( - $array['UserId'] - ); - $array['collections'] = $tmp['collections']; - $array['security'] = $tmp['security']; - $serv_controler->loadEnabledServices(); - $business_app_tools = new business_app_tools(); - $core_tools = new core_tools(); - $business_app_tools->load_app_var_session($array); - Core_CoreConfig_Service::loadVarSession($_SESSION['modules'], $array); - - /************Temporary fix*************/ - if (isset($_SESSION['user']['baskets'])) { - $array['baskets'] = $_SESSION['user']['baskets']; - } - if (isset($_SESSION['user']['entities'])) { - $array['entities'] = $_SESSION['user']['entities']; - } - if (isset($_SESSION['user']['primaryentity'])) { - $array['primaryentity'] = $_SESSION['user']['primaryentity']; - } - - if (isset($_SESSION['user']['redirect_groupbasket'])) { - $array['redirect_groupbasket'] = $_SESSION['user']['redirect_groupbasket']; - } - /*************************************/ - $array['services'] = $serv_controler->loadUserServices( - $array['UserId'] - ); - - if ($_SESSION['history']['userlogin'] == 'true') { - //add new instance in history table for the user's connexion - $hist = new history(); - if(!isset($_SERVER['REMOTE_ADDR'])){ - $ip = 'testU'; - } else { - $ip = $_SERVER['REMOTE_ADDR']; - } - - $_SESSION['user']['UserId'] = $s_login; - $_SESSION['user']['department'] = $array['department']; - $_SESSION['user']['thumbprint'] = $array['thumbprint']; - $_SESSION['user']['primarygroup'] = $array['primarygroup']; - $hist->add( - $_SESSION['tablename']['users'], - $s_login, - 'LOGIN','userlogin', - _LOGIN_HISTORY . ' '. $s_login . ' IP : ' . $ip, - $_SESSION['config']['databasetype'] - ); - } - - return array( - 'user' => $array/*, - 'error' => $error, - 'url' => 'index.php?' . $_SESSION['requestUri']*/ - ); - - return true; - } -} \ No newline at end of file diff --git a/modules/attachments/Models/AttachmentsModelAbstract.php b/modules/attachments/Models/AttachmentsModelAbstract.php index 7d1d5ac055aa199081e6ffb5ab1bec775bf291bc..379bc6941baeb5ebc747f6b0ee8c471ccee961fa 100644 --- a/modules/attachments/Models/AttachmentsModelAbstract.php +++ b/modules/attachments/Models/AttachmentsModelAbstract.php @@ -9,9 +9,10 @@ namespace Attachments\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; -class AttachmentsModelAbstract extends \Apps_Table_Service +class AttachmentsModelAbstract { public static function getAttachmentsTypesByXML() { @@ -40,9 +41,8 @@ class AttachmentsModelAbstract extends \Apps_Table_Service public static function getAttachmentsWithOptions(array $aArgs = []) { - static::checkRequired($aArgs, ['where', 'data']); - static::checkArray($aArgs, ['where', 'data']); - + ValidatorModel::notEmpty($aArgs, ['where', 'data']); + ValidatorModel::arrayType($aArgs, ['where', 'data', 'orderBy']); $select = [ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], @@ -54,8 +54,85 @@ class AttachmentsModelAbstract extends \Apps_Table_Service $select['order_by'] = $aArgs['orderBy']; } - $aReturn = static::select($select); + $aReturn = DatabaseModel::select($select); + + return $aReturn; + } + + public static function getAvailableAttachmentsInByResIdMaster(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'in']); + ValidatorModel::intVal($aArgs, ['resIdMaster']); + ValidatorModel::arrayType($aArgs, ['in']); + + $aReturn = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['res_view_attachments'], + 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], + 'data' => [$aArgs['resIdMaster'], $aArgs['in']] + ]); return $aReturn; } + + public static function getAvailableAndTemporaryAttachmentsNotInByResIdMaster(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'notIn']); + ValidatorModel::intVal($aArgs, ['resIdMaster']); + ValidatorModel::arrayType($aArgs, ['notIn', 'orderBy']); + + $select = [ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['res_view_attachments'], + 'where' => ['res_id_master = ?', 'attachment_type not in (?)', "status not in ('DEL', 'OBS')"], + 'data' => [$aArgs['resIdMaster'], $aArgs['notIn']], + ]; + if (!empty($aArgs['orderBy'])) { + $select['order_by'] = $aArgs['orderBy']; + } + + $aReturn = DatabaseModel::select($select); + + return $aReturn; + } + + public static function getObsAttachmentsNotInByResIdMaster(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'notIn']); + ValidatorModel::intVal($aArgs, ['resIdMaster']); + ValidatorModel::arrayType($aArgs, ['notIn', 'orderBy']); + + $aReturn = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['res_view_attachments'], + 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status = ?'], + 'data' => [$aArgs['resIdMaster'], $aArgs['notIn'], 'OBS'], + 'order_by' => ['relation ASC'] + ]); + + return $aReturn; + } + + public static function unsignAttachment(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['table', 'resId']); + ValidatorModel::stringType($aArgs, ['table']); + ValidatorModel::intVal($aArgs, ['resId']); + + DatabaseModel::update([ + 'table' => $aArgs['table'], + 'set' => ['status' => 'A_TRA'], + 'where' => ['res_id = ?'], + 'data' => [$aArgs['resId']] + ]); + + DatabaseModel::update([ + 'table' => $aArgs['table'], + 'set' => ['status' => 'DEL'], + 'where' => ['origin = ?', 'status != ?'], + 'data' => ["{$aArgs['resId']},{$aArgs['table']}", 'DEL'] + ]); + + return true; + } } diff --git a/modules/attachments/services/Attachments.php b/modules/attachments/services/Attachments.php deleted file mode 100644 index 7d11fb2f37868cbebeb6b8e14aae8919e652d0a0..0000000000000000000000000000000000000000 --- a/modules/attachments/services/Attachments.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/>. -*/ - -require_once 'modules/attachments/services/AttachmentsAbstract.php'; - -class Attachments_Attachments_Service extends Attachments_AttachmentsAbstract_Service { - // Do your stuff in this class -} \ No newline at end of file diff --git a/modules/attachments/services/AttachmentsAbstract.php b/modules/attachments/services/AttachmentsAbstract.php deleted file mode 100644 index 48f3278cad3c5b17ba735eeb00c13b3564b51c47..0000000000000000000000000000000000000000 --- a/modules/attachments/services/AttachmentsAbstract.php +++ /dev/null @@ -1,122 +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/>. -*/ - -require_once('apps/maarch_entreprise/services/Table.php'); - -class Attachments_AttachmentsAbstract_Service extends Apps_Table_Service { - - /** - * Récupération de la liste des méthodes disponibles via api - * - * @return string[] La liste des méthodes - */ - public static function getApiMethod() { - $aApiMethod = parent::getApiMethod(); - - return $aApiMethod; - } - - public static function getAttachmentsForSignatureBook(array $aArgs = []) { - static::checkRequired($aArgs, ['resIdMaster']); - static::checkNumeric($aArgs, ['resIdMaster']); - - - $attachments = static::select([ - 'select' => ['res_id', 'res_id_version', 'title', 'identifier', 'attachment_type', 'status', 'typist', 'path', 'filename'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status not in (?)'], - 'data' => [$aArgs['resIdMaster'], ['incoming_mail_attachment'], ['DEL', 'TMP', 'OBS']] - ]); - - foreach ($attachments as $key => $value) { - if ($value['attachment_type'] == 'converted_pdf') { - continue; - } - - $collId = ''; - $realId = 0; - if ($value['res_id'] == 0) { - $collId = 'version_attachments_coll'; - $realId = $value['res_id_version']; - } elseif ($value['res_id_version'] == 0) { - $collId = 'attachments_coll'; - $realId = $value['res_id']; - } - - $viewerId = $realId; - $pathToFind = $value['path'] . str_replace(strrchr($value['filename'], '.'), '.pdf', $value['filename']); - foreach ($attachments as $tmpKey => $tmpValue) { - if ($tmpValue['attachment_type'] == 'converted_pdf' && ($tmpValue['path'] . $tmpValue['filename'] == $pathToFind)) { - $viewerId = $tmpValue['res_id']; - unset($attachments[$tmpKey]); - } - } - - $attachments[$key]['thumbnailLink'] = "index.php?page=doc_thumb&module=thumbnails&res_id={$realId}&coll_id={$collId}&display=true&advanced=true"; - $attachments[$key]['viewerLink'] = "index.php?display=true&module=visa&page=view_pdf_attachement&res_id_master={$aArgs['resIdMaster']}&id={$viewerId}"; - - unset($attachments[$key]['res_id']); - unset($attachments[$key]['res_id_version']); - unset($attachments[$key]['path']); - unset($attachments[$key]['filename']); - } - - return $attachments; - } - - public static function getIncomingMailAttachmentsForSignatureBook(array $aArgs = []) { - static::checkRequired($aArgs, ['resIdMaster', 'collIdMaster']); - static::checkNumeric($aArgs, ['resIdMaster']); - - - $incomingMail = static::select([ - 'select' => ['subject'], - 'table' => ['res_letterbox'], - 'where' => ['res_id = ?'], - 'data' => [$aArgs['resIdMaster']] - ]); - $attachments = static::select([ - 'select' => ['res_id', 'title'], - 'table' => ['res_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type = ?', 'status not in (?)'], - 'data' => [$aArgs['resIdMaster'], 'incoming_mail_attachment', ['DEL', 'TMP', 'OBS']] - ]); - - $aReturn = [ - [ - 'title' => $incomingMail[0]['subject'], - 'truncateTitle' => ((strlen($incomingMail[0]['subject']) > 10) ? (substr($incomingMail[0]['subject'], 0, 10) . '...') : $incomingMail[0]['subject']), - 'viewerLink' => "index.php?display=true&dir=indexing_searching&page=view_resource_controler&visu&id={$aArgs['resIdMaster']}&collid={$aArgs['collIdMaster']}", - 'thumbnailLink' => "index.php?page=doc_thumb&module=thumbnails&res_id={$aArgs['resIdMaster']}&coll_id={$aArgs['collIdMaster']}&display=true&advanced=true" - ] - ]; - foreach ($attachments as $value) { - $aReturn[] = [ - 'title' => $value['title'], - 'truncateTitle' => ((strlen($value['title']) > 10) ? (substr($value['title'], 0, 10) . '...') : $value['title']), - 'viewerLink' => "index.php?display=true&module=visa&page=view_pdf_attachement&res_id_master={$aArgs['resIdMaster']}&id={$value['res_id']}", - 'thumbnailLink' => "index.php?page=doc_thumb&module=thumbnails&res_id={$value['res_id']}&coll_id=attachments_coll&display=true&advanced=true" - ]; - } - - return $aReturn; - } -} \ No newline at end of file diff --git a/modules/basket/Models/BasketsModelAbstract.php b/modules/basket/Models/BasketsModelAbstract.php index c398f4dd76482cb9310f8e3d9bd82ae488649ac5..1c05a64bca7f322ee48da73d2ef6a26b88e857a9 100644 --- a/modules/basket/Models/BasketsModelAbstract.php +++ b/modules/basket/Models/BasketsModelAbstract.php @@ -15,28 +15,26 @@ namespace Baskets\Models; +use Core\Models\DatabaseModel; use Core\Models\UserModel; +use Core\Models\ValidatorModel; -require_once 'apps/maarch_entreprise/services/Table.php'; require_once 'core/class/SecurityControler.php'; -class BasketsModelAbstract extends \Apps_Table_Service +class BasketsModelAbstract { public static function getResListById(array $aArgs = []) { - static::checkRequired($aArgs, ['basketId']); - static::checkString($aArgs, ['basketId']); + ValidatorModel::notEmpty($aArgs, ['basketId']); + ValidatorModel::stringType($aArgs, ['basketId']); - - $aBasket = static::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 []; @@ -45,50 +43,42 @@ class BasketsModelAbstract extends \Apps_Table_Service $sec = new \SecurityControler(); $where = $sec->process_security_where_clause($aBasket[0]['basket_clause'], $_SESSION['user']['UserId'], false); - $aResList = static::select( - [ + $aResList = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['res_view_letterbox'], 'where' => [$where], - 'order_by' => empty($aBasket[0]['basket_res_order']) ? ['creation_date DESC'] : $aBasket[0]['basket_res_order'], - ] - ); + 'order_by' => empty($aBasket[0]['basket_res_order']) ? ['creation_date DESC'] : [$aBasket[0]['basket_res_order']], + ]); return $aResList; } public static function getActionByActionId(array $aArgs = []) { - static::checkRequired($aArgs, ['actionId']); - static::checkNumeric($aArgs, ['actionId']); - + ValidatorModel::notEmpty($aArgs, ['actionId']); + ValidatorModel::intVal($aArgs, ['actionId']); - $aAction = static::select( - [ + $aAction = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['actions'], 'where' => ['id = ?'], 'data' => [$aArgs['actionId']] - ] - ); + ]); return $aAction[0]; } public static function getActionIdById(array $aArgs = []) { - static::checkRequired($aArgs, ['basketId']); - static::checkString($aArgs, ['basketId']); - + ValidatorModel::notEmpty($aArgs, ['basketId']); + ValidatorModel::stringType($aArgs, ['basketId']); - $aAction = static::select( - [ + $aAction = DatabaseModel::select([ 'select' => ['id_action'], 'table' => ['actions_groupbaskets'], 'where' => ['basket_id = ?'], 'data' => [$aArgs['basketId']] - ] - ); + ]); if (empty($aAction[0])) { return ''; @@ -99,8 +89,8 @@ class BasketsModelAbstract extends \Apps_Table_Service public static function getBasketsByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId']); - static::checkString($aArgs, ['userId']); + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); $userGroups = UserModel::getGroupsByUserId(['userId' => $aArgs['userId']]); $groupIds = []; @@ -110,21 +100,19 @@ class BasketsModelAbstract extends \Apps_Table_Service $aBaskets = []; if (!empty($groupIds)) { - $aBaskets = static::select( - [ + $aBaskets = DatabaseModel::select([ 'select' => ['groupbasket.basket_id', 'group_id', 'basket_name', 'basket_desc'], 'table' => ['groupbasket, baskets'], 'where' => ['group_id in (?)', 'groupbasket.basket_id = baskets.basket_id'], 'data' => [$groupIds], - 'order_by' => 'group_id, basket_order, basket_name' - ] - ); + 'order_by' => ['group_id, basket_order, basket_name'] + ]); foreach ($aBaskets as $key => $value) { $aBaskets[$key]['is_virtual'] = 'N'; $aBaskets[$key]['basket_owner'] = $aArgs['userId']; } - $aBaskets = array_merge($aBaskets, self::getAbsBasketsByUserId(['userId' => $aArgs['userId']])); + $aBaskets = array_merge($aBaskets, BasketsModel::getAbsBasketsByUserId(['userId' => $aArgs['userId']])); } return $aBaskets; @@ -132,18 +120,16 @@ class BasketsModelAbstract extends \Apps_Table_Service public static function getAbsBasketsByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId']); - static::checkString($aArgs, ['userId']); + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); - $aBaskets = static::select( - [ + $aBaskets = DatabaseModel::select([ 'select' => ['ba.basket_id', 'ba.basket_name', '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' - ] - ); + 'order_by' => ['ba.basket_order, ba.basket_name'] + ]); foreach ($aBaskets as $key => $value) { $aBaskets[$key]['userToDisplay'] = UserModel::getLabelledUserById(['userId' => $value['user_abs']]); @@ -154,22 +140,21 @@ class BasketsModelAbstract extends \Apps_Table_Service public static function setBasketsRedirection(array $aArgs = []) { - static::checkRequired($aArgs, ['userId', 'data']); - static::checkString($aArgs, ['userId']); - static::checkArray($aArgs, ['data']); - + ValidatorModel::notEmpty($aArgs, ['userId', 'data']); + ValidatorModel::stringType($aArgs, ['userId']); + ValidatorModel::arrayType($aArgs, ['data']); foreach ($aArgs['data'] as $value) { - parent::insertInto( - [ + DatabaseModel::insert([ + 'table' => 'user_abs', + 'columnsValues' => [ 'user_abs' => $aArgs['userId'], 'new_user' => $value['newUser'], 'basket_id' => $value['basketId'], 'basket_owner' => $value['basketOwner'], 'is_virtual' => $value['virtual'] - ], - 'user_abs' - ); + ] + ]); } return true; diff --git a/modules/basket/services/Baskets.php b/modules/basket/services/Baskets.php deleted file mode 100644 index 18ef9fd2fb2afe51819d2d5af0edd02dff58f7a0..0000000000000000000000000000000000000000 --- a/modules/basket/services/Baskets.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/>. -*/ - -require_once 'modules/basket/services/BasketsAbstract.php'; - -class Basket_Baskets_Service extends Basket_BasketsAbstract_Service { - // Do your stuff in this class -} \ No newline at end of file diff --git a/modules/basket/services/BasketsAbstract.php b/modules/basket/services/BasketsAbstract.php deleted file mode 100644 index cebd5ffc9b675f5366dd0f77b447fe4fa41450d5..0000000000000000000000000000000000000000 --- a/modules/basket/services/BasketsAbstract.php +++ /dev/null @@ -1,53 +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/>. -*/ - -require_once('apps/maarch_entreprise/services/Table.php'); - -class Basket_BasketsAbstract_Service extends Apps_Table_Service { - - /** - * Récupération de la liste des méthodes disponibles via api - * - * @return string[] La liste des méthodes - */ - public static function getApiMethod() { - $aApiMethod = parent::getApiMethod(); - - return $aApiMethod; - } - - public static function getServiceFromActionId(array $aArgs = []) { - static::checkRequired($aArgs, ['id']); - static::checkNumeric($aArgs, ['id']); - - - $actionstable = static::select([ - 'select' => ['action_page'], - 'table' => ['actions'], - 'where' => ['id = ? AND enabled = ?'], - 'data' => [$aArgs['id'], 'Y'] - ]); - $aReturn = []; - $aReturn['actionPage'] = $actionstable[0]['action_page']; - - return $aReturn; - } -} \ No newline at end of file diff --git a/modules/entities/Models/EntityModelAbstract.php b/modules/entities/Models/EntityModelAbstract.php index a655e691d6e7e1b3334906bfd4d563d08d1315cc..1fef4a5a1490a06a4d4bae5a74f6f567ae2789b2 100644 --- a/modules/entities/Models/EntityModelAbstract.php +++ b/modules/entities/Models/EntityModelAbstract.php @@ -15,16 +15,15 @@ namespace Entities\Models; +use Core\Models\DatabaseModel; use Core\Models\UserModel; use Core\Models\ValidatorModel; -require_once 'apps/maarch_entreprise/services/Table.php'; - -class EntityModelAbstract extends \Apps_Table_Service +class EntityModelAbstract { public static function get(array $aArgs = []) { - $aEntities = static::select([ + $aEntities = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['entities'], 'where' => ['enabled = ?'], @@ -36,15 +35,16 @@ class EntityModelAbstract extends \Apps_Table_Service public static function getById(array $aArgs = []) { - static::checkRequired($aArgs, ['entityId']); + ValidatorModel::notEmpty($aArgs, ['entityId']); + if (is_array($aArgs['entityId'])) { $where = ['entity_id in (?)']; } else { - static::checkString($aArgs, ['entityId']); + ValidatorModel::stringType($aArgs, ['entityId']); $where = ['entity_id = ?']; } - $aEntities = static::select([ + $aEntities = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['entities'], 'where' => $where, @@ -60,29 +60,12 @@ class EntityModelAbstract extends \Apps_Table_Service } } - public static function getByEmail(array $aArgs = []) - { - static::checkRequired($aArgs, ['email']); - static::checkString($aArgs, ['email']); - - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['entities'], - 'where' => ['email = ?', 'enabled = ?'], - 'data' => [$aArgs['email'], 'Y'], - 'limit' => 1, - ]); - - return $aReturn; - } - public static function getByUserId(array $aArgs = []) { ValidatorModel::notEmpty($aArgs, ['userId']); ValidatorModel::stringType($aArgs, ['userId']); - - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['users_entities'], 'where' => ['user_id = ?'], @@ -94,10 +77,10 @@ class EntityModelAbstract extends \Apps_Table_Service private static function getEntityChilds(array $aArgs = []) { - static::checkRequired($aArgs, ['entityId']); - static::checkString($aArgs, ['entityId']); + ValidatorModel::notEmpty($aArgs, ['entityId']); + ValidatorModel::stringType($aArgs, ['entityId']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => ['entity_id'], 'table' => ['entities'], 'where' => ['parent_entity_id = ?'], @@ -106,7 +89,7 @@ class EntityModelAbstract extends \Apps_Table_Service $entities = [$aArgs['entityId']]; foreach ($aReturn as $value) { - $entities = array_merge($entities, static::getEntityChilds(['entityId' => $value['entity_id']])); + $entities = array_merge($entities, EntityModel::getEntityChilds(['entityId' => $value['entity_id']])); } return $entities; @@ -114,14 +97,14 @@ class EntityModelAbstract extends \Apps_Table_Service public static function getAllEntitiesByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId']); - static::checkString($aArgs, ['userId']); + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); $aReturn = UserModel::getEntitiesById(['userId' => $aArgs['userId']]); $entities = []; foreach ($aReturn as $value) { - $entities = array_merge($entities, static::getEntityChilds(['entityId' => $value['entity_id']])); + $entities = array_merge($entities, EntityModel::getEntityChilds(['entityId' => $value['entity_id']])); } return array_unique($entities); @@ -129,12 +112,11 @@ class EntityModelAbstract extends \Apps_Table_Service public static function getAvailableEntitiesForAdministratorByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['userId', 'administratorUserId']); - static::checkString($aArgs, ['userId', 'administratorUserId']); - + ValidatorModel::notEmpty($aArgs, ['userId', 'administratorUserId']); + ValidatorModel::stringType($aArgs, ['userId', 'administratorUserId']); if ($aArgs['administratorUserId'] == 'superadmin') { - $rawEntitiesAllowedForAdministrator = self::get(['select' => ['entity_id']]); + $rawEntitiesAllowedForAdministrator = EntityModel::get(['select' => ['entity_id']]); $entitiesAllowedForAdministrator = []; foreach ($rawEntitiesAllowedForAdministrator as $value) { $entitiesAllowedForAdministrator[] = $value['entity_id']; @@ -143,14 +125,14 @@ class EntityModelAbstract extends \Apps_Table_Service $entitiesAllowedForAdministrator = EntityModel::getAllEntitiesByUserId(['userId' => $aArgs['administratorUserId']]); } - $rawUserEntities = self::getByUserId(['userId' => $aArgs['userId'], 'select' => ['entity_id']]); + $rawUserEntities = EntityModel::getByUserId(['userId' => $aArgs['userId'], 'select' => ['entity_id']]); $userEntities = []; foreach ($rawUserEntities as $value) { $userEntities[] = $value['entity_id']; } - $allEntities = self::get(['select' => ['entity_id', 'entity_label']]); + $allEntities = EntityModel::get(['select' => ['entity_id', 'entity_label']]); foreach ($allEntities as $key => $value) { if (in_array($value['entity_id'], $userEntities) || !in_array($value['entity_id'], $entitiesAllowedForAdministrator)) { diff --git a/modules/entities/Models/ListModelsModelAbstract.php b/modules/entities/Models/ListModelsModelAbstract.php index a3505bc0ba2a201c5cae11b286403ca2e0b14bd7..4876c873024770621e0d67a480eb624610eb1035 100644 --- a/modules/entities/Models/ListModelsModelAbstract.php +++ b/modules/entities/Models/ListModelsModelAbstract.php @@ -11,35 +11,33 @@ namespace Entities\Models; -require_once 'apps/maarch_entreprise/services/Table.php'; +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; -class ListModelsModelAbstract extends \Apps_Table_Service +class ListModelsModelAbstract { public static function update(array $aArgs = []) { - static::checkRequired($aArgs, ['set', 'where', 'data']); - static::checkArray($aArgs, ['set', 'where', 'data']); + ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); + ValidatorModel::arrayType($aArgs, ['set', 'where', 'data']); - $aReturn = parent::update([ + DatabaseModel::update([ 'table' => 'listmodels', 'set' => $aArgs['set'], 'where' => $aArgs['where'], 'data' => $aArgs['data'] ]); - return $aReturn; + + return true; } public static function getDiffListByUsersId(array $aArgs = []) { - static::checkRequired($aArgs, ['users_id']); - static::checkRequired($aArgs, ['object_type']); - static::checkRequired($aArgs, ['item_mode']); + ValidatorModel::notEmpty($aArgs, ['users_id', 'object_type', 'item_mode']); + ValidatorModel::arrayType($aArgs, ['users_id']); + ValidatorModel::stringType($aArgs, ['object_type', 'item_mode']); - static::checkArray($aArgs, ['users_id']); - static::checkString($aArgs, ['object_type']); - static::checkString($aArgs, ['item_mode']); - - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['listmodels'], 'where' => ['item_id in (?)', 'object_type = ?', 'item_mode = ?'], @@ -51,15 +49,11 @@ class ListModelsModelAbstract extends \Apps_Table_Service public static function getDiffListByUserId(array $aArgs = []) { - static::checkRequired($aArgs, ['itemId']); - static::checkRequired($aArgs, ['objectType']); - static::checkRequired($aArgs, ['itemMode']); - - static::checkString($aArgs, ['itemId']); - static::checkString($aArgs, ['objectType']); - static::checkString($aArgs, ['itemMode']); + ValidatorModel::notEmpty($aArgs, ['itemId', 'objectType', 'itemMode']); + ValidatorModel::arrayType($aArgs, ['users_id']); + ValidatorModel::stringType($aArgs, ['itemId', 'objectType', 'itemMode']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['listmodels'], 'where' => ['item_id = ?', 'object_type = ?', 'item_mode = ?'], diff --git a/modules/export_seda/Purge.php b/modules/export_seda/Purge.php index 7e3f5bdb44f75537a7ac826d8bafcd521a957037..a7663b445136c2b5803f18bb63549dd605089df4 100644 --- a/modules/export_seda/Purge.php +++ b/modules/export_seda/Purge.php @@ -1,7 +1,6 @@ <?php require_once 'vendor/autoload.php'; -require_once 'apps/maarch_entreprise/Models/ContactsModel.php'; require_once __DIR__.'/RequestSeda.php'; Class Purge{ @@ -73,9 +72,8 @@ Class Purge{ private function purgeContact($contactId) { - $contacts = new \ContactsModel(); - $contactDetails = $contacts->purgeContact([ - 'id'=>$contactId + $contactDetails = \Apps\Models\ContactModel::purgeContact([ + 'id' => $contactId ]); } } \ No newline at end of file diff --git a/modules/notes/Models/NoteModel.php b/modules/notes/Models/NoteModel.php new file mode 100644 index 0000000000000000000000000000000000000000..ebc7fcc4ca53a0ea1d2a108db8b354f7b45f4278 --- /dev/null +++ b/modules/notes/Models/NoteModel.php @@ -0,0 +1,21 @@ +<?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 + * @ingroup notes + */ + +namespace Notes\Models; + +class NoteModel extends NoteModelAbstract +{ + // Do your stuff in this class +} \ No newline at end of file diff --git a/modules/notes/Models/NoteModelAbstract.php b/modules/notes/Models/NoteModelAbstract.php new file mode 100644 index 0000000000000000000000000000000000000000..47b8dc2671115c7c58453a434e57477a77a5f349 --- /dev/null +++ b/modules/notes/Models/NoteModelAbstract.php @@ -0,0 +1,69 @@ +<?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 + * @ingroup notes + */ + +namespace Notes\Models; + +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; + +class NoteModelAbstract +{ + + public static function countForCurrentUserByResId(array $aArgs = []) + { + ValidatorModel::notEmpty($aArgs, ['resId']); + + $nb = 0; + $countedNotes = []; + $entities = []; + + $aEntities = DatabaseModel::select([ + 'select' => ['entity_id'], + 'table' => ['users_entities'], + 'where' => ['user_id = ?'], + 'data' => [$_SESSION['user']['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'] == $_SESSION['user']['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; + } + +} diff --git a/modules/notes/Models/NotesModel.php b/modules/notes/Models/NotesModel.php deleted file mode 100644 index 35eda9611608b2cf13526a0f4ddd927ed4d99b4a..0000000000000000000000000000000000000000 --- a/modules/notes/Models/NotesModel.php +++ /dev/null @@ -1,27 +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/>. -*/ - -require_once 'modules/notes/Models/NotesModelAbstract.php'; - -class NotesModel extends NotesModelAbstract -{ - // Do your stuff in this class -} \ No newline at end of file diff --git a/modules/notes/Models/NotesModelAbstract.php b/modules/notes/Models/NotesModelAbstract.php deleted file mode 100644 index cebf4d9ecf5ea2e3efd1f1a72cf04ecbb2db2db6..0000000000000000000000000000000000000000 --- a/modules/notes/Models/NotesModelAbstract.php +++ /dev/null @@ -1,117 +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/>. - */ - -require_once 'apps/maarch_entreprise/services/Table.php'; - -class NotesModelAbstract extends Apps_Table_Service -{ - - public static function getByResId(array $aArgs = []) - { - static::checkRequired($aArgs, ['resId']); - - //get notes - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['notes', 'users'], - 'left_join' => ['notes.user_id = users.user_id'], - 'where' => ['notes.identifier = ?'], - '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 = static::select([ - 'select' => ['note_id', 'item_id'], - 'table' => ['note_entities'], - 'where' => ['note_id in (?)'], - 'data' => [$tmpNoteId], - 'order_by' => ['item_id'] - ]); - - foreach ($entities as $key => $value) { - $tmpEntitiesRestriction[$value['note_id']][] = $value['item_id']; - } - } - - foreach ($aReturn as $key => $value) { - if (!empty($tmpEntitiesRestriction[$value['id']])) { - $aReturn[$key]['entities_restriction'] = implode(", ", $tmpEntitiesRestriction[$value['id']]); - } - } - - return $aReturn; - } - - public static function countForCurrentUserByResId(array $aArgs = []) - { - static::checkRequired($aArgs, ['resId']); - - $nb = 0; - $countedNotes = []; - $entities = []; - - $aEntities = static::select([ - 'select' => 'entity_id', - 'table' => ['users_entities'], - 'where' => ['user_id = ?'], - 'data' => [$_SESSION['user']['UserId']] - ]); - - foreach ($aEntities as $value) { - $entities[] = $value['entity_id']; - } - - $aNotes = static::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'] == $_SESSION['user']['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; - } - -} diff --git a/modules/thumbnails/class/class_modules_tools.php b/modules/thumbnails/class/class_modules_tools.php index 1e017031c84540205c393210319d291bd4e51c82..27923de8f9073f87159e94f7f5f9a099e07c4111 100644 --- a/modules/thumbnails/class/class_modules_tools.php +++ b/modules/thumbnails/class/class_modules_tools.php @@ -1,7 +1,5 @@ <?php -require_once 'apps/maarch_entreprise/services/Table.php'; - class thumbnails { /*function __construct() @@ -248,7 +246,7 @@ class thumbnails return false; } - $oRowSet = Apps_Table_Service::select([ + $oRowSet = \Core\Models\DatabaseModel::select([ 'select' => ['path_template'], 'table' => ['docservers'], 'where' => ['docserver_type_id = ?'], @@ -261,7 +259,7 @@ class thumbnails $docserverPath = $oRowSet[0]['path_template']; - $oRowSet = Apps_Table_Service::select([ + $oRowSet = \Core\Models\DatabaseModel::select([ 'select' => ['tnl_path', 'tnl_filename'], 'table' => [$resTable], 'where' => ['res_id = ?'], diff --git a/modules/visa/Controllers/VisaController.php b/modules/visa/Controllers/VisaController.php index 0d3abd23272e1b1e884e8302103f1c4ebeba1d8d..8b9b2259d0e1b9ad561d93450162e326d4db3dd0 100644 --- a/modules/visa/Controllers/VisaController.php +++ b/modules/visa/Controllers/VisaController.php @@ -13,22 +13,22 @@ */ namespace Visa\Controllers; +use Apps\Models\ContactModel; use Attachments\Models\AttachmentsModel; +use Core\Models\ResModel; use Core\Models\UserModel; use Core\Models\LangModel; +use Core\Models\DocserverModel; +use Core\Models\ServiceModel; +use Notes\Models\NoteModel; use Baskets\Models\BasketsModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Visa\Models\VisaModel; require_once 'modules/basket/class/class_modules_tools.php'; require_once 'core/class/class_core_tools.php'; require_once 'core/class/class_security.php'; -require_once 'apps/maarch_entreprise/Models/ResModel.php'; -require_once 'apps/maarch_entreprise/Models/HistoryModel.php'; -require_once 'apps/maarch_entreprise/Models/ContactsModel.php'; -require_once 'modules/notes/Models/NotesModel.php'; -require_once 'modules/visa/Models/VisaModel.php'; - class VisaController { @@ -40,11 +40,14 @@ class VisaController $basketId = $aArgs['basketId']; $collId = 'letterbox_coll'; - $coreTools = new \core_tools(); $security = new \security(); $allowed = $security->test_right_doc($collId, $resId); if (!$allowed) { - return $response->withJson(['error' => 'Not Allowed']); + return $response->withStatus(403)->withJson(['error' => 'Forbidden document']); + } + $docserver = DocserverModel::getByTypeId(['docserver_type_id' => 'TEMPLATES', 'select' => ['path_template']]); + if (!file_exists($docserver['path_template'])) { + return $response->withStatus(500)->withJson(['errors' => _UNREACHABLE_DOCSERVER]); } $documents = $this->getIncomingMailAndAttachmentsForSignatureBook(['resId' => $resId]); @@ -75,33 +78,21 @@ class VisaController $datas['documents'] = $documents; $datas['currentAction'] = $currentAction; $datas['resList'] = []; - $datas['nbNotes'] = \NotesModel::countForCurrentUserByResId(['resId' => $resId]); + $datas['nbNotes'] = NoteModel::countForCurrentUserByResId(['resId' => $resId]); $datas['signatures'] = UserModel::getSignaturesById(['id' => $user['id']]); $datas['consigne'] = UserModel::getCurrentConsigneById(['resId' => $resId]); - $datas['hasWorkflow'] = \VisaModel::hasVisaWorkflowByResId(['resId' => $resId]); - $datas['canSign'] = $coreTools->test_service('sign_document', 'visa', false); + $datas['hasWorkflow'] = VisaModel::hasVisaWorkflowByResId(['resId' => $resId]); + $datas['canSign'] = ServiceModel::hasService(['id' => 'sign_document', 'userId' => $_SESSION['user']['UserId'], 'location' => 'visa', 'type' => 'use']); $datas['lang'] = LangModel::getSignatureBookLang(); - return $response->withJson($datas); } public function unsignFile(RequestInterface $request, ResponseInterface $response, $aArgs) { - $resId = $aArgs['resId']; - $collId = $aArgs['collId']; - - $bReturnSnd = false; - $bReturnFirst = \ResModel::put(['collId' => $collId, 'set' => ['status' => 'A_TRA'], 'where' => ['res_id = ?'], 'data' => [$resId]]); - if ($bReturnFirst) { - $bReturnSnd = \ResModel::put(['collId' => $collId, 'set' => ['status' => 'DEL'], 'where' => ['origin = ?', 'status != ?'], 'data' => [$resId . ',' .$collId, 'DEL']]); - } + AttachmentsModel::unsignAttachment(['table' => $aArgs['collId'], 'resId' => $aArgs['resId']]); - if ($bReturnFirst && $bReturnSnd) { - return $response->withJson(['status' => 'OK']); - } else { - return $response->withJson(['status' => 'KO']); - } + return $response->withJson(['success' => 'success']); } public function getIncomingMailAndAttachmentsById(RequestInterface $request, ResponseInterface $response, $aArgs) @@ -122,16 +113,17 @@ class VisaController { $resId = $aArgs['resId']; - $incomingMail = \ResModel::getById([ - 'resId' => $resId, - 'select' => ['res_id', 'subject', 'alt_identifier', 'category_id'] + $incomingMail = ResModel::getById([ + 'resId' => $resId, + 'select' => ['res_id', 'subject', 'alt_identifier', 'category_id'], + 'table' => 'res_view_letterbox' ]); if (empty($incomingMail)) { return ['error' => 'No Document Found']; } - $incomingMailAttachments = \ResModel::getAvailableLinkedAttachmentsIn([ + $incomingMailAttachments = AttachmentsModel::getAvailableAttachmentsInByResIdMaster([ 'resIdMaster' => $resId, 'in' => ['incoming_mail_attachment', 'converted_pdf'], 'select' => ['res_id', 'res_id_version', 'title', 'format', 'attachment_type', 'path', 'filename'] @@ -197,23 +189,20 @@ class VisaController } $orderBy .= " ELSE {$c} END, doc_date DESC NULLS LAST, creation_date DESC"; - $attachments = \ResModel::getAvailableAndTemporaryLinkedAttachmentsNotIn( - [ - 'resIdMaster' => $aArgs['resId'], - 'notIn' => ['incoming_mail_attachment', 'print_folder'], - 'select' => [ - 'res_id', 'res_id_version', 'title', 'identifier', 'attachment_type', - 'status', 'typist', 'path', 'filename', 'updated_by', 'creation_date', - 'validation_date', 'format', 'relation', 'dest_user', 'dest_contact_id', - 'dest_address_id', 'origin', 'doc_date', 'attachment_id_master' - ], - 'orderBy' => $orderBy - ] - ); + $attachments = AttachmentsModel::getAvailableAndTemporaryAttachmentsNotInByResIdMaster([ + 'resIdMaster' => $aArgs['resId'], + 'notIn' => ['incoming_mail_attachment', 'print_folder'], + 'select' => [ + 'res_id', 'res_id_version', 'title', 'identifier', 'attachment_type', + 'status', 'typist', 'path', 'filename', 'updated_by', 'creation_date', + 'validation_date', 'format', 'relation', 'dest_user', 'dest_contact_id', + 'dest_address_id', 'origin', 'doc_date', 'attachment_id_master' + ], + 'orderBy' => [$orderBy] + ]); - $coreTools = new \core_tools(); - $canModify = $coreTools->test_service('modify_attachments', 'attachments', false); - $canDelete = $coreTools->test_service('delete_attachments', 'attachments', false); + $canModify = ServiceModel::hasService(['id' => 'modify_attachments', 'userId' => $_SESSION['user']['UserId'], 'location' => 'attachments', 'type' => 'use']); + $canDelete = ServiceModel::hasService(['id' => 'delete_attachments', 'userId' => $_SESSION['user']['UserId'], 'location' => 'attachments', 'type' => 'use']); foreach ($attachments as $key => $value) { if ($value['attachment_type'] == 'converted_pdf' || ($value['attachment_type'] == 'signed_response' && !empty($value['origin']))) { @@ -260,7 +249,7 @@ class VisaController if (!empty($value['dest_user'])) { $attachments[$key]['destUser'] = UserModel::getLabelledUserById(['userId' => $value['dest_user']]); } elseif (!empty($value['dest_contact_id']) && !empty($value['dest_address_id'])) { - $attachments[$key]['destUser'] = \ContactsModel::getLabelledContactWithAddress(['contactId' => $value['dest_contact_id'], 'addressId' => $value['dest_address_id']]); + $attachments[$key]['destUser'] = ContactModel::getLabelledContactWithAddress(['contactId' => $value['dest_contact_id'], 'addressId' => $value['dest_address_id']]); } if (!empty($value['updated_by'])) { $attachments[$key]['updated_by'] = UserModel::getLabelledUserById(['userId' => $value['updated_by']]); @@ -299,7 +288,7 @@ class VisaController $attachments[$key]['viewerLink'] = "index.php?display=true&module=attachments&page=view_attachment&res_id_master={$aArgs['resId']}&id={$viewerId}&isVersion={$isVersion}"; } - $obsAttachments = \ResModel::getObsLinkedAttachmentsNotIn([ + $obsAttachments = AttachmentsModel::getObsAttachmentsNotInByResIdMaster([ 'resIdMaster' => $aArgs['resId'], 'notIn' => ['incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response'], 'select' => [ @@ -353,13 +342,11 @@ class VisaController $resListForRequest[] = $value['res_id']; } - $attachmentsInResList = AttachmentsModel::getAttachmentsWithOptions( - [ - 'select' => ['res_id_master', 'status', 'attachment_type'], - 'where' => ['res_id_master in (?)', "attachment_type not in ('incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response')", "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$resListForRequest] - ] - ); + $attachmentsInResList = AttachmentsModel::getAttachmentsWithOptions([ + 'select' => ['res_id_master', 'status', 'attachment_type'], + 'where' => ['res_id_master in (?)', "attachment_type not in ('incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response')", "status not in ('DEL', 'TMP', 'OBS')"], + 'data' => [$resListForRequest] + ]); $attachmentTypes = AttachmentsModel::getAttachmentsTypesByXML(); foreach ($attachmentsInResList as $value) { @@ -373,7 +360,7 @@ class VisaController foreach ($resList as $key => $value) { if (!empty($value['contact_id'])) { - $resList[$key]['sender'] = \ContactsModel::getLabelledContactWithAddress(['contactId' => $value['contact_id'], 'addressId' => $value['address_id']]); + $resList[$key]['sender'] = ContactModel::getLabelledContactWithAddress(['contactId' => $value['contact_id'], 'addressId' => $value['address_id']]); } else { $resList[$key]['sender'] = $value['user_firstname'] . ' ' . $value['user_lastname']; } @@ -393,12 +380,10 @@ class VisaController { $basketId = $aArgs['basketId']; - $resList = BasketsModel::getResListById( - [ - 'basketId' => $basketId, - 'select' => ['res_id'] - ] - ); + $resList = BasketsModel::getResListById([ + 'basketId' => $basketId, + 'select' => ['res_id'] + ]); return $response->withJson(['resList' => $resList]); } diff --git a/modules/visa/Models/VisaModel.php b/modules/visa/Models/VisaModel.php index 0c5399d8e72c7e360b3ddfeb350b94d9f1b4caae..112496b0481e8f953678ac856d3b898d75dc23f0 100644 --- a/modules/visa/Models/VisaModel.php +++ b/modules/visa/Models/VisaModel.php @@ -7,7 +7,7 @@ * */ -require_once 'modules/visa/Models/VisaModelAbstract.php'; +namespace Visa\Models; class VisaModel extends VisaModelAbstract { diff --git a/modules/visa/Models/VisaModelAbstract.php b/modules/visa/Models/VisaModelAbstract.php index 87d1da116774bd53f04215984952a7db9744aa88..15c6983e9baba32db93178d58b7b9aa87190cbc3 100644 --- a/modules/visa/Models/VisaModelAbstract.php +++ b/modules/visa/Models/VisaModelAbstract.php @@ -7,25 +7,26 @@ * */ -require_once 'apps/maarch_entreprise/services/Table.php'; +namespace Visa\Models; -class VisaModelAbstract extends Apps_Table_Service +use Core\Models\DatabaseModel; +use Core\Models\ValidatorModel; + +class VisaModelAbstract { public static function hasVisaWorkflowByResId(array $aArgs = []) { - static::checkRequired($aArgs, ['resId']); - static::checkNumeric($aArgs, ['resId']); - + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); - $aReturn = static::select([ + $aReturn = DatabaseModel::select([ 'select' => ['COUNT(*)'], 'table' => ['listinstance'], 'where' => ['res_id = ?', 'item_mode in (?)'], 'data' => [$aArgs['resId'], ['visa', 'sign']] ]); - return ((int)$aReturn[0]['count'] > 0); } } \ No newline at end of file diff --git a/modules/visa/sign_file.php b/modules/visa/sign_file.php index ee049b5b649c204ee37454e312e3cdcf4156e654..aff272d65823def2943f79f94ec587a966537cab 100644 --- a/modules/visa/sign_file.php +++ b/modules/visa/sign_file.php @@ -38,7 +38,7 @@ if (!empty($_REQUEST['id']) && !empty($_REQUEST['collId'])) { } $docserver = \Core\Models\DocserverModel::getByTypeId(['docserver_type_id' => 'TEMPLATES', 'select' => ['path_template']]); - $pathToWantedSignature = $docserver[0]['path_template'] . str_replace('#', '/', $signature->signature_path) . $signature->signature_file_name; + $pathToWantedSignature = $docserver['path_template'] . str_replace('#', '/', $signature->signature_path) . $signature->signature_file_name; } else { $pathToWantedSignature = $_SESSION['user']['pathToSignature'][0]; }