/
ManagerReportUnfold.php
256 lines (167 loc) · 6.19 KB
/
ManagerReportUnfold.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
$username = $_SERVER['AUTH_USER'];
$shortusername = substr(strrchr($username,'\\'), 1);
//debug will have to use hard code
//$shortusername='chiggins';
//$shortusername='jmcgrath';
?>
<html>
<head>
<Title>IT Security and Confidentiality Training</Title>
<link rel="stylesheet" type="text/css" href="report.css" />
<script language="javascript" type="text/javascript">
function showTests(str) {
if (str==""){
document.getElementById("div1").innerHTML="Select a supervisor for more details!";
return;
}
var xhr = false;
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
xhr = new XMLHttpRequest();
}
if (xhr) {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById("div1").innerHTML = xhr.responseText;
}
}
xhr.open("GET", "Reportmini.php?q="+str, true);
xhr.send(null);
}
}
</script>
</head>
<body>
<!--script type="text/javascript"> SomeFunction(); </script-->
<?php
require 'utils.php';
require 'DBConnect.php'; //Database Connection
// get last update date
$infoQuery="SELECT ([Last Update]) FROM [APACS Sandbox].[dbo].[00securityTestLog] where [index] =1";
$infoResult =sqlsrv_query($db, $infoQuery,array(),array("Scrollable"=>"buffered"));
if ($infoResult ===False) { $db->exitWithError('query fail'); }
if(!sqlsrv_has_rows($infoResult)) { return false; }
while ($infoRow = sqlsrv_fetch_array($infoResult)) {
$date=$infoRow['Last Update'];
//$LastUpDate = $date->format('m-d-Y H:i:s');
$LastUpDate = $date->format('m-d-Y h:i A');
}
?>
<!--select name="supervisors" onchange="showTests(this.value)"-->
<?php
//$query="SELECT [supervisor] FROM [APACS Sandbox].[dbo].[00securitytestTEMP] group by [supervisor] order by [supervisor]";
//$qresult=sqlsrv_query($db, $query, array(), array("Scrollable"=>"buffered"));
//if ($qresult===False) {echo "fail";}
//if(!sqlsrv_has_rows($qresult)) { return false;}
//while ($row = sqlsrv_fetch_array($qresult)) {
//echo '<option value="'. $row['supervisor'] .'">' .$row['supervisor'] . '</option>';
//}
?>
<!--/select>
<div id="div1"> </div>
<!--Select a supervisor for latest test scores of their employees</div>
Latest test scores updated on <?php// echo $LastUpDate; ?>.
</div>
<!--p style="text-align: center;"><button onclick="self.location.href = '/ReportExcel.php';">click here to trigger CSV download</button>
</p>
<div id="headings">
<span id="HeadManager" >Manager</span>
</div-->
<div id ="listPod">
<?php
$level = 0;
$query = "SELECT * FROM [APACS Sandbox].[dbo].[00securitytestTEMP] where suplogon = '" . $shortusername . "'";
// echo $query;
$qresult =sqlsrv_query($db, $query,array(),array("Scrollable"=>"buffered"));
if ($qresult ===False) { $db->exitWithError('query fail'); }
if(!sqlsrv_has_rows($qresult)) { // no rows not a manager er livel -1 ????
//echo "supervises no one incementer = " . $x;
//$isManager=0;
echo "You are either not a manager or you don't have employees who have taken the security training ";
}
else {
echo '<div id="results">';
$Managers =array();
//$testList = array();
list($level, $Managers) = listTestDates ($shortusername, $db, $level, $Managers );
echo "</div>";
}
?>
</div>
<?php
//echo "test";
//foreach ($Managers as $key =>$value) { echo $key ." xxx ".$value ."<br>" ; }
//foreach ($classes as $key =>$value) { echo "<option value =\"$key\">$value </option> \n"; }
function listTestDates ($logon, $db , $level, $Managers ) {
$isManager=0;
$empsSupervised = 0;
$x=0;
$leftMargin=$level * 25;
$row_count=0;
$query = "SELECT * FROM [APACS Sandbox].[dbo].[00securitytestTEMP] where suplogon = '" . $logon . "'";
// echo $query;
$qresult =sqlsrv_query($db, $query,array(),array("Scrollable"=>"buffered"));
if ($qresult ===False) { $db->exitWithError('query fail'); }
if(!sqlsrv_has_rows($qresult)) { // no rows not a manager maybe manger livel -1 ????
//echo "supervises no one incementer = " . $x;
//$isManager=0;
}
else {
//$isManager=1;
// supervisor add a level
$level++;
$row_count = sqlsrv_num_rows( $qresult );
}
while ($row = sqlsrv_fetch_array($qresult)) {
$date=$row['testdate'];
$formattedDate = $date->format('m-d-Y');
$x++;
if ($x ==1) {
$Managers[$row['suplogon']] = $row['supervisor'] ;
?>
<div id="employeePod" style="margin-left:<?php echo $leftMargin;?>px;" >
<?php
//echo "Supervises ". $row_count . " people";
include ('heading.inc');
}
?>
<div id=dataline">
<div id="Emp"><?php echo $row['name'] ?><br></div>
<div id="Email"><?php echo $row['email'] ?></div>
<div id="Date"><?php echo $formattedDate ?></div>
<div id="Attempts"><?php echo $row['attempts'] ?></div>
<div id="OldMan"><?php echo $row['supervisor'] ?></div>
<div id="ManEmail"><?php echo $row['supervisor email'] ?></div>
<div id="spacer"> </div>
</div>
<?php
//Check if this employee is a supervior
$mquery = "SELECT * FROM [APACS Sandbox].[dbo].[00securitytestTEMP] where suplogon = '" . $row['logon'] . "'";
// echo $query;
$mqresult =sqlsrv_query($db, $query,array(),array("Scrollable"=>"buffered"));
if ($mqresult ===False) { $db->exitWithError('query fail'); }
if(!sqlsrv_has_rows($mqresult)) { // no rows not a manager maybe manger livel -1 ????
} else {
//$isManager=1;
// supervisor add a level
//$level++;
//$row_count = sqlsrv_num_rows( $mqresult );
list($level, $Managers) = listTestDates($row['logon'], $db, $level, $Managers);
}
// echo " employee listed increnter =" . $x ;
// echo "rowcount = " .$row_count;
//echo "Employee level is " .$level;
if ($row_count ==$x) { //last of level down
$level--;
echo " </div>";
}
//$level =listTestDates($row['logon'], $db, $level );
//list($level, $Managers) = listTestDates($row['logon'], $db, $level, $Managers);
// echo $row['name'] . "is Manager" . $isManager;
}
//return $level;
return array ($level, $Managers);
}
?>
</div>