470 lines
18 KiB
PHP
470 lines
18 KiB
PHP
<?php
|
|
/*
|
|
writeups.php
|
|
OpenDRS Online Discrepancy Reporting System
|
|
Copyright (C) 2023 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("common.php");
|
|
if (array_key_exists('print',$_REQUEST)) {
|
|
$print=true;
|
|
} else {
|
|
$print=false;
|
|
}
|
|
|
|
// 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:
|
|
*
|
|
* view
|
|
* start_date
|
|
* end_date
|
|
* showtoday
|
|
* showyesterday
|
|
* show7day
|
|
* show30day
|
|
* viewtype
|
|
* togroup
|
|
* addtogroup
|
|
* selectedids
|
|
*/
|
|
|
|
|
|
// 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);
|
|
|
|
// define local functions
|
|
function opentable($incoming,$start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
|
// grab some important global variables
|
|
global $device_term;
|
|
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
|
global $functional_term, $functional_term_short;
|
|
global $functional_yes, $functional_no;
|
|
global $functional_yes_short, $functional_no_short;
|
|
|
|
// show date range selector
|
|
echo "
|
|
<form method=post action=\"writeups.php\">
|
|
";
|
|
if ($print) {
|
|
echo "
|
|
Open writeups between $start_date and $end_date
|
|
";
|
|
} else {
|
|
echo "
|
|
<input type=\"submit\" name=\"showtoday\" value=\"Today\">
|
|
<input type=\"submit\" name=\"showyesterday\" value=\"Yesterday\">
|
|
<input type=\"submit\" name=\"show7day\" value=\"Last 7 Days\">
|
|
<input type=\"submit\" name=\"show30day\" value=\"Last 30 Days\"><br><br>
|
|
";
|
|
}
|
|
echo "
|
|
</form>
|
|
";
|
|
$writeup=mysqli_query($drs_db,"select * from writeups where status=".STAT_OPEN." and report_date between \"$start_date\" and \"$end_date\" order by report_date desc,report_time desc");
|
|
if (mysqli_num_rows($writeup)) {
|
|
$now=date("H:i l");
|
|
echo "
|
|
<font color=\"red\">As of $now</font> <font size=\"-1\">Newest at top</font><br>
|
|
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
|
<tr>
|
|
<th style=\"width:1%;\">ID</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 effective icon
|
|
if($tablerow["functional"]==1) {
|
|
$funcind="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
|
} else {
|
|
$funcind="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
|
}
|
|
|
|
// convert device number to name
|
|
$dname=dblookup($drs_db,"devices","id","name",$tablerow["device"]);
|
|
|
|
// convert subsystem number to name
|
|
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
|
|
|
// convert subsystem number to description
|
|
$ssdesc=dblookup($drs_db,"subsystems","id","description",$tablerow["subsystem"]);
|
|
|
|
// determine values for when discovered
|
|
$whendiscdesc=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscovereddesc from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
|
$whendiscname=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscoveredname from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
|
|
|
$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=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
|
}
|
|
}
|
|
|
|
// 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\"><font title=\"%s\">%s</font></td>
|
|
<td valign=\"top\">%s</td>
|
|
<td valign=\"top\"><font title=\"%s\">%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["report_date"],
|
|
$whendiscdesc, $whendiscname,
|
|
$dname,
|
|
$ssdesc, $ssname,
|
|
$tablerow["reported_by"],
|
|
$disc_txt,
|
|
$funcind
|
|
);
|
|
}
|
|
echo "</table>\n";
|
|
} else {
|
|
if (array_key_exists('showyesterday',$incoming)) {
|
|
$datespec="yesterday";
|
|
} elseif (array_key_exists('show7day',$incoming)) {
|
|
$datespec="the last 7 days";
|
|
} elseif (array_key_exists('show30day',$incoming)) {
|
|
$datespec="the last 30 days";
|
|
} else {
|
|
$datespec="today";
|
|
}
|
|
echo "<b>No open writeups for $datespec.</b>";
|
|
}
|
|
}
|
|
|
|
function viewtable($start_date,$end_date,$print,$drs_db,$viewtype="summary",$role) {
|
|
// grab some important global variables
|
|
global $device_term;
|
|
global $discovered_term, $discovered_term_short, $disc_drop_data;
|
|
global $functional_term, $functional_term_short;
|
|
global $functional_yes, $functional_no;
|
|
global $functional_yes_short, $functional_no_short;
|
|
|
|
// show date range selector
|
|
$summarystat=$detailstat="";
|
|
if ($viewtype=="detail") {
|
|
$detailstat="checked";
|
|
} else {
|
|
$summarystat="checked";
|
|
}
|
|
echo "
|
|
<form method=post action=\"writeups.php\">
|
|
<input type=\"hidden\" name=\"view\" value=\"1\">
|
|
";
|
|
if(!$print) {
|
|
echo "
|
|
<input type=\"submit\" name=\"showtoday\" value=\"Today\">
|
|
<input type=\"submit\" name=\"showyesterday\" value=\"Yesterday\">
|
|
<input type=\"submit\" name=\"show7day\" value=\"Last 7 Days\">
|
|
<input type=\"submit\" name=\"show30day\" value=\"Last 30 Days\">
|
|
";
|
|
}
|
|
echo "
|
|
Writeups between
|
|
<input type=\"text\" name=\"start_date\" size=\"10\" value=\"$start_date\" id=\"startdatepicker\" title=\"Format: YYYY-MM-DD\"> and
|
|
<input type=\"text\" name=\"end_date\" size=\"10\" value=\"$end_date\" id=\"enddatepicker\" title=\"Format: YYYY-MM-DD\"><br><br>
|
|
";
|
|
if(!$print) {
|
|
echo "
|
|
<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>
|
|
<input type=\"submit\" name=\"update\" value=\"Update\">
|
|
<br><br>
|
|
";
|
|
}
|
|
$writeup=mysqli_query($drs_db,"select * from writeups where report_date between \"$start_date\" and \"$end_date\" order by report_date desc,report_time desc");
|
|
if (mysqli_num_rows($writeup)) {
|
|
$now=date("H:i l");
|
|
if ($viewtype == "summary") {
|
|
if ($role) {
|
|
$selcol="<th style=\"width:1%;\">Sel</th>";
|
|
} else {
|
|
$selcol="";
|
|
}
|
|
echo "
|
|
<font color=\"red\">As of $now</font> <font size=\"-1\">Newest at top</font><br>
|
|
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
|
<tr>
|
|
$selcol
|
|
<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 effective icon
|
|
if($tablerow["functional"]==1) {
|
|
$funcind="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
|
} else {
|
|
$funcind="<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 subsystem number to name
|
|
$ssname=dblookup($drs_db,"subsystems","id","name",$tablerow["subsystem"]);
|
|
|
|
// determine values for when discovered
|
|
$whendiscdesc=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscovereddesc from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
|
$whendiscname=mysqli_fetch_row(mysqli_query($drs_db,"select whendiscoveredname from discovered where id=\"{$tablerow['discovered']}\""))[0];
|
|
|
|
$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=\"writeupdetail.php?id={$tablerow['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
|
}
|
|
}
|
|
|
|
// print table row
|
|
if ($role) {
|
|
$selcontent="<td align=\"center\" valign=\"top\"><input type=\"checkbox\" name=\"selectedids[]\" value={$tablerow['id']}></td>";
|
|
} else {
|
|
$selcontent="";
|
|
}
|
|
printf(
|
|
"<tr>
|
|
%s
|
|
<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",
|
|
$selcontent,
|
|
$tablerow["id"],$tablerow["id"],
|
|
$statusind,
|
|
$tablerow["report_date"],
|
|
$whendiscdesc, $whendiscname,
|
|
$dname,
|
|
$ssname,
|
|
$tablerow["reported_by"],
|
|
$disc_txt,
|
|
$funcind
|
|
);
|
|
}
|
|
echo "</table>\n";
|
|
} elseif ($viewtype == "detail") {
|
|
echo "
|
|
<font color=\"red\">As of $now</font> <font size=\"-1\">Newest at top</font><br><br>
|
|
<table border=\"0\"><tr><td>
|
|
";
|
|
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
|
if ($role) echo "<input type=\"checkbox\" name=\"selectedids[]\" value={$tablerow['id']}> Select";
|
|
displaywriteup($tablerow['id']);
|
|
echo "<br><br>";
|
|
}
|
|
echo "
|
|
</td></tr></table>
|
|
";
|
|
}
|
|
if ($role) {
|
|
echo "
|
|
<br><br>
|
|
Add selected to group: <select name=\"togroup\" id=\"sel-togroup\">
|
|
<option value=\"newgroup\">New group</option>
|
|
";
|
|
$tgrow=mysqli_query($drs_db,"select id,name from groups order by id asc");
|
|
while ($tgitem=mysqli_fetch_assoc($tgrow)) {
|
|
if($tgitem["name"]=="") {
|
|
$tgname="Group ".$tgitem["id"];
|
|
} else {
|
|
$tgname=$tgitem["name"];
|
|
}
|
|
printf("<option value=\"%s\">%s</option>",$tgitem["id"],$tgname);
|
|
}
|
|
echo "
|
|
</select>
|
|
<button name=\"addtogroup\" value=\"addtogroup\" type=\"submit\">Submit</button>
|
|
";
|
|
}
|
|
} else {
|
|
echo "<b>No writeups for the date range specified above.</b>";
|
|
}
|
|
echo "
|
|
</form>
|
|
";
|
|
}
|
|
|
|
// use default date values if not supplied
|
|
$today = date("Y-m-d");
|
|
if (!isset($start_date)) $start_date=$today;
|
|
if (!isset($end_date)) $end_date=$today;
|
|
if (isset($showtoday)) {
|
|
$start_date=$today;
|
|
$end_date=$today;
|
|
}
|
|
if (isset($showyesterday)) {
|
|
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 1 day)"))[0];
|
|
$end_date=$start_date;
|
|
}
|
|
if (isset($show7day)) {
|
|
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 7 day)"))[0];
|
|
$end_date=$today;
|
|
}
|
|
if (isset($show30day)) {
|
|
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
|
$end_date=$today;
|
|
}
|
|
|
|
if (isset($view)) {
|
|
$pgtitle="Recent Writeups";
|
|
} else {
|
|
$pgtitle="Open Writeups";
|
|
}
|
|
|
|
framework("begin","$appname",$pgtitle,$print);
|
|
|
|
//echo "_REQUEST array <br>";
|
|
//var_dump($_REQUEST);
|
|
//echo "<br><hr> incoming array <br>";
|
|
//var_dump($incoming);
|
|
|
|
|
|
// ******** begin database manipulation ********
|
|
|
|
if (isset($addtogroup) && isset($togroup) && isset($selectedids) && $role!=NULL) {
|
|
$fail=false;
|
|
if ($togroup=="newgroup") {
|
|
// Create a new group
|
|
mysqli_query($drs_db,"insert into groups(name) value(\"\")");
|
|
$fail=mysqli_error($drs_db);
|
|
$togroup=mysqli_insert_id($drs_db);
|
|
}
|
|
foreach ($selectedids as $selid) {
|
|
// add writeup to the group
|
|
if (!mysqli_num_rows(mysqli_query($drs_db,"select id from links where writeupid=\"$selid\" and linkgroup=\"$togroup\""))) {
|
|
// target is not already a member of this group
|
|
mysqli_query($drs_db,"insert into links (linkgroup,writeupid) values($togroup,$selid)");
|
|
$fail=mysqli_error($drs_db);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ******** end database manipulation ********
|
|
|
|
pagetable("begin");
|
|
if(!$print) {
|
|
pageblock("left","begin");
|
|
sidemenu();
|
|
echo "<br><br>";
|
|
pageblock("left","end");
|
|
}
|
|
pageblock("right","begin");
|
|
banner($print);
|
|
echo "<br>";
|
|
|
|
if (isset($addtogroup)) {
|
|
if (count($selectedids) > 1) {
|
|
$plural="s";
|
|
} else {
|
|
$plural="";
|
|
}
|
|
if (!$fail) {
|
|
format_message(0,"<strong>Writeup$plural successfully added to group.</strong>");
|
|
} else {
|
|
format_message(2,"<strong>An error was encountered when adding writeup$plural.</strong> The error was \" $fail \"");
|
|
}
|
|
}
|
|
if (!isset($viewtype)) $viewtype="summary";
|
|
|
|
if (isset($view)) {
|
|
// show writeup table
|
|
viewtable($start_date,$end_date,$print,$drs_db,$viewtype,$role);
|
|
} else {
|
|
// show open table
|
|
opentable($incoming,$start_date,$end_date,$print,$drs_db,$viewtype);
|
|
}
|
|
|
|
echo "<br>";
|
|
banner($print);
|
|
pageblock("right","end");
|
|
pagetable("end");
|
|
|
|
framework("end","","",$print);
|
|
|
|
?>
|