forked from Bkoech/gbvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport_excel_ud.php
executable file
·165 lines (128 loc) · 5.42 KB
/
import_excel_ud.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
<?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/Education 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/Education 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 uploadData(){
//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("\n").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");
}
}
</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>
Under development.
</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");
}
?>