<?php
    $produk->id = $_GET[id];
    $p = $produk->produk();

    if (empty($_SESSION[nama])) {
        $nama = $p[nama];
    }else{
        $nama = $_SESSION[nama];
    }

    if (empty($_SESSION[ukuran])) {
        $ukuran = $p[ukuran];
    }else{
        $ukuran = $_SESSION[ukuran];
    }

    if (empty($_SESSION[berat])) {
        $berat = $p[berat];
    }else{
        $berat = $_SESSION[berat];
    }

    if (empty($_SESSION[stock])) {
        $stock = $p[stock];
    }else{
        $stock = $_SESSION[stock];
    }

    if (empty($_SESSION[harga])) {
        $harga = $p[harga];
    }else{
        $harga = $_SESSION[harga];
    }

    if (empty($_SESSION[diskon])) {
        $diskon = $p[diskon];
    }else{
        $diskon = $_SESSION[diskon];
    }

    if (empty($_SESSION[detail])) {
        $detail = $p[detail];
    }else{
        $detail = $_SESSION[detail];
    }

    if (empty($_SESSION[kategori])) {
        $kategori = $p[id_kategori];
    }else{
        $kategori = $_SESSION[kategori];
    }

    if (empty($_SESSION[brand])) {
        $brand = $p[id_brand];
    }else{
        $brand = $_SESSION[brand];
    }

    if (empty($_SESSION[aktif])) {
        $aktif = $p[aktif];
    }else{
        $aktif = $_SESSION[aktif];
   }
?>
<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="page-header">
                <h1>
                    Data Produk
                    <small>
                        <i class="ace-icon fa fa-angle-double-right"></i>
                        Edit Produk
                    </small>
                </h1>
            </div><!-- /.page-header -->
        </div>
        <form class="form-horizontal" role="form" action="view/view/modul/mod_produk/aksi_produk.php?aksi=edit" method="post" >
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Nama </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Nama" name="nama" class="col-xs-10 col-sm-5" value="<?php echo $nama; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Ukuran </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Ukuran" name="ukuran" class="col-xs-10 col-sm-5" value="<?php echo $ukuran; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Berat </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Berat" name="berat" class="col-xs-10 col-sm-5" value="<?php echo $berat; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Stock </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Stock" name="stock" class="col-xs-10 col-sm-5" value="<?php echo $stock; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Harga </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Harga" name="harga" class="col-xs-10 col-sm-5" value="<?php echo $harga; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Diskon </label>
                    <div class="col-sm-9">
                        <input type="text" id="form-field-1" placeholder="Diskon" name="diskon" class="col-xs-10 col-sm-5" value="<?php echo $diskon; ?>" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Detail </label>
                    <div class="col-sm-9">
                        <textarea id="form-field-1" placeholder="Detail" name="detail" class="col-xs-10 col-sm-5"><?php echo $detail; ?></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Kategori </label>
                    <div class="col-sm-9">
                        <select id="form-field-select-1" class="col-xs-10 col-sm-5" name="kategori">
                            <?php
                                $k = $kategori->listkategori();

                                while($i<count($k)){
                                    if ($k[$i][id_kategori]==$kategori) {
                                        ?>
                                            <option value="<?php echo $k[$i][id_kategori]; ?>" selected><?php echo $k[$i][nama]; ?></option>
                                        <?php
                                    }else{
                                       ?>
                                            <option value="<?php echo $k[$i][id_kategori]; ?>"><?php echo $k[$i][nama]; ?></option>
                                        <?php 
                                    }
                                    $i++;
                                }
                                unset($i);
                            ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Brand </label>
                    <div class="col-sm-9">
                        <select id="form-field-select-1" class="col-xs-10 col-sm-5" name="brand">
                            <?php
                                $b = $brand->listbrand();

                                while($i<count($b)){
                                    if ($b[$i][id_brand]==$brand) {
                                        ?>
                                            <option value="<?php echo $b[$i][id_brand]; ?>" selected><?php echo $b[$i][brand]; ?></option>
                                        <?php
                                    }else{
                                        ?>
                                            <option value="<?php echo $b[$i][id_brand]; ?>"><?php echo $b[$i][brand]; ?></option>
                                        <?php
                                    }
                                    $i++;
                                }
                                unset($i);
                            ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Aktif </label>
                    <div class="col-sm-9">
                        <select id="form-field-select-1" class="col-xs-10 col-sm-5" name="aktif">
                            <?php
                                if ($aktif=='Y') {
                                    ?>
                                        <option value="Y" selected>Aktif</option>
                                        <option value="N">Tidak Aktif</option>        
                                    <?php
                                }else{
                                    ?>
                                        <option value="Y">Aktif</option>
                                        <option value="N" selected>Tidak Aktif</option>        
                                    <?php
                                }
                            ?>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-xs-12">
                        <h3 class="header smaller lighter blue">Gambar</h3>
                        <div class="clearfix">
                            <div class="form-group">
                                <div class="col-sm-9">
                                    <input type="file" id="id-input-file-2" name="gambar" class="col-xs-4" />
                                    <button class="btn btn-info btn-xs" type="submit" name="key" value="1">
                                        <i class="ace-icon fa fa-plus  bigger-110 icon-only"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="pull-right tableTools-container"></div>
                        </div>
                        <div>
                            <table id="simple-table" class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>Gambar</th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        $g = $gambar->listgambar($_GET[id]);
                                        while($i<count($g)){
                                    ?>
                                            <tr>
                                                <td><?php echo"".$g[$i][nama].""; ?></td>
                                                <td>
                                                    <div class="hidden-sm hidden-xs action-buttons">
                                                        <a class="red" href="view/view/modul/mod_produk/aksi_produk.php?aksi=deletegambar&id=<?php echo"".$g[$i][id].""; ?>">
                                                            <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                    <?php
                                            $i++;
                                        }
                                        unset($i);
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div><!-- /.col --> 
            <div class="col-xs-12">
                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            Simpan
                        </button>
                        &nbsp; &nbsp; &nbsp;
                        <a href="index.php?module=produk">
                            <button class="btn" type="button">
                                <i class="ace-icon fa fa-undo bigger-110"></i>
                                Cancel
                            </button>
                        </a>
                    </div>
                </div>
            </div>                            
        </form>
    </div><!-- /.row -->
</div><!-- /.page-content -->