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 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:38:08 +01:00
var_dump ( $_SESSION [ 'user' ] -> data );
2023-10-30 22:36:18 +01:00
$_SESSION [ 'user' ] -> save ();
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 ;
}
}