forked from Bkoech/gbvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_data.php
executable file
·268 lines (223 loc) · 9.79 KB
/
export_data.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
257
258
259
260
261
262
263
264
265
266
267
268
<?php
//TA:60:4
$page_title = "Export Data | GBV";
$current_page = "home";
require_once 'includes/global.inc.php';
// check to see if they're logged in
if (isset ( $_SESSION ['logged_in'] )) {
// get the user object from the session
$user = unserialize ( $_SESSION ['user'] );
// if( !($userTools->isAdmin($user->user_group))){
// print " You do not have permission to access this page.";
// return;
// }
// include "includes/Dash_header.php";include "includes/topbar.php"; //TA:60:1
include "includes/Dash_header.php"; // TA:60:1
include "includes/topbar.php"; // TA:60:1
// TA:60:1
//$db = new DB ();
$sectors = $db->selectAllOrdered ( "sectors", "sector");
?>
<!-- TA:60:1 date picker libs -->
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script> <!-- for calrendar picker -->
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <!-- for calrendar picker -->
<script type="text/javascript">
$(function() {
$('#fromdate').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/yy',
showButtonPanel: true,
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function() {
if ((selDate = $(this).val()).length > 0)
{
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5),
$(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
}
});
});
$(function() {
$('#todate').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/yy',
showButtonPanel: true,
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function() {
if ((selDate = $(this).val()).length > 0)
{
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5),
$(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
}
});
});
function validate(title, value){
if(value == undefined || value == ""){
alert("Please select " + title);
return false;
}
return true;
}
function validateDates(from_date, to_date){
if(validate("From Date", from_date) && validate("To Date", to_date)){
var from_date_arr = from_date.split("/");
var to_date_arr = to_date.split("/");
var from_date_new = from_date_arr[1] + from_date_arr[0];
var to_date_new = to_date_arr[1] + to_date_arr[0];
if(from_date_new > to_date_new){
alert(from_date_new + ">" + to_date_new);
alert("'From Date' must be less than 'To Date'.");
return false;
}
return true;
}else{
return false;
}
}
function export_data(){
var sector_type_id = $( "#sector_type_id" ).val();
var indicator = $( "#indicator" ).val();
var from_date = $( "#fromdate" ).val();
var to_date = $( "#todate" ).val();
if(validate("sector", sector_type_id) && validate("indicator", indicator) && validateDates(from_date, to_date)){
if(sector_type_id == '1'){
window.location.href = "Sectors/Judiciary/export_data.php?mode=export_csv&indicator=" + indicator + "&start_date=" + from_date + "&end_date=" + to_date;
}else if(sector_type_id == '2'){
window.location.href = "Sectors/Health/export_data.php?mode=export_csv&indicator=" + indicator + "&start_date=" + from_date + "&end_date=" + to_date;
}else if(sector_type_id == '3'){
window.location.href = "Sectors/Police/export_data.php?mode=export_csv&indicator=" + indicator + "&start_date=" + from_date + "&end_date=" + to_date;
}else if(sector_type_id == '4'){
window.location.href = "Sectors/Prosecution/export_data.php?mode=export_csv&indicator=" + indicator + "&start_date=" + from_date + "&end_date=" + to_date;
}else if(sector_type_id == '5'){
window.location.href = "Sectors/Education/export_data.php?mode=export_csv&indicator=" + indicator + "&start_date=" + from_date + "&end_date=" + to_date;
}else{
alert("You cannot be redirected to selected sector.");
}
}
}
function getReportTypesList(){
var sel_sector_id = $( "#sector_type_id :selected" ).val();
$("#indicator option").remove();
$('#indicator').append($("<option></option>").attr("value","").text("-- Select Indicator --"));
if($('#sector_type_id').val() == 1){
$('#indicator').append($("<option></option>").attr("value","7.1-7.4").text("Indicators 7.1-7.4"));
}else if($('#sector_type_id').val() == 2){
$('#indicator').append($("<option></option>").attr("value","4.1").text("Indicator 4.1"));
$('#indicator').append($("<option></option>").attr("value","4.2").text("Indicator 4.2"));
$('#indicator').append($("<option></option>").attr("value","4.3-4.6").text("Indicators 4.3-4.6"));
}else if($('#sector_type_id').val() == 3){
$('#indicator').append($("<option></option>").attr("value","5.1,5.3,5.4").text("Indicators 5.1, 5.3, 5.4"));
$('#indicator').append($("<option></option>").attr("value","5.2").text("Indicator 5.2"));
}else if($('#sector_type_id').val() == 4){
$('#indicator').append($("<option></option>").attr("value","6.1").text("Indicator 6.1"));
$('#indicator').append($("<option></option>").attr("value","6.2").text("Indicator 6.2"));
}else if($('#sector_type_id').val() == 5){
$('#indicator').append($("<option></option>").attr("value","8.1-8.3").text("Indicators 8.1-8.3"));
$('#indicator').append($("<option></option>").attr("value","8.4").text("Indicator 8.4"));
}
}
</script>
<!-- TA:60:1 <div id="sidebar">
<div class="sidebar-nav">
<?php
// include "../includes/sidebar.php";
?>
</div>
</div> -->
<div id="main-content_with_side_bar">
<div id="content-body">
<!-- <center>
<h2 class="page-title">Welcome to the National Sexual Gender Violence
Information System (GBVIS)</h2>
</center>-->
<!-- TA:60:1 -->
<div class="profile-data" align="left">
<!-- TA:60:1 START -->
<br clear="all">
<table width="30%" border="0" align="left" cellspacing="10">
<tr>
<td><select id="sector_type_id" name="sector_type_id" class="gbvis_select" title="Select Sector" onchange="getReportTypesList();">
<?php
//if($userTools->isSuperAdmin($user->user_group)){
echo "<option value='0'>-- Select Sector --</option>";
//}
foreach ( $sectors as $urows ) {
$disable = " disabled ";
if($userTools->isSuperAdmin($user->user_group) || ($userTools->isAdmin($user->user_group) && $urows ['0'] === $user->sector)){
$disable = "";
}
if(!$disable) {
echo "<option value='" . $urows ['0'] . "' " . $disable . " >" . ucfirst($urows ['1']) . "</option>";
}
}
?>
</select></td>
</tr>
<tr>
<td><br>
<select id="indicator" name="indicator" class="gbvis_select" title="Select Indicator" placeholder="Select sector first">
<option value=''>Select sector first</option>
</select>
</td>
</tr>
<tr>
<td><br><input type="text" id="fromdate" name="fromdate"
placeholder="From Date" class="gbvis_smallBoxInputs"
title="From Date"> <input type="text" id="todate"
name="todate" placeholder="To Date"
class="gbvis_smallBoxInputs" title="To Date"></td>
</tr>
<tr>
<td><br><button type="button" class="submit_button"
onClick='export_data();'>Export data</button></td>
</tr>
</table>
<!-- TA:60:1 END -->
<!-- TA:60:1 <a href="stardard_reports.php" style="float:left; width:25%; height:100px; margin-right:15px; text-decoration:none;" title="Standard Reports" >
<p>Standard Reports</p> <p><img src="images/reports.jpeg" height="70" /></p>
</a>
<a href="analytical_reports.php" style="float:left; width:25%; height:100px; margin-right:15px; text-decoration:none;" >
<p>Analytical Reports</p><p><img src="images/analytical.jpeg" height="70" title="Analytical Reports" /></p>
</a>-->
<br clear="all"> <br clear="all">
<br clear="all">
<br clear="all">
<!-- Your MD5 encrypted password: <font color="white"><?php //echo $passwd; ?></font>-->
<br clear="all">
<br clear="all">
<br clear="all"> <br clear="all">
<br clear="all">
<br clear="all">
</div>
<br clear="all">
</center>
</div>
</div>
<?php
include "includes/footer.php";
}
else
{
//Redirect user back to login page if there is no valid session created
header("Location: login.php");
}
?>