tournament controls
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s

This commit is contained in:
Chris 2023-10-26 21:18:32 +02:00
parent 135958c9f0
commit 00c2e1ded6
6 changed files with 217 additions and 59 deletions

View File

@ -14,4 +14,17 @@ class Tournament extends Model
'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg'] 'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg']
); );
function isMyEvent($tournament = false)
{
if ($tournament == false)
$tournament = $this->id;
if (!$this->exists($tournament))
return false;
else {
if (in_array($tournament, $_SESSION['user']->data['tournaments']))
return true;
else return false;
}
}
} }

View File

@ -102,7 +102,7 @@ class Dogs extends Page {
$photo_error = $photo['error']; $photo_error = $photo['error'];
$photo_type = $photo['type']; $photo_type = $photo['type'];
$allowed = ['jpg','jpeg','png']; $allowed = ['jpg','jpeg','png','gif'];
$photo_ext = strtolower(end(explode('.', $photo_name))); $photo_ext = strtolower(end(explode('.', $photo_name)));
$photo_name = $name.'.'.$photo_ext; $photo_name = $name.'.'.$photo_ext;
$photo_path = 'uploads/'.$photo_name; $photo_path = 'uploads/'.$photo_name;
@ -118,20 +118,14 @@ class Dogs extends Page {
$newphoto = $answer['url']; $newphoto = $answer['url'];
} }
else else
{
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']); return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']);
} }
}
else else
{
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Beim Upload der Datei ist ein Fehler aufgetreten']); return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Beim Upload der Datei ist ein Fehler aufgetreten']);
} }
}
else else
{
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']); return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']);
} }
}
$error = false; $error = false;
if(!$name || !$dog_birthday ) if(!$name || !$dog_birthday )

View File

