getDatabase() public static method

Returns the database layer to use.
public static getDatabase ( ) : Kimai_Database_Mysql
return Kimai_Database_Mysql
Example #1
0
File: func.php Project: jo91/kimai
/**
 * Check if a user is logged in or kick them.
 */
function checkUser()
{
    $database = Kimai_Registry::getDatabase();
    if (isset($_COOKIE['kimai_user']) && isset($_COOKIE['kimai_key']) && $_COOKIE['kimai_user'] != "0" && $_COOKIE['kimai_key'] != "0") {
        $kimai_user = addslashes($_COOKIE['kimai_user']);
        $kimai_key = addslashes($_COOKIE['kimai_key']);
        if ($database->get_seq($kimai_user) != $kimai_key) {
            Logger::logfile("Kicking user {$kimai_user} because of authentication key mismatch.");
            kickUser();
        } else {
            $user = $database->checkUserInternal($kimai_user);
            Kimai_Registry::setUser(new Kimai_User($user));
            return $user;
        }
    }
    Logger::logfile("Kicking user because of missing cookie.");
    kickUser();
}
Example #2
0
File: func.php Project: kimai/kimai
/**
 * Checks if the database structure needs to be updated for new Kimai version and redirects accordingly.
 *
 * @param string $path path to admin dir relative to the document that calls this function (usually "." or "..")
 * @global array $kga kimai-global-array
 * @return array
 * @author th
 */
function checkDBversion($path)
{
    $database = Kimai_Registry::getDatabase();
    $config = Kimai_Registry::getConfig();
    // check for versions before 0.7.13r96
    $installedVersion = $database->get_DBversion();
    $checkVersion = $installedVersion[0];
    if ($checkVersion == "0.5.1" && count($database->get_users()) == 0) {
        // fresh install
        header("Location: {$path}/installer/");
        exit;
    }
    // only call updater when database changes no matter the kimai version
    if ((int) $installedVersion[1] < $config->getRevision()) {
        header("Location: {$path}/updater/updater.php");
        exit;
    }
}