forked from Bkoech/gbvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport_excel.php
executable file
·203 lines (155 loc) · 6.92 KB
/
import_excel.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
<?php
// TA:60:4
$page_title = "Education sector | 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->isSuperAdmin($user->user_group) || ($userTools->isAdmin($user->user_group) && $userTools->judiciary($user->sector)))){
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
$sector_id = $mode = $_GET['sector_id'];
$sector_excel_template = "";
$sector_url_data_enter = "";
$sector_title = "";
if($sector_id === '1'){
$sector_excel_template = "Sectors/Judiciary/files/Judiciary sector data entry sheet.xlsx";
$sector_url_data_enter = "Sectors/Judiciary/enter_data.php";
$sector_title = "Judiciary";
}else if($sector_id === '2'){
$sector_excel_template = "Sectors/Health/files/Health sector data entry sheet.xlsx";
$sector_url_data_enter = "Sectors/Health/enter_data.php";
$sector_title = "Health";
}else if($sector_id === '3'){
$sector_excel_template = "Sectors/Police/files/Police sector data entry sheet.xlsx";
$sector_url_data_enter = "Sectors/Police/enter_data.php";
$sector_title = "Police";
}else if($sector_id === '4'){
$sector_excel_template = "Sectors/Prosecution/files/Prosecution sector data entry sheet.xlsx";
$sector_url_data_enter = "Sectors/Prosecution/enter_data.php";
$sector_title = "Prosecution";
}else if($sector_id === '5'){
$sector_excel_template = "Sectors/Education/files/Education sector data entry sheet.xlsx";
$sector_url_data_enter = "Sectors/Education/enter_data.php";
$sector_title = "Education";
}else{
echo "<br><b> Wrong sector id selected.</b>";
return;
}
?>
<script type="text/javascript">
function uploadDataOld(){
//read file content
if (window.File && window.FileReader && window.FileList && window.Blob) {
var fileSelected = document.getElementById('fileToUpload');
//validate file extension
if(!fileSelected.value.endsWith('.csv')){
alert("Please upload CSV file.");
return;
}
var fileExtension = /text.*/;
var fileTobeRead = fileSelected.files[0];
if (fileTobeRead.type.match(fileExtension)) {
var fileReader = new FileReader();
fileReader.onload = function (e) {
var fileContents = document.getElementById('filecontents');
var file_content = fileReader.result.split(/\r\n|\n|\r/).join(";");
$.ajax({
type:"post",
url:"<?php echo $sector_url_data_enter;?>?mode=add_aggregates_csv&data=" + file_content,
beforeSend: function( ) {
document.getElementById("entry_form").style.visibility = "hidden";
$("#progress_bar").html("<img src='UI/images/data_loading_animation.gif' width=300 height=200/>");
}
})
.done(function( data ) {
$("#progress_bar").html("");
if(data){
alert(data);
}else{
alert("No any data were insirted into database.");
}
document.getElementById("entry_form").style.visibility = "visible";
clean_form();
});
}
fileReader.readAsText(fileTobeRead);
}
else {
alert("Please select CSV file");
}
}
else {
alert("Files are not supported by your browser");
}
}
function uploadData(){
$.ajax({
type:"post",
url:"Sectors/judiciary/enter_data.php?mode=add_aggregates_csv",
fileName: document.getElementById('fileToUpload').value();
beforeSend: function( ) {
document.getElementById("entry_form").style.visibility = "hidden";
$("#progress_bar").html("<img src='UI/images/data_loading_animation.gif' width=300 height=200/>");
}
})
.done(function( data ) {
$("#progress_bar").html("");
if(data){
alert(data);
}else{
alert("No any data were insirted into database.");
}
document.getElementById("entry_form").style.visibility = "visible";
clean_form();
});
}
</script>
<div id="main-content_with_side_bar">
<div id="content-body">
<!-- TA:60:1 -->
<div class="profile-data" align="left">
<!-- TA:60:1 START -->
<div id='progress_bar' align='center'style="position: absolute; top: 250px; left: 200px;"></div>
<div id="filecontents"></div>
<div id="entry_form">
<h2 class="page-title-section"><?php echo $sector_title;?> sector import excel</h2>
<table width="900px" border="0" cellspacing="5"
style='font-family: Verdana, Geneva, sans-serif; font-size: 12px;'>
<tr>
<td>
Instruction:<br>
1. Download Excel template <a href="<?php echo $sector_excel_template;?>">here</a><br>
2. Enter data into white cells only. <i>Gray cells are not editable. Do not change headers or do not move columns.</i><br>
3. Save file into your local computer<br>
3. When file is ready to be uploaded save file as CSV file. <i>In MS Excel: File -> Save As -> Save as type: CSV (Comma delimeted) (*.csv)</i><br>
4. Select file from your local computer: <input type="file" id="fileToUpload" name="fileToUpload" multiple size="50" ><br><br>
<button type="submit" name='submit' class="submit_button" onclick=uploadData();>Upload file</button>
</td>
</tr>
</table>
</div>
<br>
<!-- TA:60:1 END -->
<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");
}
?>