<?php include('header.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
    <body>
		<?php include('navbar.php'); ?>
        <div class="container-fluid">
            <div class="row-fluid">
				<?php include('Device_sidebar.php'); ?>
		
						<div class="span9" id="content">
		                    <div class="row-fluid">
									<a href="add_Device.php" class="btn btn-info"  id="add" data-placement="right" title="Click to Add Device" ><i class="icon-plus-sign icon-large"></i> Add Device</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 stdevice 
									LEFT JOIN device_name ON stdevice.dev_id=device_name.dev_id
									LEFT JOIN stlocation ON stdevice.stdev_id=stlocation.stdev_id
									where 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="stdev_id" required>

													<option value="<?php echo $row['stdev_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="inputPassword">Staff Name</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['staff_name']; ?>" name="staff_name" id="inputPassword" placeholder="Staff Name" required>
											</div>
										</div>
										
									   <div class="control-group">
											<label class="control-label" for="inputEmail">Department</label>
											<div class="controls">			
												<select id="qtype" name="department" required>

													<option value="<?php echo $row['department']; ?>" ><?php echo $row['department']; ?></option>
													<?php
													$department = mysqli_query($con,"select * from config_department ORDER BY DEPARTMENT ASC");
													while($q = mysqli_fetch_array($department)){
													$d = $q['DEPARTMENT'];
													?>
													<option value="<?php echo $q['DEPARTMENT']; ?>"><?php echo $q['DEPARTMENT'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										
									  <div class="control-group">
											<label class="control-label" for="inputEmail">Designation</label>
											<div class="controls">			
												<select id="qtype" name="designation" >

													<option value="<?php echo $row['designation']; ?>" ><?php echo $row['designation']; ?></option>
													<?php
													$department = mysqli_query($con,"select * from config_designation ORDER BY DESIGNATION ASC");
													while($q = mysqli_fetch_array($department)){
													$d = $q['DESIGNATION'];
													?>
													<option value="<?php echo $q['DESIGNATION']; ?>"><?php echo $q['DESIGNATION'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label" for="inputEmail">Device Name</label>
											<div class="controls">			
												<select id="qtype" name="dev_id" required>

													<option value="<?php echo $row['dev_id']; ?>" ><?php echo $row['dev_name']; ?></option>
													<?php
													$device_query = mysqli_query($con,"select * from device_name");
													while($query_device_row = mysqli_fetch_array($device_query)){
													$dev_name = $row['dev_name'];
													?>
													<option value="<?php echo $query_device_row['dev_id']; ?>"><?php echo $query_device_row['dev_name'];  ?></option>
													<?php } ?>

												</select>
											</div>
										</div>
										
											<div class="control-group">
											<label class="control-label" for="inputPassword">Install Date</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['dev_install_date']; ?>" name="dev_install_date" id="inputPassword" >
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputPassword">Device Brand</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['dev_brand']; ?>" name="dev_brand" id="inputPassword" placeholder="Device Brand" required>
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputPassword">Serail No</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['dev_serial']; ?>" name="dev_serial" id="inputPassword" placeholder="Device Serial Number" required>
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputPassword">Device Model</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['dev_model']; ?>" name="dev_model" id="inputPassword" placeholder="Device Model" required>
											</div>
										</div>
										
										<div class="control-group">
											<label class="control-label" for="inputPassword">TeamViewer No</label>
											<div class="controls">
											<input type="text" class="span8" value="<?php echo $row['teamviewerno']; ?>" name="teamviewerno" id="inputPassword" placeholder="TeamViewer No">
											</div>
										</div>
										
										
											<div class="control-group">
										<div class="control-group">
											<label class="control-label" for="inputPassword"  placeholder="Device Status" >Device Status</label>
											<div class="controls">
											<select value="" name="dev_status" required>
													<option><?php echo $row['dev_status']; ?></option>
													<option value="New">New</option>	
												    <option value="In-use">In-use</option>	
													<option value="In-stock">In-stock</option>		
													<option value="Damaged">Damaged</option>													
												</select>								
											</div>
										</div>
									   </div>
										
										<div class="control-group">
											<label class="control-label" for="inputPassword">Description</label>
											<div class="controls">
													<textarea name="dev_desc" style="text-align:left" ><?php echo $row['dev_desc']; ?></textarea>
													
											</div>
										</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'])){
										$stdev_id = $_POST['stdev_id'];
										$staff_name=$_POST['staff_name'];
										$department=$_POST['department'];
										$designation=$_POST['designation'];
										$dev_id = $_POST['dev_id'];
										$dev_desc = $_POST['dev_desc'];
										$dev_serial = $_POST['dev_serial'];
										$dev_brand = $_POST['dev_brand'];
										$dev_model = $_POST['dev_model'];
										$dev_status = $_POST['dev_status'];
										
										
									
										mysql_query($con,"update stdevice set stdev_id = '$stdev_id' ,
										                                staff_name = '$staff_name',
																		department = '$department' ,
																		designation = '$designation' ,
										                                dev_id = '$dev_id' ,
																		dev_desc = '$dev_desc',
																		dev_serial  = '$dev_serial',
																		dev_brand = '$dev_brand',
																		dev_model = '$dev_model',
																		teamviewerno = '$teamviewerno',
																		dev_status = '$dev_status'
																		where id = '$get_id' ");
																										
									    mysqli_query($con,"insert into activity_log (date,username,action) values(NOW(),'$admin_username','Edit device info $dev_name')");
										?>
										<script>										
										window.location = "dev_summary.php";
										$.jGrowl("Device Successfully Update", { header: 'Device 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>