diff --git a/admin/post/users.php b/admin/post/users.php index 270809bee..ce518bb8c 100644 --- a/admin/post/users.php +++ b/admin/post/users.php @@ -10,6 +10,11 @@ if (isset($_POST['add_user'])) { validateCSRFToken(); + if (agentUserLimitReached()) { + flashAlert(agentUserLimitMessage(), 'error'); + redirect(); + } + require_once 'user_model.php'; $password = password_hash(trim($_POST['password']), PASSWORD_DEFAULT); @@ -113,6 +118,7 @@ if (isset($_POST['edit_user'])) { require_once 'user_model.php'; $user_id = intval($_POST['user_id']); + $new_password = trim($_POST['new_password']); // Update Client Access (allow / deny per client) @@ -194,6 +200,13 @@ if (isset($_GET['activate_user'])) { $user_id = intval($_GET['activate_user']); + // Only a user who isn't already using a seat can push the count over the limit + $seat_row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(user_id) FROM users WHERE user_id = $user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL")); + if (intval($seat_row[0]) === 0 && agentUserLimitReached()) { + flashAlert(agentUserLimitMessage(), 'error'); + redirect(); + } + $user_name = escapeSql(getFieldById('users', $user_id, 'user_name')); mysqli_query($mysqli, "UPDATE users SET user_status = 1 WHERE user_id = $user_id"); @@ -303,6 +316,13 @@ if (isset($_POST['restore_user'])) { validateCSRFToken(); $user_id = intval($_POST['user_id']); + + // Only a user who isn't already using a seat can push the count over the limit + $seat_row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(user_id) FROM users WHERE user_id = $user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL")); + if (intval($seat_row[0]) === 0 && agentUserLimitReached()) { + flashAlert(agentUserLimitMessage(), 'error'); + redirect(); + } $new_password = trim($_POST['new_password']); $role = intval($_POST['role']); diff --git a/admin/users.php b/admin/users.php index 80efedbd8..75679a97d 100644 --- a/admin/users.php +++ b/admin/users.php @@ -20,16 +20,33 @@ $sql = mysqli_query( $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +// Agent user limit (set in config.php, 0 / unset = unlimited) +$agent_user_limit = getAgentUserLimit(); +$agent_user_count = getActiveAgentUserCount(); +$agent_user_limit_reached = $agent_user_limit > 0 && $agent_user_count >= $agent_user_limit; + ?>