implemented profile
This commit is contained in:
@ -2,47 +2,30 @@
|
||||
|
||||
class Profile extends Page {
|
||||
|
||||
function setSubmenu()
|
||||
function index()
|
||||
{
|
||||
|
||||
if($_SESSION['user'] > 0)
|
||||
$this->set('user', $_SESSION['user']->data);
|
||||
$this->set('template', 'profile.html');
|
||||
}
|
||||
|
||||
function edit()
|
||||
{
|
||||
if($_REQUEST['submit']=='true')
|
||||
{
|
||||
$this->addSubmenuItem('Mein Profil','/profile','fa-regular fa-id-badge');
|
||||
}
|
||||
}
|
||||
|
||||
function index() {
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
}
|
||||
$error = false;
|
||||
|
||||
function delete(){
|
||||
$dogid = $this->params[0];
|
||||
$d = new Dog();
|
||||
$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'];
|
||||
|
||||
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'];
|
||||
if(!strtotime($user->data['birthday']))
|
||||
$error = 'Das Geburstdatum ist ungültig. Bitte die Eingabe prüfen';
|
||||
|
||||
$newphoto = false;
|
||||
$active = intval($_REQUEST['agi_active']);
|
||||
|
||||
if($_FILES['photo'])
|
||||
{
|
||||
$photo = $_FILES['photo'];
|
||||
@ -54,8 +37,6 @@ class Profile extends Page {
|
||||
|
||||
$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))
|
||||
{
|
||||
@ -66,6 +47,8 @@ class Profile extends Page {
|
||||
$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' => 'Fehler beim CDN Upload: '.json_encode($answer,true)]);
|
||||
}
|
||||
else
|
||||
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Die Datei ist zu groß. Bitte eine kleinere Datei hochladen']);
|
||||
@ -77,96 +60,15 @@ class Profile extends Page {
|
||||
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);
|
||||
if($newphoto)
|
||||
$user->data['photo'] = $newphoto;
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
$user->save();
|
||||
$this->redirect('/profile');
|
||||
}
|
||||
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');
|
||||
$this->set('user', $_SESSION['user']->data);
|
||||
$this->set('template', 'edit_profile.html');
|
||||
}
|
||||
|
||||
function maySeeThisPage() {
|
||||
|
Reference in New Issue
Block a user