<?php include('header.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
    <body>
    <?php include('Device_sidebar.php'); ?>
		<?php include('navbar.php'); ?>
        <div class="container-fluid">
            <div class="row-fluid">
              <div class="span9" id="content">
		                    <div class="row-fluid">
												 <a href="add_toner.php" class="btn btn-info"  id="add" data-placement="right" title="Click to Add Device" ><i class="icon-plus-sign icon-large"></i> Add Toner Stock</a>
					                <script type="text/javascript">
		                             $(document).ready(function(){
		                             $('#add').tooltip('show');
		                             $('#add').tooltip('hide');
		                              });
		                            </script> 
		                        <!-- block -->
		                        <div id="" class="block">
		                            <div class="navbar navbar-inner block-header">
		                                <div class="muted pull-left">Edit Device</div>
										<div class="muted pull-right"><a id="return" data-placement="left" title="Click to Return" href="device_stocks.php"><i class="icon-arrow-left icon-large"></i> Back</a></div>
																<script type="text/javascript">
																$(document).ready(function(){
																	$('#return').tooltip('show');
																	$('#return').tooltip('hide');
																});
																</script>     
		                            </div>
		                            <div class="block-content collapse in">									
									
									<?php
									$query = mysqli_query($con,"select * from cis_toner_instock_history 
									LEFT JOIN stlocation ON stlocation.stdev_id=cis_toner_instock_history.loc_id
									LEFT JOIN toner_color ON cis_toner_instock_history.color=toner_color.color
									where cis_toner_instock_history.toner_id = '$get_id'");
									$row = mysqli_fetch_array($query);
									?>
									
									    <form class="form-horizontal" method="post">
										<div class="control-group">
											<label class="control-label" for="inputEmail">Location</label>
											<div class="controls">			
												<select id="qtype" name="loc_id" required>

													<option value="<?php echo $row['loc_id']; ?>" ><?php echo $row['stdev_location_name']; ?></option>
													<?php
													$loc_query = mysqli_query($con,"select * from stlocation");
													while($query_loc = mysqli_fetch_array($loc_query)){
													$stdev_location_name = $query_loc['stdev_location_name'];
													?>
													<option value="<?php echo $query_loc['stdev_id']; ?>"><?php echo $query_loc['stdev_location_name'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Toner Model</label>
											<div class="controls">			
												<select id="qtype" name="toner_model" required>

													<option value="<?php echo $row['toner_model']; ?>" ><?php echo $row['toner_model']; ?></option>
													<?php
													$color_q = mysqli_query($con,"select * from toner_model");
													while($q = mysqli_fetch_array($color_q)){
													$s = $q['model'];
													?>
													<option value="<?php echo $q['model']; ?>"><?php echo $q['model'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputEmail">Color</label>
											<div class="controls">			
												<select id="qtype" name="color" required>

													<option value="<?php echo $row['color']; ?>" ><?php echo $row['color']; ?></option>
													<?php
													$color_q = mysqli_query($con,"select * from toner_color");
													while($q = mysqli_fetch_array($color_q)){
													$s = $q['color'];
													?>
													<option value="<?php echo $q['color']; ?>"><?php echo $q['color'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										 <div class="control-group">
											<label class="control-label" for="inputPassword">Description</label>
											<div class="controls">
													<textarea name="toner_description" >
													<?php echo $row['toner_description']; ?>
													</textarea>
											</div>
										</div>
										 <div class="control-group">
											<label class="control-label" for="inputPassword">Quantity</label>
											<div class="controls">
													<input name="quantity" value="<?php echo $row['quantity']; ?>"  readonly="">
													
													</input>
											</div>
									
										
										
										
										
										<div class="control-group">
										<div class="controls">
										
										<button id="update" data-placement="right" title="Click to update" name="update" type="submit" class="btn btn-info"><i class="icon-save icon-large"></i> Update</button>
										</div>
										</div>
										<script type="text/javascript">
										$(document).ready(function(){
										$('#update').tooltip('show');
										$('#update').tooltip('hide');
										});
										</script> 
										</form>
										
										<?php
										if (isset($_POST['update'])){
										$loc_id = $_POST['loc_id'];
										$toner_model = $_POST['toner_model'];
										$toner_description = $_POST['toner_description'];
										$color = $_POST['color'];
										
										
										
									
										mysqli_query($con,"update cis_toner_instock set loc_id = '$loc_id' ,
										                                toner_model = '$toner_model' ,
																		toner_description = '$toner_description',
																		color  = '$color'
																		where toner_id = '$get_id' ");
										mysqli_query($con,"update cis_toner_instock_history set loc_id = '$loc_id' ,
										                                toner_model = '$toner_model' ,
																		toner_description = '$toner_description',
																		color  = '$color'
																		where toner_id = '$get_id' ");
																										
									    mysqli_query($con,"insert into activity_log (date,username,action) values(NOW(),'$admin_username','Edit Toner info $toner_model')");
										?>
										<script>										
										window.location = "toner_instock_history.php";
										$.jGrowl("Device Successfully Update", { header: 'Toner update' });
										</script>
										<?php
										}
										
										
										?>
									
								
		                            </div>
		                        </div>
		                        <!-- /block -->
		                    </div>
              </div>
          </div>
<script>
	jQuery(document).ready(function(){
		jQuery("#opt11").hide();
		jQuery("#opt12").hide();
		jQuery("#opt13").hide();		

		jQuery("#qtype").change(function(){	
			var x = jQuery(this).val();			
			if(x == '1') {
				jQuery("#opt11").show();
				jQuery("#opt12").hide();
				jQuery("#opt13").hide();
			} else if(x == '2') {
				jQuery("#opt11").hide();
				jQuery("#opt12").show();
				jQuery("#opt13").hide();
			}
		});
		
	});
</script>
		<?php include('footer.php'); ?>
        </div>
		<?php include('script.php'); ?>
    </body>

</html>