<?php

//Hak Cipta dilindungi Undang-undang. Hak Cipta : Khamdi Rahmani, Reg. Kemenkum HAM No : 000121327. Dilarang merubah isi File tanpa ijin tertulis dari pemegang Hak Cipta. 

class modal
{
    public function linkModal($file, $link, $bi, $value, $color)
    {
        echo  "<a href='#{$link}' data-toggle='modal' class='btn btn-{$color} btn-xs mb-2 btn-rounded small px-2'> <i class='bi bi-{$bi}'></i> {$value}</a>";
        require_once($file . ".php");
        return true;
        exit();
    }
    public function linkModaltiny($file, $link, $id, $conten)
    {
        echo  "<a href='#{$link}' data-toggle='modal'  data-id='$id'>$conten</a>";
        $this->fetchUpdate($file, $link, 'xl', '', '', '', 'DETAIL');

        // return true;
    }
    public function modalUpdate($file, $link, $id, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }

    public function modalDatabase($file,  $link, $id, $tahun, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id$tahun' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }


    public function linkModalBadge($file, $link, $bi, $value, $class)
    {
        echo "<a href='#{$link}' data-toggle='modal' class='{$class}'> <i class='bi bi-{$bi}'></i> {$value}</a>";
        require_once($file . ".php");
        return true;
        exit();
    }

    public function linkUpdate($link)
    {
        $link = "href='#{$link}'";
        return $link;
    }
    public function modalSetorRKAS($file,  $link, $id, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }
    public function modalRKAS($file,  $link, $id, $tahun, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id$tahun' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }

    //TABUNGAN
    public function modalTabunganTr($file, $link, $id, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }

    public function modalDeleteTabunganTr($file, $link, $id, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i></a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }

    //SISWA

    public function modalkonfirmTransfer($file, $link, $id, $tahun, $sizeModal, $modalcolor, $valueSubmitModal, $judulModal, $bi, $valueButton, $colorButton, $tittleButton)
    {
        $button =  "<a href='#{$link}' data-toggle='modal' data-id='$id' tittle='$tittleButton' class='btn-{$colorButton} btn-xs'> <i class='bi bi-{$bi}'></i> {$valueButton}</a>";
        $this->fetchUpdate($file, $link, $sizeModal, $modalcolor, $valueSubmitModal, $bi, $judulModal);
        return $button;
    }
    private function fetchUpdate($file, $link, $sizeModal, $bgcolor, $valueSubmitModal, $bi, $judul)
    {
        echo "<script type='text/javascript'>
        $(document).ready(function() {
            $('#{$link}').on('show.bs.modal', function(e) {
                var rowid = $(e.relatedTarget).data('id');
                $.ajax({
                    type: 'post',
                    url: '{$file}.php',
                    data: 'rowid=' + rowid,
                    success: function(data) {
                        $('.fetched-data-edit').html(data);
                    }
                });
            });
            });
        </script>
        ";
        echo   "
        <div class='modal fade middle mt-5' id='{$link}' role='dialog' aria-labelledby='myModalLabel' aria-hidden='false'>
            <div class='modal-dialog modal-{$sizeModal}'>
                <div class='modal-content bg-{$bgcolor}'>
                  
                        <div class='modal-header'>
                        <h5 class='modal-title' style='font-family:Courier New, Courier, monospace'><span class='bi bi-{$bi}'></span> {$judul}</h5>
                            <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
                                <span aria-hidden='true'>&times;</span>
                            </button>
                        </div>
                        <div class='modal-body' align='left'>
                            <div class='fetched-data-edit'></div>
                        </div>
                        <div class='modal-footer justify-content-between'>
                            <div class='float-right'>
                               
                            </div>
                            <div class='float-left'>
                                <button type='button' class='badge badge-pill badge-secondary' data-dismiss='modal'><span class='badge badge-pill badge-secondary'>CLOSE</span></button>
                            </div>

                        </div>
                  
                </div>
            </div>
        </div>";

        // return true;
        //exit();
    }
}
