<?php
	//find user id
	$inventoryId = $_GET['id'];

	$result = mysqli_query($conn, "SELECT * FROM inventories WHERE iv_id=$inventoryId");
	$row = mysqli_fetch_assoc($result);

	$getTitle = $row['iv_title'];
	$getCode = $row['iv_code'];
	$getBarcode = $row['iv_bcode'];
	$getPrice = $row['iv_price'];
	$getQty = $row['iv_qty'];
	$getPhotoLink = $row['iv_photolink'];
	$getNote = $row['iv_note'];


?>
<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>Inventory Detail</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">

						<form class="form-horizontal form-label-left" method="post">
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Title <span class="required">*</span>
								</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="title" placeholder="Cloth" type="text" value="<?php echo $getTitle; ?>" required>
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Quantity</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="qty" placeholder="Cloth" type="number" value="<?php echo $getQty; ?>">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Price</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="price" placeholder="" type="currency" value="<?php echo $getPrice; ?>">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Code
								</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="code" placeholder="" type="text" value="<?php echo $getCode; ?>">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Barcode
								</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="barcode" placeholder="" type="text" value="<?php echo $getBarcode; ?>">
								</div>
							</div>
							
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Photo Link
								</label>

								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="name" class="form-control col-md-7 col-xs-12" name="photolink" placeholder="" type="text" value="<?php echo $getPhotoLink; ?>">
								</div>
							</div>

							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="note">Note</span>
								</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
									<textarea id="message" class="form-control" name="note"><?php echo $getNote; ?></textarea>
								</div>
							</div>
							
							<div class="ln_solid"></div>
							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" name="submit" class="btn btn-success">Submit</button>
								</div>
							</div>
						</form>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
	if(isset($_POST['submit']))
	{
		$title = $_POST['title'];
		$code = $_POST['code'];
		$barcode = $_POST['barcode'];
		$price = $_POST['price'];
		$qty = $_POST['qty'];
		$photolink = $_POST['photolink'];
		$note = $_POST['note'];
		
		$adminId = $_SESSION['admin'][0];
		
		mysqli_query($conn, "UPDATE inventories SET iv_title='$title', iv_code='$code', iv_bcode='$barcode', iv_price='$price', iv_qty=$qty, iv_photolink='$photolink', iv_note='$note' WHERE iv_id=$inventoryId") or die (mysql_error());
		
		header('Location: index.php?pagecontent=inventories');
	}
?>