<?php if(empty($connection) AND !isset($_COOKIE['siswa'])){
    header('location:../404');
}else{
$qrcode = ($data_user['nisn']??'');
$filepath = "../sw-content/qrcode/$qrcode.png";
if ($qrcode && !file_exists($filepath)) {
    require_once'../sw-library/phpqrcode/qrlib.php'; 
    QRCode::png($qrcode, $filepath, 'QR_ECLEVEL_Q', 10, 1);
}

$query_tema ="SELECT foto FROM kartu_nama WHERE active='Y' LIMIT 1";
$result_tema = $connection->query($query_tema);
$data_tema = $result_tema->fetch_assoc();

echo'
<main class="flex-shrink-0 main has-footer s-widodo.com">
    <div class="main-container s-widodo.com">
        <div class="container s-widodo.com mt-3">
            <h6 class="subtitle text-center mb-4">Kartu nama</h6>
            <div class="row justify-content-md-center s-widodo.com">
                <div class="col-sm-12 col-md-4 text-center s-widodo.com mb-1">
                    <div class="card s-widodo.com thema-id-card mb-3" id="idCard" style="background: url(../sw-content/tema/'.$data_tema['foto'].')">
                        <div class="header-card">
                            '.ucwords($row_site['nama_sekolah']??'-').'
                             <span class="logo-finger"><i class="fas fa-fingerprint"></i></span>
                        </div>

                        <div class="avatar-idcard s-widodo.com">';
                            if(file_exists('../sw-content/avatar/'.$avatarFile)){
                                echo'<img src="data:image/gif;base64,'.base64_encode(file_get_contents('../sw-content/avatar/'.$data_user['avatar'].'')).'" class="s-widodo.com">';
                            }else{
                                echo'<img src="../sw-content/avatar/avatar.jpg" class="s-widodo.com">';
                            }
                        echo'
                        </div>

                        <div class="description s-widodo.com">
                            <h3>'.strip_tags($data_user['nama_lengkap']??'-').'</h3>
                            <p>'.($data_user['nisn']??'-').'</p>

                            <div class="label mt-3">
                                <p class="s-widodo.com"><i class="far fa-star"></i>Kelas : '.strip_tags($data_user['kelas']??'-').'</p>
                                <p class="s-widodo.com"><i class="fas fa-calendar-alt"></i>Tanggal Lahir : '.tanggal_ind($data_user['tanggal_lahir']??'-').'</p>
                                <p class="s-widodo.com"><i class="fas fa-phone-alt"></i>'.strip_tags($data_user['telp']??'-').'</p>
                            </div>
                        </div>

                        <div class="qrcode s-widodo.com">';
                         if(file_exists('../sw-content/qrcode/'.($data_user['nisn']??'avatar').'.png')){
                                echo'<img src="data:image/png;base64,'.base64_encode(file_get_contents('../sw-content/qrcode/'.($data_user['nisn']??'avatar.jpg').'.png')).'"  class="s-widodo.com">';
                            }else{
                                echo'<img src="./sw-content/avatar/avatar.jpg" class="s-widodo.com">';
                            }
                        echo'
                        </div>

                        <div class="footer-card">
                            '.ucwords($row_site['nama_sekolah']??'-').'
                        </div>
                    </div>

                    <button class="btn btn-default rounded" onclick="downloadID()"><i class="fas fa-download"></i> Download JPG</button>
                </div>
            </div>
        </div>
    </div>
</main>';
}?>