
<?php
// $id = isset($_GET['id']) ? $_GET['id'] : '666bd02c332e00005800391e';
$idc = isset($_GET['id']) ? $_GET['id'] : '';

include_once 'mongodb_config.php';

$dbname = 'myWebhook';
$collection = 'user';

//DB connection
$db = new DbManager();
$conn = $db->getConnection();

// read all recordsID:5655228977
$filter = ['id' => $idc];
//$filter = ['_id' => new MongoDB\BSON\ObjectId($id)];
$option = [];
$read = new MongoDB\Driver\Query($filter, $option);

//fetch records
$records = $conn->executeQuery("$dbname.$collection", $read);

// echo json_encode(iterator_to_array($records));


$records1 = $conn->executeQuery("$dbname.$collection", $read);
// var_dump(intval($json['ID']));
$res1= json_encode(iterator_to_array($records1));

$result= json_decode($res1, true);
// var_dump($res1);

if(isset($result['0']['nama'])){ $result['0']['nama'];}
if(isset($result['0']['kelas'])){$result['0']['kelas'];}
if(isset($result['0']['alamat'])){$result['0']['alamat'];}
if(isset($obj['ket'])){echo $obj['ket'];}
		
	   
// $result1=$result['0']['absensi'];
// var_dump($result);
$nama =$result['0']['nama'];
$kelas =$result['0']['kelas'];
$alamat =$result['0']['alamat'];
$foto =$result['0']['foto'];
$qr =$result['0']['qr'];

date_default_timezone_set('Asia/Makassar'); // Zona Waktu indonesia
// echo date('h:i:s a'); // menampilkan jam sekarang
// echo "<br/>";
$waktu= date('H:i:s'); //kombinasi jam dan tanggal
$date=date('d-m-Y');
// echo $json['alamat'];
$day = date('D', strtotime($waktu));
$dayList = array(
    'Sun' => 'Minggu',
    'Mon' => 'Senin',
    'Tue' => 'Selasa',
    'Wed' => 'Rabu',
    'Thu' => 'Kamis',
    'Fri' => 'Jumat',
    'Sat' => 'Sabtu'
);
// echo "Tanggal {$tanggal} adalah hari : " . $dayList[$day];


// use these require statements if you point your http server directly to this folder.
require "phppdf/Fpdf.php";
require "phppdf/JsonPDF.php";

