<?php
session_start();
require_once '../../../config.php';
load('middleware', 'user');
function slug($text, string $divider = '-') {
    
    $text = preg_replace('/[0-9]+/', '', $text);
    $text = preg_replace('~[^\pL\d]+~u', $divider, $text);
    $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
    $text = preg_replace('~[^-\w]+~', '', $text);
    $text = trim($text, $divider);
    $text = preg_replace('~-+~', $divider, $text);
    $text = strtolower($text);
    
    if (empty($text)) {
        return 'n-a';
    }
    return $text;
}

if ($_SESSION['user']['level'] !== "Admin") {
    header('location:' . base_url('id'));
}

if (isset($_GET['action'])) {
    
    if ($_GET['action'] === 'hapus') {
        if (isset($_GET['id'])) {
            $id = addslashes(trim(htmlspecialchars($_GET['id'])));
            
            $query_games = mysqli_query($db, "SELECT * FROM games_guest WHERE id = '$id'");
            $fetch_games = mysqli_fetch_assoc($query_games);
            
            unlink('../../../assets/games/' . $fetch_games['img']);
            unlink('../../../id/games/' . $fetch_games['slug'] . '.php');
            
            mysqli_query($db, "DELETE FROM games_guest WHERE id = '$id'");
            
            $_SESSION['alert'] = ['success', 'Success!', 'Data games di hapus.'];
            exit(header('location: /admin/guest/product/'));
        }
    }
}

if (isset($_GET['hapusa'])) {
    $id = addslashes(trim(htmlspecialchars($_GET['hapusa'])));
    
    mysqli_query($db, "DELETE FROM games_kategori WHERE id = '$id'");
    
    $_SESSION['alert'] = ['success', 'Success!', 'Data kategori di hapus.'];
    exit(header('location: /admin/guest/product/'));
}
if (isset($_GET['hapusaa'])) {
    $id = addslashes(trim(htmlspecialchars($_GET['hapusaa'])));
    
    mysqli_query($db, "DELETE FROM games_kategori WHERE id = '$id'");
    
    $_SESSION['alert'] = ['success', 'Success!', 'Data kategori di hapus.'];
    exit(header('location: /admin/guest/product/'));
}

if (isset($_POST['tombol'])) {
    
    if (isset($_POST['name']) AND isset($_POST['operator']) AND isset($_POST['sistem_id']) AND isset($_POST['validate_status']) AND isset($_POST['keterangan'])) {
        $name = $_POST['name'];
        $sub_name = $_POST['sub_name'];
        $category = $_POST['category'];
        $tipee = $_POST['tipe'];
        $product = $_POST['operator'];
        $sistem_id = $_POST['sistem_id'];
        $validate_status = $_POST['validate_status'];
        $validate_code = $_POST['validate_code'];
        $urutan = $_POST['urutan'];
        $keterangan = $_POST['keterangan'];
        
        if (empty($name) OR empty($product) OR empty($sistem_id) OR empty($validate_status) OR empty($keterangan)) {
            $_SESSION['alert'] = ['danger', 'Failed!', 'Masih ada data yang kosong.'];
            exit(header('location: /admin/guest/product/'));
        } else {
            if (isset($_FILES['gambar'])) {
                if ($_FILES['gambar']['error'] == 4) {
                    $_SESSION['alert'] = ['danger', 'Failed!', 'Gambar product tidak boleh kosong.'];
                    exit(header('location: /admin/guest/product/'));
    
                } else {
                    $format_file = end(explode('.', strtolower($_FILES['gambar']['name'])));
                    
                    if (in_array($format_file, ['jpg', 'jpeg', 'png'])) {
                        $nama_file = uniqid() . '.' . $format_file;
                        
                        move_uploaded_file($_FILES['gambar']['tmp_name'], '../../../assets/games/' . $nama_file);
                    } else {
                        $_SESSION['alert'] = ['danger', 'Failed!', 'Format gambar tidak sesuai.'];
                        exit(header('location: /admin/guest/product/'));

                    }
                    
                    if (isset($_FILES['petunjuk'])) {
                        $format_petunjuk = end(explode('.', strtolower($_FILES['petunjuk']['name'])));
                        
                        if (in_array($format_petunjuk, ['jpg', 'jpeg', 'png'])) {
                            $name_petunjuk = uniqid() . '.' . $format_petunjuk;
                            
                            move_uploaded_file($_FILES['petunjuk']['tmp_name'], '../../../assets/images/' . $name_petunjuk);
                            
                            $petunjuk = base_url() . '/assets/images/' . $name_petunjuk;
                        } else {
                            $petunjuk = '';
                        }
                    } else {
                        $petunjuk = '';
                    }
                    
                    if ($validate_status == 'Y') {
                        if (empty($validate_code)) {
                            $_SESSION['alert'] = ['danger', 'Failed!', 'Kode validasi ID games tidak boleh kosong.'];
                            exit(header('location: /admin/guest/product/'));
    
                        } else {
                            $validate_id = $validate_code;
                        }
                    } else {
                        $validate_id = 'Tydacks';
                    }
                    
                    $slug = slug($name);
                    
                    if ($slug == 'sistem') {
                        $_SESSION['alert'] = ['danger', 'Failed!', 'Gagal menambahkan Product.'];
                        exit(header('location: /admin/guest/product/'));

                    } else {
                        mysqli_query($db, "INSERT INTO games_guest VALUES ('','$name','$sub_name','$category','$slug','$nama_file','$product','$tipee','$sistem_id','$validate_id','$urutan','$keterangan','$petunjuk','On')");
                        if($tipee !== "SOSMED"){
                        $write = '<?php
$slug = "'.$slug.'";
require "sistem.php";
';
$open = fopen('../../../id/product/'.$slug.'.php', 'w');
fwrite($open, $write);
}else{
$write = '<?php
$slug = "'.$slug.'";
require "smm.php";
';
$open = fopen('../../../id/product/'.$slug.'.php', 'w');
fwrite($open, $write);
}
                        
                        $_SESSION['alert'] = ['success', 'Success!', 'Data berhasil di tambahkan.'];
                    	exit(header("Location: ".base_url('/admin/guest/product')));
                    }
                }
            } else {
                $_SESSION['alert'] = ['danger', 'Failed!', 'Gambar product tidak boleh kosong.'];
                exit(header('location: /admin/guest/product/'));

            }
            
        }
    } else {
        $_SESSION['alert'] = ['danger', 'Failed!', 'Masih ada data yang kosong.'];
        exit(header('location: /admin/guest/product/'));
    }
}

