-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_specific.php
245 lines (243 loc) · 12.7 KB
/
report_specific.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
<!--Report page for specific queries that are too specific for a dynamic query system-->
<?php
$title = "IDCP - Generate a Report about Students in...";
$page = 'report';
$page_name = 'specific_rpt';
require('includes/header.php');
require( 'includes/report_helpers.php' ) ;
if ($_SERVER['REQUEST_METHOD'] == 'GET'){
$question = "";
$stu_dob = "";
$statement = "";
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$question = $_POST['question'];
if ($question == "stu_cert_more"){
$statement = "FROM STUDENT, CERT_EARNED WHERE STUDENT.STU_ID=CERT_EARNED.STU_ID GROUP BY CERT_EARNED.STU_ID HAVING COUNT(CERT_EARNED.STU_ID) > 1";
}
else if($question == "stu_complete_years"){
$statement = "FROM STUDENT, CRS_ENROLLED, COURSE WHERE STUDENT.STU_ID=CRS_ENROLLED.STU_ID AND COURSE.CRS_ID=CRS_ENROLLED.CRS_ID AND CRS_LEVEL='Expert' AND CRS_ENROLLED.STU_ID IN (SELECT STU_ID FROM CRS_ENROLLED, COURSE WHERE CRS_ENROLLED.CRS_ID = COURSE.CRS_ID AND CRS_LEVEL='Professional' AND STU_ID IN (SELECT STU_ID FROM CRS_ENROLLED , COURSE WHERE CRS_ENROLLED.CRS_ID = COURSE.CRS_ID AND CRS_LEVEL='Associates'))";
}
else if($question == "stu_complete_last_years"){
$year_now = date("Y");
$year_before = $year_now - 5;
$statement = ",CRS_ENROLL_START, CRS_ENROLL_END FROM STUDENT, CRS_ENROLLED WHERE STUDENT.STU_ID=CRS_ENROLLED.STU_ID AND CRS_ENROLL_START >= '$year_before-01-01' ";
}
else{
$stu_dob = $_POST['stu_dob'];
$statement = ",STU_DOB FROM STUDENT, CRS_ENROLLED WHERE STUDENT.STU_ID=CRS_ENROLLED.STU_ID AND STU_DOB > '$stu_dob'";
}
}
?>
<!-- style for printing -->
<style>
.example-print {
display: none;
}
@media print {
.example-screen {
display: none;
}
.example-print {
display: block;
}
}
</style>
<!-- Bread Crumbs -->
<ol class = "breadcrumb">
<li><a href = "home.php">Home</a></li>
<li><a href = "generate_report.php">Generate a Report</a></li>
<li class = "active">Specific Queries</li>
</ol>
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container" style="padding-right: 100px; max-width: 1100px;">
<div class="dropdown">
<div class="page-header">
<h1>Generate Specific Reports</h1>
</div>
<br>
<form action="report_specific.php" method="POST" class="form-horizontal" role="form" data-toggle="validator">
<div class="form-group">
<label class="col-xs-3 control-label">Question:*</label>
<div class="col-xs-6">
<select class="form-control" id="question1" name="question" value="<?php if (isset($_POST['question'])) echo $_POST['question'];?>" onchange="displayFields()" data-error="Please choose a field" required>
<option disabled selected value>-- select an option --</option>
<option value="stu_cert_more">How many students have completed more than one certificate?</option>
<option value="stu_complete_years">How many students have completed associate, professional, & expert level courses?</option>
<option value="stu_complete_last_years">How many undergraduates have taken our courses in the last five years?</option>
<option value="stu_dob_after">How many students who took our course were born after...</option>
</select>
</div>
<div class="help-block with-errors"></div>
</div>
<div id="stu_dob_field" class="form-group" style="display:none">
<label class="col-xs-3 control-label" for="stu_dob">Birthdate*</label>
<div class="col-xs-3">
<input type="date" class="form-control" id="stu_dob1" name="stu_dob" data-error="Please select a birthdate" required>
</div>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-lg-12">
<?php
if ($_SERVER[ 'REQUEST_METHOD' ] == 'POST') {
require('includes/connect_db_c9.php');
if(!empty($_SESSION['sel'])){
$sel = $_SESSION['sel'];
$statement = "SELECT DISTINCT * FROM (". $_SESSION['query']. ") AS NEW WHERE STU_ID IN (SELECT STU_ID FROM $sel)";
show_complex_report($dbc,$statement);
unset($_SESSION['sel']);
}
else{
if ($question == "stu_cert_more"){
$_SESSION['eng_statement'] = "How many students have completed more than one certificate";
}
else if($question == "stu_complete_years"){
$_SESSION['eng_statement'] = "How many students have completed associate, professional, & expert level courses";
}
else if($question == "stu_complete_last_years"){
$_SESSION['eng_statement'] = "How many undergraduates have taken our courses in the last five years";
}
else{
$_SESSION['eng_statement'] = "How many students who took our course were born after $stu_dob";
}
show_specific_report($dbc,$statement);
unset($_SESSION['sel']);
}
}
?>
<br>
<?php
if ($_SERVER[ 'REQUEST_METHOD' ] == 'POST') {
echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#more_query" style="margin-right: 50px; height: 50px; width: 300px;">How many of these students...</button>';
echo '<button type="button" class="btn btn-primary" style="margin-right: 50px; height: 50px; width: 200px;" onclick="printDiv(\'printableArea\')"><i class="glyphicon glyphicon-print"></i> Print</button>';
echo '<a href="#" id="xx" role="button" class="btn btn-primary" style="margin-right: 50px; padding-top: 15px; height: 50px; width: 300px;"><i class="glyphicon glyphicon-download-alt"></i> Export to Excel (.csv) </a>';
}
?>
<br>
<br>
<button class="btn btn-default btn-sm" onclick ="location.href='generate_report.php';">Back to Report Home</button>
</div>
<!-- modal dialog for more queries -->
<div class="modal fade" id="more_query" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">How many of these students...</h4>
</div>
<div class="modal-body">
<form id="more_query_form" action="includes/modal_helper.php" method="POST">
<label>Have completed a:*</label>
<select class="form-control" id="sel1" name="sel" value="<?php if (isset($_POST['sel'])) echo $_POST['sel'];?>" data-error="Please choose a field" required>
<option value="program">Program</option>
<option value="course">Course</option>
<option value="certificate">Certificate</option>
</select>
<div class="help-block with-errors"></div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="submitForm" class="btn btn-success">Submit</button>
</div>
</div>
</div>
</div>
<!--end modal-->
</div>
<!-- /#container close -->
</div>
<!--Footer-->
<?php require('includes/footer.php'); ?>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- export -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
function exportTableToCSV($table, filename) {
var $rows = $table.find('tr:has(td),tr:has(th)'),
// Temporary delimiter characters unlikely to be typed by keyboard
// This is to avoid accidentally splitting the actual contents
tmpColDelim = String.fromCharCode(11), // vertical tab character
tmpRowDelim = String.fromCharCode(0), // null character
// actual delimiter characters for CSV format
colDelim = '","',
rowDelim = '"\r\n"',
// Grab text from table into CSV formatted string
csv = '"' + $rows.map(function (i, row) {
var $row = $(row), $cols = $row.find('td,th');
return $cols.map(function (j, col) {
var $col = $(col), text = $col.text();
return text.replace(/"/g, '""'); // escape double quotes
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowDelim)
.split(tmpColDelim).join(colDelim) + '"',
// Data URI
csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
console.log(csv);
if (window.navigator.msSaveBlob) { // IE 10+
//alert('IE' + csv);
window.navigator.msSaveOrOpenBlob(new Blob([csv], {type: "text/plain;charset=utf-8;"}), "csvname.csv")
}
else {
$(this).attr({ 'download': filename, 'href': csvData, 'target': '_blank' });
}
}
// This must be a hyperlink
$("#xx").on('click', function (event) {
exportTableToCSV.apply(this, [$('#report'), 'IDCP_Report.csv']);
// IF CSV, don't do event.preventDefault() or return false
// We actually need this to be a typical hyperlink
});
});
</script>
<!-- Modals -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
/* must apply only after HTML has loaded */
jQuery(document).ready(function() {
$("#more_query_form").on("submit", function(e) {
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax({
url: formURL,
type: "POST",
data: postData,
success: function() {
window.location.reload();
$("#submitForm").remove();
},
error: function() {
console.log(status + ": " + error);
}
});
e.preventDefault();
});
$("#submitForm").on('click', function() {
$("#more_query_form").submit();
});
});
</script>
<!-- Hide fields until question selected -->
<script src="js/report.js"></script>
<!-- Print Help -->
<script src="js/printhelper.js"></script>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Validator Bootstrap Plugin-->
<script src="js/validator.js"></script>
</body>
</html>