<?php

$cekID = new cekID();
$cekID->cek('serial', 'no', 1);
$cekVersi = new update();
$cekInt = new cekint();
?>
<style>
    .fontInput {
        font-size: 11px;
        font-family: arial;
    }

    .judul {
        font-size: 15px;
        font-family: arial;
    }
</style>

<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>

    <div class="container col-12 mb-4 pb-5">
        <div class="row  mx-3 pr-3">
            <div class="col-12">
                <div class="col-12 ">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-speedometer"></span> Update Aplikasi </b>
                        </div>

                        <div class="row">
                            <div class="col-12 col-sm-6 col-md-6 mt-4 ml-2 mr-4">
                                <div class="info-box">
                                    <span class="info-box-icon bg-primary elevation-1"><i class="bi bi-columns-gap"></i></span>

                                    <div class="info-box-content pb-2">
                                        <span class="info-box-text text-primary"><strong>Update Aplikasi Otomatis</strong></span>
                                        <span class="info-box-number">
                                            <form name='update' action='' method='post'>
                                                <div class="col-sm-12 invoice-col pt-0">
                                                    VERSI APLIKASI :
                                                    <?php echo $cekVersi->versiAplikasi() . "<br>";
                                                    if ($cekInt->is_konek() == false) {
                                                        echo "<i class='text-danger'>Tidak ada Kokensi Internet. Hubungkan Internet untuk cek Update Aplikasi</i> ";
                                                    } elseif ($cekVersi->cekUpdate() == true && $cekInt->is_konek() == true) {
                                                        echo "<i class='text-purple'><b>Terdapat Update Aplikasi versi " . $cekVersi->versiUpdate() . "</b></i><br>";
                                                        echo " <button type='submit' class='btn btn-primary btn-xs mx-1 px-2 mt-1' name='submitauto'><i class='bi-send'></i> UPDATE APLIKASI </button>";
                                                    } elseif ($cekVersi->cekUpdate() == false && $cekInt->is_konek() == true) {
                                                        echo "<i class='text-success'>Aplikasi Anda sudah Versi terbaru</i> ";
                                                    } elseif ($cekInt->is_konek() == false) {
                                                        echo "<i class='text-warning'>Server tidak terjangkau</i> ";
                                                    } ?>
                                                    <br>
                                                </div>
                                            </form>
                                        </span>
                                    </div>
                                    <!-- /.info-box-content -->
                                </div>
                                <!-- /.info-box -->
                            </div>
                            <div class="col-12 col-sm-6 col-md-6 mt-4 ml-2">
                                <div class="info-box">
                                    <span class="info-box-icon bg-primary elevation-1"><i class="bi bi-columns-gap"></i></span>

                                    <div class="info-box-content pb-0">
                                        <span class="info-box-text text-primary"><strong>Update Aplikasi Manual</strong></span>
                                        <span class="info-box-number">
                                            <!--
                                            <form enctype="multipart/form-data" action="<?php $classPage = new linkpage();
                                                                                        echo $classPage->pageAction('utility/update/uploadupdate'); ?>" method="post">
-->
                                            <form enctype="multipart/form-data" action="" method="post">


                                                <div class="col-sm-12 invoice-col pt-0">
                                                    <div class="form-group">

                                                        <div class="input-group">
                                                            <div class="custom-file">
                                                                <input type="file" class="custom-file-input" id="exampleInputFile" name="file" accept=".zip" required>
                                                                <label class="custom-file-label" for="exampleInputFile">Pilih File Update (update.zip)</label>

                                                            </div>
                                                            <button type="submit" class="btn btn-primary btn-xs mx-1 px-2 mt-0" name="submitmanual" onclick="return confirm('Apakah Anda yakin akan Update Aplikasi?')"><i class="bi-gear"></i> UPDATE </button>

                                                        </div>
                                                    </div>


                                                </div>
                                            </form>
                                        </span>
                                    </div>
                                    <!-- /.info-box-content -->
                                </div>
                                <!-- /.info-box -->
                            </div>
                        </div>



                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function() {
        bsCustomFileInput.init();
    });
</script>
<?php

$update = new update();
if (isset($_POST['submitauto'])) {
    $update->proses();
    // echo $update->uploadFileUpdate('submitmanual', 'update.zip', '/', './');
} elseif (isset($_POST['submitmanual'])) {
    // $update->prosesmanual();
    $update->prosesmanual();
} else {
    echo 'error';
}