if (isset($_POST['btn_kategori'])) {
    if (isset($_POST['kategori'])) {
        $kategori = $_POST['kategori'];
        $urutan = $_POST['urutan'];
        
        if (!empty($kategori)) {
            $query_kategori = mysqli_query($db, "SELECT * FROM games_kategori WHERE kategori = '$kategori' kategori_id='0'");
            if (mysqli_num_rows($query_kategori) == 0) {
                mysqli_query($db, "INSERT INTO games_kategori VALUES ('','$kategori','0','$urutan')");
                
                $_SESSION['alert'] = ['success', 'Success!', 'Data kategori di tambahkan.'];
                exit(header('location: /admin/guest/product/'));

            } else {
                $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori sudah digunakan.'];
                exit(header('location: /admin/guest/product/'));
            }
        } else {
            $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori tidak boleh kosong.'];
            exit(header('location: /admin/guest/product/'));
        }
    } else {
        $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori tidak boleh kosong.'];
        exit(header('location: /admin/guest/product/'));
    }
}
if (isset($_POST['btn_sub'])) {
    if (isset($_POST['sub'])) {
        $kategori = $_POST['kategori'];
        $sub = $_POST['sub'];
        $urutan = $_POST['urutan'];
        
        if (!empty($sub)) {
            $query_kategori = mysqli_query($db, "SELECT * FROM games_kategori WHERE kategori = '$kategori'");
            
            if (mysqli_num_rows($query_kategori) == 0) {
                mysqli_query($db, "INSERT INTO games_kategori VALUES ('','$sub','$kategori','$urutan')");
                
                $_SESSION['alert'] = ['success', 'Success!', 'Data kategori di tambahkan.'];
                exit(header('location: /admin/guest/product/'));

            } else {
                $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori sudah digunakan.'];
                exit(header('location: /admin/guest/product/'));
            }
        } else {
            $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori tidak boleh kosong.'];
            exit(header('location: /admin/guest/product/'));
        }
    } else {
        $_SESSION['alert'] = ['danger', 'Failed!', 'Kategori tidak boleh kosong.'];
        exit(header('location: /admin/guest/product/'));
    }
}

