<?php
//print_r($_POST);
$filter = ['id' => $_GET['econid']];
$user = $auth->getApiDataFilter("get/user", $filter);
$user = $user[0];
//print_r($user);
if (isset($_POST) && $_POST != []) {
    $data = $_POST;
    //print_r($data);
    if ($data['password'] === $data['passwordControl']) {
        unset($data['passwordControl'], $data['passwordCurrent']);
        $data['id'] = $filter['id'];
        if($data['password']==""){
            unset($data['password']);
        }
        //print_r(json_encode($data));
        $req = $auth->sendApiData("update/user/data", $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="<?php echo $user->lastName ?>" />
                    </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="<?php echo $user->firstName ?>" />
                    </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="<?php echo $user->email ?>" />
                    </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 accesslevel">
                            <?php
                                $userLevels = getAccessLevels();
                                for($i=0;$i<count($userLevels);$i++){
                                    $selected = ($user->accesslevel==$i)?"selected":'';
                                    echo "<option value={$i} $selected>{$userLevels[$i]}</option>";
                                }
                            ?>
                        </select>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h5>Adózás</h5>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <select name="userTax" class="select2 userTax">
                            <?php
                                $userTaxes = getTax();
                                for($i=0;$i<count($userTaxes);$i++){
                                    $selected = (isset($user->userTax)&&$user->userTax==$i)?"selected":'';
                                    echo "<option value={$i} $selected>{$userTaxes[$i]}</option>";
                                }
                            ?>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

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