Exemple #1
0
/**
 * Update Project and Test Plan data on Project change or startup
 * Data are stored in $_SESSION array
 * 
 * If we receive TestPlan ID in the _SESSION then do some checks and if everything OK
 * Update this value at Session Level, to set it available in other pieces of the application
 * 
 * @param integer $db DB connection identifier
 * @param array $hash_user_sel input data for the page ($_REQUEST)
 * 
 * @uses initMenu() 
 * @internal Revisions:
 * 	20091111 - havlatm - menu generation added, name changed (from upd_session_tplan_tproject)
 *	20090726 - franciscom - getAccessibleTestPlans() now is method on user class
 **/
function initProject(&$db, $hash_user_sel)
{
    $tproject = new testproject($db);
    $user_sel = array("tplan_id" => 0, "tproject_id" => 0);
    $user_sel["tproject_id"] = isset($hash_user_sel['testproject']) ? intval($hash_user_sel['testproject']) : 0;
    $user_sel["tplan_id"] = isset($hash_user_sel['testplan']) ? intval($hash_user_sel['testplan']) : 0;
    $tproject_id = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
    // test project is Test Plan container, then we start checking the container
    if ($user_sel["tproject_id"] != 0) {
        $tproject_id = $user_sel["tproject_id"];
    }
    // We need to do checks before updating the SESSION to cover the case that not defined but exists
    if (!$tproject_id) {
        $all_tprojects = $tproject->get_all();
        if ($all_tprojects) {
            $tproject_data = $all_tprojects[0];
            $tproject_id = $tproject_data['id'];
        }
    }
    $tproject->setSessionProject($tproject_id);
    // set a Test Plan
    // Refresh test project id after call to setSessionProject
    $tproject_id = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
    $tplan_id = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : null;
    // Now we need to validate the TestPlan
    // dolezalz, havlatm: added remember the last selection by cookie
    $cookieName = "TL_user{$_SESSION['userID']}_proj{$tproject_id}_testPlanId";
    if ($user_sel["tplan_id"] != 0) {
        $tplan_id = $user_sel["tplan_id"];
        setcookie($cookieName, $tplan_id, time() + 60 * 60 * 24 * 90, '/');
    } elseif (isset($_COOKIE[$cookieName])) {
        $tplan_id = intval($_COOKIE[$cookieName]);
    }
    // check if the specific combination of testprojectid and testplanid is valid
    $tplan_data = $_SESSION['currentUser']->getAccessibleTestPlans($db, $tproject_id, $tplan_id);
    if (is_null($tplan_data)) {
        // Need to get first accessible test plan for user, if any exists.
        $tplan_data = $_SESSION['currentUser']->getAccessibleTestPlans($db, $tproject_id);
    }
    if (!is_null($tplan_data)) {
        $tplan_data = $tplan_data[0];
        setSessionTestPlan($tplan_data);
    }
    // initialize structure of top menu for the user and the project
    initTopMenu($db);
}
Exemple #2
0
/**
 */
