2024-09-14 23:12:21 +03:00
|
|
|
<?php
|
2024-09-15 21:31:44 +03:00
|
|
|
|
|
|
|
use \App\Services\{Auth, DB};
|
|
|
|
use \App\Models\User;
|
|
|
|
|
2024-09-15 21:12:45 +03:00
|
|
|
if (isset($_POST['create'])) {
|
|
|
|
$postData = $_POST;
|
2024-09-14 23:12:21 +03:00
|
|
|
|
2024-09-15 21:12:45 +03:00
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach ($postData as $key => $value) {
|
|
|
|
if (strpos($key, 'variable') === 0) {
|
|
|
|
preg_match('/_(\d+)$/', $key, $matches);
|
|
|
|
if (isset($matches[1])) {
|
|
|
|
$index = $matches[1];
|
2024-09-15 21:31:44 +03:00
|
|
|
|
2024-09-15 21:12:45 +03:00
|
|
|
if (!isset($result[$index])) {
|
|
|
|
$result[$index] = [];
|
|
|
|
}
|
|
|
|
$newKey = preg_replace('/^variable/', '', $key);
|
|
|
|
$newKey = preg_replace('/_\d+$/', '', $newKey);
|
2024-09-15 21:31:44 +03:00
|
|
|
|
2024-09-15 21:12:45 +03:00
|
|
|
$result[$index][$newKey] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$jsonResult = json_encode($result, JSON_PRETTY_PRINT);
|
2024-09-15 21:31:44 +03:00
|
|
|
|
|
|
|
DB::query('INSERT INTO entities VALUES (\'0\', :title, :createdate, :sampledata, :color)', array(':title' => $_POST['title'], ':createdate' => time(), ':sampledata' => $jsonResult, ':color' => $_POST['color']));
|
|
|
|
header('Location: /admin?type=Entities');
|
2024-09-15 21:12:45 +03:00
|
|
|
}
|
2024-09-14 23:12:21 +03:00
|
|
|
?>
|
|
|
|
<h1><b>Создание сущности</b></h1>
|
2024-09-15 21:12:45 +03:00
|
|
|
<form action="/admin?type=EntityCreate" method="post" name="form" id="form" enctype="multipart/form-data" style="display:inline-block; min-width:500px;">
|
2024-09-14 23:12:21 +03:00
|
|
|
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput1" class="form-label">Название</label>
|
2024-09-15 21:31:44 +03:00
|
|
|
<input type="text" name="title" class="form-control" id="exampleFormControlInput1" placeholder="Вагон метро">
|
2024-09-14 23:12:21 +03:00
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput1" class="form-label">Цвет</label>
|
2024-09-15 21:31:44 +03:00
|
|
|
<input type="text" name="color" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
|
2024-09-14 23:12:21 +03:00
|
|
|
</div>
|
|
|
|
<p>Вводимые переменные</p>
|
|
|
|
<div class="alert alert-dark" role="alert">
|
|
|
|
Добавляйте и регулируйте поля ввода, которые будут являться шаблонной формой для создания моделей к сущности.
|
|
|
|
</div>
|
2024-09-14 23:55:42 +03:00
|
|
|
<div class="row" id="entityform">
|
2024-09-14 23:12:21 +03:00
|
|
|
<div class="col-md-3">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput1" class="form-label">Название переменной</label>
|
2024-09-14 23:55:42 +03:00
|
|
|
<input name="variablename_1" type="text" class="form-control" id="exampleFormControlInput1" placeholder="#FFFFFF">
|
2024-09-14 23:12:21 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput1" class="form-label">ID</label>
|
2024-09-14 23:55:42 +03:00
|
|
|
<input name="variableid_1" type="text" class="form-control" id="exampleFormControlInput1" placeholder="blablabla">
|
2024-09-14 23:12:21 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
2024-09-15 21:31:44 +03:00
|
|
|
<label for="exampleFormControlInput1" class="form-label">Тип</label>
|
2024-09-14 23:55:42 +03:00
|
|
|
<select name="variabletype_1" class="form-select" aria-label="Default select example">
|
2024-09-14 23:12:21 +03:00
|
|
|
<option value="1">Строка</option>
|
|
|
|
<option value="2">Число</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
2024-09-15 21:31:44 +03:00
|
|
|
<label for="exampleFormControlInput1" class="form-label">Обязателен?</label>
|
2024-09-14 23:55:42 +03:00
|
|
|
<select name="variableimportant_1" class="form-select" aria-label="Default select example">
|
2024-09-14 23:12:21 +03:00
|
|
|
<option value="1">Да</option>
|
|
|
|
<option value="2">Нет</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-09-14 23:55:42 +03:00
|
|
|
<button id="addButton" type="button" class="btn btn-outline-primary">Добавить ещё</button>
|
2024-09-15 21:12:45 +03:00
|
|
|
<button id="addButton" type="submit" name="create" class="btn btn-primary">Создать сущность</button>
|
2024-09-14 23:12:21 +03:00
|
|
|
</div>
|
2024-09-15 21:31:44 +03:00
|
|
|
|
|
|
|
|
2024-09-14 23:55:42 +03:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<script>
|
2024-09-15 21:31:44 +03:00
|
|
|
let count = 1; // Начальное значение для номера переменной
|
2024-09-14 23:55:42 +03:00
|
|
|
|
2024-09-15 21:31:44 +03:00
|
|
|
document.getElementById('addButton').addEventListener('click', function() {
|
|
|
|
count++; // Увеличиваем номер переменной
|
2024-09-14 23:55:42 +03:00
|
|
|
|
2024-09-15 21:31:44 +03:00
|
|
|
// Создаем новый элемент
|
|
|
|
const newElement =
|
|
|
|
`<div class="col-md-3">
|
2024-09-14 23:55:42 +03:00
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput${count}" class="form-label">Название переменной</label>
|
|
|
|
<input name="variablename_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="#FFFFFF">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="exampleFormControlInput${count}" class="form-label">ID</label>
|
|
|
|
<input name="variableid_${count}" type="text" class="form-control" id="exampleFormControlInput${count}" placeholder="blablabla">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
|
|
<label for="exampleFormControlInput${count}" class="form-label">Тип</label>
|
|
|
|
<select name="variabletype_${count}" class="form-select" aria-label="Default select example">
|
|
|
|
<option value="1">Строка</option>
|
|
|
|
<option value="2">Число</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
|
|
<label for="exampleFormControlInput${count}" class="form-label">Обязателен?</label>
|
|
|
|
<select name="variableimportant_${count}" class="form-select" aria-label="Default select example">
|
|
|
|
<option value="1">Да</option>
|
|
|
|
<option value="2">Нет</option>
|
|
|
|
</select>
|
2024-09-15 21:31:44 +03:00
|
|
|
</div>`;
|
2024-09-14 23:55:42 +03:00
|
|
|
|
2024-09-15 21:31:44 +03:00
|
|
|
// Добавляем новый элемент в #entityform
|
|
|
|
document.getElementById('entityform').insertAdjacentHTML('beforeend', newElement);
|
|
|
|
});
|
2024-09-14 23:55:42 +03:00
|
|
|
</script>
|