<?php
/**
 * File			: menu_list.php
 * Description  : View untuk halaman menu
 * Created By	: Hendi
 * Created Date : 15 Mar 2021
 * Last Update  : 05 Apr 2021
**/
# cek validasi 
$inputs = session()->getFlashdata('inputs');
$errors = session()->getFlashdata('errors');
$success = session()->getFlashdata('success');
# sts add keterangannya jadi tambah
$sts = $inputs['sts'] ?? 'Tambah';
$stsket = ($sts == 'add' ? 'Tambah' : ucwords($sts));
?>
<div class="container-fluid">
	<div class="row">
		<div class="col-md-4">
			<div class="card">
				<div class="card-header card-header-info">
					<h4 class="card-title">Form Menu</h4>
					<p id="from-menu-category" class="card-category"><?= esc($stsket) ?> Menu Makanan/Minuman</p>
				</div>
				<div class="card-body">
					<?php 
						if (!empty($errors))
						{ 
							echo '<div class="alert alert-danger" role="alert">
									<button type="button" class="close" data-dismiss="alert" aria-label="Close">
										<i class="material-icons">close</i>
									</button>
									<ul>';
							 
							foreach ($errors as $error) 
							{ 
								echo '<li>'.esc($error).'</li>';
							} 
							
							echo '	</ul>
								  </div>';
						}
						
						if (!empty($success))
						{ 
							echo '<div class="alert alert-success" role="alert">
									<button type="button" class="close" data-dismiss="alert" aria-label="Close">
										<i class="material-icons">close</i>
									</button>
									<span>'.$success.'<span>
								  </div>';
						}
						
						# jika menggunakan form_open(), maka csrf token otomatis sudah dibuat.
						# esc() berfungsi menjaga serangan xss (cross site scripting)
					?>
					<?= form_open('menu/save', ['id' => 'form-menu']) ?>
						<input type="hidden" id="sts" name="sts" value="<?= esc($inputs['sts'] ?? 'add') ?>" />
						<div class="row">
                            <div class="col-md-12">
								<label>Kode</label>
								<div class="form-group">
									<input type="text" id="menu-id" name="menu_id" class="form-control" maxlength="4" value="<?= esc($inputs['menu_id'] ?? '') ?>" required <?= ($sts == 'edit' ? 'readonly' : '') ?> />
								    <small>Kode makanan / minuman</small>
                                </div>
							</div>
							<div class="col-md-12">
								<label>Nama Menu</label>
								<div class="form-group">
									<input type="text" id="menu-name" name="menu_name" class="form-control" value="<?= esc($inputs['menu_name'] ?? '') ?>" required />
									<small>Yang akan ditampilkan di monitor</small>
								</div>
							</div>
                            <div class="col-md-12">
								<label>Satuan</label>
								<div class="form-group">
									<input type="text" id="unit" name="unit" class="form-control" value="<?= esc($inputs['unit'] ?? '') ?>" required />
								</div>
							</div>
                            <div class="col-md-12">
								<label>Harga</label>
								<div class="form-group">
									<input type="text" id="price" name="price" class="form-control" value="<?= esc($inputs['price'] ?? '') ?>" required />
								</div>
							</div>
							<div class="col-md-12" hidden>
								<label>Slug</label>
								<div class="form-group">
									<input type="text" id="slug" name="slug" class="form-control" value="<?= esc($inputs['slug'] ?? '') ?>" readonly />
									<small>otomatis</small>
								</div>
							</div>
						</div>
						<div class="row" hidden>
							<div class="col-md-12">
								<div class="form-group">
									<label>Keterangan</label>
									<div class="form-group">
										<textarea id="description" name="description" class="form-control" rows="4"><?= esc($inputs['description'] ?? '') ?></textarea>
										<small>Opsional, boleh dikosongkan</small>
									</div>
								</div>
							</div>
						</div>
						<button type="submit" class="btn btn-info pull-right">Simpan</button>
						<div class="clearfix"></div>
					<?= form_close() ?>
				</div>
			</div>
		</div>
		<div class="col-md-8">
			<div class="card">
				<div class="card-header card-header-info">
					<h4 class="card-title">List Menu</h4>
					<p class="card-category">Menampilkan Data Menu Makanan/Minuman</p>
				</div>
				<div id="list-menu" class="card-body">
					<div class="toolbar">
						<button id="btn-add" rel="tooltip" title class="btn btn-info btn-fab" data-original-title="Input Menu Baru"><i class="material-icons">border_color</i><div class="ripple-container"></div></button>
					</div>
					<div class="material-datatables">
						<table id="dt-<?= $mod ?>" class="table table-striped table-no-bordered table-hover dataTable dtr-inline" cellspacing="0" width="100%" role="grid">
							<thead>
								<tr role="row">
                                    <th>Kode</th>
									<th>Nama</th>
									<!--<th>Slug</th>-->
                                    <th>Satuan</th>
                                    <th>Harga</th>
									<!--<th>Keterangan</th>-->
									<th>Aksi</th>
								</tr>
							</thead>
							<tbody></tbody>
							<tfoot></tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
  //_mod dideklarasikan di myscrypt.js
  _mod = '<?= $mod ?>';
</script>