<?php
session_start();
require '../../config.php';
load('middleware', 'user');

if ($_SESSION['user']['level'] !== "Admin") {
    header('location:' . base_url('id'));
}
if(isset($_POST['tombol_DF'])){
    $key = $_POST['api_key'];
    $id = $_POST['api_id'];
    if(empty($id) OR empty($key)){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
    }else{
        $db->query("UPDATE provider SET api_id='$id', api_key='$key' WHERE code='DF'");
        $_SESSION['alert'] = ['success','Success','Digiflazz Berhasil Diperbarui'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }
}
if(isset($_POST['tombol_MP'])){
    $key = $_POST['api_key'];
    $id = $_POST['api_id'];
    if(empty($id) OR empty($key)){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }else{
        $db->query("UPDATE provider SET api_id='$id', api_key='$key' WHERE code='MP'");
        $_SESSION['alert'] = ['success','Success','MedanPedia Berhasil Diperbarui'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }
}
if(isset($_POST['tombol_AG'])){
    $key = $_POST['api_key'];
    $merchant = $_POST['merchant_id'];
    $api_id = $_POST['api_id'];
    if(empty($key) OR empty($merchant) OR empty($api_id)){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }else{
        $db->query("UPDATE provider SET merchant_id='$merchant', api_key='$key', api_id='$api_id' WHERE code='AG'");
        $_SESSION['alert'] = ['success','Success','ApiGames Berhasil Diperbarui'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }
}
if(isset($_POST['tombol_VR'])){
    $key = $_POST['key'];
    $id = $_POST['id'];
    if(empty($key) OR empty($id)){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }else{
        $db->query("UPDATE provider SET api_id='$id', api_key='$key' WHERE code='VR'");
        $_SESSION['alert'] = ['success','Success','Vip Reseller Berhasil Diperbarui'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
        
    }
}
if(isset($_POST['tombol_SO'])){
    $key = $_POST['key'];
    if(empty($key)){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }else{
        $db->query("UPDATE provider SET api_key='$key' WHERE code='SO'");
        $_SESSION['alert'] = ['success','Success','Smile One Berhasil Diperbarui'];
        exit(header("Location: ".base_url('/admin/setting/provider')));
    }
}
$DF = $db->query("SELECT * FROM provider WHERE code='DF'")->fetch_assoc();
$AG = $db->query("SELECT * FROM provider WHERE code='AG'")->fetch_assoc();
$VR = $db->query("SELECT * FROM provider WHERE code='VR'")->fetch_assoc();
$MP = $db->query("SELECT * FROM provider WHERE code='MP'")->fetch_assoc();
$SO = $db->query("SELECT * FROM provider WHERE code='SO'")->fetch_assoc();
require '../../layouts/header-admin.php';?>
<div class="row justify-content-center">
    <div class="col-12">
        <ul class="nav nav-pills justify-content-right horitab-scroll" id="myTab" role="tablist">
            <li class="nav-item ms-1 nav-tab">
                <a class="nav-link btn-sm btn-category active" style="font-size:12px;" data-toggle="pill" href="#DF">Digi Flazz</a>
            </li>
            <li class="nav-item ms-1 nav-tab">
                <a class="nav-link btn-sm btn-category" data-toggle="pill" style="font-size:12px;" href="#AG">Api Games</a>
            </li>
            <li class="nav-item ms-1 nav-tab">
                <a class="nav-link btn-sm btn-category" data-toggle="pill" style="font-size:12px;" href="#VR">Vip Reseller</a>
            </li>
            <li class="nav-item ms-1 nav-tab">
                <a class="nav-link btn-sm btn-category" data-toggle="pill" style="font-size:12px;" href="#MP">Medan Pedia</a>
            </li>
            <li class="nav-item ms-1 nav-tab">
                <a class="nav-link btn-sm btn-category" data-toggle="pill" style="font-size:12px;" href="#SO">Smile One</a>
            </li>
        </ul>
        <div class="tab-content">
            <div id="DF" class="tab-pane active">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">Digiflazz</h4>
                    </div>
                    <div class="card-body">
                        <form action="" method="POST" enctype="multipart/form-data">
                            <div class="form-group mb-3">
                                <label class="mb-1">Username</label>
                                    <input type="text" class="form-control" name="api_id" placeholder="LS91222" value="<?= $DF['api_id'];?>">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Key</label>
                                        <input type="text" class="form-control" name="api_key" placeholder="" value="<?= $DF['api_key'];?>">
                                </div>
                                <div class="float-left">
                                    <a class="btn btn-success" href="/admin/other/df-service?redirect">Get Layanan</a>
                                </div>
                                <div class="text-right">
                                    <button class="btn btn-light" type="reset">Batal</button>
                                    <button class="btn btn-primary" type="submit" name="tombol_DF">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div id="MP" class="tab-pane fade">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">Medan Pedia</h4>
                    </div>
                    <div class="card-body">
                        <form action="" method="POST" enctype="multipart/form-data">
                            <div class="form-group mb-3">
                                <label class="mb-1">Api Key</label>
                                    <input type="text" class="form-control" name="api_key" placeholder="LS91222" value="<?= $MP['api_key'];?>">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Id</label>
                                        <input type="text" class="form-control" name="api_id" placeholder="" value="<?= $MP['api_id'];?>">
                                </div>
                                <div class="float-left">
                                    <a class="btn btn-success" href="/admin/other/mp-service?redirect">Get Layanan</a>
                                </div>
                                <div class="text-right">
                                    <button class="btn btn-light" type="reset">Batal</button>
                                    <button class="btn btn-primary" type="submit" name="tombol_MP">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div id="AG" class="tab-pane fade">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">Api Games</h4>
                    </div>
                    <div class="card-body">
                        <form action="" method="POST" enctype="multipart/form-data">
                                <div class="form-group mb-3">
                                    <label class="mb-1">Merchant</label>
                                        <input type="text" class="form-control" name="merchant_id" placeholder="wcode.id" value="<?= $AG['merchant_id'];?>">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Key</label>
                                        <input type="text" class="form-control" name="api_key" placeholder="wcode.id" value="<?= $AG['api_key'];?>">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Id</label>
                                        <input type="text" class="form-control" name="api_id" placeholder="wcode.id" value="<?= $AG['api_id'];?>">
                                </div>
                                <div class="text-right">
                                    <button class="btn btn-light" type="reset">Reset</button>
                                    <button class="btn btn-primary" type="submit" name="tombol_AG">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div id="SO" class="tab-pane fade">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">Smile One</h4>
                    </div>
                    <div class="card-body">
                        <form action="" method="POST" enctype="multipart/form-data">
                                <div class="form-group mb-3">
                                    <label class="mb-1">PHPSESSION</label>
                                        <input type="text" class="form-control" name="key" placeholder="wcode.id" value="<?= $SO['api_key'];?>">
                                </div>
                                <div class="text-right">
                                    <button class="btn btn-light" type="reset">Reset</button>
                                    <button class="btn btn-primary" type="submit" name="tombol_SO">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <div id="VR" class="tab-pane fade">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">Vip Reseller</h4>
                    </div>
                    <div class="card-body">
                        <form action="" method="POST" enctype="multipart/form-data">
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Key</label>
                                        <input type="text" class="form-control" name="key" placeholder="wcode.id" value="<?= $VR['api_key'];?>">
                                </div>
                                <div class="form-group mb-3">
                                    <label class="mb-1">Api Id</label>
                                        <input type="text" class="form-control" name="id" placeholder="wcode.id" value="<?= $VR['api_id'];?>">
                                </div>
                                <div class="float-left">
                                    <a class="btn btn-success" href="/admin/other/vr-service?redirect">Get Layanan</a>
                                </div>
                                <div class="text-right">
                                    <button class="btn btn-primary" type="submit" name="tombol_VR">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php require '../../layouts/footer-admin.php';?>