77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
|
<?PHP
|
||
|
/**
|
||
|
* Generates a CSV template based on the field list provided for 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'];
|
||
|
|
||
|
if (!empty($_POST) and !empty($_POST['selectedFields'])) {
|
||
|
$selectionActive = true;
|
||
|
$selectedFields = explode(",", trim($_POST['selectedFields'], ","));
|
||
|
}
|
||
|
else $selectionActive = false;
|
||
|
|
||
|
require __DIR__ . "/values/availableFields.php";
|
||
|
|
||
|
$line1 = $line2 = $line3 = $line4 = [];
|
||
|
|
||
|
$tLine1 = $tLine2 = $tLine3 = $tLine4 = [];
|
||
|
foreach ($availableFields as $headline => $fields) {
|
||
|
|
||
|
$i = 0;
|
||
|
$tLine1[] = $headline;
|
||
|
|
||
|
foreach($fields as $fieldName => $field) {
|
||
|
|
||
|
if ($selectionActive === true and !in_array($fieldName, $selectedFields)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if ($i !== 0) $tLine1[] = "";
|
||
|
$tLine2[] = $fieldName;
|
||
|
$tLine3[] = $field['name_human_readable'];
|
||
|
$tLine4[] = $field['remark'];
|
||
|
$i++;
|
||
|
}
|
||
|
|
||
|
if (empty($tLine2)) continue;
|
||
|
|
||
|
for ($i = 1; $i <= 4; $i++) {
|
||
|
${"line$i"} = array_merge(${"line$i"}, ${"tLine$i"});
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
header('Content-Type: text/csv');
|
||
|
if ($selectionActive === true)
|
||
|
header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}_selection.csv");
|
||
|
else
|
||
|
header("Content-Disposition: attachment; filename=csvxml_museum-digital_template-{$lang}.csv");
|
||
|
|
||
|
for ($i = 1; $i <= 4; $i++) {
|
||
|
echo '"' . implode("\";\"", ${"line$i"}) . '"' . PHP_EOL;
|
||
|
}
|