Merge branch 'master' of gitea.haschek.at:Crispi/dogstats
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
This commit is contained in:
commit
87401267e1
@ -16,8 +16,8 @@
|
||||
</div>
|
||||
|
||||
<h1>Admin stuff</h1>
|
||||
<figure>
|
||||
<table role="grid">
|
||||
<figure class="table-responsive">
|
||||
<table class="table" role="grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php foreach (array_keys($userdata[0]) as $key) : ?>
|
||||
@ -38,18 +38,19 @@
|
||||
<?php foreach ($userdata as $user) : ?>
|
||||
|
||||
<tr>
|
||||
<?php foreach (array_keys($user) as $key) : ?>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
<?= is_array($user[$key])?json_encode($user[$key]):$user[$key] ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<td>
|
||||
<button name="email" value="<?= $user['email'] ?>" hx-post="/admin/loginas/">Login</button>
|
||||
</td>
|
||||
<td>
|
||||
<button name="email" value="<?= $user['email'] ?>" hx-post="/admin/edituser/" hx-target="#main">Edit</button>
|
||||
</td>
|
||||
<?php foreach (array_keys($user) as $key) : ?>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">
|
||||
<?= is_array($user[$key])?json_encode($user[$key]):$user[$key] ?>
|
||||
</td>
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
178
web/pages/profile/controller.php
Normal file
178
web/pages/profile/controller.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
class Profile extends Page {
|
||||
|
||||
function setSubmenu()
|
||||
{
|
||||
|
||||
if($_SESSION['user'] > 0)
|
||||
{
|
||||
$this->addSubmenuItem('Mein Profil','/profile','fa-regular fa-id-badge');
|
||||
}
|
||||
}
|
||||
|
||||
function index() {
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
}
|
||||
|
||||
function delete(){
|
||||
$dogid = $this->params[0];
|
||||
$d = new Dog();
|
||||
|
||||
if(!$d->isMyDog($dogid))
|
||||
return 'Not your dog :(';
|
||||
|
||||
$d->load($dogid);
|
||||
$d->delete();
|
||||
|
||||
$_SESSION['user']->removeDog($dogid);
|
||||
$this->redirect('/');
|
||||
}
|
||||
|
||||
function edit() {
|
||||
if($_REQUEST['submit'])
|
||||
{
|
||||
$id = $_REQUEST['dog_id'];
|
||||
$name = $_REQUEST['name'];
|
||||
$kennel_name = $_REQUEST['kennel_name'];
|
||||
$dog_breed = $_REQUEST['dog_breed'];
|
||||
$dog_size = intval($_REQUEST['dog_size']);
|
||||
$dog_birthday = $_REQUEST['dog_birthday'];
|
||||
$agi_height_category = $_REQUEST['agi_height_category'];
|
||||
$newphoto = false;
|
||||
$active = intval($_REQUEST['agi_active']);
|
||||
|
||||
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','gif'];
|
||||
$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;
|
||||
$dog->active = $active;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
40
web/pages/profile/edit_profile.html
Normal file
40
web/pages/profile/edit_profile.html
Normal file
@ -0,0 +1,40 @@
|
||||
<div>
|
||||
<h1>Hund <?= $dogid?'Bearbeiten':'Hinzufügen'; ?></h1>
|
||||
|
||||
<form id="dogeditform" hx-post="/dogs/edit" hx-encoding='multipart/form-data' hx-target="#response">
|
||||
<input type="hidden" name="dog_id" value="<?= $dogid; ?>">
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
|
||||
<input type="text" value="<?= $user['name']; ?>" id="name" name="name" class="form-control" placeholder="Max" required>
|
||||
</div>
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="surname" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Nachname</label>
|
||||
<input type="text" value="<?= $user['surname']; ?>" id="surname" name="surname" class="form-control" placeholder="Mustermann">
|
||||
</div>
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="user_birthday" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Geburtstag</label>
|
||||
<input type="date" value="<?= $user['birthday']; ?>" id="user_birthday" name="user_birthday" class="form-control" placeholder="" required>
|
||||
</div>
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">E-Mail</label>
|
||||
<input type="text" value="<?= $user['email']; ?>" id="email" name="email" class="form-control" placeholder="max@max.com">
|
||||
</div>
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="club" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Verein</label>
|
||||
<input type="number" value="<?= $user['club']; ?>" id="club" name="club" class="form-control" placeholder="Vereinsname">
|
||||
</div>
|
||||
<div class="mb-3 mb-md-4">
|
||||
<label for="photo" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Photo</label>
|
||||
<input type="file" accept="image/png, image/jpeg, image/gif" id="photo" name="photo">
|
||||
</div>
|
||||
<button type="submit" name="submit" value="true" class="btn btn-primary">Speichern</button>
|
||||
</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>
|
29
web/pages/profile/profile.html
Normal file
29
web/pages/profile/profile.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!-- FILEPATH: /home/chris/git/dogstats/web/pages/dogs/dog.html -->
|
||||
|
||||
<div class="container">
|
||||
<h1>Profil</h1>
|
||||
<div class="row">
|
||||
<div class="col-3">
|
||||
<img src="<?= $user['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($user['name']); ?>'s profile Picture">
|
||||
</div>
|
||||
|
||||
<div class="col-9">
|
||||
<h3 class="card-title"><?= escape($user['name']); ?> <?= escape($user['surname']); ?></h3>
|
||||
<div>
|
||||
<?php if($user['birthday']): ?><p>Alter: <?= date_diff(date_create($user['birthday']), date_create('now'))->y ?></p> <?php endif; ?>
|
||||
<?php if($user['email']): ?><p>Rasse: <?= escape($user['email']); ?></p> <?php endif; ?>
|
||||
<?php if($user['club']): ?><p>Zuchtname: <?= escape($user['club']); ?></p> <?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-end">
|
||||
<button type="button" class="btn btn-secondary" hx-get="/user/edit/<?= $userid; ?>" hx-target="#main">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-8" id="sitemain">
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user