/**
 *  Get actual system status
 *  No caching, just check the system status
 */
function apiActualLoadSystemStatus()
{
    global $sugar_flavor, $db;
    checkSystemLicenseStatus();
    if (!isset($_SESSION['LICENSE_EXPIRES_IN'])) {
        // BEGIN CE-OD License User Limit Enforcement
        if (isset($sugar_flavor) && ($sugar_flavor == 'CE' || !empty($admin->settings['license_enforce_user_limit']))) {
            $query = "SELECT count(id) as total from users WHERE " . User::getLicensedUsersWhere();
            $result = $db->query($query, true, "Error filling in user array: ");
            $row = $db->fetchByAssoc($result);
            $admin = Administration::getSettings();
            $license_users = $admin->settings['license_users'];
            $license_seats_needed = $row['total'] - $license_users;
            if ($license_seats_needed > 0) {
                $_SESSION['EXCEEDS_MAX_USERS'] = 1;
                return array('level' => 'admin_only', 'message' => 'WARN_LICENSE_SEATS_MAXED', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
            }
        }
        // END CE-OD License User Limit Enforcement
    }
    // Only allow administrators because of altered license issue
    if (!empty($_SESSION['HomeOnly'])) {
        return array('level' => 'admin_only', 'message' => 'FATAL_LICENSE_ALTERED', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
    }
    if (!ocLicense()) {
        if (!empty($_SESSION['INVALID_LICENSE'])) {
            return array('level' => 'admin_only', 'message' => 'ERROR_LICENSE_VALIDATION', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
        }
        if (isset($_SESSION['LICENSE_EXPIRES_IN']) && $_SESSION['LICENSE_EXPIRES_IN'] != 'valid') {
            if ($_SESSION['LICENSE_EXPIRES_IN'] < -1) {
                return array('level' => 'admin_only', 'message' => 'ERROR_LICENSE_EXPIRED', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
            } else {
                if (isset($GLOBALS['current_user']->id) && $GLOBALS['current_user']->isAdmin()) {
                    // Not yet expired, but soon enough to warn
                    return array('level' => 'warning', 'message' => 'WARN_LICENSE_EXPIRED', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
                }
            }
        } elseif (isset($_SESSION['VALIDATION_EXPIRES_IN']) && $_SESSION['VALIDATION_EXPIRES_IN'] != 'valid') {
            if ($_SESSION['VALIDATION_EXPIRES_IN'] < -1) {
                return array('level' => 'admin_only', 'message' => 'ERROR_LICENSE_VALIDATION', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
            } else {
                if (isset($GLOBALS['current_user']->id) && $GLOBALS['current_user']->isAdmin()) {
                    // Not yet expired, but soon enough to warn
                    return array('level' => 'warning', 'message' => 'WARN_LICENSE_VALIDATION', 'url' => '#bwc/index.php?action=LicenseSettings&module=Administration');
                }
            }
        }
    }
    if (!empty($_SESSION['EXCEEDING_OC_LICENSES'])) {
        return array('level' => 'admin_only', 'message' => 'ERROR_EXCEEDING_OC_LICENSES', 'url' => '#bwc/index.php?module=Administration&action=ListViewOfflineClient');
    }
    return true;
}
}
if (isset($_SESSION['rebuild_relationships'])) {
    displayAdminError(translate('MSG_REBUILD_RELATIONSHIPS', 'Administration'));
}
if (isset($_SESSION['rebuild_extensions'])) {
    displayAdminError(translate('MSG_REBUILD_EXTENSIONS', 'Administration'));
}
if (empty($license)) {
    $license = Administration::getSettings('license');
}
// This section of code is a portion of the code referred
// to as Critical Control Software under the End User
// License Agreement.  Neither the Company nor the Users
// may modify any portion of the Critical Control Software.
if (!isset($_SESSION['LICENSE_EXPIRES_IN'])) {
    checkSystemLicenseStatus();
}
if (!ocLicense() && isset($_SESSION['LICENSE_EXPIRES_IN']) && $_SESSION['LICENSE_EXPIRES_IN'] != 'valid') {
    if ($_SESSION['LICENSE_EXPIRES_IN'] < -1) {
        setSystemState('LICENSE_KEY');
    }
}
if (!ocLicense() && isset($_SESSION['VALIDATION_EXPIRES_IN']) && $_SESSION['VALIDATION_EXPIRES_IN'] != 'valid') {
    if ($_SESSION['VALIDATION_EXPIRES_IN'] < -1) {
        setSystemState('LICENSE_KEY');
    }
}
//END REQUIRED CODE DO NOT MODIFY
if (!empty($_SESSION['HomeOnly'])) {
    displayAdminError(translate('FATAL_LICENSE_ALTERED', 'Administration'));
}