Files
OpenDRS/distfiles/create.php

248 lines
8.3 KiB
PHP

<?php
/*
create.php
OpenDRS Online Discrepancy Reporting System
Copyright (C) 2021 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("common.php");
// redirect to writeups.php on change cancel
if ($_REQUEST['cancel']) {
header("Cache-Control:no-cache, must-revalidate");
header("Pragma:no-cache");
header("Location:writeups.php");
exit();
}
// import session variables
if (isset($_SESSION['personid'])) $personid=$_SESSION['personid'];
// 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
$create=$incoming['create'];
$device=$incoming['device'];
$discovered=$incoming['discovered'];
$functional=$incoming['functional'];
$reported_by=$incoming['reported_by'];
$report_date=$incoming['report_date'];
$report_time=$incoming['report_time'];
$subsystem=$incoming['subsystem'];
$discrepancy_text=$incoming['discrepancy_text'];
$status=$incoming['status'];
// assign variables from constants
$appname=APP_NAME;
if ($print=="Printer Friendly") {
$mbgcolor=P_MENUBG_COLOR;
} else {
$mbgcolor=MENUBG_COLOR;
}
$role=dblookup($drs_db,"persons","id","role",$personid);
framework("begin","$appname","New Writeup",$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");
if (!$report_date || $report_date=="automatic") $report_date=$today;
if (!$report_time || $report_time=="automatic") $report_time=$now;
if ($create) {
// add the entry if create is pressed
if ($discrepancy_text && $reported_by && $device && $subsystem && $discovered) {
// sanitize and fix blank date and time
$report_date=mysqli_real_escape_string($drs_db,$report_date);
$report_time=mysqli_real_escape_string($drs_db,$report_time);
if (!$report_date) $report_date=$today;
if (!$report_time) $report_time=$now;
// remove html tags from discrepancy text and sanitize
$discrepancy_text=strip_tags($discrepancy_text);
$clean_discrepancy_text=mysqli_real_escape_string($drs_db,$discrepancy_text);
$clean_reported_by=mysqli_real_escape_string($drs_db,$reported_by);
// add the record to writeups
mysqli_query($drs_db,"insert into writeups(device,discovered,functional,reported_by,report_date,report_time,subsystem,discrepancy_text,status)
values (\"$device\",\"$discovered\",\"$functional\",\"$clean_reported_by\",\"$report_date\",\"$report_time\",\"$subsystem\",\"$clean_discrepancy_text\",\"$status\")");
}
}
// ******** end database manipulation ********
pagetable("begin");
if (!$print) {
pageblock("left","begin");
sidemenu();
pageblock("left","end");
}
pageblock("right","begin");
banner($print);
echo "<br>";
// display the form
if ($create) {
if ($discrepancy_text && $reported_by) {
format_message(0,"<strong>Writeup created.</strong> You may create another writeup or <a href=\"writeups.php\">return to Open Writeups page.</a>");
$preserve=FALSE;
}
if (!$device) {
format_message(1,"You didn't select a $device_term. Please try again.");
$preserve=TRUE;
}
if (!$subsystem) {
format_message(1,"You didn't select a subsystem. Please try again.");
$preserve=TRUE;
}
if (!$discovered) {
format_message(1,"You didn't select a $discovered_term. Please try again.");
$preserve=TRUE;
}
if (!$discrepancy_text) {
format_message(1,"You didn't enter any discrepancy text. Please try again.");
$preserve=TRUE;
}
if (!$reported_by) {
format_message(1,"You didn't enter your name in the Reported by: block. Please try again.");
$preserve=TRUE;
}
} else {
$preserve=FALSE;
}
echo "
<form method=\"post\" action=\"create.php\">
";
// start writeup entry section
if ($status==1) $statusind="<b><font color=\"#FF0000\">OPEN</font></b>";
if ($status==2) $statusind="<b><font color=\"#008000\">CLSD</font></b>";
if ($status==3) $statusind="<b><font color=\"#FFFF00\">DFRD</font></b>";
echo "
<table border=\"0\" cellpadding=\"5\">
<tr>
<td align=\"left\">$device_term<br>
<select name=\"device\" id=\"device\">
<option value=\"\">Please select...</option>
";
$trow=mysqli_query($drs_db,"select * from devices where active is true order by id asc");
while ($titem=mysqli_fetch_assoc($trow)) {
if ($device==$titem["id"] && $preserve) {
printf("<option value=\"%s\" selected>%s</option>",$titem["id"],$titem["name"]);
} else {
printf("<option value=\"%s\">%s</option>",$titem["id"],$titem["name"]);
}
}
echo "
</select></td>
<td align=\"left\">Subsystem<br>
<select name=\"subsystem\" id=\"subsystem\">
<option value=\"\">Please select...</option>
";
$ssrow=mysqli_query($drs_db,"select * from subsystems where active is true order by id asc");
while ($ssitem=mysqli_fetch_assoc($ssrow)) {
if ($subsystem==$ssitem["id"] && $preserve) {
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></td><td></td>
</tr>
<tr>
<td align=\"left\">$discovered_term<br>
<select name=\"discovered\" id=\"discoveredselect\">
<option value=\"\">Please select...</option>
";
if ($disc_drop_data=="Name") {
$discddtitle="whendiscovereddesc";
$discddtext="whendiscoveredname";
} else if ($disc_drop_data=="Desc") {
$discddtitle="whendiscoveredname";
$discddtext="whendiscovereddesc";
}
$drow=mysqli_query($drs_db,"select * from discovered where active is true order by whendiscoveredname asc");
while ($ditem=mysqli_fetch_assoc($drow)) {
if ($discoverd==$ditem["id"] && $preserve) {
printf("<option value=\"%s\" title=\"%s\" selected>%s</option>",$ditem["id"],$ditem["$discddtitle"],$ditem["$discddtext"]);
} else {
printf("<option value=\"%s\" title=\"%s\">%s</option>",$ditem["id"],$ditem["$discddtitle"],$ditem["$discddtext"]);
}
}
if (!$preserve) {
$report_date="automatic";
$report_time="automatic";
$discrepancy_text="";
$reported_by="";
}
$funcyesstate=$funcnostate="";
if ($preserve) {
if($functional==1) $funcyesstate="checked";
if($functional==0) $funcnostate="checked";
} else {
$funcyesstate="checked";
}
echo "
</select></td>
<td align=\"left\" >Report Date<br>
<input type=\"text\" name=\"report_date\" size=\"10\" maxlength=\"10\" value=\"$report_date\" id=\"singledatepicker\" title=\"Format: YYYY-MM-DD\"></td>
<td align=\"left\">Report Time<br>
<input type=\"text\" name=\"report_time\" size=\"8\" maxlength=\"8\" value=\"$report_time\" title=\"Format: HH:MM:SS\"></td>
</tr>
<tr><td></td><td></td><td></td></tr>
<tr><td colspan=\"3\">
Discrepancy <font size=\"-2\">(required)</font><br>
<textarea rows=\"10\" cols=\"80\" name=\"discrepancy_text\" wrap=\"soft\">$discrepancy_text</textarea><br>
</tr>
<tr>
<td>Reported by <font size=\"-2\">(required)</font><br>
<input type=\"text\" name=\"reported_by\" size=\"30\" value=\"$reported_by\" title=\"Who to contact with questions about this writeup\"></td>
<td>$functional_term? &nbsp; <img src=\"icons/question.png\" title=\"" . FUNCTIONAL_HELP_TXT . "\"><br>
<input type=\"radio\" name=\"functional\" value=\"1\" $funcyesstate> Yes &nbsp;&nbsp;&nbsp;&nbsp;
<input type=\"radio\" name=\"functional\" value=\"0\" $funcnostate> No
</td>
<td align=\"right\" valign=\"bottom\"><input type=\"submit\" name=\"create\" value=\"Submit Writeup\" id=\"createbutton\"></td>
</tr>
<tr><td></td><td></td><td></td></tr>
<td></td><td></td><td align=\"right\" valign=\"bottom\">
<input type=\"submit\" name=\"cancel\" value=\"Cancel\" id=\"usercancelbutton\"></td>
</tr>
</table>
<input type=\"hidden\" name=\"status\" value=\"1\">
</form>
<br>
";
banner($print);
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>