<?php
  require_once('includes/load.php');
  // Checkin What level user has permission to view this page
  page_require_level(1);
?>
<?php
  $color = find_by_id_new('colordetails',(int)$_GET['ColorId'],'ColorId');
  if(!$color){
    $session->msg("d","Missing Color id.");
    redirect('color.php');
  }
  
   $stockcheck = find_by_column("stockdetails",(int)$_GET['ColorId'],"ColorId");
  $prodcheck = find_by_column("productdetails",(int)$_GET['ColorId'],"ColorId");
  $subcatcheck = find_by_column("subcategorydetails",(int)$_GET['ColorId'],"ColorId");

  if(isset($stockcheck['ColorId']) || isset($prodcheck['ColorId']) || isset($subcatcheck['ColorId'])) {
    $session->msg("d","Unable to detele!... A dependend entry is existing in the database ");
    redirect('color.php');
  }
  
?>
<?php
  $delete_id = delete_by_id_new('colordetails',(int)$color['ColorId'],'ColorId');
  if($delete_id){
      $session->msg("s","Color deleted.");
      redirect('color.php');
  } else {
      $session->msg("d","Color deletion failed.");
      redirect('color.php');
  }
?>
