<?php 
// Delete Item....
if(isset($_REQUEST['del-type'])){
  $DeType = $_REQUEST['del-type'];
  $check = $conn->prepare("SELECT * FROM `tbl_items` WHERE `itype`='$DeType' ");
  $check->execute();
  if($check->rowCount()==0){
  $d=$conn->prepare("DELETE from `tbl_typesitem` WHERE `item_type_id`='".$_REQUEST['del-type']."' ");
  $d->execute();
    $msge="Data Removed";
  }else{
    $msg="Do not delete this data";  
  }
  
}

 if(isset($_REQUEST['btnType'])){
		try{
			$typeName = $_REQUEST['typeName'];
			
			$sql = $db->query("INSERT INTO `tbl_typesitem`(`itypeName`,`sttype`)
			VALUES ('$typeName',1)");
			$msg = " Successfully Added Type!";
			
		}catch(PDOException $e){
			$msg = $e->getMessage();
		}
		
	}

  ##### UPDATE #####endregion
  if(isset($_POST['update_Itpe'])){
		try{
			$typename_upd = $_POST['typename_upd'];
			$itpe_id = $_POST['itpe_id'];
			$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			
			$sql = $db->query("UPDATE `tbl_typesitem` SET `itypeName` = '$typename_upd' WHERE `item_type_id` = '$itpe_id'");
			$msg = "Updated Successfully";
			
		}catch(PDOException $e){
			echo $e->getMessage();
		}
	}
?>


<div class="subheader">
    <h1 class="subheader-title" style="font-weight: bold;">
        <i class='subheader-icon fa fa-folder-open text-primary'></i><?php echo $title;?> 
    </h1>
    <div class="d-flex mr-4">
    <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
    </div>
</div>
<?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="row">
    <div class="col-md-4">
        <?php 
        if(isset($_REQUEST['t'])){
        include 'tpe_upd.php';
        }else{
        include 'tpefm.php';
        }
        ?> 
    </div>
  
    <div class="col-md-8">
      <?php include 'listType.php';?>   
   </div>
</div>