<!-- **********************************************************************************************************************************************************
    MAIN CONTENT
    *********************************************************************************************************************************************************** -->
<!--main content start-->
<?php
if ($data_product->num_rows() == 0) {
    $id = "";
    $nama = "";
    $cost = "";
    $price = "";
    $diskon = "";
    $desk = "";
    $berat = "";
} else {
    foreach ($data_product->result() as $pro) {
        $id = $pro->id;
        $nama = $pro->product_name;
        $cost = $pro->cost;
        $price = $pro->price;
        $diskon = $pro->discount;
        $desk = $pro->description;
        $berat = $pro->weight;
    }
}
?>
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb"><i class="fa fa-angle-right"></i> Product Category</h4>
                    <form class="form-horizontal style-form" method="POST" action="<?= base_url() ?>admin/product/simpanData" enctype="multipart/form-data">
                        <input type="hidden" value="<?= $id ?>" name="id">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Kategori</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="id_category">
                                    <option value="">kategori</option>
                                    <?php
                                    foreach ($data_category->result() as $dct) {
                                        ?>
                                        <option value="<?= $dct->id ?>"><?= $dct->kategori_utama ?></option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Products Name</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" value="<?= $nama ?>" name="product_name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Cost</label>
                            <div class="col-sm-10">
                                <input type="text" id="cost" class="form-control" value="<?= $cost ?>" name="cost" onkeyup="formatAngka(this, '.');">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Price</label>
                            <div class="col-sm-10">
                                <input type="text" id="price" class="form-control" value="<?= $price ?>" name="price" onkeyup="formatAngka(this, '.');">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Berat</label>
                            <div class="col-sm-10">
                                <input type="text" id="price" class="form-control" value="<?= $berat ?>" name="berat" onkeyup="formatAngka(this, '.');">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Discount</label>
                            <div class="col-sm-10">
                                <input type="number" id="discount" class="form-control" value="<?= $diskon ?>" name="discount">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Products Image</label>
                            <div class="col-sm-10">
                                <input type="file" class="form-control" name="userfile">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Description</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" style="height: 120px" name="description"><?= $desk ?></textarea>
                            </div>
                        </div>
                        <hr/>
                        <a href="<?= base_url() ?>admin/products">
                            <button type="button" class="btn btn-default"><i class="fa fa-arrow-left"></i> Cancel</button>
                        </a>
                        <button type="submit" class="btn btn-primary pull-right"><i class="fa fa-save"></i> Save Data</button>
                    </form>
                    <div style="clear: both"></div>
                </div>
            </div>
        </div><!--row -->
    </section>
</section>

<script language="JavaScript">
    function formatAngka(objek, separator) {
        a = objek.value;
        b = a.replace(/[^\d]/g, "");
        c = "";
        panjang = b.length;
        j = 0;
        for (i = panjang; i > 0; i--) {
            j = j + 1;
            if (((j % 3) == 1) && (j != 1)) {
                c = b.substr(i - 1, 1) + separator + c;
            } else {
                c = b.substr(i - 1, 1) + c;
            }
        }
        objek.value = c;
    }
</script>


