<?php
session_start(); 
include ("dbinfo.php");   
$error=''; 

if (isset($_POST['btn_login'])) 
{
	$username=$_POST['username'];
	$password=$_POST['password'];
		
	$query = mysqli_query($conn,"SELECT * FROM `admin_login` WHERE admin_email='".$username."' AND admin_pass='".$password."'")or die(mysqli_error($conn));

	$row = mysqli_fetch_array($query);
	$cnt = mysqli_num_rows($query);
	if ($cnt == 1) 
	{
		$_SESSION['admin_session']=$row['admin_id']; 
		header("location:admin_index.php"); 
	}
	else
	{
		header('location:index.php?status=1');
	}
}

//--------------------------------------- add fabric ----------------------------------
if (isset($_POST['btn_fsubmit'])) 
{
	$fid=$_POST['txt_fid'];
	$fname=$_POST['txt_fname'];
	$fstatus=$_POST['txt_fstatus'];
	
	if($fid=='')
	{   
		$query=mysqli_query($conn,"INSERT INTO `fabric`(`fname`, `fstatus`) VALUES('$fname','$fstatus')")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:fabric.php?status=1');
		}
		else
		{
		header('location:fabric.php?status=3');
		}
	}
	else
	{ 
		header("location:fabric.php?status=3");
	}
}

//--------------------------------------- update fabric ----------------------------------
if (isset($_POST['btn_fupdate'])) 
{
	$fid=$_POST['txt_fid'];
	$fname=$_POST['txt_fname'];
	$fstatus=$_POST['txt_fstatus'];
	
	if($fid!='')
	{   
		$query=mysqli_query($conn,"UPDATE `fabric` SET `fname`='$fname', `fstatus`='$fstatus' WHERE `fid`='$fid'")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:fabric.php?status=1');
		}
		else
		{
		header('location:fabric.php?status=3');
		}
	}
	else
	{ 
		header("location:fabric.php?status=3");
	}
}

//--------------------------------------- add gsm ----------------------------------
if (isset($_POST['btn_gsubmit'])) 
{
	$gid=$_POST['txt_gid'];
	$gname=$_POST['txt_gname'];
	$gstatus=$_POST['txt_gstatus'];
	
	if($gid=='')
	{   
		$query=mysqli_query($conn,"INSERT INTO `gsm`(`gname`, `gstatus`) VALUES('$gname','$gstatus')")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:gsm.php?status=1');
		}
		else
		{
		header('location:gsm.php?status=3');
		}
	}
	else
	{ 
		header("location:gsm.php?status=3");
	}
}

//--------------------------------------- update gsm ----------------------------------
if (isset($_POST['btn_gupdate'])) 
{
	$gid=$_POST['txt_gid'];
	$gname=$_POST['txt_gname'];
	$gstatus=$_POST['txt_gstatus'];
	
	if($gid!='')
	{   
		$query=mysqli_query($conn,"UPDATE `gsm` SET `gname`='$gname', `gstatus`='$gstatus' WHERE `gid`='$gid'")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:gsm.php?status=1');
		}
		else
		{
		header('location:gsm.php?status=3');
		}
	}
	else
	{ 
		header("location:gsm.php?status=3");
	}
}

//--------------------------------------- add color ----------------------------------
if (isset($_POST['btn_csubmit'])) 
{
	$cid=$_POST['txt_cid'];
	$cname=$_POST['txt_cname'];
	$hex=$_POST['txt_hex'];
	$cstatus=$_POST['txt_cstatus'];
	
	if($cid=='')
	{   
		$query=mysqli_query($conn,"INSERT INTO `color`(`cname`, `hex`, `cstatus`) VALUES('$cname','$hex','$cstatus')")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:color.php?status=1');
		}
		else
		{
		header('location:color.php?status=3');
		}
	}
	else
	{ 
		header("location:color.php?status=3");
	}
}

//--------------------------------------- update color ----------------------------------
if (isset($_POST['btn_cupdate'])) 
{
	$cid=$_POST['txt_cid'];
	$cname=$_POST['txt_cname'];
	$hex=$_POST['txt_hex'];
	$cstatus=$_POST['txt_cstatus'];
	
	if($cid!='')
	{   
		$query=mysqli_query($conn,"UPDATE `color` SET `cname`='$cname', `hex`='$hex', `cstatus`='$cstatus' WHERE `cid`='$cid'")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:color.php?status=1');
		}
		else
		{
		header('location:color.php?status=3');
		}
	}
	else
	{ 
		header("location:color.php?status=3");
	}
}

//--------------------------------------- add Category ----------------------------------
if (isset($_POST['btn_ctsubmit'])) 
{
	$ctid=$_POST['txt_ctid'];
	$ctname=$_POST['txt_ctname'];
	$ctstatus=$_POST['txt_ctstatus'];
	
	if($ctid=='')
	{   
		$query=mysqli_query($conn,"INSERT INTO `category`(`ctname`, `ctstatus`) VALUES('$ctname','$ctstatus')")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:category.php?status=1');
		}
		else
		{
		header('location:category.php?status=3');
		}
	}
	else
	{ 
		header("location:category.php?status=3");
	}
}

//--------------------------------------- update Category ----------------------------------
if (isset($_POST['btn_ctupdate'])) 
{
	$ctid=$_POST['txt_ctid'];
	$ctname=$_POST['txt_ctname'];
	$ctstatus=$_POST['txt_ctstatus'];
	
	if($ctid!='')
	{   
		$query=mysqli_query($conn,"UPDATE `category` SET `ctname`='$ctname', `ctstatus`='$ctstatus' WHERE `ctid`='$ctid'")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:category.php?status=2');
		}
		else
		{
		header('location:category.php?status=3');
		}
	}
	else
	{ 
		header("location:category.php?status=3");
	}
}

//--------------------------------------- add manufacturer ----------------------------------
if (isset($_POST['btn_msubmit'])) 
{
	$mid=$_POST['txt_mid'];
	$mname=$_POST['txt_mname'];
	$maddress=$_POST['txt_maddress'];
	$cperson=$_POST['txt_cperson'];
	$cnumber=$_POST['txt_cnumber'];
	$email=$_POST['txt_email'];
	
	if($mid=='')
	{   
		$query=mysqli_query($conn,"INSERT INTO `manufacturer`(`mill_name`, `mill_address`, `contact_person`, `contact_no`, `email_id`) VALUES('$mname','$maddress','$cperson','$cnumber','$email')")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:manufacturer.php?status=1');
		}
		else
		{
		header('location:manufacturer.php?status=3');
		}
	}
	else
	{ 
		header("location:manufacturer.php?status=3");
	}
}

//--------------------------------------- update manufacturer ----------------------------------
if (isset($_POST['btn_mupdate'])) 
{
	$mid=$_POST['txt_mid'];
	$mname=$_POST['txt_mname'];
	$maddress=$_POST['txt_maddress'];
	$cperson=$_POST['txt_cperson'];
	$cnumber=$_POST['txt_cnumber'];
	$email=$_POST['txt_email'];
	
	if($mid!='')
	{   
		$query=mysqli_query($conn,"UPDATE `manufacturer` SET `mill_name`='$mname', `mill_address`='$maddress', `contact_person`='$cperson', `contact_no`='$cnumber', `email_id`='$email' WHERE `mid`='$mid'")or die(mysqli_error($conn));
		
		if($query==true)
		{
		header('location:manufacturer.php?status=1');
		}
		else
		{
		header('location:manufacturer.php?status=3');
		}
	}
	else
	{ 
		header("location:manufacturer.php?status=3");
	}
}




?>
