<?php include("side_nav.php"); ?>
<?php include("top_nav.php"); ?>
<?php
// escape variables for security
$output = '';
if(isset($_POST['delete'])){
$sub_category_id = mysqli_real_escape_string($con, $_POST['sub_category']);

$sql = mysqli_query($con, "UPDATE sub_category SET display_status = 0 WHERE sub_category_id = $sub_category_id " );

if($sql){
	   $output =    '<div class="alert alert-success alert-dismissible fade in" role="alert">
						<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
						</button>
						<strong>Success. </strong> The subcategory has been deleted.
					</div>';
}else{
		$output =   '<div class="alert alert-danger alert-dismissible fade in" role="alert">
						<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
						</button>
						<strong>Failed. </strong> to delete subcategory.
					</div>';
	}
}

?>

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="clearfix"></div>
            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Delete Subcategory <small></small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                          <li><a href="#">Settings 1</a>
                          </li>
                          <li><a href="#">Settings 2</a>
                          </li>
                        </ul>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <br />
                    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" class="form-horizontal form-label-left">

					<div class="form-group">
							<div class="col-md-8 col-sm-8 col-xs-12 col-md-offset-2">
							    <?php echo $output; ?>
							</div>
					   </div>
					   
					 <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Delete Category</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="sub_category" id="selection2" class="form-control">
                            	<option id="sub_category_id"> <?php
                                    $filter =mysqli_query($con, "SELECT * FROM sub_category WHERE display_status = 1");
                                    while($row = mysqli_fetch_array($filter))
                                    {
                                    echo"<option value=".$row['sub_category_id'].">" . $row['sub_category'] . "</option>";
                                    }
                                   ?> 
								</option>
                            </select>
                        </div>
                      </div>
					
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                          <button type="submit" name="delete" class="btn btn-primary">Delete</button>
                        </div>
                      </div>

                    </form>
                  </div>
                </div>
              </div>
            </div>
			</div>
			</div>
    <!-- jQuery -->
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    
    <!-- Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	</body>
</html>              
		