Incorporate changes for 1.2.0
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
dbadmin.php
|
||||
OpenDRS Online Discrepancy Reporting System
|
||||
Copyright (C) 2020 Rod Wright
|
||||
Copyright (C) 2021 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
@@ -79,13 +79,14 @@ $reason_id=$incoming['reason_id'];
|
||||
$reason_text=$incoming['reason_text'];
|
||||
$reason_active=$incoming['reason_active'];
|
||||
|
||||
$edit_period=$incoming['edit_period'];
|
||||
$add_period=$incoming['add_period'];
|
||||
$update_period=$incoming['update_period'];
|
||||
$delete_period=$incoming['delete_period'];
|
||||
$period_id=$incoming['period_id'];
|
||||
$period_times=$incoming['period_times'];
|
||||
$period_active=$incoming['period_active'];
|
||||
$edit_discovered=$incoming['edit_discovered'];
|
||||
$add_discovered=$incoming['add_discovered'];
|
||||
$update_discovered=$incoming['update_discovered'];
|
||||
$delete_discovered=$incoming['delete_discovered'];
|
||||
$discovered_id=$incoming['discovered_id'];
|
||||
$discovered_name=$incoming['discovered_name'];
|
||||
$discovered_desc=$incoming['discovered_desc'];
|
||||
$discovered_active=$incoming['discovered_active'];
|
||||
|
||||
// define local functions
|
||||
|
||||
@@ -101,7 +102,9 @@ if ($print=="Printer Friendly") {
|
||||
|
||||
framework("begin","$appname","Database Administration",$print);
|
||||
|
||||
//echo "_REQUEST array <br>";
|
||||
//var_dump($_REQUEST);
|
||||
//echo "<br><hr> incoming array <br>";
|
||||
//var_dump($incoming);
|
||||
|
||||
// ******** begin database manipulation ********
|
||||
@@ -526,102 +529,118 @@ if ($edit_reason) {
|
||||
}
|
||||
}
|
||||
|
||||
// periods-----------------------------------
|
||||
if ($add_period) {
|
||||
// when discovered-----------------------------------
|
||||
if ($add_discovered) {
|
||||
// do error checking
|
||||
// remove html tags from id and times
|
||||
$period_id=strip_tags($period_id);
|
||||
$period_times=strip_tags($period_times);
|
||||
// test for id supplied
|
||||
if (strlen(trim($period_id))) {
|
||||
$peridsuppld=true;
|
||||
// remove html tags from name and description
|
||||
$discovered_name=strip_tags($discovered_name);
|
||||
$discovered_desc=strip_tags($discovered_desc);
|
||||
// test for name supplied
|
||||
if (strlen(trim($discovered_name))) {
|
||||
$discnamesuppld=true;
|
||||
} else {
|
||||
$peridsuppld=false;
|
||||
$peridsuppld_err=true;
|
||||
$discnamesuppld=false;
|
||||
$discnamesuppld_err=true;
|
||||
}
|
||||
// test for id is integer
|
||||
if (preg_match('/^[0-9]+$/',$period_id)) {
|
||||
$peridisint=true;
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\""))) {
|
||||
$discnameunique=false;
|
||||
$discnameunique_err=true;
|
||||
} else {
|
||||
$peridisint=false;
|
||||
$peridisint_err=true;
|
||||
$discnameunique=true;
|
||||
}
|
||||
// test for id unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where id=\"$period_id\""))) {
|
||||
$peridunique=false;
|
||||
$peridunique_err=true;
|
||||
// test for description supplied
|
||||
if (strlen(trim($discovered_desc))) {
|
||||
$discdescsuppld=true;
|
||||
} else {
|
||||
$peridunique=true;
|
||||
$discdescsuppld=false;
|
||||
$discdescsuppld_err=true;
|
||||
}
|
||||
// test for times supplied
|
||||
if (strlen(trim($period_times))) {
|
||||
$pertimessuppld=true;
|
||||
// test for description unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from description where whendiscovereddesc =\"$discovered_desc\""))) {
|
||||
$discdescunique=false;
|
||||
$discdescunique_err=true;
|
||||
} else {
|
||||
$pertimessuppld=false;
|
||||
$pertimessuppld_err=true;
|
||||
}
|
||||
// test for times unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\""))) {
|
||||
$pertimesunique=false;
|
||||
$pertimesunique_err=true;
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
$discdescunique=true;
|
||||
}
|
||||
|
||||
// set active status
|
||||
if (!$period_active) $period_active=0;
|
||||
if (!$discovered_active) $discovered_active=0;
|
||||
|
||||
if ($pertimessuppld && $pertimesunique && $peridsuppld && $peridunique && $peridisint) {
|
||||
// sanitize times
|
||||
$clean_pertimes=mysqli_real_escape_string($drs_db,$period_times);
|
||||
if ($discnamesuppld && $discnameunique && $discdescsuppld) {
|
||||
// sanitize name
|
||||
$clean_discovered_name=mysqli_real_escape_string($drs_db,$discovered_name);
|
||||
// sanitize description
|
||||
$clean_discovered_desc=mysqli_real_escape_string($drs_db,$discovered_desc);
|
||||
// modify the table
|
||||
mysqli_query($drs_db,"insert into periods(id,times,active) values(\"$period_id\",\"$clean_pertimes\",\"$period_active\")");
|
||||
mysqli_query($drs_db,"insert into discovered(whendiscoveredname,whendiscovereddesc,active) values(\"$clean_discovered_name\",\"$clean_discovered_desc\",\"$discovered_active\")");
|
||||
} else {
|
||||
$period_add_fail=true;
|
||||
$discovered_add_fail=true;
|
||||
}
|
||||
}
|
||||
if ($edit_period) {
|
||||
if ($delete_period) {
|
||||
// check for writeups with this period
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from writeups where period=\"$period_id\""))) {
|
||||
$perhaswriteups=true;
|
||||
$perhaswriteups_err=true;
|
||||
if ($edit_discovered) {
|
||||
if ($delete_discovered) {
|
||||
// check for writeups with this when discovered
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from writeups where discovered=\"$discovered_id\""))) {
|
||||
$dischaswriteups=true;
|
||||
$dischaswriteups_err=true;
|
||||
} else {
|
||||
$perhaswriteups=false;
|
||||
$dischaswriteups=false;
|
||||
}
|
||||
// if none, then remove from db
|
||||
if (!$perhaswriteups) mysqli_query($drs_db,"delete from periods where id=\"$period_id\"");
|
||||
if (!$dischaswriteups) mysqli_query($drs_db,"delete from discovered where id=\"$discovered_id\"");
|
||||
}
|
||||
if ($update_period) {
|
||||
if ($update_discovered) {
|
||||
// do error checking
|
||||
// remove html tags from times
|
||||
$period_times=strip_tags($period_times);
|
||||
// test for times supplied
|
||||
if (strlen(trim($period_times))) {
|
||||
$pertimessuppld=true;
|
||||
} else {
|
||||
$pertimessuppld=false;
|
||||
$pertimessuppld_err=true;
|
||||
}
|
||||
// test for period times unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\" and id!=\"$period_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from periods where times=\"$period_times\""))) {
|
||||
$pertimesunique=false;
|
||||
$pertimesunique_err=true;
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
}
|
||||
} else {
|
||||
$pertimesunique=true;
|
||||
}
|
||||
|
||||
// remove html tags from name and description
|
||||
$discovered_name=strip_tags($discovered_name);
|
||||
$discovered_desc=strip_tags($discovered_desc);
|
||||
// test for name supplied
|
||||
if (strlen(trim($discovered_name))) {
|
||||
$discnamesuppld=true;
|
||||
} else {
|
||||
$discnamesuppld=false;
|
||||
$discnamesuppld_err=true;
|
||||
}
|
||||
// test for name unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\" and id!=\"$discovered_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscoveredname=\"$discovered_name\""))) {
|
||||
$discnameunique=false;
|
||||
$discnameunique_err=true;
|
||||
} else {
|
||||
$discnameunique=true;
|
||||
}
|
||||
} else {
|
||||
$discnameunique=true;
|
||||
}
|
||||
// test for description supplied
|
||||
if (strlen(trim($discovered_desc))) {
|
||||
$discdescsuppld=true;
|
||||
} else {
|
||||
$discdescsuppld=false;
|
||||
$discdescsuppld_err=true;
|
||||
}
|
||||
// test for description unique
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscovereddesc=\"$discovered_text\" and id!=\"$discovered_id\""))) {
|
||||
if (mysqli_num_rows(mysqli_query($drs_db,"select id from discovered where whendiscovereddesc =\"$discovered_desc\""))) {
|
||||
$discdescunique=false;
|
||||
$discdescunique_err=true;
|
||||
} else {
|
||||
$discdescunique=true;
|
||||
}
|
||||
} else {
|
||||
$discdescunique=true;
|
||||
}
|
||||
// set active status
|
||||
if (!$period_active) $period_active=0;
|
||||
if (!$discovered_active) $discovered_active=0;
|
||||
|
||||
// sanitize times
|
||||
$clean_pertimes=mysqli_real_escape_string($drs_db,$period_times);
|
||||
$updqry="update periods set times=\"$clean_pertimes\",active=\"$period_active\" where id=\"$period_id\"";
|
||||
if ($pertimessuppld && $pertimesunique) {
|
||||
// sanitize name
|
||||
$clean_discovered_name=mysqli_real_escape_string($drs_db,$discovered_name);
|
||||
// sanitize description
|
||||
$clean_discovered_desc=mysqli_real_escape_string($drs_db,$discovered_desc);
|
||||
|
||||
$updqry="update discovered set whendiscoveredname=\"$clean_discovered_name\",whendiscovereddesc=\"$clean_discovered_desc\",active=\"$discovered_active\" where id=\"$discovered_id\"";
|
||||
if ($discnamesuppld && $discnameunique && $discdescsuppld && $discdescunique) {
|
||||
// modify the table
|
||||
mysqli_query($drs_db,$updqry);
|
||||
}
|
||||
@@ -646,7 +665,7 @@ echo "
|
||||
<li><a href=\"#devices\">Device Management</a></li>
|
||||
<li><a href=\"#subsystems\">Subsystem Management</a></li>
|
||||
<li><a href=\"#reasons\">Action Reasons Management</a></li>
|
||||
<li><a href=\"#periods\">Period Management</a></li>
|
||||
<li><a href=\"#discovered\">When Discovered Management</a></li>
|
||||
</ul>
|
||||
|
||||
<div id=\"users\">
|
||||
@@ -1001,53 +1020,49 @@ echo "</table>";
|
||||
echo "
|
||||
</div>
|
||||
|
||||
<div id=\"periods\">
|
||||
<div id=\"discovered\">
|
||||
";
|
||||
if ($peridisint_err) format_message(1,"Period number must be an integer.");
|
||||
if ($peridsuppld_err) format_message(1,"Period number cannot be blank.");
|
||||
if ($peridunique_err) format_message(1,"Period number already exists.");
|
||||
if ($pertimesunique_err) format_message(1,"Period already exists.");
|
||||
if ($pertimessuppld_err) format_message(1,"Period times cannot be blank.");
|
||||
if ($perhaswriteups_err) format_message(1,"Period has writeups in the database and cannot be deleted.");
|
||||
if ($discnamesuppld_err) format_message(1,"When Discovered name cannot be blank.");
|
||||
if ($discnameunique_err) format_message(1,"When Discovered name already exists.");
|
||||
if ($dischaswriteups_err) format_message(1,"When Discovered has writeups in the database and cannot be deleted.");
|
||||
|
||||
if ($edit_period && !$delete_period) {
|
||||
if ($edit_discovered && !$delete_discovered) {
|
||||
// set form options for editing
|
||||
$sectiontitle="<b><font size=\"+1\">Modify Period</font></b> <a href=\"dbadmin.php#periods\">Click here to add a new period</a><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php?edit_period=1#periods\">";
|
||||
$sectiontitle="<b><font size=\"+1\">Modify When Discovered</font></b> <a href=\"dbadmin.php#discovered\">Click here to add a new when discovered</a><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php?edit_discovered=1#discovered\">";
|
||||
$buttontags="
|
||||
<input type=\"hidden\" name=\"period_id\" value=\"$period_id\">
|
||||
<input type=\"submit\" name=\"update_period\" value=\"Update Period\">
|
||||
<input type=\"submit\" name=\"delete_period\" value=\"Delete Period\">
|
||||
<input type=\"hidden\" name=\"discovered_id\" value=\"$discovered_id\">
|
||||
<input type=\"submit\" name=\"update_discovered\" value=\"Update When Discovered\">
|
||||
<input type=\"submit\" name=\"delete_discovered\" value=\"Delete When Discovered\">
|
||||
<input type=\"submit\" name=\"reset\" value=\"Reset\"><br>
|
||||
";
|
||||
// pull current values from database
|
||||
$currentvalues=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from periods where id=$period_id"));
|
||||
$period_times=$currentvalues["times"];
|
||||
$currentvalues=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from discovered where id=$discovered_id"));
|
||||
$discovered_name=$currentvalues["whendiscoveredname"];
|
||||
$discovered_desc=$currentvalues["whendiscovereddesc"];
|
||||
if ($currentvalues["active"]==1) {
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\" checked>";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\" checked>";
|
||||
} else {
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\">";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\">";
|
||||
}
|
||||
$idtag="$period_id";
|
||||
} else {
|
||||
// set form options for add
|
||||
if (!$period_add_fail) unset($period_id,$period_times,$period_active);
|
||||
$sectiontitle="<b><font size=\"+1\">Add New Period</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#periods\">";
|
||||
if (!$discovered_add_fail) unset($discovered_id,$discovered_name,$discovered_desc,$discovered_active);
|
||||
$sectiontitle="<b><font size=\"+1\">Add New When Discovered</font></b><br><br>";
|
||||
$formtag="<form method=\"post\" action=\"dbadmin.php#discovered\">";
|
||||
$buttontags="
|
||||
<input type=\"submit\" name=\"add_period\" value=\"Add Period\">
|
||||
<input type=\"submit\" name=\"add_discovered\" value=\"Add When Discovered\">
|
||||
";
|
||||
$idtag="<input type=\"text\" name=\"period_id\" size=\"3\" value=\"$period_id\">";
|
||||
// set default values
|
||||
$activetag="<input type=\"checkbox\" name=\"period_active\" value=\"1\" checked>";
|
||||
$activetag="<input type=\"checkbox\" name=\"discovered_active\" value=\"1\" checked>";
|
||||
}
|
||||
echo "
|
||||
$sectiontitle
|
||||
$formtag
|
||||
<table border=\"0\">
|
||||
<tr><td>
|
||||
Period Number: $idtag<br><br>
|
||||
Period Times: <input type=\"text\" name=\"period_times\" size=\"40\" value=\"$period_times\"><br><br>
|
||||
When Discovered Name: <input type=\"text\" name=\"discovered_name\" size=\"8\" value=\"$discovered_name\"><br><br>
|
||||
When Discovered Description: <input type=\"text\" name=\"discovered_desc\" size=\"60\" value=\"$discovered_desc\"><br><br>
|
||||
Active: $activetag <br><br>
|
||||
</td></tr>
|
||||
</table>
|
||||
@@ -1057,11 +1072,11 @@ $buttontags
|
||||
";
|
||||
|
||||
// show the table of entities
|
||||
$existingdata=mysqli_query($drs_db,"select * from periods order by id asc");
|
||||
$existingdata=mysqli_query($drs_db,"select * from discovered order by id asc");
|
||||
echo "
|
||||
<b>Existing Periods</b> <font size=\"-1\">Click on the Period ID to edit.</font><br><br>
|
||||
<b>Existing When Discovereds</b> <font size=\"-1\">Click on the When Disc ID to edit.</font><br><br>
|
||||
<table border=\"1\">
|
||||
<tr><th>Period ID</th><th>Period Times</th><th>Active</th></tr>
|
||||
<tr><th>When Disc ID</th><th>Name</th><th>Description</th><th>Active</th></tr>
|
||||
";
|
||||
while ($tablerow=mysqli_fetch_assoc($existingdata)) {
|
||||
if ($tablerow["active"]) {
|
||||
@@ -1071,12 +1086,14 @@ while ($tablerow=mysqli_fetch_assoc($existingdata)) {
|
||||
}
|
||||
printf("
|
||||
<tr>
|
||||
<td><a href=\"dbadmin.php?edit_period=1&period_id=%s#periods\">%s</a></td>
|
||||
<td><a href=\"dbadmin.php?edit_discovered=1&discovered_id=%s#discovered\">%s</a></td>
|
||||
<td>%s</td>
|
||||
<td>%s</td>
|
||||
<td align=\"center\">%s</td>
|
||||
</tr>",
|
||||
$tablerow["id"],$tablerow["id"],
|
||||
$tablerow["times"],
|
||||
$tablerow["whendiscoveredname"],
|
||||
$tablerow["whendiscovereddesc"],
|
||||
$activedef);
|
||||
}
|
||||
echo "</table>";
|
||||
|
||||
Reference in New Issue
Block a user