csvxml/index.php
Joshua Ramon Enslin 9d73a9b61e Add anti-CSRF token
phpcs-errors:238 phpunit-status:successful
2020-07-03 16:41:31 +02:00

114 lines
3.5 KiB
PHP

<?PHP
/**
* New start page for CSVXML.
*
* @link https://groupit.museum-digital.de/csvxml/
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
error_reporting(E_ALL);
ini_set('display_errors', "1");
require_once __DIR__ . "/functions/functions.php";
if (session_status() != PHP_SESSION_ACTIVE) {
session_start();
}
// This array contains all available languages
$allowed_langs = ['ar', 'de', 'en', 'hu', 'id', 'it', 'pl','pt'];
// Some languages are in translation. They will only be available for logged in users.
if (isset($_GET['navlang'])) {
$_SESSION['lang'] = $_GET['navlang'];
if (!in_array($_SESSION['lang'], $allowed_langs)) $_SESSION['lang'] = 'de';
}
else if (!isset($_SESSION['lang'])) {
$_SESSION['lang'] = lang_getfrombrowser($allowed_langs, 'en', "", false);
}
$lang = $_SESSION['lang'];
require __DIR__ . "/translation-importer/$lang/csvxml-overview.php";
$toInject = '
<link rel="stylesheet" type="text/css" href="assets/css/editMenu.css" />
<script src="assets/js/newToolTip.js" type="text/javascript" defer></script>
';
echo printHTMLHead($toInject);
echo '
<div class="uploader">
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" id="csrf-token" name="csrf-token" aria-label="Anti-CSRF Token" value="' . htmlspecialchars(getAntiCsrfToken()) . '" />
<label for="fileToUpload">' . $csvxml_overview['select_csv_file_for_upload'] . '</label>
<input name="uploaded" type="file" accept=".csv" id="fileToUpload" required />
<button type="submit">' . $csvxml_overview['upload'] . '</button>
</form>
</div>
<div>
<h2>' . $csvxml_overview['currently_approved_tags'] . '</h2>
<div class="options">
<a href="csv.php" class="buttonLike">' . $csvxml_overview['download_csv_all'] . '</a>
<a class="buttonLike invisible" id="csvBySelection">' . $csvxml_overview['download_csv_by_selection'] . '</a>
<br />
<a class="buttonLike" id="selectRequired">' . $csvxml_overview['select_required_fields'] . '</a>
<a class="buttonLike" id="selectAll">' . $csvxml_overview['select_all_fields'] . '</a>
<a class="buttonLike invisible" id="unsetSelection">' . $csvxml_overview['unset_selection'] . '</a>
</div>
';
require __DIR__ . "/values/availableFields.php";
$tooltips = [];
foreach ($availableFields as $headline => $fields) {
echo "
<h3>{$headline}</h3>
<ul class='fieldList'>
";
foreach($fields as $fieldName => $field) {
if (!empty($field['remark']) or !empty($field['explica'])) $hasTooltip = true;
else $hasTooltip = false;
echo "
<li id='{$fieldName}' data-alt='{$field['name_human_readable']}' data-value='{$fieldName}' data-for='{$fieldName}' class='";
if ($hasTooltip === true) echo " newToolTipTag";
if (!empty($field['required']) and $field['required'] === true) echo " requiredField";
echo "'";
if (!empty($field['dependsOn'])) {
echo " data-dependencies='" . htmlspecialchars(implode(";", $field['dependsOn'])) . "'";
}
echo ">{$fieldName}";
if (!empty($field['explica'])) $toolTipExplica = "</p><h5>General</h5><p>" . $field['explica'];
else $toolTipExplica = "";
$toolTip = generateHelpTooltip($fieldName, $field['name_human_readable'], "{$field['remark']}{$toolTipExplica}");
if ($hasTooltip) $tooltips[] = $toolTip[0];
echo "</li>";
}
echo '
</ul>
';
}
echo '
</div>
';
echo implode($tooltips);
echo '
</body>
</html>
';