<?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');
requiresLogin ($_SERVER['REQUEST_URI']);
// BUGFIX: show_bug.cgi?id=232
$current_date = date('m/d/Y', time());
$product_id = $_GET['product_id'];
if (!$product_id) {
redirect("products_modify_search.php");
}
else {
$product_id = (int)$product_id;
}
$id = $_GET['id'];
if (!$id) {
redirect("versions_copy_search.php?product_id=$product_id");
}
else {
$id = (int)$id;
}
$PAGE_TITLE = "Versions";
$PAGE_LOGO = "images/versions_logo.gif";
$AREA_TYPE = AREA_TYPE_PRODUCT_VERSIONS;
$PAGE_TYPE = PAGE_TYPE_COPY;
$tmt = new TMT($_SESSION['USER_ID']);
if (!$tmt->check_right($AREA_TYPE, $PAGE_TYPE)) {
include('includes/no_rights.inc');
exit();
}
// get product details
$product = $tmt->products->get($product_id);
if (!$product) {
redirect("products_modify_search.php");
}
// get version details
$version = $tmt->products->get_version($product_id, $id);
if (!$version) {
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();
}
else {
$version_name = "Copy of " . htmlspecialchars($version['Version']);
$version_desc = htmlspecialchars($version['Description']);
// BUGFIX: show_bug.cgi?id=232
$version_date = $version['VersionDate'];
}
$page_action = $_POST['page_action'];
$page_action2 = $_POST['page_action2'];
if ($page_action == "save") {
$version_name = $_POST['version_name'];
$version_desc = $_POST['version_desc'];
// BUGFIX: show_bug.cgi?id=232
$version_date = $_POST['version_date'];
if ($tmt->products->verify_product_version_exists($product_id, $version_name)) {
// versio name already exists
$msg = "Version Name already exists. Please choose another.";
$version_name = htmlspecialchars(stripslashes($version_name));
$version_desc = htmlspecialchars(stripslashes($version_desc));
// BUGFIX: show_bug.cgi?id=232
$version_date = htmlspecialchars(stripslashes($version_date));
}
else {
// save
// BUGFIX: show_bug.cgi?id=232
//$version_id = $tmt->products->add_version($product_id, $version_name, $version_desc);
$ts = strtotime($version_date);
if ($ts === -1 || $ts === false) {
$version_date = "";
}
else {
$version_date = date("Y-m-d", $ts);
}
$version_id = $tmt->products->add_version($product_id, $version_name, $version_desc, $version_date);
if (!$version_id) {
// error while save
$msg = "An error occured while saving this product version. Please try again.";
}
else {
// save ok
// redirect
if ($page_action2 == "modify") {
redirect("versions_modify_content.php?product_id=$product_id&id=$version_id");
}
elseif ($page_action2 == "view") {
redirect("versions_view_content.php?product_id=$product_id&id=$version_id");
}
elseif ($page_action2 == "copy") {
redirect("versions_copy_content.php?product_id=$product_id&id=$version_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 findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function setTextOfTextfield(objName,x,newText) { //v3.0
var obj = findObj(objName); if (obj) obj.value = newText;
}
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
}
return this
}
function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
}
return true
}
function handleSave() {
if (document.main.version_name.value == "") {
alert ("Please enter the Version Name !");
return;
}
if (document.main.version_desc.value == "") {
alert ("Please enter the Version Description !");
return;
}
if (document.main.version_date) {
if (document.main.version_date.value != "") {
if (!isDate(document.main.version_date.value)) {
return;
}
} else {
alert ("Please enter the Version Date !");
return;
}
}
document.main.page_action.value = "save";
document.main.page_action2.value = "modify";
document.main.submit();
}
function handleSaveView() {
if (document.main.version_name.value == "") {
alert ("Please enter the Version Name !");
return;
}
if (document.main.version_desc.value == "") {
alert ("Please enter the Version Description !");
return;
}
if (document.main.version_date) {
if (document.main.version_date.value != "") {
if (!isDate(document.main.version_date.value)) {
return;
}
} else {
alert ("Please enter the Version Date !");
return;
}
}
document.main.page_action.value = "save";
document.main.page_action2.value = "view";
document.main.submit();
}
function handleSaveModify() {
if (document.main.version_name.value == "") {
alert ("Please enter the Version Name !");
return;
}
if (document.main.version_desc.value == "") {
alert ("Please enter the Version Description !");
return;
}
if (document.main.version_date) {
if (document.main.version_date.value != "") {
if (!isDate(document.main.version_date.value)) {
return;
}
} else {
alert ("Please enter the Version Date !");
return;
}
}
document.main.page_action.value = "save";
document.main.page_action2.value = "modify";
document.main.submit();
}
function handleSaveCopy() {
if (document.main.version_name.value == "") {
alert ("Please enter the Version Name !");
return;
}
if (document.main.version_desc.value == "") {
alert ("Please enter the Version Description !");
return;
}
if (document.main.version_date) {
if (document.main.version_date.value != "") {
if (!isDate(document.main.version_date.value)) {
return;
}
} else {
alert ("Please enter the Version Date !");
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 Product Version", 660);?>
<TABLE width="580" border="0" cellspacing="0" cellpadding="0" align="center">
<TR>
<TD width="163" align="right" valign="middle" class="normal"> </TD>
<TD width="435" align="left" valign="middle" class="normal"> </TD>
</TR>
<TR>
<TD width="163" align="right" class="normal" height="16" valign="top"><B> </B></TD>
<TD width="435" align="left" class="normal" height="16" valign="top"><font color="red"><?php echo $msg;?></font></TD>
</TR>
<TR>
<TD width="163" align="right" class="normal" height="16" valign="top"><B>Version Name : </B></TD>
<TD width="435" align="left" class="normal" height="16" valign="top"><INPUT type="text" name="version_name" value="<?php echo $version_name;?>" class="txtbox" size="30"></TD>
</TR>
<TR>
<TD width="163" align="right" class="normal" height="16" valign="top"><B>Version Description : </B></TD>
<TD width="435" align="left" class="normal" height="16" valign="top"><TEXTAREA name="version_desc" class="txtbox" rows="6" cols="40"><?php echo $version_desc;?></TEXTAREA></TD>
</TR>
<TR>
<TD width="163" align="right" class="normal" height="16" valign="top"><B>Version Date : </B></TD>
<TD width="435" align="left" class="normal" height="16" valign="top">
<INPUT type="button" value="T" title="Today" class="button" onClick="setTextOfTextfield('version_date','','<?php echo $current_date?>')" value=" T ">
<input type="text" name="version_date" value="<?php echo $version_date?>" class="normal" maxlength="10" size="10"><B> (mm/dd/yyyy)</B>
</TD>
</TR>
<TR>
<TD 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="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>
</TABLE>
<?php echo table_end(660);?>
</FORM>
</TD>
</TR>
</TABLE>
<?php
include('includes/bottom.inc');
?>