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

87 lines
3.3 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 23:51:51 +01:00
$_SESSION['user']->load();
2023-10-30 22:36:18 +01:00
$_SESSION['user']->data['firstname'] = trim($_REQUEST['firstname']);
$_SESSION['user']->data['lastname'] = trim($_REQUEST['lastname']);
//$_SESSION['user']->data['email'] = $_REQUEST['email'];
$_SESSION['user']->data['birthday'] = $_REQUEST['birthday'];
$_SESSION['user']->data['club'] = trim($_REQUEST['club']);
//$_SESSION['user']->data['timezone'] = $_REQUEST['timezone'];
2023-10-27 12:32:04 +02:00
2023-10-30 22:36:18 +01:00
if(!strtotime($_SESSION['user']->data['birthday']))
2023-10-30 19:27:44 +01:00
$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)
2023-10-30 22:36:18 +01:00
$_SESSION['user']->data['photo'] = $newphoto;
2023-10-27 12:32:04 +02:00
2023-10-30 22:45:42 +01:00
try{
$_SESSION['user']->save();
}
catch(Exception $e)
{
return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Profils: '.$e->getMessage()]);
}
2023-10-30 19:27:44 +01:00
$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;
}
}