Location: PHPKode > projects > QaTraq > qatraq/results_modify_search.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');

requiresLogin ($_SERVER['REQUEST_URI']); 

$PAGE_TITLE = "Results";
$PAGE_LOGO = "images/result_logo.gif";
$AREA_TYPE = AREA_TYPE_TEST_RESULTS;
$PAGE_TYPE = PAGE_TYPE_MODIFY;

$tmt = new TMT($_SESSION['USER_ID']);

if (!$tmt->check_right($AREA_TYPE, $PAGE_TYPE)) {
	include('includes/no_rights.inc');
	exit();
}

$page_action = $_POST['page_action'];

if ($page_action == "search") {
	$title = $_POST['title'];
	$doc_id = $_POST['doc_id'];
	$version = $_POST['version'];
	$latest_version = $_POST['latest_version'];
	
    // BUGFIX: show_bug.cgi?id=661
	$product_id = $_POST['product_id'];
	$product_version_id = $_POST['product_version_id'];

	// BUGFIX: show_bug.cgi?id=195
	$plan_id = $_POST['plan_id'];
	$design_id = $_POST['design_id'];

	$count = 0;
	$results = $tmt->test_scripts->search_test_results($title, $doc_id, $version, $latest_version, $content, $plan_id, $design_id, $product_id, $product_version_id, $count);

	// BUGFIX: show_bug.cgi?id=160
    redirect($tmt->get_self());

	$title = htmlspecialchars(stripslashes($title));
	$doc_id = htmlspecialchars(stripslashes($doc_id));
	$version = htmlspecialchars(stripslashes($version));

	if ($title == "") {
		$title = "all";
	}
	if ($doc_id == "") {
		$doc_id = "all";
	}

	if ($content == "") {
		$content = "all";
	}

	if ($latest_version) {
		$version = "";
	}
	else {
		if ($version == "") {
			$version = "all";
		}
	}
}
elseif ($page_action == "change") {
	$title = $_POST['title'];
	$doc_id = $_POST['doc_id'];
	$version = $_POST['version'];
	$latest_version = $_POST['latest_version'];
	
    // BUGFIX: show_bug.cgi?id=661
	$product_id = $_POST['product_id'];
	$product_version_id = $_POST['product_version_id'];

	// BUGFIX: show_bug.cgi?id=195
	$plan_id = $_POST['plan_id'];
	$design_id = $_POST['design_id'];

	$title = htmlspecialchars(stripslashes($title));
	$doc_id = htmlspecialchars(stripslashes($doc_id));
	$version = htmlspecialchars(stripslashes($version));

}
elseif ($_SESSION['list'][$AREA_TYPE]) {

    // if a search list is present in session vars then use
    // saved search criteria
    if($_SESSION['list'][$AREA_TYPE]["criteria"]["title"])
        $title = $_SESSION['list'][$AREA_TYPE]["criteria"]["title"];
    else
        $title = "";

    if($_SESSION['list'][$AREA_TYPE]["criteria"]["trs_id"])
        $doc_id = $_SESSION['list'][$AREA_TYPE]["criteria"]["trs_id"];
    else
        $doc_id = "";

    if($_SESSION['list'][$AREA_TYPE]["criteria"]["version"])
        $version = $_SESSION['list'][$AREA_TYPE]["criteria"]["version"];
    else
        $version = "";

    if($_SESSION['list'][$AREA_TYPE]["criteria"]["latest_version"])
        $latest_version = $_SESSION['list'][$AREA_TYPE]["criteria"]["latest_version"];
    else
        $latest_version = "";

    // BUGFIX: show_bug.cgi?id=661
    if($_SESSION['list'][$AREA_TYPE]["criteria"]["product_id"])
        $product_id = $_SESSION['list'][$AREA_TYPE]["criteria"]["product_id"];
    else
        $product_id = "";

    if($_SESSION['list'][$AREA_TYPE]["criteria"]["product_version_id"])
        $product_version_id = $_SESSION['list'][$AREA_TYPE]["criteria"]["product_version_id"];
    else
        $product_version_id = "";

    // BUGFIX: show_bug.cgi?id=195
    if($_SESSION['list'][$AREA_TYPE]["criteria"]["plan_id"])
        $plan_id = $_SESSION['list'][$AREA_TYPE]["criteria"]["plan_id"];
    else
        $plan_id = "";

    if($_SESSION['list'][$AREA_TYPE]["criteria"]["design_id"])
        $design_id = $_SESSION['list'][$AREA_TYPE]["criteria"]["design_id"];
    else
        $design_id = "";

    $results = $tmt->test_scripts->search_test_results($title, $doc_id, $version, $latest_version, $content, $plan_id, $design_id, $product_id, $product_version_id, $count);
    $page_action = "search";

}
else {
	$title = "";
	$doc_id = "";
	$version = "";
	$latest_version = 1;
	
	// BUGFIX: show_bug.cgi?id=661
	$product_id = 0;
	$product_version_id = 0;

	// BUGFIX: show_bug.cgi?id=195
	$plan_id = 0;
	$design_id = 0;
}

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 handleSearch() {
			document.main.page_action.value = "search";
			document.main.submit();
		}

		function handleChangeProduct() {
			document.main.product_version_id.value = "0";
			document.main.page_action.value = "change";
			document.main.submit();
		}

		function handleChangePlan() {
			document.main.design_id.value = "0";
			document.main.page_action.value = "change";
			document.main.submit();
		}
	  //-->
	  </script>
      <FORM name="main" method="post" action="<?php echo $tmt->get_self()?>">
		  <input type="hidden" name="page_action" value="">
		  <?php echo table_start("Search for Test Results to Modify", 660);?>

            <TABLE width="580" border="0" cellspacing="0" cellpadding="0" align="center">
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="8" height="5"></TD>
              </TR>
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="8" height="5">
				Searches across multiple fields will be executed with the '&' operator
				</TD>
              </TR>
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="8" height="15"></TD>
              </TR>
              <TR>
                <TD valign="bottom" class="normal" width="5">&nbsp;</TD>
				<TD valign="bottom" class="normal" width="100" colspan="4">Plan</TD>
				<TD valign="bottom" class="normal" width="100" colspan="2">Design</TD>
				<TD valign="bottom" class="normal" width="75">&nbsp;</TD>
			  </TR>
			  <TR>
			    <TD valign="top" class="normal">&nbsp;</TD>
				<TD valign="top" class="normal" colspan="4">
					<SELECT name="plan_id" class="txtbox" onchange="javascript:handleChangePlan();" style="max-width:220px; width:220px;">
						<option value="0"<?php if (!$plan_id) {echo " SELECTED";}?>>All plans</option>
						<?php
							$plans = $tmt->test_plans->get_all_plans();
							foreach($plans as $plan) {
						?>
						<option value="<?php echo $plan["TestPlanID"]?>"<?php if ($plan_id==$plan["TestPlanID"]) {echo " SELECTED";}?>><?php echo $plan["Title"]?></option>
						<?php
							}
						?>
					</SELECT>
				</TD>
				<TD valign="top" class="normal" colspan="2">
					<SELECT name="design_id" class="txtbox" style="max-width:220px; width:220px;">
						<option value="0"<?php if (!$design_id) {echo " SELECTED";}?>>All designs</option>
						<?php if ($plan_id) {
							$designs = $tmt->test_designs->get_latest_designs_by_plan($plan_id);
							foreach($designs as $design) {
						?>
						<option value="<?php echo $design["TestDesignID"]?>"<?php if ($design_id==$design["TestDesignID"]) {echo " SELECTED";}?>><?php echo $design["Title"]?></option>
						<?php
							}
						}
						?>
					</SELECT>
				</TD>
				<TD valign="top" class="normal">&nbsp;</TD>
              </TR>
			  <TR>
				<TD valign="bottom" class="normal" width="5">&nbsp;</TD>
				<TD valign="bottom" class="normal" width="100">Title</TD>
				<TD valign="bottom" class="normal" width="75">ID</TD>
				<TD valign="bottom" class="normal" width="50">Version</TD>
				<TD valign="bottom" class="normal" width="50">Latest Version</TD>
				<TD valign="bottom" class="normal" width="150">Product</TD>
				<TD valign="bottom" class="normal" width="150">&nbsp;Product Version</TD>
				<TD valign="bottom" class="normal">&nbsp;</TD>
			  </TR>
			  <TR>
				<TD valign="top" class="normal">&nbsp;</TD>
				<TD valign="top" class="normal"><INPUT type="text" name="title" value="<?php echo $title;?>" class="txtbox" size="12"></TD>
				<TD valign="top" class="normal"><INPUT type="text" name="doc_id" value="<?php echo $doc_id;?>" class="txtbox" size="8"></TD>
				<TD valign="top" class="normal"><INPUT type="text" name="version" value="<?php echo $version;?>" class="txtbox" size="5"></TD>
				<TD valign="top" class="normal"><INPUT type="checkbox" name="latest_version" value="1" class="txtbox"<?php if ($latest_version) echo ' CHECKED';?>></TD>
				<TD valign="top" class="normal">
					<SELECT name="product_id" class="txtbox" onchange="javascript:handleChangeProduct();">
						<option value="0"<?php if (!$product_id) {echo " SELECTED";}?>>All products</option>
						<?php
							$products = $tmt->products->get_all_products();
							foreach($products as $product) {
						?>
						<option value="<?php echo $product["ID"]?>"<?php if ($product_id==$product["ID"]) {echo " SELECTED";}?>><?php echo $product["Name"]?></option>
						<?php
							}
						?>
					</SELECT>
				</TD>
				<TD valign="top" class="normal">
					&nbsp;<SELECT name="product_version_id" class="txtbox" style="max-width:100px; width:100px;">
						<option value="0"<?php if (!$product_version_id) {echo " SELECTED";}?>>All versions</option>
						<?php if ($product_id) {
							$versions = $tmt->products->get_versions($product_id, $cnt);
							foreach($versions as $version) {
						?>
						<option value="<?php echo $version["ID"]?>"<?php if ($product_version_id==$version["ID"]) {echo " SELECTED";}?>><?php echo $version["Version"]?></option>
						<?php
							}
						}
						?>
					</SELECT>
				</TD>
				<TD valign="top" class="normal"><INPUT type="submit" name="search_button" value=" SEARCH " class="button" onclick="javascript:handleSearch();"></TD>
			  </TR>

              <TR>
                <TD align="center" valign="bottom" class="normal" colspan="8" height="5">&nbsp;</TD>
              </TR>
            </TABLE>
		  <?php echo table_end(660);?>
		  <br>
		  <?php if ($page_action == "search") {?>
			<?php if ($count == 0 ) {?>
				<?php echo table_start("Search results", 660);?>
				<TABLE width="580" border="0" cellspacing="0" cellpadding="0" align="center">
				  <TR>
					<TD align="left" valign="bottom" class="normal" colspan="4" height="5"></TD>
				  </TR>
				  <TR>
					<TD align="left" valign="bottom" class="normal" colspan="4" height="5">
					Your search returned no results. Please try again.
					</TD>
				  </TR>
				</TABLE>
				<?php echo table_end(660);?>
			<?php } else {?>

			<?php
				// BUGFIX: show_bug.cgi?id=661
				$arr_table_cols = array("Title", "ID", "Intended Tester", "Product", "Product Version", "&nbsp;", "&nbsp;");
				$table_width = 660;

				// BUGFIX: show_bug.cgi?id=661
				$arr_table_widths = array(150, 80, 90, 90, 90, 75, 75);

				table_multi_start($arr_table_cols, $table_width, $arr_table_widths);

				foreach($results as $result) {
					// BUGFIX: show_bug.cgi?id=483
					// BUGFIX: show_bug.cgi?id=229
					//$temp_content = format_search($result["Content"]);

					$tester = $tmt->users->get($result['TesterID']);

					// BUGFIX: show_bug.cgi?id=661					
					$arr_table_vals = array($result["Title"], $result["TestResultDocumentID"], $tester['UserName'], $result['Product'], $result['ProductVersion'], "&nbsp;<input type=\"button\" value=\" Single \" class=\"button\" onclick=\"document.location.href='results_modify_single.php?id=" . $result["ID"] . "';\">", "&nbsp;<input type=\"button\" value=\"Multiple\" class=\"button\" onclick=\"document.location.href='results_modify_multiple.php?id=" . $result["ID"] . "';\">");
					
					table_multi_display_line($arr_table_vals, $arr_table_widths);
				}

				table_multi_end($arr_table_cols, $table_width);
			?>

			<?php }?>
		  <?php }?>
      </FORM>
    </TD>
  </TR>
</TABLE>


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