2019-08-27 00:32:24 +02:00
|
|
|
<?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 = [];
|
|
|
|
|
|
|
|
foreach ($availableFields as $headline => $fields) {
|
|
|
|
|
|
|
|
$i = 0;
|
2019-09-01 19:54:01 +02:00
|
|
|
$tLine1 = $tLine2 = $tLine3 = $tLine4 = [];
|
2019-08-27 00:32:24 +02:00
|
|
|
$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'];
|
2019-09-01 19:54:01 +02:00
|
|
|
# $tLine4[] = $field['remark'];
|
|
|
|
if (!empty($field['allowedValues'])) $tLine4[] = end($field['allowedValues']);
|
|
|
|
else $tLine4[] = $field['name_human_readable'];
|
|
|
|
|
2019-08-27 00:32:24 +02:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
2019-09-01 19:54:01 +02:00
|
|
|
if (empty($tLine2) or count($tLine2) === 0) continue;
|
2019-08-27 00:32:24 +02:00
|
|
|
|
|
|
|
for ($i = 1; $i <= 4; $i++) {
|
|
|
|
${"line$i"} = array_merge(${"line$i"}, ${"tLine$i"});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-01 19:54:01 +02:00
|
|
|
header('Content-Type: text/csv; charset=utf-8');
|
2019-08-27 00:32:24 +02:00
|
|
|
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");
|
|
|
|
|
2019-09-01 19:54:01 +02:00
|
|
|
for ($i = 2; $i <= 4; $i++) {
|
|
|
|
echo mb_convert_encoding('"' . implode("\";\"", ${"line$i"}) . '"' . PHP_EOL, 'utf-16','utf-8');;
|
2019-08-27 00:32:24 +02:00
|
|
|
}
|