Innovator inn = this.getInnovator();
int LicenseNumber = 175;
int excessNo = 4;
// Get the logon enabled setting for this user and then
// count the currently available ones (minus this). If the total
// is greater than the number of licenses + 6 then we will not allow
// the save to occur.
string action = this.getAttribute("action", "add");
string currUser = this.getProperty("logon_enabled", "0");
// Go and count the number of logon_enabled users in the DB, there could be a 1 user variance here
string sql = "select count(*) as active_users from innovator.[user] where logon_enabled = 1 and login_name not in ('root','wipadmin','vadmin','pdftron_user', 'esadmin')";
Item sqlResponse = inn.applySQL(sql);
string countStr = sqlResponse.getProperty("active_users", "0");
int count = Int32.Parse(countStr);
// If we are trying to Add a user then we need to ensure we have not exceeded the license count
if (action == "add") {
// If the logon enabled is set, then trigger the error, otherwise allow the add
if (currUser == "1") {
if (count > LicenseNumber + excessNo) {
return inn.newError("Unable to add this user as it has exceeded the number of active users allowed. If you are able to disable an existing user (logon active unchecked) then you will be able to create this user.");
}
}
}
// If we are doing an update and the logon active has not changed, then allow the change to occur.
// If the login_enabled has changed from off to on, then we need to ensure the license check.
if (action == "update") {
Item existUser = inn.newItem("User", "get");
existUser.setAttribute("id", this.getID());
existUser.setAttribute("select", "id, logon_enabled");
existUser = existUser.apply();
string existLog = existUser.getProperty("logon_enabled", "");
// Do we have a logon change.
if (existLog != currUser) {
if (existLog == "0" && currUser == "1") {
if (count > LicenseNumber) {
return inn.newError("Unable to update this user as it will cause the number of active logons to exceed the license limit. To activate this user you need to deactivate one first.");
}
}
}
}
return this;