-
Notifications
You must be signed in to change notification settings - Fork 0
/
attend_datesums.php
131 lines (121 loc) · 5.41 KB
/
attend_datesums.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
<?php
include('functions.php');
include('accesscontrol.php');
header1(_('Attendance Summary').(!empty($_POST['preselected']) ?
sprintf(_(' (%d People/Orgs Pre-selected)'),substr_count($_POST['preselected'],',')+1) : ''));
?>
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="style.php" type="text/css" />
<script type="text/JavaScript" src="js/jquery.js"></script>
<?php
if (!empty($_POST['preselected'])) {
?>
<script type="text/javascript">
$(document).ready(function() {
$(".eventcell>a, .sumcell>a").click(function(ev) {
ev.preventDefault();
$("#filterform").attr("action", $(this).attr("href")).submit();
return false;
});
});
</script>
<?php
} //end of if there is a preselected list
header2($_GET['nav']);
//echo "<pre>".print_r($_POST,true)."</pre>";
if ($_GET['nav']==1) echo '<h1 id="title">'._('Attendance Summary Chart').($_POST['preselected']!='' ?
sprintf(_(' (%d People/Orgs Pre-selected)'),substr_count($_POST['preselected'],',')+1) : '')."</h1>\n";
if (!$_REQUEST['emultiple']) {
die('Insufficient parameters - please select one or more events.');
}
$eids = implode(',', $_REQUEST['emultiple']);
//get the event info (row headings for table and event names for top of page)
$earray = array();
$events = '';
$result = sqlquery_checked("SELECT EventID,Event,UseTimes,Remarks FROM event WHERE EventID IN ($eids) ORDER BY Event");
while ($row = mysqli_fetch_object($result)) {
$events .= ', "'.$row->Event.'"';
$earray[] = $row;
}
echo '<h3>'._('Events').': '.substr($events,2);
if (!empty($_REQUEST['startdate']) && !empty($_REQUEST['enddate'])) printf(_(', between %s and %s'),$_REQUEST['startdate'],$_REQUEST['enddate']);
elseif (!empty($_REQUEST['startdate'])) printf(_(', on or after %s'),$_REQUEST['startdate']);
elseif (!empty($_REQUEST['enddate'])) printf(_(', on or before %s'),$_REQUEST['enddate']);
if (!empty($_POST['preselected'])) printf(_(' (%d People/Orgs Pre-selected)'),substr_count($_POST['preselected'],',')+1);
echo "</h3>";
//get the list of dates (column headings for table)
$sql = "SELECT DISTINCT AttendDate FROM attendance WHERE EventID IN ($eids)";
if (!empty($_POST['preselected'])) $sql .= " AND PersonID IN (".$_POST['preselected'].")";
if (!empty($_REQUEST["startdate"])) $sql .= " AND AttendDate >= '".$_REQUEST["startdate"]."'";
if (!empty($_REQUEST["enddate"])) $sql .= " AND AttendDate <= '".$_REQUEST["enddate"]."'";
$sql .= " ORDER BY AttendDate";
$result = sqlquery_checked($sql);
if (mysqli_num_rows($result) == 0) {
echo "<p>"._("There are no attendance records matching your criteria.")."</p>";
footer();
exit;
}
while ($darray[] = mysqli_fetch_row($result));
if (!empty($_POST['preselected'])) {
echo '<form id="filterform" method="post" action="" target="_blank">';
echo '<input type="hidden" id="preselected" name="preselected" value="'.$_POST['preselected'].'">';
}
echo '<table border="1" cellspacing="0" cellpadding="3">'."\n";
// loop for rows of the table
for ($r=0; $r<(count($earray)); $r++) {
echo '<tr>';
if ($r % 7 == 0) { // repeat header row every 7 rows
for ($c=0; $c<(count($darray)-1); $c++) {
if ($c % 15 == 0) { // repeat event info every 15 columns
echo '<td class="eventhead">Event</td>';
}
echo '<td class="';
switch (date("w",strtotime($darray[$c][0]))) {
case 0:
echo 'sundaydate';
break;
case 6:
echo 'saturdaydate';
break;
default:
echo 'weekdaydate';
}
echo '">'.substr($darray[$c][0],0,4).'<br />'.substr($darray[$c][0],5).'</td>';
}
echo '</tr><tr>';
}
//query for this event's total attendance numbers according to dates
$sql = "SELECT AttendDate,COUNT(PersonID) AS count".
($earray[$r]->UseTimes ? ",SUM(TIME_TO_SEC(SUBTIME(EndTime,StartTime))) DIV 60 AS minutes" : "").
" FROM attendance WHERE EventID=".$earray[$r]->EventID;
if (!empty($_REQUEST["startdate"])) $sql .= " AND AttendDate >= '".$_REQUEST["startdate"]."'";
if (!empty($_REQUEST["enddate"])) $sql .= " AND AttendDate <= '".$_REQUEST["enddate"]."'";
if (!empty($_POST['preselected'])) $sql .= " AND PersonID IN (".$_POST['preselected'].")";
$sql .= " GROUP BY AttendDate ORDER BY AttendDate";
$result = sqlquery_checked($sql);
$row = mysqli_fetch_object($result);
$done = 0;
// loop for cells in this row
for ($c=0; $c<(count($darray)-1); $c++) {
// repeat names every 15 columns
if ($c % 15 == 0) {
echo '<td class="eventcell"><a href="attend_detail.php?'.(!empty($_POST['preselected'])?'preselected='.$_POST['preselected']:'').
'&eid='.$earray[$r]->EventID.'" target="_blank"><span title="'.$earray[$r]->Remarks.'">'.
$earray[$r]->Event."</span></a></td>\n";
}
if (($done == 0) && ($row->AttendDate == $darray[$c][0])) { //matches date
echo '<td class="sumcell"><a href="list.php?eventselect1[]='.$earray[$r]->EventID.
'&astartdate1='.$darray[$c][0].'&aenddate1='.$darray[$c][0].'" target="_blank">'.$row->count.'</a>';
if ($earray[$r]->UseTimes) echo '<br />['.(($row->minutes-$row->minutes%60)/60).':'.sprintf("%02d",$row->minutes%60).']';
echo "</td>\n";
if (!$row = mysqli_fetch_object($result)) $done = 1;
} else {
echo '<td class="zerocell">0</td>';
}
}
echo "</tr>\n";
}
echo "</table>\n";
if (!empty($_POST['preselected'])) echo "</form>\n";
footer();
?>