From c2bc48d320319753c4120bb7a1e097d944b03e01 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 28 Nov 2019 16:51:38 +0100 Subject: [PATCH 1/9] - Placed a timestamp in the filter/table widget session - Added a constant as fallback timeout for filter/table widget - Added a parameter to specify the filter/table widget life time - Filter/table widget on load removes expired filter/table widgets from session --- application/libraries/FilterWidgetLib.php | 77 ++++++++++++++++------- application/libraries/TableWidgetLib.php | 59 ++++++++++++----- application/widgets/FilterWidget.php | 75 ++++++++++++++-------- application/widgets/TableWidget.php | 55 +++++++++++----- 4 files changed, 189 insertions(+), 77 deletions(-) diff --git a/application/libraries/FilterWidgetLib.php b/application/libraries/FilterWidgetLib.php index 0117377a5..c2e57eed2 100644 --- a/application/libraries/FilterWidgetLib.php +++ b/application/libraries/FilterWidgetLib.php @@ -7,8 +7,10 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); */ class FilterWidgetLib { - // Session parameters names - const SESSION_NAME = 'FHC_FILTER_WIDGET'; // Filter session name + // FilterWidget session name + const SESSION_NAME = 'FHC_FILTER_WIDGET'; + + // Session elements const SESSION_FILTER_NAME = 'filterName'; const SESSION_FIELDS = 'fields'; const SESSION_SELECTED_FIELDS = 'selectedFields'; @@ -17,13 +19,19 @@ class FilterWidgetLib const SESSION_CHECKBOXES = 'checkboxes'; const SESSION_FILTERS = 'filters'; const SESSION_METADATA = 'datasetMetadata'; - const SESSION_DATASET = 'dataset'; const SESSION_ROW_NUMBER = 'rowNumber'; - const SESSION_RELOAD_DATASET = 'reloadDataset'; + const SESSION_TIMEOUT = 'sessionTimeout'; + + // Session dataset elements + const SESSION_DATASET = 'dataset'; + const SESSION_DATASET_RELOAD = 'reloadDataset'; const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation'; const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions'; const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions'; + // Default session timeout + const SESSION_DEFAULT_TIMEOUT = 30; + // Alias for the dynamic table used to retrieve the dataset const DATASET_TABLE_ALIAS = 'datasetFilterTable'; @@ -33,16 +41,16 @@ class FilterWidgetLib // ...to identify a single filter widget in the DB const FILTER_ID = 'filter_id'; - const APP_PARAMETER = 'app'; - const DATASET_NAME_PARAMETER = 'datasetName'; - const FILTER_KURZBZ_PARAMETER = 'filterKurzbz'; - const DATASET_RELOAD_PARAMETER = 'reloadDataset'; + const APP = 'app'; + const DATASET_NAME = 'datasetName'; + const FILTER_KURZBZ = 'filterKurzbz'; + const DATASET_RELOAD = 'reloadDataset'; // ...to specify permissions that are needed to use this FilterWidget - const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions'; + const REQUIRED_PERMISSIONS = 'requiredPermissions'; // ...stament to retrieve the dataset - const QUERY_PARAMETER = 'query'; + const QUERY = 'query'; // ...to specify more columns or aliases for them const ADDITIONAL_COLUMNS = 'additionalColumns'; @@ -131,7 +139,7 @@ class FilterWidgetLib // 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); + if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS); return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_FILTER_METHOD, self::PERMISSION_TYPE); } @@ -179,6 +187,29 @@ class FilterWidgetLib setSessionElement(self::SESSION_NAME, $this->_filterUniqueId, $session); // stores the single value } + /** + * + */ + public function dropExpiredFilterWidgets() + { + // Loads the session for all the filter widgets + $filterWidgetsSession = getSession(self::SESSION_NAME); + + // If something is present in session + if ($filterWidgetsSession != null) + { + // Loops in the session for all the filter widgets + foreach ($filterWidgetsSession as $filterWidget => $filterWidgetData) + { + // If this filter widget is not the currrent used filter widget and the it is expired... + if ($this->_filterUniqueId != $filterWidget && $filterWidgetData[self::SESSION_TIMEOUT] <= time()) + { + cleanSessionElement(self::SESSION_NAME, $filterWidget); // ...remove it + } + } + } + } + /** * Loads the definition data from DB for a filter widget */ @@ -471,7 +502,7 @@ class FilterWidgetLib // Write changes into the session $this->setSessionElement(self::SESSION_FILTERS, $filters); - $this->setSessionElement(self::SESSION_RELOAD_DATASET, true); // the dataset must be reloaded + $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded $removeAppliedFilter = true; } @@ -523,7 +554,7 @@ class FilterWidgetLib // Write changes into the session $this->setSessionElement(self::SESSION_FILTERS, $filters); - $this->setSessionElement(self::SESSION_RELOAD_DATASET, true); // the dataset must be reloaded + $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded $applyFilters = true; } @@ -537,7 +568,7 @@ class FilterWidgetLib */ public function reloadDataset() { - $this->setSessionElement(self::SESSION_RELOAD_DATASET, true); + $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); } /** @@ -603,8 +634,8 @@ class FilterWidgetLib // Loads the definition to check if is already present in the DB $definition = $this->_ci->FiltersModel->loadWhere(array( - 'app' => $this->getSessionElement(self::APP_PARAMETER), - 'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER), + 'app' => $this->getSessionElement(self::APP), + 'dataset_name' => $this->getSessionElement(self::DATASET_NAME), 'description' => $descPGArray, 'person_id' => $authPersonId )); @@ -632,8 +663,8 @@ class FilterWidgetLib // update it $this->_ci->FiltersModel->update( array( - 'app' => $this->getSessionElement(self::APP_PARAMETER), - 'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER), + 'app' => $this->getSessionElement(self::APP), + 'dataset_name' => $this->getSessionElement(self::DATASET_NAME), 'description' => $descPGArray, 'person_id' => $authPersonId ), @@ -648,8 +679,8 @@ class FilterWidgetLib { $this->_ci->FiltersModel->insert( array( - 'app' => $this->getSessionElement(self::APP_PARAMETER), - 'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER), + 'app' => $this->getSessionElement(self::APP), + 'dataset_name' => $this->getSessionElement(self::DATASET_NAME), 'filter_kurzbz' => uniqid($authPersonId, true), 'description' => $descPGArray, 'person_id' => $authPersonId, @@ -693,7 +724,7 @@ class FilterWidgetLib public function generateFilterMenu($navigationPage) { // Loads the NavigationLib for the current page (given as parameter) - $this->_ci->load->library('NavigationLib', array(FilterWidgetLib::NAVIGATION_PAGE => $navigationPage)); + $this->_ci->load->library('NavigationLib', array(self::NAVIGATION_PAGE => $navigationPage)); $filterMenu = null; $currentMenu = $this->_ci->navigationlib->getSessionMenu(); // The navigation menu currently stored in session @@ -706,7 +737,7 @@ class FilterWidgetLib // Loads all the filters related to this page (same dataset_name and same app name) $filters = $this->_ci->FiltersModel->getFiltersByAppDatasetName( - $session[self::APP_PARAMETER], $session[self::DATASET_NAME_PARAMETER] + $session[self::APP], $session[self::DATASET_NAME] ); // If filters were loaded @@ -775,7 +806,7 @@ class FilterWidgetLib ); // Sets in the session only the element related to the filters menu - $this->_ci->navigationlib->setSessionElementMenu(FilterWidgetLib::NAV_MENU_FILTER_KEY, $filterMenu); + $this->_ci->navigationlib->setSessionElementMenu(self::NAV_MENU_FILTER_KEY, $filterMenu); } } } diff --git a/application/libraries/TableWidgetLib.php b/application/libraries/TableWidgetLib.php index 009103e68..42f645954 100644 --- a/application/libraries/TableWidgetLib.php +++ b/application/libraries/TableWidgetLib.php @@ -9,33 +9,40 @@ class TableWidgetLib { const TABLE_UNIQUE_ID = 'tableUniqueId'; // TableWidget unique id - // Session parameters names - const SESSION_NAME = 'FHC_TABLE_WIDGET'; // Table session name + // TableWidget session name + const SESSION_NAME = 'FHC_TABLE_WIDGET'; + + // Session elements const SESSION_FIELDS = 'fields'; const SESSION_COLUMNS_ALIASES = 'columnsAliases'; const SESSION_ADDITIONAL_COLUMNS = 'additionalColumns'; const SESSION_CHECKBOXES = 'checkboxes'; const SESSION_METADATA = 'datasetMetadata'; - const SESSION_DATASET = 'dataset'; const SESSION_ROW_NUMBER = 'rowNumber'; - const SESSION_RELOAD_DATASET = 'reloadDataset'; + + // Session dataset elements + const SESSION_DATASET = 'dataset'; + const SESSION_DATASET_RELOAD = 'reloadDataset'; const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation'; const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions'; const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions'; + // Default session timeout + const SESSION_DEFAULT_TIMEOUT = 30; + // Alias for the dynamic table used to retrieve the dataset const DATASET_TABLE_ALIAS = 'datasetTableWidget'; // Parameters names... // ...to reload the dataset - const DATASET_RELOAD_PARAMETER = 'reloadDataset'; + const DATASET_RELOAD = 'reloadDataset'; // ...to specify permissions that are needed to use this TableWidget - const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions'; + const REQUIRED_PERMISSIONS = 'requiredPermissions'; // ...stament to retrieve the dataset - const QUERY_PARAMETER = 'query'; + const QUERY = 'query'; // ...to specify more columns or aliases for them const ADDITIONAL_COLUMNS = 'additionalColumns'; @@ -50,6 +57,7 @@ class TableWidgetLib const DATASET_REPRESENTATION = 'datasetRepresentation'; const DATASET_REP_OPTIONS = 'datasetRepOptions'; const DATASET_REP_FIELDS_DEFS = 'datasetRepFieldsDefs'; + const DATASET_TIMEOUT = 'datasetTimeout'; // ...and its expiring time // Different dataset representations const DATASET_REP_TABLESORTER = 'tablesorter'; @@ -86,13 +94,13 @@ class TableWidgetLib // 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); + if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS); return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE); } /** - * Wrapper method to the session helper funtions to retrieve the whole session for this filter + * Wrapper method to the session helper funtions to retrieve the whole session for this table widget */ public function getSession() { @@ -100,7 +108,7 @@ class TableWidgetLib } /** - * Wrapper method to the session helper funtions to retrieve one element from the session of this filter + * Wrapper method to the session helper funtions to retrieve one element from the session of this table widget */ public function getSessionElement($name) { @@ -115,7 +123,7 @@ class TableWidgetLib } /** - * Wrapper method to the session helper funtions to set the whole session for this filter + * Wrapper method to the session helper funtions to set the whole session for this table widget */ public function setSession($data) { @@ -123,7 +131,7 @@ class TableWidgetLib } /** - * Wrapper method to the session helper funtions to set one element in the session for this filter + * Wrapper method to the session helper funtions to set one element in the session for this table widget */ public function setSessionElement($name, $value) { @@ -135,7 +143,30 @@ class TableWidgetLib } /** - * Generate the query to retrieve the dataset for a filter + * + */ + public function dropExpiredTableWidgets() + { + // Loads the session for all the table widgets + $tableWidgetsSession = getSession(self::SESSION_NAME); + + // If something is present in session + if ($tableWidgetsSession != null) + { + // Loops in the session for all the table widgets + foreach ($tableWidgetsSession as $tableWidget => $tableWidgetData) + { + // If this table widget is not the currrent used table widget and the it is expired... + if ($this->_tableUniqueId != $tableWidget && $tableWidgetData[self::SESSION_TIMEOUT] <= time()) + { + cleanSessionElement(self::SESSION_NAME, $tableWidget); // ...remove it + } + } + } + } + + /** + * Generate the query to retrieve the dataset for a table widget */ public function generateDatasetQuery($query) { @@ -177,7 +208,7 @@ class TableWidgetLib } /** - * Return an unique string that identify this filter widget + * Return an unique string that identify this table widget * NOTE: The default value is the URI where the FilterWidget is called * If the fhc_controller_id is present then is also used */ diff --git a/application/widgets/FilterWidget.php b/application/widgets/FilterWidget.php index d168744c8..f02fb7950 100644 --- a/application/widgets/FilterWidget.php +++ b/application/widgets/FilterWidget.php @@ -57,6 +57,8 @@ class FilterWidget extends Widget private $_reloadDataset; // Force Reload of Dataset + private $_sessionTimeout; // session expiring time + private static $_FilterWidgetInstance; // static property that contains the instance of itself /** @@ -202,27 +204,28 @@ class FilterWidget extends Widget $this->_datasetRepresentation = null; $this->_datasetRepresentationOptions = null; $this->_datasetRepFieldsDefs = null; + $this->_sessionTimeout = FilterWidgetLib::SESSION_DEFAULT_TIMEOUT; // Retrieved the required permissions parameter if present - if (isset($args[FilterWidgetLib::REQUIRED_PERMISSIONS_PARAMETER])) + if (isset($args[FilterWidgetLib::REQUIRED_PERMISSIONS])) { - $this->_requiredPermissions = $args[FilterWidgetLib::REQUIRED_PERMISSIONS_PARAMETER]; + $this->_requiredPermissions = $args[FilterWidgetLib::REQUIRED_PERMISSIONS]; } // Parameters needed to retrieve univocally a filter from DB - if (isset($args[FilterWidgetLib::APP_PARAMETER])) + if (isset($args[FilterWidgetLib::APP])) { - $this->_app = $args[FilterWidgetLib::APP_PARAMETER]; + $this->_app = $args[FilterWidgetLib::APP]; } - if (isset($args[FilterWidgetLib::DATASET_NAME_PARAMETER])) + if (isset($args[FilterWidgetLib::DATASET_NAME])) { - $this->_datasetName = $args[FilterWidgetLib::DATASET_NAME_PARAMETER]; + $this->_datasetName = $args[FilterWidgetLib::DATASET_NAME]; } - if (isset($args[FilterWidgetLib::FILTER_KURZBZ_PARAMETER])) + if (isset($args[FilterWidgetLib::FILTER_KURZBZ])) { - $this->_filterKurzbz = $args[FilterWidgetLib::FILTER_KURZBZ_PARAMETER]; + $this->_filterKurzbz = $args[FilterWidgetLib::FILTER_KURZBZ]; } if (isset($args[FilterWidgetLib::FILTER_ID])) @@ -231,14 +234,14 @@ class FilterWidget extends Widget } // How to retrieve data for the filter: SQL statement or a result from DB - if (isset($args[FilterWidgetLib::QUERY_PARAMETER])) + if (isset($args[FilterWidgetLib::QUERY])) { - $this->_query = $args[FilterWidgetLib::QUERY_PARAMETER]; + $this->_query = $args[FilterWidgetLib::QUERY]; } - if (isset($args[FilterWidgetLib::DATASET_RELOAD_PARAMETER])) + if (isset($args[FilterWidgetLib::DATASET_RELOAD])) { - $this->_reloadDataset = $args[FilterWidgetLib::DATASET_RELOAD_PARAMETER]; + $this->_reloadDataset = $args[FilterWidgetLib::DATASET_RELOAD]; } // Parameter is used to add extra columns to the dataset @@ -332,6 +335,12 @@ class FilterWidget extends Widget { $this->_datasetRepFieldsDefs = $args[FilterWidgetLib::DATASET_REP_FIELDS_DEFS]; } + + // To specify the expiring session time + if (isset($args[FilterWidgetLib::SESSION_TIMEOUT]) && is_numeric($args[FilterWidgetLib::SESSION_TIMEOUT])) + { + $this->_sessionTimeout = $args[FilterWidgetLib::SESSION_TIMEOUT]; + } } /** @@ -339,31 +348,36 @@ class FilterWidget extends Widget */ private function _checkParameters($args) { + // If no options are given to this widget... if (!is_array($args) || (is_array($args) && count($args) == 0)) { show_error('Second parameter of the widget call must be a NOT empty associative array'); } - else + else // ...otherwise { - if ((!isset($args[FilterWidgetLib::APP_PARAMETER]) && !isset($args[FilterWidgetLib::DATASET_NAME_PARAMETER])) + // Parameters (app AND dataset name) OR filter id are mandatory + if ((!isset($args[FilterWidgetLib::APP]) && !isset($args[FilterWidgetLib::DATASET_NAME])) && !isset($args[FilterWidgetLib::FILTER_ID])) { show_error( - 'The parameters ("'.FilterWidgetLib::APP_PARAMETER.'" AND "'.FilterWidgetLib::DATASET_NAME_PARAMETER.') OR "'. + 'The parameters ("'.FilterWidgetLib::APP.'" AND "'.FilterWidgetLib::DATASET_NAME.') OR "'. FilterWidgetLib::FILTER_ID.'" must be specified' ); } - if (!isset($args[FilterWidgetLib::QUERY_PARAMETER])) + // The query parameter is mandatory + if (!isset($args[FilterWidgetLib::QUERY])) { - show_error('The parameters "'.FilterWidgetLib::QUERY_PARAMETER.'" must be specified'); + show_error('The parameter "'.FilterWidgetLib::QUERY.'" must be specified'); } + // The dataset representation parameter is mandatory if (!isset($args[FilterWidgetLib::DATASET_REPRESENTATION])) { show_error('The parameter "'.FilterWidgetLib::DATASET_REPRESENTATION.'" must be specified'); } + // Checks if the dataset representation parameter is valid if (isset($args[FilterWidgetLib::DATASET_REPRESENTATION]) && $args[FilterWidgetLib::DATASET_REPRESENTATION] != FilterWidgetLib::DATASET_REP_TABLESORTER && $args[FilterWidgetLib::DATASET_REPRESENTATION] != FilterWidgetLib::DATASET_REP_PIVOTUI @@ -377,6 +391,12 @@ class FilterWidget extends Widget .FilterWidgetLib::DATASET_REP_TABULATOR.'")' ); } + + // If given the session timeout parameter must be a number + if (isset($args[FilterWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[FilterWidgetLib::SESSION_TIMEOUT])) + { + show_error('The parameter "'.FilterWidgetLib::SESSION_TIMEOUT.'" must be a number'); + } } } @@ -385,6 +405,9 @@ class FilterWidget extends Widget */ private function _startFilterWidget() { + // Looks for expired filter widgets in session and drops them + $this->filterwidgetlib->dropExpiredFilterWidgets(); + // Read the all session for this filter widget $session = $this->filterwidgetlib->getSession(); @@ -402,14 +425,14 @@ class FilterWidget extends Widget } else // else if the filter loaded in session is the same that is being requested { - // Get SESSION_RELOAD_DATASET from the session - $sessionReloadDataset = $this->filterwidgetlib->getSessionElement(FilterWidgetLib::SESSION_RELOAD_DATASET); + // Get SESSION_DATASET_RELOAD from the session + $sessionReloadDataset = $this->filterwidgetlib->getSessionElement(FilterWidgetLib::SESSION_DATASET_RELOAD); // if Filter changed or reload is forced by parameter then reload the Dataset if ($this->_reloadDataset === true || $sessionReloadDataset === true) { // Set as false to stop changing the dataset - $this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_RELOAD_DATASET, false); + $this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_DATASET_RELOAD, false); // Generate dataset query using filters from the session $datasetQuery = $this->filterwidgetlib->generateDatasetQuery( @@ -467,8 +490,8 @@ class FilterWidget extends Widget $this->filterwidgetlib->setSession( array( FilterWidgetLib::FILTER_ID => $this->_filterId, // the current filter id - FilterWidgetLib::APP_PARAMETER => $this->_app, // the current app parameter - FilterWidgetLib::DATASET_NAME_PARAMETER => $this->_datasetName, // the carrent dataset name + FilterWidgetLib::APP => $this->_app, // the current app parameter + FilterWidgetLib::DATASET_NAME => $this->_datasetName, // the carrent dataset name FilterWidgetLib::SESSION_FILTER_NAME => $filterName, // the current filter name FilterWidgetLib::SESSION_FIELDS => $this->FiltersModel->getExecutedQueryListFields(), // all the fields of the dataset FilterWidgetLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns), // all the selected fields @@ -479,7 +502,7 @@ class FilterWidget extends Widget FilterWidgetLib::SESSION_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), // the metadata of the dataset FilterWidgetLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this filter FilterWidgetLib::SESSION_DATASET => $dataset->retval, // the entire dataset - FilterWidgetLib::SESSION_RELOAD_DATASET => false, // if the dataset must be reloaded, not needed the first time + FilterWidgetLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time FilterWidgetLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation FilterWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options FilterWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition @@ -489,9 +512,11 @@ class FilterWidget extends Widget } } + // NOTE: latest operations to be performed in the session to be shure that they are always present // To be always stored in the session, otherwise is not possible to load data from Filters controller - // NOTE: must the latest operation to be performed in the session to be shure that is always present - $this->filterwidgetlib->setSessionElement(FilterWidgetLib::REQUIRED_PERMISSIONS_PARAMETER, $this->_requiredPermissions); + $this->filterwidgetlib->setSessionElement(FilterWidgetLib::REQUIRED_PERMISSIONS, $this->_requiredPermissions); + // Renew or set the session expiring time + $this->filterwidgetlib->setSessionElement(FilterWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time())); } /** diff --git a/application/widgets/TableWidget.php b/application/widgets/TableWidget.php index a0f64b291..a536225f7 100644 --- a/application/widgets/TableWidget.php +++ b/application/widgets/TableWidget.php @@ -38,6 +38,8 @@ class TableWidget extends Widget private $_reloadDataset; // Force Reload of Dataset + private $_sessionTimeout; // session expiring time + private static $_TableWidgetInstance; // static property that contains the instance of itself /** @@ -124,22 +126,23 @@ class TableWidget extends Widget $this->_datasetRepresentation = null; $this->_datasetRepresentationOptions = null; $this->_datasetRepFieldsDefs = null; + $this->_sessionTimeout = TableWidgetLib::SESSION_DEFAULT_TIMEOUT; // Retrieved the required permissions parameter if present - if (isset($args[TableWidgetLib::REQUIRED_PERMISSIONS_PARAMETER])) + if (isset($args[TableWidgetLib::REQUIRED_PERMISSIONS])) { - $this->_requiredPermissions = $args[TableWidgetLib::REQUIRED_PERMISSIONS_PARAMETER]; + $this->_requiredPermissions = $args[TableWidgetLib::REQUIRED_PERMISSIONS]; } // How to retrieve data for the table: SQL statement or a result from DB - if (isset($args[TableWidgetLib::QUERY_PARAMETER])) + if (isset($args[TableWidgetLib::QUERY])) { - $this->_query = $args[TableWidgetLib::QUERY_PARAMETER]; + $this->_query = $args[TableWidgetLib::QUERY]; } - if (isset($args[TableWidgetLib::DATASET_RELOAD_PARAMETER])) + if (isset($args[TableWidgetLib::DATASET_RELOAD])) { - $this->_reloadDataset = $args[TableWidgetLib::DATASET_RELOAD_PARAMETER]; + $this->_reloadDataset = $args[TableWidgetLib::DATASET_RELOAD]; } // Parameter is used to add extra columns to the dataset @@ -197,6 +200,12 @@ class TableWidget extends Widget { $this->_datasetRepFieldsDefs = $args[TableWidgetLib::DATASET_REP_FIELDS_DEFS]; } + + // To specify the expiring session time + if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && is_numeric($args[TableWidgetLib::SESSION_TIMEOUT])) + { + $this->_sessionTimeout = $args[TableWidgetLib::SESSION_TIMEOUT]; + } } /** @@ -204,27 +213,32 @@ class TableWidget extends Widget */ private function _checkParameters($args) { + // If no options are given to this widget... if (!is_array($args) || (is_array($args) && count($args) == 0)) { show_error('Second parameter of the widget call must be a NOT empty associative array'); } - else + else // ...otherwise { + // The unique id parameter is mandatory if (!isset($args[TableWidgetLib::TABLE_UNIQUE_ID])) { show_error('The parameter "'.TableWidgetLib::TABLE_UNIQUE_ID.'" must be specified'); } - if (!isset($args[TableWidgetLib::QUERY_PARAMETER])) + // The query parameter is mandatory + if (!isset($args[TableWidgetLib::QUERY])) { - show_error('The parameters "'.TableWidgetLib::QUERY_PARAMETER.'" must be specified'); + show_error('The parameter "'.TableWidgetLib::QUERY.'" must be specified'); } + // The dataset representation parameter is mandatory if (!isset($args[TableWidgetLib::DATASET_REPRESENTATION])) { show_error('The parameter "'.TableWidgetLib::DATASET_REPRESENTATION.'" must be specified'); } + // Checks if the dataset representation parameter is valid if (isset($args[TableWidgetLib::DATASET_REPRESENTATION]) && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABLESORTER && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_PIVOTUI @@ -238,6 +252,12 @@ class TableWidget extends Widget .TableWidgetLib::DATASET_REP_TABULATOR.'")' ); } + + // If given the session timeout parameter must be a number + if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[TableWidgetLib::SESSION_TIMEOUT])) + { + show_error('The parameter "'.TableWidgetLib::SESSION_TIMEOUT.'" must be a number'); + } } } @@ -246,20 +266,23 @@ class TableWidget extends Widget */ private function _startTableWidget($tableUniqueId) { + // Looks for expired table widgets in session and drops them + $this->tablewidgetlib->dropExpiredTableWidgets(); + // Read the all session for this table widget $session = $this->tablewidgetlib->getSession(); // If session is NOT empty -> a table was already loaded if ($session != null) { - // Get SESSION_RELOAD_DATASET from the session - $sessionReloadDataset = $this->tablewidgetlib->getSessionElement(TableWidgetLib::SESSION_RELOAD_DATASET); + // Get SESSION_DATASET_RELOAD from the session + $sessionReloadDataset = $this->tablewidgetlib->getSessionElement(TableWidgetLib::SESSION_DATASET_RELOAD); // if Filter changed or reload is forced by parameter then reload the Dataset if ($this->_reloadDataset === true || $sessionReloadDataset === true) { // Set as false to stop changing the dataset - $this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_RELOAD_DATASET, false); + $this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_DATASET_RELOAD, false); // Generate dataset query using tables from the session $datasetQuery = $this->tablewidgetlib->generateDatasetQuery($this->_query); @@ -305,7 +328,7 @@ class TableWidget extends Widget TableWidgetLib::SESSION_METADATA => $this->tablewidgetlib->getExecutedQueryMetaData(), // the metadata of the dataset TableWidgetLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this table TableWidgetLib::SESSION_DATASET => $dataset->retval, // the entire dataset - TableWidgetLib::SESSION_RELOAD_DATASET => false, // if the dataset must be reloaded, not needed the first time + TableWidgetLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time TableWidgetLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation TableWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options TableWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition @@ -314,9 +337,11 @@ class TableWidget extends Widget } } - // To be always stored in the session, otherwise is not possible to load data from Filters controller // NOTE: must the latest operation to be performed in the session to be shure that is always present - $this->tablewidgetlib->setSessionElement(TableWidgetLib::REQUIRED_PERMISSIONS_PARAMETER, $this->_requiredPermissions); + // To be always stored in the session, otherwise is not possible to load data from Filters controller + $this->tablewidgetlib->setSessionElement(TableWidgetLib::REQUIRED_PERMISSIONS, $this->_requiredPermissions); + // Renew or set the session expiring time + $this->filterwidgetlib->setSessionElement(TableWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time())); } /** From fb806285101b53cf7024875895c187c72758a6d0 Mon Sep 17 00:00:00 2001 From: Nikolaus Krondraf Date: Wed, 8 Jan 2020 13:15:29 +0100 Subject: [PATCH 2/9] =?UTF-8?q?Studiengang=20wird=20bei=20Pr=C3=BCfungsanm?= =?UTF-8?q?eldung=20nicht=20mehr=20gepr=C3=BCft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pruefung/pruefungsanmeldung.json.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/cis/private/lehre/pruefung/pruefungsanmeldung.json.php b/cis/private/lehre/pruefung/pruefungsanmeldung.json.php index e96f0fcea..ce7479cf0 100644 --- a/cis/private/lehre/pruefung/pruefungsanmeldung.json.php +++ b/cis/private/lehre/pruefung/pruefungsanmeldung.json.php @@ -632,24 +632,11 @@ function saveAnmeldung($aktStudiensemester = null, $uid = null) { foreach ($prestudenten as $ps) { - if($ps->studiengang_kz === $studiengang_kz) + if ($ps->getLaststatus($ps->prestudent_id, $stdsem)) { - if ($ps->getLaststatus($ps->prestudent_id, $stdsem)) + if (($ps->status_kurzbz == "Student") || ($ps->status_kurzbz == "Unterbrecher")) { - if (($ps->status_kurzbz == "Student") || ($ps->status_kurzbz == "Unterbrecher")) - { - $prestudent_id = $ps->prestudent_id; - } - else - { - if ($ps->getLaststatus($ps->prestudent_id, $stdsem_lv_besuch)) - { - if (($ps->status_kurzbz == "Student") || ($ps->status_kurzbz == "Unterbrecher")) - { - $prestudent_id = $ps->prestudent_id; - } - } - } + $prestudent_id = $ps->prestudent_id; } else { @@ -662,6 +649,16 @@ function saveAnmeldung($aktStudiensemester = null, $uid = null) } } } + else + { + if ($ps->getLaststatus($ps->prestudent_id, $stdsem_lv_besuch)) + { + if (($ps->status_kurzbz == "Student") || ($ps->status_kurzbz == "Unterbrecher")) + { + $prestudent_id = $ps->prestudent_id; + } + } + } } } else From d8437a9936760cb13fc99f7d8fdbe630be98abb4 Mon Sep 17 00:00:00 2001 From: Nikolaus Krondraf Date: Wed, 8 Jan 2020 13:48:45 +0100 Subject: [PATCH 3/9] =?UTF-8?q?Fehler=20beim=20Auslesen=20des=20gew=C3=A4h?= =?UTF-8?q?lten=20Studiengangs=20korrigiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/private/lehre/pruefung/pruefung.js.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cis/private/lehre/pruefung/pruefung.js.php b/cis/private/lehre/pruefung/pruefung.js.php index 15bd195ee..7a76f48d0 100644 --- a/cis/private/lehre/pruefung/pruefung.js.php +++ b/cis/private/lehre/pruefung/pruefung.js.php @@ -575,8 +575,8 @@ function saveAnmeldung(lehrveranstaltung_id, termin_id) studienverpflichtung_id = $("#studienverpflichtung option:selected").val(); var studiengang_kz = null; - if($('#select_studiengang').length) - studiengang_kz = $('#select_studiengang option:selected').val(); + if($('#prestudent_studiengang').length) + studiengang_kz = $('#prestudent_studiengang option:selected').val(); $.ajax({ dataType: 'json', From 232379ae7251588d08c3094b8e8858d3bfc3dd82 Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 8 Jan 2020 15:49:26 +0100 Subject: [PATCH 4/9] Added SESSION_TIMEOUT constant to TableWidgetLib --- application/libraries/TableWidgetLib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/libraries/TableWidgetLib.php b/application/libraries/TableWidgetLib.php index 42f645954..139e5d6cb 100644 --- a/application/libraries/TableWidgetLib.php +++ b/application/libraries/TableWidgetLib.php @@ -19,6 +19,7 @@ class TableWidgetLib const SESSION_CHECKBOXES = 'checkboxes'; const SESSION_METADATA = 'datasetMetadata'; const SESSION_ROW_NUMBER = 'rowNumber'; + const SESSION_TIMEOUT = 'sessionTimeout'; // Session dataset elements const SESSION_DATASET = 'dataset'; From bf9cc35dd51a5b6f575e7d13aa7f0f7bd650defd Mon Sep 17 00:00:00 2001 From: Paolo Date: Wed, 8 Jan 2020 15:52:03 +0100 Subject: [PATCH 5/9] TableWidget fixed a typo --- application/widgets/TableWidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/widgets/TableWidget.php b/application/widgets/TableWidget.php index a536225f7..97bc29d5e 100644 --- a/application/widgets/TableWidget.php +++ b/application/widgets/TableWidget.php @@ -341,7 +341,7 @@ class TableWidget extends Widget // To be always stored in the session, otherwise is not possible to load data from Filters controller $this->tablewidgetlib->setSessionElement(TableWidgetLib::REQUIRED_PERMISSIONS, $this->_requiredPermissions); // Renew or set the session expiring time - $this->filterwidgetlib->setSessionElement(TableWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time())); + $this->tablewidgetlib->setSessionElement(TableWidgetLib::SESSION_TIMEOUT, strtotime('+'.$this->_sessionTimeout.' minutes', time())); } /** From a5fae5f07fd384f93d4b78fee471075de69c4f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Wed, 8 Jan 2020 16:16:49 +0100 Subject: [PATCH 6/9] =?UTF-8?q?Lehrauftragsverwaltung=20-=20Berechtigungsp?= =?UTF-8?q?r=C3=BCfung=20beim=20Akzeptieren=20von=20Lehrauftr=C3=A4gen=20a?= =?UTF-8?q?ngepasst=20wenn=20Lektor=20mehrere=20Accounts=20besitzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lehrauftrag/LehrauftragAkzeptieren.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php b/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php index 31e2ffb31..cc37eb9ec 100644 --- a/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php +++ b/application/controllers/lehre/lehrauftrag/LehrauftragAkzeptieren.php @@ -131,7 +131,16 @@ class LehrauftragAkzeptieren extends Auth_Controller if ($result = getData($this->BenutzerModel->getFromPersonId($result[0]->person_id))) { // * finally check uid of contract against the logged in user - if ($result[0]->uid != $this->_uid) + $account_found = false; + foreach($result as $row_accounts) + { + if($row_accounts->uid == $this->_uid) + { + $account_found = true; + } + } + + if (!$account_found) { show_error('Keine Berechtigung für diesen Vertrag'); } @@ -148,7 +157,7 @@ class LehrauftragAkzeptieren extends Auth_Controller // Set status to accepted $result = $this->VertragvertragsstatusModel->setStatus($vertrag_id, $this->_uid, 'akzeptiert'); - + if ($result->retval) { $json []= array( @@ -165,7 +174,7 @@ class LehrauftragAkzeptieren extends Auth_Controller } } } - + /** * Check if lectors latest active Verwendung has inkludierte Lehre * - inkludierte_lehre is null OR 0: freelancer lector -> has NO inkludierte Lehre @@ -175,7 +184,7 @@ class LehrauftragAkzeptieren extends Auth_Controller public function checkInkludierteLehre() { $result = $this->BisverwendungModel->getLast($this->_uid); - + if (hasData($result)) { $this->outputJsonSuccess(!is_null($result->retval[0]->inkludierte_lehre) && $result->retval[0]->inkludierte_lehre != 0); From 03903ec51b89c2528f90b308520e356f0ec5fa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Wed, 8 Jan 2020 17:06:14 +0100 Subject: [PATCH 7/9] Usernames are always lowered and trimmed after Login --- application/libraries/AuthLib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/libraries/AuthLib.php b/application/libraries/AuthLib.php index c5345a250..1c7c07ed8 100644 --- a/application/libraries/AuthLib.php +++ b/application/libraries/AuthLib.php @@ -378,7 +378,8 @@ class AuthLib } else // otherwise { - $hta = $this->_createAuthObjByPerson(array('uid' => trim($_SERVER['PHP_AUTH_USER']))); + // NOTE: Username needs to be trimmed and lowered because htaccess is allowing login + $hta = $this->_createAuthObjByPerson(array('uid' => mb_strtolower(trim($_SERVER['PHP_AUTH_USER'])))); } // Invalid credentials From 13785a4697580043bfe99ca3ecfd9f453948bf93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Wed, 8 Jan 2020 17:13:23 +0100 Subject: [PATCH 8/9] =?UTF-8?q?PHP=20Notice=20entfernt=20wenn=20eine=20Nac?= =?UTF-8?q?hpr=C3=BCfung=20eingetragen=20wird=20ohne=20dass=20eine=20Note?= =?UTF-8?q?=20vorhanden=20ist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/private/lehre/benotungstool/nachpruefungeintragen.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cis/private/lehre/benotungstool/nachpruefungeintragen.php b/cis/private/lehre/benotungstool/nachpruefungeintragen.php index f1afe0420..0ad985e76 100644 --- a/cis/private/lehre/benotungstool/nachpruefungeintragen.php +++ b/cis/private/lehre/benotungstool/nachpruefungeintragen.php @@ -170,7 +170,9 @@ if (isset($_REQUEST["submit"]) && ($_REQUEST["student_uid"] != '') ) if($pr->getPruefungen($student_uid, "Termin1", $lvid, $stsem)) { if ($pr->result) + { $termin1 = 1; + } else { $lvnote = new lvgesamtnote(); @@ -183,6 +185,7 @@ if (isset($_REQUEST["submit"]) && ($_REQUEST["student_uid"] != '') ) else { $pr_note = 9; + $pr_punkte = ''; $benotungsdatum = $jetzt; } From 2073b7ceda30e48d989fbc57be5720b6445eb451 Mon Sep 17 00:00:00 2001 From: Nikolaus Krondraf Date: Thu, 9 Jan 2020 08:40:40 +0100 Subject: [PATCH 9/9] =?UTF-8?q?Reihung=20wird=20nicht=20neu=20gespeichert?= =?UTF-8?q?=20wenn=20letzte=20Anmeldung=20gel=C3=B6scht=20wird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cis/private/lehre/pruefung/pruefung.js.php | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/cis/private/lehre/pruefung/pruefung.js.php b/cis/private/lehre/pruefung/pruefung.js.php index 7a76f48d0..661094780 100644 --- a/cis/private/lehre/pruefung/pruefung.js.php +++ b/cis/private/lehre/pruefung/pruefung.js.php @@ -892,28 +892,31 @@ function saveReihung(terminId, lehrveranstaltung_id) anmeldung.uid = v.id; reihung.push(anmeldung); }); - $.ajax({ - dataType: 'json', - url: "./pruefungsanmeldung.json.php", - type: "POST", - data: { - method: "saveReihung", - reihung: reihung - }, - error: loadError, - success: function(data){ - if(data.error === 'false' && data.result === true) - { - messageBox("message", "t('pruefung/reihunghErfolgreichGeaendert'); ?>", "green", "highlight", 1000); - } - else - { - messageBox("message", data.errormsg, "red", "highlight", 1000); - } - showAnmeldungen(terminId, lehrveranstaltung_id); - } - }); + if (reihung.length > 0) { + $.ajax({ + dataType: 'json', + url: "./pruefungsanmeldung.json.php", + type: "POST", + data: { + method: "saveReihung", + reihung: reihung + }, + error: loadError, + success: function(data){ + if(data.error === 'false' && data.result === true) + { + messageBox("message", "t('pruefung/reihunghErfolgreichGeaendert'); ?>", "green", "highlight", 1000); + } + else + { + messageBox("message", data.errormsg, "red", "highlight", 1000); + } + + showAnmeldungen(terminId, lehrveranstaltung_id); + } + }); + } } /**