diff --git a/include/mitarbeiter.class.php b/include/mitarbeiter.class.php index ad99cd2c7..5c728ecbb 100644 --- a/include/mitarbeiter.class.php +++ b/include/mitarbeiter.class.php @@ -22,7 +22,7 @@ require_once(dirname(__FILE__).'/person.class.php'); require_once(dirname(__FILE__).'/benutzer.class.php'); require_once(dirname(__FILE__).'/functions.inc.php'); -require_once(dirname(__FILE__).'/udf.class.php'); +require_once(dirname(__FILE__).'/udf.class.php'); // required only to check if UDFs are defined class mitarbeiter extends benutzer { diff --git a/include/udf.class.php b/include/udf.class.php index eda139227..220665bfd 100644 --- a/include/udf.class.php +++ b/include/udf.class.php @@ -1,5 +1,5 @@ */ require_once(dirname(__FILE__).'/basis_db.class.php'); require_once(dirname(__FILE__).'/../config/global.config.inc.php'); +require_once(dirname(__FILE__).'/benutzerberechtigung.class.php'); /** * Used to export UDF in MS Excel format @@ -286,14 +286,21 @@ class UDF extends basis_db }); } - /** - * Returns an array of associative arrays that contains the couple name and title related to an UDF - * These data are retrived from the UDF definitions given as parameter - */ - private function _getUDFDefinition($jsons) - { + /** + * Returns an array of associative arrays that contains the couple name and title related to an UDF + * These data are retrived from the UDF definitions given as parameter + */ + private function _getUDFDefinition($jsons) + { $names = array(); + $uid = get_uid(); // get the UID of the logged person + if ($uid == null) return names(); // if no logged then it is not possible to loads UDFs + + // Gets the permissions for the logged user + $berechtigung = new benutzerberechtigung(); + $berechtigung->getBerechtigungen($uid); + if ($jsons != null && ($jsonsDecoded = json_decode($jsons)) != null) { if (is_object($jsonsDecoded) || is_array($jsonsDecoded)) @@ -305,27 +312,51 @@ class UDF extends basis_db $this->_sortJsonSchemas($jsonsDecoded); - foreach($jsonsDecoded as $udfJsonShema) + foreach ($jsonsDecoded as $udfJsonShema) { - if (isset($udfJsonShema->name) && isset($udfJsonShema->title)) + // Checks if the requiredPermissions property exists + if (isset($udfJsonShema->requiredPermissions)) { - $tmpArray = array('name' => $udfJsonShema->name, 'title' => $udfJsonShema->title); + $isAllowed = false; - if (isset($udfJsonShema->type) - && ($udfJsonShema->type == 'dropdown' || $udfJsonShema->type == 'multipledropdown') - && isset($udfJsonShema->listValues) && isset($udfJsonShema->listValues->enum)) + // If requiredPermissions is an array check if at least one of the permissions belongs to the logged user + if (is_array($udfJsonShema->requiredPermissions)) { - $tmpArray['enum'] = $udfJsonShema->listValues->enum; + foreach ($udfJsonShema->requiredPermissions as $permission) + { + $isAllowed = $berechtigung->isBerechtigt($permission); + if ($isAllowed === true) break; + } + } + else // otherwise check it directly + { + $isAllowed = $berechtigung->isBerechtigt($udfJsonShema->requiredPermissions); } - $names[] = $tmpArray; - } + // If the logged user has at least one of the required permissions + if ($isAllowed === true) + { + if (isset($udfJsonShema->name) && isset($udfJsonShema->title)) + { + $tmpArray = array('name' => $udfJsonShema->name, 'title' => $udfJsonShema->title); + + if (isset($udfJsonShema->type) + && ($udfJsonShema->type == 'dropdown' || $udfJsonShema->type == 'multipledropdown') + && isset($udfJsonShema->listValues) && isset($udfJsonShema->listValues->enum)) + { + $tmpArray['enum'] = $udfJsonShema->listValues->enum; + } + + $names[] = $tmpArray; + } + } // otherwise this UDF is discarted because the requiredPermissions is mandatory + } // otherwise this UDF is discarted because the requiredPermissions is mandatory } } } return $names; - } + } /** * Loads UDf titles from phrases @@ -374,3 +405,4 @@ class UDF extends basis_db return $titles; } } +