I'm currently working on an Employee Work Monitoring, where their output as encoder will be monitored by recording when they start and finished the needed documents.
After they finished encoding they save the final data in a server based on the category. So the data is not stored in one folder only, it has multiple folders.
example : data1 :
server/category1/000000-1/000000-1-final data.pdf
server/category2/000000-2/000000-2-final data.pdf
As you can see in this sample image, before staff can finished one output, they have to click first a button. This button will check or search for the data (where filename is same as the work code) in server if it exist. Reason for this is to make sure they encode correctly the standard filename for the data. They cannot finished one output if filename is incorrect/doesn't exist.
How can I achieve this kind of logic? Where it must search for different folder to check the data.
If it exists then update the SQL table by timestamp as value of finished column.
This is what I've tried for the function of the button:
var id = $(this).attr('id').split('-')[1]
var work_code = document.getElementById('work_code-'+id).value;
$.ajax({ /// CHECK PHP SCRIPT IF TRUE
type:'post',
url: 'checkData.php',
data:{
work_code: work_code
},
success: function() { /// if file found
$("#CheckButton").css("display","none"); // hides the button when click
$('#Finished-'+id).html(CurrentTimestamp) // make column value to timestamp
var value = (CurrentTimestamp);
var column = $("#Finished-"+id).attr('id').split('-')[0]
$.ajax({ /// if file found then update value of sql
type:'post',
url: 'editable.php',
data:{
value: value,
id: id,
column: column
}
}).done(function(data){
GrowlNotification.notify({
title: 'DATA FOUND!',
description: 'Plan Successfully Finished',
showProgress: false,
image: {
visible: true,
customImage: 'Images/success.png'
},
type: 'success',
position: 'top-right',
closeTimeout: 2000
});
setTimeout(function(){
sessionStorage.reloadAfterPageLoad = true;
window.location.reload(); // then reload the page.(3)
}, 2500);
})
},
error: function() { // if file not found
swal("DATA NOT FOUND!", "Please double check data's filename.", {
icon: 'error',
button: false,
timer: 1900,
});
}
});
})
This is the script for checkData.php
: (This part is what I don't know what to put in order to check the data in server.)
<?php
$server = 'http://10.000.00.00:0000/';
$cat1 = $server.'/category1'.$_REQUEST["work_code"].'/'.$_REQUEST["work_code"].'-final data.pdf';
$cat2 = $server.'/category2'.$_REQUEST["work_code"].'/'.$_REQUEST["work_code"].'-final data.pdf';
// condition to check if file exist
if (fopen($cat1,"r") || fopen($cat2,"r")) {
return true;
}else{
return false;
}
?>