811 lines
29 KiB
PHP
811 lines
29 KiB
PHP
<?php
|
|
/*
|
|
common.php
|
|
OpenDRS Online Discrepancy Reporting System
|
|
Copyright (C) 2018 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");
|
|
|
|
// define some constants
|
|
define("STAT_OPEN",1);
|
|
define("STAT_CLOSED",2);
|
|
define("STAT_DEFERRED",3);
|
|
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");
|
|
|
|
// 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\">
|
|
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, #period, #period_effective, [id|='sel']\" ).selectmenu();
|
|
$( \"#status, #user, #reason\" ).selectmenu();
|
|
$( \"#subsystem, #period, #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 $drs_db,$mbgcolor;
|
|
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>
|
|
";
|
|
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 open writeups\"><font size=\"+1\"><b>View Open Writeups</b></font></a></td></tr>
|
|
<tr><td align=\"center\"><a href=\"writeups.php?view=1\" title=\"View all writeups for a date range\">View All 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 (isset($_SESSION['userid'])) {
|
|
$menuuser=$_SESSION['userid'];
|
|
if (mysqli_fetch_row(mysqli_query($drs_db,"select role from users where id=\"$menuuser\""))[0] == ADMIN) {
|
|
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>
|
|
</table>
|
|
<br>
|
|
";
|
|
}
|
|
}
|
|
|
|
if (!isset($_SESSION['userid'])) {
|
|
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 {
|
|
$loginid=$_SESSION['userid'];
|
|
$loggedinas=mysqli_fetch_row(mysqli_query($drs_db,"select firstname,lastname from users where id=\"$loginid\""));
|
|
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 $drs_db;
|
|
$bannerid=BANNER;
|
|
// get banner parameters from banner table
|
|
$banrow=mysqli_fetch_assoc(mysqli_query($drs_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($dbhandle,$table,$in_field,$out_field,$in_data) {
|
|
// look up a single field in a database given a value for a single field
|
|
$out_data=mysqli_fetch_row(mysqli_query($dbhandle,"select $out_field from $table where $in_field=\"$in_data\""));
|
|
return($out_data[0]);
|
|
}
|
|
|
|
function arrayCopy( array $array ) {
|
|
$result = array();
|
|
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=array();
|
|
|
|
// 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) {
|
|
global $drs_db;
|
|
$writeupdata=mysqli_fetch_assoc(mysqli_query($drs_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 effective icon
|
|
if($writeupdata["period_effective"]==1) {
|
|
$effind="<font color=\"#00FF00\" title=\"Period Effective\">EFF</font>";
|
|
} else {
|
|
$effind="<font color=\"#FF0000\" title=\"Period Non-effective\">NEF</font>";
|
|
}
|
|
// look up text data
|
|
$devicename=dblookup($drs_db,"devices","id","name",$writeupdata["device"]);
|
|
$subsystemname=dblookup($drs_db,"subsystems","id","name",$writeupdata["subsystem"]);
|
|
$subsystemdesc=dblookup($drs_db,"subsystems","id","description",$writeupdata["subsystem"]);
|
|
$discrtxt=$writeupdata["discrepancy_text"];
|
|
$rdate=$writeupdata["report_date"];
|
|
$rtime=$writeupdata["report_time"];
|
|
$repby=$writeupdata["reported_by"];
|
|
$period=$writeupdata["period"];
|
|
$periodtimes=dblookup($drs_db,"periods","id","times",$period);
|
|
$techfname=dblookup($drs_db,"users","id","firstname",$writeupdata["action_by"]);
|
|
$techlname=dblookup($drs_db,"users","id","lastname",$writeupdata["action_by"]);
|
|
$reasonname=dblookup($drs_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($drs_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($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) {
|
|
$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=\"groups.php\"><img src=\"icons/block.png\" alt=\"GRP\" title=\"View writeup groups\"></a></div>";
|
|
}
|
|
}
|
|
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:</b> $devicename</td><td> </td>
|
|
<td><b>Subsystem:</b> <font title=\"$subsystemdesc\">$subsystemname</font></td><td> </td>
|
|
<td><b>Period:</b> <font title=\"$periodtimes\">$period</font></td><td> </td>
|
|
<td><b>$effind</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 $drs_db;
|
|
$confvalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select id,value from config where name=\"$setting_name\""))['value'];
|
|
$uservalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""))['value'];
|
|
if ($uservalue) {
|
|
return $uservalue;
|
|
} else {
|
|
return $confvalue;
|
|
}
|
|
}
|
|
|
|
function putsetting($setting_name,$setting_value,$user_id) {
|
|
// set the value of a setting for a tech
|
|
global $drs_db;
|
|
$confvalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from config where name=\"$setting_name\""))['value'];
|
|
$uservalue=mysqli_fetch_assoc(mysqli_query($drs_db,"select value from profile where name=\"$setting_name\" and user=\"$user_id\""))['value'];
|
|
if ($setting_value==$confvalue) {
|
|
mysqli_query($drs_db,"delete from profile where user=\"$user_id\" and name=\"$setting_name\"");
|
|
} else {
|
|
if ($uservalue) {
|
|
if ($uservalue != $setting_value) mysqli_query($drs_db,"update profile set value=\"$setting_value\" where name=\"$setting_name\" and user=\"$user_id\"");
|
|
} else {
|
|
mysqli_query($drs_db,"insert into profile(user,name,value) values(\"$user_id\",\"$setting_name\",\"$setting_value\")");
|
|
}
|
|
}
|
|
}
|
|
|
|
function group_table($groupid,$role=false,$mode="view",$selection="none",$expanded=false) {
|
|
// display a table for a single group
|
|
global $drs_db;
|
|
// print group id and name
|
|
if ($selection == "all") {
|
|
$sel_flag="checked";
|
|
} elseif ($selection == "none") {
|
|
$sel_flag="";
|
|
}
|
|
if ($expanded) {
|
|
echo "
|
|
<a href=\"groups.php\" style=\"text-decoration:none\">
|
|
<img src=\"icons/minus-white.png\" alt=\"Unexpand group\">
|
|
</a>
|
|
";
|
|
}
|
|
$groupname=dblookup($drs_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%;\">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>
|
|
";
|
|
} 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%;\">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>
|
|
";
|
|
}
|
|
|
|
$writeup_qry=mysqli_query($drs_db,"select writeupid from links where linkgroup=$groupid");
|
|
while ($writeup=mysqli_fetch_row($writeup_qry)) {
|
|
// get writeup data
|
|
$writeupdata=mysqli_fetch_assoc(mysqli_query($drs_db,"select * from writeups where id={$writeup[0]}"));
|
|
|
|
// convert device number to name
|
|
$tname=dblookup($drs_db,"devices","id","name",$writeupdata["device"]);
|
|
// convert subsystem number to name
|
|
$ssname=dblookup($drs_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 times for period
|
|
$ptimes=mysqli_fetch_row(mysqli_query($drs_db,"select times from periods where id=\"{$writeupdata['period']}\""))[0];
|
|
// determine effective icon
|
|
if($writeupdata["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\">";
|
|
}
|
|
// 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"],
|
|
$ptimes, $writeupdata["period"],
|
|
$tname,
|
|
$ssname,
|
|
$writeupdata["reported_by"],
|
|
$writeupdata["discrepancy_text"],
|
|
$eff_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"],
|
|
$ptimes, $writeupdata["period"],
|
|
$tname,
|
|
$ssname,
|
|
$writeupdata["reported_by"],
|
|
$writeupdata["discrepancy_text"],
|
|
$eff_icon
|
|
);
|
|
}
|
|
}
|
|
echo "</table><br>";
|
|
|
|
}
|
|
|
|
|
|
?>
|