<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
if(!$statuslogin) exit;
$mod = basename(__FILE__, '.php');
$page->tbJs($mod);
$page->addPlugin("upload");
if(isset($_GET['id'])){
	$page->addJs(BS_JS."reqcb.js");
	$id=strip_tags(stripslashes($_GET['id']));
	$page->setJudul("Input Data Produk Baru");
	$nama="";
	$kode="";
	$harga="";
	$point="";
	$keterangan="";
	if($id>0){
		$page->setJudul("Edit Data Produk");
		$query="SELECT t1.`id`,
					t1.`tanggal`,
					t1.`kode`,
					t1.`nama`,
					t1.`harga`,
					t1.`point`,
					t1.keterangan,
					t1.`jumlah_gambar`,
					t1.`status`
			FROM tb_produk as t1
			WHERE t1.id=?";
		$rs=$db->loadAssoc($query,array($id));
		if(isset($rs['id'])){
			$nama=$rs['nama'];
			$kode=$rs['kode'];
			$keterangan=$rs['keterangan'];
			$harga=number_format($rs['harga'],0,',','.');
			$point=number_format($rs['point'],2,',','.');
		}else{
			exit;
		}
	}
	$hasildata=array(
		"id"=>$id
	);
	$page->addLoad("masterproduk.edit(".json_encode($hasildata,true).")");
	?>
	<div class="box_main_konten">
		<h3>DETAIL DATA PRODUK</h3>
		<div class="group_form">
			<title>Nama</title>
			<div class="col10">
				<input id="nama" value="<?php echo $nama;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Kode</title>
			<div class="col10">
				<input id="kode" value="<?php echo $kode;?>" />
			</div>
		</div>
		
		<div class="group_form">
			<title>Harga</title>
			<div class="col10">
				<input id="harga" onkeyup="kudus.buatduitel(this)" value="<?php echo $harga;?>" />
			</div>
		</div>
		<div class="group_form">
			<title>Point</title>
			<div class="col10">
				<input id="point" onkeyup="kudus.buatduitel(this)" value="<?php echo $point;?>" />
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>GAMBAR PRODUK</h3>
		<div>
			<div id="grid_gambar"></div>
		</div>
		<div class="box_button_bawah">
			<div id="loader_input_gambar" class="error"></div>
			<span class="bthijau medium" onclick="masterproduk.inputgambarproduk()">Input Gambar Produk</span>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_main_konten">
		<h3>DESKRIPSI PRODUK</h3>
		<div>
			<textarea id="keterangan" style="height: 100px;"><?php echo $keterangan;?></textarea>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="box_button_bawah">
		<div id="loader_produk_err" class="error"></div>
		<span class="btmerah btncancel" onclick="masterproduk.kembali()">Kembali</span>&nbsp;&nbsp;<span onclick="masterproduk.simpan()" class="bthijau btnsave">Simpan</span>
	</div>
	<?php
}else{
	$page->addLoad("masterproduk.load()");
	$page->setJudul("Master Data Produk");
	?>
	<div class="box_button_atas">
		Jumlah baris: <select id="jumlah_hal" class="slkecil" onchange="masterproduk.loade()">
			<option value="30">30</option>
			<option value="50">50</option>
			<option value="100">100</option>
		</select> &nbsp;
		Hal: <select id="hal_ke" class="slkecil" onchange="masterproduk.load()"><option value="1">1</option></select>
		&nbsp;<input placeholder="Default: Nama Produk" onkeypress="masterproduk.enter(event)" id="cari" class="in_cari" />
		&nbsp;&nbsp;<span id="btcari" class="btnone btncari" onclick="masterproduk.loade()">Cari</span>
		&nbsp;&nbsp;<span class="btnone btncanggih" onclick="masterproduk.caricanggih()">Cari Detail</span>
	</div>
	<div id="grid_masterproduk"></div>
	<div id="loader_daataproduk" class="error"></div>
	<div class="box_button_bawah">
		<span onclick="masterproduk.buat(0)" class="bthijau btninput">Tambah produk</span>
	</div>
	<div id="btedit" style="display:none;">
		<span class="icon_del" onclick="masterproduk.hapus(#{id})"></span>
		<span class="icon_edit" onclick="masterproduk.buat(#{id})"></span>
	</div>
	<span id="bturutan" class="bthijau medium" style="display: none;" onclick="masterproduk.ubahurutan(#{id},##{jumlah_tabel},##{baris_tabel},this)">#{urutan}</span>
	
	<span id="btstatus" style="display: none" class="#(#{status}==1)?'mini_ok':'mini_dis'#" onclick="masterproduk.setstatus(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
	<div id="btdetailproduk" style="display: none;">
		<div>#{kode}</div>
		<div><b>#{nama}</b></div>
	</div>
	<?php
}
?>
<div id="box_upload" style="display: none;">
	<div style="padding: 10px;">
		<div class="group_form">
			<title>Keterangan</title>
			<div class="col10">
				<input id="namagambar" />
			</div>
		</div>
		<div class="group_form">
			<title>Gambar Produk</title>
			<div class="col10">
				<div id="box_upload_gambar"></div>
			</div>
		</div>
		<div class="group_form">
			<title>&nbsp;</title>
			<div class="col10">
				<div class="box_button_bawah" style="margin-top: 20px;">
					<div id="loader_simpan_upload" class="error"></div>
					<div>
						<span class="btmerah" onclick="masterproduk.batalupload()">Batal</span>&nbsp;&nbsp;
						<span onclick="masterproduk.simpanupload()" class="bthijau">Simpan</span>
					</div>
				</div>
			</div>
		</div>
		<div style="clear: both;"></div>
	</div>
</div>
<span id="btdokumen" style="display: none" class="#(#{idgambar}==0)?'dok_tidak':'dok_ya'#" onclick="masterproduk.bukagambar(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
<div id="bteditgambar" style="display:none;">
	<span class="icon_del" onclick="masterproduk.hapusgambar(#{id},##{jumlah_tabel},##{baris_tabel},this)"></span>
</div>	