1062 lines
42 KiB
PHP
1062 lines
42 KiB
PHP
<?php
|
|
/*
|
|
search.php
|
|
OpenDRS Online Discrepancy Reporting System
|
|
Copyright (C) 2026 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("common.php");
|
|
if (array_key_exists('print',$_REQUEST)) {
|
|
$print=true;
|
|
} else {
|
|
$print=false;
|
|
}
|
|
|
|
// redirect to login page if access_mode is untrusted and user is
|
|
// not logged in
|
|
if ($access_mode == "untrusted" && ! isset($_SESSION['userid'])) {
|
|
header("Cache-Control:no-cache, must-revalidate");
|
|
header("Pragma:no-cache");
|
|
header("Location:login.php");
|
|
exit();
|
|
}
|
|
|
|
// redirect to search.php on cancel button press
|
|
if (array_key_exists('cancel',$_REQUEST)) {
|
|
header("Cache-Control:no-cache, must-revalidate");
|
|
header("Pragma:no-cache");
|
|
header("Location:search.php");
|
|
exit();
|
|
}
|
|
|
|
// assign variables from constants
|
|
$appname=APP_NAME;
|
|
|
|
if (array_key_exists('exportcsv',$_REQUEST)) {
|
|
$exportcsv=true;
|
|
$csv_filename="{$appname}_Search_Results_" . date("Y-m-d_His") . ".csv";
|
|
// disable caching
|
|
$lastmodified = gmdate("D, d M Y H:i:s");
|
|
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
|
|
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
|
|
header("Last-Modified: {$lastmodified} GMT");
|
|
|
|
// force download
|
|
header("Content-Type: application/force-download");
|
|
header("Content-Type: application/octet-stream");
|
|
header("Content-Type: application/download");
|
|
|
|
// disposition / encoding on response body
|
|
header("Content-Disposition: attachment;filename={$csv_filename}");
|
|
header("Content-Transfer-Encoding: binary");
|
|
} else {
|
|
$exportcsv=false;
|
|
}
|
|
|
|
// import session variables
|
|
if (isset($_SESSION['userid'])) {
|
|
$userid=$_SESSION['userid'];
|
|
} else {
|
|
$userid=NULL;
|
|
}
|
|
|
|
// import incoming arrays
|
|
if ($print || $exportcsv) {
|
|
// if printer friendly or export csv was clicked, values will be
|
|
// passed in serialized form as "all_parameters" so we need to load
|
|
// those into $incoming[]
|
|
$incoming=unserialize($_REQUEST['all_parameters']);
|
|
} else {
|
|
$incoming=arrayCopy($_REQUEST);
|
|
}
|
|
|
|
// extract incoming array keys into variables
|
|
extract($incoming, EXTR_SKIP);
|
|
/*
|
|
* possible keys are:
|
|
* search
|
|
* viewtype
|
|
* s_device
|
|
* s_discovered
|
|
* s_functional
|
|
* s_reported_by
|
|
* s_report_date_start
|
|
* s_report_date_end
|
|
* s_report_time_start
|
|
* s_report_time_end
|
|
* s_action_date_start
|
|
* s_action_date_end
|
|
* s_action_time_start
|
|
* s_action_time_end
|
|
* s_action_by
|
|
* s_action_reason
|
|
* s_action_text
|
|
* s_subsystem
|
|
* s_id
|
|
* s_discrepancy_text
|
|
* s_status
|
|
* s_group
|
|
* sort
|
|
* order
|
|
*/
|
|
|
|
if (!isset($search)) $search=false;
|
|
if (!isset($viewtype)) $viewtype="summary";
|
|
if (!isset($s_id)) $s_id=NULL;
|
|
if (!isset($s_discrepancy_text)) $s_discrepancy_text=NULL;
|
|
if (!isset($s_reported_by)) $s_reported_by=NULL;
|
|
if (!isset($s_action_text)) $s_action_text=NULL;
|
|
if (!isset($s_action_date_start)) $s_action_date_start=NULL;
|
|
if (!isset($s_action_date_end)) $s_action_date_end=NULL;
|
|
if (!isset($s_action_time_start)) $s_action_time_start=NULL;
|
|
if (!isset($s_action_time_end)) $s_action_time_end=NULL;
|
|
if (!isset($sort)) $sort=NULL;
|
|
if (!isset($order)) $order=NULL;
|
|
|
|
if ($print) {
|
|
$mbgcolor=P_MENUBG_COLOR;
|
|
} else {
|
|
$mbgcolor=MENUBG_COLOR;
|
|
}
|
|
|
|
$role=dblookup($drs_db,"users","id","role",$userid);
|
|
$pgtitle="Search Writeups";
|
|
|
|
if (! $exportcsv) framework("begin","$appname",$pgtitle,$print);
|
|
|
|
//echo "_REQUEST array <br>";
|
|
//var_dump($_REQUEST);
|
|
//echo "<br><hr> incoming array <br>";
|
|
//var_dump($incoming);
|
|
|
|
|
|
// ******** begin database manipulation ********
|
|
|
|
// get min, max report and action_dates from writeups table, validate input dates/times and set defaults
|
|
$minmaxqry=mysqli_query($drs_db,"select min(report_date),max(report_date),min(action_date),max(action_date) from writeups");
|
|
$minmaxdates=mysqli_fetch_row($minmaxqry);
|
|
if (!isset($s_report_date_start) || !validateDate($s_report_date_start)) $s_report_date_start=$minmaxdates[0];
|
|
if (!isset($s_report_date_end) || !validateDate($s_report_date_end)) $s_report_date_end=$minmaxdates[1];
|
|
if (!isset($s_report_time_start) || !validateTime($s_report_time_start)) $s_report_time_start="00:00:00";
|
|
if (!isset($s_report_time_end) || !validateTime($s_report_time_end)) $s_report_time_end="23:59:59";
|
|
|
|
if ($search) {
|
|
// strip whitespace from beginning and end of text fields
|
|
$s_reported_by=trim($s_reported_by);
|
|
$s_action_text=trim($s_action_text);
|
|
$s_discrepancy_text=trim($s_discrepancy_text);
|
|
$s_id=trim($s_id);
|
|
|
|
// build the query string
|
|
$query_string="";
|
|
// device
|
|
if ($s_device) {
|
|
$query_string="{$query_string}(";
|
|
$device_param="{$device_term}s:";
|
|
foreach ($s_device as $dev_val) {
|
|
$query_string="{$query_string}device=\"{$dev_val}\" or ";
|
|
$device_dsp=dblookup($drs_db,"devices","id","name",$dev_val);
|
|
$device_param="{$device_param} {$device_dsp}, ";
|
|
}
|
|
$device_param=rtrim($device_param,", ");
|
|
$num_devices=mysqli_num_rows(mysqli_query($drs_db,"select id from devices"));
|
|
if (count($s_device)==$num_devices) $device_param="{$device_term}s: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// subsystem
|
|
if ($s_subsystem) {
|
|
$query_string="{$query_string}(";
|
|
$subsystem_param="Subsystems:";
|
|
foreach ($s_subsystem as $sub_val) {
|
|
$query_string="{$query_string}subsystem=\"{$sub_val}\" or ";
|
|
$subsystem_dsp=dblookup($drs_db,"subsystems","id","name",$sub_val);
|
|
$subsystem_param="{$subsystem_param} {$subsystem_dsp}, ";
|
|
}
|
|
$subsystem_param=rtrim($subsystem_param,", ");
|
|
$num_subsystems=mysqli_num_rows(mysqli_query($drs_db,"select id from subsystems"));
|
|
if (count($s_subsystem)==$num_subsystems) $subsystem_param="Subsystems: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// id
|
|
if ($s_id) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}id={$s_id}";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$id_param="ID: {$s_id}";
|
|
} else {
|
|
$id_param="ID: any";
|
|
}
|
|
// discovered
|
|
if ($s_discovered) {
|
|
$query_string="{$query_string}(";
|
|
$discovered_param="{$discovered_term_short}:";
|
|
foreach ($s_discovered as $disc_val) {
|
|
$query_string="{$query_string}discovered=\"{$disc_val}\" or ";
|
|
$disc_dsp=$disc_val;
|
|
$discovered_param="{$discovered_param} {$disc_dsp}, ";
|
|
}
|
|
$discovered_param=rtrim($discovered_param,", ");
|
|
$num_discovereds=mysqli_num_rows(mysqli_query($drs_db,"select id from discovered"));
|
|
if (count($s_discovered)==$num_discovereds) $discovered_param="{$discovered_term_short}s: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// functional
|
|
if ($s_functional) {
|
|
$query_string="{$query_string}(";
|
|
$func_param="$functional_term:";
|
|
foreach ($s_functional as $func_val) {
|
|
$query_string="{$query_string}functional=\"{$func_val}\" or ";
|
|
if ($func_val=="0") $func_dsp="<font color=\"#FF0000\">$functional_no_short</font>";
|
|
if ($func_val=="1") $func_dsp="<font color=\"#00FF00\">$functional_yes_short</font>";
|
|
$func_param="{$func_param} {$func_dsp}, ";
|
|
}
|
|
$func_param=rtrim($func_param,", ");
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// status
|
|
if ($s_status) {
|
|
$query_string="{$query_string}(";
|
|
$status_param="Status:";
|
|
foreach ($s_status as $stat_val) {
|
|
$query_string="{$query_string}status=\"{$stat_val}\" or ";
|
|
if ($stat_val=="1") $stat_dsp="<font color=\"#FF0000\">OPEN</font>";
|
|
if ($stat_val=="2") $stat_dsp="<font color=\"#00FF00\">CLSD</font>";
|
|
if ($stat_val=="3") $stat_dsp="<font color=\"#FFFF00\">DFRD</font>";
|
|
$status_param="{$status_param} {$stat_dsp}, ";
|
|
}
|
|
$status_param=rtrim($status_param,", ");
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// action by
|
|
if ($s_action_by) {
|
|
$query_string="{$query_string}(";
|
|
$actionby_param="Status changed by:";
|
|
foreach ($s_action_by as $actby_val) {
|
|
$query_string="{$query_string}action_by=\"{$actby_val}\" or ";
|
|
if ($actby_val==0) {
|
|
$actionby_dsp=" (none set)";
|
|
} else {
|
|
$actionby_dsp=dblookup($drs_db,"users","id","firstname",$actby_val)." ".dblookup($drs_db,"users","id","lastname",$actby_val);
|
|
}
|
|
$actionby_param="{$actionby_param} {$actionby_dsp}, ";
|
|
}
|
|
$actionby_param=rtrim($actionby_param,", ");
|
|
$num_users=mysqli_num_rows(mysqli_query($drs_db,"select id from users"));
|
|
if (count($s_action_by)==$num_users+1) $actionby_param="Status changed by: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// action reason
|
|
if ($s_action_reason) {
|
|
$query_string="{$query_string}(";
|
|
$reason_param="Status change reason:";
|
|
foreach ($s_action_reason as $actrn_val) {
|
|
$query_string="{$query_string}action_reason=\"{$actrn_val}\" or ";
|
|
if ($actrn_val==0) {
|
|
$reason_dsp=" (none set)";
|
|
} else {
|
|
$reason_dsp=dblookup($drs_db,"reasons","id","text",$actrn_val);
|
|
}
|
|
$reason_param="{$reason_param} {$reason_dsp}, ";
|
|
}
|
|
$reason_param=rtrim($reason_param,", ");
|
|
$num_reasons=mysqli_num_rows(mysqli_query($drs_db,"select id from reasons"));
|
|
if (count($s_action_reason)==$num_reasons+1) $reason_param="Status change reason: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// report date
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}report_date between \"{$s_report_date_start}\" and \"{$s_report_date_end}\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$reportdate_param="Report date between {$s_report_date_start} and {$s_report_date_end}";
|
|
// report time
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}report_time between \"{$s_report_time_start}\" and \"{$s_report_time_end}\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$reporttime_param="Report time between {$s_report_time_start} and {$s_report_time_end}";
|
|
// action date
|
|
if ($s_action_date_start && $s_action_date_end) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}action_date between \"{$s_action_date_start}\" and \"{$s_action_date_end}\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$actiondate_param="Action taken date between {$s_action_date_start} and {$s_action_date_end}";
|
|
} else {
|
|
$actiondate_param="Action taken date: any";
|
|
}
|
|
// action time
|
|
if ($s_action_time_start && $s_action_time_end) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}action_time between \"{$s_action_time_start}\" and \"{$s_action_time_end}\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$actiontime_param="Action taken time between {$s_action_time_start} and {$s_action_time_end}";
|
|
} else {
|
|
$actiontime_param="Action taken time: any";
|
|
}
|
|
// discrepancy text
|
|
if ($s_discrepancy_text) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}discrepancy_text like \"%{$s_discrepancy_text}%\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$discrepancytext_param="Text in discrepancy: {$s_discrepancy_text}";
|
|
} else {
|
|
$discrepancytext_param="Text in discrepancy: any";
|
|
}
|
|
// action text
|
|
if ($s_action_text) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}action_text like \"%{$s_action_text}%\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$actiontext_param="Text in Action taken: {$s_action_text}";
|
|
} else {
|
|
$actiontext_param="Text in Action taken: any";
|
|
}
|
|
// reported by
|
|
if ($s_reported_by) {
|
|
$query_string="{$query_string}(";
|
|
$query_string="{$query_string}reported_by like \"%{$s_reported_by}%\"";
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
$repby_param="Text in Reported by: {$s_reported_by}";
|
|
} else {
|
|
$repby_param="Text in Reported by: any";
|
|
}
|
|
|
|
$query_string=rtrim($query_string," and ");
|
|
$query_string="select * from writeups where {$query_string} order by $sort $order";
|
|
|
|
// group membership
|
|
if (isset($s_group)) {
|
|
$group_param="Group member: ";
|
|
// create an array of writeups that are members of the groups specified
|
|
$group_writeups=[];
|
|
foreach ($s_group as $group_val) {
|
|
$wulink_query=mysqli_query($drs_db,"select writeupid from links where linkgroup=$group_val");
|
|
while($wulinkrow=mysqli_fetch_assoc($wulink_query)){
|
|
$group_writeups[]=$wulinkrow['writeupid'];
|
|
}
|
|
$group_name=dblookup($drs_db,"groups","id","name",$group_val);
|
|
$group_param="{$group_param} <font title=\"{$group_name}\">{$group_val}</font>, ";
|
|
}
|
|
$group_param=rtrim($group_param,", ");
|
|
} else {
|
|
$group_param="Group member: any";
|
|
}
|
|
}
|
|
|
|
|
|
// ******** end database manipulation ********
|
|
if (! $exportcsv) {
|
|
pagetable("begin");
|
|
if(!$print) {
|
|
pageblock("left","begin");
|
|
sidemenu();
|
|
echo "<br><br>";
|
|
pageblock("left","end");
|
|
}
|
|
pageblock("right","begin");
|
|
banner($print);
|
|
echo "<br>";
|
|
|
|
// show search form
|
|
if (!$print) {
|
|
echo "
|
|
<form method=\"post\" action=\"search.php#results\">
|
|
<table border=\"0\" cellpadding=\"5\">
|
|
<tr>
|
|
<td align=\"left\">
|
|
";
|
|
// ID cell *****************
|
|
echo "
|
|
ID<br>
|
|
<input type=\"text\" name=\"s_id\" size=\"10\" value=\"$s_id\">
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// Device cell *********************
|
|
echo "
|
|
$device_term<br>
|
|
<select name=\"s_device[]\" id=\"ms-device\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
";
|
|
$drow=mysqli_query($drs_db,"select * from devices order by id asc");
|
|
while ($ditem=mysqli_fetch_assoc($drow)) {
|
|
if (!$search || in_array($ditem["id"],$s_device,true)) {
|
|
printf("<option value=\"%s\" selected>%s</option>",$ditem["id"],$ditem["name"]);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>",$ditem["id"],$ditem["name"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// Subsystem cell *******************
|
|
echo "
|
|
Subsystem<br>
|
|
<select name=\"s_subsystem[]\" id=\"ms-subsystem\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
";
|
|
$ssrow=mysqli_query($drs_db,"select * from subsystems order by id asc");
|
|
while ($ssitem=mysqli_fetch_assoc($ssrow)) {
|
|
if (!$search || in_array($ssitem["id"],$s_subsystem,true)) {
|
|
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$ssitem["id"],$ssitem["description"],$ssitem["name"]);
|
|
} else {
|
|
printf("<option value=\"%s\" title=\"%s\">%s</option>",$ssitem["id"],$ssitem["description"],$ssitem["name"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
";
|
|
echo "
|
|
</tr>
|
|
<tr>
|
|
<td align=\"left\">
|
|
";
|
|
// Discovered cell **********************
|
|
echo "
|
|
$discovered_term<br>
|
|
<select name=\"s_discovered[]\" id=\"ms-discovered\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
";
|
|
if ($disc_drop_data=="Name") {
|
|
$discddtitle="whendiscovereddesc";
|
|
$discddtext="whendiscoveredname";
|
|
} else if ($disc_drop_data=="Desc") {
|
|
$discddtitle="whendiscoveredname";
|
|
$discddtext="whendiscovereddesc";
|
|
}
|
|
$discrow=mysqli_query($drs_db,"select * from discovered order by whendiscoveredname asc");
|
|
while ($discitem=mysqli_fetch_assoc($discrow)) {
|
|
if (!$search || in_array($discitem["id"],$s_discovered,true)) {
|
|
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
|
} else {
|
|
printf("<option value=\"%s\" title=\"%s\">%s</option>",$discitem["id"],$discitem["$discddtitle"],$discitem["$discddtext"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// Report Date cell *****************
|
|
echo "
|
|
Report Date Between<br>
|
|
<input type=\"text\" name=\"s_report_date_start\" size=\"10\" maxlength=\"10\" value=\"$s_report_date_start\" id=\"sdp-report_date\" title=\"Format: YYYY-MM-DD\">
|
|
and
|
|
<input type=\"text\" name=\"s_report_date_end\" size=\"10\" maxlength=\"10\" value=\"$s_report_date_end\" id=\"edp-report_date\" title=\"Format: YYYY-MM-DD\">
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
";
|
|
echo "
|
|
<td align=\"left\">
|
|
";
|
|
// Report Time cell *****************
|
|
echo "
|
|
Report Time Between<br>
|
|
<input type=\"text\" name=\"s_report_time_start\" size=\"8\" maxlength=\"8\" value=\"$s_report_time_start\" title=\"Format: HH:MM:SS\">
|
|
and
|
|
<input type=\"text\" name=\"s_report_time_end\" size=\"8\" maxlength=\"8\" value=\"$s_report_time_end\" title=\"Format: HH:MM:SS\">
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
</tr>
|
|
<tr><td></td><td></td><td></td></tr>
|
|
<tr>
|
|
<td colspan=\"3\">
|
|
";
|
|
// Discrepancy text cell ************
|
|
echo "
|
|
Words in Discrepancy<br>
|
|
<textarea rows=\"5\" cols=\"80\" name=\"s_discrepancy_text\" wrap=\"soft\">$s_discrepancy_text</textarea><br>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align=\"left\">
|
|
";
|
|
// Reported by cell *****************
|
|
echo "
|
|
Reported by<br>
|
|
<input type=\"text\" name=\"s_reported_by\" size=\"30\" value=\"$s_reported_by\">
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// functional cell ************
|
|
echo "
|
|
$functional_term? <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
|
|
";
|
|
if ($search) {
|
|
$funcyesstate=$funcnostate="";
|
|
if (in_array("1",$s_functional,true)) $funcyesstate="selected";
|
|
if (in_array("0",$s_functional,true)) $funcnostate="selected";
|
|
} else {
|
|
$funcyesstate=$funcnostate="selected";
|
|
}
|
|
echo "
|
|
<select name=\"s_functional[]\" id=\"ms-functional\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
<option value=\"1\" $funcyesstate>$functional_yes</option>
|
|
<option value=\"0\" $funcnostate>$functional_no</option>
|
|
</select>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// Group status cell **************
|
|
echo "
|
|
Group Assignments:<br>
|
|
<select style=\"max-width:40%;\" name=\"s_group[]\" id=\"ms-group\" multiple title=\"Select the groups the results should be a member of. If you uncheck them all, this field will not be included in the search.\">
|
|
";
|
|
if (!isset($s_group)) $s_group=[];
|
|
$grow=mysqli_query($drs_db,"select * from groups order by id asc");
|
|
while ($gitem=mysqli_fetch_assoc($grow)) {
|
|
if ($gitem["name"]=="") {
|
|
$gname="Group ".$gitem["id"];
|
|
} else {
|
|
$gname=$gitem["name"];
|
|
}
|
|
if($search) {
|
|
if (in_array($gitem["id"],$s_group,true)) {
|
|
printf("<option value=\"%s\" selected>%s</option>",$gitem["id"],$gname);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>",$gitem["id"],$gname);
|
|
}
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>",$gitem["id"],$gname);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
|
|
// ************************************
|
|
echo "
|
|
</td></tr>
|
|
<tr><td colspan=\"3\" bgcolor=\"black\"></td></tr>
|
|
<tr><td colspan=\"3\" bgcolor=\"black\"></td></tr>
|
|
<tr>
|
|
<td align=\"left\">
|
|
";
|
|
// Status cell **********************
|
|
echo "
|
|
Status<br>
|
|
";
|
|
if ($search) {
|
|
$openstate=$clsdstate=$dfrdstate="";
|
|
if (in_array("1",$s_status,true)) $openstate="selected";
|
|
if (in_array("2",$s_status,true)) $clsdstate="selected";
|
|
if (in_array("3",$s_status,true)) $dfrdstate="selected";
|
|
} else {
|
|
$openstate=$clsdstate=$dfrdstate="selected";
|
|
}
|
|
echo "
|
|
<select name=\"s_status[]\" id=\"ms-status\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
<option title=\"Open\" value=\"1\" $openstate>OPEN</option>
|
|
<option title=\"Closed\" value=\"2\" $clsdstate>CLSD</option>
|
|
<option title=\"Deferred\" value=\"3\" $dfrdstate>DFRD</option>
|
|
</select>
|
|
";
|
|
// **********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// action by cell ************
|
|
echo "
|
|
Status changed by<br>
|
|
<select name=\"s_action_by[]\" id=\"ms-user\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
<option value=\"0\" selected>(none set)</option>
|
|
";
|
|
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users order by lastname asc");
|
|
while ($persitem=mysqli_fetch_assoc($persrow)) {
|
|
if (!$search || in_array($persitem["id"],$s_action_by,true)) {
|
|
printf("<option value=\"%s\" selected>%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
|
} else {
|
|
printf("<option value=\"%s\">%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
// ***********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// action reason cell *********
|
|
echo "
|
|
Status change reason<br>
|
|
<select name=\"s_action_reason[]\" id=\"ms-reason\" multiple title=\"If you uncheck all, then this field will not be included in the search.\">
|
|
<option value=\"0\" selected>(none set)</option>
|
|
";
|
|
$reasrow=mysqli_query($drs_db,"select id,text from reasons order by id asc");
|
|
while ($reasitem=mysqli_fetch_assoc($reasrow)) {
|
|
if (!$search || in_array($reasitem["id"],$s_action_reason,true)) {
|
|
printf("<option value=\"%s\" selected>%s</option>",$reasitem["id"],$reasitem["text"]);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>",$reasitem["id"],$reasitem["text"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
// ***********************************
|
|
echo "
|
|
</td>
|
|
</tr>
|
|
<tr><td></td><td></td><td></td></tr>
|
|
<tr>
|
|
<td colspan=\"3\">
|
|
";
|
|
// Action taken text cell ************
|
|
echo "
|
|
Words in Action Taken<br>
|
|
<textarea rows=\"5\" cols=\"80\" name=\"s_action_text\" wrap=\"soft\">$s_action_text</textarea><br>
|
|
";
|
|
// ***********************************
|
|
echo "
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align=\"left\" >
|
|
";
|
|
// Action date cell ******************
|
|
echo "
|
|
Action Taken Date Between<br>
|
|
<input type=\"text\" name=\"s_action_date_start\" size=\"10\" maxlength=\"10\" value=\"$s_action_date_start\" id=\"sdp-action_date\" title=\"Format: YYYY-MM-DD\">
|
|
and
|
|
<input type=\"text\" name=\"s_action_date_end\" size=\"10\" maxlength=\"10\" value=\"$s_action_date_end\" id=\"edp-action_date\" title=\"Format: YYYY-MM-DD\">
|
|
";
|
|
// ***********************************
|
|
echo "
|
|
</td>
|
|
<td align=\"left\">
|
|
";
|
|
// Action time cell ******************
|
|
echo "
|
|
Action Taken Time Between<br>
|
|
<input type=\"text\" name=\"s_action_time_start\" size=\"8\" maxlength=\"8\" value=\"$s_action_time_start\" title=\"Format: HH:MM:SS\">
|
|
and
|
|
<input type=\"text\" name=\"s_action_time_end\" size=\"8\" maxlength=\"8\" value=\"$s_action_time_end\" title=\"Format: HH:MM:SS\">
|
|
";
|
|
// ***********************************
|
|
$summarystat=$detailstat="";
|
|
if ($viewtype=="detail") {
|
|
$detailstat="checked";
|
|
} else {
|
|
$summarystat="checked";
|
|
}
|
|
$idsort=$statussort=$datesort=$discsort=$devicesort=$subsyssort=$repbysort=$discrepsort=$funcsort="";
|
|
switch ($sort) {
|
|
case "id":
|
|
$idsort="checked";
|
|
break;
|
|
case "status":
|
|
$statussort="checked";
|
|
break;
|
|
case "report_date":
|
|
$datesort="checked";
|
|
break;
|
|
case "discovered":
|
|
$discsort="checked";
|
|
break;
|
|
case "device":
|
|
$devicesort="checked";
|
|
break;
|
|
case "subsystem":
|
|
$subsyssort="checked";
|
|
break;
|
|
case "reported_by":
|
|
$repbysort="checked";
|
|
break;
|
|
case "discrepancy_text":
|
|
$discrepsort="checked";
|
|
break;
|
|
case "functional":
|
|
$funcsort="checked";
|
|
break;
|
|
default:
|
|
$datesort="checked";
|
|
}
|
|
$ascsort=$descsort="";
|
|
if ($order=="desc") {
|
|
$descsort="checked";
|
|
} else {
|
|
$ascsort="checked";
|
|
}
|
|
echo "</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<input type=\"radio\" $summarystat name=\"viewtype\" value=\"summary\" id=\"summaryview\" ><label for=\"summaryview\" title=\"Show one writeup per line with minimal detail.\">Results in summary view</label>
|
|
<input type=\"radio\" $detailstat name=\"viewtype\" value=\"detail\" id=\"detailview\"><label for=\"detailview\" title=\"Show each writeup's full details.\">Results in detail view</label>
|
|
<br><br>
|
|
Sort Field:<br>
|
|
<input type=\"radio\" $idsort name=\"sort\" value=\"id\" id=\"idview\" ><label for=\"idview\" title=\"Sort by ID.\">ID</label>
|
|
<input type=\"radio\" $statussort name=\"sort\" value=\"status\" id=\"statusview\" ><label for=\"statusview\" title=\"Sort by Status.\">Status</label>
|
|
<input type=\"radio\" $datesort name=\"sort\" value=\"report_date\" id=\"dateview\" ><label for=\"dateview\" title=\"Sort by Report Date.\">Date</label>
|
|
<input type=\"radio\" $discsort name=\"sort\" value=\"discovered\" id=\"discoveredview\" ><label for=\"discoveredview\" title=\"Sort by $discovered_term.\">$discovered_term_short</label>
|
|
<input type=\"radio\" $devicesort name=\"sort\" value=\"device\" id=\"deviceview\" ><label for=\"deviceview\" title=\"Sort by $device_term.\">$device_term</label>
|
|
<input type=\"radio\" $subsyssort name=\"sort\" value=\"subsystem\" id=\"subsysview\" ><label for=\"subsysview\" title=\"Sort by Subsystem.\">Subsystem</label>
|
|
<input type=\"radio\" $repbysort name=\"sort\" value=\"reported_by\" id=\"repbyview\" ><label for=\"repbyview\" title=\"Sort by Reported by.\">Reported by</label>
|
|
<input type=\"radio\" $discrepsort name=\"sort\" value=\"discrepancy_text\" id=\"discrepview\" ><label for=\"discrepview\" title=\"Sort by Discrepancy.\">Discrepancy</label>
|
|
<input type=\"radio\" $funcsort name=\"sort\" value=\"functional\" id=\"funcview\" ><label for=\"funcview\" title=\"Sort by $functional_term.\">$functional_term_short</label>
|
|
<br>Sort Order:<br>
|
|
<input type=\"radio\" $ascsort name=\"order\" value=\"asc\" id=\"ascview\" ><label for=\"ascview\" title=\"Sort results in ascending order.\">Ascending</label>
|
|
<input type=\"radio\" $descsort name=\"order\" value=\"desc\" id=\"descview\" ><label for=\"descview\" title=\"Sort results in descending order.\">Descending</label>
|
|
<br><br>
|
|
<input type=\"submit\" name=\"search\" value=\"Search\">
|
|
|
|
<input type=\"submit\" name=\"cancel\" value=\"Start New Search\">
|
|
</form>
|
|
<br>
|
|
";
|
|
}
|
|
}
|
|
// display the results
|
|
if ($search) {
|
|
if (! $exportcsv) {
|
|
//display the search parameters used
|
|
if (!$print) echo "<a id=\"results\"></a>";
|
|
echo "
|
|
<table border=\"2\" width=\"100%\">
|
|
<tr><td align=\"left\"><b>Parameters used in this search</b>
|
|
";
|
|
if (!$print) {
|
|
echo " <font size=\"-1\">Scroll up to modify parameters</font></td>";
|
|
} else {
|
|
echo "</td>";
|
|
}
|
|
echo "
|
|
</tr>
|
|
<tr><td>
|
|
<table border=\"0\">
|
|
<td><b>$status_param</b></td><td> </td>
|
|
<td>$device_param</td><td> </td>
|
|
<td>$subsystem_param</td><td> </td>
|
|
<td>$id_param</td><td> </td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$discovered_param</td><td> </td>
|
|
<td>$reportdate_param</td><td> </td>
|
|
<td>$reporttime_param</td><td> </td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$discrepancytext_param</td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$repby_param</td><td> </td>
|
|
<td>$func_param</td><td> </td>
|
|
<td>$group_param</td><td> </td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$actionby_param</td><td> </td>
|
|
<td>$reason_param</td><td> </td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$actiontext_param</td>
|
|
</tr>
|
|
</table>
|
|
<table border=\"0\">
|
|
<tr>
|
|
<td>$actiondate_param</td><td> </td>
|
|
<td>$actiontime_param</td><td> </td>
|
|
</tr>
|
|
</table>
|
|
</td></tr></table>
|
|
<br>
|
|
";
|
|
}
|
|
$currentparams=arrayCopy($_REQUEST);
|
|
if (! $exportcsv) {
|
|
echo "
|
|
<form method=\"post\" target=\"_blank\">
|
|
<input type=\"hidden\" name=\"all_parameters\" value=\"". htmlentities(serialize($currentparams))."\">
|
|
<input type=\"submit\" name=\"exportcsv\" value=\"Export as CSV\" id=\"exportascsv\"></form>
|
|
";
|
|
}
|
|
$writeup=mysqli_query($drs_db,$query_string);
|
|
// create an array of ids returned by the query string
|
|
$result_ids=[];
|
|
while ($eachid=mysqli_fetch_assoc($writeup)) {
|
|
$result_ids[]=$eachid['id'];
|
|
}
|
|
|
|
mysqli_data_seek($writeup,0);
|
|
if (!isset($group_writeups)) $group_writeups=[];
|
|
reset($group_writeups);
|
|
$num_results=mysqli_num_rows($writeup);
|
|
if ($num_results > 0) {
|
|
if ($exportcsv) {
|
|
// generate csv file
|
|
// create an array of lines of the csv data
|
|
$csv_data=[];
|
|
$csv_data[]=['WriteupID','Status',$device_term,'Subsystem',$discovered_term_short,$functional_term,'Discrepancy','Group','Report date','Report time','Reported by','Action taken by','Status Change Reason','Action taken','Action date','Action time'];
|
|
|
|
$csv_fp=fopen('php://temp', 'w+');
|
|
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
|
|
|
// writeup id for csv
|
|
$csv_id=$tablerow['id'];
|
|
|
|
// determine status text
|
|
if ($tablerow['status']==1) $csv_status_text="Open";
|
|
if ($tablerow['status']==2) $csv_status_text="Closed";
|
|
if ($tablerow['status']==3) $csv_status_text="Deferred";
|
|
|
|
// convert device number to name for csv
|
|
$csv_dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]);
|
|
|
|
// convert subsystem number to name for csv
|
|
$csv_ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
|
|
|
// discovered name for csv
|
|
$csv_discovered=dblookup($drs_db,"discovered","id","whendiscoveredname",$tablerow["discovered"]);
|
|
|
|
// determine functional text for csv
|
|
if($tablerow["functional"]==1) {
|
|
$csv_func_text="$functional_yes_short";
|
|
} else {
|
|
$csv_func_text="$functional_no_short";
|
|
}
|
|
|
|
// discrepancy text for csv
|
|
$csv_disc_txt="{$tablerow["discrepancy_text"]}";
|
|
$csv_disc_txt=str_replace("\n","\r\n",$csv_disc_txt);
|
|
|
|
// group name or number for csv
|
|
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
|
$is_member=mysqli_num_rows($member_qry);
|
|
// look up group name
|
|
if ($is_member) {
|
|
$group_count=$is_member;
|
|
if ($group_count == 1) {
|
|
$group_num=mysqli_fetch_row(mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\""))[0];
|
|
$member_group_name=dblookup($drs_db,"groups","id","name",$group_num);
|
|
if ($member_group_name) {
|
|
$csv_member_group_name=$member_group_name;
|
|
} else {
|
|
$csv_member_group_name=$group_num;
|
|
}
|
|
} else {
|
|
$csv_member_group_name="multiple";
|
|
}
|
|
} else {
|
|
$csv_member_group_name="none";
|
|
}
|
|
|
|
// report date for csv
|
|
$csv_report_date="{$tablerow["report_date"]}";
|
|
|
|
// report time for csv
|
|
$csv_report_time="{$tablerow["report_time"]}";
|
|
|
|
// reported by text for csv
|
|
$csv_reported_by_text="{$tablerow["reported_by"]}";
|
|
$csv_reported_by_text=str_replace("\n","\r\n",$csv_reported_by_text);
|
|
|
|
// action taken by text for csv
|
|
$techfname=dblookup($drs_db,"users","id","firstname","{$tablerow["action_by"]}");
|
|
$techlname=dblookup($drs_db,"users","id","lastname","{$tablerow["action_by"]}");
|
|
$csv_action_by="$techfname $techlname";
|
|
|
|
// status change reason for csv
|
|
$csv_reasonname=dblookup($drs_db,"reasons","id","text","{$tablerow["action_reason"]}");
|
|
|
|
// action taken text for csv
|
|
$csv_action_text="{$tablerow["action_text"]}";
|
|
$csv_action_text=str_replace("\n","\r\n",$csv_action_text);
|
|
|
|
// action date for csv
|
|
$csv_action_date="{$tablerow["action_date"]}";
|
|
|
|
// action time for csv
|
|
$csv_action_time="{$tablerow["action_time"]}";
|
|
|
|
// add line of results to csv array
|
|
$csv_data[]=[$csv_id, $csv_status_text, $csv_dname, $csv_ssname, $csv_discovered, $csv_func_text, $csv_disc_txt, $csv_member_group_name, $csv_report_date, $csv_report_time, $csv_reported_by_text, $csv_action_by, $csv_reasonname, $csv_action_text, $csv_action_date, $csv_action_time];
|
|
}
|
|
|
|
foreach ($csv_data as $csv_fields) {
|
|
// add row to csv buffer
|
|
fputcsv($csv_fp, $csv_fields);
|
|
}
|
|
$csv_filename="data_export_" . date("Y-m-d") . ".csv";
|
|
// reset pointer back to start
|
|
rewind($csv_fp);
|
|
// send file contents
|
|
$csv_contents=stream_get_contents($csv_fp);
|
|
// Close our pointer and free up memory and /tmp space
|
|
fclose($csv_fp);
|
|
echo $csv_contents;
|
|
} else {
|
|
if ($viewtype=="summary") {
|
|
echo "
|
|
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
|
<tr>
|
|
<th style=\"width:1%;\">ID</th>
|
|
<th style=\"width:1%;\">Status</th>
|
|
<th style=\"width:100px;\">Date</th>
|
|
<th style=\"width:1%;\">$discovered_term_short</th>
|
|
<th style=\"width:1%;\">$device_term</th>
|
|
<th style=\"width:1%;\">Subsystem</th>
|
|
<th style=\"width:1%;\">Reported by</th>
|
|
<th>Discrepancy</th>
|
|
<th style=\"width:1%;\">$functional_term_short</th>
|
|
</tr>
|
|
";
|
|
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
|
// determine if this is a member of a group
|
|
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
|
$is_member=mysqli_num_rows($member_qry);
|
|
|
|
// determine functional icon
|
|
if($tablerow["functional"]==1) {
|
|
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
|
} else {
|
|
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
|
}
|
|
|
|
// determine status indicator
|
|
if ($tablerow['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
|
|
if ($tablerow['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
|
|
if ($tablerow['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
|
|
|
|
// convert device number to name
|
|
$dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]);
|
|
// convert discovered number to description
|
|
$discname=dblookup($drs_db,"discovered","id","whendiscoveredname",$tablerow["discovered"]);
|
|
// convert discovered number to description
|
|
$discdesc=dblookup($drs_db,"discovered","id","whendiscovereddesc",$tablerow["discovered"]);
|
|
// convert subsystem number to name
|
|
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
|
$disc_txt="{$tablerow["discrepancy_text"]}";
|
|
|
|
// set group indicator
|
|
if ($is_member) {
|
|
$group_count=$is_member;
|
|
if ($group_count == 1) {
|
|
$group_num=mysqli_fetch_row(mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\""))[0];
|
|
$member_group_name=dblookup($drs_db,"groups","id","name",$group_num);
|
|
if ($member_group_name) {
|
|
$imgtitle="Member of group: $member_group_name";
|
|
} else {
|
|
$imgtitle="Member of group ID: $group_num";
|
|
}
|
|
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php?group=$group_num\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
|
} else {
|
|
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
|
}
|
|
}
|
|
|
|
if(in_array($tablerow['id'],$group_writeups) || count($s_group)==0) {
|
|
// print table row
|
|
printf(
|
|
"<tr>
|
|
<td align=\"center\" valign=\"top\"><a href=\"writeupdetail.php?id=%s\" title=\"View or change details of this writeup\">%s</a></td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\"><font title=\"%s\">%s</font></td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\">%s</td>
|
|
<td align=\"center\" valign=\"top\">%s</td>
|
|
</tr>\n",
|
|
$tablerow["id"],$tablerow["id"],
|
|
$statusind,
|
|
$tablerow["report_date"],
|
|
$discdesc,$discname,
|
|
$dname,
|
|
$ssname,
|
|
$tablerow["reported_by"],
|
|
$disc_txt,
|
|
$func_icon
|
|
);
|
|
}
|
|
}
|
|
echo "</table>\n";
|
|
} elseif ($viewtype=="detail") {
|
|
echo "
|
|
<table border=\"0\"><tr><td>
|
|
";
|
|
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
|
// determine if this is a member of a group
|
|
$member_qry=mysqli_query($drs_db,"select linkgroup from links where writeupid=\"{$tablerow['id']}\"");
|
|
$is_member=mysqli_num_rows($member_qry);
|
|
if(in_array($tablerow['id'],$group_writeups) || count($s_group)==0) {
|
|
displaywriteup($tablerow['id']);
|
|
echo "<br>";
|
|
}
|
|
}
|
|
echo "
|
|
</td></tr></table>
|
|
";
|
|
}
|
|
}
|
|
} else {
|
|
echo "<b>No writeups match your search parameters.</b><br>";
|
|
}
|
|
}
|
|
if (! $exportcsv) {
|
|
echo "<br>";
|
|
banner($print);
|
|
pageblock("right","end");
|
|
pagetable("end");
|
|
|
|
framework("end","","",$print);
|
|
}
|
|
?>
|