Incorporate common.php
This commit is contained in:
856
distfiles/common.php
Normal file
856
distfiles/common.php
Normal file
@@ -0,0 +1,856 @@
|
||||
<?php
|
||||
/*
|
||||
common.php
|
||||
OpenLog Online Logbook
|
||||
Copyright (C) 2026 Rod Wright
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
// test for correct installation
|
||||
if (!file_exists("db.php")) {
|
||||
echo "
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=\"x-ua-compatible\" content=\"IE=edge\">
|
||||
<title>Installation error</title>
|
||||
</head>
|
||||
<body>
|
||||
Could not find the db.php file required for this installation.
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
exit();
|
||||
}
|
||||
|
||||
include("db.php");
|
||||
include("settings.php");
|
||||
|
||||
// assign variables from constants
|
||||
|
||||
|
||||
// define some other constants
|
||||
define("ADMIN",2);
|
||||
define("USER",1);
|
||||
|
||||
// build the basic color array
|
||||
$basic_colors=array(
|
||||
"White" => "#FFFFFF",
|
||||
"Silver" => "#C0C0C0",
|
||||
"Gray" => "#808080",
|
||||
"Black" => "#000000",
|
||||
"Red" => "#FF0000",
|
||||
"Maroon" => "#800000",
|
||||
"Orange" => "#FFA500",
|
||||
"Yellow" => "#FFFF00",
|
||||
"Olive" => "#808000",
|
||||
"Lime" => "#00FF00",
|
||||
"Green" => "#008000",
|
||||
"Aqua" => "#00FFFF",
|
||||
"Teal" => "#008080",
|
||||
"Blue" => "#0000FF",
|
||||
"Navy" => "#000080",
|
||||
"Fuchsia" => "#FF00FF",
|
||||
"Purple" => "#800080");
|
||||
|
||||
// Determine access mode, login status, and admin status
|
||||
if ($access_mode == "trusted") $trusted=true; else $trusted=false;
|
||||
$loggedin=$isadmin=false;
|
||||
if (isset($_SESSION['userid'])) {
|
||||
$uid=$_SESSION['userid'];
|
||||
$loggedin=true;
|
||||
if (mysqli_fetch_row(mysqli_query($db,"select role from users where id=\"$uid\""))[0] == ADMIN) {
|
||||
$isadmin=true;
|
||||
}
|
||||
}
|
||||
|
||||
// Generic functions
|
||||
|
||||
function framework($option,$htmltitle,$pagetitle,$print) {
|
||||
// generates html code for the beginning and end of all pages
|
||||
if ($option=="begin") {
|
||||
// generates everything down to the sidemenu/pagetable
|
||||
// htmltitle is the page title that appears in the window titlebar
|
||||
// pagetitle is what will appear as the title of the page itself
|
||||
// print is whether to format for printing or not
|
||||
if ($print) {
|
||||
$bgcolor=P_BACKGROUND_COLOR;
|
||||
$textcolor=P_TEXT_COLOR;
|
||||
$linkcolor=P_LINK_COLOR;
|
||||
$vlinkcolor=P_VLINK_COLOR;
|
||||
$hdgcolor=P_HEADING_COLOR;
|
||||
} else {
|
||||
$bgcolor=BACKGROUND_COLOR;
|
||||
$textcolor=TEXT_COLOR;
|
||||
$linkcolor=LINK_COLOR;
|
||||
$vlinkcolor=VLINK_COLOR;
|
||||
$hdgcolor=HEADING_COLOR;
|
||||
}
|
||||
|
||||
echo "
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=\"x-ua-compatible\" content=\"IE=edge\">
|
||||
<title>$htmltitle</title>
|
||||
<style type=\"text/css\">
|
||||
* {font-family: Arial, Helvetica, sans-serif;}
|
||||
table.writeup {table-layout:fixed;}
|
||||
td.forcewrap {word-wrap: break-word;}
|
||||
</style>
|
||||
<style type=\"text/css\">
|
||||
.fixed {
|
||||
position:fixed;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function goBack() {
|
||||
window.history.back()
|
||||
}
|
||||
</script>
|
||||
<link href=\"jquery-ui/jquery-ui.css\" rel=\"stylesheet\">
|
||||
<link href=\"jquery-ui/jquery.multiselect.css\" rel=\"stylesheet\">
|
||||
<style>div.ui-datepicker{font-size:12px;}</style>
|
||||
|
||||
<link rel=\"stylesheet\" type=\"text/css\" href=\"colorpicker/css/screen.css\">
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/ddcolorposter.js\"></script>
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/YAHOO.js\" ></script>
|
||||
<script type=\"text/javascript2\" src=\"colorpicker/js/log.js\" ></script>
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/color.js\" ></script>
|
||||
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/event.js\" ></script>
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/dom.js\" ></script>
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/animation.js\" ></script>
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/dragdrop.js\" ></script>
|
||||
|
||||
<script type=\"text/javascript\" src=\"colorpicker/js/slider.js\" ></script>
|
||||
<script type=\"text/javascript\">
|
||||
|
||||
var hue;
|
||||
var picker;
|
||||
//var gLogger;
|
||||
var dd1, dd2;
|
||||
var r, g, b;
|
||||
|
||||
function init() {
|
||||
if (typeof(ygLogger) != \"undefined\")
|
||||
ygLogger.init(document.getElementById(\"logDiv\"));
|
||||
pickerInit();
|
||||
ddcolorposter.fillcolorbox(\"bgcfield\", \"bgcbox\")
|
||||
ddcolorposter.fillcolorbox(\"mbgcfield\", \"mbgcbox\")
|
||||
ddcolorposter.fillcolorbox(\"tcfield\", \"tcbox\")
|
||||
ddcolorposter.fillcolorbox(\"lcfield\", \"lcbox\")
|
||||
ddcolorposter.fillcolorbox(\"vlcfield\", \"vlcbox\")
|
||||
ddcolorposter.fillcolorbox(\"hcfield\", \"hcbox\")
|
||||
}
|
||||
|
||||
// Picker ---------------------------------------------------------
|
||||
|
||||
function pickerInit() {
|
||||
hue = YAHOO.widget.Slider.getVertSlider(\"hueBg\", \"hueThumb\", 0, 180);
|
||||
hue.onChange = function(newVal) { hueUpdate(newVal); };
|
||||
|
||||
picker = YAHOO.widget.Slider.getSliderRegion(\"pickerDiv\", \"selector\",
|
||||
0, 180, 0, 180);
|
||||
picker.onChange = function(newX, newY) { pickerUpdate(newX, newY); };
|
||||
|
||||
hueUpdate();
|
||||
|
||||
dd1 = new YAHOO.util.DD(\"pickerPanel\");
|
||||
dd1.setHandleElId(\"pickerHandle\");
|
||||
dd1.endDrag = function(e) {
|
||||
// picker.thumb.resetConstraints();
|
||||
// hue.thumb.resetConstraints();
|
||||
};
|
||||
}
|
||||
|
||||
executeonload(init);
|
||||
|
||||
function pickerUpdate(newX, newY) {
|
||||
pickerSwatchUpdate();
|
||||
}
|
||||
|
||||
|
||||
function hueUpdate(newVal) {
|
||||
|
||||
var h = (180 - hue.getValue()) / 180;
|
||||
if (h == 1) { h = 0; }
|
||||
|
||||
var a = YAHOO.util.Color.hsv2rgb( h, 1, 1);
|
||||
|
||||
document.getElementById(\"pickerDiv\").style.backgroundColor =
|
||||
\"rgb(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \")\";
|
||||
|
||||
pickerSwatchUpdate();
|
||||
}
|
||||
|
||||
function pickerSwatchUpdate() {
|
||||
var h = (180 - hue.getValue());
|
||||
if (h == 180) { h = 0; }
|
||||
document.getElementById(\"pickerhval\").value = (h*2);
|
||||
|
||||
h = h / 180;
|
||||
|
||||
var s = picker.getXValue() / 180;
|
||||
document.getElementById(\"pickersval\").value = Math.round(s * 100);
|
||||
|
||||
var v = (180 - picker.getYValue()) / 180;
|
||||
document.getElementById(\"pickervval\").value = Math.round(v * 100);
|
||||
|
||||
var a = YAHOO.util.Color.hsv2rgb( h, s, v );
|
||||
|
||||
document.getElementById(\"pickerSwatch\").style.backgroundColor =
|
||||
\"rgb(\" + a[0] + \", \" + a[1] + \", \" + a[2] + \")\";
|
||||
|
||||
document.getElementById(\"pickerrval\").value = a[0];
|
||||
document.getElementById(\"pickergval\").value = a[1];
|
||||
document.getElementById(\"pickerbval\").value = a[2];
|
||||
var hexvalue = document.getElementById(\"pickerhexval\").value =
|
||||
YAHOO.util.Color.rgb2hex(a[0], a[1], a[2]);
|
||||
ddcolorposter.initialize(a[0], a[1], a[2], hexvalue)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
";
|
||||
echo "
|
||||
<body bgcolor=\"#$bgcolor\" text=\"#$textcolor\" link=\"#$linkcolor\" vlink=\"#$vlinkcolor\">
|
||||
";
|
||||
if ($htmltitle || $pagetitle) {
|
||||
echo "<font size=5 color=\"#$hdgcolor\"><b> $htmltitle - $pagetitle</b></font>";
|
||||
if ($print) {
|
||||
echo "
|
||||
<input type=\"button\" onClick=\"window.print()\" value=\"Print\" id=\"printbutton\">
|
||||
<input type=\"button\" onClick=\"window.close()\" value=\"Close\" id=\"closebutton\">
|
||||
";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
} else if ($option=="end") {
|
||||
echo "
|
||||
<script src=\"jquery-ui/external/jquery/jquery.js\"></script>
|
||||
<script src=\"jquery-ui/jquery-ui.js\"></script>
|
||||
<script src=\"jquery-ui/jquery.multiselect.js\"></script>
|
||||
|
||||
<script>
|
||||
$( \".sidemenu\").addClass(\"fixed\");
|
||||
|
||||
$( \":button, :submit, :reset\" ).button();
|
||||
|
||||
$( \"#singledatepicker, #reportdatepicker, #actiondatepicker, [id|='onedp']\" ).datepicker({
|
||||
showOn: \"focus\",
|
||||
showButtonPanel: true,
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
dateFormat: \"yy-mm-dd\"
|
||||
});
|
||||
|
||||
$( \"#startdatepicker, [id|='sdp']\" ).datepicker({
|
||||
showOn: \"focus\",
|
||||
buttonImage: \"icons/calendar.gif\",
|
||||
buttonImageOnly: true,
|
||||
buttonText: \"Select start date\",
|
||||
inline: true,
|
||||
showButtonPanel: true,
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
dateFormat: \"yy-mm-dd\"
|
||||
});
|
||||
|
||||
$( \"#enddatepicker, [id|='edp']\" ).datepicker({
|
||||
showOn: \"focus\",
|
||||
buttonImage: \"icons/calendar.gif\",
|
||||
buttonImageOnly: true,
|
||||
buttonText: \"Select end date\",
|
||||
inline: true,
|
||||
showButtonPanel: true,
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
dateFormat: \"yy-mm-dd\"
|
||||
});
|
||||
|
||||
$( \"#logoutall\" ).checkboxradio({
|
||||
icon: false
|
||||
});
|
||||
$( \"#device, #subsystem, #discoveredselect, #functional, [id|='sel']\" ).selectmenu();
|
||||
$( \"#status, #user, #reason\" ).selectmenu();
|
||||
$( \"#showdays\" ).selectmenu( { width : 130 } );
|
||||
$( \"#subsystem, #discovered, #searchstatus, #pass, #passconf\").tooltip();
|
||||
$( \"[id|='ms']\").multiselect();
|
||||
$( \"#configtabs, #dbadmintabs, #profiletabs\" ).tabs();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br>Invalid option \"$option\" passed to framework(). Valid options are \"begin\" and \"end\".<br>
|
||||
";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
function pagetable($option) {
|
||||
if ($option=="begin") {
|
||||
echo "
|
||||
<br>
|
||||
<table border=\"0\" width=\"100%\" cellpadding=\"10\">
|
||||
<tr>
|
||||
";
|
||||
} else if ($option=="end") {
|
||||
echo "
|
||||
</tr></table>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br>Invalid option \"$option\" passed to pagetable(). Valid options are \"begin\" and \"end\".<br>
|
||||
";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function pageblock($block,$option) {
|
||||
if ($block=="left") {
|
||||
if ($option=="begin") {
|
||||
echo "
|
||||
<td width=\"210\" valign=\"top\">
|
||||
";
|
||||
} else if ($option=="end") {
|
||||
echo "
|
||||
</td>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br>Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".<br>
|
||||
";
|
||||
exit(1);
|
||||
}
|
||||
} else if ($block=="right") {
|
||||
if ($option=="begin") {
|
||||
echo "
|
||||
<td valign=\"top\">
|
||||
";
|
||||
} else if ($option=="end") {
|
||||
if (defined("FOOTER_MESSAGE")) {
|
||||
$footer_msg=FOOTER_MESSAGE;
|
||||
echo "
|
||||
<br><br>
|
||||
<center>$footer_msg</center><br>
|
||||
";
|
||||
}
|
||||
echo "
|
||||
</td>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<br>Invalid option \"$option\" passed to pageblock(). Valid options are \"begin\" and \"end\".<br>
|
||||
";
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
echo "
|
||||
<br>Invalid block \"$block\" passed to pageblock(). Valid blocks are \"left\" and \"right\".<br>
|
||||
";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function sidemenu($printable=true) {
|
||||
// Displays sidebar menu
|
||||
global $db,$mbgcolor,$trusted,$loggedin,$isadmin;
|
||||
|
||||
if ($trusted || $loggedin) {
|
||||
echo "
|
||||
<div class=\"sidemenu\">
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"create.php\" title=\"Create new writeup\"><font size=\"+1\"><b>Create New Writeup</b></font></a></td></tr>
|
||||
</table>
|
||||
<br>";
|
||||
}
|
||||
echo "
|
||||
<center><button onclick=\"goBack()\">Go Back</button></center>
|
||||
";
|
||||
if ($trusted || $loggedin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"writeups.php\" title=\"View writeups\">View Writeups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"groups.php\" title=\"View writeup groups\">Writeup Groups</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"search.php\">Search Writeups</a></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
";
|
||||
if ($isadmin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><b>Admin Functions</b></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"config.php\" title=\"Control global settings. Must be an administrator.\">Global Settings</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"dbadmin.php\" title=\"Manage the database. Must be an administrator.\">Manage Database</a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"https://localhost:10000\" title=\"Webmin for managing a terminal. Webmin must be running on localhost.\">Manage Terminal</a></td></tr>
|
||||
</table>
|
||||
<br>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
if (! $loggedin) {
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><b>My Account</b></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"login.php\"><b>Log In</b></a></td></tr>
|
||||
</table>
|
||||
<br>";
|
||||
} else {
|
||||
$menuuser=$_SESSION['userid'];
|
||||
$loggedinas=mysqli_fetch_row(mysqli_query($db,"select firstname,lastname from users where id=\"$menuuser\""));
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><b>My Account</b></td></tr>
|
||||
<tr><td align=\"center\">Logged in as $loggedinas[0] $loggedinas[1]</td></tr><tr><td align=\"center\"><a href=\"login.php?cancel=1\"><b>Log Out</b></a></td></tr>
|
||||
<tr><td align=\"center\"><a href=\"profile.php\">My Profile</a></td></tr>
|
||||
</table>
|
||||
<br>";
|
||||
}
|
||||
if ($printable) {
|
||||
$currentparams=arrayCopy($_REQUEST);
|
||||
echo "
|
||||
<br>
|
||||
<center>
|
||||
<form method=\"post\" target=\"_blank\">
|
||||
<input type=\"hidden\" name=\"all_parameters\" value=\"". htmlentities(serialize($currentparams))."\">
|
||||
<input type=\"submit\" name=\"print\" value=\"Show Printable\" id=\"showprintable\"></form>
|
||||
</center>
|
||||
";
|
||||
}
|
||||
echo "
|
||||
<br>
|
||||
<table style=\"table-layout:fixed;width:210px;\" bgcolor=\"#$mbgcolor\" border=\"1\" width=\"100%\">
|
||||
<tr><td align=\"center\"><a href=\"about.php\">About</a></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
|
||||
function banner($print) {
|
||||
// displays a banner
|
||||
global $db;
|
||||
$bannerid=BANNER;
|
||||
// get banner parameters from banner table
|
||||
$banrow=mysqli_fetch_assoc(mysqli_query($db,"select * from banners where bannerid=\"$bannerid\""));
|
||||
if (!$banrow) {
|
||||
$bannerid=1;
|
||||
} else {
|
||||
$bannertext=$banrow["bannername"];
|
||||
if ($print) {
|
||||
$bannercolor="#FFFFFF";
|
||||
$bannertxtcolor="#000000";
|
||||
} else {
|
||||
$bannercolor=$banrow["bannercolor"];
|
||||
$bannertxtcolor=$banrow["textcolor"];
|
||||
}
|
||||
}
|
||||
if ($bannerid != 1) {
|
||||
echo "
|
||||
<table width=\"100%\">
|
||||
<tr bgcolor=\"$bannercolor\" align=\"center\"><td colspan=2><font size=\"+1\" color=\"$bannertxtcolor\"><b>$bannertext</b></font></td></tr></table>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
function dblookup($db,$table,$in_field,$out_field,$in_data) {
|
||||
// look up a single field in a database given a value for a single field
|
||||
$lookup_result=(mysqli_query($db,"select $out_field from $table where $in_field=\"$in_data\""));
|
||||
if (mysqli_num_rows($lookup_result) > 0) {
|
||||
$out_data=mysqli_fetch_row($lookup_result);
|
||||
return($out_data[0]);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function arrayCopy( array $array ) {
|
||||
$result=[];
|
||||
foreach( $array as $key => $val ) {
|
||||
if( is_array( $val ) ) {
|
||||
$result[$key] = arrayCopy( $val );
|
||||
} elseif ( is_object( $val ) ) {
|
||||
$result[$key] = clone $val;
|
||||
} else {
|
||||
$result[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function validateDate($date, $format = 'Y-m-d') {
|
||||
$d = DateTime::createFromFormat($format, $date);
|
||||
return $d && $d->format($format) == $date;
|
||||
}
|
||||
|
||||
function validateTime($time, $format = 'H:i:s') {
|
||||
$t = DateTime::createFromFormat($format, $time);
|
||||
return $t && $t->format($format) == $time;
|
||||
}
|
||||
|
||||
function validate_password($pass,$passconf) {
|
||||
// run some checks on supplied passwords
|
||||
// returns a two element array
|
||||
// first element is true if passwords match, false if not
|
||||
// second element is true if passwords meet complexity requirements, false if not
|
||||
|
||||
$results=[];
|
||||
|
||||
// check for match
|
||||
if ($pass==$passconf) {
|
||||
$results['match']=true;
|
||||
} else {
|
||||
$results['match']=false;
|
||||
}
|
||||
|
||||
// check for complexity
|
||||
// length
|
||||
if (strlen($pass) < 8) {
|
||||
$passlength=false;
|
||||
} else {
|
||||
$passlength=true;
|
||||
}
|
||||
// upper case
|
||||
if (preg_match('/[A-Z]/',$pass)) {
|
||||
$hasupper=true;
|
||||
} else {
|
||||
$hasupper=false;
|
||||
}
|
||||
// lower case
|
||||
if (preg_match('/[a-z]/',$pass)) {
|
||||
$haslower=true;
|
||||
} else {
|
||||
$haslower=false;
|
||||
}
|
||||
// number
|
||||
if (preg_match('/[0-9]/',$pass)) {
|
||||
$hasnumber=true;
|
||||
} else {
|
||||
$hasnumber=false;
|
||||
}
|
||||
// special character
|
||||
if (preg_match('/[[:punct:]]/',$pass)) {
|
||||
$hasspecial=true;
|
||||
} else {
|
||||
$hasspecial=false;
|
||||
}
|
||||
if ($passlength && $hasupper && $haslower && $hasnumber && $hasspecial) {
|
||||
$results['complex']=true;
|
||||
} else {
|
||||
$results['complex']=false;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
function displaywriteup($id) {
|
||||
// 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;
|
||||
global $db;
|
||||
|
||||
$writeupdata=mysqli_fetch_assoc(mysqli_query($db,"select * from writeups where id=\"$id\""));
|
||||
// determine status indicator
|
||||
if ($writeupdata['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
|
||||
if ($writeupdata['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
|
||||
if ($writeupdata['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
|
||||
// determine functional indicator
|
||||
if($writeupdata["functional"]==1) {
|
||||
$funcind="<font color=\"#00FF00\" title=\"$functional_yes\">$functional_yes_short</font>";
|
||||
} else {
|
||||
$funcind="<font color=\"#FF0000\" title=\"$functional_no\">$functional_no_short</font>";
|
||||
}
|
||||
// look up text data
|
||||
$devicename=dblookup($db,"devices","id","name",$writeupdata["device"]);
|
||||
$subsystemname=dblookup($db,"subsystems","id","name",$writeupdata["subsystem"]);
|
||||
$subsystemdesc=dblookup($db,"subsystems","id","description",$writeupdata["subsystem"]);
|
||||
$discrtxt=$writeupdata["discrepancy_text"];
|
||||
$rdate=$writeupdata["report_date"];
|
||||
$rtime=$writeupdata["report_time"];
|
||||
$repby=$writeupdata["reported_by"];
|
||||
$whendiscoveredname=dblookup($db,"discovered","id","whendiscoveredname",$writeupdata["discovered"]);
|
||||
$whendiscovereddesc=dblookup($db,"discovered","id","whendiscovereddesc",$writeupdata["discovered"]);
|
||||
$techfname=dblookup($db,"users","id","firstname",$writeupdata["action_by"]);
|
||||
$techlname=dblookup($db,"users","id","lastname",$writeupdata["action_by"]);
|
||||
$reasonname=dblookup($db,"reasons","id","text",$writeupdata["action_reason"]);
|
||||
$actxt=$writeupdata["action_text"];
|
||||
$adate=$writeupdata["action_date"];
|
||||
if ($adate=="0000-00-00") $adate="";
|
||||
$atime=$writeupdata["action_time"];
|
||||
|
||||
// determine if this is a member of a group
|
||||
$member_qry=mysqli_query($db,"select linkgroup from links where writeupid=\"{$writeupdata['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($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) {
|
||||
$group_ind="<a href=\"groups.php?group=$member_group\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"$imgtitle\"></a></div>";
|
||||
} else {
|
||||
$group_ind="<a href=\"writeupdetail.php?id={$writeupdata['id']}\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"Member of $group_count groups. Click here to view.\"></a></div>";
|
||||
}
|
||||
} else {
|
||||
$group_ind=NULL;
|
||||
}
|
||||
echo "
|
||||
<table border=\"2\" width=\"100%\"><tr><td>
|
||||
<table border=\"0\">
|
||||
<tr><td><b>ID:</b> <a href=\"writeupdetail.php?id=$id\" title=\"View or change details of this writeup\">$id</a></td><td> </td>
|
||||
<td><b>$statusind</b></td><td> </td>
|
||||
<td><b>$device_term:</b> $devicename</td><td> </td>
|
||||
<td><b>Subsystem:</b> <font title=\"$subsystemdesc\">$subsystemname</font></td><td> </td>
|
||||
<td><b>$discovered_term:</b> <font title=\"$whendiscovereddesc\">$whendiscoveredname</font></td><td> </td>
|
||||
<td><b>$funcind</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td><b>Discrepancy:</b><br>$discrtxt</td><td> </td>
|
||||
<td align=\"right\" valign=\"bottom\">$group_ind</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td><b>Report date:</b> $rdate</td><td> </td>
|
||||
<td><b>Report time:</b> $rtime</td><td> </td>
|
||||
<td><b>Reported by:</b> $repby</td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td><b>Action taken by:</b> $techfname $techlname</td><td> </td>
|
||||
<td><b>Status change reason:</b> $reasonname</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td><b>Action taken:</b><br>$actxt</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table border=\"0\">
|
||||
<tr>
|
||||
<td><b>Action date:</b> $adate</td><td> </td>
|
||||
<td><b>Action time:</b> $atime</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr></table>
|
||||
";
|
||||
}
|
||||
|
||||
function format_message($msgtype,$msgtxt) {
|
||||
// displays a formatted message
|
||||
// $msgtype is 0 for success or anything else for failure
|
||||
// $msgtxt is the string to display
|
||||
if ($msgtype == 0) {
|
||||
$state="ui-state-highlight";
|
||||
$icon="ui-icon-info";
|
||||
} else {
|
||||
$state="ui-state-error";
|
||||
$icon="ui-icon-alert";
|
||||
}
|
||||
if ($msgtxt == "") $msgtxt="PROGRAM ERROR: No message text was supplied.";
|
||||
echo "
|
||||
<div class=\"$state ui-corner-all\" style=\"margin-top: 20px; padding: 0 .7em;\">
|
||||
<p><span class=\"ui-icon $icon\" style=\"float: left; margin-right: .3em;\"></span>
|
||||
$msgtxt</p>
|
||||
</div><br><br>
|
||||
";
|
||||
}
|
||||
|
||||
function getsetting($setting_name,$user_id) {
|
||||
// get the value of a setting for a user
|
||||
global $db;
|
||||
$confqry=mysqli_query($db,"select id,value from config where name=\"$setting_name\"");
|
||||
$confvalue=mysqli_fetch_assoc($confqry)['value'];
|
||||
$userqry=mysqli_query($db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
if (mysqli_num_rows($userqry) > 0) {
|
||||
$uservalue=mysqli_fetch_assoc($userqry)['value'];
|
||||
if ($uservalue) {
|
||||
return $uservalue;
|
||||
} else {
|
||||
return $confvalue;
|
||||
}
|
||||
} else {
|
||||
return $confvalue;
|
||||
}
|
||||
}
|
||||
|
||||
function putsetting($setting_name,$setting_value,$user_id) {
|
||||
// set the value of a setting for a tech
|
||||
global $db;
|
||||
$confqry=mysqli_query($db,"select value from config where name=\"$setting_name\"");
|
||||
$confvalue=mysqli_fetch_assoc($confqry)['value'];
|
||||
$userqry=mysqli_query($db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
if (mysqli_num_rows($userqry) > 0) {
|
||||
$uservalue=mysqli_fetch_assoc($userqry)['value'];
|
||||
if ($setting_value==$confvalue) {
|
||||
mysqli_query($db,"delete from profile where user=\"$user_id\" and name=\"$setting_name\"");
|
||||
} else {
|
||||
if ($uservalue) {
|
||||
if ($uservalue != $setting_value) mysqli_query($db,"update profile set value=\"$setting_value\" where name=\"$setting_name\" and user=\"$user_id\"");
|
||||
} else {
|
||||
mysqli_query($db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mysqli_query($db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
||||
}
|
||||
}
|
||||
|
||||
function group_detail($groupid,$role=false,$mode="view",$selection="none") {
|
||||
// display a table for a single group
|
||||
|
||||
// groupid is the group for which detail is to be shown
|
||||
// role is true if user is logged in, false if not.
|
||||
// mode is "select" if selection boxes are to be displayed, "view" if not.
|
||||
// selection is "all" or "none"
|
||||
|
||||
// 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;
|
||||
global $db;
|
||||
|
||||
// print group id and name
|
||||
if ($selection == "all") {
|
||||
$sel_flag="checked";
|
||||
} elseif ($selection == "none") {
|
||||
$sel_flag="";
|
||||
}
|
||||
$groupname=dblookup($db,"groups","id","name",$groupid);
|
||||
if ($groupname == "") {
|
||||
echo "<b>Group ID: $groupid";
|
||||
} else {
|
||||
echo "<b>Group Name: $groupname";
|
||||
}
|
||||
echo "</b><br>";
|
||||
// print table headers
|
||||
if ($role && $mode=="select") {
|
||||
echo "
|
||||
<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%;\">$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>
|
||||
";
|
||||
} else {
|
||||
echo "
|
||||
<table border=\"1\" cellpadding=\"5\" style=\"width:100%;\">
|
||||
<tr>
|
||||
<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>
|
||||
";
|
||||
}
|
||||
|
||||
$writeup_qry=mysqli_query($db,"select writeupid from links where linkgroup=$groupid order by writeupid asc");
|
||||
while ($writeup=mysqli_fetch_row($writeup_qry)) {
|
||||
// get writeup data
|
||||
$writeupdata=mysqli_fetch_assoc(mysqli_query($db,"select * from writeups where id={$writeup[0]}"));
|
||||
|
||||
// convert device number to name
|
||||
$tname=dblookup($db,"devices","id","name",$writeupdata["device"]);
|
||||
// convert subsystem number to name
|
||||
$ssname=dblookup($db,"subsystems","id","name",$writeupdata["subsystem"]);
|
||||
// determine status indicator
|
||||
if ($writeupdata['status']==1) $statusind="<font color=\"#FF0000\"><div title=\"Open\">OPEN</div></font>";
|
||||
if ($writeupdata['status']==2) $statusind="<font color=\"#00FF00\"><div title=\"Closed\">CLSD</div></font>";
|
||||
if ($writeupdata['status']==3) $statusind="<font color=\"#FFFF00\"><div title=\"Deferred\">DFRD</div></font>";
|
||||
// determine whendiscovered text for discovered id
|
||||
$whendiscname=mysqli_fetch_row(mysqli_query($db,"select whendiscoveredname from discovered where id=\"{$writeupdata['discovered']}\""))[0];
|
||||
$whendiscdesc=mysqli_fetch_row(mysqli_query($db,"select whendiscovereddesc from discovered where id=\"{$writeupdata['discovered']}\""))[0];
|
||||
// determine functional icon
|
||||
if($writeupdata["functional"]==1) {
|
||||
$func_icon="<img src=\"icons/tick.png\" border=\"0\" title=\"$functional_yes\" alt=\"$functional_yes_short\">";
|
||||
} else {
|
||||
$func_icon="<img src=\"icons/cross.png\" border=\"0\" title=\"$functional_no\" alt=\"$functional_no_short\">";
|
||||
}
|
||||
// print table row
|
||||
if ($role && $mode=="select") {
|
||||
printf(
|
||||
"<tr>
|
||||
<td align=\"center\" valign=\"top\"><input type=\"checkbox\" name=\"targets[]\" value=\"%s\" $sel_flag></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\"><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",
|
||||
$writeupdata["id"],
|
||||
$writeupdata["id"],$writeupdata["id"],
|
||||
$statusind,
|
||||
$writeupdata["report_date"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$tname,
|
||||
$ssname,
|
||||
$writeupdata["reported_by"],
|
||||
$writeupdata["discrepancy_text"],
|
||||
$func_icon
|
||||
);
|
||||
} else {
|
||||
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\">%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",
|
||||
$writeupdata["id"],$writeupdata["id"],
|
||||
$statusind,
|
||||
$writeupdata["report_date"],
|
||||
$whendiscdesc, $whendiscname,
|
||||
$tname,
|
||||
$ssname,
|
||||
$writeupdata["reported_by"],
|
||||
$writeupdata["discrepancy_text"],
|
||||
$func_icon
|
||||
);
|
||||
}
|
||||
}
|
||||
echo "</table><br>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -7,7 +7,8 @@
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
*/
|
||||
|
||||
include("functions.php");
|
||||
//---include("functions.php");
|
||||
include("common.php");
|
||||
|
||||
//$tgt_year=$_REQUEST['y'];
|
||||
//$tgt_month=$_REQUEST['m'];
|
||||
|
||||
Reference in New Issue
Block a user