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

	$result = mysqli_query($conn, "SELECT * FROM stocks WHERE s_id=$stockId");
	$row = mysqli_fetch_assoc($result);

	$stockTitle = $row['s_title'];
	$stockCode = $row['s_code'];
	$stockBarcode = $row['s_bcode'];
	$stockPrice = $row['s_price'];
	$stockQty = $row['s_qty'];
	$stockPhotoLink = $row['s_photolink'];
	$stockNote = $row['s_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>Stock 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 $stockTitle; ?>" 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 $stockQty; ?>">
								</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 $stockPrice; ?>">
								</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 $stockCode; ?>">
								</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 $stockBarcode; ?>">
								</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 $stockPhotoLink; ?>">
								</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 $stockNote; ?></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'];
		
		$userId = 0; //$_SESSION['users']; //
		
		mysqli_query($conn, "UPDATE stocks SET s_title='$title', s_code='$code', s_bcode='$barcode', s_price='$price', s_qty=$qty, s_photolink='$photolink', s_note='$note', u_id=$userId WHERE s_id=$stockId") or die (mysql_error());
		
		header('Location: index.php?pagecontent=stocks');
	}
?>