-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatusview.php
More file actions
254 lines (228 loc) · 9.28 KB
/
Copy pathstatusview.php
File metadata and controls
254 lines (228 loc) · 9.28 KB
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
<!DOCTYPE html>
<html>
<head>
<title>PSCS Attendance: Status View</title>
<?php
require_once('header.php');
$TimeQuery = $db_server->query("SELECT starttime,endtime FROM globals");
$TimeQuery = $TimeQuery->fetch_array();
$globalstarttime = new DateTime($TimeQuery['starttime']);
$globalendtime = new DateTime($TimeQuery['endtime']);
$globalstarttime = $globalstarttime->format("H:iA");
$globalendtime = $globalendtime->format("H:iA");
?>
<script type="text/javascript">
$(document).ready(function(){
$('#offtime').timepicker({ 'scrollDefaultNow': true, 'minTime': <?php echo(json_encode($globalstarttime)); ?>, 'maxTime': <?php echo(json_encode($globalendtime)); ?>, 'timeFormat': 'g:i', 'step': 5 });
$('#fttime').timepicker({ 'scrollDefaultNow': true, 'minTime': <?php echo(json_encode($globalstarttime)); ?>, 'maxTime': <?php echo(json_encode($globalendtime)); ?>, 'timeFormat': 'g:i', 'step': 15 });
$('.late_time').timepicker({ 'scrollDefaultNow': true, 'minTime': <?php echo(json_encode($globalstarttime)); ?>, 'maxTime': <?php echo(json_encode($globalendtime)); ?>, 'timeFormat': 'g:i', 'step': 5 });
});
</script>
<link rel="stylesheet" type="text/css" href="a/css/jquery.datetimepicker.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="a/p/js/scrollTo.js"></script>
<script src="a/p/js/jquery.datetimepicker.js"></script>
<script type="text/javascript">
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click, mousemove', refresh);
refresh();
}
setIdle(function() {location.href = location.href;}, 300);
</script>
</head>
<body class="mainpage statusview">
<!-- setup -->
<?php
//get number of students
$StudentNumQuery = $db_server->query("SELECT firstname FROM studentdata WHERE current = 1");
$StudentCount = 0;
while ($current_student = $StudentNumQuery->fetch_assoc()) {
$StudentCount++;
}
//echo "count: " . $StudentCount;
$null_value = null;
$status_result = $db_server->query("SELECT DISTINCT statusname FROM statusdata");
$result_array = array();
while ($blah = $status_result->fetch_assoc()) {
$status_array[] = $blah['statusname'];
}
//this function sorts multidimensional arrays by one of their subkeys
//$a = the array to be sorted -- $subkey = the subkey to be sorted by
function subval_sort($a, $subkey, $result) {
//dynamic variable naming to ensure the result array is named 'subkey'_array
$temp_varname = $result . "_array";
$$temp_varname = array();
//goes through the array, $k = the key, $v = value in the array
foreach($a as $k=>$v) {
$b[$k] = $v[$subkey];
}
if (!empty($b)) {
if ($subkey == 'statusname') {
asort($b);
}
foreach($b as $key=>$val) {
if ($val == $result) {
array_push($$temp_varname, $a[$key]);
}
}
if ($subkey == 'statusname') {
asort($$temp_varname);
}
return $$temp_varname;
}
}
//facilitator array, $facilitators is array of all from sql
$facget = $db_server->query("SELECT * FROM facilitators ORDER BY facilitatorname ASC");
$facilitators = array();
while ($fac_row = $facget->fetch_row()) {
array_push ($facilitators, $fac_row[0]);
}
//current students array
$studentquery = "SELECT studentid FROM studentdata WHERE current=1 ORDER BY firstname";
if (!empty($_GET['sortBy'])) {
if ($_GET['sortBy'] == 'student' && $_GET['r'] == 1) {
$studentquery = "SELECT studentid FROM studentdata WHERE current=1 ORDER BY firstname DESC";
}
}
$current_users_result = $db_server->query($studentquery);
// changestatus functions to create new entries in the database
//each only triggers if each field is correctly filled out, and the corresponding submit button has been pressed
//individual present button querying -- "1" refers to "Present" in statusdata table
if (!empty($_POST['present_bstudent'])) {
$name = $_POST['present_bstudent'];
changestatus($name, '1', '', $null_value);
}
//late status querying -- "5" refers to "Late" in statusdata table
if (!empty($_POST['Late'])) {
$name = $_POST['late_student'];
$status = $_POST['late_time'];
changestatus($name, '5', '', $status);
}
//absent buttons
if (!empty($_POST['Absent'])) {
$name = $_POST['absent_student'];
changestatus($name, '7', '', $null_value);
}
?>
<div id="top_header">
<div>
<a href="index.php">Return to main attendance view</a>
</div>
</div>
<!-- student information table rendering -->
<?php
if(!empty($_POST['datetimepicker'])){
$DateFromPicker = $_POST['datetimepicker'];
}
$student_data_array = array();
if (empty($DateFromPicker)){
$Date = new DateTime();
//echo "the date from picker is " . $DateFromPicker;
} else {
$Date = new DateTime($DateFromPicker);
}
?>
<h1 class="statusview_header"><?php echo "Attendance status as of " . $Date->format('l F jS \a\t g:ia'); ?></h1>
<form method='post' id="datepicker" action='<?php echo basename($_SERVER['PHP_SELF']); ?>'>
<input type='text' id="datetimepicker" class = 'datetimepicker' name='datetimepicker' placeholder="select a date">
<input type='submit' name='submit'>
</form>
<?php
$TimeFromPicker = $Date->format('Y-m-d H:i:s');
$DateFromPicker = $Date->format('Y-m-d');
//loops through current students
while ($current_student_id = $current_users_result->fetch_assoc()) {
//fetches most recent data from the events table
//joins with the tables that key student names/status names to the ids in the events table
$result = $db_server->query("SELECT firstname,lastname,statusname,studentdata.studentid,info,timestamp,returntime
FROM events
JOIN statusdata ON events.statusid = statusdata.statusid
RIGHT JOIN studentdata ON events.studentid = studentdata.studentid
WHERE studentdata.studentid = $current_student_id[studentid]
AND timestamp BETWEEN '$DateFromPicker' AND '$TimeFromPicker'
ORDER BY timestamp DESC
LIMIT 1")
or die(mysqli_error($db_server));
$result_array = $result->fetch_assoc();
//pushed each individual students data into an array
array_push($student_data_array, $result_array);
} ?>
<div class="column_wrapper">
<?php
//using the above data from the query, this renders the alternate status view
//creates a table header for each of the possible statuses
foreach ($status_array as $status) {
//calls the sort function to sort the array of students by subkey status
$sorted_data_array = subval_sort($student_data_array, 'statusname' , $status);
//only renders the table headers for statuses that have students assigned to that status
if (!empty($sorted_data_array)) {
$StudentCountPerStatus = 0;
foreach($sorted_data_array as $student){
$StudentCountPerStatus++;
}
$StudentPercent = $StudentCountPerStatus / $StudentCount;
$StudentPercent = $StudentPercent*100;
$StudentPercent = floor($StudentPercent);
?> <div class='altview_status'>
<style>
.hovertext, .statuslabel:hover span { display: none }
.statuslabel:hover .hovertext { display: inline }
</style>
<p class = statuslabel>
<span> <?php echo $status; ?> </span>
<span class = "hovertext"><?php echo $StudentCountPerStatus . " ≈ " . $StudentPercent . "%"; ?></span>
</p> <!-- header for each status -->
<ul class='altview_list'>
<?php
foreach ($sorted_data_array as $student) {
if (!empty($student['returntime'])) {
$returntime_statusview = new DateTime($student['returntime']);
$returntime_statusview = $returntime_statusview->format('g:i');
}
else {
$returntime_statusview = '';
}
?>
<li>
<?php
echo "<a class='unstyled-link' href=viewreports.php?id=" . $student['studentid'] . ">" . $student['firstname'] . " " . substr($student['lastname'], 0, 1) . " ";
if ($status == "Offsite" || $status == "Late" || $status == "Field Trip" || $status == "Independent Study") {echo $returntime_statusview;}
echo "</a>";
?>
</li>
<?php } ?>
</ul>
</div> <?php } } ?>
</div>
<?php
//globals query
$globalsquery = "SELECT * FROM globals";
$globals_result = $db_server->query($globalsquery);
$globalsdata = $globals_result->fetch_array();
$startdateforpicker = $globalsdata['startdate'];
$enddateforpicker = $globalsdata['enddate'];
$startdateforpicker = new DateTime($startdateforpicker);
$enddateforpicker = new DateTime($enddateforpicker);
$startdateforpicker = $startdateforpicker->format('Y/m/d');
$enddateforpicker = $enddateforpicker->format('Y/m/d');
?>
<script>
$('#datetimepicker').datetimepicker({
onGenerate:function( ct ){
jQuery(this).find('.xdsoft_date.xdsoft_weekend')
.addClass('xdsoft_disabled');
},
minDate:<?php echo(json_encode($startdateforpicker)); ?>,
maxDate:<?php echo(json_encode($enddateforpicker)); ?>,
format:'Y-m-d H:i:s',
step: 5,
});
</script>
</body>
</html>