X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttUserHelper.class.php;h=17ef08c23a603e7ffe1a9936607f51d70db87fd2;hb=75a1eedb8977b8f2db459128bab9aaf367e3b58b;hp=26ced938acf251afc89741aa16687cf9a94f4adf;hpb=448c3e07930dbf902c97c93f252a474cb0931e23;p=timetracker.git diff --git a/WEB-INF/lib/ttUserHelper.class.php b/WEB-INF/lib/ttUserHelper.class.php index 26ced938..17ef08c2 100644 --- a/WEB-INF/lib/ttUserHelper.class.php +++ b/WEB-INF/lib/ttUserHelper.class.php @@ -386,4 +386,39 @@ class ttUserHelper { $sql = "update tt_users set accessed = now(), accessed_ip = $accessed_ip where id = $user->id"; $mdb2->exec($sql); } + + // canAdd determines if we can add a user in case there is a limit. + 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); + $val = $res->fetchRow(); + if (!$val) return true; // No limit. + + $max_count = $val['param_value']; + $sql = "select count(*) as user_count from tt_users where group_id > 0 and status is not null"; + $res = $mdb2->query($sql); + $val = $res->fetchRow(); + if ($val['user_count'] <= $max_count - $num_users) + return true; // Limit not reached. + + return false; + } + + // getUserRank - obtains a rank for a given user. + static function getUserRank($user_id) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select r.rank from tt_users u". + " left join tt_roles r on (u.role_id = r.id)". + " where u.id = $user_id and u.group_id = $group_id and u.org_id = $org_id"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) return 0; + $val = $res->fetchRow(); + return $val['rank']; + } }