diff --git a/adm_program/system/classes/TableRoles.php b/adm_program/system/classes/TableRoles.php index 8c04719ca5..3746cf6798 100644 --- a/adm_program/system/classes/TableRoles.php +++ b/adm_program/system/classes/TableRoles.php @@ -300,7 +300,7 @@ public static function getCostPeriods($costPeriod = null) */ public function getDefaultList() { - global $gSettingsManager; + global $gSettingsManager, $gCurrentOrganization; $defaultListId = (int) $this->getValue('rol_lst_id'); @@ -317,8 +317,24 @@ public function getDefaultList() } else { - // read system default list configuration - return $gSettingsManager->getInt('lists_default_configuration'); + try + { + // read system default list configuration + $defaultListConfiguration = $gSettingsManager->getInt('lists_default_configuration'); + } + catch (\InvalidArgumentException $exception) + { + // if no default list was set than load another global list of this organization + $sql = 'SELECT MIN(lst_id) as lst_id + FROM '.TBL_LISTS.' + WHERE lst_org_id = ? -- $gCurrentOrganization->getValue(\'org_id\') + AND lst_global = 1 '; + $statement = $this->db->queryPrepared($sql, array($gCurrentOrganization->getValue('org_id'))); + $row = $statement->fetch(); + $defaultListConfiguration = $row['lst_id']; + } + + return $defaultListConfiguration; } } @@ -462,14 +478,14 @@ public function setValue($columnName, $newValue, $checkValue = true) if($columnName === 'rol_cat_id' && isset($gCurrentUser) && $gCurrentUser instanceof User) { $category = new TableCategory($this->db, $newValue); - + if(!$category->isVisible() || $category->getValue('cat_type') !== 'ROL') { throw new AdmException('Category of the role '. $this->getValue('dat_name'). ' could not be set because the category is not visible to the current user and current organization.'); } } - + if ($columnName === 'rol_default_registration' && $newValue == '0' && $this->dbColumns[$columnName] == '1') { // checks if at least one other role has this flag @@ -481,7 +497,7 @@ public function setValue($columnName, $newValue, $checkValue = true) AND rol_id <> ? -- $this->getValue(\'rol_id\') AND cat_org_id = ? -- $gCurrentOrganization->getValue(\'org_id\')'; $pdoStatement = $this->db->queryPrepared($sql, array((int) $this->getValue('rol_id'), (int) $gCurrentOrganization->getValue('org_id'))); - + if ((int) $pdoStatement->fetchColumn() === 0) { throw new AdmException('ROL_NO_DEFAULT_ROLE', array($gL10n->get('ROL_DEFAULT_REGISTRATION')));