<?php

$currentUser = new User();
$update = new User();
$sexo = "";
$photoPath = 'images\\' . $_SESSION['user']->name . '\\';
$currentUser = User::DameUsuarioActual($_SESSION['user']->id);
if (isset($_POST['guardar'])) {
    $update = $currentUser;
    $update->name = $_POST['name'];
    $update->email = $_POST['email'];
    $update->intro = $_POST['intro'];
    if (!empty($_FILES['photo']['name'])) {
        $update->photo = isset($_FILES['photo']['name']) ? $_FILES['photo']['name'] : 'default.jpg';
        $filePath = $photoPath . $update->photo;
        if (is_dir($photoPath)) {
            if (!file_exists($filePath)) {
                move_uploaded_file($_FILES['photo']['tmp_name'], $filePath);
                chmod($filePath, 0644);
            }
        } else {
            mkdir($photoPath, 0777);
            move_uploaded_file($_FILES['photo']['tmp_name'], $filePath);
            chmod($filePath, 0644);
        }
    }
    $update->gender = isset($_POST['gender']) ? $_POST['gender'] : "I DONT KNOW!";
    // $currentUser->datebirth = $_POST['datebirth'];
    $update = $currentUser->modificarUsuario($update);
    $currentUser = $update;
    $_SESSION['user'] = $currentUser;