add ext-form
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Paul Spenke
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form;
|
||||
|
||||
use Plugi\Repositories\BaseRepository;
|
||||
|
||||
class DefinitionsRepository extends BaseRepository {
|
||||
/**
|
||||
* The uploads database table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'ext__form_definitions';
|
||||
|
||||
public function create(array $data): null|object|array
|
||||
{
|
||||
return parent::create($data);
|
||||
}
|
||||
public function update($instance, array $data)
|
||||
{
|
||||
return parent::update($instance, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form;
|
||||
|
||||
use Plugi\Repositories\BaseRepository;
|
||||
|
||||
class EntriesRepository extends BaseRepository {
|
||||
/**
|
||||
* The uploads database table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'ext__form_entries';
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return parent::create($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form\Finishers;
|
||||
use Plugi\Extensions\Form\DefinitionsRepository;
|
||||
|
||||
class DefaultFinisher {
|
||||
public $formId;
|
||||
public $form;
|
||||
public $data;
|
||||
public function __construct()
|
||||
{
|
||||
$formRepository = new DefinitionsRepository();
|
||||
$this->formId = $_GET['id'] ?? 0;
|
||||
$this->form = $formRepository->findWithId($this->formId);
|
||||
$this->data = file_get_contents('php://input');
|
||||
}
|
||||
public function execute (): bool {
|
||||
return true;
|
||||
}
|
||||
public function getFormFields (): array {
|
||||
return json_decode($this->form['fields'], true);
|
||||
}
|
||||
public function getEntryFields (): array {
|
||||
return json_decode($this->data, true)['fields'];
|
||||
}
|
||||
public function getFormName (): string {
|
||||
return $this->form['name'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form\Finishers;
|
||||
|
||||
class FinishersRepository {
|
||||
private $config;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = require __DIR__ . '/config.php';
|
||||
}
|
||||
|
||||
public function getFinisherConfig (string $key) : array|null
|
||||
{
|
||||
return $this->config['finishers'][$key] ?? null;
|
||||
}
|
||||
|
||||
public function finisherExists (string $key) : bool
|
||||
{
|
||||
return array_key_exists($key, $this->config['finishers']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form\Finishers;
|
||||
class SaveEntryToDatabase extends DefaultFinisher
|
||||
{
|
||||
public function execute(): bool
|
||||
{
|
||||
$entriesRepository = new \Plugi\Extensions\Form\EntriesRepository();
|
||||
$entriesRepository->create([
|
||||
'formId' => $this->formId,
|
||||
'data' => $this->data,
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Plugi\Extensions\Form\Finishers;
|
||||
use Plugi\Extensions;
|
||||
|
||||
class SendEmailToAdmin extends DefaultFinisher
|
||||
{
|
||||
public function execute(): bool
|
||||
{
|
||||
$to = Extensions::getSettings('form')['email']['value'];
|
||||
$subject = 'Formulareinsendung: '.$this->getFormName();
|
||||
$message = $this->getNiceFields();
|
||||
return mail(
|
||||
$to,
|
||||
$subject,
|
||||
$message,
|
||||
$additional_headers = [],
|
||||
$additional_params = ""
|
||||
);
|
||||
}
|
||||
private function getNiceFields(): string {
|
||||
$text = '';
|
||||
foreach ($this->getFormFields() as $field) {
|
||||
$text .= $field['label'] . ': ' . $this->getEntryFields()[$field['name']] . "\n";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'finishers' => [
|
||||
'saveToDatabase' => [
|
||||
'class' => \Plugi\Extensions\Form\Finishers\SaveEntryToDatabase::class,
|
||||
'label' => 'In Datenbank speichern'
|
||||
],
|
||||
'sendMailToAdmin' => [
|
||||
'class' => \Plugi\Extensions\Form\Finishers\SendEmailToAdmin::class,
|
||||
'label' => 'Email an Admin senden'
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
use Plugi\Extensions\Form\DefinitionsRepository;
|
||||
|
||||
$formsRepository = new DefinitionsRepository();
|
||||
|
||||
$form = [
|
||||
'name' => "Neues Formular",
|
||||
'fields' => "[]",
|
||||
'finishers' => "[]",
|
||||
];
|
||||
|
||||
if(isset($_GET['id']))
|
||||
$form = $formsRepository->findWithId($_GET['id']);
|
||||
|
||||
$isEditing = isset($form['id']) && $form['id'] > 0;
|
||||
?>
|
||||
|
||||
<div class="mb-6">
|
||||
<div class="flex items-center gap-3">
|
||||
<a href="?tab=ext--form" class="btn btn-ghost btn-sm btn-circle">
|
||||
<i class="ph-duotone ph-arrow-left text-xl"></i>
|
||||
</a>
|
||||
<div>
|
||||
<h2 class="text-xl font-bold"><?= $isEditing ? 'Formular bearbeiten' : 'Neues Formular' ?></h2>
|
||||
<p class="text-sm text-base-content/60"><?= $isEditing ? 'Ändere die Einstellungen deines Formulars.' : 'Erstelle ein neues Formular mit Feldern und Aktionen.' ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const fields = <?= $form["fields"] ?>;
|
||||
const finishers = <?= $form["finishers"] ?>;
|
||||
</script>
|
||||
|
||||
<form action="/ext--form/save-form" method="post" x-data="{
|
||||
fields: fields,
|
||||
finishers: finishers,
|
||||
defaultField: {name: 'formularfeld', label: 'Formularfeld', type: 'text', required: false, options: []},
|
||||
defaultFinisher: {type: 'saveToDatabase'},
|
||||
dragIndex: null,
|
||||
addField() {
|
||||
const nextNum = this.fields.length + 1;
|
||||
this.fields.push({
|
||||
name: 'feld_' + nextNum,
|
||||
label: 'Feld ' + nextNum,
|
||||
type: 'text',
|
||||
required: false,
|
||||
options: []
|
||||
});
|
||||
},
|
||||
getValidationErrors(field, index) {
|
||||
const errors = [];
|
||||
if (!field.name || !field.name.trim()) {
|
||||
errors.push('Feldname darf nicht leer sein.');
|
||||
}
|
||||
if (!field.label || !field.label.trim()) {
|
||||
errors.push('Beschriftung darf nicht leer sein.');
|
||||
}
|
||||
// Check for duplicate names
|
||||
const nameCount = this.fields.filter((f, i) => i !== index && f.name && f.name.trim() === field.name && field.name.trim() !== '').length;
|
||||
if (nameCount > 0) {
|
||||
errors.push('Feldname wird bereits verwendet.');
|
||||
}
|
||||
return errors;
|
||||
},
|
||||
getOptionsLabel(type) {
|
||||
if (type === 'select') return 'Dropdown-Optionen';
|
||||
if (type === 'checkbox') return 'Checkbox-Optionen (mehrfach wählbar)';
|
||||
if (type === 'radio') return 'Radio-Optionen (einzeln wählbar)';
|
||||
return 'Optionen';
|
||||
},
|
||||
moveField(fromIndex, toIndex) {
|
||||
if (toIndex < 0 || toIndex >= this.fields.length) return;
|
||||
const field = this.fields.splice(fromIndex, 1)[0];
|
||||
this.fields.splice(toIndex, 0, field);
|
||||
}
|
||||
}">
|
||||
<?php
|
||||
if(isset($form['id'])) echo '<input type="hidden" name="id" value="'.$form['id'].'">';
|
||||
?>
|
||||
|
||||
<div class="card bg-base-100 shadow mb-6">
|
||||
<div class="card-body">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<i class="ph-duotone ph-text-aa text-2xl text-base-content/60"></i>
|
||||
<h3 class="card-title text-lg">Grundlegendes</h3>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Formularname</span>
|
||||
</label>
|
||||
<input type="text" name="name" value="<?= $form['name'] ?>" placeholder="z.B. Kontaktformular" class="input input-bordered w-full" required />
|
||||
<span class="label-text-alt text-base-content/60">Ein eindeutiger Name für dein Formular.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card bg-base-100 shadow mb-6">
|
||||
<div class="card-body">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<i class="ph-duotone ph-list-dashes text-2xl text-base-content/60"></i>
|
||||
<h3 class="card-title text-lg">Formularfelder</h3>
|
||||
</div>
|
||||
<p class="text-sm text-base-content/60 mb-4">Definiere die Felder, die Nutzer ausfüllen können.</p>
|
||||
|
||||
<input type="hidden" name="fields" :value="JSON.stringify(fields)">
|
||||
|
||||
<div x-show="fields.length === 0" class="text-center py-8 border-2 border-dashed border-base-300 rounded-lg">
|
||||
<i class="ph-duotone ph-plus-circle text-4xl text-base-content/30"></i>
|
||||
<p class="text-sm text-base-content/50 mt-2">Noch keine Felder hinzugefügt</p>
|
||||
<a href="javascript:void(0)" @click="addField()" class="btn btn-sm btn-primary mt-2">Erstes Feld hinzufügen</a>
|
||||
</div>
|
||||
|
||||
<div x-show="fields.length > 0" class="space-y-3">
|
||||
<template x-for="(field, index) in fields">
|
||||
<div
|
||||
class="border rounded-lg p-3 bg-base-200/50 transition-colors"
|
||||
:class="{
|
||||
'border-error': getValidationErrors(field, index).length > 0,
|
||||
'border-base-300': getValidationErrors(field, index).length === 0,
|
||||
'bg-base-200': dragIndex === index
|
||||
}"
|
||||
draggable="true"
|
||||
@dragstart="dragIndex = index; $event.dataTransfer.effectAllowed = 'move'"
|
||||
@dragover.prevent="$event.dataTransfer.dropEffect = 'move'"
|
||||
@drop.prevent="moveField(dragIndex, index)"
|
||||
@dragend="dragIndex = null"
|
||||
>
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<!-- Drag handle -->
|
||||
<button type="button" class="btn btn-ghost btn-xs btn-square cursor-grab active:cursor-grabbing text-base-content/40 hover:text-base-content" title="Ziehen zum Verschieben">
|
||||
<i class="ph-duotone ph-dots-six-vertical text-lg"></i>
|
||||
</button>
|
||||
<span class="text-xs font-mono text-base-content/40 w-6">#[<span x-text="index + 1"></span>]</span>
|
||||
<div class="flex-1">
|
||||
<input
|
||||
type="text"
|
||||
x-model="field.name"
|
||||
placeholder="Feldname"
|
||||
class="input input-bordered input-sm w-full"
|
||||
:class="{'input-error': getValidationErrors(field, index).some(e => e.includes('Feldname'))}"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<input
|
||||
type="text"
|
||||
x-model="field.label"
|
||||
placeholder="Beschriftung"
|
||||
class="input input-bordered input-sm w-full"
|
||||
:class="{'input-error': getValidationErrors(field, index).some(e => e.includes('Beschriftung'))}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Validation errors -->
|
||||
<div x-show="getValidationErrors(field, index).length > 0" x-transition class="mb-2 p-2 bg-error/10 border border-error/30 rounded text-error text-xs">
|
||||
<template x-for="(error, errIndex) in getValidationErrors(field, index)">
|
||||
<div :key="errIndex" class="flex items-center gap-1">
|
||||
<i class="ph-duotone ph-warning text-sm"></i>
|
||||
<span x-text="error"></span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<select x-model="field.type" class="select select-bordered select-sm flex-1">
|
||||
<option value="text">Text</option>
|
||||
<option value="email">Email</option>
|
||||
<option value="textarea">Textbereich</option>
|
||||
<option value="checkbox">Checkbox</option>
|
||||
<option value="radio">Radio</option>
|
||||
<option value="select">Auswahl</option>
|
||||
</select>
|
||||
<label class="label cursor-pointer gap-2">
|
||||
<span class="label-text text-sm">Pflichtfeld</span>
|
||||
<input type="checkbox" x-model="field.required" class="checkbox checkbox-sm checkbox-primary" />
|
||||
</label>
|
||||
<button @click="fields.splice(index, 1)" type="button" class="btn btn-ghost btn-sm btn-circle text-error" title="Entfernen">
|
||||
<i class="ph-duotone ph-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div x-show="field.type === 'select' || field.type === 'checkbox' || field.type === 'radio'" x-transition class="mt-3 ml-2 pl-4 border-l-2 border-primary/30">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<span class="text-xs font-medium text-base-content/60 uppercase tracking-wide" x-text="getOptionsLabel(field.type)"></span>
|
||||
<a href="javascript:void(0)" @click="field.options.push({label: 'Option', value: 'option'})" class="btn btn-xs btn-ghost btn-primary">
|
||||
<i class="ph-duotone ph-plus"></i>
|
||||
Neu
|
||||
</a>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<template x-for="(option, optIndex) in field.options">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs text-base-content/40 w-4">#[<span x-text="optIndex + 1"></span>]</span>
|
||||
<input type="text" x-model="option.label" placeholder="Beschriftung" class="input input-bordered input-sm flex-1" />
|
||||
<input type="text" x-model="option.value" placeholder="Wert" class="input input-bordered input-sm flex-1" />
|
||||
<button @click="field.options.splice(optIndex, 1)" type="button" class="btn btn-ghost btn-xs btn-circle text-error" title="Entfernen">
|
||||
<i class="ph-duotone ph-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<a href="javascript:void(0)" @click="addField()" class="btn btn-outline btn-sm btn-primary">
|
||||
<i class="ph-duotone ph-plus"></i>
|
||||
Feld hinzufügen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card bg-base-100 shadow mb-6">
|
||||
<div class="card-body">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<i class="ph-duotone ph-gear text-2xl text-base-content/60"></i>
|
||||
<h3 class="card-title text-lg">Aktionen</h3>
|
||||
</div>
|
||||
<p class="text-sm text-base-content/60 mb-4">Was soll passieren, wenn ein Formular abgeschickt wird?</p>
|
||||
|
||||
<input type="hidden" name="finishers" :value="JSON.stringify(finishers)">
|
||||
|
||||
<div x-show="finishers.length === 0" class="text-center py-8 border-2 border-dashed border-base-300 rounded-lg">
|
||||
<i class="ph-duotone ph-plus-circle text-4xl text-base-content/30"></i>
|
||||
<p class="text-sm text-base-content/50 mt-2">Noch keine Aktionen hinzugefügt</p>
|
||||
<a href="javascript:void(0)" @click="finishers.push({...defaultFinisher})" class="btn btn-sm btn-primary mt-2">Erste Aktion hinzufügen</a>
|
||||
</div>
|
||||
|
||||
<div x-show="finishers.length > 0" class="space-y-2">
|
||||
<template x-for="(finisher, index) in finishers">
|
||||
<div class="flex items-center gap-3 p-3 border border-base-300 rounded-lg bg-base-200/50">
|
||||
<span class="text-xs font-mono text-base-content/40">#[<span x-text="index + 1"></span>]</span>
|
||||
<select x-model="finisher.type" class="select select-bordered select-sm flex-1">
|
||||
<option value="saveToDatabase">In Datenbank speichern</option>
|
||||
<option value="sendMailToAdmin">Email an Admin senden</option>
|
||||
</select>
|
||||
<button @click="finishers.splice(index, 1)" type="button" class="btn btn-ghost btn-sm btn-circle text-error" title="Entfernen">
|
||||
<i class="ph-duotone ph-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<a href="javascript:void(0)" @click="finishers.push({...defaultFinisher})" class="btn btn-outline btn-sm btn-primary">
|
||||
<i class="ph-duotone ph-plus"></i>
|
||||
Aktion hinzufügen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-2">
|
||||
<a href="?tab=ext--form" class="btn btn-ghost btn-sm">
|
||||
Abbrechen
|
||||
</a>
|
||||
<button type="submit" class="btn btn-primary btn-sm">
|
||||
<i class="ph-duotone ph-floppy-disk"></i>
|
||||
Speichern
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,16 @@
|
||||
<div class="card bg-base-100 shadow">
|
||||
<div class="card-body">
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<i class="ph-duotone ph-gear text-2xl text-base-content/60"></i>
|
||||
<h3 class="card-title text-lg">Einstellungen</h3>
|
||||
</div>
|
||||
<p class="text-sm text-base-content/60 mb-4">Konfiguriere die globalen Einstellungen für das Formulare-Extension.</p>
|
||||
<div class="space-y-4">
|
||||
<?php
|
||||
foreach (\Plugi\Extensions::getSettings('form') as $setting) {
|
||||
phpb_render_setting($setting);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
use Plugi\Extensions\Form\DefinitionsRepository;
|
||||
use Plugi\Extensions\Form\EntriesRepository;
|
||||
|
||||
$id = $_GET['id'];
|
||||
|
||||
$formsRepository = new DefinitionsRepository();
|
||||
$form = $formsRepository->findWithId($id);
|
||||
$fields = json_decode($form['fields'], true);
|
||||
|
||||
$entriesRepository = new EntriesRepository();
|
||||
$entries = $entriesRepository->findWhere('formId', $id);
|
||||
|
||||
?>
|
||||
|
||||
<div class="mb-6">
|
||||
<div class="flex items-center gap-3">
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form']) ?>" class="btn btn-ghost btn-sm btn-circle">
|
||||
<i class="ph-duotone ph-arrow-left text-xl"></i>
|
||||
</a>
|
||||
<div>
|
||||
<h2 class="text-xl font-bold"><?= phpb_e($form['name']) ?></h2>
|
||||
<p class="text-sm text-base-content/60"><?= count($entries) ?> Eintrag<?= count($entries) !== 1 ? 'e' : '' ?> für dieses Formular</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (empty($entries)): ?>
|
||||
<div class="card bg-base-100 shadow">
|
||||
<div class="card-body items-center text-center py-16">
|
||||
<i class="ph-duotone ph-inbox text-6xl text-base-content/20"></i>
|
||||
<h3 class="card-title text-lg mt-4">Noch keine Einträge</h3>
|
||||
<p class="text-base-content/60 mt-1">Wenn jemand das Formular ausfüllt, erscheint die Eintragung hier.</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="card bg-base-100 shadow">
|
||||
<div class="card-body p-0">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table w-full">
|
||||
<thead>
|
||||
<tr class="bg-base-200/50">
|
||||
<th class="w-16">ID</th>
|
||||
<th class="w-40">Erstellt</th>
|
||||
<?php foreach ($fields as $field): ?>
|
||||
<th><?= phpb_e($field['label']) ?></th>
|
||||
<?php endforeach; ?>
|
||||
<th class="w-12 text-center"><?= phpb_trans('website-manager.actions') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($entries as $entry):
|
||||
$entryData = json_decode($entry['data'], true);
|
||||
$createdDate = new DateTime($entry['created'] . ' UTC');
|
||||
$createdDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
?>
|
||||
<tr class="hover:bg-base-200/30">
|
||||
<td class="font-mono text-sm text-base-content/60"><?= phpb_e($entry['id']) ?></td>
|
||||
<td class="text-sm"><?= $createdDate->format('d.m.Y H:i') ?></td>
|
||||
<?php foreach ($fields as $field):
|
||||
$fieldName = $field['name'];
|
||||
$fieldValue = '';
|
||||
if (isset($entryData['fields'][$fieldName])) {
|
||||
$fieldValue = $entryData['fields'][$fieldName];
|
||||
// Handle array values (e.g., from checkboxes)
|
||||
if (is_array($fieldValue)) {
|
||||
$fieldValue = implode(', ', $fieldValue);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<td class="text-sm"><?= phpb_e($fieldValue) ?></td>
|
||||
<?php endforeach; ?>
|
||||
<td>
|
||||
<div class="flex justify-center">
|
||||
<a href="/ext--form/delete-entry?id=<?= $entry['id'] ?>&formId=<?= $id ?>" class="btn btn-ghost btn-sm btn-circle text-error" title="<?= phpb_trans('website-manager.remove') ?>">
|
||||
<i class="ph-duotone ph-trash text-lg"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
use Plugi\Extensions\Form\DefinitionsRepository;
|
||||
|
||||
$formsRepository = new DefinitionsRepository();
|
||||
$forms = $formsRepository->getAll();
|
||||
|
||||
?>
|
||||
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h2 class="text-xl font-bold">Formulare</h2>
|
||||
<p class="text-sm text-base-content/60"><?= count($forms) ?> Formular<?= count($forms) !== 1 ? 'e' : '' ?> vorhanden</p>
|
||||
</div>
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'editForm']) ?>" class="btn btn-primary btn-sm">
|
||||
<i class="ph-duotone ph-plus"></i>
|
||||
Neues Formular
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($forms)): ?>
|
||||
<div class="card bg-base-100 shadow">
|
||||
<div class="card-body items-center text-center py-16">
|
||||
<i class="ph-duotone ph-notebook text-6xl text-base-content/20"></i>
|
||||
<h3 class="card-title text-lg mt-4">Noch keine Formulare</h3>
|
||||
<p class="text-base-content/60 mt-1">Erstelle dein erstes Formular, um Einträge von deiner Website zu sammeln.</p>
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'editForm']) ?>" class="btn btn-primary mt-4">
|
||||
<i class="ph-duotone ph-plus"></i>
|
||||
Erstes Formular erstellen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="card bg-base-100 shadow">
|
||||
<div class="card-body p-0">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table w-full">
|
||||
<thead>
|
||||
<tr class="bg-base-200/50">
|
||||
<th class="w-16">ID</th>
|
||||
<th><?= phpb_trans('website-manager.name') ?></th>
|
||||
<th class="w-16 text-center"><?= phpb_trans('website-manager.actions') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($forms as $form): ?>
|
||||
<tr class="hover:bg-base-200/30">
|
||||
<td class="font-mono text-sm text-base-content/60"><?= phpb_e($form['id']) ?></td>
|
||||
<td>
|
||||
<div class="font-medium"><?= phpb_e($form['name']) ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="flex items-center justify-center gap-1">
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'listEntries', 'id' => $form['id']]) ?>" class="btn btn-ghost btn-sm btn-circle" title="Einträge ansehen">
|
||||
<i class="ph-duotone ph-eye text-lg"></i>
|
||||
</a>
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'editForm', 'id' => $form['id']]) ?>" class="btn btn-ghost btn-sm btn-circle" title="<?= phpb_trans('website-manager.edit') ?>">
|
||||
<i class="ph-duotone ph-pencil-line text-lg"></i>
|
||||
</a>
|
||||
<a href="/ext--form/delete-form?id=<?= $form['id'] ?>" class="btn btn-ghost btn-sm btn-circle text-error" title="<?= phpb_trans('website-manager.remove') ?>">
|
||||
<i class="ph-duotone ph-trash text-lg"></i>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
$modules = [
|
||||
'listForms' => [
|
||||
'include' => __DIR__ . '/Views/ListForms.php',
|
||||
'label' => 'Formulare',
|
||||
'icon' => 'ph-list-dashes',
|
||||
'showTabs' => true,
|
||||
'inMenu' => true,
|
||||
],
|
||||
'settings' => [
|
||||
'include' => __DIR__ . '/Views/ExtSettings.php',
|
||||
'label' => 'Einstellungen',
|
||||
'icon' => 'ph-gear',
|
||||
'showTabs' => true,
|
||||
'inMenu' => true,
|
||||
],
|
||||
'editForm' => [
|
||||
'include' => __DIR__ . '/Views/EditForm.php',
|
||||
'showTabs' => false,
|
||||
'inMenu' => false,
|
||||
],
|
||||
'listEntries' => [
|
||||
'include' => __DIR__ . '/Views/ListEntries.php',
|
||||
'showTabs' => false,
|
||||
'inMenu' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$activeModule = array_keys($modules)[0];
|
||||
if (isset($_GET['action']) && array_key_exists($_GET['action'], $modules)) $activeModule = $_GET['action'];
|
||||
|
||||
?>
|
||||
<?php
|
||||
if ($modules[$activeModule]['showTabs'] === true):
|
||||
?>
|
||||
<div class="tabs tabs-boxed bg-base-200/50 mb-6">
|
||||
<?php
|
||||
foreach ($modules as $name => $module):
|
||||
if ($module['inMenu'] === false) continue;
|
||||
$icon = $module['icon'] ?? 'ph-circle';
|
||||
?>
|
||||
<a class="tab gap-2 <?= $name === $activeModule ? 'tab-active' : '' ?>" href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => $name]) ?>">
|
||||
<i class="ph-duotone <?= $icon ?>"></i>
|
||||
<?= $module['label'] ?>
|
||||
</a>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<div class="w-full">
|
||||
<?php
|
||||
include $modules[$activeModule]['include'];
|
||||
?>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,680 @@
|
||||
/*! tailwindcss v4.3.5 | MIT License | https://tailwindcss.com */
|
||||
@layer properties;
|
||||
@layer theme, base, components, utilities;
|
||||
@layer theme {
|
||||
:root, :host {
|
||||
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
|
||||
"Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
|
||||
"Segoe UI Symbol", "Noto Color Emoji";
|
||||
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
|
||||
"Courier New", monospace;
|
||||
--spacing: 0.25rem;
|
||||
--container-2xl: 42rem;
|
||||
--text-xs: 0.75rem;
|
||||
--text-xs--line-height: calc(1 / 0.75);
|
||||
--text-sm: 0.875rem;
|
||||
--text-sm--line-height: calc(1.25 / 0.875);
|
||||
--text-lg: 1.125rem;
|
||||
--text-lg--line-height: calc(1.75 / 1.125);
|
||||
--text-xl: 1.25rem;
|
||||
--text-xl--line-height: calc(1.75 / 1.25);
|
||||
--text-2xl: 1.5rem;
|
||||
--text-2xl--line-height: calc(2 / 1.5);
|
||||
--text-3xl: 1.875rem;
|
||||
--text-3xl--line-height: calc(2.25 / 1.875);
|
||||
--text-4xl: 2.25rem;
|
||||
--text-4xl--line-height: calc(2.5 / 2.25);
|
||||
--text-6xl: 3.75rem;
|
||||
--text-6xl--line-height: 1;
|
||||
--font-weight-medium: 500;
|
||||
--font-weight-bold: 700;
|
||||
--tracking-wide: 0.025em;
|
||||
--radius-lg: 0.5rem;
|
||||
--default-transition-duration: 150ms;
|
||||
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
--default-font-family: var(--font-sans);
|
||||
--default-mono-font-family: var(--font-mono);
|
||||
}
|
||||
}
|
||||
@layer base {
|
||||
*, ::after, ::before, ::backdrop, ::file-selector-button {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0 solid;
|
||||
}
|
||||
html, :host {
|
||||
line-height: 1.5;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
tab-size: 4;
|
||||
font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
|
||||
font-feature-settings: var(--default-font-feature-settings, normal);
|
||||
font-variation-settings: var(--default-font-variation-settings, normal);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
hr {
|
||||
height: 0;
|
||||
color: inherit;
|
||||
border-top-width: 1px;
|
||||
}
|
||||
abbr:where([title]) {
|
||||
-webkit-text-decoration: underline dotted;
|
||||
text-decoration: underline dotted;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-size: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
a {
|
||||
color: inherit;
|
||||
-webkit-text-decoration: inherit;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
b, strong {
|
||||
font-weight: bolder;
|
||||
}
|
||||
code, kbd, samp, pre {
|
||||
font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
|
||||
font-feature-settings: var(--default-mono-font-feature-settings, normal);
|
||||
font-variation-settings: var(--default-mono-font-variation-settings, normal);
|
||||
font-size: 1em;
|
||||
}
|
||||
small {
|
||||
font-size: 80%;
|
||||
}
|
||||
sub, sup {
|
||||
font-size: 75%;
|
||||
line-height: 0;
|
||||
position: relative;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
sub {
|
||||
bottom: -0.25em;
|
||||
}
|
||||
sup {
|
||||
top: -0.5em;
|
||||
}
|
||||
table {
|
||||
text-indent: 0;
|
||||
border-color: inherit;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
:-moz-focusring:where(:not(iframe)) {
|
||||
outline: auto;
|
||||
}
|
||||
progress {
|
||||
vertical-align: baseline;
|
||||
}
|
||||
summary {
|
||||
display: list-item;
|
||||
}
|
||||
ol, ul, menu {
|
||||
list-style: none;
|
||||
}
|
||||
img, svg, video, canvas, audio, iframe, embed, object {
|
||||
display: block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
img, video {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
button, input, select, optgroup, textarea, ::file-selector-button {
|
||||
font: inherit;
|
||||
font-feature-settings: inherit;
|
||||
font-variation-settings: inherit;
|
||||
letter-spacing: inherit;
|
||||
color: inherit;
|
||||
border-radius: 0;
|
||||
background-color: transparent;
|
||||
opacity: 1;
|
||||
}
|
||||
:where(select:is([multiple], [size])) optgroup {
|
||||
font-weight: bolder;
|
||||
}
|
||||
:where(select:is([multiple], [size])) optgroup option {
|
||||
padding-inline-start: 20px;
|
||||
}
|
||||
::file-selector-button {
|
||||
margin-inline-end: 4px;
|
||||
}
|
||||
::placeholder {
|
||||
opacity: 1;
|
||||
}
|
||||
@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
|
||||
::placeholder {
|
||||
color: currentcolor;
|
||||
@supports (color: color-mix(in lab, red, red)) {
|
||||
color: color-mix(in oklab, currentcolor 50%, transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
::-webkit-date-and-time-value {
|
||||
min-height: 1lh;
|
||||
text-align: inherit;
|
||||
}
|
||||
::-webkit-datetime-edit {
|
||||
display: inline-flex;
|
||||
}
|
||||
::-webkit-datetime-edit-fields-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
|
||||
padding-block: 0;
|
||||
}
|
||||
::-webkit-calendar-picker-indicator {
|
||||
line-height: 1;
|
||||
}
|
||||
:-moz-ui-invalid {
|
||||
box-shadow: none;
|
||||
}
|
||||
button, input:where([type="button"], [type="reset"], [type="submit"]), ::file-selector-button {
|
||||
appearance: button;
|
||||
}
|
||||
::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
|
||||
height: auto;
|
||||
}
|
||||
[hidden]:where(:not([hidden="until-found"])) {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
@layer utilities {
|
||||
.mx-auto {
|
||||
margin-inline: auto;
|
||||
}
|
||||
.mt-1 {
|
||||
margin-top: var(--spacing);
|
||||
}
|
||||
.mt-2 {
|
||||
margin-top: calc(var(--spacing) * 2);
|
||||
}
|
||||
.mt-3 {
|
||||
margin-top: calc(var(--spacing) * 3);
|
||||
}
|
||||
.mt-4 {
|
||||
margin-top: calc(var(--spacing) * 4);
|
||||
}
|
||||
.mt-6 {
|
||||
margin-top: calc(var(--spacing) * 6);
|
||||
}
|
||||
.mb-1 {
|
||||
margin-bottom: var(--spacing);
|
||||
}
|
||||
.mb-2 {
|
||||
margin-bottom: calc(var(--spacing) * 2);
|
||||
}
|
||||
.mb-4 {
|
||||
margin-bottom: calc(var(--spacing) * 4);
|
||||
}
|
||||
.mb-6 {
|
||||
margin-bottom: calc(var(--spacing) * 6);
|
||||
}
|
||||
.ml-1 {
|
||||
margin-left: var(--spacing);
|
||||
}
|
||||
.ml-2 {
|
||||
margin-left: calc(var(--spacing) * 2);
|
||||
}
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
.table {
|
||||
display: table;
|
||||
}
|
||||
.h-16 {
|
||||
height: calc(var(--spacing) * 16);
|
||||
}
|
||||
.w-4 {
|
||||
width: calc(var(--spacing) * 4);
|
||||
}
|
||||
.w-6 {
|
||||
width: calc(var(--spacing) * 6);
|
||||
}
|
||||
.w-12 {
|
||||
width: calc(var(--spacing) * 12);
|
||||
}
|
||||
.w-16 {
|
||||
width: calc(var(--spacing) * 16);
|
||||
}
|
||||
.w-40 {
|
||||
width: calc(var(--spacing) * 40);
|
||||
}
|
||||
.w-full {
|
||||
width: 100%;
|
||||
}
|
||||
.max-w-2xl {
|
||||
max-width: var(--container-2xl);
|
||||
}
|
||||
.flex-1 {
|
||||
flex: 1;
|
||||
}
|
||||
.cursor-grab {
|
||||
cursor: grab;
|
||||
}
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
.items-center {
|
||||
align-items: center;
|
||||
}
|
||||
.justify-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
.justify-center {
|
||||
justify-content: center;
|
||||
}
|
||||
.justify-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.gap-1 {
|
||||
gap: var(--spacing);
|
||||
}
|
||||
.gap-2 {
|
||||
gap: calc(var(--spacing) * 2);
|
||||
}
|
||||
.gap-3 {
|
||||
gap: calc(var(--spacing) * 3);
|
||||
}
|
||||
:where(.space-y-1 > :not(:last-child)) {
|
||||
--tw-space-y-reverse: 0;
|
||||
margin-block-start: calc(var(--spacing) * var(--tw-space-y-reverse));
|
||||
margin-block-end: calc(var(--spacing) * calc(1 - var(--tw-space-y-reverse)));
|
||||
}
|
||||
:where(.space-y-2 > :not(:last-child)) {
|
||||
--tw-space-y-reverse: 0;
|
||||
margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
|
||||
margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
|
||||
}
|
||||
:where(.space-y-3 > :not(:last-child)) {
|
||||
--tw-space-y-reverse: 0;
|
||||
margin-block-start: calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));
|
||||
margin-block-end: calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)));
|
||||
}
|
||||
:where(.space-y-4 > :not(:last-child)) {
|
||||
--tw-space-y-reverse: 0;
|
||||
margin-block-start: calc(calc(var(--spacing) * 4) * var(--tw-space-y-reverse));
|
||||
margin-block-end: calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-y-reverse)));
|
||||
}
|
||||
.overflow-x-auto {
|
||||
overflow-x: auto;
|
||||
}
|
||||
.rounded {
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
.rounded-full {
|
||||
border-radius: calc(infinity * 1px);
|
||||
}
|
||||
.rounded-lg {
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
.border {
|
||||
border-style: var(--tw-border-style);
|
||||
border-width: 1px;
|
||||
}
|
||||
.border-2 {
|
||||
border-style: var(--tw-border-style);
|
||||
border-width: 2px;
|
||||
}
|
||||
.border-l-2 {
|
||||
border-left-style: var(--tw-border-style);
|
||||
border-left-width: 2px;
|
||||
}
|
||||
.border-dashed {
|
||||
--tw-border-style: dashed;
|
||||
border-style: dashed;
|
||||
}
|
||||
.p-0 {
|
||||
padding: 0px;
|
||||
}
|
||||
.p-2 {
|
||||
padding: calc(var(--spacing) * 2);
|
||||
}
|
||||
.p-3 {
|
||||
padding: calc(var(--spacing) * 3);
|
||||
}
|
||||
.py-8 {
|
||||
padding-block: calc(var(--spacing) * 8);
|
||||
}
|
||||
.py-16 {
|
||||
padding-block: calc(var(--spacing) * 16);
|
||||
}
|
||||
.pl-4 {
|
||||
padding-left: calc(var(--spacing) * 4);
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
.font-mono {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
.text-2xl {
|
||||
font-size: var(--text-2xl);
|
||||
line-height: var(--tw-leading, var(--text-2xl--line-height));
|
||||
}
|
||||
.text-3xl {
|
||||
font-size: var(--text-3xl);
|
||||
line-height: var(--tw-leading, var(--text-3xl--line-height));
|
||||
}
|
||||
.text-4xl {
|
||||
font-size: var(--text-4xl);
|
||||
line-height: var(--tw-leading, var(--text-4xl--line-height));
|
||||
}
|
||||
.text-6xl {
|
||||
font-size: var(--text-6xl);
|
||||
line-height: var(--tw-leading, var(--text-6xl--line-height));
|
||||
}
|
||||
.text-lg {
|
||||
font-size: var(--text-lg);
|
||||
line-height: var(--tw-leading, var(--text-lg--line-height));
|
||||
}
|
||||
.text-sm {
|
||||
font-size: var(--text-sm);
|
||||
line-height: var(--tw-leading, var(--text-sm--line-height));
|
||||
}
|
||||
.text-xl {
|
||||
font-size: var(--text-xl);
|
||||
line-height: var(--tw-leading, var(--text-xl--line-height));
|
||||
}
|
||||
.text-xs {
|
||||
font-size: var(--text-xs);
|
||||
line-height: var(--tw-leading, var(--text-xs--line-height));
|
||||
}
|
||||
.font-bold {
|
||||
--tw-font-weight: var(--font-weight-bold);
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
.font-medium {
|
||||
--tw-font-weight: var(--font-weight-medium);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
.tracking-wide {
|
||||
--tw-tracking: var(--tracking-wide);
|
||||
letter-spacing: var(--tracking-wide);
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.shadow {
|
||||
--tw-shadow: 0 1px 3px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 1px 2px -1px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
||||
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||
}
|
||||
.shadow-lg {
|
||||
--tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
|
||||
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
|
||||
}
|
||||
.transition-colors {
|
||||
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to;
|
||||
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
|
||||
transition-duration: var(--tw-duration, var(--default-transition-duration));
|
||||
}
|
||||
.active\:cursor-grabbing:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
}
|
||||
@layer theme, base, components, utilities;
|
||||
@layer theme;
|
||||
@layer base {
|
||||
*, ::after, ::before, ::backdrop, ::file-selector-button {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0 solid;
|
||||
}
|
||||
html, :host {
|
||||
line-height: 1.5;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
tab-size: 4;
|
||||
font-family: var(--default-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");
|
||||
font-feature-settings: var(--default-font-feature-settings, normal);
|
||||
font-variation-settings: var(--default-font-variation-settings, normal);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
hr {
|
||||
height: 0;
|
||||
color: inherit;
|
||||
border-top-width: 1px;
|
||||
}
|
||||
abbr:where([title]) {
|
||||
-webkit-text-decoration: underline dotted;
|
||||
text-decoration: underline dotted;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-size: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
a {
|
||||
color: inherit;
|
||||
-webkit-text-decoration: inherit;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
b, strong {
|
||||
font-weight: bolder;
|
||||
}
|
||||
code, kbd, samp, pre {
|
||||
font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);
|
||||
font-feature-settings: var(--default-mono-font-feature-settings, normal);
|
||||
font-variation-settings: var(--default-mono-font-variation-settings, normal);
|
||||
font-size: 1em;
|
||||
}
|
||||
small {
|
||||
font-size: 80%;
|
||||
}
|
||||
sub, sup {
|
||||
font-size: 75%;
|
||||
line-height: 0;
|
||||
position: relative;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
sub {
|
||||
bottom: -0.25em;
|
||||
}
|
||||
sup {
|
||||
top: -0.5em;
|
||||
}
|
||||
table {
|
||||
text-indent: 0;
|
||||
border-color: inherit;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
:-moz-focusring:where(:not(iframe)) {
|
||||
outline: auto;
|
||||
}
|
||||
progress {
|
||||
vertical-align: baseline;
|
||||
}
|
||||
summary {
|
||||
display: list-item;
|
||||
}
|
||||
ol, ul, menu {
|
||||
list-style: none;
|
||||
}
|
||||
img, svg, video, canvas, audio, iframe, embed, object {
|
||||
display: block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
img, video {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
button, input, select, optgroup, textarea, ::file-selector-button {
|
||||
font: inherit;
|
||||
font-feature-settings: inherit;
|
||||
font-variation-settings: inherit;
|
||||
letter-spacing: inherit;
|
||||
color: inherit;
|
||||
border-radius: 0;
|
||||
background-color: transparent;
|
||||
opacity: 1;
|
||||
}
|
||||
:where(select:is([multiple], [size])) optgroup {
|
||||
font-weight: bolder;
|
||||
}
|
||||
:where(select:is([multiple], [size])) optgroup option {
|
||||
padding-inline-start: 20px;
|
||||
}
|
||||
::file-selector-button {
|
||||
margin-inline-end: 4px;
|
||||
}
|
||||
::placeholder {
|
||||
opacity: 1;
|
||||
}
|
||||
@supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
|
||||
::placeholder {
|
||||
color: currentcolor;
|
||||
@supports (color: color-mix(in lab, red, red)) {
|
||||
color: color-mix(in oklab, currentcolor 50%, transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
::-webkit-date-and-time-value {
|
||||
min-height: 1lh;
|
||||
text-align: inherit;
|
||||
}
|
||||
::-webkit-datetime-edit {
|
||||
display: inline-flex;
|
||||
}
|
||||
::-webkit-datetime-edit-fields-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
|
||||
padding-block: 0;
|
||||
}
|
||||
::-webkit-calendar-picker-indicator {
|
||||
line-height: 1;
|
||||
}
|
||||
:-moz-ui-invalid {
|
||||
box-shadow: none;
|
||||
}
|
||||
button, input:where([type="button"], [type="reset"], [type="submit"]), ::file-selector-button {
|
||||
appearance: button;
|
||||
}
|
||||
::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
|
||||
height: auto;
|
||||
}
|
||||
[hidden]:where(:not([hidden="until-found"])) {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
@layer utilities;
|
||||
@property --tw-space-y-reverse {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0;
|
||||
}
|
||||
@property --tw-border-style {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: solid;
|
||||
}
|
||||
@property --tw-font-weight {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-tracking {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-shadow {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0 0 #0000;
|
||||
}
|
||||
@property --tw-shadow-color {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-shadow-alpha {
|
||||
syntax: "<percentage>";
|
||||
inherits: false;
|
||||
initial-value: 100%;
|
||||
}
|
||||
@property --tw-inset-shadow {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0 0 #0000;
|
||||
}
|
||||
@property --tw-inset-shadow-color {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-inset-shadow-alpha {
|
||||
syntax: "<percentage>";
|
||||
inherits: false;
|
||||
initial-value: 100%;
|
||||
}
|
||||
@property --tw-ring-color {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-ring-shadow {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0 0 #0000;
|
||||
}
|
||||
@property --tw-inset-ring-color {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-inset-ring-shadow {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0 0 #0000;
|
||||
}
|
||||
@property --tw-ring-inset {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
}
|
||||
@property --tw-ring-offset-width {
|
||||
syntax: "<length>";
|
||||
inherits: false;
|
||||
initial-value: 0px;
|
||||
}
|
||||
@property --tw-ring-offset-color {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: #fff;
|
||||
}
|
||||
@property --tw-ring-offset-shadow {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: 0 0 #0000;
|
||||
}
|
||||
@layer properties {
|
||||
@supports ((-webkit-hyphens: none) and (not (margin-trim: block))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
|
||||
*, ::before, ::after, ::backdrop {
|
||||
--tw-space-y-reverse: 0;
|
||||
--tw-border-style: solid;
|
||||
--tw-font-weight: initial;
|
||||
--tw-tracking: initial;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
--tw-shadow-color: initial;
|
||||
--tw-shadow-alpha: 100%;
|
||||
--tw-inset-shadow: 0 0 #0000;
|
||||
--tw-inset-shadow-color: initial;
|
||||
--tw-inset-shadow-alpha: 100%;
|
||||
--tw-ring-color: initial;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-inset-ring-color: initial;
|
||||
--tw-inset-ring-shadow: 0 0 #0000;
|
||||
--tw-ring-inset: initial;
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@import "tailwindcss";
|
||||
@import "tailwindcss" source("..");
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
$formRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
|
||||
$forms = $formRepository->getAll(["id", "name"]);
|
||||
|
||||
$formOptions = [];
|
||||
foreach ($forms as $form) {
|
||||
$formOptions[] = [
|
||||
"id" => $form["id"],
|
||||
"name" => $form["name"],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"title" => "Form Wrapper",
|
||||
"category" => "Form",
|
||||
"icon" => "fa fa-hand-peace-o",
|
||||
"settings" => [
|
||||
"formId" => [
|
||||
"type" => "select",
|
||||
"label" => "Formular",
|
||||
"value" => 0,
|
||||
"options" => $formOptions,
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
$formRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
|
||||
$id = $block->setting("formId");
|
||||
if ($id > 0):
|
||||
|
||||
$form = $formRepository->findWithId($id);
|
||||
$fields = json_decode($form["fields"], true);
|
||||
?>
|
||||
|
||||
<div class="max-w-2xl mx-auto">
|
||||
<div x-data="{data: {fields : {}}, status: 'idle', submitted: false}">
|
||||
<form x-show="!submitted" x-transition:leave x-transition:leave-opacity-0 x-on:submit.prevent="
|
||||
status = 'busy';
|
||||
fetch('/ext--form/submit?id=<?= $id ?>', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
}).finally(() => {
|
||||
status = 'idle';
|
||||
submitted = true;
|
||||
})
|
||||
">
|
||||
<?php foreach ($fields as $field):
|
||||
|
||||
$fieldName = $field["name"];
|
||||
$fieldLabel = $field["label"];
|
||||
$fieldType = $field["type"];
|
||||
$fieldRequired =
|
||||
isset($field["required"]) && $field["required"];
|
||||
$fieldOptions = isset($field["options"])
|
||||
? $field["options"]
|
||||
: [];
|
||||
?>
|
||||
<div class="form-control mb-4">
|
||||
<label class="label mb-1">
|
||||
<span class="label-text font-medium">
|
||||
<?= $fieldLabel ?>
|
||||
<?php if ($fieldRequired): ?>
|
||||
<span class="text-error ml-1">*</span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</label>
|
||||
<?php if ($fieldType === "select"): ?>
|
||||
<select x-model="data.fields.<?= $fieldName ?>" class="select select-bordered w-full" <?= $fieldRequired
|
||||
? "required"
|
||||
: "" ?>>
|
||||
<option value="" disabled selected>Bitte wählen</option>
|
||||
<?php foreach ($fieldOptions as $option): ?>
|
||||
<option value="<?= $option[
|
||||
"value"
|
||||
] ?>"><?= $option["label"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php elseif ($fieldType === "checkbox"): ?>
|
||||
<div class="space-y-2">
|
||||
<?php foreach ($fieldOptions as $option): ?>
|
||||
<label class="label cursor-pointer gap-3">
|
||||
<span class="label-text"><?= $option[
|
||||
"label"
|
||||
] ?></span>
|
||||
<input type="checkbox" value="<?= $option[
|
||||
"value"
|
||||
] ?>" x-model="data.fields.<?= $fieldName ?>" class="checkbox checkbox-sm checkbox-primary" />
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($fieldType === "radio"): ?>
|
||||
<div class="space-y-2">
|
||||
<?php foreach ($fieldOptions as $option): ?>
|
||||
<label class="label cursor-pointer gap-3">
|
||||
<span class="label-text"><?= $option[
|
||||
"label"
|
||||
] ?></span>
|
||||
<input type="radio" name="<?= $fieldName ?>" value="<?= $option[
|
||||
"value"
|
||||
] ?>" x-model="data.fields.<?= $fieldName ?>" class="radio radio-sm radio-primary" />
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php elseif ($fieldType === "textarea"): ?>
|
||||
<textarea x-model="data.fields.<?= $fieldName ?>" class="textarea textarea-bordered w-full" placeholder="<?= $fieldLabel ?>" <?= $fieldRequired
|
||||
? "required"
|
||||
: "" ?> rows="4"></textarea>
|
||||
<?php else: ?>
|
||||
<input type="<?= $fieldType ?>" x-model="data.fields.<?= $fieldName ?>" class="input input-bordered w-full" placeholder="<?= $fieldLabel ?>" <?= $fieldRequired
|
||||
? "required"
|
||||
: "" ?>>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
endforeach; ?>
|
||||
<div class="mt-6">
|
||||
<button type="submit" class="btn btn-primary w-full" :disabled="status === 'busy'">
|
||||
<span x-show="status === 'idle'">
|
||||
<i class="ph-duotone ph-paper-plane-tilt"></i>
|
||||
Absenden
|
||||
</span>
|
||||
<span x-show="status === 'busy'">
|
||||
<span class="loading loading-spinner loading-sm"></span>
|
||||
Wird gesendet...
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<div x-show="submitted" x-transition:enter x-transition:enter-opacity-0 x-transition:enter-delay-100 class="card bg-base-100 shadow-lg mt-4">
|
||||
<div class="card-body items-center text-center">
|
||||
<div class="w-16 h-16 rounded-full bg-success/20 flex items-center justify-center mb-2">
|
||||
<i class="ph-duotone ph-check text-3xl text-success"></i>
|
||||
</div>
|
||||
<h3 class="card-title text-lg">Vielen Dank!</h3>
|
||||
<p class="text-base-content/60">Ihre Nachricht wurde erfolgreich gesendet.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
else:
|
||||
?>
|
||||
<div class="form-wrapper max-w-2xl mx-auto">
|
||||
<div class="card bg-base-200 border-2 border-dashed border-base-300">
|
||||
<div class="card-body items-center text-center py-8">
|
||||
<i class="ph-duotone ph-plus-circle text-4xl text-base-content/30"></i>
|
||||
<p class="text-sm text-base-content/50 mt-2">Wählen Sie ein Formular in den Einstellungen aus</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endif; ?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"title" => "Form",
|
||||
"author" => "Paul Spenke",
|
||||
"identifier" => "form",
|
||||
"licence" => "MIT",
|
||||
"version" => "1.0.0",
|
||||
"settings" => [
|
||||
[
|
||||
"name" => "email",
|
||||
"label" => "Email",
|
||||
"default" => "admin@example.com",
|
||||
"type" => "text",
|
||||
],
|
||||
],
|
||||
"assets" => [
|
||||
[
|
||||
"src" => "/assets/dist.css",
|
||||
"type" => "style",
|
||||
"location" => "header",
|
||||
],
|
||||
],
|
||||
"tables" => [
|
||||
"entries" => [
|
||||
"columns" => [
|
||||
"formId" => "int NOT NULL",
|
||||
"data" => "longtext NOT NULL",
|
||||
"created" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP",
|
||||
],
|
||||
"uniqueKeys" => [],
|
||||
],
|
||||
"definitions" => [
|
||||
"columns" => [
|
||||
"name" => "varchar(255) NOT NULL",
|
||||
"fields" => "longtext NOT NULL",
|
||||
"finishers" => "longtext NOT NULL",
|
||||
],
|
||||
"uniqueKeys" => [
|
||||
"name" => ["name"],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Plugi\Extensions;
|
||||
|
||||
Extensions::addRoutes([
|
||||
'/ext--form/submit' => dirname(__FILE__) . '/routes/submit.php',
|
||||
'/ext--form/save-form' => dirname(__FILE__) . '/routes/saveForm.php',
|
||||
'/ext--form/delete-form' => dirname(__FILE__) . '/routes/deleteForm.php',
|
||||
'/ext--form/delete-entry' => dirname(__FILE__) . '/routes/deleteEntry.php',
|
||||
]);
|
||||
|
||||
Extensions::addBlocks([
|
||||
'form-wrapper' => __DIR__ . '/blocks/form-wrapper'
|
||||
]);
|
||||
|
||||
Extensions::registerBackend('form', [
|
||||
'title' => 'Form',
|
||||
'include' => __DIR__ . '/admin/form.php',
|
||||
'icon' => '<i class="ph ph-paper-plane-tilt"></i>',
|
||||
]);
|
||||
+1030
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@tailwindcss/cli": "^4.3.5",
|
||||
"tailwindcss": "^4.3.5"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npx -y @tailwindcss/cli -i ./assets/main.css -o ./assets/dist.css --watch",
|
||||
"build": "npx -y @tailwindcss/cli -i ./assets/main.css -o ./assets/dist.css"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
phpb_requires_authenticated();
|
||||
$entriesRepository = new \Plugi\Extensions\Form\EntriesRepository();
|
||||
|
||||
if(
|
||||
isset($_GET['id'])
|
||||
) {
|
||||
$entriesRepository->destroy($_GET['id']);
|
||||
}
|
||||
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'listEntries', 'id' => $_GET['formId']]));
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
phpb_requires_authenticated();
|
||||
$formsRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
|
||||
$entriesRepository = new \Plugi\Extensions\Form\EntriesRepository();
|
||||
|
||||
if(
|
||||
isset($_GET['id'])
|
||||
) {
|
||||
$formsRepository->destroy($_GET['id']);
|
||||
$entriesRepository->destroyWhere('formId', $_GET['id']);
|
||||
}
|
||||
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'listForms']));
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
phpb_requires_authenticated();
|
||||
$formsRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
|
||||
|
||||
if(
|
||||
isset($_POST['name'])
|
||||
) {
|
||||
if(isset($_POST['id'])){
|
||||
$form = [
|
||||
'id' => $_POST['id'],
|
||||
'name' => $_POST['name'],
|
||||
'fields' => $_POST['fields'],
|
||||
'finishers' => $_POST['finishers'],
|
||||
];
|
||||
$formsRepository->update($form, $form);
|
||||
} else {
|
||||
$formsRepository->create([
|
||||
'name' => $_POST['name'],
|
||||
'fields' => $_POST['fields'],
|
||||
'finishers' => $_POST['finishers'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
phpb_redirect(phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'listForms']));
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$formsRepository = new \Plugi\Extensions\Form\DefinitionsRepository();
|
||||
|
||||
$form = $formsRepository->findWithId($_GET['id']);
|
||||
$formFinishers = json_decode($form['finishers'], true);
|
||||
|
||||
$finishers = new \Plugi\Extensions\Form\Finishers\FinishersRepository();
|
||||
|
||||
|
||||
|
||||
foreach ($formFinishers as $finisher) {
|
||||
if ($finishers->finisherExists($finisher['type'])) {
|
||||
$config = $finishers->getFinisherConfig($finisher['type']);
|
||||
$instance = new $config['class'];
|
||||
$instance->execute();
|
||||
}
|
||||
}
|
||||
|
||||
phpb_redirect('/', [], 201);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user