116 lines
4.8 KiB
JavaScript
116 lines
4.8 KiB
JavaScript
|
/**
|
||
|
* /script/admin.js
|
||
|
* @version 1.3
|
||
|
* @desc Javascript file for the admin submenu
|
||
|
* @author Fándly Gergő Zoltán (fandlygergo@gmail.hu, systemtest.tk)
|
||
|
* @copy 2017 Fándly Gergő Zoltán
|
||
|
* License:
|
||
|
Result Manager for managing results of students in bilingual school systems.
|
||
|
Copyright (C) 2017 Fándly Gergő Zoltán
|
||
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
**/
|
||
|
|
||
|
function adminImportUsers(){
|
||
|
//hide all status messages if any shown
|
||
|
$("#statuses").children().each(function(){
|
||
|
$(this).css("display", "none");
|
||
|
});
|
||
|
|
||
|
//get file
|
||
|
var file=$("#csvFile")[0].files[0];
|
||
|
|
||
|
//if greater than 10MB don't upload
|
||
|
if(file.size>10000000){
|
||
|
$("#status_fileTooBig").slideDown();
|
||
|
return;
|
||
|
}
|
||
|
else{
|
||
|
$("#status_uploading").slideDown(function(){
|
||
|
//generate form data
|
||
|
var data=new FormData();
|
||
|
data.append("import_file", file);
|
||
|
|
||
|
//run ajax upload request
|
||
|
$.ajax({
|
||
|
url: "./subs/loader.php?load=admin&backend",
|
||
|
type: "POST",
|
||
|
data: data,
|
||
|
cache: false,
|
||
|
contentType: false,
|
||
|
processData: false,
|
||
|
xhr: function(){
|
||
|
var myXHR=$.ajaxSettings.xhr();
|
||
|
if(myXHR.upload){
|
||
|
myXHR.upload.addEventListener("progress", function(e){
|
||
|
if(e.lengthComputable){
|
||
|
//calculate percent with 1 decimal precision
|
||
|
var percent=Math.round(e.loaded*100/e.total*10)/10;
|
||
|
percent=percent.toString()+"%";
|
||
|
|
||
|
//upload progressbar
|
||
|
$("#uploadStatus").children("div").css("width", percent);
|
||
|
$("#uploadStatus").children("div").children("span").text(percent);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
return myXHR;
|
||
|
},
|
||
|
success: function(response){
|
||
|
$("#status_uploading").slideUp();
|
||
|
|
||
|
//something went wrong during the upload
|
||
|
if(response=="error"){
|
||
|
loadMessages();
|
||
|
$("#status_uploadError").slideDown();
|
||
|
}
|
||
|
else{
|
||
|
//everything ok so far
|
||
|
$("#status_processing").slideDown();
|
||
|
|
||
|
//start listener that checks processing status (run every 500ms)
|
||
|
var progressChecker=setInterval(function(){
|
||
|
$.ajax({
|
||
|
url: "./subs/loader.php",
|
||
|
type: "GET",
|
||
|
data: {"load":"admin", "backend":true, "import_progress":response},
|
||
|
success: function(response2){
|
||
|
//update progressbar
|
||
|
$("#processStatus").children("div").css("width", response2);
|
||
|
$("#processStatus").children("div").children("span").text(response2);
|
||
|
}
|
||
|
});
|
||
|
}, 500);
|
||
|
|
||
|
//start processing of file with ajax
|
||
|
$.ajax({
|
||
|
url: "./subs/loader.php?load=admin&backend",
|
||
|
type: "POST",
|
||
|
data: {"process_file":response},
|
||
|
success: function(response2){
|
||
|
//import complete
|
||
|
$("#status_processing").slideUp();
|
||
|
$("#status_done").slideDown();
|
||
|
|
||
|
//stop progress checker
|
||
|
clearInterval(progressChecker);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|