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

This commit is contained in:
piapassecker 2023-10-26 17:42:33 +02:00
parent 0f13bdea27
commit cda6945324
5 changed files with 404 additions and 0 deletions

View File

@ -0,0 +1,202 @@
<?php
class Tournaments extends Page {
function setMenu()
{
$this->menu_text = 'Turniere';
$this->menu_image = 'far fa-medal';
$this->menu_priority = 1;
}
function index() {
$dogs = $_SESSION['user']->data['dogs'];
$doggos = [];
foreach($dogs as $key => $dogid)
{
//var_dump($dogid);
$dog = new Dog();
try{
$dog->load($dogid);
}
catch(Exception $e)
{
error_log("Dog $dogid not found. Deleting from user");
unset($_SESSION['user']->data['dogs'][$key]);
$_SESSION['user']->save();
continue;
}
if($dog->data)
$doggos[] = array_merge($dog->data,['id'=>$dogid]);
}
//var_dump($doggos);
if(count($doggos) > 0)
{
$this->set('doggos',$doggos);
$this->set('template', 'list.html');
}
else
{
$this->set('template','/templates/partials/info.html');
$this->set('infoTitle', 'Keine Turniere gefunden');
$this->set('infoMessage', 'Du hast aktuell noch kein Turnier angelegt. Klicke im Menü auf "Turnier hinzufügen" um einen Turnier anzulegen.');
}
}
function add() {
$this->set('template', 'edit.html');
}
function edit() {
if($_REQUEST['submit'])
{
$id = $_REQUEST['dog_id'];
$name = $_REQUEST['name'];
$kennel_name = $_REQUEST['kennel_name'];
$dog_breed = $_REQUEST['dog_breed'];
$dog_size = $_REQUEST['dog_size'];
$dog_birthday = $_REQUEST['dog_birthday'];
$agi_height_category = $_REQUEST['agi_height_category'];
$newphoto = false;
if($_FILES['photo'])
{
$photo = $_FILES['photo'];
$photo_name = $photo['name'];
$photo_tmp_name = $photo['tmp_name'];
$photo_size = $photo['size'];
$photo_error = $photo['error'];
$photo_type = $photo['type'];
$allowed = ['jpg','jpeg','png'];
$photo_ext = strtolower(end(explode('.', $photo_name)));
$photo_name = $name.'.'.$photo_ext;
$photo_path = 'uploads/'.$photo_name;
if(in_array($photo_ext, $allowed))
{
if($photo_error === 0)
{
if($photo_size < 10000000)
{
$answer = pictshareUploadImage($photo_tmp_name);
if($answer['status']=='ok' && in_array($answer['filetype'],['jpeg','png','gif']))
$newphoto = $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 || !$dog_birthday )
$error = 'Bitte zumindest Name und Geburtsdatum angeben';
else if(!strtotime($dog_birthday))
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
if($error){
$this->set('errorMessage', $error);
$this->set('template', '/templates/partials/error.html');
return;
}
else
{
$dog = new Dog();
if($id)
$dog->load($id);
$dog->name = $name;
$dog->kennel_name = $kennel_name;
$dog->breed = $dog_breed;
$dog->size = $dog_size;
$dog->birthday = $dog_birthday;
$dog->agility_size = $agi_height_category;
if($newphoto)
$dog->photo = $newphoto;
try
{
$dogid = $dog->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['dogs']) || !in_array($dogid, $_SESSION['user']->data['dogs'])) // new dog!
{
$_SESSION['user']->data['dogs'][] = $dogid;
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('/dogs');
}
else
{
$this->set('template', '/templates/partials/success.html');
$this->set('successMessage', "Daten erfolgreich gespeichert");
return;
}
}
}
else
{
//checken ob der den hund eh bearbeiten darf
$id = $this->params[0];
$dog = new Dog();
$dog->load($id);
$this->set('dogdata',$dog->data);
$this->set('dogid',$dog->id);
$this->set('template', 'edit.html');
}
}
function overview()
{
$dogid = $this->params[0];
$d = new Dog();
if(!$d->isMyDog($dogid))
return 'Not your dog :(';
$d->load($dogid);
$this->set('dogdata', $d->data);
$this->set('dogid', $dogid);
$this->set('template', 'dog.html');
}
function maySeeThisPage() {
if($_SESSION['user']) //wenn eingeloggt, kein problem
return true;
else return false;
}
}

View File

@ -0,0 +1,28 @@
<div>
<h1>Turnier <?= $tournamentid?'Bearbeiten':'Hinzufügen'; ?></h1>
<form id="tournamenteditform" hx-post="/tournaments/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="tournament_id" value="<?= $tournamentid; ?>">
<div>
<label for="tournament_name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Veranstaltung</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>
</div>
<div>
<label for="tournament_date" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">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">
</div>
<div>
<label for="tournament_judge" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Richter</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">
</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 -->
</form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div>
</div>
<script>
htmx.on('#dogeditform', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>

View File

@ -0,0 +1,96 @@
<!-- das hier sollte bei einem Turnier mehrfach hinzugefügt werden können. Auswahl aus Agility & Jumping -->
<div>
<h1>Agility / Jumping <?= $run_id?'Bearbeiten':'Hinzufügen'; ?></h1>
<form id="tournamenteditform" hx-post="/tournaments/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="tournament_id" value="<?= $run_id; ?>">
<h2>Parcourdetails</h2>
<div>
<label for="run_category" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Parcourtyp</label>
<select id="run_category" name="run_category" 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">
<option value="Agility" <?= $dogdata['run_category']=='Agility'?'selected':''; ?>>Agility</option>
<option value="Jumping" <?= $dogdata['run_category']=='Jumping'?'selected':''; ?>>Jumping</option>
</select>
</div>
<div>
<label for="run_length" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Parcourlänge (in m)</label>
<input type="text" value="<?= $run['run_length']; ?>" id="run_length" name="run_length" 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>
</div>
<div>
<label for="norm_time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Normzeit</label>
<input type="number" value="<?= $run['norm_time']; ?>" id="norm_time" name="norm_time" 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">
</div>
<div>
<label for="max_time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Maxzeit</label>
<input type="number" value="<?= $run['max_time']; ?>" id="max_time" name="max_time" 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">
</div>
<h2>Ergebnis</h2>
<div>
<label for="eliminated" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Disqualifiziert</label>
<input type="number" value="<?= $run['eliminated']; ?>" id="eliminated" name="eliminated" 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">
</div>
<div>
<label for="refusals" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Verweigerungen</label>
<input type="number" value="<?= $run['refusals']; ?>" id="refusals" name="refusals" 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">
</div>
<div>
<label for="faults" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Fehler</label>
<input type="number" value="<?= $run['faults']; ?>" id="faults" name="faults" 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">
</div>
<div>
<label for="time_faults" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Zeitfehler</label>
<input type="number" value="<?= $run['time_faults']; ?>" id="time_faults" name="time_faults" 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">
</div>
<div>
<label for="time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Zeit</label>
<input type="number" value="<?= $run['time']; ?>" id="time" name="time" 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">
</div>
<div>
<label for="penalties" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Gesamtfehler</label>
<input type="number" value="<?= $run['penalties']; ?>" id="penalties" name="penalties" 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">
</div>
<div>
<label for="time_speed" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">m/Sek</label>
<input type="number" value="<?= $run['time_speed']; ?>" id="time_speed" name="time_speed" 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">
</div>
<div>
<label for="bewertung" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Bewertung</label>
<select id="bewertung" name="bewertung" 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">
<option value="V" <?= $dogdata['bewertung']=='V'?'selected':''; ?>>V</option>
<option value="SG" <?= $dogdata['bewertung']=='SG'?'selected':''; ?>>SG</option>
<option value="G" <?= $dogdata['bewertung']=='G'?'selected':''; ?>>G</option>
<option Galue="B" <?= $dogdata['bewertung']=='B'?'selected':''; ?>>B</option>
</select>
</div>
<div>
<label for="points" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Punkte</label>
<input type="number" value="<?= $run['points']; ?>" id="points" name="points" 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">
</div>
<div>
<label for="rank" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Platz</label>
<input type="number" value="<?= $run['rank']; ?>" id="rank" name="rank" 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">
</div>
<div>
<label for="uploads" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Uploads</label>
<input type="file" accept="image/png, image/jpeg, image/gif" id="uploads" name="uploads">
</div>
<div>
<label for="video-url" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Video Url</label>
<input type="text" value="<?= $run['video-url']; ?>" class="form-control" id="video-url" aria-describedby="basic-addon3">
</div>
<div>
<label for="memo" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Memo</label>
<textarea value="<?= $run['memo']; ?>" id="memo" name="memo" 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="Deine Gedankengänge"></textarea>
</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 -->
</form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div>
</div>
<script>
htmx.on('#dogeditform', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>

View File

@ -0,0 +1,43 @@
<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>

View File

@ -0,0 +1,35 @@
<!-- FILEPATH: /home/chris/git/dogstats/web/pages/dogs/dog.html -->
<div class="container">
<h1>Wettkämpfe</h1>
<div class="row">
<div class="col-3">
<div class="card">
<img src="<?= $dogdata['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($dogdata['name']); ?>'s profile Picture">
<div class="card-body">
<h5 class="card-title"><?= escape($dogdata['name']); ?></h5>
<p class="card-text">
<ul>
<li>Rasse: <?= escape($dogdata['breed'])?:'Nicht eingetragen'; ?></li>
<li>Alter: <?= date_diff(date_create($dogdata['birthday']), date_create('now'))->y ?></li>
<?php if($dogdata['kennel_name']): ?><li>Zuchtname: <?= escape($dogdata['kennel_name']); ?></li> <?php endif; ?>
<?php if($dogdata['size']): ?><li>Größe: <?= escape($dogdata['size']); ?> cm</li> <?php endif; ?>
<?php if($dogdata['agility_size']): ?><li>Agility Größe: <?= escape($dogdata['agility_size']); ?></li> <?php endif; ?>
</ul>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-secondary" hx-get="/dogs/edit/<?= $dogid; ?>" hx-target="#main">
<i class="fas fa-edit"></i>
</button>
</div>
</div>
</div>
</div>
<div class="col-8">
Second Column
</div>
</div>
</div>