<?php
//print_r($_POST);
//$user = $user[0];
//print_r($user);
if (isset($_POST) && $_POST != []) {
    $data = $_POST;
    //print_r($data);
    $filter = ['email' => $data['email']];
    $response = $auth->getApiDataFilter('get/partner/exists', $filter);
    if (isset($response->status)) {
        if ($data['password'] === $data['passwordControl']) {
            unset($data['passwordControl'], $data['passwordCurrent']);
            $response = $auth->getApiData("get/user/lastid");
            $response = $response[0];
            $data['id'] = $response->id + 1;
            if ($data['password'] == "") {
                unset($data['password']);
            }
            $req = $auth->sendApiData("set/user/new", $data);
            if (isset($req->status) && $req->status == "ok") {
                echo sendCallout('success', 'Sikeres jelszó változtatás', '');
            } else {
                echo sendCallout('warning', 'Sikertelen jelszó változtatás', '');
            }
        } else {
            echo sendCallout('warning', 'Hibás megerősítő jelszó', 'Sajnos a megadott új jelszó nem egyezik a megerősítő jelszóval! </br> Kérjük próbálja meg újra!');
        }
    }
}
//$partners = $auth->getApiDataFilter("get/machine/full", $filter);
?>
<div class="row card">
    <div class="col-12 text-center">
        <button type="button" class="btn btn-block bg-gradient-success btn-lg savedata">Mentés</button>
    </div>
</div>
<form id="sendForm" class="row" method="POST">
    <div class="col-lg-6 col-sm-12">
        <div class="card">
            <div class="card-header">
                <h4>Profil információk</h4>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Vezetéknév</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <input class="form-control" name="lastName" value="" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Keresztnév</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <input name="firstName" class="form-control" value="" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>E-mail</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <input type="email" name="email" class="form-control" value="" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Új jelszó</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <input value="" type="password" name="password" class="form-control" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Új jelszó megerősítése</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <input value="" type="password" name="passwordControl" class="form-control" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Szint</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <select name="accesslevel" class="select2">
                            <?php
                            $userLevels = getAccessLevels();
                            for ($i = 0; $i < count($userLevels); $i++) {
                                echo "<option value={$i} $selected>{$userLevels[$i]}</option>";
                            }
                            ?>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<?php
addJS("edituser.js");
?>