Location: PHPKode > projects > QaTraq > qatraq/requ_new_content.php
<?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']);

$product_id = $_GET['product_id'];
if (!$product_id) {
	redirect("requ_new_search.php");
}
else {
	$product_id = (int)$product_id;
	$id = (int)$id;
}

$PAGE_TITLE = "Requ";
$PAGE_LOGO = "images/requ_logo.gif";
$AREA_TYPE = AREA_TYPE_REQUIREMENTS;
$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 product details
$product = $tmt->products->get($product_id);
if (!$product) {
	redirect("requ_new_search.php");
}

// get current user details
$user = $tmt->users->get($_SESSION['USER_ID']);

$uploader = new Attachements($tmt->userid, $tmt->shared_db, UPLOAD_REQUIREMENT_ID, -1, $PAGE_TYPE);

$page_action  = $_POST['page_action'];
$page_action2 = $_POST['page_action2'];

if ($page_action == "save") {
	$title   = $_POST['title'];
	$content = $_POST['content'];
	$url     = $_POST['url'];

	// save
	$req_id = $tmt->requirements->add_requirement($product_id, $title, $content, $url);

	if (!$req_id) {
		// error while save
		$msg = "An error occured while saving this requirement. Please try again.";
	}
	else {
		// save ok
		$uploader->change_parent($req_id);
        $uploader->flush_mem_into_db();

		// redirect
		if ($page_action2 == "modify") {
			redirect("requ_modify_content.php?id=$req_id");
		}
		elseif ($page_action2 == "view") {
			redirect("requ_view_content.php?id=$req_id");
		}
		elseif ($page_action2 == "copy") {
			redirect("requ_copy_content.php?id=$req_id");
		}
	}
}
elseif ($page_action == "change") {
	$title   = $_POST['title'];
	$content = $_POST['content'];
	$url     = $_POST['url'];

	$title   = htmlspecialchars(stripslashes($title));
	$content = htmlspecialchars(stripslashes($content));
}
else {
	$title   = "";
	$content = "";
	$url     = "";
}

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 Requirement", 660);?>

                <TABLE width="540" border="0" cellspacing="0" cellpadding="0" align="center">
                  <TR>
                    <TD class="normal" width="270">&nbsp;</TD>
                    <TD class="normal" width="270">&nbsp;</TD>
                  </TR>
                  <TR>
                    <TD colspan="2" class="normal"><B>Title</B></TD>
                  </TR>
                  <TR>
                    <TD colspan="2" class="normal">
                      <INPUT type="text" name="title" value="<?php echo $title?>" class="txtbox" size="85">
                    </TD>
                  </TR>
                  <TR>
                    <TD class="normal" width="270">&nbsp;</TD>
                    <TD class="normal" width="270">&nbsp;</TD>
                  </TR>
                  <TR>
                    <TD class="normal" width="270"><B>Type</B></TD>
                    <TD class="normal" width="270"><B>Author</B></TD>
                  </TR>
                  <TR>
                    <TD class="normal" width="270"><?php echo DOC_TYPE_REQUIREMENT?>&nbsp;</TD>
                    <TD class="normal" width="270">
						<?php echo $user["UserName"]?>
					</TD>
                  </TR>
                  <TR>
                    <TD class="normal" colspan="2">
                        <B>Product</B><BR />
						<?php 
							$product = $tmt->products->get($product_id);
							echo $product["Name"];
						?>
					</TD>
                  </TR>
                  <TR>
                    <TD class="normal" colspan="2">
                        <b>URL</b><br />
                        <INPUT type="text" name="url" value="<?php echo $url?>" class="txtbox" size="55">
                    </TD>
                  </TR>
                  <TR>
                    <TD class="normal" width="270">&nbsp;</TD>
                    <TD class="normal" width="270">&nbsp;</TD>
                  </TR>

                  <TR>
                    <TD class="normal" colspan="2"><?php 
                    $uploader->draw_attachements(1);
                    ?></TD>
                  </TR>

                  <TR>
                    <TD class="normal" colspan="2">&nbsp;</TD>
                  </TR>

                  <TR>
                    <TD class="normal" colspan="2"><B>Content</B></TD>
                  </TR>
                  <TR>
                    <TD class="normal" colspan="2">
                      <TEXTAREA name="content" wrap="VIRTUAL" class="txtbox" cols="85" rows="8"><?php echo $content?></TEXTAREA>
                    </TD>
                  </TR>
                  <TR>
                    <TD class="normal" colspan="2">&nbsp;</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();">&nbsp;&nbsp;
					<input type="button" class="button" name="save" value="  SAVE AND MODIFY " onclick="javascript:handleSaveModify();">&nbsp;&nbsp;
					<input type="button" class="button" name="save" value="  SAVE AND COPY " onclick="javascript:handleSaveCopy();">&nbsp;&nbsp;
				  </TD>
                </TR>
                  <TR>
                    <TD class="normal" colspan="2">&nbsp;</TD>
                  </TR>
                </TABLE>
		  <?php echo table_end(660);?>

      </FORM>
    </TD>
  </TR>
</TABLE>


<?php
include('includes/bottom.inc');
?>
Return current item: QaTraq