Location: PHPKode > projects > Druid Defect Control > defectcontrol_0.9.4/tts/usercheck.php
<?php  ob_start();

    if (!isset($PHP_AUTH_USER)) {
        header("Location: login.php");
        ob_end_flush();
        exit();
    }

    $ddts_username = $PHP_AUTH_USER;
    

include_once('database.php');

/*
 * OPTIMIZATION TODO: it is possible to do only one query to cache all the 
 *  user information per page load. 
 */

/*  
 *  Returns: username 
 */
function ttus_getLoginUserId($connection)
{

    global $ddts_username;

    $query = "SELECT iid FROM users WHERE sname = '$ddts_username'";
//    echo $query;    
    $res = ttdb_execQuery($connection, $query); 

    // user has been previously validated, so it should exist in the DB. 
    // Anyway check, you never know with low end DBMS... (...)
        
    $fields = ttdb_getArray($res);
    
    if (is_array($fields)) 
        return $fields['iid'];
    else
        return -1;   
        
        
}

$cachedUserData = "";

/*  
 *  Returns: userdata in $fields array style
 */
function ttus_getLoginUserInfo($connection)
{

    global $cachedUserData; 
    global $ddts_username;

    if ($cachedUserData != "") 
        return $cachedUserData;

    $query = "SELECT * FROM users WHERE sname = '$ddts_username'";
    $res = ttdb_execQuery($connection, $query); 
    
    $fields = ttdb_getArray($res);

    if (is_array($fields)) {
        $cachedUserData = $fields;
        return $cachedUserData;
    } else
        return -1;    
        
}

$cachedIsAdminValue = "";

/*  
 *  Returns: userdata in $fields array style
 */
function ttus_userIsAdmin($connection)
{
    
    global $cachedIsAdminValue;
    
    if ($cachedIsAdminValue != "") return $cachedIsAdminValue;
    
    $userInfo = ttus_getLoginUserInfo($connection);
    
    $cachedIsAdminValue = $userInfo['bisadmin'];
    
    return $cachedIsAdminValue;

}

?>
Return current item: Druid Defect Control