/lib/general/navBar.php

https://github.com/viglesiasce/testlink · PHP · 136 lines · 85 code · 18 blank · 33 comment · 11 complexity · bbb4f27f99629ce19a3259821c4f707c MD5 · raw file

  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. *
  5. * Filename $RCSfile: navBar.php,v $
  6. *
  7. * @version $Revision: 1.53 $
  8. * @modified $Date: 2009/11/11 14:10:29 $ $Author: havlat $
  9. *
  10. * This file manages the navigation bar.
  11. *
  12. * rev :
  13. * 20090404 - franciscom - adjust size of test case input using len of tcase prefix
  14. * 20080504 - franciscom - add code based on contribution by Eugenia Drosdezki
  15. * get files present on docs directory, and pass to template.
  16. *
  17. * 20070505 - franciscom - use of role_separator configuration
  18. *
  19. **/
  20. require_once('../../config.inc.php');
  21. require_once("common.php");
  22. testlinkInitPage($db,true);
  23. $tproject_mgr = new testproject($db);
  24. $args = init_args();
  25. $gui = new stdClass();
  26. $gui->tprojectID = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
  27. $gui->tcasePrefix = '';
  28. $gui->searchSize = 8; // magic default
  29. if($gui->tprojectID > 0)
  30. {
  31. $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($gui->tprojectID) .
  32. config_get('testcase_cfg')->glue_character;
  33. $gui->searchSize = tlStringLen($gui->tcasePrefix) + 7; // magic again
  34. }
  35. $user = $_SESSION['currentUser'];
  36. $userID = $user->dbID;
  37. $gui->TestProjects = $tproject_mgr->get_accessible_for_user($userID,'map',$tlCfg->gui->tprojects_combo_order_by);
  38. $gui->TestProjectCount = sizeof($gui->TestProjects);
  39. $gui->TestPlanCount = 0;
  40. if ($gui->tprojectID)
  41. {
  42. $testPlanSet = $user->getAccessibleTestPlans($db,$gui->tprojectID);
  43. $gui->TestPlanCount = sizeof($testPlanSet);
  44. $tplanID = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : null;
  45. if( !is_null($tplanID) )
  46. {
  47. // Need to set this info on session with first Test Plan from $testPlanSet
  48. // if this test plan is present on $testPlanSet
  49. // OK we will set it on $testPlanSet as selected one.
  50. // else
  51. // need to set test plan on session
  52. //
  53. $index=0;
  54. $testPlanFound=0;
  55. $loop2do=count($testPlanSet);
  56. for($idx=0; $idx < $loop2do; $idx++)
  57. {
  58. if( $testPlanSet[$idx]['id'] == $tplanID )
  59. {
  60. $testPlanFound = 1;
  61. $index = $idx;
  62. $break;
  63. }
  64. }
  65. if( $testPlanFound == 0 )
  66. {
  67. $tplanID = $testPlanSet[0]['id'];
  68. setSessionTestPlan($testPlanSet[0]);
  69. }
  70. $testPlanSet[$index]['selected']=1;
  71. }
  72. }
  73. if ($gui->tprojectID && isset($user->tprojectRoles[$gui->tprojectID]))
  74. {
  75. // test project specific role applied
  76. $role = $user->tprojectRoles[$gui->tprojectID];
  77. $testprojectRole = $role->getDisplayName();
  78. }
  79. else
  80. {
  81. // general role applied
  82. $testprojectRole = $user->globalRole->getDisplayName();
  83. }
  84. $gui->whoami = $user->getDisplayName() . ' ' . $tlCfg->gui->role_separator_open .
  85. $testprojectRole . $tlCfg->gui->role_separator_close;
  86. // only when the user has changed project using the combo the _GET has this key.
  87. // Use this clue to launch a refresh of other frames present on the screen
  88. // using the onload HTML body attribute
  89. $gui->updateMainPage = 0;
  90. if ($args->testproject)
  91. {
  92. $gui->updateMainPage = 1;
  93. // set test project ID for the next session
  94. setcookie('TL_lastTestProjectForUserID_'. $userID, $args->testproject, TL_COOKIE_KEEPTIME, '/');
  95. }
  96. $gui->grants = getGrants($db);
  97. $smarty = new TLSmarty();
  98. $smarty->assign('gui',$gui);
  99. $smarty->display('navBar.tpl');
  100. /**
  101. * @todo havlatm: project rights should be get from $_SESSION
  102. */
  103. function getGrants(&$db)
  104. {
  105. $grants = new stdClass();
  106. $grants->view_testcase_spec = has_rights($db,"mgt_view_tc");
  107. return $grants;
  108. }
  109. function init_args()
  110. {
  111. $iParams = array(
  112. "testproject" => array(tlInputParameter::INT_N),
  113. );
  114. $args = new stdClass();
  115. $pParams = G_PARAMS($iParams,$args);
  116. return $args;
  117. }
  118. ?>