From: Nik Okuntseff Date: Mon, 24 Dec 2018 16:02:43 +0000 (+0000) Subject: Fixed handling user limit for admin. X-Git-Tag: timetracker_1.19-1~377 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=87dff6fdf1e60ff60fb429290488cb1c9bf778d9;p=timetracker.git Fixed handling user limit for admin. --- diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index b33901b2..251cb3ea 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -31,6 +31,7 @@ class ttOrgImportHelper { var $errors = null; // Errors go here. Set in constructor by reference. var $schema_version = null; // Database schema version from XML file we import from. + var $num_users = 0; // A number of active and inactive users we are importing. var $conflicting_logins = null; // A comma-separated list of logins we cannot import. var $canImport = true; // False if we cannot import data due to a conflict such as login collision. var $firstPass = true; // True during first pass through the file. @@ -81,6 +82,7 @@ class ttOrgImportHelper { // In first pass we check user logins for potential collisions with existing. if ($name == 'USER' && $this->canImport) { $login = $attrs['LOGIN']; + if ('' != $attrs['STATUS']) $this->num_users++; if ('' != $attrs['STATUS'] && $this->loginExists($login)) { // We have a login collision. Append colliding login to a list of things we cannot import. $this->conflicting_logins .= ($this->conflicting_logins ? ", $login" : $login); @@ -569,6 +571,10 @@ class ttOrgImportHelper { $this->errors->add($i18n->get('error.user_exists')); $this->errors->add(sprintf($i18n->get('error.cannot_import'), $this->conflicting_logins)); } + if (!ttUserHelper::canAdd($this->num_users)) { + $this->canImport = false; + $this->errors->add($i18n->get('error.user_count')); + } $this->firstPass = false; // We are done with 1st pass. xml_parser_free($parser); diff --git a/WEB-INF/lib/ttUserHelper.class.php b/WEB-INF/lib/ttUserHelper.class.php index b3a5e360..538a2fc4 100644 --- a/WEB-INF/lib/ttUserHelper.class.php +++ b/WEB-INF/lib/ttUserHelper.class.php @@ -388,7 +388,7 @@ class ttUserHelper { } // canAdd determines if we can add a user in case there is a limit. - static function canAdd() { + static function canAdd($num_users = 1) { $mdb2 = getConnection(); $sql = "select param_value from tt_site_config where param_name = 'max_users'"; $res = $mdb2->query($sql); @@ -399,7 +399,7 @@ class ttUserHelper { $sql = "select count(*) as user_count from tt_users where status is not null"; $res = $mdb2->query($sql); $val = $res->fetchRow(); - if ($val['user_count'] < $max_count) + if ($val['user_count'] < $max_count - $num_users) // TODO: test this. return true; // Limit not reached. return false; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 6cac932b..f3396726 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.36.4688 | Copyright © Anuko | +  Anuko Time Tracker 1.18.36.4689 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/admin_group_add.php b/admin_group_add.php index 52b4134f..c42644f0 100644 --- a/admin_group_add.php +++ b/admin_group_add.php @@ -99,6 +99,8 @@ if ($request->isPost()) { $err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password')); if (!ttValidEmail($cl_manager_email, true)) $err->add($i18n->get('error.field'), $i18n->get('label.email')); + if (!ttUserHelper::canAdd()) + $err->add($i18n->get('error.user_count')); if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');