@ -13,14 +13,14 @@ class Tournaments extends Page {
{ {
$this->addSubmenuItem('Übersicht','/tournaments','far fa-list-alt'); $this->addSubmenuItem('Übersicht','/tournaments','far fa-list-alt');
$this->addSubmenuItem('Turnier anlegen','/tournaments/add','fas fa-calendar-plus'); $this->addSubmenuItem('Turnier anlegen','/tournaments/add','fas fa-calendar-plus');
if($_SESSION['user']->data['dogs'] && count($_SESSION['user']->data['tournaments']) > 0) if($_SESSION['user']->data['tournaments'] && count($_SESSION['user']->data['tournaments']) > 0)
{ {
$this->addSubmenuItem('divider'); $this->addSubmenuItem('divider');
foreach($_SESSION['user']->data['tournaments'] as $tid) foreach($_SESSION['user']->data['tournaments'] as $tid)
{ {
$t = new Tournament(); $t = new Tournament();
$t->load($tid); $t->load($tid);
$this->addSubmenuItem($t->data['name'],'/dogs/overview/'.$tid,'fas fa-dog'); $this->addSubmenuItem($t->data['name'],'/tournaments/event/'.$tid,'fas fa-dog');
} }
} }
} }
@ -34,6 +34,144 @@ class Tournaments extends Page {
} }
function event()
{
$tid = $this->params[0];
$t = new Tournament();
if(!$t->isMyEvent($tid))
return 'Not your event :(';
$t->load($tid);
$this->set('tournament_id',$tid);
$this->set('tdata',$t->data);
$this->set('template','event.html');
}
function edit()
{
if($_REQUEST['submit'])
{
$id = $_REQUEST['tournament_id'];
$name = $_REQUEST['tournament_name'];
$date = $_REQUEST['tournament_date'];
$tournament_referee = $_REQUEST['tournament_referee'];
$tournament_duration = intval($_REQUEST['tournament_duration']);
$tournament_url = $_REQUEST['tournament_url'];
$tournament_text = $_REQUEST['tournament_text'];
$newlogo = false;
if($_FILES['logo'])
{
$logo = $_FILES['logo'];
$logo_name = $logo['name'];
$logo_tmp_name = $logo['tmp_name'];
$logo_size = $logo['size'];
$logo_error = $logo['error'];
$logo_type = $logo['type'];
$allowed = ['jpg','jpeg','png','gif'];
$logo_ext = strtolower(end(explode('.', $logo_name)));
$logo_name = $name.'.'.$logo_ext;
$logo_path = 'uploads/'.$logo_name;
if(in_array($logo_ext, $allowed))
{
if($logo_error === 0)
{
if($logo_size < 10000000)
{
$answer = pictshareUploadImage($logo_tmp_name);
if($answer['status']=='ok' && in_array($answer['filetype'],['jpeg','png','gif']))
$newlogo = $answer['url'];
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Beim Upload der Datei ist ein Fehler aufgetreten']);
}
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen']);
}
$error = false;
if(!$name || !$date )
$error = 'Bitte zumindest Name und Datum angeben';
else if(!strtotime($date))
$error = 'Das Datumm ist ungültig. Bitte die Eingabe prüfen';
if($error){
$this->set('errorMessage', $error);
$this->set('template', '/templates/partials/error.html');
return;
}
else
{
$t = new Tournament();
if($id)
$t->load($id);
$t->name = $name;
$t->date = $date;
$t->duration = $tournament_duration;
$t->referee = $tournament_referee;
$t->text = $tournament_text;
$t->url = $tournament_url;
if($newlogo)
$t->logo = $newlogo;
try
{
$tid = $t->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
//var_dump($_SESSION['user']->data['dogs']);
if(!is_array($_SESSION['user']->data['tournaments']) || !in_array($tid, $_SESSION['user']->data['tournaments'])) // new t!
{
$_SESSION['user']->data['tournaments'][] = $tid;
try
{
$_SESSION['user']->save();
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
return;
}
$this->redirect('/tournaments/event/'.$tid);
}
else
{
$this->set('template', '/templates/partials/success.html');
$this->set('successMessage', "Daten erfolgreich gespeichert");
return;
}
}
}
else
{
$id = $this->params[0];
$t = new Tournament();
$t->load($id);
$this->set('tournamentdata',$t->data);
$this->set('tournamentid',$t->id);
$this->set('template', 'edit_tournament.html');
}
}
function maySeeThisPage() { function maySeeThisPage() {
if($_SESSION['user']) //wenn eingeloggt, kein problem if($_SESSION['user']) //wenn eingeloggt, kein problem
return true; return true;

View File

@ -4,19 +4,40 @@
<form id="tournamenteditform" hx-post="/tournaments/edit" hx-encoding='multipart/form-data' hx-target="#response"> <form id="tournamenteditform" hx-post="/tournaments/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="tournament_id" value="<?= $tournamentid; ?>"> <input type="hidden" name="tournament_id" value="<?= $tournamentid; ?>">
<div> <div>
<label for="tournament_name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Veranstaltung</label> <label for="tournament_name">Veranstaltungsname</label>
<input type="text" value="<?= $tournament['name']; ?>" id="tournament_name" name="tournament_name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Max" required> <input type="text" value="<?= $tournamentdata['name']; ?>" id="tournament_name" name="tournament_name" placeholder="Agilititties" required>
</div> </div>
<div> <div>
<label for="tournament_date" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Datum</label> <label for="tournament_date">Datum</label>
<input type="date" value="<?= $tournamentdata['tournament_date']; ?>" id="tournament_date" name="tournament_date" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Zuchtname"> <input type="date" value="<?= $tournamentdata['date']; ?>" id="date" name="tournament_date" placeholder="Zuchtname">
</div> </div>
<div> <div>
<label for="tournament_judge" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Richter</label> <label for="tournament_duration">Dauer der Veranstaltung in tagen</label>
<input type="text" value="<?= $tournamentdata['tournament_judge']; ?>" id="tournament_judge" name="tournament_judge" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Flowbite"> <input type="number" min="1" max="7" value="<?= $tournamentdata['duration']; ?>" id="tournament_duration" name="tournament_duration">
</div>
<div>
<label for="tournament_referee">Richter</label>
<input type="text" value="<?= $tournamentdata['referee']; ?>" id="tournament_referee" name="tournament_referee" placeholder="Franz Ferdinand">
</div>
<div>
<label for="tournament_url">Weblink</label>
<input type="text" value="<?= $tournamentdata['url']; ?>" id="tournament_url" name="tournament_url" placeholder="https://facebook.com/...">
</div>
<div>
<label for="logo">Logo des Events</label>
<input type="file" accept="image/png, image/jpeg, image/gif" id="logo" name="logo">
</div>
<div>
<label for="tournament_text">Beschreibungstext</label>
<textarea id="tournament_text" name="tournament_text"><?= $tournamentdata['text']; ?></textarea>
</div> </div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Submit</button> <!-- Submit Button führt auf eine neue Seite wo man die Laufinfo eingibt --> <button type="submit" name="submit" value="true" class="btn btn-primary">Submit</button> <!-- Submit Button führt auf eine neue Seite wo man die Laufinfo eingibt -->
</form> </form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div> <div id="response"></div>
</div> </div>

View File

@ -0,0 +1,35 @@
<!-- FILEPATH: /home/chris/git/tournamentstats/web/pages/tournaments/dog.html -->
<div class="container">
<div class="row">
<div class="col-3">
<div class="card">
<img src="<?= $tdata['logo'] ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($tdata['name']); ?>'s profile Picture">
<div class="card-body">
<h5 class="card-title"><?= escape($tdata['name']); ?></h5>
<p class="card-text">
<ul>
<li>Datum: <?= escape($tdata['date']) ?></li>
<?php if($tdata['duration']): ?><li>Dauer: <?= escape($tdata['duration']); ?> Tag/e</li> <?php endif; ?>
<?php if($tdata['referee']): ?><li>Richter: <?= escape($tdata['referee']); ?></li> <?php endif; ?>
<?php if($tdata['size']): ?><li>Größe: <?= escape($tdata['size']); ?> cm</li> <?php endif; ?>
<?php if($tdata['url']): ?><li>Webseite: <a href="<?= $tdata['url']; ?>"><?= escape($tdata['url']); ?></a></li> <?php endif; ?>
</ul>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-secondary" hx-get="/tournaments/edit/<?= $tournament_id; ?>" hx-target="#main">
<i class="fas fa-edit"></i>
</button>
</div>
</div>
</div>
</div>
<div class="col-8" id="sitemain">
<pre><?= escape($tdata['text']); ?></pre>
</div>
</div>
</div>

View File

@ -1,43 +0,0 @@
<h1">Meine Hunde</h1>
<figure>
<table>
<thead>
<tr>
<?php foreach (array_keys($doggos[0]) as $key) : ?>
<th>
<?= $key ?>
</th>
<?php endforeach; ?>
<th>
Bearbeiten
</th>
<th>
Löschen
</th>
</tr>
</thead>
<tbody>
<?php foreach ($doggos as $dog) : ?>
<tr>
<?php foreach (array_keys($dog) as $key) : ?>
<td>
<?= $dog[$key] ?>
</td>
<?php endforeach; ?>
<td>
<button hx-get="/dogs/edit/<?= $dog['id'] ?>" hx-push-url="/dogs/edit/<?= $dog['id'] ?>" hx-target="#main" >Bearbeiten</button>
</td>
<td>
<button hx-get="/dogs/delete/<?= $dog['id'] ?>" hx-target="#main" >Löschen</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</figure>