I have a user interface that interacts with some software.
My user interface displays a database with data paths. The user selects the data paths they want to simulate/run, and that sends the data path to the software. After its finished the output is an excel report saved in a folder on the same computer. This is were I'm a bit stuck on how exactly I'm supposed to show the excel report to the user for the specified data path the user selected to simulate/run.
My idea was to create a routine that converts the excel report to pdf and then saves the file path of the report to a database. I then create a div with id="result" to be displayed inside a table row for the specified path selected and loads pdf_report.php which then displays the desired report.
The problem is that every time I reload the page the div tag goes away. I tried using localstorage but it still doesn't get displayed after page reload.
My code is the following:
**Lets the user simulate/run the path selected
Search.php
<?php
...
while($row = $result->fetch_assoc()){
$field1name = $row["test_id"];
$field2name = $row["path"];
$field3name = $row["video1_path"];
$field4name = $row["video2_path"];
$field5name = $row["video3_path"];
$field6name = $row["video4_path"];
echo "<tr>
<td> ".$field1name." </td>
<td> ".$field2name." </td>
<td> ".$field3name." </td>
<td> ".$field4name." </td>
<td> ".$field5name." </td>
<td> ".$field6name." </td>
<td><div>
<button class='edit' id='" . $row['test_id'] . "' >Run</button>
</div></td>
<td><div id='result'>
<p></p>
</div></td>
</tr>";
}
}else {
echo '<span style="color:#ff0000;text-align:center;">No Test ID Selected!</span>';
}
}
// Close connection
mysqli_close($conn);
?>
</table>
</div><br>
<div style="overflow-x:auto;">
<table id=test_data>
<tr>
<th>Progress</th>
<th>Progress Status</th>
</tr>
<tr>
<td><div><progress id='progBar' value='0' max='100'></progress></div></td>
<td><div><p id='progress-text'></p></div></td>
</tr>
</table>
</div>
<script type="text/javascript">
var show = localStorage.getItem('showDiv');
if(show === 'true'){
$("#result").show();
}
</script>
<!--Uses jquery to run 3 scripts and displays it in a progress bar-->
<script>
$(document).on('click', '.edit', function(event){
//set cookie value to 'path'
var fcookie='mycookie';
//if button inside row is clicked the path gets saved to a cookie and received in ajax.php
var test_id = $(this).attr('id');
if(test_id) {
var path = $(this).closest('tr').find("td:nth-child(2)").text();
//Cookie gets saved
document.cookie='fcookie='+path;
var $this = $(this);
//Start of 1st script
$.ajax({
url: "ajax.php",
type:"POST",
success: function(data) {
//alert("File 1 Completed")
$("#progress-text").text("Executing file 1");
$('#progBar').val(25);
//Start of 2nd script
$.ajax({
url: "ajax2.php",
type:"POST",
success: function(data2) {
//alert("File 2 Completed")
$("#progress-text").text("Executing file 2");
$('#progBar').val(50);
//Start of 3rd script
$.ajax({
url: "ajax3.php",
type:"POST",
success: function(data3) {
//alert("File 2 Completed")
$("#progress-text").text("Complete");
$('#progBar').val(100);
//Displays the <div id=result> for the selected data path
$this.closest("tr").find("td:nth-child(8)").load("pdf_report.php");
event.preventDefault();
$("#result").show();
localStorage.setItem('showDiv', true);
}
});
}
});
}
});
}
});
</script>