PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/testcases/containerEdit.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 865 lines | 517 code | 122 blank | 226 comment | 42 complexity | b447992725102d908257464c7809ffd0 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. * @version $Revision: 1.117 $
  7. * @modified $Date: 2010/08/11 23:08:13 $ by $Author: asimon83 $
  8. * @author Martin Havlat
  9. *
  10. * @internal revisions
  11. * 20100811 - asimon - BUGID 3669
  12. * 20100722 - asimon - BUGID 3406, removal of changes for 3049
  13. * 20100628 - asimon - removal of constants from filter control class
  14. * 20100625 - asimon - refactoring for new filter features and BUGID 3516
  15. * 20100624 - asimon - CVS merge (experimental branch to HEAD)
  16. * 20100314 - franciscom - added logic to refresh tree when copying N test cases
  17. * added logic to get user choice regarding refresh tree from SESSION.
  18. * 20100223 - asimon - added removeTestcaseAssignments() for BUGID 3049
  19. * 20100204 - franciscom - changes in $tsuiteMgr->copy_to() call
  20. * 20100202 - franciscom - BUGID 3130: TestSuite: Edit - rename Test Suite Name causes PHP Fatal Error
  21. * (bug created due change in show() interface
  22. * 20091206 - franciscom - addTestSuite() - new test suites are order set to last on tree branch
  23. * 20081225 - franciscom - Postgres SQL Error
  24. * 20080827 - franciscom - BUGID 1692
  25. * 20080329 - franciscom - added contribution by Eugenia Drosdezki - Move/copy testcases
  26. * 20080223 - franciscom - BUGID 1408
  27. * 20080129 - franciscom - contribution - tuergeist@gmail.com - doTestSuiteReorder() remove global coupling
  28. * 20080122 - franciscom - BUGID 1312
  29. */
  30. require_once("../../config.inc.php");
  31. require_once("common.php");
  32. require_once("opt_transfer.php");
  33. require_once("web_editor.php");
  34. // BUGID 3406
  35. // require_once("specview.php"); //BUGID 3049
  36. $editorCfg=getWebEditorCfg('design');
  37. require_once(require_web_editor($editorCfg['type']));
  38. testlinkInitPage($db);
  39. $tree_mgr = new tree($db);
  40. $tproject_mgr = new testproject($db);
  41. // BUGID 3406
  42. // $tplan_mgr = new testplan($db);
  43. $tsuite_mgr = new testsuite($db);
  44. $tcase_mgr = new testcase($db);
  45. $template_dir = 'testcases/';
  46. $refreshTree = false;
  47. $level = null;
  48. // Option Transfer configuration
  49. $opt_cfg=new stdClass();
  50. $opt_cfg->js_ot_name = 'ot';
  51. $args = init_args($opt_cfg);
  52. $gui_cfg = config_get('gui');
  53. $smarty = new TLSmarty();
  54. $smarty->assign('editorType',$editorCfg['type']);
  55. $a_keys['testsuite'] = array('details');
  56. $a_tpl = array( 'move_testsuite_viewer' => 'containerMove.tpl',
  57. 'delete_testsuite' => 'containerDelete.tpl',
  58. 'del_testsuites_bulk' => 'containerDeleteBulk.tpl',
  59. 'updateTCorder' => 'containerView.tpl',
  60. 'move_testcases_viewer' => 'containerMoveTC.tpl',
  61. 'do_copy_tcase_set' => 'containerMoveTC.tpl');
  62. // BUGID 3406 - removed 'doUnassignFromPlan' => 0
  63. $a_actions = array ('edit_testsuite' => 0,'new_testsuite' => 0,'delete_testsuite' => 0,'do_move' => 0,
  64. 'do_copy' => 0,'reorder_testsuites' => 1,'do_testsuite_reorder' => 0,
  65. 'add_testsuite' => 1,'move_testsuite_viewer' => 0,'update_testsuite' => 1,
  66. 'move_testcases_viewer' => 0,'do_move_tcase_set' => 0,
  67. 'do_copy_tcase_set' => 0, 'del_testsuites_bulk' => 0);
  68. $a_init_opt_transfer=array('edit_testsuite' => 1,'new_testsuite' => 1,'add_testsuite' => 1,
  69. 'update_testsuite' => 1);
  70. $the_tpl = null;
  71. $action = null;
  72. foreach ($a_actions as $the_key => $the_val)
  73. {
  74. if (isset($_POST[$the_key]) )
  75. {
  76. $the_tpl = isset($a_tpl[$the_key]) ? $a_tpl[$the_key] : null;
  77. $init_opt_transfer = isset($a_init_opt_transfer[$the_key])?1:0;
  78. $action = $the_key;
  79. $get_c_data = $the_val;
  80. $level = 'testsuite';
  81. $warning_empty_name = lang_get('warning_empty_com_name');
  82. break;
  83. }
  84. }
  85. $smarty->assign('level', $level);
  86. $smarty->assign('page_title',lang_get('container_title_' . $level));
  87. if($init_opt_transfer)
  88. {
  89. $opt_cfg = initializeOptionTransfer($tproject_mgr,$tsuite_mgr,$args,$action);
  90. }
  91. // create web editor objects
  92. list($oWebEditor,$webEditorHtmlNames,$webEditorTemplateKey)=initWebEditors($a_keys,$level,$editorCfg);
  93. if($get_c_data)
  94. {
  95. $name_ok = 1;
  96. $c_data = getValuesFromPost($webEditorHtmlNames);
  97. if($name_ok && !check_string($c_data['container_name'],$g_ereg_forbidden))
  98. {
  99. $msg = lang_get('string_contains_bad_chars');
  100. $name_ok = 0;
  101. }
  102. if($name_ok && ($c_data['container_name'] == ""))
  103. {
  104. $msg = $warning_empty_name;
  105. $name_ok = 0;
  106. }
  107. }
  108. switch($action)
  109. {
  110. case 'edit_testsuite':
  111. case 'new_testsuite':
  112. keywords_opt_transf_cfg($opt_cfg, $args->assigned_keyword_list);
  113. $smarty->assign('opt_cfg', $opt_cfg);
  114. $tsuite_mgr->viewer_edit_new($smarty,$template_dir,$webEditorHtmlNames,$oWebEditor,$action,
  115. $args->containerID, $args->testsuiteID,null,$webEditorTemplateKey);
  116. break;
  117. case 'delete_testsuite':
  118. $refreshTree = deleteTestSuite($smarty,$args,$tsuite_mgr,$tree_mgr,$tcase_mgr,$level);
  119. break;
  120. case 'del_testsuites_bulk':
  121. $refreshTree = deleteTestSuitesBulk($smarty,$args,$tsuite_mgr,$tree_mgr,$tcase_mgr,$level);
  122. break;
  123. case 'move_testsuite_viewer':
  124. moveTestSuiteViewer($smarty,$tproject_mgr,$args);
  125. break;
  126. case 'move_testcases_viewer':
  127. moveTestCasesViewer($db,$smarty,$tproject_mgr,$tree_mgr,$args);
  128. break;
  129. case 'reorder_testsuites':
  130. $ret = reorderTestSuiteViewer($smarty,$tree_mgr,$args);
  131. $level = is_null($ret) ? $level : $ret;
  132. break;
  133. case 'do_move':
  134. moveTestSuite($smarty,$template_dir,$tproject_mgr,$args);
  135. break;
  136. case 'do_copy':
  137. copyTestSuite($smarty,$template_dir,$tsuite_mgr,$args);
  138. break;
  139. case 'update_testsuite':
  140. if ($name_ok)
  141. {
  142. $msg = updateTestSuite($tsuite_mgr,$args,$c_data,$_REQUEST);
  143. }
  144. $guiObj = new stdClass();
  145. $guiObj->attachments = getAttachmentInfosFrom($tsuite_mgr,$args->testsuiteID);
  146. $guiObj->id = $args->testsuiteID;
  147. $guiObj->page_title = lang_get('container_title_testsuite');
  148. $tsuite_mgr->show($smarty,$guiObj,$template_dir,$args->testsuiteID,null,$msg);
  149. break;
  150. case 'add_testsuite':
  151. $messages = null;
  152. $op['status'] = 0;
  153. if ($name_ok)
  154. {
  155. $op = addTestSuite($tsuite_mgr,$args,$c_data,$_REQUEST);
  156. $messages = array( 'result_msg' => $op['messages']['msg'],
  157. 'user_feedback' => $op['messages']['user_feedback']);
  158. }
  159. // $userInput is used to maintain data filled by user if there is
  160. // a problem with test suite name.
  161. $userInput = $op['status'] ? null : $_REQUEST;
  162. $assignedKeywords = $op['status'] ? "" : $args->assigned_keyword_list;
  163. keywords_opt_transf_cfg($opt_cfg, $assignedKeywords);
  164. $smarty->assign('opt_cfg', $opt_cfg);
  165. $tsuite_mgr->viewer_edit_new($smarty,$template_dir,$webEditorHtmlNames, $oWebEditor, $action,
  166. $args->containerID, null,$messages,
  167. $webEditorTemplateKey,$userInput);
  168. break;
  169. case 'do_move_tcase_set':
  170. moveTestCases($smarty,$template_dir,$tsuite_mgr,$tree_mgr,$args);
  171. break;
  172. case 'do_copy_tcase_set':
  173. $op = copyTestCases($smarty,$template_dir,$tsuite_mgr,$tcase_mgr,$args);
  174. $refreshTree = $op['refreshTree'];
  175. moveTestCasesViewer($db,$smarty,$tproject_mgr,$tree_mgr,$args,$op['userfeedback']);
  176. break;
  177. // BUGID 3406
  178. // // BUGID 3049
  179. // case 'doUnassignFromPlan':
  180. // removeTestcaseAssignments($db, $args, $tplan_mgr, $smarty, $template_dir);
  181. // break;
  182. default:
  183. trigger_error("containerEdit.php - No correct GET/POST data", E_USER_ERROR);
  184. break;
  185. }
  186. if($the_tpl)
  187. {
  188. $smarty->assign('refreshTree',$refreshTree && $args->refreshTree);
  189. $smarty->display($template_dir . $the_tpl);
  190. }
  191. function getValuesFromPost($akeys2get)
  192. {
  193. $akeys2get[] = 'container_name';
  194. $c_data = array();
  195. foreach($akeys2get as $key)
  196. {
  197. $c_data[$key] = isset($_POST[$key]) ? strings_stripSlashes($_POST[$key]) : null;
  198. }
  199. return $c_data;
  200. }
  201. /*
  202. function:
  203. args :
  204. returns:
  205. */
  206. function build_del_testsuite_warning_msg(&$tree_mgr,&$tcase_mgr,&$testcases,$tsuite_id)
  207. {
  208. $msg = null;
  209. $msg['warning'] = null;
  210. $msg['link_msg'] = null;
  211. $msg['delete_msg'] = null;
  212. if(!is_null($testcases))
  213. {
  214. $show_warning = 0;
  215. $delete_msg = '';
  216. $verbose = array();
  217. $msg['link_msg'] = array();
  218. $status_warning = array('linked_and_executed' => 1,
  219. 'linked_but_not_executed' => 1,
  220. 'no_links' => 0);
  221. $delete_notice = array('linked_and_executed' => lang_get('delete_notice'),
  222. 'linked_but_not_executed' => '',
  223. 'no_links' => '');
  224. foreach($testcases as $the_key => $elem)
  225. {
  226. $verbose[] = $tree_mgr->get_path($elem['id'],$tsuite_id);
  227. $status = $tcase_mgr->check_link_and_exec_status($elem['id']);
  228. $msg['link_msg'][] = $status;
  229. if($status_warning[$status])
  230. {
  231. $show_warning = 1;
  232. $msg['delete_msg'] = $delete_notice[$status];
  233. }
  234. }
  235. $idx = 0;
  236. if($show_warning)
  237. {
  238. $msg['warning'] = array();
  239. foreach($verbose as $the_key => $elem)
  240. {
  241. $msg['warning'][$idx] = '';
  242. $bSlash = false;
  243. foreach($elem as $tkey => $telem)
  244. {
  245. if ($bSlash)
  246. {
  247. $msg['warning'][$idx] .= "\\";
  248. }
  249. $msg['warning'][$idx] .= $telem['name'];
  250. $bSlash = true;
  251. }
  252. $idx++;
  253. }
  254. }
  255. else
  256. {
  257. $msg['link_msg'] = null;
  258. $msg['warning'] = null;
  259. }
  260. }
  261. return $msg;
  262. }
  263. /*
  264. function:
  265. args :
  266. returns:
  267. */
  268. function init_args($optionTransferCfg)
  269. {
  270. $args = new stdClass();
  271. $_REQUEST = strings_stripSlashes($_REQUEST);
  272. $args->tprojectID = $_SESSION['testprojectID'];
  273. $args->tprojectName = $_SESSION['testprojectName'];
  274. $args->userID = $_SESSION['userID'];
  275. $keys2loop=array('nodes_order' => null, 'tcaseSet' => null,
  276. 'target_position' => 'bottom', 'doAction' => '');
  277. foreach($keys2loop as $key => $value)
  278. {
  279. $args->$key = isset($_REQUEST[$key]) ? $_REQUEST[$key] : $value;
  280. }
  281. $args->tsuite_name = isset($_REQUEST['testsuiteName']) ? $_REQUEST['testsuiteName'] : null;
  282. $args->bSure = (isset($_REQUEST['sure']) && ($_REQUEST['sure'] == 'yes'));
  283. $rl_html_name = $optionTransferCfg->js_ot_name . "_newRight";
  284. $args->assigned_keyword_list = isset($_REQUEST[$rl_html_name])? $_REQUEST[$rl_html_name] : "";
  285. // integer values
  286. // BUGID 3406 - removed 'tplan_id' => 0
  287. $keys2loop=array('testsuiteID' => null, 'containerID' => null,
  288. 'objectID' => null, 'copyKeywords' => 0);
  289. foreach($keys2loop as $key => $value)
  290. {
  291. $args->$key = isset($_REQUEST[$key]) ? intval($_REQUEST[$key]) : $value;
  292. }
  293. if(is_null($args->containerID))
  294. {
  295. $args->containerID = $args->tprojectID;
  296. }
  297. // BUGID 3669
  298. $args->refreshTree = isset($_SESSION['setting_refresh_tree_on_action']) ?
  299. $_SESSION['setting_refresh_tree_on_action'] : 0;
  300. return $args;
  301. }
  302. /*
  303. function:
  304. args:
  305. returns:
  306. */
  307. function writeCustomFieldsToDB(&$db,$tprojectID,$tsuiteID,&$hash)
  308. {
  309. $ENABLED = 1;
  310. $NO_FILTERS = null;
  311. $cfield_mgr = new cfield_mgr($db);
  312. $cf_map = $cfield_mgr->get_linked_cfields_at_design($tprojectID,$ENABLED,
  313. $NO_FILTERS,'testsuite');
  314. $cfield_mgr->design_values_to_db($hash,$tsuiteID,$cf_map);
  315. }
  316. /*
  317. function: deleteTestSuite
  318. args:
  319. returns: true -> refresh tree
  320. false -> do not refresh
  321. */
  322. function deleteTestSuite(&$smartyObj,&$argsObj,&$tsuiteMgr,&$treeMgr,&$tcaseMgr,$level)
  323. {
  324. $feedback_msg = '';
  325. if($argsObj->bSure)
  326. {
  327. $tsuite = $tsuiteMgr->get_by_id($argsObj->objectID);
  328. $tsuiteMgr->delete_deep($argsObj->objectID);
  329. $tsuiteMgr->deleteKeywords($argsObj->objectID);
  330. $smartyObj->assign('objectName', $tsuite['name']);
  331. $doRefreshTree = true;
  332. $feedback_msg = 'ok';
  333. $smartyObj->assign('user_feedback',lang_get('testsuite_successfully_deleted'));
  334. }
  335. else
  336. {
  337. $doRefreshTree = false;
  338. // Get test cases present in this testsuite and all children
  339. $testcases = $tsuiteMgr->get_testcases_deep($argsObj->testsuiteID);
  340. $map_msg['warning'] = null;
  341. $map_msg['link_msg'] = null;
  342. $map_msg['delete_msg'] = null;
  343. if(!is_null($testcases))
  344. {
  345. $map_msg = build_del_testsuite_warning_msg($treeMgr,$tcaseMgr,$testcases,$argsObj->testsuiteID);
  346. }
  347. // prepare to show the delete confirmation page
  348. $smartyObj->assign('objectID',$argsObj->testsuiteID);
  349. $smartyObj->assign('objectName', $argsObj->tsuite_name);
  350. $smartyObj->assign('delete_msg',$map_msg['delete_msg']);
  351. $smartyObj->assign('warning', $map_msg['warning']);
  352. $smartyObj->assign('link_msg', $map_msg['link_msg']);
  353. }
  354. $smartyObj->assign('page_title', lang_get('delete') . " " . lang_get('container_title_' . $level));
  355. $smartyObj->assign('sqlResult',$feedback_msg);
  356. return $doRefreshTree;
  357. }
  358. /*
  359. function: addTestSuite
  360. args:
  361. returns: map with messages and status
  362. revision: 20091206 - franciscom - new items are created as last element of tree branch
  363. */
  364. function addTestSuite(&$tsuiteMgr,&$argsObj,$container,&$hash)
  365. {
  366. $new_order = null;
  367. // compute order
  368. $nt2exclude=array('testplan' => 'exclude_me','requirement_spec'=> 'exclude_me','requirement'=> 'exclude_me');
  369. $siblings = $tsuiteMgr->tree_manager->get_children($argsObj->containerID,$nt2exclude);
  370. if( !is_null($siblings) )
  371. {
  372. $dummy = end($siblings);
  373. $new_order = $dummy['node_order']+1;
  374. }
  375. $ret = $tsuiteMgr->create($argsObj->containerID,$container['container_name'],$container['details'],
  376. $new_order,config_get('check_names_for_duplicates'),config_get('action_on_duplicate_name'));
  377. $op['messages']= array('msg' => $ret['msg'], 'user_feedback' => '');
  378. $op['status']=$ret['status_ok'];
  379. if($ret['status_ok'])
  380. {
  381. $op['messages']['user_feedback'] = lang_get('testsuite_created');
  382. if($op['messages']['msg'] != 'ok')
  383. {
  384. $op['messages']['user_feedback'] = $op['messages']['msg'];
  385. }
  386. if(trim($argsObj->assigned_keyword_list) != "")
  387. {
  388. $tsuiteMgr->addKeywords($ret['id'],explode(",",$argsObj->assigned_keyword_list));
  389. }
  390. writeCustomFieldsToDB($tsuiteMgr->db,$argsObj->tprojectID,$ret['id'],$hash);
  391. }
  392. return $op;
  393. }
  394. /*
  395. function: moveTestSuiteViewer
  396. prepares smarty variables to display move testsuite viewer
  397. args:
  398. returns: -
  399. */
  400. function moveTestSuiteViewer(&$smartyObj,&$tprojectMgr,$argsObj)
  401. {
  402. $testsuites = $tprojectMgr->gen_combo_test_suites($argsObj->tprojectID,
  403. array($argsObj->testsuiteID => 'exclude'));
  404. // Added the Test Project as the FIRST Container where is possible to copy
  405. $testsuites = array($argsObj->tprojectID => $argsObj->tprojectName) + $testsuites;
  406. // original container (need to comment this better)
  407. $smartyObj->assign('old_containerID', $argsObj->tprojectID);
  408. $smartyObj->assign('containers', $testsuites);
  409. $smartyObj->assign('objectID', $argsObj->testsuiteID);
  410. $smartyObj->assign('object_name', $argsObj->tsuite_name);
  411. $smartyObj->assign('top_checked','checked=checked');
  412. $smartyObj->assign('bottom_checked','');
  413. }
  414. /*
  415. function: reorderTestSuiteViewer
  416. prepares smarty variables to display reorder testsuite viewer
  417. args:
  418. returns: -
  419. */
  420. function reorderTestSuiteViewer(&$smartyObj,&$treeMgr,$argsObj)
  421. {
  422. $level = null;
  423. $oid = is_null($argsObj->testsuiteID) ? $argsObj->containerID : $argsObj->testsuiteID;
  424. $children = $treeMgr->get_children($oid, array("testplan" => "exclude_me",
  425. "requirement_spec" => "exclude_me"));
  426. $object_info = $treeMgr->get_node_hierarchy_info($oid);
  427. $object_name = $object_info['name'];
  428. if (!sizeof($children))
  429. $children = null;
  430. $smartyObj->assign('arraySelect', $children);
  431. $smartyObj->assign('objectID', $oid);
  432. $smartyObj->assign('object_name', $object_name);
  433. if($oid == $argsObj->tprojectID)
  434. {
  435. $level = 'testproject';
  436. $smartyObj->assign('level', $level);
  437. $smartyObj->assign('page_title',lang_get('container_title_' . $level));
  438. }
  439. return $level;
  440. }
  441. /*
  442. function: doTestSuiteReorder
  443. args:
  444. returns: -
  445. rev:
  446. 20080602 - franciscom - fixed typo bug
  447. 20080223 - franciscom - fixed typo error - BUGID 1408
  448. removed wrong global coupling
  449. */
  450. // function doTestSuiteReorder(&$smartyObj,$template_dir,&$tprojectMgr,&$tsuiteMgr,$argsObj)
  451. // {
  452. // $nodes_in_order = transform_nodes_order($argsObj->nodes_order,$argsObj->containerID);
  453. // $tprojectMgr->tree_manager->change_order_bulk($nodes_in_order);
  454. // if($argsObj->containerID == $argsObj->tprojectID)
  455. // {
  456. // $objMgr = $tprojectMgr;
  457. // }
  458. // else
  459. // {
  460. // $objMgr = $tsuiteMgr;
  461. // }
  462. // $objMgr->show($smartyObj,$template_dir,$argsObj->containerID,,null,'ok');
  463. // }
  464. /*
  465. function: updateTestSuite
  466. args:
  467. returns:
  468. */
  469. function updateTestSuite(&$tsuiteMgr,&$argsObj,$container,&$hash)
  470. {
  471. $msg = 'ok';
  472. $ret = $tsuiteMgr->update($argsObj->testsuiteID,$container['container_name'],$container['details']);
  473. if($ret['status_ok'])
  474. {
  475. $tsuiteMgr->deleteKeywords($argsObj->testsuiteID);
  476. if(trim($argsObj->assigned_keyword_list) != "")
  477. {
  478. $tsuiteMgr->addKeywords($argsObj->testsuiteID,explode(",",$argsObj->assigned_keyword_list));
  479. }
  480. writeCustomFieldsToDB($tsuiteMgr->db,$argsObj->tprojectID,$argsObj->testsuiteID,$hash);
  481. }
  482. else
  483. {
  484. $msg = $ret['msg'];
  485. }
  486. return $msg;
  487. }
  488. /*
  489. function: copyTestSuite
  490. args:
  491. returns:
  492. */
  493. function copyTestSuite(&$smartyObj,$template_dir,&$tsuiteMgr,$argsObj)
  494. {
  495. $exclude_node_types=array('testplan' => 1, 'requirement' => 1, 'requirement_spec' => 1);
  496. $options = array();
  497. $options['check_duplicate_name'] = config_get('check_names_for_duplicates');
  498. $options['action_on_duplicate_name'] = config_get('action_on_duplicate_name');
  499. $options['copyKeywords'] = $argsObj->copyKeywords;
  500. $op=$tsuiteMgr->copy_to($argsObj->objectID, $argsObj->containerID, $argsObj->userID,$options);
  501. if( $op['status_ok'] )
  502. {
  503. $tsuiteMgr->tree_manager->change_child_order($argsObj->containerID,$op['id'],
  504. $argsObj->target_position,$exclude_node_types);
  505. }
  506. $guiObj = new stdClass();
  507. $guiObj->attachments = getAttachmentInfosFrom($tsuiteMgr,$argsObj->objectID);
  508. $guiObj->id = $argsObj->objectID;
  509. $tsuiteMgr->show($smartyObj,$guiObj,$template_dir,$argsObj->objectID,null,'ok');
  510. }
  511. /*
  512. function: moveTestSuite
  513. args:
  514. returns:
  515. */
  516. function moveTestSuite(&$smartyObj,$template_dir,&$tprojectMgr,$argsObj)
  517. {
  518. $exclude_node_types=array('testplan' => 1, 'requirement' => 1, 'requirement_spec' => 1);
  519. $tprojectMgr->tree_manager->change_parent($argsObj->objectID,$argsObj->containerID);
  520. $tprojectMgr->tree_manager->change_child_order($argsObj->containerID,$argsObj->objectID,
  521. $argsObj->target_position,$exclude_node_types);
  522. $guiObj = new stdClass();
  523. $guiObj->id = $argsObj->tprojectID;
  524. $tprojectMgr->show($smartyObj,$guiObj,$template_dir,$argsObj->tprojectID,null,'ok');
  525. }
  526. /*
  527. function: initializeOptionTransfer
  528. args:
  529. returns: option transfer configuration
  530. */
  531. function initializeOptionTransfer(&$tprojectMgr,&$tsuiteMgr,$argsObj,$doAction)
  532. {
  533. $opt_cfg = opt_transf_empty_cfg();
  534. $opt_cfg->js_ot_name='ot';
  535. $opt_cfg->global_lbl='';
  536. $opt_cfg->from->lbl=lang_get('available_kword');
  537. $opt_cfg->from->map = $tprojectMgr->get_keywords_map($argsObj->tprojectID);
  538. $opt_cfg->to->lbl=lang_get('assigned_kword');
  539. if($doAction=='edit_testsuite')
  540. {
  541. $opt_cfg->to->map=$tsuiteMgr->get_keywords_map($argsObj->testsuiteID," ORDER BY keyword ASC ");
  542. }
  543. return $opt_cfg;
  544. }
  545. /*
  546. function: moveTestCasesViewer
  547. prepares smarty variables to display move testcases viewer
  548. args:
  549. returns: -
  550. */
  551. function moveTestCasesViewer(&$dbHandler,&$smartyObj,&$tprojectMgr,&$treeMgr,$argsObj,$feedback='')
  552. {
  553. $tables = $tprojectMgr->getDBTables(array('nodes_hierarchy','node_types','tcversions'));
  554. $testcase_cfg = config_get('testcase_cfg');
  555. $glue = $testcase_cfg->glue_character;
  556. $containerID = isset($argsObj->testsuiteID) ? $argsObj->testsuiteID : $argsObj->objectID;
  557. $containerName = $argsObj->tsuite_name;
  558. if( is_null($containerName) )
  559. {
  560. $dummy = $treeMgr->get_node_hierarchy_info($argsObj->objectID);
  561. $containerName = $dummy['name'];
  562. }
  563. // 20081225 - franciscom have discovered that exclude selected testsuite branch is not good
  564. // when you want to move lots of testcases from one testsuite to it's children
  565. // testsuites. (in this situation tree drag & drop is not ergonomic).
  566. $testsuites = $tprojectMgr->gen_combo_test_suites($argsObj->tprojectID);
  567. $tcasePrefix = $tprojectMgr->getTestCasePrefix($argsObj->tprojectID) . $glue;
  568. // 20081225 - franciscom
  569. // While testing with PostGres have found this behaivour:
  570. // No matter is UPPER CASE has used on field aliases, keys on hash returned by
  571. // ADODB are lower case.
  572. // Accessing this keys on Smarty template using UPPER CASE fails.
  573. // Solution: have changed case on Smarty to lower case.
  574. //
  575. $sql = "SELECT NHA.id AS tcid, NHA.name AS tcname, NHA.node_order AS tcorder," .
  576. " MAX(TCV.version) AS tclastversion, TCV.tc_external_id AS tcexternalid" .
  577. " FROM {$tables['nodes_hierarchy']} NHA, {$tables['nodes_hierarchy']} NHB, " .
  578. " {$tables['node_types']} NT, {$tables['tcversions']} TCV " .
  579. " WHERE NHB.parent_id=NHA.id " .
  580. " AND TCV.id=NHB.id AND NHA.node_type_id = NT.id AND NT.description='testcase'" .
  581. " AND NHA.parent_id={$containerID} " .
  582. " GROUP BY NHA.id,NHA.name,NHA.node_order,TCV.tc_external_id " .
  583. " ORDER BY TCORDER,TCNAME";
  584. $children = $dbHandler->get_recordset($sql);
  585. // check if operation can be done
  586. $user_feedback = $feedback;
  587. if(!is_null($children) && (sizeof($children) > 0) && sizeof($testsuites))
  588. {
  589. $op_ok = true;
  590. }
  591. else
  592. {
  593. $children = null;
  594. $op_ok = false;
  595. $user_feedback = lang_get('no_testcases_available');
  596. }
  597. $smartyObj->assign('op_ok', $op_ok);
  598. $smartyObj->assign('user_feedback', $user_feedback);
  599. $smartyObj->assign('tcprefix', $tcasePrefix);
  600. $smartyObj->assign('testcases', $children);
  601. $smartyObj->assign('old_containerID', $argsObj->tprojectID); //<<<<-- check if is needed
  602. $smartyObj->assign('containers', $testsuites);
  603. $smartyObj->assign('objectID', $containerID);
  604. $smartyObj->assign('object_name', $containerName);
  605. $smartyObj->assign('top_checked','checked=checked');
  606. $smartyObj->assign('bottom_checked','');
  607. }
  608. /*
  609. function: copyTestCases
  610. copy a set of choosen test cases.
  611. args:
  612. returns: -
  613. */
  614. function copyTestCases(&$smartyObj,$template_dir,&$tsuiteMgr,&$tcaseMgr,$argsObj)
  615. {
  616. $op = array('refreshTree' => false, 'userfeedback' => '');
  617. if( ($qty=sizeof($argsObj->tcaseSet)) > 0)
  618. {
  619. $msg_id = $qty == 1 ? 'one_testcase_copied' : 'testcase_set_copied';
  620. $op['userfeedback'] = sprintf(lang_get($msg_id),$qty);
  621. $check_names_for_duplicates_cfg = config_get('check_names_for_duplicates');
  622. $action_on_duplicate_name_cfg = config_get('action_on_duplicate_name');
  623. foreach($argsObj->tcaseSet as $key => $tcaseid)
  624. {
  625. $copy_op = $tcaseMgr->copy_to($tcaseid, $argsObj->containerID, $argsObj->userID,
  626. $argsObj->copyKeywords,$check_names_for_duplicates_cfg,
  627. $action_on_duplicate_name_cfg);
  628. }
  629. $guiObj = new stdClass();
  630. $guiObj->attachments = getAttachmentInfosFrom($tsuiteMgr,$argsObj->objectID);
  631. $guiObj->id = $argsObj->objectID;
  632. $guiObj->refreshTree = true;
  633. // $tsuiteMgr->show($smartyObj,$guiObj,$template_dir,$argsObj->objectID);
  634. $op['refreshTree'] = true;
  635. }
  636. return $op;
  637. }
  638. /*
  639. function: moveTestCases
  640. move a set of choosen test cases.
  641. args:
  642. returns: -
  643. */
  644. function moveTestCases(&$smartyObj,$template_dir,&$tsuiteMgr,&$treeMgr,$argsObj)
  645. {
  646. if(sizeof($argsObj->tcaseSet) > 0)
  647. {
  648. $status_ok = $treeMgr->change_parent($argsObj->tcaseSet,$argsObj->containerID);
  649. $user_feedback= $status_ok ? '' : lang_get('move_testcases_failed');
  650. // objectID - original container
  651. $guiObj = new stdClass();
  652. $guiObj->attachments = getAttachmentInfosFrom($tsuiteMgr,$argsObj->objectID);
  653. $guiObj->id = $argsObj->objectID;
  654. // BUGID 3669
  655. $guiObj->refreshTree = true;
  656. $tsuiteMgr->show($smartyObj,$guiObj,$template_dir,$argsObj->objectID,null,$user_feedback);
  657. }
  658. }
  659. /**
  660. * initWebEditors
  661. *
  662. */
  663. function initWebEditors($webEditorKeys,$containerType,$editorCfg)
  664. {
  665. switch($containerType)
  666. {
  667. case 'testsuite':
  668. // $cfg=config_get('testsuite_template');
  669. $itemTemplateKey='testsuite_template';
  670. break;
  671. default:
  672. //$cfg=null;
  673. $itemTemplateKey=null;
  674. break;
  675. }
  676. $htmlNames = $webEditorKeys[$containerType];
  677. $oWebEditor = array();
  678. foreach ($htmlNames as $key)
  679. {
  680. $oWebEditor[$key] = web_editor($key,$_SESSION['basehref'],$editorCfg);
  681. }
  682. return array($oWebEditor,$htmlNames,$itemTemplateKey);
  683. }
  684. /*
  685. function: deleteTestSuitesBulk
  686. args:
  687. returns: true -> refresh tree
  688. false -> do not refresh
  689. */
  690. function deleteTestSuitesBulk(&$smartyObj,&$argsObj,&$tsuiteMgr,&$treeMgr,&$tcaseMgr,$level)
  691. {
  692. }
  693. ?>