<?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']);
$plan_id = $_GET['plan_id'];
if (!$plan_id) {
redirect("design_new_search.php");
}
else {
$plan_id = (int)$plan_id;
}
$PAGE_TITLE = "Test Design";
$PAGE_LOGO = "images/design_logo.gif";
$AREA_TYPE = AREA_TYPE_TEST_DESIGN;
$PAGE_TYPE = PAGE_TYPE_NEW;
$tmt = new TMT($_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']);
// get plan details
$plan = $tmt->test_plans->get_latest_version($plan_id);
if (!$plan) {
redirect("design_new_search.php");
}
$uploader = new Attachements($tmt->userid, $tmt->shared_db, UPLOAD_DESIGN_ID, -1, $PAGE_TYPE);
$page_action = $_POST['page_action'];
$page_action2 = $_POST['page_action2'];
if ($page_action == "save") {
$version_increment = $_POST['version_increment'];
$title = $_POST['title'];
$content = $_POST['content'];
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
$tdg_id = $tmt->test_designs->add_design($plan_id, $title, $content, $major_version, $minor_version);
if (!$tdg_id) {
// error while save
$msg = "An error occured while saving this test design version. Please try again.";
}
else {
// save ok
$crt_design = $tmt->test_designs->get($tdg_id);
$uploader->change_parent($crt_design["TestDesignID"]);
$uploader->flush_mem_into_db();
// redirect
if ($page_action2 == "modify") {
redirect("design_modify_content.php?id=$tdg_id&plan_id=" . $plan["TestPlanID"]);
}
elseif ($page_action2 == "view") {
redirect("design_view_content.php?id=$tdg_id");
}
elseif ($page_action2 == "copy") {
redirect("design_copy_content.php?id=$tdg_id&plan_id=" . $plan["TestPlanID"]);
}
}
}
elseif ($page_action == "change") {
$version_increment = $_POST['version_increment'];
$title = $_POST['title'];
$content = $_POST['content'];
$title = htmlspecialchars(stripslashes($title));
$content = htmlspecialchars(stripslashes($content));
}
else {
$version_increment = 2; // increment minor
$title = "";
$content = "";
}
switch ($version_increment) {
case 1:
$version = "v1.0";
break;
case 2:
$version = "v0.1";
break;
case 3:
$version = "v1.1";
break;
}
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() {
document.main.page_action.value = "change";
document.main.page_action2.value = "";
document.main.submit();
}
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("New Test Design", 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>
<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>
<TD class="normal" width="216"><B>Plan</B></TD>
</TR>
<TR>
<TD class="normal" width="165"><?php echo $version?></TD>
<TD class="normal" width="165"><?php echo DOC_TYPE_TEST_DESIGN?> </TD>
<TD class="normal" width="216"><?php echo $plan["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="middle">
<B>Author</B><br>
<?php echo $user["UserName"]?>
</TD>
<TD class="normal" width="216" valign="bottom"> </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" colspan="3"><?php
$uploader->draw_attachements(1);
?></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');
?>