3
0
Fork 0
mirror of https://github.com/fsr/eseeva synced 2024-11-15 00:43:12 +01:00
eseeva/keyTable.php

148 lines
5.9 KiB
PHP
Raw Normal View History

2014-07-08 20:14:37 +02:00
<?php
//============================================================================
// Name : keyTable.php
// Author : Patrick Reipschläger, Lucas Woltmann
// Version : 2.0
// Date : 01-2017
2014-07-08 20:14:37 +02:00
// Description : For managing all keys and their states.
//============================================================================
include_once 'libs/keyLib.php';
include_once 'libs/formLib.php';
// start a session prevent sending the same post twice
session_start();
2014-07-08 20:14:37 +02:00
$keyFile = KEYFILE;
if (isset($_GET["keyFile"]))
$keyFile = $_GET["keyFile"];
else
// holds the key data, either be generated from the form or by from the database
2014-07-08 20:14:37 +02:00
$keyData;
// if the submission ids of the post and the form don't match, the
// user has refreshed the site and thus its reseted to the default state
if (isset($_SESSION["submissionId"]) && ($_SESSION["submissionId"] == $_POST["submissionId"]))
2014-07-08 20:14:37 +02:00
{
//user changes the states of some keys or deletes keys
2014-07-08 20:14:37 +02:00
if (isset($_POST["changesConfirm"]))
{
$i = 0;
while(isset($_POST["keyIndex" . $i]))
{
if (isset($_POST["keyDelete" . $i]))
DeleteKey($keyFile, $_POST["keyCode" . $i]);
else
SetKeyState($keyFile, $_POST["keyCode" . $i], $_POST["keyState" . $i]);
2014-07-08 20:14:37 +02:00
$i++;
}
$keyData = ReadKeys($keyFile);
2014-07-08 20:14:37 +02:00
}
//user generates new keys
2014-07-08 20:14:37 +02:00
else if (isset($_POST["keyGenNew"]))
{
$amount = $_POST["keyAmount"];
$keyFile = $_POST["keyFile"];
CreateKeys($amount, $keyFile);
$keyData = ReadKeys($keyFile);
2014-07-08 20:14:37 +02:00
}
//user appends new keys
2014-07-08 20:14:37 +02:00
else if (isset($_POST["keyGenAppend"]))
{
$amount = $_POST["keyAmount"];
2014-07-08 20:14:37 +02:00
$keyFile = $_POST["keyFile"];
CreateKeys($amount, $keyFile);
$keyData = ReadKeys($keyFile);
2014-07-08 20:14:37 +02:00
}
else
$keyData = ReadKeys($keyFile);
2014-07-08 20:14:37 +02:00
}
// if the page was refreshed by the user, just load the key file
else
$keyData = ReadKeys($keyFile);
2014-07-08 20:14:37 +02:00
// generate a new submission id that is used within the form to prevent double posts
$_SESSION["submissionId"] = rand();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ESE Evaluation für Studenten</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<?php
CreateHeadLine("Key Control Panel");
?>
<?php
echo "<form action=\"keyTable.php?keyFile=" . $keyFile . "\" method=\"post\">\n";
CreateSectionHeader("Key Overview");
CreateRowHeader();
echo " <div class=\"col-1\">\n <p class=\"lead\">Index</p>\n </div>\n";
echo " <div class=\"col-6\">\n <p class=\"lead\">Code</p>\n </div>\n";
echo " <div class=\"col-2\">\n <p class=\"lead\">State</p>\n </div>\n";
echo " <div class=\"col-1\">\n <p class=\"lead\">Delete</p>\n </div>\n";
echo "</div>";
for ($i = 0; $i < count($keyData); $i++)
{
CreateRowHeader();
echo " <div class=\"col-1\">\n";
echo " <p class=\"lead\">" . $i . "</p>\n";
echo " <input type=\"hidden\" name=\"keyIndex" . $i . "\" value=\"" . $i . "\"/>";
echo " </div>\n";
echo " <div class=\"col-6\">\n";
echo " <input type=\"textbox\" class=\"form-control\" name=\"keyCode" . $i . "\" value=\"" . $keyData[$i]["KeyId"] . "\" readonly/>\n";
2014-07-08 20:14:37 +02:00
echo " </div>\n";
echo " <div class=\"col-2\">\n";
echo " <select class=\"form-control lead\" name=\"keyState" . $i . "\">";
echo " <option value=\"" . KEYSTATE_UNISSUED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_UNISSUED) echo " selected"; echo">" . KEYSTATE_UNISSUED . "</option>";
echo " <option value=\"" . KEYSTATE_ISSUED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_ISSUED) echo " selected"; echo">" . KEYSTATE_ISSUED . "</option>";
echo " <option value=\"" . KEYSTATE_ACTIVATED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_ACTIVATED) echo " selected"; echo">" . KEYSTATE_ACTIVATED . "</option>";
echo " <option value=\"" . KEYSTATE_USED . "\""; if ($keyData[$i]["Status"] == KEYSTATE_USED) echo " selected"; echo">" . KEYSTATE_USED . "</option>";
2014-07-08 20:14:37 +02:00
echo " </select>";
echo " </div>\n";
echo " <div class=\"col-1\">\n";
echo " <input type=\"checkbox\" class=\"form-control\" name=\"keyDelete" . $i . "\"/>\n";
echo " </div>\n";
echo "</div>\n";
}
CreateRowHeader();
echo " <div class=\"col-5\">\n <input type=\"submit\" class=\"form-control btn-success\" name=\"changesConfirm\" value=\"Confirm Changes\"/>\n </div>\n";
2014-07-08 20:14:37 +02:00
echo " <div class=\"col-2\"></div>\n";
echo " <div class=\"col-5\">\n <input type=\"submit\" class=\"form-control btn-danger\" name=\"changesDiscard\" value=\"Discard Changes\"/>\n </div>\n";
2014-07-08 20:14:37 +02:00
echo "</div>\n";
// Hidden input with previously generated id - used for preventing double posts
echo "<input type=\"hidden\" value=\"" . $_SESSION['submissionId'] . "\" name=\"submissionId\" />\n";
echo "</form>\n";
?>
<?php
echo "<form action=\"keyTable.php?keyFile=" . $keyFile . "\" method=\"post\">\n";
CreateSectionHeader("Key File Manipulation");
CreateTextBox("Number of keys", "keyAmount", "10");
CreateTextBox("Key file name", "keyFile", $keyFile);
CreateRowHeader();
echo " <div class=\"col-5\">\n <input type=\"submit\" class=\"form-control btn-success\" name=\"keyGenNew\" value=\"Generate New Key File\"/>\n </div>\n";
2014-07-08 20:14:37 +02:00
echo " <div class=\"col-2\"></div>\n";
echo " <div class=\"col-5\">\n <input type=\"submit\" class=\"form-control btn-warning\" name=\"keyGenAppend\" value=\"Append existing Key File\"/>\n </div>\n";
2014-07-08 20:14:37 +02:00
echo "</div>\n";
// Hidden input with previously generated id - used for preventing double posts
echo "<input type=\"hidden\" value=\"" . $_SESSION['submissionId'] . "\" name=\"submissionId\" />\n";
echo "</form>\n";
?>
</div>
</body>
</html>