<?php
if ($mod == '') {
    header('location:../404');
    echo 'kosong';
} else {
    include_once 'sw-mod/sw-header.php';
    if (!isset($_COOKIE['COOKIES_MEMBER'])) {
        setcookie('COOKIES_MEMBER', '', 0, '/');
        setcookie('COOKIES_COOKIES', '', 0, '/');
        // Login tidak ditemukan
        setcookie("COOKIES_MEMBER", "", time() - $expired_cookie);
        setcookie("COOKIES_COOKIES", "", time() - $expired_cookie);
        session_destroy();
        header("location:./");
    } else {
        echo '<!-- App Capsule -->
    <div id="appCapsule">
        <div class="section mt-3 text-center">
            <div class="avatar-section">
                <input type="file" class="upload" name="file" id="avatar" accept=".jpg, .jpeg, ,gif, .png" capture="camera">
                <a href="#">';
        if ($row_user['photo'] == '') {
            echo '<img src="' . $base_url . 'sw-content/avatar.jpg" alt="image" class="imaged w100 rounded">';
        } else {
            echo '
                    <img src="timthumb?src=' . $base_url . 'sw-content/karyawan/' . $row_user['photo'] . '&h=100&w=105" alt="avatar" class="imaged w100 rounded">';
        }
        echo '
                    <span class="button">
                        <ion-icon name="camera-outline"></ion-icon>
                    </span>
                </a>
            </div>
        </div>

        <div class="section mt-2 mb-2">
            <div class="section-title">Profil</div>
            <div class="card">
                <div class="card-body">
                    <form id="update-profile">
                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="text4">NIK</label>
                                <input type="text" class="form-control" name="employees_code" value="' . $row_user['employees_code'] . '" required>
                                <i class="clear-input">
                                    <ion-icon name="close-circle"></ion-icon>
                                </i>
                            </div>
                        </div>

                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="email4">Nama</label>
                                <input type="text" class="form-control" id="name" name="employees_name" value="' . $row_user['employees_name'] . '" required>
                                <i class="clear-input">
                                    <ion-icon name="close-circle"></ion-icon>
                                </i>
                            </div>
                        </div>

                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="select4">Jabatan</label>
                                <select class="form-control custom-select" name="position_id">';
        $query = "SELECT * from position order by position_name ASC";
        $result = $connection->query($query);
        while ($rowa = $result->fetch_assoc()) {
            if ($rowa['position_id'] == $row_user['position_id']) {
                echo '<option value="' . $rowa['position_id'] . '" selected>' . $rowa['position_name'] . '</option>';
            } else {
                echo '<option value="' . $rowa['position_id'] . '">' . $rowa['position_name'] . '</option>';
            }
        }
        echo '
                                </select>
                            </div>
                        </div>

                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="select4">Jam Kerja</label>
                                <select class="form-control custom-select" name="shift_id">';
        $query = "SELECT shift_id,shift_name from shift order by shift_name ASC";
        $result = $connection->query($query);
        while ($rowa = $result->fetch_assoc()) {
            if ($rowa['shift_id'] == $row_user['shift_id']) {
                echo '<option value="' . $rowa['shift_id'] . '" selected>' . $rowa['shift_name'] . '</option>';
            } else {
                echo '<option value="' . $rowa['shift_id'] . '">' . $rowa['shift_name'] . '</option>';
            }
        }
        echo '
                                </select>
                            </div>
                        </div>


                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <!-- <label class="label" for="password4">Lokasi Penempatan</label> 
                                <select class="form-control custom-select" name="building_id">';
        $query  = "SELECT building_id,name,address from building";
        $result = $connection->query($query);
        while ($row = $result->fetch_assoc()) {
            if ($row['building_id'] == $row_user['building_id']) {
                echo '<option value="' . $row['building_id'] . '" selected>' . $row['name'] . '</option>';
            } else {
                echo '<option value="' . $row['building_id'] . '">' . $row['name'] . '</option>';
            }
        }
        echo '
                                </select>
                            </div> -->
                        </div>

                        <hr>
                            <button type="submit" class="btn btn-success mr-1 btn-lg btn-block btn-profile">Simpan</button>
                        
                    </form>

                </div>
            </div>
        </div>

      
        <div class="section mt-2 mb-2">
            <div class="section-title">Update Password</div>
            <div class="card">
                <div class="card-body">
                    <form id="update-password">
                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="text4">Kode Pegawai</label>
                                <input type="email" class="form-control" name="employees_email" value="' . $row_user['employees_email'] . '" style="background:#eeeeee" readonly>
                                <i class="clear-input">
                                    <ion-icon name="close-circle"></ion-icon>
                                </i>
                            </div>
                        </div>

                        <div class="form-group boxed">
                            <div class="input-wrapper">
                                <label class="label" for="email4">Password baru</label>
                                <input type="password" class="form-control" name="employees_password" id="employees_password" required>
                                <i class="clear-input">
                                    <ion-icon name="close-circle"></ion-icon>
                                </i>
                            </div>
                        </div>
                        <hr>
                        <button type="submit" class="btn btn-success mr-1 btn-lg btn-block">Simpan</button>
                    </form>

                </div>
            </div>
        </div>
        
    </div>
    <!-- * App Capsule -->
';
    }
    include_once 'sw-mod/sw-footer.php';
}