// use this require statement instead if you install JsonPDF via composer
// and comment out the above require statements.
//require 'vendor/autoload.php';

    $document = array(
        'header' => array(
             array(
                'type' => 'image',
                'url'  => "profil/".$idc.".jpg",
                'x' => 11,
                'y' => 6,
                'width' => 32,
                // 'render-as' => 'form|data|(both)',
                'render-as' => 'form',
            ),
            array(
                'type' => 'image',
                'url'  => 'img/cad5.png',
                'x' => 2,
                'y' => 1,
                'width' => 49,
                'radius' => 2,
                // 'render-as' => 'form|data|(both)',
                'render-as' => 'form',
            ),
            
            array(
                'type' => 'image',
                'url'  => "logo/".$idc.".png",
                'x' => 11,
                'y' => 36,
                'width' => 32,
                

                // 'render-as' => 'form|data|(both)',
                'render-as' => 'form',
            ),
//  array(
//                 'type' => 'image',
//                 'url'  => 'img/card.png',
//                 'x' => 2,
//                 'y' => 1,
//                 'width' => 49,
//                 'radius' => 2,
//                 // 'render-as' => 'form|data|(both)',
//                 'render-as' => 'form',
//             ),



            // array(
            //     'type' => 'image',
            //     'url'  => "qrcode/$qr",
            //     'x' => 23,
            //     'y' => 101,
            //     'width' => 35,
            //     // 'render-as' => 'form|data|(both)',
            //     'render-as' => 'form',
            // ),
            // array(
            //     'type' => 'rect', //garis bingkai
            //     'x' => 9,
            //     'y' => 5,
            //     'width' => 30,
            //     'height' => 30,
            //     'radius' => 10,
            //     'render-as' => 'form',
            // ),

            
            array(
                'type' => 'text',
                'text' => $nama,
                'font' => 'THSarabun',
                'font-style' => 'b',
                'font-size'  => 20,
                'x' => 1,
                'y' => 71,
                'width' => 50,
                'align' => 'C', 
                'text-color' => '224,235,255',
                'render-as' => 'form',
            ),
            array(
                'type' => 'text',
                'text' => $kelas,
                'font' => 'THSarabun',
                'font-size'  => 16,
                'x' => 1,
                'y' => 77,
                'width' => 50,
                'align' => 'C',
                'text-color' => '224,235,255',
                'render-as' => 'form',
            ),
            // array(
            //     'type' => 'line',
            //     'x1' => 10, 'y1' => 28,
            //     'draw-color' => '100',  // gray scale
            //     'render-as' => 'form',
            // ),
            // array(
            //     'type' => 'text',
            //     'text' => "$nama",
            //     // 'font' => 'THSarabun',
            //          'font' => 'Arial',
            //            'text-color' => '224,235,255',
            //             // 'fill-color' => '224,235,255',
                  
            //     'align' => 'C',
            //     'font-size'  => 12,
            //     'x' => 10,
            //     'y' => 88,
            //     'width' => 70,
            //     'render-as' => 'form',
            // ),
            // array(
            //     'type' => 'text',
            //     'text' => "$kelas",
            //     // 'font' => 'THSarabun',
            //          'font' => 'Arial',
            //            'text-color' => '224,235,255',
            //             // 'fill-color' => '224,235,255',
                  
            //     'align' => 'C',
            //     'font-size'  => 12,
            //     'x' => 10,
            //     'y' => 95,
            //     'width' => 70,
            //     'render-as' => 'form',
            // ),
            // array(
            //     'type' => 'text',
            //     'text' => "Alamat  : $alamat",
            //     'font' => 'THSarabun',
            //     'font-size'  => 16,
            //     'x' => 10,
            //     'y' => 43,
            //     'width' => 80,
            //     'render-as' => 'form',
            // ),
            array(
                'type' => 'table-header',
                'render-as' => 'form',
                'y' => 50,
                'x' => 10,
                'table' => 'world_info_table',
                'font' => 'THSarabun',
                'font-size' => 20,
                'style' => array(
                    'title-row' => array(
                        'height' => 8,
                        // 'draw-text' => false,
                    )
                )
            ),
        ),
        'footer' => array(
            // array(
            //     'type' => 'text',
            //     'y' => -15,
            //     'width' => 0,
            //     'height' => 10,
            //     'font' => 'Arial',
            //     'font-style' => 'I',
            //     'font-size'  => 8,
            //     'draw-color' => '0,0,0',
            //     'text' => 'Page {page}/{nb}',
            //     'border' => 'T',
            //     'align' => 'C',
            //     'render-as' => 'form',
            // ),
            // array(
            //     'type' => 'text',
            //     'y' => 18,
            //     'x' => 210,
            //     'width' => 0,
            //     'height' => 10,
            //     'font' => 'Arial',
            //     'font-size'  => 8,
            //     'font-style' => '',
            //     'draw-color' => '0,0,0',
            //     'text' => 'Page {page}/{nb}',
            //     'align' => 'R',
            //     'render-as' => 'form',
            // ),
        ),

        'body' => array(
            array(
                'type' => 'table-body',
                'table' => 'world_info_table',
                'font' => 'THSarabun',
                'font-size' => 20,
                // override default setting
                'style' => array(
                    // 'border' => 'LR',
                    'data-row' => array(
                        // 'height' => 10,
                        // 'text-color' => '0,0,0',
                        // 'fill-color' => '224,235,255',
                        // 'striped' => false,
                        // 'draw-text' => false,
                    )
                ),
            ),
        ),

        'tables' => array(
            'world_info_table' => array(
                'columns' => array(
                ),
                'data' => 'world_info',
                'style' => array(
                    'border-color' => '50,55,200',
                    // 'border' => 'LR',
                    'title-row' => array(
                        'height' => 8,
                        'text-color' => '200, 100, 50',
                        'fill-color' => '100,50,50',
                        // 'font' => 'Arial',
                    ),
                    'data-row' => array(
                        'height' => 8,
                        'text-color' => '0,0,0',
                        'fill-color' => '224,235,255',
                        'striped' => true,
                    ),
                ),
            ),
        ),

        'settings' => array(
            'title'       => 'Test PDF',
            'author'      => 'Rati Wannapanop',
            'subject'     => 'Test Creating PDF',
            'keywords'    => 'test pdf fpdf ratiw',
            'default-font' => array(
                'name' => 'THSarabun',
                'size' => 30,
            ),
            'header-height' => 100,
        ),

        'fonts' => array(
            array('THSarabun', '', 'THSarabun.php'),
            array('THSarabun', 'B', 'THSarabun Bold.php'),
            array('THSarabun', 'I', 'THSarabun Italic.php'),
            array('THSarabun', 'BI', 'THSarabun Bold Italic.php'),
        ),
    );

    $data = array(
        'name' => 'smkn2plp',
        'date' => '12/15/2022',
      //  'report_name' => "Daftar kehadiran siswa ID : $id ",
        // 'world_info' => $result1
        
    );

    $pdf = new ratiw\JsonPDF\JsonPDF('P', 'mm', 'ktp1');
    $pdf->make(json_encode($document), json_encode($data), 'both');
    $pdf->render("cetak/".$idc.".pdf", 'F');   // save ro server
    // $pdf->render($idc.".pdf", 'D');             //dowload
// $pdf->render();
?>
