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/admin/controller.php
Chris f7a7c3457b
All checks were successful
Build and push / Pulling repo on server (push) Successful in 18s
man kann hunde anlegen yay
2023-10-22 23:05:24 +02:00

78 lines
2.1 KiB
PHP

<?php
class Admin extends Page {
function loginas()
{
$user = $_REQUEST['email'];
$u = new User();
if($u->load($user))
{
$u->login();
$this->redirect('/');
}
else
{
$this->set('message', 'User '.escape($user).' not found');
$this->set('template', 'notfound.html');
}
}
function edituser()
{
$user = $_REQUEST['email'];
$u = new User();
if($u->load($user))
{
$data = $u->data;
$this->set('userdata', $data);
$this->set('userid', $user);
$this->set('template', 'edituser.html');
}
else
{
$this->set('message', 'User '.escape($user).' not found');
$this->set('template', 'notfound.html');
}
}
function edituserdata()
{
$user = $_REQUEST['email'];
$u = new User();
if(!$u->load($user))
{
$this->set('message', 'User '.escape($user).' not found');
$this->set('template', '/templates/notfound.html');
return;
}
foreach($_REQUEST as $key => $value)
{
if($key == 'email') continue;
if($key=='dogs')
{
$value = json_decode(html_entity_decode($value),true);
}
$u->$key = $value;
}
try{
$u->save();
}
catch(Exception $e)
{
$this->set('errorMessage', $e->getMessage());
$this->set('template', '/templates/partials/error.html');
return;
}
$this->set('successMessage', 'Speichern erfolgreich');
$this->set('template', '/templates/partials/success.html');
}
function maySeeThisPage(){return true;}
}