168 lines
4.5 KiB
PHP
168 lines
4.5 KiB
PHP
<?php
|
|
$targetDirectory = "uploads/";
|
|
$targetFile = $targetDirectory . basename($_FILES["fileToUpload"]["name"]);
|
|
$uploadOk = 1;
|
|
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
|
|
|
|
// check if file already exists
|
|
if (file_exists($targetFile)) {
|
|
// echo "Sorry, file already exists.";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// check file size
|
|
if ($_FILES["fileToUpload"]["size"] > 500000) {
|
|
// echo "Sorry, your file is too large.";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// allow certain file formats
|
|
if ($imageFileType != "pdf") {
|
|
// echo "Sorry, only PDF files are allowed.";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// check if $uploadOk is set to 0 by an error
|
|
if ($uploadOk == 0) {
|
|
// echo "Sorry, your file was not uploaded.";
|
|
|
|
// otherwise upload file
|
|
} else {
|
|
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
|
|
// echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
|
|
} else {
|
|
// echo "Sorry, there was an error uploading your file.";
|
|
}
|
|
}
|
|
|
|
$fileName = htmlspecialchars(basename($_FILES["fileToUpload"]["name"]));
|
|
|
|
// process file
|
|
$output = shell_exec("java -jar TaskSheetChecker.jar " . $targetDirectory . $fileName);
|
|
exec("rm " . $targetDirectory . $fileName);
|
|
|
|
$keySeparator = ',';
|
|
$delimiter = ';';
|
|
|
|
$keyArray = array();
|
|
$valueArray = array();
|
|
|
|
$currentString = "";
|
|
|
|
for ($i = 0; $i < strlen($output); $i++) {
|
|
if ($output[$i] == $keySeparator) {
|
|
array_push($keyArray, $currentString);
|
|
$currentString = "";
|
|
} else if ($output[$i] == $delimiter) {
|
|
array_push($valueArray, $currentString);
|
|
$currentString = "";
|
|
} else
|
|
$currentString = $currentString . $output[$i];
|
|
}
|
|
|
|
// remove field that are not filled by student
|
|
array_splice($keyArray, 0, 4);
|
|
array_splice($valueArray, 0, 4);
|
|
|
|
$emptyFields = 0;
|
|
$filledFields = 0;
|
|
|
|
foreach ($valueArray as $value) {
|
|
if (strlen($value) == 0)
|
|
$emptyFields++;
|
|
else
|
|
$filledFields++;
|
|
}
|
|
?>
|
|
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta name="description" content="">
|
|
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
|
|
<meta name="generator" content="Jekyll v4.1.1">
|
|
<title>NES Sheet Checking Tool</title>
|
|
|
|
<link rel="canonical" href="https://getbootstrap.com/docs/4.5/examples/dashboard/">
|
|
|
|
<!-- Bootstrap core CSS -->
|
|
<link href="./assets/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
<style>
|
|
.bd-placeholder-img {
|
|
font-size: 1.125rem;
|
|
text-anchor: middle;
|
|
-webkit-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
}
|
|
|
|
@media (min-width: 768px) {
|
|
}
|
|
</style>
|
|
<!-- Custom styles for this template -->
|
|
<link href="status.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
|
|
<a class="navbar-brand col-md-3 col-lg-2 mr-0 px-3">Sheet Checking Tool</a>
|
|
</nav>
|
|
|
|
<div class="container">
|
|
|
|
<h2>Document Status</h2>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-sm">
|
|
|
|
<tbody>
|
|
<tr>
|
|
<th>Unfilled fields</th>
|
|
<td><p style="color:red"><?php echo $emptyFields; ?></p></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Filled fields</th>
|
|
<td><p style="color:green"><?php echo $filledFields; ?></p></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container-fluid">
|
|
|
|
<h2>Field Overview</h2>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>Field</th>
|
|
<th>Answer</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
|
|
<?php
|
|
for ($i = 0; $i < count($keyArray); $i++) {
|
|
echo '<tr>';
|
|
echo '<td>' . $keyArray[$i] . '</td>';
|
|
echo '<td>' . $valueArray[$i] . '</td>';
|
|
if (strlen($valueArray[$i]) == 0)
|
|
echo '<td><p style="color:red">EMPTY</p></td>';
|
|
else
|
|
echo '<td><p style="color:green">OK</p></td>';
|
|
echo '</tr>';
|
|
}
|
|
?>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</html>
|
|
|
|
|