include_once '../../../layouts/header-admin.php'; ?>
<div class="row justify-content-center">
    <div class="col-md-8 col-12">
        <div class="card bg-dark shadow">
            <div class="card-header">
                <h4 class="card-title">Kelola Produk</h4>
            </div>
            <div class="card-body card-dashboard">
                <ul class="nav nav-pills justify-content-left horitab-scroll" id="myTab" role="tablist">
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <button class="nav-link btn btn-sm btn-outline-primary" onclick="modal_tambah();">Tambah Produk</button>
                    </li>
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <button class="nav-link btn btn-sm btn-outline-danger" onclick="modal_kategori();">Kategori</button>
                    </li>
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <button class="nav-link btn btn-sm btn-outline-success" onclick="modal_sub();">Sub Kategori</button>
                    </li>
                    </ul>
                <div class="table-responsive">
                    <table class="table" id="tbb">
                        <thead>
                        <tr>
                            <th>No</th>
                            <th style="white-space: nowrap;">Nama Produk</th>
                            <th>Produk</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $no = 1;
                        $query_games = mysqli_query($db, "SELECT * FROM games_guest");
                        while($fetch_games = mysqli_fetch_assoc($query_games)):
                        ?>
                        <tr>
                            <td><?= $no++; ?></td>
                            <td style="white-space: nowrap;"><?= $fetch_games['name']; ?></td>
                            <td><?= $fetch_games['product']; ?></td>
                            <td>
                                <select class="form-control" onchange="ganti_status('<?= $fetch_games['id'] ?>', this.value);">
                                    <option value="On" <?= $fetch_games['status'] == 'On' ? 'selected' : ''; ?>>On</option>
                                    <option value="Off" <?= $fetch_games['status'] == 'Off' ? 'selected' : ''; ?>>Off</option>
                                </select>
                            </td>
                            <td width="10" style="white-space: nowrap;">
                                <a href="/admin/guest/product/edit.php?id=<?= $fetch_games['id']; ?>" class="btn btn-info btn-sm">Edit</a>
                                <a href="/admin/guest/product/?action=hapus&id=<?= $fetch_games['id']; ?>" class="btn btn-danger btn-sm">Hapus</a>
                            </td>
                        </tr>
                        <?php endwhile; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content bg-dark">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Tambah Produk</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
            </div>
            <form action="" method="POST" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label>Nama Produk</label>
                                <input type="text" class="form-control" autocomplete="off" name="name">
                            </div>
                            <div class="form-group mb-3">
                                <label>Sub Name</label>
                                <input type="text" class="form-control" autocomplete="off" name="sub_name">
                            </div>
                            <div class="form-group mb-3">
                                <label>Kategori</label>
                                <select class="form-control" name="category">
                                    <option value="">Pilih salah satu</option>
                                    <?php
                                    $query_games_categor = mysqli_query($db, "SELECT DISTINCT kategori FROM games_kategori WHERE NOT kategori_id='0' ORDER BY urutan ASC");
                                    while($fetch_games_catego = mysqli_fetch_assoc($query_games_categor)): ?>
                                    <option value="<?= $fetch_games_catego['kategori']; ?>"><?= $fetch_games_catego['kategori']; ?></option>
                                    <?php endwhile; ?>
                                </select>
                            </div>
                            <div class="form-group mb-3">
                                <label>Gambar</label>
                                <div class="custom-file">
                                    <input type="file" accept=".jpg, .jpeg, .png" class="custom-file-input" id="customFile" name="gambar">
                                    <label class="custom-file-label" for="customFile">Choose file</label>
                                </div>
                            </div>
                            <div class="form-group mb-3">
                                <label>Pilih Kategori Produk</label>
                                <select class="form-control" name="tipe" id="tipe">
                                    <option value="0">Pilih salah satu</option>
                                    <option value="VGAME">Voucher Game</option>
                                    <option value="PULSA">Pulsa</option>
                                    <option value="DATA">Data</option>
                                    <option value="EMONEY">E-Money</option>
                                    <option value="SMSDANTELPON">Paket SMS & Telpon</option>
                                    <option value="SOSMED">Sosial Media</option>
                                </select>
                            </div>
                            <div class="form-group mb-3">
                                <label>Produk</label>
                                <select class="form-control" name="operator" id="operator">
                                    <option value="0">Pilih salah satu</option>
                                </select>
                            </div>
                            <div class="form-group mb-3">
                                <label>Sistem ID</label>
                                <select class="form-control" name="sistem_id">
                                    <option value="0">Pilih salah satu</option>
                                    <?php $sis = $db->query("SELECT * FROM form_input ORDER BY id ASC");
                                    while($siss = $sis->fetch_assoc()):?>
                                    <option value="<?= $siss['slug'];?>"<?= $siss['slug'] == $siss['slug'] ? 'selected' : ''; ?>><?= $siss['name'];?></option>
                                    <?php endwhile;?>
                                </select>
                            </div>
                            <div class="form-group mb-3">
                                <label>Validate ID</label>
                                <select class="form-control" name="validate_status" onchange="select_validate(this.value);">
                                    <option value="Y">Ya</option>
                                    <option value="N" selected>Tidak</option>
                                </select>
                                <div id="input-lynchstore" class="d-none">
                                    <input type="text" name="validate_code" class="form-control mt-1" placeholder="Kode Games" autocomplete="off">
                                    <small>Cek kode games <a href="https://documenter.getpostman.com/view/21960688/VUjLJRm3" target="_blank">disini</a></small>
                                </div>
                            </div>
                            <div class="form-group mb-3">
                                <label>Urutan</label>
                                <input type="number" class="form-control" name="urutan" autocomplete="off">
                            </div>
                            <div class="form-group mb-3">
                                <label>Foto Petunjuk</label>
                                <div class="custom-file">
                                    <input type="file" accept=".jpg, .jpeg, .png" class="custom-file-input" id="customFile" name="petunjuk">
                                    <label class="custom-file-label" for="customFile">Choose file</label>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group mb-3">
                                <label>Keterangan</label>
                                <textarea name="keterangan"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="float-right">
                        <button type="button" data-bs-dismiss="modal" aria-label="Close" class="btn bg-light fw-bold">BACK</button>
                        <button class="btn btn-info" type="submit" name="tombol">Tambah Sub Kategori</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="modal-kategori" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-dark">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Kategori</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
            </div>
            <div class="modal-body">
                <ul class="nav nav-pills justify-content-left" id="myTab" role="tablist">
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <a class="nav-link btn-sm btn-category active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Kategori</a>
                    </li>
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <a class="nav-link btn-sm btn-category" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Tambah</a>
                    </li>
                </ul>
                <br>
                <div class="tab-content" id="myTabContent">
                    <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                        <div class="table-responsive">
                            <table class="table border" id="tbb">
                                <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Kategori</th>
                                    <th style="min-width: 100px;">Urutan</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
                                $no = 1;
                                $query_games_kategori = mysqli_query($db, "SELECT * FROM games_kategori WHERE kategori_id='0'");
                                while($fetch_games_kategori = mysqli_fetch_assoc($query_games_kategori)):
                                ?>
                                <tr>
                                    <td width="10"><?= $no++; ?></td>
                                    <td><?= $fetch_games_kategori['kategori']; ?></td>
                                    <td>
                                        <div class="input-group">
                                            <input type="number" id="urutan-kategori-<?= $fetch_games_kategori['id']; ?>" class="form-control" value="<?= $fetch_games_kategori['urutan']; ?>">
                                            <button class="btn btn-info" onclick="save_urutan('<?= $fetch_games_kategori['id']; ?>');">Ok</button>
                                        </div>
                                    </td>
                                    <td width="10">
                                        <a href="/admin/guest/product/?hapusa=<?= $fetch_games_kategori['id']; ?>" class="btn btn-danger btn-sm">Hapus</a>
                                    </td>
                                </tr>
                                <?php endwhile; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
                        <form action="" method="POST" enctype="multipart/form-data">
                            <div class="form-group mb-3">
                                <label>Kategori Baru</label>
                                <input type="text" class="form-control" autocomplete="off" name="kategori">
                            </div>
                            <div class="form-group mb-3">
                                <label>Urutan</label>
                                <input type="number" class="form-control" name="urutan" autocomplete="off">
                            </div>
                            <div class="float-right">
                                <button type="button" data-bs-dismiss="modal" aria-label="Close" class="btn bg-light fw-bold">BACK</button>
                                <button class="btn btn-info" type="submit" name="btn_kategori">Tambah Sub Kategori</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-sub" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content bg-dark">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Sub Kategori</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
            </div>
            <div class="modal-body">
                <ul class="nav nav-pills justify-content-left" id="myTab" role="tablist">
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <a class="nav-link btn-sm btn-category active" id="sub-tab" data-toggle="tab" href="#sub" role="tab" aria-controls="sub" aria-selected="true">Sub Kategori</a>
                    </li>
                    <li class="nav-item ms-1 nav-tab" role="presentation">
                        <a class="nav-link btn-sm btn-category" id="add-sub-tab" data-toggle="tab" href="#add-sub" role="tab" aria-controls="add-sub" aria-selected="false">Tambah</a>
                    </li>
                </ul>
                <br>
                <div class="tab-content" id="myTabContent">
                    <div class="tab-pane fade show active" id="sub" role="tabpanel" aria-labelledby="sub-tab">
                        <div class="table-responsive">
                            <table class="table border" id="tbb">
                                <thead>
                                <tr>
                                    <th>No</th>
                                    <th>Sub Kategori</th>
                                    <th>Kategori</th>
                                    <th style="min-width: 100px;">Urutan</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
                                $no = 1;
                                $query_games_kategori = mysqli_query($db, "SELECT * FROM games_kategori WHERE kategori_id NOT IN ('0')");
                                while($games_kategori = mysqli_fetch_assoc($query_games_kategori)):
                                $cat = $db->query("SELECT * FROM games_kategori WHERE id='".$games_kategori['kategori_id']."'")->fetch_assoc();
                                ?>
                                <tr>
                                    <td width="10"><?= $no++; ?></td>
                                    <td><?= $games_kategori['kategori'];?></td>
                                    <td><?= $cat['kategori']; ?></td>
                                    <td>
                                        <div class="input-group">
                                            <input type="number" id="urutan-kategori-<?= $games_kategori['id']; ?>" class="form-control" value="<?= $games_kategori['urutan']; ?>">
                                            <button class="btn btn-info" onclick="save_urutan('<?= $games_kategori['id']; ?>');">Ok</button>
                                        </div>
                                    </td>
                                    <td width="10">
                                        <a href="/admin/guest/product/?hapusaa=<?= $games_kategori['id']; ?>" class="btn btn-danger btn-sm">Hapus</a>
                                    </td>
                                </tr>
                                <?php endwhile; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="add-sub" role="tabpanel" aria-labelledby="add-sub-tab">
                        <form action="" method="POST">
                            <div class="form-group mb-3">
                                <label>Sub Kategori Baru</label>
                                <input type="text" class="form-control" autocomplete="off" name="sub">
                            </div>
                            <div class="form-group mb-3">
                                <label>Kategori</label>
                                <select class="form-control" name="kategori">
                                    <?php
                                    $catt = $db->query("SELECT * FROM games_kategori WHERE kategori_id='0'");
                                    while($cat = $catt->fetch_assoc()):?>
                                    <option value="<?= $cat['id'];?>"><?=$cat['kategori'];?></option>
                                    <?php endwhile;?>
                                </select>
                            </div>
                            <div class="form-group mb-3">
                                <label>Urutan</label>
                                <input type="number" class="form-control" name="urutan" autocomplete="off">
                            </div>
                            <div class="float-right">
                                <button type="button" data-bs-dismiss="modal" aria-label="Close" class="btn bg-light fw-bold">BACK</button>
                                <button class="btn btn-info" type="submit" name="btn_sub">Tambah Sub Kategori</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include_once '../../../layouts/footer-admin.php'; ?>
