diff --git a/application/config/udfmasterschema.json b/application/config/udfmasterschema.json index fa06dc80d..ab3faa8c9 100644 --- a/application/config/udfmasterschema.json +++ b/application/config/udfmasterschema.json @@ -9,6 +9,13 @@ "name": { "type": "string" }, + "type": { + "type": "string", + "enum": ["checkbox", "textfield", "textarea", "date", "dropdown", "multipledropdown"] + }, + "requiredPermissions": { + "type": "array" + }, "description": { "type": "array", }, @@ -18,10 +25,6 @@ "title": { "type": "array", }, - "type": { - "type": "string", - "enum": ["checkbox", "textfield", "textarea", "date", "dropdown", "multipledropdown"] - }, "sort": { "type": "integer" }, @@ -67,5 +70,6 @@ } } }, - "required": ["type", "name"] -} \ No newline at end of file + "required": ["type", "name", "requiredPermissions"] +} + diff --git a/application/controllers/system/FAS_UDF.php b/application/controllers/system/FAS_UDF.php index febe266c7..ecaa44393 100644 --- a/application/controllers/system/FAS_UDF.php +++ b/application/controllers/system/FAS_UDF.php @@ -31,7 +31,7 @@ class FAS_UDF extends Auth_Controller if (isset($person_id) && is_numeric($person_id)) { - if ($this->PersonModel->hasUDF()) + if ($this->PersonModel->udfsExistAndDefined()) { $personUdfs = $this->PersonModel->getUDFs($person_id); $data['person_id'] = $person_id; @@ -41,7 +41,7 @@ class FAS_UDF extends Auth_Controller if (isset($prestudent_id) && is_numeric($prestudent_id)) { - if ($this->PrestudentModel->hasUDF()) + if ($this->PrestudentModel->udfsExistAndDefined()) { $prestudentUdfs = $this->PrestudentModel->getUDFs($prestudent_id); $data['prestudent_id'] = $prestudent_id; diff --git a/application/controllers/widgets/UDF.php b/application/controllers/widgets/UDF.php index 5b4c45776..26c30293c 100644 --- a/application/controllers/widgets/UDF.php +++ b/application/controllers/widgets/UDF.php @@ -26,9 +26,6 @@ class UDF extends FHC_Controller // Loads the UDFLib with HTTP GET/POST parameters $this->_loadUDFLib(); - - // Checks if the caller is allow to use this UDF widget - $this->_isAllowed(); } //------------------------------------------------------------------------------------------------------------------ @@ -39,7 +36,6 @@ class UDF extends FHC_Controller */ public function saveUDFs() { - $udfUniqueId = $this->input->post(self::UDF_UNIQUE_ID); $udfs = $this->input->post(UDFLib::UDFS_ARG_NAME); if (!isEmptyString($udfs)) @@ -47,7 +43,7 @@ class UDF extends FHC_Controller $jsonDecodedUDF = json_decode($udfs); if ($jsonDecodedUDF != null) { - $this->outputJson($this->udflib->saveUDFs($udfUniqueId, $jsonDecodedUDF)); + $this->outputJson($this->udflib->saveUDFs($jsonDecodedUDF)); } else { @@ -63,17 +59,6 @@ class UDF extends FHC_Controller //------------------------------------------------------------------------------------------------------------------ // Private methods - /** - * Checks if the user is allowed to use this UDFWidget - */ - private function _isAllowed() - { - if (!$this->udflib->isAllowed()) - { - $this->terminateWithJsonError('You are not allowed to access to this content'); - } - } - /** * Loads the UDFLib with the UDF_UNIQUE_ID parameter * If the parameter UDF_UNIQUE_ID is not given then the execution of the controller is terminated and @@ -105,3 +90,4 @@ class UDF extends FHC_Controller } } } + diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 4b89ae5bf..4e555be6c 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -86,7 +86,7 @@ class DB_Model extends CI_Model if (is_null($this->dbTable)) return error('The given database table name is not valid', EXIT_MODEL); // If this table has UDF and the validation of them is ok - if (isError($validate = $this->_manageUDFs($data, $this->dbTable))) return $validate; + if (isError($validate = $this->_prepareUDFsWrite($data, $this->dbTable))) return $validate; // DB-INSERT $insert = $this->db->insert($this->dbTable, $data); @@ -137,7 +137,7 @@ class DB_Model extends CI_Model if (is_null($this->dbTable)) return error('The given database table name is not valid', EXIT_MODEL); // If this table has UDF and the validation of them is ok - if (isError($validate = $this->_manageUDFs($data, $this->dbTable, $id))) return $validate; + if (isError($validate = $this->_prepareUDFsWrite($data, $this->dbTable, $id))) return $validate; $tmpId = $id; @@ -670,6 +670,7 @@ class DB_Model extends CI_Model /** * Returns all the UDF contained in this table ($dbTable) * If no UDF are present, an empty array will be returned + * NOTE: only the UDFs that the logged user is allowed to read are loaded by this method */ public function getUDFs($id, $udfName = null) { @@ -700,9 +701,9 @@ class DB_Model extends CI_Model } /** - * Checks if this table has the field udf_values + * Checks if this table has the field udf_values and if there is a UDF definition for this table */ - public function hasUDF() + public function udfsExistAndDefined() { if ($this->fieldExists(UDFLib::COLUMN_NAME)) { @@ -844,25 +845,25 @@ class DB_Model extends CI_Model } /** - * Wrapper method for UDFLib->manageUDFs + * Wrapper method for UDFLib->prepareUDFsWrite */ - private function _manageUDFs(&$data, $schemaAndTable, $id = null) + private function _prepareUDFsWrite(&$data, $schemaAndTable, $id = null) { - $manageUDFs = success(); + $prepareUDFsWrite = success(); - if ($this->hasUDF()) + if ($this->udfsExistAndDefined()) { if ($id != null) { - $manageUDFs = $this->udflib->manageUDFs($data, $this->dbTable, $this->getUDFs($id)); + $prepareUDFsWrite = $this->udflib->prepareUDFsWrite($data, $this->dbTable, $this->_getUDFsNoPerms($id)); } else { - $manageUDFs = $this->udflib->manageUDFs($data, $this->dbTable); + $prepareUDFsWrite = $this->udflib->prepareUDFsWrite($data, $this->dbTable); } } - return $manageUDFs; + return $prepareUDFsWrite; } /** @@ -874,9 +875,10 @@ class DB_Model extends CI_Model */ private function _toPhp($result) { + $udfs = false; // if UDFs are inside the given result set $toPhp = $result; // if there is nothing to convert then return the result from DB - // If it's an object its fields will be parsed to find booleans and arrays types + // If it's an object its fields will be parsed to find booleans, arrays and UDFs types if (is_object($result)) { $toBeConverterdArray = array(); // Fields to be converted @@ -884,40 +886,48 @@ class DB_Model extends CI_Model $this->executedQueryMetaData = $result->field_data(); // Fields information $this->executedQueryListFields = $result->list_fields(); // List of the retrieved fields - for ($i = 0; $i < count($this->executedQueryMetaData); $i++) // Looking for booleans and arrays + // Looking for booleans, arrays and UDFs + foreach ($this->executedQueryMetaData as $eqmd) { // If array type, boolean type OR a UDF - if (strpos($this->executedQueryMetaData[$i]->type, DB_Model::PGSQL_ARRAY_TYPE) !== false - || $this->executedQueryMetaData[$i]->type == DB_Model::PGSQL_BOOLEAN_TYPE - || $this->udflib->isUDFColumn($this->executedQueryMetaData[$i]->name, $this->executedQueryMetaData[$i]->type)) + if (strpos($eqmd->type, DB_Model::PGSQL_ARRAY_TYPE) !== false + || $eqmd->type == DB_Model::PGSQL_BOOLEAN_TYPE + || $this->udflib->isUDFColumn($eqmd->name, $eqmd->type)) { - // Name and type of the field to be converted - $toBeConverted = new stdClass(); - // Set the type of the field to be converted - $toBeConverted->type = $this->executedQueryMetaData[$i]->type; - // Set the name of the field to be converted - $toBeConverted->name = $this->executedQueryMetaData[$i]->name; - // Add the field to be converted to $toBeConverterdArray - array_push($toBeConverterdArray, $toBeConverted); + // If UDFs are inside this result set + if ($this->udflib->isUDFColumn($eqmd->name, $eqmd->type)) + { + $udfs = true; + } + else // all the other cases + { + // Name and type of the field to be converted + $toBeConverted = new stdClass(); + // Set the type of the field to be converted + $toBeConverted->type = $eqmd->type; + // Set the name of the field to be converted + $toBeConverted->name = $eqmd->name; + // Add the field to be converted to $toBeConverterdArray + array_push($toBeConverterdArray, $toBeConverted); + } } } - // If there is something to convert, otherwhise don't lose time - if (count($toBeConverterdArray) > 0) - { - // Returns the array of objects, each of them represents a DB record - $resultsArray = $result->result(); - // Looping on results - for ($i = 0; $i < count($resultsArray); $i++) - { - // Single element - $resultElement = $resultsArray[$i]; - // Looping on fields to be converted - for ($j = 0; $j < count($toBeConverterdArray); $j++) - { - // Single element - $toBeConverted = $toBeConverterdArray[$j]; + // Returns the array of objects, each of them represents a DB record + $resultsArray = $result->result(); + // If in this result set there are UDFs then prepare them + if ($udfs) $this->udflib->prepareUDFsRead($resultsArray, $this->dbTable); + + // If there is something to convert, otherwhise don't waste time + if (!isEmptyArray($toBeConverterdArray)) + { + // Looping on results + foreach ($resultsArray as $resultElement) + { + // Looping on fields to be converted + foreach ($toBeConverterdArray as $toBeConverted) + { // Array type if (strpos($toBeConverted->type, DB_Model::PGSQL_ARRAY_TYPE) !== false) { @@ -931,30 +941,12 @@ class DB_Model extends CI_Model { $resultElement->{$toBeConverted->name} = $this->pgBoolPhp($resultElement->{$toBeConverted->name}); } - // UDF - elseif ($this->udflib->isUDFColumn($toBeConverted->name, $toBeConverted->type)) - { - $jsonValues = json_decode($resultElement->{$toBeConverted->name}); // decode UDFs values - if ($jsonValues != null) // if decode is ok - { - // For every UDF - foreach ($jsonValues as $key => $value) - { - $resultElement->{$key} = $value; // create a new element called like the UDF - } - } - unset($resultElement->{UDFLib::COLUMN_NAME}); // remove udf_values from the response - } } } - // Returns DB data as an array - $toPhp = $resultsArray; - } - // And returns DB data as an array - else - { - $toPhp = $result->result(); } + + // Returns DB data as an array + $toPhp = $resultsArray; } return $toPhp; @@ -998,4 +990,48 @@ class DB_Model extends CI_Model { if ($this->debugMode) $this->loglib->logDebug($this->db->last_query()); } + + /** + * Returns all the UDF contained in this table ($dbTable) + * If no UDF are present, an empty array will be returned + * NOTE: it returns all the UDFs, does _not_ check the permissions + */ + private function _getUDFsNoPerms($id) + { + $udfs = array(); + + $this->db->select(UDFLib::COLUMN_NAME, true); // get only the UDF column + + // Primary key management + $tmpId = $id; + + // Check for composite Primary Key + if (is_array($id)) + { + if (isset($id[0])) + { + $tmpId = $this->_arrayCombine($this->pk, $id); + } + } + elseif ($id != null) + { + $tmpId = array($this->pk => $id); + } + + // Read the record from the table + $result = $this->db->get_where($this->dbTable, $tmpId); + + // If was a success and there are data + if ($result && count($result->result()) == 1) + { + // Get the UDF column and decode it from JSON + $jsonValues = json_decode($result->result()[0]->{UDFLib::COLUMN_NAME}); + + // If the JSON convertion was fine convert the object to an array + if ($jsonValues != null) $udfs = get_object_vars($jsonValues); + } + + return $udfs; + } } + diff --git a/application/libraries/UDFLib.php b/application/libraries/UDFLib.php index f9ad7d20d..827bdc989 100644 --- a/application/libraries/UDFLib.php +++ b/application/libraries/UDFLib.php @@ -30,13 +30,14 @@ class UDFLib // ...to specify permissions that are needed to use this TableWidget const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions'; + const PERMISSION_TABLE_METHOD = 'UDFWidget'; // Name for fake method to be checked by the PermissionLib + const PERMISSION_TYPE_READ = 'r'; + const PERMISSION_TYPE_WRITE = 'w'; + // ...to specify the primary key name and value const PRIMARY_KEY_NAME = 'primaryKeyName'; const PRIMARY_KEY_VALUE = 'primaryKeyValue'; - const PERMISSION_TABLE_METHOD = 'UDFWidget'; // Name for fake method to be checked by the PermissionLib - const PERMISSION_TYPE = 'rw'; - // HTML components const LABEL = 'title'; const TITLE = 'description'; @@ -76,10 +77,10 @@ class UDFLib // Public methods /** - * UDFWidget - */ - public function UDFWidget($args, $htmlArgs = array()) - { + * UDFWidget + */ + public function UDFWidget($args, $htmlArgs = array()) + { if ((isset($args[self::SCHEMA_ARG_NAME]) && !isEmptyString($args[self::SCHEMA_ARG_NAME])) && (isset($args[self::TABLE_ARG_NAME]) && !isEmptyString($args[self::TABLE_ARG_NAME]))) { @@ -112,16 +113,17 @@ class UDFLib show_error(self::TABLE_ARG_NAME.' parameter is missing!'); } } - } + } - /** + /** * It renders the HTML of the UDF * * NOTE: When this method is called $widgetData contains different data from * parameter $args in the constructor */ - public function displayUDFWidget(&$widgetData) + public function displayUDFWidget(&$widgetData) { + $field = null; $schema = $widgetData[self::SCHEMA_ARG_NAME]; // schema attribute $table = $widgetData[self::TABLE_ARG_NAME]; // table attribute @@ -133,7 +135,7 @@ class UDFLib $udfResults = $this->_loadUDF($schema, $table); // loads UDF definition if (hasData($udfResults)) { - $udf = $udfResults->retval[0]; // only one record is loaded + $udf = getData($udfResults)[0]; // only one record is loaded if (isset($udf->jsons)) { $jsonSchemas = json_decode($udf->jsons); // decode the json schema @@ -155,7 +157,7 @@ class UDFLib $found = false; // used to check if the field is found or not in the json schema $this->_sortJsonSchemas($jsonSchemasArray); // Sort the list of UDF by sort property - + // Loops through json schemas foreach ($jsonSchemasArray as $jsonSchema) { @@ -169,21 +171,37 @@ class UDFLib { show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table)); } + // If the requiredPermissions property is not present then show an error + if (!isset($jsonSchema->{self::REQUIRED_PERMISSIONS_PARAMETER})) + { + show_error(sprintf('%s.%s: Attribute "requiredPermissions" not present in the json schema', $schema, $table)); + } + + // Set the required permissions for this UDF + $this->_setRequiredPermissions($jsonSchema->{self::NAME}, $jsonSchema->{self::REQUIRED_PERMISSIONS_PARAMETER}); // If a UDF is specified and is present in the json schemas list or no UDF is specified if ((isset($field) && $field == $jsonSchema->{self::NAME}) || !isset($field)) { - // Set attributes using phrases - $this->_setAttributesWithPhrases($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); + // If the user has the permissions to read this field + if ($this->_readAllowed($jsonSchema->{self::REQUIRED_PERMISSIONS_PARAMETER})) + { + // Set attributes using phrases + $this->_setAttributesWithPhrases($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); - // Set validation attributes - $this->_setValidationAttributes($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); + // Set validation attributes + $this->_setValidationAttributes($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); - // Set name and id attributes - $this->_setNameAndId($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); + // Set name and id attributes + $this->_setNameAndId($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); - // Render the HTML for this UDF - $this->_render($jsonSchema, $widgetData); + // Set if the field is in read only mode + $this->_setReadOnly($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]); + + // Render the HTML for this UDF + $this->_render($jsonSchema, $widgetData); + } + // otherwise the UDF is not displayed // If a UDf is specified and it was found then stop looking through this list if (isset($field) && $field == $jsonSchema->{self::NAME}) @@ -213,12 +231,97 @@ class UDFLib show_error(sprintf('%s.%s: Does not contain "jsons" field', $schema, $table)); } } - } + } /** - * Manage UDFs + * UDFs permissions check and convertion to read them from database */ - public function manageUDFs(&$data, $schemaAndTable, $udfValues = null) + public function prepareUDFsRead(&$data, $schemaAndTable, $udfValues = null) + { + $this->_ci->load->model('system/UDF_model', 'UDFModel'); + + // Retrieves UDFs definitions for this table + $resultUDFsDefinitions = $this->_ci->UDFModel->getUDFsDefinitions($schemaAndTable); + + // If an error occurred while reading from database + if (isError($resultUDFsDefinitions)) + { + $data = array(); // then set data as an empty array + return; // and exit from this method + } + + // If there are no UDFs defined for this table the return + if (!hasData($resultUDFsDefinitions)) return; + + // If not an error and has data, decodes json that define the UDFs for this table + $decodedUDFDefinitions = json_decode( + getData($resultUDFsDefinitions)[0]->{self::COLUMN_JSON_DESCRIPTION} + ); + + // Looping on results, resultElement is an object that represent a database record + foreach ($data as $resultElement) + { + // Decode the JSON column udf_values + $udfColumn = json_decode($resultElement->{self::COLUMN_NAME}); + + // If this is not a valid JSON then skip to the next database record + if ($udfColumn == null) continue; + + // For each UDF column of this database record + foreach (get_object_vars($udfColumn) as $columnName => $columnValue) + { + $udfColumnToBeRemoved = $columnName; // let's try to remove it + + // Loops through the UDFs definitions + foreach ($decodedUDFDefinitions as $decodedUDFDefinition) + { + // If the column exists in the UDF definition + if ($columnName == $decodedUDFDefinition->{self::NAME}) + { + $udfColumnToBeRemoved = null; // then keep it + } + } + + // If in this record have been found a _not_ defined UDF then remove it + if (!isEmptyString($udfColumnToBeRemoved)) unset($udfColumn->{$udfColumnToBeRemoved}); + } + + // Loops through the UDFs definitions + foreach ($decodedUDFDefinitions as $decodedUDFDefinition) + { + // Checks if the requiredPermissions is available and it is a valid array or a valid string + if (isset($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}) + && (!isEmptyArray($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}) + || !isEmptyString($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}))) + { + // Then check if the user has the permissions to read such UDF + if (!$this->_readAllowed($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER})) + { + // If not then remove the UDF from the result set + unset($udfColumn->{$decodedUDFDefinition->{self::NAME}}); + } + } + else // If not then remove the UDF from the result set + { + unset($udfColumn->{$decodedUDFDefinition->{self::NAME}}); + } + } + + // Add the defined and permitted UDF columns to the record set + foreach (get_object_vars($udfColumn) as $columnName => $columnValue) + { + $resultElement->{$columnName} = $columnValue; + } + } + + // And finally remove the UDFs column + unset($resultElement->{self::COLUMN_NAME}); + } + + /** + * UDFs validation and permissions check to write them into database + */ + public function prepareUDFsWrite(&$data, $schemaAndTable, $udfValues = null) { $validate = success(true); // returned value // Contains a list of validation errors for the UDFs that have not passed the validation @@ -241,18 +344,34 @@ class UDFLib // Decodes json that define the UDFs for this table $decodedUDFDefinitions = json_decode( - $resultUDFsDefinitions->retval[0]->{self::COLUMN_JSON_DESCRIPTION} + getData($resultUDFsDefinitions)[0]->{self::COLUMN_JSON_DESCRIPTION} ); // Loops through the UDFs definitions - for ($i = 0; $i < count($decodedUDFDefinitions); $i++) + foreach ($decodedUDFDefinitions as $decodedUDFDefinition) { - $decodedUDFDefinition = $decodedUDFDefinitions[$i]; // Definition of a single UDF + // Checks if the requiredPermissions is available and it is a valid array or a valid string + if (isset($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}) + && (!isEmptyArray($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}) + || !isEmptyString($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER}))) + { + // Then check if the user has the permissions to write such UDF + if (!$this->_writeAllowed($decodedUDFDefinition->{self::REQUIRED_PERMISSIONS_PARAMETER})) + { + // If the logged user has no permissions then remove the UDF + unset($udfsParameters[$decodedUDFDefinition->{self::NAME}]); + } + } + else + { + // If no permissions have been defined for this UDF then remove it + unset($udfsParameters[$decodedUDFDefinition->{self::NAME}]); + } // Loops through the UDFs values that should be stored foreach ($udfsParameters as $key => $val) { - $tmpValidate = success(true); // temporary variable used to store the returned value from _validateUDFs + $tmpValidateArray = array(); // temporary variable used to store the returned value from _validateUDFs // If this is the definition of this UDF if ($decodedUDFDefinition->{self::NAME} == $key) @@ -314,7 +433,7 @@ class UDFLib if ($toBeValidated === true) // Checks if validation should be performed { - $tmpValidate = $this->_validateUDFs( + $tmpValidateArray = $this->_validateUDFs( $decodedUDFDefinition->{self::VALIDATION}, $decodedUDFDefinition->{self::NAME}, $val @@ -324,13 +443,13 @@ class UDFLib } // If validation is ok copy the value that is to be stored into $toBeStoredUDFsArray - if (isSuccess($tmpValidate)) + if (isEmptyArray($tmpValidateArray)) { $toBeStoredUDFsArray[$key] = $val; } - else // otherwise store the validation error in $notValidUDFsArray + else // otherwise store the validation errors in $notValidUDFsArray { - $notValidUDFsArray[] = $tmpValidate; + $notValidUDFsArray = array_merge($notValidUDFsArray, $tmpValidateArray); } } } @@ -344,11 +463,11 @@ class UDFLib } // If the validation of all the supplied UDFs is ok - if (count($notValidUDFsArray) == 0) + if (isEmptyArray($notValidUDFsArray)) { // An update is performed, then in this case it preserves the values // of the UDF that are not updated - if (is_array($udfValues) && count($udfValues) > 0) + if (!isEmptyArray($udfValues)) { foreach ($udfValues as $fieldName => $fieldValue) { @@ -379,7 +498,7 @@ class UDFLib /** * isUDFColumn */ - public function isUDFColumn($columnName, $columnType) + public function isUDFColumn($columnName, $columnType = self::COLUMN_TYPE) { $isUDFColumn = false; @@ -466,7 +585,7 @@ class UDFLib /** * Save UDFs */ - public function saveUDFs($udfUniqueId, $udfs) + public function saveUDFs($udfs) { // Read the all session for this udf widget $session = $this->getSession(); @@ -490,30 +609,80 @@ class UDFLib // Returns the result of the database update operation to save UDFs return $dbModel->update( array($session[self::PRIMARY_KEY_NAME] => $session[self::PRIMARY_KEY_VALUE]), - (array)$udfs + get_object_vars($udfs) ); } - /** - * Checks if at least one of the permissions given as parameter (requiredPermissions) belongs - * to the authenticated user, if confirmed then is allowed to use this UDFWidget. - * If the parameter requiredPermissions is NOT given or is not present in the session, - * then NO one is allow to use this UDFWidget - * Wrapper method to permissionlib->hasAtLeastOne - */ - public function isAllowed($requiredPermissions = null) - { - $this->_ci->load->library('PermissionLib'); // Load permission library - - // Gets the required permissions from the session if they are not provided as parameter - $rq = $requiredPermissions; - if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER); - - return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE); - } - // ------------------------------------------------------------------------------------------------- // Private methods + // + + /** + * Checks if at least one of the permissions given as parameter belongs to the authenticated user in read mode + * Wrapper method to permissionlib->hasAtLeastOne + */ + private function _readAllowed($requiredPermissions) + { + $readAllowed = false; + + // If the user is logged then it is possible to check the permissions + if (isLogged()) + { + $this->_ci->load->library('PermissionLib'); // Load permission library + + $readAllowed = $this->_ci->permissionlib->hasAtLeastOne( + $requiredPermissions, + self::PERMISSION_TABLE_METHOD, + self::PERMISSION_TYPE_READ + ); + } // otherwise it is not possible to check the permissions + + return $readAllowed; + } + + /** + * Checks if at least one of the permissions given as parameter belongs to the authenticated user in write mode + * Wrapper method to permissionlib->hasAtLeastOne + */ + private function _writeAllowed($requiredPermissions) + { + $writeAllowed = false; + + // If the user is logged then it is possible to check the permissions + if (isLogged()) + { + $this->_ci->load->library('PermissionLib'); // Load permission library + + $writeAllowed = $this->_ci->permissionlib->hasAtLeastOne( + $requiredPermissions, + self::PERMISSION_TABLE_METHOD, + self::PERMISSION_TYPE_WRITE + ); + } // otherwise it is not possible to check the permissions + + return $writeAllowed; + } + + /** + * Set an array of required permissions for a UDF into the session + */ + private function _setRequiredPermissions($udfName, $permissions) + { + // Get the session for this UDFWidget + $session = $this->getSession(); + + // If does _not_ exist yet in the session + if (!isset($session[self::REQUIRED_PERMISSIONS_PARAMETER])) + { + $session[self::REQUIRED_PERMISSIONS_PARAMETER] = array(); + } + + // Set the required permission in the session for this UDFWidget + $session[self::REQUIRED_PERMISSIONS_PARAMETER][$udfName] = $permissions; + + // Write into the session + $this->setSession($session); + } /** * Print the block for UDFs @@ -544,12 +713,12 @@ class UDFLib { $udfsParameters = array(); - foreach ($data as $key => $val) + foreach ($data as $columnName => $columnValue) { - if (substr($key, 0, 4) == self::COLUMN_PREFIX) + if ($this->isUDFColumn($columnName)) { - $udfsParameters[$key] = $val; // stores UDF value into property UDFs - unset($data[$key]); // remove from data + $udfsParameters[$columnName] = $columnValue; // stores UDF value into property UDFs + unset($data[$columnName]); // remove from data } } @@ -645,29 +814,39 @@ class UDFLib } } - // If no UDF validation errors were raised, it's a success!! - if (count($returnArrayValidation) == 0) - { - $returnArrayValidation = success(true); - } - return $returnArrayValidation; } - /** - * Set the name and id attribute of the HTML element - */ - private function _setNameAndId($jsonSchema, &$htmlParameters) - { + /** + * Disable the HTML element if in read only mode + */ + private function _setReadOnly($jsonSchema, &$htmlParameters) + { + // If write permissions _not_ exist then set the field as disabled + if (!$this->_writeAllowed($jsonSchema->{self::REQUIRED_PERMISSIONS_PARAMETER})) + { + $htmlParameters[HTMLWidget::DISABLED] = HTMLWidget::DISABLED; // any values is fine + } + else // otherwise restore to default + { + if (isset($htmlParameters[HTMLWidget::DISABLED])) unset($htmlParameters[HTMLWidget::DISABLED]); + } + } + + /** + * Set the name and id attribute of the HTML element + */ + private function _setNameAndId($jsonSchema, &$htmlParameters) + { $htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{self::NAME}; $htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{self::NAME}; - } - - /** - * Sort the list of UDF by sort property - */ - private function _sortJsonSchemas(&$jsonSchemasArray) - { + } + + /** + * Sort the list of UDF by sort property + */ + private function _sortJsonSchemas(&$jsonSchemasArray) + { usort($jsonSchemasArray, function ($a, $b) { if (!isset($a->{self::SORT})) { @@ -684,13 +863,13 @@ class UDFLib return ($a->{self::SORT} < $b->{self::SORT}) ? -1 : 1; }); - } - - /** - * Loads the UDF description by the given schema and table - */ - private function _loadUDF($schema, $table) - { + } + + /** + * Loads the UDF description by the given schema and table + */ + private function _loadUDF($schema, $table) + { // Loads UDF model $this->_ci->load->model('system/UDF_model', 'UDFModel'); @@ -703,18 +882,7 @@ class UDFLib if (isError($udfResults)) { - if (is_object($udfResults) && isset($udfResults->retval)) - { - show_error(getError($udfResults)); - } - elseif (is_string($udfResults)) - { - show_error($udfResults); - } - else - { - show_error('UDFWidget: generic error occurred'); - } + show_error(getError($udfResults)); } elseif (!hasData($udfResults)) { @@ -722,13 +890,13 @@ class UDFLib } return $udfResults; - } + } - /** - * Render the HTML for the UDF - */ - private function _render($jsonSchema, &$widgetData) - { + /** + * Render the HTML for the UDF + */ + private function _render($jsonSchema, &$widgetData) + { // Checkbox if ($jsonSchema->{self::TYPE} == 'checkbox') { @@ -759,11 +927,11 @@ class UDFLib { $this->_renderDropdown($jsonSchema, $widgetData, true); } - } + } - /** - * Renders a dropdown element - */ + /** + * Renders a dropdown element + */ private function _renderDropdown($jsonSchema, &$widgetData, $multiple = false) { // Selected element/s @@ -792,7 +960,7 @@ class UDFLib $queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{self::LIST_VALUES}->sql); if (hasData($queryResult)) { - $parameters = $queryResult->retval; + $parameters = getData($queryResult); } } @@ -805,8 +973,8 @@ class UDFLib } /** - * Renders a textarea element - */ + * Renders a textarea element + */ private function _renderTextarea($jsonSchema, &$widgetData) { $text = null; // text value @@ -823,8 +991,8 @@ class UDFLib } /** - * Renders an input text element - */ + * Renders an input text element + */ private function _renderTextfield($jsonSchema, &$widgetData) { $text = null; // text value @@ -841,8 +1009,8 @@ class UDFLib } /** - * Renders a checkbox element - */ + * Renders a checkbox element + */ private function _renderCheckbox($jsonSchema, &$widgetData) { // Set checkbox value if present in the DB @@ -861,11 +1029,11 @@ class UDFLib $checkboxWidgetUDF->render(); } - /** - * Sets the attributes of the HTML element using the phrases system - */ - private function _setAttributesWithPhrases($jsonSchema, &$htmlParameters) - { + /** + * Sets the attributes of the HTML element using the phrases system + */ + private function _setAttributesWithPhrases($jsonSchema, &$htmlParameters) + { // By default set to null all the attributes $htmlParameters[HTMLWidget::LABEL] = null; $htmlParameters[HTMLWidget::TITLE] = null; @@ -893,7 +1061,7 @@ class UDFLib ); if (hasData($tmpResult)) { - $htmlParameters[HTMLWidget::LABEL] = $tmpResult->retval[0]->text; + $htmlParameters[HTMLWidget::LABEL] = getData($tmpResult)[0]->text; } } @@ -911,7 +1079,7 @@ class UDFLib ); if (hasData($tmpResult)) { - $htmlParameters[HTMLWidget::TITLE] = $tmpResult->retval[0]->text; + $htmlParameters[HTMLWidget::TITLE] = getData($tmpResult)[0]->text; } } @@ -929,17 +1097,17 @@ class UDFLib ); if (hasData($tmpResult)) { - $htmlParameters[HTMLWidget::PLACEHOLDER] = $tmpResult->retval[0]->text; + $htmlParameters[HTMLWidget::PLACEHOLDER] = getData($tmpResult)[0]->text; } } } - } + } - /** - * Sets the validation attributes of the HTML element using the configuration inside the json schema - */ - private function _setValidationAttributes($jsonSchema, &$htmlParameters) - { + /** + * Sets the validation attributes of the HTML element using the configuration inside the json schema + */ + private function _setValidationAttributes($jsonSchema, &$htmlParameters) + { // Validation attributes set by default to null $htmlParameters[HTMLWidget::REGEX] = null; $htmlParameters[HTMLWidget::REQUIRED] = null; @@ -998,3 +1166,4 @@ class UDFLib } } } + diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index 2553fd5fa..5589e5049 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -291,7 +291,7 @@ class Prestudent_model extends DB_Model $prestudentdata->prestudentstatus = $lastStatusData; - if ($this->hasUDF()) + if ($this->udfsExistAndDefined()) { $prestudentdata->prestudentUdfs = $this->getUDFs($prestudent_id); } diff --git a/application/views/system/fas_udf.php b/application/views/system/fas_udf.php index 8a1200b6a..e6fa396cf 100644 --- a/application/views/system/fas_udf.php +++ b/application/views/system/fas_udf.php @@ -45,7 +45,6 @@ echo $this->udflib->UDFWidget( array( UDFLib::UDF_UNIQUE_ID => 'fasPersonUDFs', - UDFLib::REQUIRED_PERMISSIONS_PARAMETER => 'basis/person', UDFLib::SCHEMA_ARG_NAME => 'public', UDFLib::TABLE_ARG_NAME => 'tbl_person', UDFLib::PRIMARY_KEY_NAME => 'person_id', @@ -70,7 +69,6 @@ echo $this->udflib->UDFWidget( array( UDFLib::UDF_UNIQUE_ID => 'fasPrestudentUDFs', - UDFLib::REQUIRED_PERMISSIONS_PARAMETER => 'basis/person', UDFLib::SCHEMA_ARG_NAME => 'public', UDFLib::TABLE_ARG_NAME => 'tbl_prestudent', UDFLib::PRIMARY_KEY_NAME => 'prestudent_id', @@ -109,3 +107,4 @@ load->view("templates/footer"); ?> + diff --git a/application/views/system/infocenter/zgvpruefungen.php b/application/views/system/infocenter/zgvpruefungen.php index a2b2f8da8..253145557 100644 --- a/application/views/system/infocenter/zgvpruefungen.php +++ b/application/views/system/infocenter/zgvpruefungen.php @@ -341,7 +341,6 @@ echo $this->udflib->UDFWidget( array( UDFLib::UDF_UNIQUE_ID => 'infocenterPrestudentUDFs_'.$zgvpruefung->prestudent_id, - UDFLib::REQUIRED_PERMISSIONS_PARAMETER => 'infocenter', UDFLib::SCHEMA_ARG_NAME => 'public', UDFLib::TABLE_ARG_NAME => 'tbl_prestudent', UDFLib::PRIMARY_KEY_NAME => 'prestudent_id', @@ -553,3 +552,4 @@ endforeach; // end foreach zgvpruefungen ?> + diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index 6a0969cd4..f4ba1bb4b 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -44,6 +44,8 @@ <?php printPageTitle($title); ?> + + + - \ No newline at end of file + + diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php index d9faf1978..51db6d536 100644 --- a/application/views/widgets/dropdown.php +++ b/application/views/widgets/dropdown.php @@ -33,6 +33,7 @@ + > + diff --git a/application/views/widgets/textarea.php b/application/views/widgets/textarea.php index c72b52658..5346fefa8 100644 --- a/application/views/widgets/textarea.php +++ b/application/views/widgets/textarea.php @@ -29,9 +29,11 @@ + > - \ No newline at end of file + + diff --git a/application/views/widgets/textfield.php b/application/views/widgets/textfield.php index 73b1daa1b..c5ba81710 100644 --- a/application/views/widgets/textfield.php +++ b/application/views/widgets/textfield.php @@ -31,10 +31,12 @@ + value="" > - \ No newline at end of file + + diff --git a/application/widgets/html/HTMLWidget.php b/application/widgets/html/HTMLWidget.php index 9639890ea..0034edfd9 100644 --- a/application/widgets/html/HTMLWidget.php +++ b/application/widgets/html/HTMLWidget.php @@ -6,18 +6,18 @@ class HTMLWidget extends Widget { // The name of the array present in the data array given to the view that will render this widget - const HTML_ARG_NAME = 'HTML'; + const HTML_ARG_NAME = 'HTML'; const HTML_DEFAULT_VALUE = ''; // Default value of the html element - const HTML_NAME = 'name'; // HTML name attribute - const HTML_ID = 'id'; // HTML id attribute - - // External block definition - const EXTERNAL_BLOCK = 'externalBlock'; // External block name - const EXTERNAL_START_BLOCK_HTML_TAG = '
'; // External block start tag - const EXTERNAL_END_BLOCK_HTML_TAG = '
'; // External block end tag - - // HTML attributes - const LABEL = 'title'; + const HTML_NAME = 'name'; // HTML name attribute + const HTML_ID = 'id'; // HTML id attribute + + // External block definition + const EXTERNAL_BLOCK = 'externalBlock'; // External block name + const EXTERNAL_START_BLOCK_HTML_TAG = '
'; // External block start tag + const EXTERNAL_END_BLOCK_HTML_TAG = '
'; // External block end tag + + // HTML attributes + const LABEL = 'title'; const REGEX = 'regex'; const TITLE = 'description'; const REQUIRED = 'required-field'; @@ -26,11 +26,12 @@ class HTMLWidget extends Widget const MAX_LENGTH = 'max-length'; const MIN_LENGTH = 'min-length'; const PLACEHOLDER = 'placeholder'; + const DISABLED = 'disabled'; - /** - * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties - */ - public function __construct($name, $args = array(), $htmlArgs = array()) + /** + * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties + */ + public function __construct($name, $args = array(), $htmlArgs = array()) { parent::__construct($name, $args); @@ -38,11 +39,11 @@ class HTMLWidget extends Widget $this->_setHtmlProperties($htmlArgs); } - /** - * Initialising html properties, such as the id and name attributes of the HTML element - */ - private function _setHtmlProperties($htmlArgs) - { + /** + * Initialising html properties, such as the id and name attributes of the HTML element + */ + private function _setHtmlProperties($htmlArgs) + { // If $htmlArgs wasn't already stored in $this->_args if (!isset($this->_args[HTMLWidget::HTML_ARG_NAME])) { @@ -58,9 +59,9 @@ class HTMLWidget extends Widget $this->_args[HTMLWidget::HTML_ARG_NAME][$argName] = $argValue; } } - } + } - /** + /** * Prints an attribute name and eventually also the value extracted from $htmlArgs * Set $isValuePresent to false the value should not be displayed */ @@ -113,3 +114,4 @@ class HTMLWidget extends Widget } } } + diff --git a/application/widgets/udf/UDFWidget.php b/application/widgets/udf/UDFWidget.php index 7af3dd926..abbbab022 100644 --- a/application/widgets/udf/UDFWidget.php +++ b/application/widgets/udf/UDFWidget.php @@ -6,8 +6,6 @@ */ class UDFWidget extends HTMLWidget { - private $_requiredPermissions; // The required permissions to use this UDF widget - private $_schema; // Schema name private $_table; // Table name private $_primaryKeyName; // Primary key name @@ -26,26 +24,16 @@ class UDFWidget extends HTMLWidget $this->_initUDFWidget($args); // checks parameters and initialize properties - // Let's start if it's allowed - // NOTE: If it is NOT allowed then no data are loaded - if ($this->udflib->isAllowed($this->_requiredPermissions)) - { - $this->_startUDFWidget($args[UDFLib::UDF_UNIQUE_ID]); - } + $this->_startUDFWidget($args[UDFLib::UDF_UNIQUE_ID]); } /** * Called by the WidgetLib, it renders the HTML of the UDF */ - public function display($widgetData) + public function display($widgetData) { - // Let's start if it's allowed - // NOTE: If it is NOT allowed then no data are loaded - if ($this->_ci->udflib->isAllowed($this->_requiredPermissions)) - { - $this->_ci->udflib->displayUDFWidget($widgetData); - } - } + $this->_ci->udflib->displayUDFWidget($widgetData); + } //------------------------------------------------------------------------------------------------------------------ // Private methods @@ -60,18 +48,11 @@ class UDFWidget extends HTMLWidget // If here then everything is ok // Initialize class properties - $this->_requiredPermissions = null; $this->_schema = null; $this->_table = null; $this->_primaryKeyName = null; $this->_primaryKeyValue = null; - // Retrieved the required permissions parameter if present - if (isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER])) - { - $this->_requiredPermissions = $args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER]; - } - // Retrieved the if (isset($args[UDFLib::SCHEMA_ARG_NAME])) { @@ -113,11 +94,6 @@ class UDFWidget extends HTMLWidget show_error('The parameter "'.UDFLib::UDF_UNIQUE_ID.'" must be specified'); } - if (!isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER])) - { - show_error('The parameter "'.UDFLib::REQUIRED_PERMISSIONS_PARAMETER.'" must be specified'); - } - if (!isset($args[UDFLib::SCHEMA_ARG_NAME])) { show_error('The parameter "'.UDFLib::SCHEMA_ARG_NAME.'" must be specified'); @@ -149,7 +125,6 @@ class UDFWidget extends HTMLWidget $this->udflib->setSession( array( UDFLib::UDF_UNIQUE_ID => $udfUniqueId, // table unique id - UDFLib::REQUIRED_PERMISSIONS_PARAMETER => $this->_requiredPermissions, // UDFLib::SCHEMA_ARG_NAME => $this->_schema, // UDFLib::TABLE_ARG_NAME => $this->_table, // UDFLib::PRIMARY_KEY_NAME => $this->_primaryKeyName, // @@ -158,3 +133,4 @@ class UDFWidget extends HTMLWidget ); } } + 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; } } + diff --git a/public/js/UDFWidget.js b/public/js/UDFWidget.js index b9c3a7386..82c29de35 100644 --- a/public/js/UDFWidget.js +++ b/public/js/UDFWidget.js @@ -55,17 +55,27 @@ var FHC_UDFWidget = { if (FHC_AjaxClient.hasData(data)) { - FHC_DialogLib.alertSuccess('Done!'); + FHC_DialogLib.alertSuccess("Successfully saved"); } else { - console.log(FHC_AjaxClient.getError(data)); + var msgError = "An error occurred while saving these fields:
"; + var errors = FHC_AjaxClient.getError(data); + + for (var i = 0; i < errors.length; i++) + { + var error = errors[i]; + + msgError += FHC_AjaxClient.getError(error)+ "
"; + } + + FHC_DialogLib.alertError(msgError); } } }, { errorCallback: function(data, textStatus, jqXHR) { - console.log('Contact the administrator'); + FHC_DialogLib.alertError("A generic error occurred, please contact the support"); } } ); @@ -98,3 +108,4 @@ $(document).ready(function() { FHC_UDFWidget.display(); }); + diff --git a/soap/stip.class.php b/soap/stip.class.php index 2787dfac3..2c17ad77f 100644 --- a/soap/stip.class.php +++ b/soap/stip.class.php @@ -173,7 +173,7 @@ class stip extends basis_db * Suche Studenten anhand PersonKz * @param $PersonKz */ - function searchMatrikelnummerStg($Matrikelnummer, $StgKz) + function searchMatrikelnummerStg($Matrikelnummer, $StgKz, $studSemester) { $qry = "SELECT prestudent_id, vorname, nachname, svnr, matrikelnr, student.studiengang_kz, person.matr_nr @@ -183,20 +183,35 @@ class stip extends basis_db JOIN public.tbl_person person using(person_id) WHERE person.matr_nr = ".$this->db_add_param($Matrikelnummer)." - AND student.studiengang_kz=".$this->db_add_param(ltrim($StgKz,0)).";"; + AND student.studiengang_kz=".$this->db_add_param(ltrim($StgKz,0))." + AND EXISTS( + SELECT 1 FROM public.tbl_prestudentstatus + WHERE + prestudent_id=student.prestudent_id + AND studiensemester_kurzbz=".$this->db_add_param($studSemester)." + );"; if($this->db_query($qry)) { - if($row = $this->db_fetch_object()) + // wenn mehr als 1 Datensatz gefunden wird --> Fehler + if($this->db_num_rows() == 1 ) { - $this->Vorname_Antwort = $row->vorname; - $this->Familienname_Antwort = $row->nachname; - $this->SVNR_Antwort = $row->svnr; - $this->PersKz_Antwort = trim($row->matrikelnr); - $this->StgKz_Antwort = str_pad($row->studiengang_kz, 4,'0', STR_PAD_LEFT); - $this->Matrikelnummer_Antwort = $row->matr_nr; - $this->AntwortStatusCode = 1; - return $row->prestudent_id; + if($row = $this->db_fetch_object()) + { + $this->Vorname_Antwort = $row->vorname; + $this->Familienname_Antwort = $row->nachname; + $this->SVNR_Antwort = $row->svnr; + $this->PersKz_Antwort = trim($row->matrikelnr); + $this->StgKz_Antwort = str_pad($row->studiengang_kz, 4,'0', STR_PAD_LEFT); + $this->Matrikelnummer_Antwort = $row->matr_nr; + $this->AntwortStatusCode = 1; + return $row->prestudent_id; + } + else + { + $this->AntwortStatusCode = 2; + return false; + } } else { @@ -215,7 +230,7 @@ class stip extends basis_db * Suche Studenten anhand Sozialversicherungsnummer * @param $Svnr */ - function searchSvnr($Svnr) + function searchSvnr($Svnr, $StgKz, $studSemester) { $qry = "SELECT prestudent_id, vorname, nachname, svnr, matrikelnr, student.studiengang_kz, person.matr_nr @@ -223,7 +238,18 @@ class stip extends basis_db public.tbl_student student JOIN public.tbl_benutzer benutzer on(benutzer.uid=student.student_uid) JOIN public.tbl_person person using(person_id) - WHERE person.svnr = ".$this->db_add_param($Svnr).";"; + WHERE person.svnr = ".$this->db_add_param($Svnr); + + if ($StgKz != '') + $qry.=" AND student.studiengang_kz=".$this->db_add_param($StgKz); + + if ($studSemester != '') + $qry.=" AND EXISTS( + SELECT 1 FROM public.tbl_prestudentstatus + WHERE + prestudent_id=student.prestudent_id + AND studiensemester_kurzbz=".$this->db_add_param($studSemester)." + )"; if($this->db_query($qry)) { @@ -266,7 +292,7 @@ class stip extends basis_db * Suche Studenten anhand Vor- und Nachname * @param $Svnr */ - function searchVorNachname($Vorname, $Nachname) + function searchVorNachname($Vorname, $Nachname, $StgKz, $studSemester) { $qry = "SELECT prestudent_id, vorname, nachname, svnr, matrikelnr, student.studiengang_kz, person.matr_nr @@ -276,7 +302,18 @@ class stip extends basis_db JOIN public.tbl_person person using(person_id) WHERE person.vorname = ".$this->db_add_param($Vorname)." - AND person.nachname = ".$this->db_add_param($Nachname).";"; + AND person.nachname = ".$this->db_add_param($Nachname); + + if ($StgKz != '') + $qry.=" AND student.studiengang_kz=".$this->db_add_param($StgKz); + + if ($studSemester != '') + $qry.=" AND EXISTS( + SELECT 1 FROM public.tbl_prestudentstatus + WHERE + prestudent_id=student.prestudent_id + AND studiensemester_kurzbz=".$this->db_add_param($studSemester)." + )"; if($this->db_query($qry)) { diff --git a/soap/stip.soap.php b/soap/stip.soap.php index c2ae5eeea..8962dc103 100644 --- a/soap/stip.soap.php +++ b/soap/stip.soap.php @@ -117,11 +117,11 @@ function GetStipendienbezieherStip($parameters) if(!$prestudentID = $StipBezieher->searchPersonKz($BezieherStip->PersKz)) { - if(!$prestudentID = $StipBezieher->searchMatrikelnummerStg($BezieherStip->Matrikelnummer, $BezieherStip->StgKz)) + if(!$prestudentID = $StipBezieher->searchMatrikelnummerStg($BezieherStip->Matrikelnummer, $BezieherStip->StgKz, $studSemester)) { - if(!$prestudentID = $StipBezieher->searchSvnr($BezieherStip->SVNR)) + if(!$prestudentID = $StipBezieher->searchSvnr($BezieherStip->SVNR, $BezieherStip->StgKz, $studSemester)) { - $prestudentID = $StipBezieher->searchVorNachname($BezieherStip->Vorname, $BezieherStip->Familienname); + $prestudentID = $StipBezieher->searchVorNachname($BezieherStip->Vorname, $BezieherStip->Familienname, $BezieherStip->StgKz, $studSemester); } } } diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index f2be0b9e4..6e24987c1 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -12492,6 +12492,246 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => '3gNachweis', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "3G Nachweis", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "3G evidence", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'QrViaWebcam', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "QR-Code via Webcam scannen", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "scan qr code via webcam", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'oder', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "oder", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "or", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'ZertifikatAlsPdfHochladen', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Zertifikat als PDF hochladen", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "upload certificate pdf", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'ValidierungsergebnisAktuellesGueltigkeitsdatum', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Validierungsergebnis / aktuelles Gültigkeitsdatum", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "validation result / current valid date", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'DateiZiehenUndAblegen', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Datei hier hinziehen und ablegen", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "drag & drop file here", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'KeinZugriffWebcam', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Zugriff auf die Webcam nicht möglich!", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "webcam access denied", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'gueltigBis', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "gültig bis", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "valid to", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'ZertifikatUngueltig', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Zertifikat ungültig", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "certificate invalid", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'ZertifikatKonnteNichtGeprueftWerden', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Das Zertifikat konnte nicht verifiziert werden.", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "certificate could not be verified.", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => 'Laedt', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Lädt", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "loading", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'eucovidqr', + 'phrase' => '3G', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => "Covid19 Gültigkeitsdatum", + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => "covid19 valid date", + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), );