<?php
// QaTraq - Test Management application
// Copyright (C) 2006 Traq Software Ltd
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// The Original Code is QaTraq code, released 20th June 2004.
//
// The Initial Developer of the Original Code is Traq Software Ltd.
// Portions created by Traq Software are Copyright (C) 2004-2006
// Traq Software Ltd. All Rights Reserved.
include('lib/session.inc');
include('lib/tmt.inc');
include('lib/uploads.inc');
requiresLogin ($_SERVER['REQUEST_URI']);
$id = $_GET['id'];
if (!$id) {
redirect("test_plans_copy_search.php");
}
else {
$id = (int)$id;
}
// BUGFIX: show_bug.cgi?id=130
// project_id Hardwired to '1' as project is always '1' now
//$project_id = $_GET['project_id'];
//if (!$project_id) {
// redirect("test_plans_copy_search.php");
//}
//else {
// $project_id = (int)$project_id;
//}
$project_id = 1;
$PAGE_TITLE = "Test Plans";
$PAGE_LOGO = "images/plan_logo.gif";
$AREA_TYPE = AREA_TYPE_TEST_PLANS;
$PAGE_TYPE = PAGE_TYPE_COPY;
$tmt = new TMT($_SESSION['USER_ID']);
if (stg_check())
{
include('lib/tmtpro.inc');
$tmt = new TMTPRO($_SESSION['USER_ID']);
}
if (!$tmt->check_right($AREA_TYPE, $PAGE_TYPE)) {
include('includes/no_rights.inc');
exit();
}
// get current user details
$user = $tmt->users->get($_SESSION['USER_ID']);
$page_action = $_POST['page_action'];
$page_action2 = $_POST['page_action2'];
$project = $tmt->test_projects->get_latest_version($project_id);
if (!$project) {
redirect("test_plans_copy_search.php");
}
// get test plan details
$test_plan = $tmt->test_plans->get($id);
$uploader = new attachements($tmt->userid, $tmt->shared_db, UPLOAD_PLAN_ID, $test_plan["TestPlanID"]);
if ($page_action == "save") {
$version_increment = $_POST['version_increment'];
$title = $_POST['title'];
$content = $_POST['content'];
$phases_id = $_POST['phases_id'];
if (!$phases_id) {
$phases_id = array();
}
switch ($version_increment) {
case 1:
$major_version = 1;
$minor_version = 0;
break;
case 2:
$major_version = 0;
$minor_version = 1;
break;
case 3:
$major_version = 1;
$minor_version = 1;
break;
}
// save
$tpn_id = $tmt->test_plans->add_test_plan($project_id, $title, $content, $major_version, $minor_version, $phases_id);
if (!$tpn_id) {
// error while save
$msg = "An error occured while saving this test case version. Please try again.";
}
else {
// save ok
$crt_plan = $tmt->test_plans->get($tpn_id);
$uploader->change_parent($crt_plan["TestPlanID"]);
$uploader->flush_mem_into_db(1);
// redirect
if ($page_action2 == "modify") {
redirect("test_plans_modify_content.php?id=$tpn_id&project_id=$project_id");
}
elseif ($page_action2 == "view") {
redirect("test_plans_view_content.php?id=$tpn_id");
}
elseif ($page_action2 == "copy") {
redirect("test_plans_copy_content.php?id=$tpn_id&project_id=$project_id");
}
}
}
else {
// initial page display
if (!$project_id) {
redirect("test_plans_copy_search.php");
}
else {
$project_id = (int)$project_id;
}
if (!$test_plan) {
include('includes/top.inc');
echo table_start("Record deleted", 660);
?>
<TABLE width="580" border="0" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD height="100" width="163" align="right" valign="middle" class="normal"> </TD>
<TD width="435" align="left" valign="middle" class="normal"> </TD>
</TR>
<TR>
<TD colspan="2" align="center" valign="middle" class="normal">
<font color="red"><b>Record does not exist. It might have been deleted recently !</b></font>
</TD>
</TR>
<TR>
<TD height="100" width="163" align="right" valign="middle" class="normal"> </TD>
<TD width="435" align="left" valign="middle" class="normal"> </TD>
</TR>
</TABLE>
<?php
echo table_end(660);
include('includes/bottom.inc');
exit();
}
$version_increment = 2; // increment minor
$title = "Copy of " . htmlspecialchars($test_plan["Title"]);
$content = htmlspecialchars($test_plan["Content"]);
$phases_id = $tmt->test_plans->get_phase_ids_for_test_plan_version($id);
}
switch ($version_increment) {
case 1:
$version = "v1.0";
break;
case 2:
$version = "v0.1";
break;
case 3:
$version = "v1.1";
break;
}
$latest_record = $tmt->test_plans->get_latest_version($test_plan["TestPlanID"]);
if (!$test_plan["LatestVersion"] && $_GET["latest"]) {
redirect("test_plans_copy_content.php?id=" . $latest_record["ID"]);
}
include('includes/top.inc');
?>
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD align="middle" valign="top" height="90">
<script language="javascript">
<!--
function handleChange() {
}
function handleSave() {
if (document.main.title.value == "") {
alert ("Please enter the Title !");
return;
}
if (document.main.content.value == "") {
alert ("Please enter the Content !");
return;
}
document.main.page_action.value = "save";
document.main.page_action2.value = "modify";
document.main.submit();
}
function handleSaveView() {
if (document.main.title.value == "") {
alert ("Please enter the Title !");
return;
}
if (document.main.content.value == "") {
alert ("Please enter the Content !");
return;
}
document.main.page_action.value = "save";
document.main.page_action2.value = "view";
document.main.submit();
}
function handleSaveModify() {
if (document.main.title.value == "") {
alert ("Please enter the Title !");
return;
}
if (document.main.content.value == "") {
alert ("Please enter the Content !");
return;
}
document.main.page_action.value = "save";
document.main.page_action2.value = "modify";
document.main.submit();
}
function handleSaveCopy() {
if (document.main.title.value == "") {
alert ("Please enter the Title !");
return;
}
if (document.main.content.value == "") {
alert ("Please enter the Content !");
return;
}
document.main.page_action.value = "save";
document.main.page_action2.value = "copy";
document.main.submit();
}
//-->
</script>
<FORM name="main" method="post" action="<?php echo $tmt->get_self()?>">
<input type="hidden" name="page_action" value="">
<input type="hidden" name="page_action2" value="">
<?php echo table_start("Copy Test Plan", 660);?>
<TABLE width="540" border="0" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
<?php if (!$test_plan["LatestVersion"]) {?>
<TR>
<TD colspan="3" class="normal"><B><font color="red">This is not the <a href="test_plans_copy_content.php?id=<?php echo $latest_record["ID"] ?>&latest=1">latest version</a> of this document.</font></B>
</TD>
</TR>
<TR>
<TD class="normal" colspan="3"> </TD>
</TR>
<?php }?>
<TR>
<TD colspan="3" class="normal"><B>Title</B></TD>
</TR>
<TR>
<TD colspan="3" class="normal">
<INPUT type="text" name="title" value="<?php echo $title?>" class="txtbox" size="85">
</TD>
</TR>
<TR>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
<TR>
<TD class="normal" width="165"><B>Version</B></TD>
<TD class="normal" width="165"><B>Type</B></TD>
<?php
// BUGFIX: show_bug.cgi?id=130
// project_id Hardwired to '1' as project is always '1' now
//<TD class="normal" width="216"><B>Project</B></TD>
?>
</TR>
<TR>
<TD class="normal" width="165"><?php echo $version?></TD>
<TD class="normal" width="165"><?php echo DOC_TYPE_TEST_PLAN?> </TD>
<?php
// BUGFIX: show_bug.cgi?id=130
// project_id Hardwired to '1' as project is always '1' now
//<TD class="normal" width="216"><?php echo $project["Title"]?*></TD>
?>
</TR>
<TR>
<TD class="normal" width="165" valign="bottom">
<INPUT type="radio" name="version_increment" value="1" onclick="javascript:handleChange();"<?php if ($version_increment==1) echo ' CHECKED';?>>Increment major<br>
<INPUT type="radio" name="version_increment" value="2" onclick="javascript:handleChange();"<?php if ($version_increment==2) echo ' CHECKED';?>>Increment minor<br>
<INPUT type="radio" name="version_increment" value="3" onclick="javascript:handleChange();"<?php if ($version_increment==3) echo ' CHECKED';?>>Increment both
</TD>
<TD class="normal" width="165" valign="bottom">
<B>Author</B><br>
<?php echo $user["UserName"]?>
</TD>
<?php if (method_exists($tmt, 'check_licence')) { ?>
<?php if ($lic = $tmt->check_licence()) { ?>
<TD class="normal" width="216" valign="bottom">
<B>Phases</B><br>
<SELECT name="phases_id[]" class="normal" size="4" multiple>
<?php
$phases = $tmt->test_phases->get_all_phases();
foreach($phases as $phase) {
?>
<option value="<?php echo $phase["TestPhaseID"]?>"<?php if (in_array($phase["TestPhaseID"], $phases_id)) {echo " SELECTED";}?>><?php echo $phase["Title"]?></option>
<?php
}
?>
</SELECT>
</TD>
<?php } ?>
<?php } else { ?>
<TD class="normal" width="216" valign="bottom"> </TD>
<?php } ?>
</TR>
<TR>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
<TR>
<TD class="normal" colspan="3"><?php
$uploader->draw_attachements(2);
?></TD>
</TR>
<TR><TD class="normal" colspan="4"> </TD></TR>
<TR>
<TD class="normal" width="165"><B>Content</B></TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
<TR>
<TD class="normal" colspan="3">
<TEXTAREA name="content" wrap="VIRTUAL" class="txtbox" cols="85" rows="8"><?php echo $content?></TEXTAREA>
</TD>
</TR>
<TR>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
<TR>
<TD colspan="3" align="middle" valign="middle" class="normal">
<INPUT type="button" class="button" name="save" value=" SAVE AND VIEW " onclick="javascript:handleSaveView();">
<INPUT type="button" class="button" name="save" value=" SAVE AND MODIFY " onclick="javascript:handleSaveModify();">
<INPUT type="button" class="button" name="save" value=" SAVE AND COPY " onclick="javascript:handleSaveCopy();">
</TD>
</TR>
<TR>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="165"> </TD>
<TD class="normal" width="216"> </TD>
</TR>
</TABLE>
<?php echo table_end(660);?>
</FORM>
</TD>
</TR>
</TABLE>
<?php
include('includes/bottom.inc');
?>