<script src="https://cdn.ckeditor.com/4.17.2/standard/ckeditor.js"></script>
<script>
    CKEDITOR.replace('keterangan', {
        height: 400,
    });
</script>
<script type="text/javascript">
		$(document).ready(function() {
		    $("#tipe").change(function() {
			    var tipe = $("#tipe").val();
		        $.ajax({
			        url: '<?= base_url(); ?>ajax/list-produk.php',
			        data: 'tipe=' + tipe,
			        type: 'POST',
			        dataType: 'html',
			        success: function(msg) {
				        $("#operator").html(msg);
			        }
		        });
	        });
		});
</script>
<script>
    function modal_tambah() {
        $("#exampleModal").modal('show');
    }
    function modal_kategori() {
        $("#modal-kategori").modal('show');
    }
    function modal_sub() {
        $("#modal-sub").modal('show');
    }
    function select_validate(status) {
        if (status == 'N') {
            $("#input-lynchstore").addClass('d-none');
        } else {
            $("#input-lynchstore").removeClass('d-none');
        }
    }
    function save_urutan(id) {
        
        var urutan = $("#urutan-kategori-" + id).val();
        
        $.ajax({
            url: '<?= base_url(); ?>admin/guest/ajax/save-urutan.php',
            type: 'POST',
            data: 'urutan=' + urutan + '&id=' + id,
        });
    }
    function ganti_status(id, status) {
        
        $.ajax({
            url: '<?= base_url(); ?>admin/guest/ajax/update-status.php',
            type: 'POST',
            data: 'id=' + id + '&status=' + status + '&table=games_guest',
        });
    }
</script>
<script>
$(document).ready(function() {
	$('#tbb').dataTable();
 });
    $(".custom-file-input").on("change", function() {
        var fileName = $(this).val().split("\\").pop();
        $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
    });
</script>