<?php include("side_nav.php"); ?>
<?php include("top_nav.php"); ?>
<?php
$output = '';
if(isset($_POST['submit'])){
	
  $category_id = mysqli_real_escape_string($con, $_POST['category_id']);
  $sub_category = mysqli_real_escape_string($con, $_POST['sub_category']);
  
  $sql = mysqli_query($con, "INSERT INTO sub_category (category_id, sub_category, user_id, display_status) VALUE ($category_id, '$sub_category', $user_id, 1)");
   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> Subcategory added.
					</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> Subcategory already in use.
						</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>Product Form <small>New product</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']); ?>" data-parsley-validate 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" >Sub Category <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="text" id="sub_category" name="sub_category" required="required" class="form-control col-md-7 col-xs-12">
                        </div>
                      </div>
					  
                      <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Category</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select name="category_id" class="form-control">
                            	<option> <?php
                                    $filter =mysqli_query($con, "SELECT * FROM category WHERE display_status = 1");
                                    while($row = mysqli_fetch_array($filter))
                                    {
                                    echo"<option value=".$row['category_id'].">" . $row['category_name'] . "</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="submit" class="btn btn-primary">Submit</button>
                        </div>
                      </div>

                    </form>
                  </div>
                </div>
              </div>
            </div>

  <?php include("footer.php"); ?>         
		