Initial commit as release 1.1.0
This commit is contained in:
422
distfiles/writeups.php
Normal file
422
distfiles/writeups.php
Normal file
@@ -0,0 +1,422 @@
|
||||
<?php
|
||||
/*
|
||||
writeups.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2018 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("common.php");
|
||||
|
||||
// import session variables
|
||||
if (isset($_SESSION['userid'])) $userid=$_SESSION['userid'];
|
||||
|
||||
// import incoming arrays
|
||||
$print=$_REQUEST['print'];
|
||||
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);
|
||||
}
|
||||
|
||||
// load variables from incoming array
|
||||
|
||||
$view=$incoming['view'];
|
||||
$start_date=$incoming['start_date'];
|
||||
$end_date=$incoming['end_date'];
|
||||
$showtoday=$incoming['showtoday'];
|
||||
$showyesterday=$incoming['showyesterday'];
|
||||
$show7day=$incoming['show7day'];
|
||||
$show30day=$incoming['show30day'];
|
||||
$viewtype=$incoming['viewtype'];
|
||||
|
||||
$togroup=$incoming['togroup'];
|
||||
$addtogroup=$incoming['addtogroup'];
|
||||
$selectedids=$incoming['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($start_date,$end_date,$print,$drs_db,$viewtype="summary") {
|
||||
// show date range selector
|
||||
echo "
|
||||
<form method=post action=\"writeups.php\">
|
||||
";
|
||||
if ($print) {
|
||||
echo "
|
||||
<form method=post action=\"writeups.php\">
|
||||
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,period 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%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
}
|
||||
|
||||
// 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 times for period
|
||||
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$tablerow['period']}\""))[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=\"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\"><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\">%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"],
|
||||
$ptimes, $tablerow["period"],
|
||||
$dname,
|
||||
$ssname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
);
|
||||
}
|
||||
echo "</table>\n";
|
||||
} else {
|
||||
if ($_REQUEST['showyesterday']) {
|
||||
$datespec="yesterday";
|
||||
} elseif ($_REQUEST['show7day']) {
|
||||
$datespec="the last 7 days";
|
||||
} elseif ($_REQUEST['show30day']) {
|
||||
$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) {
|
||||
// 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\">
|
||||
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\">
|
||||
";
|
||||
if(!$print) {
|
||||
echo "
|
||||
<input type=\"submit\" name=\"update\" value=\"Update\">
|
||||
<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>
|
||||
<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>";
|
||||
}
|
||||
$writeup=mysqli_query($drs_db,"select * from writeups where report_date between \"$start_date\" and \"$end_date\" order by report_date desc,period 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%;\">Period</th>
|
||||
<th style=\"width:1%;\">Device</th>
|
||||
<th style=\"width:1%;\">Subsystem</th>
|
||||
<th style=\"width:1%;\">Reported by</th>
|
||||
<th>Discrepancy</th>
|
||||
<th style=\"width:1%;\">Msn Eff</th>
|
||||
</tr>
|
||||
";
|
||||
while ($tablerow = mysqli_fetch_assoc($writeup)) {
|
||||
// determine effective icon
|
||||
if($tablerow["period_effective"]==1) {
|
||||
$eff_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"Period Effective\" alt=\"Period Effective\">";
|
||||
} else {
|
||||
$eff_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"Period Non-effective\" alt=\"Period Non-effective\">";
|
||||
}
|
||||
|
||||
// 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 times for period
|
||||
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$tablerow['period']}\""))[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=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></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"],
|
||||
$ptimes, $tablerow["period"],
|
||||
$dname,
|
||||
$ssname,
|
||||
$tablerow["reported_by"],
|
||||
$disc_txt,
|
||||
$eff_icon
|
||||
);
|
||||
}
|
||||
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>
|
||||
<button name=\"addtogroup\" value=\"addtogroup\" type=\"submit\">Add selected to group:</button> <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)) {
|
||||
printf("<option value=\"%s\">%s</option>",$tgitem["id"],$tgitem["name"]);
|
||||
}
|
||||
echo "
|
||||
</select>
|
||||
";
|
||||
}
|
||||
} 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 ($start_date=="") $start_date=$today;
|
||||
if ($end_date=="") $end_date=$today;
|
||||
if ($showtoday) {
|
||||
$start_date=$today;
|
||||
$end_date=$today;
|
||||
}
|
||||
if ($showyesterday) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 1 day)"))[0];
|
||||
$end_date=$start_date;
|
||||
}
|
||||
if ($show7day) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 7 day)"))[0];
|
||||
$end_date=$today;
|
||||
}
|
||||
if ($show30day) {
|
||||
$start_date=mysqli_fetch_row(mysqli_query($drs_db,"select date_sub(curdate(),interval 30 day)"))[0];
|
||||
$end_date=$today;
|
||||
}
|
||||
|
||||
if ($view) {
|
||||
$pgtitle="Recent Writeups";
|
||||
} else {
|
||||
$pgtitle="Open Writeups";
|
||||
}
|
||||
framework("begin","$appname",$pgtitle,$print);
|
||||
|
||||
//var_dump($_REQUEST);
|
||||
//var_dump($incoming);
|
||||
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
|
||||
if ($addtogroup && $togroup && $selectedids && $role) {
|
||||
$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 ($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 (!$viewtype) $viewtype="summary";
|
||||
|
||||
if ($view==1) {
|
||||
// show writeup table
|
||||
viewtable($start_date,$end_date,$print,$drs_db,$viewtype,$role);
|
||||
} else {
|
||||
// show open table
|
||||
opentable($start_date,$end_date,$print,$drs_db,$viewtype);
|
||||
}
|
||||
|
||||
echo "<br>";
|
||||
banner($print);
|
||||
pageblock("right","end");
|
||||
pagetable("end");
|
||||
|
||||
framework("end","","",$print);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user