Location: PHPKode > projects > QaTraq > qatraq/reports_copy_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 = "Reports";
$PAGE_LOGO = "images/reports_logo.gif";
$AREA_TYPE = AREA_TYPE_TEST_REPORTS;
$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();
}

$page_action = $_POST['page_action'];
if ($page_action == "search") {
	$title = $_POST['title'];
	$id = $_POST['id'];

	$id2 = str_replace("RPT-", "", $id);
	$id2 = str_replace("RPT", "", $id2);

	$author_id = $_POST['author_id'];
	$report_type = $_POST['report_type'];

	if ($id2) {
		$id2 = (int)$id2;
	}
	else {
		$id = 0;
		$id2 = 0;
	}

	$count = 0;
	$results = $tmt->reports->search($title, $id2, $author_id, $report_type, $count);

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

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

	if ($title == "") {
		$title = "all";
	}
	if (!$id) {
		$id = "all";
	}
}
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"]["id"])
        $id = $_SESSION['list'][$AREA_TYPE]["criteria"]["id"];
    else
        $id = "";

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

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


    $results = $tmt->reports->search($title, $id2, $author_id, $report_type, $count);
    $page_action = "search";

}
// BUGFIX: show_bug.cgi?id=241
else {
	$author_id = $_SESSION['USER_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 handleSearch() {

			document.main.page_action.value = "search";
			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 Reports to Copy", 660);?>

            <TABLE width="620" border="0" cellspacing="0" cellpadding="0" align="center">
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="6" height="5"></TD>
              </TR>
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="6" height="5">
				Searches across multiple fields will be executed with the '&' operator
				</TD>
              </TR>
              <TR>
                <TD align="left" valign="bottom" class="normal" colspan="6" height="15"></TD>
              </TR>
			  <TR>
				<TD valign="top" class="normal" width="10">&nbsp;</TD>
				<TD valign="top" class="normal" width="100">Title</TD>
				<TD valign="top" class="normal" width="70">ID</TD>
				<TD valign="top" class="normal" width="110">Author</TD>
				<TD valign="top" class="normal" width="230">&nbsp;Format Type</TD>
				<TD valign="top" class="normal" width="80">&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="id" value="<?php echo $id;?>" class="txtbox" size="7"></TD>
				<TD valign="top" class="normal">
					<SELECT name="author_id" class="txtbox">
						<option value="0"<?php if (!$author_id) {echo " SELECTED";}?>>All users</option>
						<?php 
							$users = $tmt->users->get_all_users();
							foreach($users as $user) {
						?>
						<option value="<?php echo $user["ID"]?>"<?php if ($author_id==$user["ID"]) {echo " SELECTED";}?>><?php echo $user["UserName"]?></option>
						<?php 
							}
						?>
					</SELECT>
				</TD>
				<TD valign="top" class="normal">
					&nbsp;<SELECT name="report_type" class="txtbox" style="max-width:200px; width:200px;">
						<option value="0"<?php if (!$report_type) {echo " SELECTED";}?>>All types</option>
						<?php 
							$reports = $tmt->reports->get_report_types();
							foreach($reports as $rep) {
						?>
						<option value="<?php echo $rep["Type"]?>"<?php if ($report_type==$rep["Type"]) {echo " SELECTED";}?>><?php echo $rep["Type"]?></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="6" 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 
				$arr_table_cols = array("&nbsp;", "Title", "ID", "Author", "Format Type", "&nbsp");
				$table_width = 660;
				$arr_table_widths = array(20, 160, 70, 129, 160, 120);

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

				foreach($results as $result) {
					$user = $tmt->users->get($result["AuthorID"]);
					$arr_table_vals = array("&nbsp;", $result["Title"], DOC_TYPE_TEST_REPORT . "-" . $result["ID"], $user["UserName"], $result["Type"], "&nbsp;&nbsp;<input type=\"button\" value=\"    Copy    \" class=\"button\" onclick=\"document.location.href='reports_copy_content.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