File: /home/imensosw/demo.imensosoftware.com/matrix/admin/show_doc.php
<?php
include 'admin_header.php';
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/error.log');
require '../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
/**
* ============================
* INPUT (SECURE)
* ============================
*/
$assignment_no = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['assignment_no'] ?? '');
if (empty($assignment_no)) {
die("Invalid assignment");
}
/**
* ============================
* FILE RESOLUTION
* ============================
*/
$xls = "../docs/$assignment_no/$assignment_no.xls";
$xlsx = "../docs/$assignment_no/$assignment_no.xlsx";
if (file_exists($xls)) {
$inputFileName = $xls;
} elseif (file_exists($xlsx)) {
$inputFileName = $xlsx;
} else {
die("File not found");
}
/**
* ============================
* LOAD EXCEL (FAST)
* ============================
*/
$spreadsheet = IOFactory::load($inputFileName);
$data = $spreadsheet->getSheet(0)->toArray(); // FAST
?>
<div class="container-area">
<div class="container-fluid h-100">
<div class="row">
<!-- LEFT SIDE -->
<div class="left-side border-right">
<ul class="list-group list-group-flush">
<?php
foreach ($data as $index => $row) {
// Skip header
if ($index === 0 || empty($row[0]) || $row[0] === "Document ID") {
continue;
}
// Determine status
if (!empty($row[3])) {
$check_data = "done doubt";
} elseif (!empty($row[2]) || !empty($row[1])) {
$check_data = "done";
} else {
$check_data = "default";
}
?>
<li class="list-group-item p-0 <?= $check_data ?>">
<a href="javascript:;"
class="row_link"
data-row_id="<?= $index ?>"
data-doc_id="<?= htmlspecialchars($row[0]) ?>">
<?= htmlspecialchars($row[0]) ?>
</a>
</li>
<?php } ?>
</ul>
</div>
<!-- RIGHT SIDE -->
<div class="right-side">
<div class="row h-100">
<div class="col-md-12 h-100">
<iframe id="row_iframe" src="" width="100%" class="h-100"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var app = app || {};
/* ================= DOCUMENT STATE ================= */
app.document = {
docId: "",
rowId: "",
assignment_no: "<?= $assignment_no ?>"
};
/* ================= CLICK ROW ================= */
$(document).on('click', '.row_link', function () {
app.document.docId = $(this).data('doc_id');
app.document.rowId = $(this).data('row_id');
app.clickToDocId();
});
/* ================= DEFAULT LOAD ================= */
$(document).ready(function () {
const first = $('.list-group-item a').first();
if (first.length) {
first.trigger('click');
first.closest('li').addClass('active');
}
});
/* ================= DOCUMENT VIEW ================= */
app.clickToDocId = function () {
if (!app.document.assignment_no || !app.document.docId) {
console.warn("Missing document info");
return;
}
const pdfPath = "../docs/" + app.document.assignment_no + "/" + app.document.docId + ".pdf";
$("#row_iframe").attr("src", pdfPath);
$('ul.list-group > li.active').removeClass('active');
$('ul')
.find('[data-doc_id="' + app.document.docId + '"]')
.closest('li')
.addClass('active');
};
</script>