From a4b918f61a3659781973512202c9e42655b1af23 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Fri, 24 Jan 2020 18:03:06 +0100 Subject: [PATCH] FEAT #12073 TIME 0:25 History keywords clean --- apps/maarch_entreprise/phpids_control.php | 5 +- core/class/docservers_controler.php | 314 ------------------ core/class/usergroups_controler.php | 36 -- core/class/users_controler.php | 82 ----- .../history/controllers/HistoryController.php | 1 + src/app/user/controllers/UserController.php | 2 +- 6 files changed, 5 insertions(+), 435 deletions(-) diff --git a/apps/maarch_entreprise/phpids_control.php b/apps/maarch_entreprise/phpids_control.php index 7dac00fa6be..b318145a20b 100755 --- a/apps/maarch_entreprise/phpids_control.php +++ b/apps/maarch_entreprise/phpids_control.php @@ -65,8 +65,9 @@ if ($processIDS) { $_SESSION['config']['databasetype'], 'admin', false, - _OK, - _LEVEL_ERROR + 'ok', + 'ERROR', + 'superadmin' ); if ($_SESSION['config']['debug'] == 'true') { echo $result; diff --git a/core/class/docservers_controler.php b/core/class/docservers_controler.php index 723c0c437fe..a8122e3de4c 100755 --- a/core/class/docservers_controler.php +++ b/core/class/docservers_controler.php @@ -174,41 +174,6 @@ class docservers_controler */ public function enable($docserver) { - $control = array(); - if (!isset($docserver) || empty($docserver)) { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _DOCSERVER_EMPTY, - ); - return $control; - } - $docserver = $this->isADocserver($docserver); - $this->set_foolish_ids(array('docserver_id')); - $this->set_specific_id('docserver_id'); - if ($this->advanced_enable($docserver)) { - $control = array( - 'status' => 'ok', - 'value' => $docserver->docserver_id, - ); - if ($_SESSION['history']['docserversallow'] == 'true') { - $history = new history(); - $history->add( - _DOCSERVERS_TABLE_NAME, - $docserver->docserver_id, - 'VAL','docserversallow', - _DOCSERVER_ENABLED . ' : ' . $docserver->docserver_id, - $_SESSION['config']['databasetype'] - ); - } - } else { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _PB_WITH_DOCSERVER, - ); - } - return $control; } /** @@ -233,107 +198,6 @@ class docservers_controler } } - /** - * Test if a given docserver exists - * - * @param $docserver docservers object - * @return bool true if exists, false otherwise - */ - public function docserversExists($docserver_id) - { - if (!isset($docserver_id) || empty($docserver_id)) { - return false; - } - $db = new Database(); - $query = "select docserver_id from " . _DOCSERVERS_TABLE_NAME - . " where docserver_id = ?"; - try{ - $stmt = $db->query($query, array($docserver_id)); - } catch (Exception $e) { - echo _UNKNOWN . _DOCSERVER . ' ' . functions::xssafe($docserver_id) . ' // '; - } - if ($stmt->rowCount() > 0) { - return true; - } - return false; - } - - /** - *Check if the docserver is linked to a ressource - *@param docserver_id docservers - *@return bool true if it's linked - */ - public function resxLinkExists($docserver_id, $coll_id) - { - if ($coll_id == 'templates') { - return false; - } - $security = new security(); - $db = new Database(); - $tableName = $security->retrieve_table_from_coll($coll_id); - if (!isset($tableName) || empty($tableName)) { - return false; - } - $query = "select docserver_id from " . $tableName - . " where docserver_id = ?"; - $stmt = $db->query($query, array($docserver_id)); - if ($stmt->rowCount() > 0) { - return true; - } - return false; - } - - /** - *Check if the docserver is linked to a ressource address - *@param docserver_id docservers - *@return bool true if it's linked - */ - public function adrxLinkExists($docserver_id, $coll_id) - { - $security = new security(); - $db = new Database(); - $adrName = $security->retrieveAdrFromColl($coll_id); - if (!isset($adrName) || empty($adrName)) { - return false; - } - $query = "select docserver_id from " . $adrName - . " where docserver_id = ?"; - $stmt = $db->query($query, array($docserver_id)); - if ($stmt->rowCount() > 0) { - return true; - } - } - - /** - * Check if the docserver actual size is less than the size limit - * - * @param $docserver docservers object - * @return bool true if the control is ok - */ - public function actualSizeNumberControl($docserver) - { - if (!isset($docserver) || empty($docserver)) { - return false; - } - $size_limit_number = floatval($docserver->size_limit_number); - $size_limit_number = $size_limit_number * 1000 * 1000 * 1000; - $db = new Database(); - $query = "select actual_size_number from " . _DOCSERVERS_TABLE_NAME - . " where docserver_id = ?"; - $stmt = $db->query($query, array($docserver->docserver_id)); - $queryResult = $stmt->fetchObject(); - if (isset($queryResult->actual_size_number)) { - $actual_size_number = floatval($queryResult->actual_size_number); - } else { - $actual_size_number = 0; - } - if ($size_limit_number < $actual_size_number) { - return true; - } else { - return false; - } - } - public function getDocserverToInsert($collId, $typeId = 'DOC') { if ($collId == 'templates') { @@ -637,185 +501,7 @@ class docservers_controler return $newSize; } - - /** - * - * Get a resources at a specific address in adr table or res table - * @param array $adr - */ - public function viewResourceAdr($adr) { - //retrieve infos of the docserver type - require_once('core' . DIRECTORY_SEPARATOR . 'class' - . DIRECTORY_SEPARATOR . 'docserver_types_controler.php'); - $history = new history(); - $coreTools = new core_tools(); - $fingerprintFromDb = $adr['fingerprint']; - //$format = $adr[0][$cptDocserver]['format']; - $docserverObject = $this->get($adr['docserver_id']); - $docserver = $docserverObject->path_template; - $file = $docserver . $adr['path'] - . $adr['filename']; - $file = str_replace('#', DIRECTORY_SEPARATOR, $file); - $docserverTypeControler = new docserver_types_controler(); - $docserverTypeObject = $docserverTypeControler->get( - $docserverObject->docserver_type_id - ); - if (!file_exists($file)) { - $concatError .= _FILE_NOT_EXISTS_ON_THE_SERVER . ' : ' - . $file . '||'; - $history->add( - $tableName, $gedId, 'ERR', 'docserverserr', - _FAILOVER . ' ' . _DOCSERVERS . ' ' - . $adr['docserver_id'] . ':' - . _FILE_NOT_EXISTS_ON_THE_SERVER . ' : ' - . $file, $_SESSION['config']['databasetype'] - ); - } else { - $fingerprintFromDocserver = Ds_doFingerprint( - $file, $docserverTypeObject->fingerprint_mode - ); - $adrToExtract = $adr; - $adrToExtract['path_to_file'] = $file; - $mimeType = Ds_getMimeType( - $adrToExtract['path_to_file'] - ); - $format = substr( - $adrToExtract['filename'], - strrpos($adrToExtract['filename'], '.') + 1 - ); - //manage view of the file - $use_tiny_mce = false; - if (strtolower($format) == 'maarch' - && $coreTools->is_module_loaded('templates') - ) { - $mode = 'content'; - $type_state = true; - $use_tiny_mce = true; - $mimeType = 'application/maarch'; - } else { - require_once 'core/docservers_tools.php'; - $arrayIsAllowed = array(); - $arrayIsAllowed = Ds_isFileTypeAllowed($file); - $type_state = $arrayIsAllowed['status']; - } - //if fingerprint from db = 0 we do not control fingerprint - if ($fingerprintFromDb == '0' - || ($fingerprintFromDb == $fingerprintFromDocserver) - ) { - if ($type_state <> false) { - if ($_SESSION['history']['resview'] == 'true') { - require_once( - 'core' . DIRECTORY_SEPARATOR - . 'class' . DIRECTORY_SEPARATOR - . 'class_history.php' - ); - $history->add( - $tableName, $gedId, 'VIEW', 'resview', - _VIEW_DOC_NUM . $gedId, - $_SESSION['config']['databasetype'], - 'indexing_searching' - ); - } - //count number of viewed in listinstance for - //the user - if ($coreTools->is_module_loaded('entities') - && $coreTools->is_module_loaded('basket') - ) { - require_once( - 'modules' . DIRECTORY_SEPARATOR - . 'entities' . DIRECTORY_SEPARATOR - . 'class' . DIRECTORY_SEPARATOR - . 'class_manage_entities.php' - ); - $ent = new entity(); - $ent->increaseListinstanceViewed($gedId); - } - $encodedContent = ''; - if (file_exists($file) && !$error) { - if ($calledByWS) { - $content = ''; - $handle = fopen($file, 'r'); - if ($handle) { - while (!feof($handle)) { - $content .= fgets($handle, 4096); - } - fclose($handle); - } - $encodedContent = base64_encode($content); - } else { - $fileNameOnTmp = 'tmp_file_' . rand() - . '.' . strtolower($format); - $filePathOnTmp = $_SESSION['config'] - ['tmppath'] . DIRECTORY_SEPARATOR - . $fileNameOnTmp; - copy($file, $filePathOnTmp); - } - $result = array( - 'status' => 'ok', - 'mime_type' => $mimeType, - 'ext' => $format, - 'file_content' => $encodedContent, - 'tmp_path' => $_SESSION['config'] - ['tmppath'], - 'file_path' => $filePathOnTmp, - 'called_by_ws' => $calledByWS, - 'error' => '', - ); - if (isset($extract) - && file_exists($extract['tmpArchive']) - ) { - Ds_washTmp($extract['tmpArchive']); - } - return $result; - } else { - $concatError .= _FILE_NOT_EXISTS . '||'; - $history->add( - $tableName, $gedId, 'ERR', 'docserverserr', - _FAILOVER . ' ' . _DOCSERVERS . ' ' - . $adr['docserver_id'] - . ':' . _FILE_NOT_EXISTS, - $_SESSION['config']['databasetype'] - ); - } - } else { - $concatError .= strtoupper(_WRONG_FILE_TYPE) . ' (extension => '.strtoupper($format).', mime_type => '.$mimeType.') ||'; - $history->add( - $tableName, $gedId, 'ERR', 'docserverserr', - _FAILOVER . ' ' . _DOCSERVERS . ' ' - . $adr['docserver_id'] . ':' - . _WRONG_FILE_TYPE, - $_SESSION['config']['databasetype'] - ); - } - } else { - $concatError .= _PB_WITH_FINGERPRINT_OF_DOCUMENT . '||'; - $history->add( - $tableName, $gedId, 'ERR', 'docserverserr', - _FAILOVER . ' ' . _DOCSERVERS . ' ' - . $adr['docserver_id'] . ':' - . _PB_WITH_FINGERPRINT_OF_DOCUMENT, - $_SESSION['config']['databasetype'] - ); - } - if (file_exists($extract['tmpArchive'])) { - Ds_washTmp($extract['tmpArchive']); - } - } - //if errors : - $result = array( - 'status' => 'ko', - 'mime_type' => '', - 'ext' => '', - 'file_content' => '', - 'tmp_path' => '', - 'file_path' => '', - 'called_by_ws' => $calledByWS, - 'error' => $concatError, - ); - return $result; - } - /** * View the resource, returns the content of the resource * @param bigint $gedId id of th resource diff --git a/core/class/usergroups_controler.php b/core/class/usergroups_controler.php index 9631650aca3..899854ed7a9 100755 --- a/core/class/usergroups_controler.php +++ b/core/class/usergroups_controler.php @@ -513,42 +513,6 @@ class usergroups_controler extends ObjectControler implements ObjectControlerIF */ public function enable($group, $params=array()) { - $control = array(); - if (!isset($group) || empty($group)) { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _GROUP_EMPTY, - ); - return $control; - } - $group = $this->_isAGroup($group); - $this->set_foolish_ids(array('group_id')); - $this->set_specific_id('group_id'); - if ($this->advanced_enable($group)) { - $control = array( - 'status' => 'ok', - 'value' => $group->group_id, - ); - if (isset($params['log_group_enabled']) - && ($params['log_group_enabled'] == 'true' - || $params['log_group_enabled'] == true) - ) { - $history = new history(); - $history->add( - USERGROUPS_TABLE, $group->group_id, 'VAL','usergroupval', - _AUTORIZED_GROUP . ' : ' . $group->group_id, - $params['databasetype'] - ); - } - } else { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _PB_WITH_GROUP_ID, - ); - } - return $control; } /** diff --git a/core/class/users_controler.php b/core/class/users_controler.php index 4279ae8a112..3d02bba1c29 100755 --- a/core/class/users_controler.php +++ b/core/class/users_controler.php @@ -524,47 +524,6 @@ class users_controler extends ObjectControler implements ObjectControlerIF */ public function disable($user, $params=array()) { - $control = array(); - if (! isset($user) || empty($user)) { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _USER_EMPTY, - ); - return $control; - } - $user = self::_isAUser($user); - self::set_foolish_ids(array('user_id', 'docserver_location_id')); - self::set_specific_id('user_id'); - - if (self::advanced_disable($user)) { - $control = array( - 'status' => 'ok', - 'value' => $user->user_id, - ); - if (isset($params['log_user_disabled']) - && ($params['log_user_disabled'] == 'true' - || $params['log_user_disabled'] == true) - ) { - $history = new history(); - $history->add( - USERS_TABLE, - $user->user_id, - 'BAN', - 'usersban', - _SUSPENDED_USER . ' : ' . $user->lastname . ' ' - . $user->firstname . ' (' . $user->user_id . ')', - $params['databasetype'] - ); - } - } else { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _PB_WITH_USER_ID, - ); - } - return $control; } /** @@ -575,47 +534,6 @@ class users_controler extends ObjectControler implements ObjectControlerIF */ public function enable($user, $params=array()) { - $control = array(); - if (! isset($user) || empty($user)) { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _USER_EMPTY, - ); - return $control; - } - $user = self::_isAUser($user); - self::set_foolish_ids(array('user_id', 'docserver_location_id')); - self::set_specific_id('user_id'); - - if (self::advanced_enable($user)) { - $control = array( - 'status' => 'ok', - 'value' => $user->user_id, - ); - if (isset($params['log_user_enabled']) - && ($params['log_user_enabled'] == 'true' - || $params['log_user_enabled'] == true) - ) { - $history = new history(); - $history->add( - USERS_TABLE, - $user->user_id, - 'VAL', - 'usersval', - _AUTORIZED_USER .' : ' . $user->lastname . ' ' - . $user->firstname . ' (' . $user->user_id . ')', - $params['databasetype'] - ); - } - } else { - $control = array( - 'status' => 'ko', - 'value' => '', - 'error' => _PB_WITH_USER_ID, - ); - } - return $control; } /** diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index 0419127c97a..89b1b3eaebb 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -111,6 +111,7 @@ class HistoryController } $order = !in_array($queryParams['order'], ['asc', 'desc']) ? '' : $queryParams['order']; + $queryParams['orderBy'] = (!empty($queryParams['orderBy']) && $queryParams['orderBy'] == 'userLabel') ? 'user_id' : null; $orderBy = !in_array($queryParams['orderBy'], ['event_date', 'user_id', 'info']) ? ['event_date DESC'] : ["{$queryParams['orderBy']} {$order}"]; $history = HistoryModel::get([ diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 0585f9c5046..e3878fb5a1e 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -842,7 +842,7 @@ class UserController HistoryController::add([ 'tableName' => 'users', 'recordId' => $user['user_id'], - 'eventType' => 'RET', + 'eventType' => 'UP', 'eventId' => 'userabs', 'info' => "{$user['firstname']} {$user['lastname']} " ._BACK_FROM_VACATION ]); -- GitLab