<?php 
if(!isset($_COOKIE['ADMIN_KEY']) && !isset($_COOKIE['KEY'])){
  header('location:./login/');
  exit;
} else{
require_once'../../../sw-library/sw-config.php';
require_once'../../../sw-library/sw-function.php';
require_once'../../login/user.php';
require_once'../../../sw-library/fpdf/fpdf.php';


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


if(file_exists('../../../sw-content/tema/'.$data_tema['foto'].'')){
    $background = '../../../sw-content/tema/'.$data_tema['foto'].'';
}else{
    $background = '';
}

if(isset($_GET['jabatan']) && !empty($_GET['jabatan'])){
    $jabatan = strip_tags($_GET['jabatan']??'-');
    $filter = "WHERE jabatan='$jabatan'";
}else{
    $filter = "";
}   


$query_user ="SELECT * FROM pegawai $filter ORDER BY nama_lengkap ASC";
$result_user = $connection->query($query_user);
if($result_user->num_rows > 0){

echo'
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="noindex">
    <meta name="googlebot" content="noindex">
    <meta name="description" content="s-widodo.com">
    <meta name="author" content="s-widodo.com">
    <title>ID Card</title>
    <link rel="stylesheet" href="../../sw-assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
    <style>
        body{font-family:Arial,Helvetica,sans-serif}

      
        
.thema-id-card {
  position: relative;
  display: inline-block;
  background: #ffffff;
  background-size: 100% !important;
  width :204px;
  height:321px;
  margin:10px;
  padding:20px;
  border-radius:15px;
  float:left;
  border:solid 1px #cccccc;
}

.thema-id-card .header-card{
  text-align: left;
  color: #ffffff;
  text-transform: uppercase;
  font-size:10px;
}

.thema-id-card .logo-finger{
  float: right;
  top: -5px;
  background: #1c52bc;
  padding: 5px;
  border-radius: 5px;
  width: 40px;
  color: #ffffff;
  text-align: center;
  font-size: 16px;
}

.thema-id-card .avatar-idcard {
  display: table;
  margin-top:15px;
  position: relative;
}

.thema-id-card .avatar-idcard img {
  float: left;
  width:60px;
  height:60px;
  object-fit: cover;
  border-radius: 50%;
  border: solid 2px #ffffff;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.05);
  -webkit-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.05);
}

.thema-id-card .description {
  margin-top:20px;
  text-align: left;
}

.thema-id-card .description h3{
  font-size: 13px;
  text-transform: uppercase;
  color: #008FFF;
  line-height:0;
}


.thema-id-card .description p {
  font-size: 11px;
  line-height: 17px;
}

.thema-id-card .description .label i{
  color: #008FFF;
  margin-right: 10px;
}

.thema-id-card .description .label p {
  font-size: 11px;
  line-height:20px;
  padding: 0px;
  margin: auto;
  color: #111111;
}

.thema-id-card .description ul {
  list-style: none;
  padding: 0;
  display: inline-block;
  flex-direction: column;
  margin-top: 25px;
  text-align: left;
}

.thema-id-card .description ul li {
  display: inline-block;
  align-items: center;
  font-size: 13px;
}

.thema-id-card .description ul li span {
  width: 50px;
  margin-right: 10px;
  line-height: 22px;
}


.thema-id-card .qrcode {
  display:block;
  text-align:center;
}

.thema-id-card .qrcode img {
  height:60px;
  width: 60px;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.05);
  -webkit-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.05);
  margin-top: 10px;
  border: solid 2px #fff;
}

.thema-id-card .footer-card{
    text-align: center;
    position: absolute;
    bottom:18px;
    left: 0;
    right: 0;
    font-size:12px;
    text-transform: uppercase;
}

    </style>
    <script>
        window.onafterprint = window.close;
        window.print();
      </script>
</head>
<body>';
    while ($data_user = $result_user->fetch_assoc()) {
        // Tentukan avatar path
        if (file_exists('../../../sw-content/avatar/'.strip_tags($data_user['avatar']??'-').'')) {
            $avatarPath = '../../../sw-content/avatar/'.strip_tags($data_user['avatar']??'-').'';
        } else {
            $avatarPath = '../../../sw-content/avatar/avatar.jpg';
        }

        echo'
        <div class="card s-widodo.com thema-id-card" style="background: url('.$background.')">
                <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/'.($data_user['avatar']??'.jpg'))){
                        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>'.ucfirst($data_user['jabatan']??'-').'</p>

                    <div class="label mt-3">
                        <p class="s-widodo.com"><i class="far fa-star"></i>ID : '.strip_tags($data_user['nip']??'-').'</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"></i>'.strip_tags($data_user['telp']??'-').'</p>
                    </div>
                </div>

                <div class="qrcode s-widodo.com">';
                    if(file_exists('../../../sw-content/qrcode/pegawai_'.($data_user['qrcode']??'avatar').'.png')){
                        echo'<img src="data:image/png;base64,'.base64_encode(file_get_contents('../../../sw-content/qrcode/pegawai_'.($data_user['qrcode']??'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>';

    }
    
echo'
</body>
</html>';


}else{
    echo'Data yang Anda cari tidak ditemukan';
}
}?>
