919 lines
39 KiB
PHP
919 lines
39 KiB
PHP
<?php
|
|
/*
|
|
groups.php
|
|
OpenDRS Online Discrepancy Reporting System
|
|
Copyright (C) 2022 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("common.php");
|
|
if (array_key_exists('print',$_REQUEST)) {
|
|
$print=true;
|
|
} else {
|
|
$print=false;
|
|
}
|
|
|
|
// redirect to groups.php on cancel button press
|
|
if (array_key_exists('cancel',$_REQUEST)) {
|
|
header("Cache-Control:no-cache, must-revalidate");
|
|
header("Pragma:no-cache");
|
|
header("Location:groups.php");
|
|
exit();
|
|
}
|
|
|
|
// import session variables
|
|
if (isset($_SESSION['userid'])) {
|
|
$userid=$_SESSION['userid'];
|
|
} else {
|
|
$userid=NULL;
|
|
}
|
|
|
|
// import incoming arrays
|
|
if ($print) {
|
|
// if printer friendly 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 {
|
|
// copy $_REQUEST to $incoming
|
|
$incoming=arrayCopy($_REQUEST);
|
|
}
|
|
|
|
// extract incoming array keys into variables
|
|
extract($incoming, EXTR_SKIP);
|
|
/*
|
|
* possible keys are:
|
|
* action
|
|
* save
|
|
* targets
|
|
* group
|
|
* name
|
|
* search
|
|
* s_status
|
|
* s_device
|
|
* s_subsystem
|
|
* s_discovered
|
|
* s_report_date_start
|
|
* s_report_date_end
|
|
* s_report_time_start
|
|
* s_report_time_end
|
|
* s_discrepancy_text
|
|
* s_reported_by
|
|
* s_functional
|
|
* edit_status
|
|
* edit_action_by
|
|
* edit_action_reason
|
|
* edit_action_date
|
|
* edit_action_time
|
|
* edit_action_text
|
|
*/
|
|
|
|
if (!isset($action)) $action=NULL;
|
|
if (!isset($s_discrepancy_text)) $s_discrepancy_text=NULL;
|
|
if (!isset($s_reported_by)) $s_reported_by=NULL;
|
|
if (!isset($edit_status)) $edit_status=NULL;
|
|
if (!isset($edit_action_by)) $edit_action_by=NULL;
|
|
if (!isset($edit_action_reason)) $edit_action_reason=NULL;
|
|
if (!isset($edit_action_text)) $edit_action_text=NULL;
|
|
if (!isset($save)) $save=false;
|
|
if (!isset($search)) $search=false;
|
|
if (!isset($group)) $group=NULL;
|
|
if (!isset($name)) $name=NULL;
|
|
|
|
|
|
// define local functions
|
|
|
|
|
|
// assign variables from constants
|
|
$appname=APP_NAME;
|
|
|
|
if ($print) {
|
|
$mbgcolor=P_MENUBG_COLOR;
|
|
} else {
|
|
$mbgcolor=MENUBG_COLOR;
|
|
}
|
|
|
|
$role=dblookup($drs_db,"users","id","role",$userid);
|
|
|
|
framework("begin","$appname","Writeup Groups",$print);
|
|
|
|
//echo "_REQUEST array <br>";
|
|
//var_dump($_REQUEST);
|
|
//echo "<br><hr> incoming array <br>";
|
|
//var_dump($incoming);
|
|
|
|
// ******** begin database manipulation ********
|
|
|
|
// determine today's date and make it the default
|
|
$today=date("Y-m-d");
|
|
$now=date("H:i:s");
|
|
|
|
// get max report date from writeups table, validate input dates/times and set defaults
|
|
$maxrepdate_qry=mysqli_query($drs_db,"select max(report_date) from writeups");
|
|
$maxrepdate=mysqli_fetch_row($maxrepdate_qry)[0];
|
|
if (!isset($s_report_date_start) || !validateDate($s_report_date_start)) $s_report_date_start=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
|
if (!isset($s_report_date_end) || !validateDate($s_report_date_end)) $s_report_date_end=$maxrepdate;
|
|
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 (!isset($edit_action_date) || !validateDate($edit_action_date)) $edit_action_date=$today;
|
|
if (!isset($edit_action_time) || !validateTime($edit_action_time)) $edit_action_time=$now;
|
|
|
|
|
|
if ($action=="add" && $role && $save) {
|
|
$fail=false;
|
|
if ($group==NULL) {
|
|
// group was not supplied, so create a new one
|
|
mysqli_query($drs_db,"insert into groups(name) value(\"\")");
|
|
$fail=mysqli_error($drs_db);
|
|
$group=mysqli_insert_id($drs_db);
|
|
}
|
|
foreach ($targets as $target) {
|
|
// add writeup to the group
|
|
if (!mysqli_num_rows(mysqli_query($drs_db,"select id from links where writeupid=\"$target\" and linkgroup=\"$group\""))) {
|
|
// target is not already a member of this group
|
|
mysqli_query($drs_db,"insert into links (linkgroup,writeupid) values($group,$target)");
|
|
$fail=mysqli_error($drs_db);
|
|
}
|
|
}
|
|
} elseif ($action=="remove" && $role && $save) {
|
|
$fail=false;
|
|
$writeups=[];
|
|
$writeups_qry=mysqli_query($drs_db,"select writeupid from links where linkgroup=\"$group\"");
|
|
while ($writeuprow=mysqli_fetch_row($writeups_qry)) {
|
|
$writeups[]=$writeuprow[0];
|
|
}
|
|
foreach ($writeups as $writeup) {
|
|
if (!isset($targets) || !in_array($writeup,$targets)) {
|
|
// remove writeup from group
|
|
mysqli_query($drs_db,"delete from links where writeupid=$writeup and linkgroup=$group");
|
|
$fail=mysqli_error($drs_db);
|
|
}
|
|
}
|
|
// if there are no longer any writeups in this group, dissolve it
|
|
$memb_qty_query=mysqli_query($drs_db,"select id from links where linkgroup=\"$group\"");
|
|
if (mysqli_num_rows($memb_qty_query) == 0) {
|
|
mysqli_query($drs_db,"delete from groups where id=$group");
|
|
$fail=mysqli_error($drs_db);
|
|
}
|
|
} elseif ($action=="dissolve" && $role && $save) {
|
|
$fail=false;
|
|
// unassign all writeups from a group and delete the group
|
|
mysqli_query($drs_db,"delete from links where linkgroup=$group");
|
|
$fail=mysqli_error($drs_db);
|
|
mysqli_query($drs_db,"delete from groups where id=$group");
|
|
$fail=mysqli_error($drs_db);
|
|
} elseif ($action=="setname" && $role && $save) {
|
|
$fail=false;
|
|
// change the name of a group
|
|
// remove html tags from group name and sanitize
|
|
$name=strip_tags($name);
|
|
$clean_name=mysqli_real_escape_string($drs_db,$name);
|
|
mysqli_query($drs_db,"update groups set name=\"$clean_name\" where id=\"$group\"");
|
|
$fail=mysqli_error($drs_db);
|
|
} elseif ($action=="takeaction" && $role && $save) {
|
|
$fail=false;
|
|
// set the status, action by, reason action date/time and append supplied text to action text
|
|
// for all ids in group
|
|
if ($edit_action_reason!=NULL) {
|
|
// sanitize date and time
|
|
$edit_action_date=mysqli_real_escape_string($drs_db,$edit_action_date);
|
|
$edit_action_time=mysqli_real_escape_string($drs_db,$edit_action_time);
|
|
// remove html tags from action text and sanitize
|
|
$edit_action_text=strip_tags($edit_action_text);
|
|
$clean_edit_action_text=mysqli_real_escape_string($drs_db,$edit_action_text);
|
|
// update the group members
|
|
$groupmem_qry=mysqli_query($drs_db,"select writeupid from links where linkgroup=\"$group\"");
|
|
while ($edit_row=mysqli_fetch_row($groupmem_qry)) {
|
|
$writeup_to_edit=$edit_row[0];
|
|
$writeup_action_text=dblookup($drs_db,"writeups","id","action_text",$writeup_to_edit);
|
|
$full_action_text=$writeup_action_text." GROUP ACTION TAKEN: ".$clean_edit_action_text;
|
|
mysqli_query($drs_db,"update writeups set status=\"$edit_status\",action_by=\"$edit_action_by\",action_date=\"$edit_action_date\",action_time=\"$edit_action_time\",action_reason=\"$edit_action_reason\",action_text=\"$full_action_text\" where id=\"$writeup_to_edit\"");
|
|
$fail=mysqli_error($drs_db);
|
|
}
|
|
} else {
|
|
$fail="A status change reason was not selected.";
|
|
}
|
|
}
|
|
if ($search) {
|
|
// strip whitespace from beginning and end of text fields
|
|
$s_reported_by=trim($s_reported_by);
|
|
$s_discrepancy_text=trim($s_discrepancy_text);
|
|
|
|
// build the query string
|
|
$query_string="";
|
|
// device
|
|
if (isset($s_device)) {
|
|
$query_string="{$query_string}(";
|
|
$device_param="Devices:";
|
|
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="Devices: any";
|
|
$query_string=rtrim($query_string," or ");
|
|
$query_string="{$query_string})";
|
|
$query_string="{$query_string} and ";
|
|
}
|
|
// subsystem
|
|
if (isset($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 ";
|
|
}
|
|
// discovered
|
|
if (isset($s_discovered)) {
|
|
$query_string="{$query_string}(";
|
|
$discovered_param="{$discovered_term_short}s:";
|
|
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 (isset($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 (isset($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 ";
|
|
}
|
|
// 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}";
|
|
// discrepancy text
|
|
if (isset($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";
|
|
}
|
|
// reported by
|
|
if (isset($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 report_date asc";
|
|
}
|
|
|
|
// ******** end database manipulation ********
|
|
|
|
pagetable("begin");
|
|
if (!$print) {
|
|
pageblock("left","begin");
|
|
sidemenu();
|
|
pageblock("left","end");
|
|
}
|
|
pageblock("right","begin");
|
|
banner($print);
|
|
echo "<br>";
|
|
|
|
if ($action=="add") {
|
|
if (!isset($targets)) $targets=[];
|
|
if (count($targets) > 1) {
|
|
$plural="s";
|
|
} else {
|
|
$plural="";
|
|
}
|
|
if ($save && !$fail) {
|
|
format_message(0,"<strong>Writeup$plural successfully added.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
|
|
} elseif ($save && $fail) {
|
|
format_message(2,"<strong>An error was encountered when adding writeup$plural.</strong> The error was \" $fail \"");
|
|
}
|
|
if ($save) {
|
|
// show the group
|
|
$mode="view";
|
|
group_detail($group,$role,$mode);
|
|
if ($role) {
|
|
// show buttons
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"add\">
|
|
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
|
|
|
|
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
|
|
|
|
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
|
|
|
|
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
|
|
|
|
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
|
|
</form>
|
|
";
|
|
}
|
|
} else {
|
|
if ($role){
|
|
// show mini search with discrepancy data only
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"add\">
|
|
<b>Search Parameters</b> Enter search terms to find writeups to add to the group.<br>
|
|
<table border=\"0\" cellpadding=\"5\">
|
|
<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\">
|
|
";
|
|
// Device cell *********************
|
|
echo "
|
|
Device<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.\">
|
|
";
|
|
$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["whendiscovereddesc"],$discitem["whendiscoveredname"]);
|
|
} else {
|
|
printf("<option value=\"%s\" title=\"%s\">%s</option>",$discitem["id"],$discitem["whendiscovereddesc"],$discitem["whendiscoveredname"]);
|
|
}
|
|
}
|
|
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>
|
|
</td>
|
|
";
|
|
// **********************************"
|
|
echo "
|
|
<td align=\"right\">
|
|
<input type=\"submit\" name=\"search\" value=\"Find Writeups\">
|
|
</td></tr>
|
|
</table>
|
|
</form>";
|
|
// display the results
|
|
if ($search) {
|
|
$writeup_qry=mysqli_query($drs_db,$query_string);
|
|
if (mysqli_num_rows($writeup_qry)) {
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"add\">
|
|
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
|
<tr>
|
|
<th style=\"width:1%;\">Select</th>
|
|
<th style=\"width:1%;\">ID</th>
|
|
<th style=\"width:1%;\">Status</th>
|
|
<th style=\"width:100px;\">Date</th>
|
|
<th style=\"width:1%;\">Device</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_qry)) {
|
|
// determine functional icon
|
|
if($tablerow["functional"]==1) {
|
|
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes\">";
|
|
} else {
|
|
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no\">";
|
|
}
|
|
|
|
// 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"]);
|
|
$disc_txt="{$tablerow["discrepancy_text"]}";
|
|
// 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 ($is_member) {
|
|
$group_count=$is_member;
|
|
$member_group=mysqli_fetch_row($member_qry)[0];
|
|
$member_group_name=dblookup($drs_db,"groups","id","name",$member_group);
|
|
if ($member_group_name) {
|
|
$imgtitle="Member of group: $member_group_name";
|
|
} else {
|
|
$imgtitle="Member of group ID: $member_group";
|
|
}
|
|
if ($group_count == 1) {
|
|
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php?group=$member_group\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
|
} else {
|
|
$disc_txt=$disc_txt."<div align=\"right\"><a href=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
|
}
|
|
}
|
|
// print table row
|
|
printf(
|
|
"<tr>
|
|
<td align=\"center\" valign=\"top\"><input type=\"checkbox\" name=\"targets[]\" value=\"%s\"></td>
|
|
<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\">%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"],$tablerow["id"],
|
|
$statusind,
|
|
$tablerow["report_date"],
|
|
$dname,
|
|
$tablerow["reported_by"],
|
|
$disc_txt,
|
|
$func_icon
|
|
);
|
|
}
|
|
echo "
|
|
</table>\n
|
|
<br>
|
|
Select the writeups above you'd like to add to the group and
|
|
<button name=\"save\" value=\"save\" type=\"submit\">Save group</button>
|
|
<br><br>
|
|
If nothing looks appropriate, you can modify the search parameters above and search again or select another menu option.
|
|
</form>";
|
|
} else {
|
|
echo "
|
|
<b>No writeups match your search parameters.</b><br><br>
|
|
You can modify the search parameters above and search again or select another menu option.
|
|
";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} elseif ($action=="remove") {
|
|
if ($save && !$fail) {
|
|
format_message(0,"<strong>Group successfully modified.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
|
|
} elseif ($save && $fail) {
|
|
format_message(2,"<strong>An error was encountered when modifying group.</strong> The error was \" $fail \"");
|
|
}
|
|
if ($role && mysqli_num_rows(mysqli_query($drs_db,"select id from links where linkgroup=$group"))) {
|
|
// show group table with everything selected
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"remove\">
|
|
";
|
|
group_detail($group,$role,"select","all");
|
|
echo "
|
|
Deselect the writeups you want to remove from this group. <br><br>
|
|
<b>NOTE:</b> Deselecting them all will dissolve the group.
|
|
<br><br>
|
|
<button name=\"save\" value=\"save\" type=\"submit\">Modify this group</button>
|
|
|
|
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
|
|
</form>
|
|
";
|
|
}
|
|
} elseif ($action=="dissolve") {
|
|
if ($save && !$fail) {
|
|
format_message(0,"<strong>Group dissolved.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
|
|
} elseif ($save && $fail) {
|
|
format_message(2,"<strong>An error was encountered when dissolving the group.</strong> The error was \" $fail \"");
|
|
} else {
|
|
if ($role) {
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"dissolve\">
|
|
<b>NOTE:</b> Dissolving this group will unassign its member writeups and remove the group.<br><br>
|
|
It will not delete any writeups or affect their assignment to other groups.<br><br>
|
|
<button name=\"save\" value=\"save\" type=\"submit\">Dissolve this group</button>
|
|
|
|
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
|
|
</form>
|
|
";
|
|
}
|
|
// show the group
|
|
$mode="view";
|
|
group_detail($group,$role,$mode);
|
|
if ($role) {
|
|
// show buttons
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
|
|
|
|
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
|
|
|
|
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
|
|
|
|
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
|
|
|
|
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
|
|
</form>
|
|
";
|
|
}
|
|
}
|
|
} elseif ($action=="setname") {
|
|
if ($save && !$fail) {
|
|
format_message(0,"<strong>Group name updated.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
|
|
} elseif ($save && $fail) {
|
|
format_message(2,"<strong>An error was encountered when updating the group name.</strong> The error was \" $fail \"");
|
|
}
|
|
if ($role) {
|
|
// get current group name if there is one and show the form
|
|
$curr_name=dblookup($drs_db,"groups","id","name",$group);
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"setname\">
|
|
<input type=\"text\" name=\"name\" size=\"60\" value=\"$curr_name\">
|
|
<button name=\"save\" value=\"save\" type=\"submit\">Update group name</button>
|
|
|
|
<button name=\"cancel\" value=\"cancel\" type=\"submit\">Cancel</button>
|
|
</form>
|
|
";
|
|
}
|
|
// show the group
|
|
$mode="view";
|
|
group_detail($group,$role,$mode);
|
|
if ($role) {
|
|
// show buttons
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
|
|
|
|
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
|
|
|
|
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
|
|
|
|
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
|
|
|
|
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
|
|
</form>
|
|
";
|
|
}
|
|
} elseif ($action=="takeaction") {
|
|
if ($save && !$fail) {
|
|
format_message(0,"<strong>Group action completed.</strong> <a href=\"groups.php\">Return to Writeup Groups page.</a>");
|
|
} elseif ($save && $fail) {
|
|
format_message(2,"<strong>An error was encountered when taking group action.</strong> The error was \" $fail \"");
|
|
}
|
|
// show the group
|
|
$mode="view";
|
|
group_detail($group,$role,$mode);
|
|
if ($role && ! $save) {
|
|
// show action form
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<input type=\"hidden\" name=\"action\" value=\"takeaction\">
|
|
<table border=\"0\" cellpadding=\"5\" width=\"600\">
|
|
<tr>
|
|
<td>Status<br>
|
|
<select name=\"edit_status\" id=\"status\">
|
|
<option value=\"1\">OPEN</option>
|
|
<option value=\"2\"selected>CLOSED</option>
|
|
<option value=\"3\">DEFERRED</option>
|
|
</select>
|
|
</td>
|
|
<td>Action taken by<br>
|
|
";
|
|
if ($role==ADMIN) {
|
|
// allow selection of tech name
|
|
echo "
|
|
<select name=\"edit_action_by\" id=\"user\">
|
|
";
|
|
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users where active is true order by lastname asc");
|
|
while ($persitem=mysqli_fetch_assoc($persrow)) {
|
|
if ($userid==$persitem["id"]) {
|
|
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>
|
|
";
|
|
} else {
|
|
// limit the choice to the tech in question
|
|
echo "
|
|
<select name=\"edit_action_by\" id=\"user\">
|
|
";
|
|
$persrow=mysqli_query($drs_db,"select id,firstname,lastname from users where active is true order by lastname asc");
|
|
while ($persitem=mysqli_fetch_assoc($persrow)) {
|
|
if ($userid==$persitem["id"]) {
|
|
printf("<option value=\"%s\" selected>%s %s</option>",$persitem["id"],$persitem["firstname"],$persitem["lastname"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
";
|
|
}
|
|
echo "
|
|
</td>
|
|
<td>Status change reason<br>
|
|
<select name=\"edit_action_reason\" id=\"reason\">
|
|
";
|
|
$reasrow=mysqli_query($drs_db,"select id,text from reasons where active is true order by id asc");
|
|
if ($edit_action_reason==NULL) echo "<option selected></option>";
|
|
while ($reasitem=mysqli_fetch_assoc($reasrow)) {
|
|
if ($edit_action_reason==$reasitem["id"]) {
|
|
printf("<option value=\"%s\" selected>%s</option>",$reasitem["id"],$reasitem["text"]);
|
|
} else {
|
|
printf("<option value=\"%s\">%s</option>",$reasitem["id"],$reasitem["text"]);
|
|
}
|
|
}
|
|
echo "
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr><td></td><td></td><td></td></tr>
|
|
<tr><td colspan=\"3\">
|
|
Action Taken <font size=\"-2\">(required)</font><br>
|
|
<textarea rows=\"10\" cols=\"80\" name=\"edit_action_text\" wrap=\"soft\"></textarea><br>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align=\"left\" >Action Taken Date<br>
|
|
<input type=\"text\" name=\"edit_action_date\" size=\"10\" maxlength=\"10\" value=\"$today\" id=\"actiondatepicker\" title=\"Format: YYYY-MM-DD\"></td>
|
|
<td align=\"left\">Action Taken Time<br>
|
|
<input type=\"text\" name=\"edit_action_time\" size=\"8\" maxlength=\"8\" value=\"$now\" title=\"Format: HH:MM:SS\"></td>
|
|
<td align=\"right\" valign=\"bottom\"><button type=\"submit\" name=\"save\" value=\"save\">Save action</button></td>
|
|
</tr>
|
|
<tr>
|
|
<td align=\"left\" valign=\"bottom\">
|
|
<td></td><td align=\"right\" valign=\"bottom\">
|
|
<input type=\"submit\" name=\"cancel\" value=\"Cancel Changes\"></td>
|
|
</tr>
|
|
</table>
|
|
</form>
|
|
";
|
|
}
|
|
} else {
|
|
if ($role) {
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<button name=\"action\" value=\"add\" type=\"submit\">Create a new group</button>
|
|
</form>
|
|
<hr>
|
|
";
|
|
}
|
|
if ($group!=NULL) {
|
|
// show only the requested group
|
|
$mode="view";
|
|
group_detail($group,$role,$mode);
|
|
if ($role) {
|
|
// show buttons
|
|
echo "
|
|
<form method=post action=\"groups.php\">
|
|
<input type=\"hidden\" name=\"group\" value=\"$group\">
|
|
<button name=\"action\" value=\"add\" type=\"submit\">Add writeups to this group</button>
|
|
|
|
<button name=\"action\" value=\"remove\" type=\"submit\">Remove writeups from this group</button>
|
|
|
|
<button name=\"action\" value=\"dissolve\" type=\"submit\">Dissolve this group</button>
|
|
|
|
<button name=\"action\" value=\"setname\" type=\"submit\">Set name for this group</button>
|
|
|
|
<button name=\"action\" value=\"takeaction\" type=\"submit\">Take group action</button>
|
|
</form>
|
|
";
|
|
}
|
|
echo "<hr><br>";
|
|
} else {
|
|
// show group table
|
|
$groups_qry=mysqli_query($drs_db,"select * from groups");
|
|
if (mysqli_num_rows($groups_qry)) {
|
|
echo "
|
|
<br><br>
|
|
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
|
<tr>
|
|
<th style=\"width:1%;\">ID</th>
|
|
<th>Name</th>
|
|
<th style=\"width:1%;\">Writeups assigned</th>
|
|
</tr>
|
|
";
|
|
while ($grouprow=mysqli_fetch_assoc($groups_qry)) {
|
|
$num_query=mysqli_query($drs_db,"select id from links where linkgroup={$grouprow['id']}");
|
|
$num_writeups=mysqli_num_rows($num_query);
|
|
if($grouprow['name']=="") {
|
|
$name_text="Group {$grouprow['id']} has not been named";
|
|
} else {
|
|
$name_text="{$grouprow['name']}";
|
|
}
|
|
// print table row
|
|
printf(
|
|
"<tr>
|
|
<td align=\"center\" valign=\"top\"><a href=\"groups.php?group=%s\" title=\"View or change details of this group\">%s</a></td>
|
|
<td valign=\"top\">%s</td>
|
|
<td align=\"center\" valign=\"top\">%s</td>
|
|
</tr>\n",
|
|
$grouprow["id"],$grouprow["id"],
|
|
$name_text,
|
|
$num_writeups
|
|
);
|
|
}
|
|
echo "</table><br>";
|
|
} else {
|
|
echo "<br>No writeup groups were found.<br><br><br>";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
echo "<br>";
|
|
banner($print);
|
|
pageblock("right","end");
|
|
pagetable("end");
|
|
|
|
framework("end","","",$print);
|
|
|
|
?>
|