/
attendance_user.php
executable file
·155 lines (138 loc) · 4.81 KB
/
attendance_user.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
<?php
// --------------------------------------------------------------------
// attendance_user.php -- Attendance report for a given user.
//
// Created: 1/22/15 DLB
// --------------------------------------------------------------------
require_once "config.php";
require_once "libs/all.php";
session_start();
log_page();
CheckLogin();
$timer = new Timer();
$loc = 'attendance_user.php';
$userid = 0;
$data = null;
$name = "";
if( $_SERVER["REQUEST_METHOD"] == "GET")
{
if(empty($_GET["UserID"]))
{
DieWithMsg($loc, "Bad Page Invoke. No UserID given.");
}
$userid = $_GET["UserID"];
$data = GetUserInfo($userid);
if($data === false) DieWithMsg($loc, 'User with ID=' . $userid . ' not found.');
$name = $data['FirstName'] . ' ' . $data["LastName"];
goto GenerateHtml;
}
else
{
DieWithMsg($loc, "Bad Page Invoke. Must be by GET.");
}
GenerateHtml:
include "forms/header.php";
include "forms/navform.php";
include "forms/attendance_menubar.php";
echo '<div class="content_area">';
echo '<h2>Detailed Attendance Report for ' . $name . '</h2>';
if(empty($data["BadgeID"]))
{
echo '<p>' . $name . ' does not have a badge. Nothing to report. <\p>';
}
else GenerateUserReport($data);
include "forms/footer.php";
// --------------------------------------------------------------------
// Generate report for a user.
function GenerateUserReport($data)
{
$badgeid = $data["BadgeID"];
$score = CalculateScoreForOne($badgeid);
$c = $score["Counts"];
$tm = $c[0] + $c[1] + $c[2];
$ne = $score["NEvents"];
RptLine('As of <b>' . $score["LastDay"] . '</b>:');
RptLine(' ');
RptLine('Total possible meetings:', $tm);
RptLine('Meeting types: Manditory=<b>' . $c[0] . '</b>, Regular=<b>' . $c[1] . '</b>, Optional=<b>' . $c[2] . '</b>');
RptLine(' ');
RptLine('Meetings attended:', $score["Present"]);
RptLine('Attendance score: <b>' . sprintf("%4.1f", $score["Score"]) . '</b>%');
RptLine('Total hours:', sprintf("%5.1f", $score["TotalHours"]));
RptLine('Hours on days of meetings:', sprintf("%5.1f", $score["InHours"]));
RptLine('Hours outside of meeting days:', sprintf("%5.1f", $score["OutHours"]));
RptLine(' ');
for($i = 0; $i < $ne; $i++)
{
$d = $score[$i];
$sout = $d["Name"] . ': ';
if($d["Present"]) $sout .= "Present";
else $sout .= "<b>Absent</b>";
if($d["Hours"] > 0.001) $sout .= ', Hours: <b>' . sprintf("%4.1f", $d["Hours"]) . '</b>';
if(isset($d["Correction"])) $sout .= ', **' . $d["Correction"];
RptLine($sout);
}
RptLine(' ');
RptLine('Raw Scans:');
ShowRawScans($data["BadgeID"]);
ShowCorrections($data["BadgeID"]);
}
function RptLine($s, $t="")
{
echo '<div style="font-size: 12pt; margin-top: 5px; min-height: 10px;">';
echo $s;
if(!empty($t)) echo ' <b>' . $t . '</b>';
echo '</div>' . "\n";
}
function ShowRawScans($badgeid)
{
$loc = "attendance_user.php->ShowRawScans()";
$sql = 'SELECT * from RawScans WHERE BadgeID="' . $badgeid . '"';
$result = SqlQuery($loc, $sql);
while($row = $result->fetch_assoc())
{
echo '<div style="display: block; height: 20px; ">';
echo '<br>' . "\n";
echo '<div style="float: left; width: 180px;">';
echo $row["ScanTime"];
echo '</div>' . "\n";
$dir = "";
if($row["Direction"] == 0) $dir = "Scan In";
if($row["Direction"] == 1) $dir = "Scan Out";
if($row["Direction"] == 2) $dir = "?";
echo '<div style="float: left; width: 100px;">';
echo $dir;
echo '</div>' . "\n";
echo '<div style="float: left; width: 80px;">';
echo $row["Flags"];
echo '</div>' . "\n";
echo '<div style="clear: both;"></div>' . "\n";
echo '</div>';
}
}
function ShowCorrections($badgeid)
{
$loc = "attendance_user.php->ShowRawScans()";
$corrections = GetSqlTable("Corrections");
RptLine('');
RptLine('Corrections applied:');
foreach($corrections as $c)
{
if($c["BadgeID"] == '*' || strtolower($badgeid) == strtolower($c["BadgeID"]))
{
echo '<div style="display: block; hieght: 20px; ">';
echo '<div style="float: left; width: 100px;">';
echo $c["Action"];
echo '</div>';
echo '<div style="float: left; width: 150px;">';
echo $c["ScanTime"];
echo '</div>';
echo '<div style="float: left; width: 350px; margin-left: 10px; ">';
echo $c["Reason"];
echo '</div>';
echo '</div>';
echo '<div style="clear: both;"></div>' . "\n";
}
}
}
?>