function initEnvironment(&$dbHandler, &$userObj)
{
    $argsObj = new stdClass();
    $guiObj = new stdClass();
    $cfg = config_get("gui");
    $tprojectMgr = new testproject($dbHandler);
    $_REQUEST = strings_stripSlashes($_REQUEST);
    $iParams = array("tprojectIDNavBar" => array(tlInputParameter::INT_N), "tproject_id" => array(tlInputParameter::INT_N), "tplan_id" => array(tlInputParameter::INT_N), "testplan" => array(tlInputParameter::INT_N), "updateMainPage" => array(tlInputParameter::INT_N), "runUpdateLogic" => array(tlInputParameter::INT_N));
    R_PARAMS($iParams, $argsObj);
    // @TODO in future refactor tlInput logic to allow pass default value
    $argsObj->updateMainPage = is_null($argsObj->updateMainPage) ? 0 : $argsObj->updateMainPage;
    $argsObj->runUpdateLogic = is_null($argsObj->runUpdateLogic) ? 1 : $argsObj->runUpdateLogic;
    $argsObj->updateMainPage = intval($argsObj->updateMainPage);
    $guiObj->tcasePrefix = '';
    $guiObj->tplanCount = 0;
    $guiObj->tprojectSet = $tprojectMgr->get_accessible_for_user($userObj->dbID);
    $guiObj->tprojectCount = sizeof($guiObj->tprojectSet);
    // -----------------------------------------------------------------------------------------------------
    // Important Logic
    // -----------------------------------------------------------------------------------------------------
    // only when the user has changed test project using the combo in NavBar.tpl this key is present
    // Use this clue to launch a refresh of other frames present on the screen
    // using the onload HTML body attribute
    $argsObj->tprojectIDNavBar = intval($argsObj->tprojectIDNavBar);
    $argsObj->tproject_id = intval($argsObj->tproject_id);
    $guiObj->updateMainPage = $argsObj->updateMainPage;
    if ($guiObj->updateMainPage == 0 && $argsObj->runUpdateLogic) {
        $guiObj->updateMainPage = $argsObj->tprojectIDNavBar > 0 ? 1 : 0;
        if ($argsObj->tprojectIDNavBar == 0 && $argsObj->tproject_id == 0) {
            // we have this situation when doing refresh on browser with something similar
            // http://localhost:8080/development/gitrepo/tlcode/index.php
            // on browser URL
            $guiObj->updateMainPage = 1;
        }
    }
    $argsObj->tproject_id = $argsObj->tproject_id > 0 ? $argsObj->tproject_id : $argsObj->tprojectIDNavBar;
    if ($argsObj->tproject_id == 0) {
        $argsObj->tproject_id = key($guiObj->tprojectSet);
    }
    $guiObj->tprojectID = $argsObj->tproject_id;
    $guiObj->tprojectOptions = null;
    $guiObj->tprojectTopMenu = null;
    if ($guiObj->tprojectID > 0) {
        $dummy = $tprojectMgr->get_by_id($guiObj->tprojectID);
        $guiObj->tprojectOptions = $dummy['opt'];
        if ($guiObj->updateMainPage) {
            setcookie('TL_lastTestProjectForUserID_' . $userObj->dbID, $guiObj->tprojectID, TL_COOKIE_KEEPTIME, '/');
        }
    }
    // -----------------------------------------------------------------------------------------------------
    $argsObj->tplan_id = intval($argsObj->tplan_id);
    $argsObj->tplan_id = $argsObj->tplan_id > 0 ? $argsObj->tplan_id : intval($argsObj->testplan);
    $guiObj->tplanID = $argsObj->tplan_id;
    // Julian: left magic here - do think this value will never be used as a project with a prefix
    //         has to be created after first login -> searchSize should be set dynamically.
    //         If any reviewer agrees on that feel free to change it.
    $guiObj->searchSize = 8;
    $reqMgmtEnabled = 0;
    if ($guiObj->tprojectID > 0) {
        $dummy = $tprojectMgr->get_by_id($guiObj->tprojectID);
        $reqMgmtEnabled = $dummy['opt']->requirementsEnabled;
        $guiObj->tcasePrefix = $dummy['prefix'] . config_get('testcase_cfg')->glue_character;
        $guiObj->searchSize = tlStringLen($guiObj->tcasePrefix) + $cfg->dynamic_quick_tcase_search_input_size;
        $guiObj->tplanSet = $userObj->getAccessibleTestPlans($dbHandler, $guiObj->tprojectID);
        $guiObj->tplanCount = sizeof($guiObj->tplanSet);
        if ($guiObj->tplanID == 0) {
            $guiObj->tplanID = $guiObj->tplanSet[0]['id'];
            $guiObj->tplanSet[0]['selected'] = 1;
        }
    }
    $guiObj->topMenu = initTopMenu($dbHandler, $userObj, $guiObj->tprojectID, $guiObj->tplanID, $reqMgmtEnabled);
    return array($argsObj, $guiObj);
}