PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/testcases/tcEdit.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 737 lines | 511 code | 107 blank | 119 comment | 48 complexity | 01eca154ddaac482b676709e19aa73c2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. * This script is distributed under the GNU General Public License 2 or later.
  5. *
  6. * Test Case and Test Steps operations
  7. *
  8. * @package TestLink
  9. * @author TestLink community
  10. * @copyright 2007-2009, TestLink community
  11. * @version CVS: $Id: tcEdit.php,v 1.157 2010/08/31 14:19:26 asimon83 Exp $
  12. * @link http://www.teamst.org/index.php
  13. *
  14. *
  15. * @internal revisions
  16. * 20100831 - asimon - BUGID 3532
  17. * 20100828 - franciscom - BUGID 3156 tinymce problems - OK Internet Explorer 8, Firefox
  18. * 20100810 - asimon - BUGID 3579: solved tree refreshing problems
  19. * 20100628 - asimon - removal of constants from filter control class
  20. * 20100625 - asimon - refactoring of filter feature
  21. * 20100624 - asimon - CVS merge (experimental branch to HEAD)
  22. * 20100621 - eloff - BUGID 3241 - Implement vertical layout
  23. * 20100605 - franciscom - BUGID 3377
  24. * 20100403 - franciscom - BUGID 3359: Copy Test Case Step
  25. * 20100124 - franciscom - fixed bug on copy test cases - do not obey to top or bottom user choice
  26. * 20100106 - franciscom - Multiple Test Case Steps Feature
  27. * 20100104 - franciscom - fixed bug on create new version, now is created
  28. * from selected version and NOT FROM LATEST
  29. * 20100103 - franciscom - refactoring to use command class
  30. * 20090831 - franciscom - preconditions
  31. * 20090401 - franciscom - BUGID 2364 - edit while executing
  32. * 20090401 - franciscom - BUGID 2316
  33. * 20090325 - franciscom - BUGID - problems with add to testplan
  34. * 20090302 - franciscom - BUGID 2163 - Create test case with same title, after submit, all data lost
  35. * 20080827 - franciscom - BUGID 1692
  36. * 20080105 - franciscom - REQID 1248 - added logic to manage copy/move on top or bottom
  37. * 20071106 - BUGID 1165
  38. **/
  39. require_once("../../config.inc.php");
  40. require_once("common.php");
  41. require_once("opt_transfer.php");
  42. require_once("web_editor.php");
  43. $cfg = getCfg();
  44. testlinkInitPage($db);
  45. $optionTransferName = 'ot';
  46. $args = init_args($cfg->spec,$optionTransferName);
  47. // BUGID 3532
  48. if ($args->doAction == "editStep" || $args->doAction == "createStep" || $args->doAction == "doCreateStep") {
  49. $cfg->webEditorCfg=getWebEditorCfg('steps_design');
  50. }
  51. require_once(require_web_editor($cfg->webEditorCfg['type']));
  52. $tcase_mgr = new testcase($db);
  53. $tproject_mgr = new testproject($db);
  54. $tree_mgr = new tree($db);
  55. $tsuite_mgr = new testsuite($db);
  56. $templateCfg = templateConfiguration('tcEdit');
  57. $commandMgr = new testcaseCommands($db);
  58. $commandMgr->setTemplateCfg(templateConfiguration());
  59. $testCaseEditorKeys = array('summary' => 'summary','preconditions' => 'preconditions');
  60. $oWebEditor = createWebEditors($args->basehref,$cfg->webEditorCfg,$testCaseEditorKeys);
  61. $sqlResult = "";
  62. $init_inputs=true; // BUGID 2163 - Create test case with same title, after submit, all data lost
  63. $show_newTC_form = 0;
  64. $opt_cfg = initializeOptionTransferCfg($optionTransferName,$args,$tproject_mgr);
  65. $gui = initializeGui($db,$args,$cfg,$tcase_mgr);
  66. $smarty = new TLSmarty();
  67. $active_status = 0;
  68. $name_ok = 1;
  69. $action_result = "deactivate_this_version";
  70. if($args->do_activate_this)
  71. {
  72. $active_status = 1;
  73. $action_result = "activate_this_version";
  74. }
  75. $doRender = false;
  76. $pfn = $args->doAction;
  77. switch($args->doAction)
  78. {
  79. case "doUpdate":
  80. case "doAdd2testplan":
  81. $op = $commandMgr->$pfn($args,$_REQUEST);
  82. break;
  83. case "edit":
  84. case "create":
  85. case "doCreate":
  86. $oWebEditorKeys = array_keys($oWebEditor->cfg);
  87. $op = $commandMgr->$pfn($args,$opt_cfg,$oWebEditorKeys);
  88. $doRender = true;
  89. break;
  90. case "delete":
  91. case "doDelete":
  92. case "createStep":
  93. case "editStep":
  94. case "doCreateStep":
  95. case "doCopyStep":
  96. case "doUpdateStep":
  97. case "doDeleteStep":
  98. case "doReorderSteps":
  99. $op = $commandMgr->$pfn($args,$_REQUEST);
  100. $doRender = true;
  101. break;
  102. }
  103. if( $doRender )
  104. {
  105. renderGui($args,$gui,$op,$templateCfg,$cfg);
  106. exit();
  107. }
  108. if($args->delete_tc_version)
  109. {
  110. $status_quo_map = $tcase_mgr->get_versions_status_quo($args->tcase_id);
  111. $exec_status_quo = $tcase_mgr->get_exec_status($args->tcase_id);
  112. $msg = '';
  113. $sq = null;
  114. if(!is_null($exec_status_quo))
  115. {
  116. if(isset($exec_status_quo[$args->tcversion_id]))
  117. {
  118. $sq = array($args->tcversion_id => $exec_status_quo[$args->tcversion_id]);
  119. }
  120. }
  121. if(intval($status_quo_map[$args->tcversion_id]['executed']))
  122. {
  123. $msg = lang_get('warning') . TITLE_SEP . lang_get('delete_linked_and_exec');
  124. }
  125. else if(intval($status_quo_map[$args->tcversion_id]['linked']))
  126. {
  127. $msg = lang_get('warning') . TITLE_SEP . lang_get('delete_linked');
  128. }
  129. $tcinfo = $tcase_mgr->get_by_id($args->tcase_id,$args->tcversion_id);
  130. $gui->title = lang_get('title_del_tc') .
  131. TITLE_SEP_TYPE3 . lang_get('version') . " " . $tcinfo[0]['version'];
  132. $gui->testcase_name = $tcinfo[0]['name'];
  133. $gui->testcase_id = $args->tcase_id;
  134. $gui->tcversion_id = $args->tcversion_id;
  135. $gui->delete_message = $msg;
  136. $gui->exec_status_quo = $sq;
  137. $gui->refreshTree = 0;
  138. $smarty->assign('gui',$gui);
  139. $templateCfg = templateConfiguration('tcDelete');
  140. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  141. }
  142. else if($args->move_copy_tc)
  143. {
  144. // need to get the testproject for the test case
  145. $tproject_id = $tcase_mgr->get_testproject($args->tcase_id);
  146. $the_tc_node = $tree_mgr->get_node_hierarchy_info($args->tcase_id);
  147. $tc_parent_id = $the_tc_node['parent_id'];
  148. $the_xx = $tproject_mgr->gen_combo_test_suites($tproject_id);
  149. $the_xx[$the_tc_node['parent_id']] .= ' (' . lang_get('current') . ')';
  150. $tc_info = $tcase_mgr->get_by_id($args->tcase_id);
  151. $container_qty = count($the_xx);
  152. $gui->move_enabled = 1;
  153. if($container_qty == 1)
  154. {
  155. // move operation is nonsense
  156. $gui->move_enabled = 0;
  157. }
  158. $gui->top_checked = 'checked=checked';
  159. $gui->bottom_checked = '';
  160. $gui->old_container = $the_tc_node['parent_id']; // original container
  161. $gui->array_container = $the_xx;
  162. $gui->testcase_id = $args->tcase_id;
  163. $gui->name = $tc_info[0]['name'];
  164. $smarty->assign('gui', $gui);
  165. $templateCfg = templateConfiguration('tcMove');
  166. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  167. }
  168. else if($args->do_move)
  169. {
  170. $result = $tree_mgr->change_parent($args->tcase_id,$args->new_container_id);
  171. $tree_mgr->change_child_order($args->new_container_id,$args->tcase_id,
  172. $args->target_position,$cfg->exclude_node_types);
  173. $gui->refreshTree = $args->refreshTree;
  174. $tsuite_mgr->show($smarty,$gui,$templateCfg->template_dir,$args->old_container_id);
  175. }
  176. else if($args->do_copy)
  177. {
  178. $user_feedback='';
  179. $msg = '';
  180. $action_result = 'copied';
  181. $options = array('check_duplicate_name' => config_get('check_names_for_duplicates'),
  182. 'action_on_duplicate_name' => config_get('action_on_duplicate_name'),
  183. 'copy_also' => $args->copy);
  184. $result = $tcase_mgr->copy_to($args->tcase_id,$args->new_container_id,$args->user_id,$options);
  185. $msg = $result['msg'];
  186. if($result['status_ok'])
  187. {
  188. $tree_mgr->change_child_order($args->new_container_id,$result['id'],
  189. $args->target_position,$cfg->exclude_node_types);
  190. $ts_sep = config_get('testsuite_sep');
  191. $tc_info = $tcase_mgr->get_by_id($args->tcase_id);
  192. $container_info = $tree_mgr->get_node_hierarchy_info($args->new_container_id);
  193. $container_path = $tree_mgr->get_path($args->new_container_id);
  194. $path = '';
  195. foreach($container_path as $key => $value)
  196. {
  197. $path .= $value['name'] . $ts_sep;
  198. }
  199. $path = trim($path,$ts_sep);
  200. $user_feedback = sprintf(lang_get('tc_copied'),$tc_info[0]['name'],$path);
  201. }
  202. $gui->refreshTree = $args->refreshTree;
  203. $viewer_args['action'] = $action_result;
  204. $viewer_args['refreshTree']=$args->refreshTree? 1 : 0;
  205. $viewer_args['msg_result'] = $msg;
  206. $viewer_args['user_feedback'] = $user_feedback;
  207. $tcase_mgr->show($smarty,$gui,$templateCfg->template_dir,$args->tcase_id,
  208. $args->tcversion_id,$viewer_args,null, $args->show_mode);
  209. }
  210. else if($args->do_create_new_version)
  211. {
  212. $user_feedback = '';
  213. $show_newTC_form = 0;
  214. $action_result = "do_update";
  215. $msg = lang_get('error_tc_add');
  216. $op = $tcase_mgr->create_new_version($args->tcase_id,$args->user_id,$args->tcversion_id);
  217. if ($op['msg'] == "ok")
  218. {
  219. $user_feedback = sprintf(lang_get('tc_new_version'),$op['version']);
  220. $msg = 'ok';
  221. }
  222. $viewer_args['action'] = $action_result;
  223. $viewer_args['refreshTree'] = DONT_REFRESH;
  224. $viewer_args['msg_result'] = $msg;
  225. $viewer_args['user_feedback'] = $user_feedback;
  226. // used to implement go back ??
  227. // 20090419 - BUGID -
  228. $gui->loadOnCancelURL = $_SESSION['basehref'] .
  229. '/lib/testcases/archiveData.php?edit=testcase&id=' . $args->tcase_id .
  230. "&show_mode={$args->show_mode}";
  231. $testcase_version = !is_null($args->show_mode) ? $args->tcversion_id : testcase::ALL_VERSIONS;
  232. $tcase_mgr->show($smarty,$gui,$templateCfg->template_dir,$args->tcase_id,$testcase_version,
  233. $viewer_args,null, $args->show_mode);
  234. }
  235. else if($args->do_activate_this || $args->do_deactivate_this)
  236. {
  237. $gui->loadOnCancelURL = $_SESSION['basehref'] .
  238. '/lib/testcases/archiveData.php?edit=testcase&id=' . $args->tcase_id .
  239. "&show_mode={$args->show_mode}";
  240. $tcase_mgr->update_active_status($args->tcase_id, $args->tcversion_id, $active_status);
  241. $viewer_args['action'] = $action_result;
  242. $viewer_args['refreshTree']=DONT_REFRESH;
  243. $tcase_mgr->show($smarty,$gui,$templateCfg->template_dir,$args->tcase_id,
  244. testcase::ALL_VERSIONS,$viewer_args,null, $args->show_mode);
  245. }
  246. // --------------------------------------------------------------------------
  247. if ($show_newTC_form)
  248. {
  249. // BUGID 2163 - Create test case with same title, after submit, all data lost
  250. $tc_default=array('id' => 0, 'name' => '');
  251. $tc_default['importance'] = $init_inputs ? $tlCfg->testcase_importance_default : $args->importance;
  252. $tc_default['execution_type'] = $init_inputs ? TESTCASE_EXECUTION_TYPE_MANUAL : $args->exec_type;
  253. foreach ($oWebEditor->cfg as $key => $value)
  254. {
  255. $of = &$oWebEditor->editor[$key];
  256. $rows = $oWebEditor->cfg[$key]['rows'];
  257. $cols = $oWebEditor->cfg[$key]['cols'];
  258. if( $init_inputs)
  259. {
  260. $of->Value = getItemTemplateContents('testcase_template', $of->InstanceName, '');
  261. }
  262. else
  263. {
  264. $of->Value = $args->$key;
  265. }
  266. $smarty->assign($key, $of->CreateHTML($rows,$cols));
  267. } // foreach ($a_oWebEditor_cfg as $key)
  268. $filters=$tcase_mgr->buildCFLocationMap();
  269. foreach($filters as $locationKey => $locationFilter)
  270. {
  271. $cf_smarty[$locationKey] =
  272. $tcase_mgr->html_table_of_custom_field_inputs($args->tcase_id,$args->container_id,'design','',
  273. null,null,null,$locationFilter);
  274. }
  275. $gui->cf = $cf_smarty;
  276. $gui->tc = $tc_default;
  277. $gui->containerID = $args->container_id;
  278. $smarty->assign('gui',$gui);
  279. $templateCfg = templateConfiguration('tcNew');
  280. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  281. }
  282. /*
  283. function:
  284. args:
  285. returns:
  286. */
  287. function init_args($spec_cfg,$otName)
  288. {
  289. $tc_importance_default=config_get('testcase_importance_default');
  290. $args = new stdClass();
  291. $_REQUEST = strings_stripSlashes($_REQUEST);
  292. $rightlist_html_name = $otName . "_newRight";
  293. $args->assigned_keywords_list = isset($_REQUEST[$rightlist_html_name])? $_REQUEST[$rightlist_html_name] : "";
  294. $args->container_id = isset($_REQUEST['containerID']) ? intval($_REQUEST['containerID']) : 0;
  295. $args->tcase_id = isset($_REQUEST['testcase_id']) ? intval($_REQUEST['testcase_id']) : 0;
  296. $args->tcversion_id = isset($_REQUEST['tcversion_id']) ? intval($_REQUEST['tcversion_id']) : 0;
  297. $args->name = isset($_REQUEST['testcase_name']) ? $_REQUEST['testcase_name'] : null;
  298. // Normally Rich Web Editors
  299. $args->summary = isset($_REQUEST['summary']) ? $_REQUEST['summary'] : null;
  300. $args->preconditions = isset($_REQUEST['preconditions']) ? $_REQUEST['preconditions'] : null;
  301. $args->steps = isset($_REQUEST['steps']) ? $_REQUEST['steps'] : null;
  302. $args->expected_results = isset($_REQUEST['expected_results']) ? $_REQUEST['expected_results'] : null;
  303. $args->new_container_id = isset($_REQUEST['new_container']) ? intval($_REQUEST['new_container']) : 0;
  304. $args->old_container_id = isset($_REQUEST['old_container']) ? intval($_REQUEST['old_container']) : 0;
  305. $args->has_been_executed = isset($_REQUEST['has_been_executed']) ? intval($_REQUEST['has_been_executed']) : 0;
  306. $args->exec_type = isset($_REQUEST['exec_type']) ? $_REQUEST['exec_type'] : TESTCASE_EXECUTION_TYPE_MANUAL;
  307. $args->importance = isset($_REQUEST['importance']) ? $_REQUEST['importance'] : $tc_importance_default;
  308. $args->doAction = isset($_REQUEST['doAction']) ? $_REQUEST['doAction'] : '';
  309. $edit_tc = isset($_REQUEST['edit_tc']) ? 1 : 0;
  310. $delete_tc = isset($_REQUEST['delete_tc']) ? 1 : 0;
  311. $do_delete = isset($_REQUEST['do_delete']) ? 1 : 0;
  312. $create_tc = isset($_REQUEST['create_tc']) ? 1 : 0;
  313. $do_create = isset($_REQUEST['do_create']) ? 1 : 0;
  314. if( $edit_tc )
  315. {
  316. $args->doAction = 'edit';
  317. }
  318. if( $delete_tc )
  319. {
  320. $args->doAction = 'delete';
  321. }
  322. if( $do_delete )
  323. {
  324. $args->doAction = 'doDelete';
  325. }
  326. if( $create_tc )
  327. {
  328. $args->doAction = 'create';
  329. }
  330. if( $do_create )
  331. {
  332. $args->doAction = 'doCreate';
  333. }
  334. $args->move_copy_tc = isset($_REQUEST['move_copy_tc']) ? 1 : 0;
  335. $args->delete_tc_version = isset($_REQUEST['delete_tc_version']) ? 1 : 0;
  336. $args->do_move = isset($_REQUEST['do_move']) ? 1 : 0;
  337. $args->do_copy = isset($_REQUEST['do_copy']) ? 1 : 0;
  338. $args->do_create_new_version = isset($_REQUEST['do_create_new_version']) ? 1 : 0;
  339. $args->do_delete_tc_version = isset($_REQUEST['do_delete_tc_version']) ? 1 : 0;
  340. $args->do_activate_this = isset($_REQUEST['activate_this_tcversion']) ? 1 : 0;
  341. $args->do_deactivate_this = isset($_REQUEST['deactivate_this_tcversion']) ? 1 : 0;
  342. $args->target_position = isset($_REQUEST['target_position']) ? $_REQUEST['target_position'] : 'bottom';
  343. // BUGID 2316
  344. $key2loop=array("keyword_assignments","requirement_assignments");
  345. foreach($key2loop as $key)
  346. {
  347. $args->copy[$key]=isset($_REQUEST[$key])?true:false;
  348. }
  349. // 20090419 - franciscom - BUGID - edit while executing
  350. $args->show_mode = (isset($_REQUEST['show_mode']) && $_REQUEST['show_mode'] != '') ? $_REQUEST['show_mode'] : null;
  351. // Multiple Test Case Steps Feature
  352. $args->step_number = isset($_REQUEST['step_number']) ? intval($_REQUEST['step_number']) : 0;
  353. $args->step_id = isset($_REQUEST['step_id']) ? intval($_REQUEST['step_id']) : 0;
  354. $args->step_set = isset($_REQUEST['step_set']) ? $_REQUEST['step_set'] : null;
  355. $args->tcaseSteps = isset($_REQUEST['tcaseSteps']) ? $_REQUEST['tcaseSteps'] : null;
  356. // from session
  357. $args->testproject_id = $_SESSION['testprojectID'];
  358. $args->user_id = $_SESSION['userID'];
  359. // 3579
  360. $args->refreshTree = isset($_SESSION['setting_refresh_tree_on_action']) ?
  361. $_SESSION['setting_refresh_tree_on_action'] : 0;
  362. $args->opt_requirements = null;
  363. if( isset($_SESSION['testprojectOptions']) )
  364. {
  365. $args->opt_requirements = $_SESSION['testprojectOptions']->requirementsEnabled;
  366. }
  367. $args->basehref = $_SESSION['basehref'];
  368. $args->goback_url=isset($_REQUEST['goback_url']) ? $_REQUEST['goback_url'] : null;
  369. return $args;
  370. }
  371. /*
  372. function: initializeOptionTransferCfg
  373. args :
  374. returns:
  375. */
  376. function initializeOptionTransferCfg($otName,&$argsObj,&$tprojectMgr)
  377. {
  378. $otCfg = new stdClass();
  379. switch($argsObj->doAction)
  380. {
  381. case 'create':
  382. case 'edit':
  383. case 'doCreate':
  384. $otCfg = opt_transf_empty_cfg();
  385. $otCfg->global_lbl = '';
  386. $otCfg->from->lbl = lang_get('available_kword');
  387. $otCfg->from->map = $tprojectMgr->get_keywords_map($argsObj->testproject_id);
  388. $otCfg->to->lbl = lang_get('assigned_kword');
  389. break;
  390. }
  391. $otCfg->js_ot_name = $otName;
  392. return $otCfg;
  393. }
  394. /*
  395. function: createWebEditors
  396. When using tinymce or none as web editor, we need to set rows and cols
  397. to appropriate values, to avoid an ugly ui.
  398. null => use default values defined on editor class file
  399. Rows and Cols values are useless for FCKeditor
  400. args :
  401. returns: object
  402. rev: 20080902 - franciscom - manage column number as function of layout for tinymce
  403. */
  404. function createWebEditors($basehref,$editorCfg,$editorSet=null)
  405. {
  406. $specGUICfg=config_get('spec_cfg');
  407. $layout=$specGUICfg->steps_results_layout;
  408. // Rows and Cols configuration
  409. $owe = new stdClass();
  410. $cols = array('steps' => array('horizontal' => 38, 'vertical' => 44),
  411. 'expected_results' => array('horizontal' => 38, 'vertical' => 44));
  412. $owe->cfg = array('summary' => array('rows'=> null,'cols' => null),
  413. 'preconditions' => array('rows'=> null,'cols' => null) ,
  414. 'steps' => array('rows'=> null,'cols' => $cols['steps'][$layout]) ,
  415. 'expected_results' => array('rows'=> null, 'cols' => $cols['expected_results'][$layout]));
  416. $owe->editor = array();
  417. $force_create = is_null($editorSet);
  418. foreach ($owe->cfg as $key => $value)
  419. {
  420. if( $force_create || isset($editorSet[$key]) )
  421. {
  422. $owe->editor[$key] = web_editor($key,$basehref,$editorCfg);
  423. }
  424. else
  425. {
  426. unset($owe->cfg[$key]);
  427. }
  428. }
  429. return $owe;
  430. }
  431. /*
  432. function: getCfg
  433. args :
  434. returns: object
  435. */
  436. function getCfg()
  437. {
  438. $cfg=new stdClass();
  439. $cfg->treemenu_default_testcase_order = config_get('treemenu_default_testcase_order');
  440. $cfg->spec = config_get('spec_cfg');
  441. $cfg->exclude_node_types = array('testplan' => 1, 'requirement' => 1, 'requirement_spec' => 1);
  442. $cfg->tcase_template = config_get('testcase_template');
  443. $cfg->webEditorCfg=getWebEditorCfg('design');
  444. $cfg->editorKeys = new stdClass();
  445. $cfg->editorKeys->testcase = array('summary' => true, 'preconditions' => true);
  446. $cfg->editorKeys->step = array('steps' => true, 'expected_results' => true);
  447. return $cfg;
  448. }
  449. /*
  450. function: getGrants
  451. args :
  452. returns: object
  453. */
  454. function getGrants(&$dbHandler)
  455. {
  456. $grants=new stdClass();
  457. $grants->requirement_mgmt=has_rights($dbHandler,"mgt_modify_req");
  458. return $grants;
  459. }
  460. /**
  461. *
  462. *
  463. */
  464. function initializeGui(&$dbHandler,&$argsObj,$cfgObj,&$tcaseMgr)
  465. {
  466. $guiObj = new stdClass();
  467. $guiObj->editorType = $cfgObj->webEditorCfg['type'];
  468. $guiObj->grants = getGrants($dbHandler);
  469. $guiObj->opt_requirements = $argsObj->opt_requirements;
  470. $guiObj->action_on_duplicated_name = 'generate_new';
  471. $guiObj->show_mode = $argsObj->show_mode;
  472. $guiObj->has_been_executed = $argsObj->has_been_executed;
  473. $guiObj->attachments = null;
  474. $guiObj->parent_info = null;
  475. $guiObj->user_feedback = '';
  476. $guiObj->steps_results_layout = config_get('spec_cfg')->steps_results_layout;
  477. $guiObj->loadOnCancelURL = $_SESSION['basehref'] .
  478. "/lib/testcases/archiveData.php?edit=testcase&id=" . $argsObj->tcase_id .
  479. "&show_mode={$argsObj->show_mode}";
  480. if($argsObj->container_id > 0)
  481. {
  482. $pnode_info = $tcaseMgr->tree_manager->get_node_hierarchy_info($argsObj->container_id);
  483. $node_descr = array_flip($tcaseMgr->tree_manager->get_available_node_types());
  484. $guiObj->parent_info['name'] = $pnode_info['name'];
  485. $guiObj->parent_info['description'] = lang_get($node_descr[$pnode_info['node_type_id']]);
  486. }
  487. $guiObj->direct_link = $tcaseMgr->buildDirectWebLink($_SESSION['basehref'],$argsObj->tcase_id,$argsObj->testproject_id);
  488. return $guiObj;
  489. }
  490. /**
  491. * manage GUI rendering
  492. *
  493. * BUGID 3359
  494. */
  495. function renderGui(&$argsObj,$guiObj,$opObj,$templateCfg,$cfgObj)
  496. {
  497. $smartyObj = new TLSmarty();
  498. // BUGID 3156
  499. // need by webeditor loading logic present on inc_head.tpl
  500. $smartyObj->assign('editorType',$guiObj->editorType);
  501. $renderType = 'none';
  502. //
  503. // key: operation requested (normally received from GUI on doAction)
  504. // value: operation value to set on doAction HTML INPUT
  505. // This is useful when you use same template (example xxEdit.tpl), for create and edit.
  506. // When template is used for create -> operation: doCreate.
  507. // When template is used for edit -> operation: doUpdate.
  508. //
  509. // used to set value of: $guiObj->operation
  510. //
  511. $actionOperation = array('create' => 'doCreate', 'doCreate' => 'doCreate',
  512. 'edit' => 'doUpdate','delete' => 'doDelete', 'doDelete' => '',
  513. 'createStep' => 'doCreateStep', 'doCreateStep' => 'doCreateStep',
  514. 'doCopyStep' => 'doUpdateStep',
  515. 'editStep' => 'doUpdateStep', 'doUpdateStep' => 'doUpdateStep',
  516. 'doDeleteStep' => '', 'doReorderSteps' => '');
  517. $key2work = 'initWebEditorFromTemplate';
  518. $initWebEditorFromTemplate = property_exists($opObj,$key2work) ? $opObj->$key2work : false;
  519. $key2work = 'cleanUpWebEditor';
  520. $cleanUpWebEditor = property_exists($opObj,$key2work) ? $opObj->$key2work : false;
  521. $oWebEditor = createWebEditors($argsObj->basehref,$cfgObj->webEditorCfg);
  522. foreach ($oWebEditor->cfg as $key => $value)
  523. {
  524. $of = &$oWebEditor->editor[$key];
  525. $rows = $oWebEditor->cfg[$key]['rows'];
  526. $cols = $oWebEditor->cfg[$key]['cols'];
  527. switch($argsObj->doAction)
  528. {
  529. case "edit":
  530. case "delete":
  531. case "editStep":
  532. $initWebEditorFromTemplate = false;
  533. $of->Value = $argsObj->$key;
  534. break;
  535. case "doCreate":
  536. case "doDelete":
  537. case "doCopyStep":
  538. case "doUpdateStep":
  539. $initWebEditorFromTemplate = false;
  540. $of->Value = $argsObj->$key;
  541. break;
  542. case "create":
  543. case "doCreateStep":
  544. default:
  545. $initWebEditorFromTemplate = true;
  546. break;
  547. }
  548. $guiObj->operation = $actionOperation[$argsObj->doAction];
  549. if( $initWebEditorFromTemplate )
  550. {
  551. $of->Value = getItemTemplateContents('testcase_template', $of->InstanceName, '');
  552. }
  553. else if( $cleanUpWebEditor )
  554. {
  555. $of->Value = '';
  556. }
  557. $smartyObj->assign($key, $of->CreateHTML($rows,$cols));
  558. }
  559. // manage tree refresh
  560. // 3579
  561. switch($argsObj->doAction) {
  562. case "doDelete":
  563. $guiObj->refreshTree = $argsObj->refreshTree;
  564. break;
  565. }
  566. switch($argsObj->doAction)
  567. {
  568. case "edit":
  569. case "create":
  570. case "delete":
  571. case "createStep":
  572. case "editStep":
  573. case "doCreate":
  574. case "doDelete":
  575. case "doCreateStep":
  576. case "doUpdateStep":
  577. case "doDeleteStep":
  578. case "doReorderSteps":
  579. case "doCopyStep":
  580. $renderType = 'template';
  581. // Document !!!!
  582. $key2loop = get_object_vars($opObj);
  583. foreach($key2loop as $key => $value)
  584. {
  585. $guiObj->$key = $value;
  586. // if( isset($guiObj->webEditor[$key]) )
  587. // {
  588. // $guiObj->webEditor[$key] = $value;
  589. // }
  590. // else
  591. // {
  592. // $guiObj->$key = $value;
  593. // }
  594. }
  595. $guiObj->operation = $actionOperation[$argsObj->doAction];
  596. $tplDir = (!isset($opObj->template_dir) || is_null($opObj->template_dir)) ? $templateCfg->template_dir : $opObj->template_dir;
  597. $tpl = is_null($opObj->template) ? $templateCfg->default_template : $opObj->template;
  598. $pos = strpos($tpl, '.php');
  599. if($pos === false)
  600. {
  601. $tpl = $tplDir . $tpl;
  602. }
  603. else
  604. {
  605. $renderType = 'redirect';
  606. }
  607. break;
  608. }
  609. switch($renderType)
  610. {
  611. case 'template':
  612. $smartyObj->assign('gui',$guiObj);
  613. $smartyObj->display($tpl);
  614. break;
  615. case 'redirect':
  616. header("Location: {$tpl}");
  617. exit();
  618. break;
  619. default:
  620. break;
  621. }
  622. }
  623. ?>