} else {
                        if (!empty($conf->multicompany->force_entity) && is_numeric($conf->multicompany->force_entity)) {
                            $conf->entity = $conf->multicompany->force_entity;
                        }
                    }
                }
            }
        }
    }
    // Sanitize entity
    if (!is_numeric($conf->entity)) {
        $conf->entity = 1;
    }
    //print "Will work with data into entity instance number '".$conf->entity."'";
    // Here we read database (llx_const table) and define $conf->global->XXX var.
    $conf->setValues($db);
}
// Overwrite database value
if (!empty($conf->file->mailing_limit_sendbyweb)) {
    $conf->global->MAILING_LIMIT_SENDBYWEB = $conf->file->mailing_limit_sendbyweb;
}
// If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
    $ok = 0;
    if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"])) {
        $ok = 1;
    } elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
        $ok = 1;
    } elseif (defined('NOREQUIREDB')) {
        $ok = 1;
    } elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {