PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/requirements/reqSpecEdit.php

https://github.com/viglesiasce/testlink
PHP | 241 lines | 171 code | 29 blank | 41 comment | 5 complexity | 0e78f7ebcecf87f63a1a26b8c1b99c9f MD5 | raw file
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. *
  5. * @filesource $RCSfile: reqSpecEdit.php,v $
  6. * @version $Revision: 1.39 $
  7. * @modified $Date: 2010/08/10 14:10:12 $ $Author: asimon83 $
  8. *
  9. * @author Martin Havlat
  10. *
  11. * View existing and create a new req. specification.
  12. *
  13. * rev:
  14. * 20100810 - asimon - BUGID 3317: disabled total count of requirements by default
  15. * 20100808 - aismon - added logic to refresh filtered tree on action
  16. * 20091202 - franciscom - fixed bug on webeditor value init.
  17. * 20091119 - franciscom - doc_id
  18. * 20080830 - franciscom - added code to manage unlimited depth tree
  19. * (will be not enabled yet)
  20. *
  21. * 20080827 - franciscom - BUGID 1692
  22. *
  23. */
  24. require_once("../../config.inc.php");
  25. require_once("common.php");
  26. require_once('requirements.inc.php');
  27. require_once("web_editor.php");
  28. $editorCfg = getWebEditorCfg('requirement_spec');
  29. require_once(require_web_editor($editorCfg['type']));
  30. $req_cfg = config_get('req_cfg');
  31. testlinkInitPage($db,false,false,"checkRights");
  32. $templateCfg = templateConfiguration();
  33. $args = init_args();
  34. $commandMgr = new reqSpecCommands($db);
  35. $gui = initialize_gui($db,$commandMgr,$req_cfg);
  36. $auditContext = new stdClass();
  37. $auditContext->tproject = $args->tproject_name;
  38. $commandMgr->setAuditContext($auditContext);
  39. $pFn = $args->doAction;
  40. $op = null;
  41. if(method_exists($commandMgr,$pFn))
  42. {
  43. $op = $commandMgr->$pFn($args,$_REQUEST);
  44. }
  45. renderGui($args,$gui,$op,$templateCfg,$editorCfg);
  46. /**
  47. *
  48. *
  49. */
  50. function init_args()
  51. {
  52. $args = new stdClass();
  53. $iParams = array("countReq" => array(tlInputParameter::INT_N,99999),
  54. "req_spec_id" => array(tlInputParameter::INT_N),
  55. "reqParentID" => array(tlInputParameter::INT_N),
  56. "doAction" => array(tlInputParameter::STRING_N,0,250),
  57. "title" => array(tlInputParameter::STRING_N,0,100),
  58. "scope" => array(tlInputParameter::STRING_N),
  59. "doc_id" => array(tlInputParameter::STRING_N,1,32),
  60. "nodes_order" => array(tlInputParameter::ARRAY_INT),
  61. "containerID" => array(tlInputParameter::INT_N),
  62. "itemSet" => array(tlInputParameter::ARRAY_INT),
  63. "reqSpecType" => array(tlInputParameter::STRING_N,0,1),
  64. "copy_testcase_assignment" => array(tlInputParameter::CB_BOOL));
  65. $args = new stdClass();
  66. R_PARAMS($iParams,$args);
  67. $args->tproject_id = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
  68. $args->tproject_name = isset($_SESSION['testprojectName']) ? $_SESSION['testprojectName'] : "";
  69. $args->user_id = isset($_SESSION['userID']) ? $_SESSION['userID'] : 0;
  70. $args->basehref = $_SESSION['basehref'];
  71. $args->reqParentID = is_null($args->reqParentID) ? $args->tproject_id : $args->reqParentID;
  72. // asimon - 20100808 - added logic to refresh filtered tree on action
  73. $args->refreshTree = isset($_SESSION['setting_refresh_tree_on_action'])
  74. ? $_SESSION['setting_refresh_tree_on_action'] : 0;
  75. if (is_null($args->countReq)) {
  76. $args->countReq = 0;
  77. }
  78. return $args;
  79. }
  80. /**
  81. * renderGui
  82. *
  83. */
  84. function renderGui(&$argsObj,$guiObj,$opObj,$templateCfg,$editorCfg)
  85. {
  86. $smartyObj = new TLSmarty();
  87. $renderType = 'none';
  88. $tpl = $tpd = null;
  89. $actionOperation = array('create' => 'doCreate', 'edit' => 'doUpdate',
  90. 'doDelete' => '', 'doReorder' => '', 'reorder' => '',
  91. 'doCreate' => 'doCreate', 'doUpdate' => 'doUpdate',
  92. 'createChild' => 'doCreate', 'copy' => 'doCopy',
  93. 'doCopy' => 'doCopy',
  94. 'copyRequirements' => 'doCopyRequirements',
  95. 'doCopyRequirements' => 'doCopyRequirements');
  96. $owebEditor = web_editor('scope',$argsObj->basehref,$editorCfg) ;
  97. switch($argsObj->doAction)
  98. {
  99. case "edit":
  100. case "doCreate":
  101. $owebEditor->Value = $argsObj->scope;
  102. break;
  103. default:
  104. $owebEditor->Value = getItemTemplateContents('req_spec_template',$owebEditor->InstanceName, $argsObj->scope);
  105. break;
  106. }
  107. $guiObj->scope = $owebEditor->CreateHTML();
  108. $guiObj->editorType = $editorCfg['type'];
  109. // 20100808 - aismon - added logic to refresh filtered tree on action
  110. switch($argsObj->doAction)
  111. {
  112. case "doCreate":
  113. case "doUpdate":
  114. case "doCopyRequirements":
  115. case "doCopy":
  116. case "doDelete":
  117. $guiObj->refreshTree = $argsObj->refreshTree;
  118. break;
  119. }
  120. switch($argsObj->doAction)
  121. {
  122. case "edit":
  123. case "create":
  124. case "createChild":
  125. case "reorder":
  126. case "doDelete":
  127. case "doReorder":
  128. case "doCreate":
  129. case "doUpdate":
  130. case "copyRequirements":
  131. case "doCopyRequirements":
  132. case "copy":
  133. case "doCopy":
  134. $renderType = 'template';
  135. $key2loop = get_object_vars($opObj);
  136. foreach($key2loop as $key => $value)
  137. {
  138. $guiObj->$key = $value;
  139. }
  140. $guiObj->operation = $actionOperation[$argsObj->doAction];
  141. $tpl = is_null($opObj->template) ? $templateCfg->default_template : $opObj->template;
  142. $tpd = isset($key2loop['template_dir']) ? $opObj->template_dir : $templateCfg->template_dir;
  143. break;
  144. }
  145. switch($argsObj->doAction)
  146. {
  147. case "edit":
  148. case "create":
  149. case "createChild":
  150. case "reorder":
  151. case "doDelete":
  152. case "doReorder":
  153. case "copyRequirements":
  154. case "copy":
  155. $tpl = $tpd . $tpl;
  156. break;
  157. case "doCreate":
  158. case "doUpdate":
  159. case "doCopyRequirements":
  160. case "doCopy":
  161. $pos = strpos($tpl, '.php');
  162. if($pos === false)
  163. {
  164. $tpl = $templateCfg->template_dir . $tpl;
  165. }
  166. else
  167. {
  168. $renderType = 'redirect';
  169. }
  170. break;
  171. }
  172. switch($renderType)
  173. {
  174. case 'template':
  175. $smartyObj->assign('mgt_view_events',has_rights($db,"mgt_view_events"));
  176. $smartyObj->assign('gui',$guiObj);
  177. $smartyObj->display($tpl);
  178. break;
  179. case 'redirect':
  180. header("Location: {$tpl}");
  181. exit();
  182. break;
  183. default:
  184. break;
  185. }
  186. }
  187. /**
  188. *
  189. *
  190. */
  191. function initialize_gui(&$dbHandler, &$commandMgr, &$req_cfg)
  192. {
  193. $gui = $commandMgr->initGuiBean();
  194. $gui->user_feedback = null;
  195. $gui->main_descr = null;
  196. $gui->action_descr = null;
  197. $gui->refresh_tree = 'no';
  198. // 20100810 - asimon - BUGID 3317: disabled total count of requirements by default
  199. $gui->external_req_management = ($req_cfg->external_req_management == ENABLED) ? 1 : 0;
  200. $gui->grants = new stdClass();
  201. $gui->grants->req_mgmt = has_rights($dbHandler,"mgt_modify_req");
  202. return $gui;
  203. }
  204. /**
  205. *
  206. *
  207. */
  208. function checkRights(&$db,&$user)
  209. {
  210. return ($user->hasRight($db,'mgt_view_req') && $user->hasRight($db,'mgt_modify_req'));
  211. }
  212. ?>