<?php 
// Delete Item....
if(isset($_REQUEST['del-sctg'])){
  $Dectg = $_REQUEST['del-sctg'];
  $check = $conn->prepare("SELECT * FROM `tbl_sub_supp` WHERE `ctg_su`='$Dectg' ");
  $check->execute();
  if($check->rowCount()==0){
  $d=$conn->prepare("DELETE from `tbl_categ_su` WHERE `ctg_id`='".$_REQUEST['del-sctg']."' ");
  $d->execute();
    $msge="Data Removed";
  }else{
    $msge="Do not delete this data";  
  }
  
}

 if(isset($_REQUEST['btnSS'])){
		try{
			$categName = $_REQUEST['categName'];
            $stype = $_REQUEST['stype'];
			
			$sql = $db->query("INSERT INTO `tbl_categ_su`(`ctg_name`,`categ_sts`,`ss_type`)
			VALUES ('$categName',1,'$stype')");
			$msg="Successfully Added Category!";
			
		}catch(PDOException $e){
			$msg = $e->getMessage();
		}
		
	}

  ##### UPDATE #####endregion
  if(isset($_POST['updateSctg'])){
		try{

            $ctg_id = $_REQUEST['ctg_id'];
            $categName = $_REQUEST['categName'];
            $stype = $_REQUEST['stype'];
			$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			
			$sql=$db->query("UPDATE `tbl_categ_su` SET `ctg_name` = '$categName',`ss_type` = '$stype' WHERE `ctg_id` = '$ctg_id'");
			$msg="Updated Successfully";
			
		}catch(PDOException $e){
			echo $e->getMessage();
		}  
	}
?>


<?php if(isset($msg)){?>
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        <strong>Well Done!</strong> <?php echo htmlentities($msg); ?>
      </div>
    <?php 
    }elseif(isset($msge)){
    ?>
     
    <div class="alert alert-danger alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
      <strong>Oooh Snap!</strong> <?php echo htmlentities($msge); ?>
    </div>
 <?php 
 }
?>

<div class="subheader">
    <h1 class="subheader-title" style="font-weight: bold;">
        <i class='subheader-icon fa fa-wrench'></i><?php echo $title;?> 
    </h1>
    <div class="d-flex mr-4">
        <div>
          <a href="<?php echo web_root;?>beam/bm?b=box">
            <label class="fs-sm mb-0 mt-2 mt-md-0">Unread Message</label>
            <h4 class="font-weight-bold mb-0"><i class="fa fa-envelope-o" aria-hidden="true"></i> <?php echo $notifieIncom;?></h4>
          </a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-4">
        <?php 
        if(isset($_REQUEST['s'])){
        include 'updte_ss_ctg.php';
        }else{
        include 's_sfm.php';
        }
        ?> 
    </div>
  
    <div class="col-md-8">
      <?php include 'list_s_subco.php';?>   
   </div>
</div>