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

This commit is contained in:
Chris 2023-10-26 13:46:55 +02:00
parent 61d7ae9adf
commit 12c11b65ba
5 changed files with 132 additions and 4 deletions

View File

@ -209,4 +209,32 @@ function uuid4($data = null) {
// Output the 36 character UUID.
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
/*
* @param $path string Path to the file that should be uploaded
* @param $hash string Optional. File name we want on pictshare for the file
*/
function pictshareUploadImage($path,$hash=false)
{
if(!file_exists($path)) return false;
$request = curl_init('https://i.haschek.at/api/upload.php');
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'file' => curl_file_create($path),
'hash'=>$hash
));
// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($request).PHP_EOL,true);
// close the session
curl_close($request);
return $json;
}

View File

@ -12,6 +12,7 @@ class Dog extends Model
'size' => ['type' => 'text'], //in cm
'birthday' => ['type' => 'text'],
'agility_size' => ['type' => 'text'], //S,M,I,L
'photo' => ['type' => 'text'],
'active' => ['type' => 'int', 'default' => 1]
);

View File

@ -77,6 +77,53 @@ class Dogs extends Page {
$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
{
$this->set('errorMessage', 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen');
$this->set('template', '/templates/partials/error.html');
return;
}
}
else
{
$this->set('errorMessage', 'Beim Upload der Datei ist ein Fehler aufgetreten');
$this->set('template', '/templates/partials/error.html');
return;
}
}
else
{
$this->set('errorMessage', 'Dieser Dateityp ist nicht erlaubt. Bitte nur jpg, jpeg oder png Dateien hochladen');
$this->set('template', '/templates/partials/error.html');
return;
}
}
$error = false;
if(!$name || !$dog_birthday )
@ -101,6 +148,8 @@ class Dogs extends Page {
$dog->size = $dog_size;
$dog->birthday = $dog_birthday;
$dog->agility_size = $agi_height_category;
if($newphoto)
$dog->photo = $newphoto;
try
{
@ -160,7 +209,11 @@ class Dogs extends Page {
if(!$d->isMyDog($dogid))
return 'Not your dog :(';
return 'hier wird der hund angezeigt';
$d->load($dogid);
$this->set('dogdata', $d->data);
$this->set('dogid', $dogid);
$this->set('template', 'dog.html');
}
function maySeeThisPage() {

35
web/pages/dogs/dog.html Normal file
View File

@ -0,0 +1,35 @@
<!-- FILEPATH: /home/chris/git/dogstats/web/pages/dogs/dog.html -->
<div class="container">
<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>

View File

@ -1,7 +1,7 @@
<div>
<h1>Hund hinzufügen/bearbeiten</h1>
<h1>Hund <?= $dogid?'Bearbeiten':'Hinzufügen'; ?></h1>
<form hx-post="/dogs/edit" hx-target="#response">
<form id="dogeditform" hx-post="/dogs/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="dog_id" value="<?= $dogid; ?>">
<div>
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
@ -32,7 +32,18 @@
<option value="L" <?= $dogdata['agility_size']=='L'?'selected':''; ?>>L</option>
</select>
</div>
<div>
<label for="photo" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Photo</label>
<input type="file" id="photo" name="photo" class="" placeholder="Max" required>
</div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Submit</button>
</form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div>
</div>
</div>
<script>
htmx.on('#dogeditform', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>