This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
dogstats/web/pages/profile/controller.php

80 lines
3.0 KiB
PHP
Raw Normal View History

2023-10-27 12:32:04 +02:00
<?php
class Profile extends Page {
2023-10-30 19:27:44 +01:00
function index()
2023-10-27 12:32:04 +02:00
{
2023-10-30 19:27:44 +01:00
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'profile.html');
2023-10-27 12:32:04 +02:00
}
2023-10-30 19:27:44 +01:00
function edit()
{
if($_REQUEST['submit']=='true')
{
$error = false;
2023-10-27 12:32:04 +02:00
2023-10-30 19:27:44 +01:00
$user = $_SESSION['user'];
$user->data['firstname'] = trim($_REQUEST['firstname']);
$user->data['lastname'] = trim($_REQUEST['lastname']);
//$user->data['email'] = $_REQUEST['email'];
$user->data['birthday'] = $_REQUEST['birthday'];
$user->data['club'] = trim($_REQUEST['club']);
//$user->data['timezone'] = $_REQUEST['timezone'];
2023-10-27 12:32:04 +02:00
2023-10-30 19:27:44 +01:00
if(!strtotime($user->data['birthday']))
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
2023-10-27 12:32:04 +02:00
$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','gif'];
$photo_ext = strtolower(end(explode('.', $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'];
2023-10-30 19:27:44 +01:00
else
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Fehler beim CDN Upload: '.json_encode($answer,true)]);
2023-10-27 12:32:04 +02:00
}
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']);
}
2023-10-30 19:27:44 +01:00
if($newphoto)
$user->data['photo'] = $newphoto;
2023-10-27 12:32:04 +02:00
2023-10-30 19:27:44 +01:00
$user->save();
$this->redirect('/profile');
2023-10-27 12:32:04 +02:00
}
2023-10-30 19:27:44 +01:00
$this->set('user', $_SESSION['user']->data);
$this->set('template', 'edit_profile.html');
2023-10-27 12:32:04 +02:00
}
function maySeeThisPage() {
if($_SESSION['user']) //wenn eingeloggt, kein problem
return true;
else return false;
}
}