<?php
error_reporting(0);
include("../../include/db.php");	


function get_jobcard_check($jobcard_no)
{
	$Isql=mysql_query("select * from media_main where jobcard_no='$jobcard_no'");
    $rscount=mysql_num_rows($Isql);
	return $rscount;
}

/***************************** Main Add***********************************************************/
if(($_POST['action']=="SUBMIT")) 
{
$jobcard_no=$_POST['jobcard_no'];
$entry_time=$_POST['entry_time'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$created_by=$_POST['created_by'];
$style_name=$_POST['style_name'];
$cust_po_no=$_POST['cust_po_no'];
$combo=$_POST['combo'];
$jobtype=$_POST['jobtype'];
$fabric_type=$_POST['fabric_type'];
$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];
$check_item=get_jobcard_check($jobcard_no);
if($check_item==0)
{
 $Insql1=mysql_query("insert into media_main(jobcard_no,entry_date,created_by,cust_name,style_no,style_name,cust_po_no,job_type,fabric_type,combo,academic_yr,createdate)values('$jobcard_no','$entry_time','$created_by','$customer_name','$style_no','$style_name','$cust_po_no','$jobtype','$fabric_type','$combo','$acdmc_yr_res','$create_date1')");
 echo "Added Successfully";
 $insert_id = mysql_insert_id();
 $Upsq1211="update media_sub_list set insert_id='$insert_id' where jobcard_no='$jobcard_no'";
 mysql_query($Upsq1211) or die(error);
}
else
{
	echo "Already Exists...";
}
}
/***************************** Main Update***********************************************************/
if($_POST['action']=="UPDATE")
{
$edit_ids=$_POST['main_edit_id'];
$jobcard_no=$_POST['jobcard_no'];
$entry_time=$_POST['entry_time'];
$customer_name=$_POST['customer_name'];
$style_no=$_POST['style_no'];
$created_by=$_POST['created_by'];
$style_name=$_POST['style_name'];
$cust_po_no=$_POST['cust_po_no'];
$combo=$_POST['combo'];
$jobtype=$_POST['jobtype'];
$fabric_type=$_POST['fabric_type'];
$create_date1=date('Y-m-d');
$acadamic_yr=explode("-",$create_date1);
$acdmc_yr_res=$acadamic_yr[0];
  $Upsq12="update media_main set jobcard_no='$jobcard_no',entry_date='$entry_time',created_by='$created_by',cust_name='$customer_name',style_no='$style_no',style_name='$style_name',cust_po_no='$cust_po_no',job_type='$jobtype',fabric_type='$fabric_type',combo='$combo',academic_yr='$acdmc_yr_res',createdate='$create_date1', where main_id='$_POST[main_edit_id]'";
 mysql_query($Upsq12) or die(error);
 echo "Updated Successfully";
}


 /**********************************SUB ADD  QUERY ***************************************/


 if($_POST['action']=="ADD")
	{
	  $jobcard_no=$_POST['jobcard_no'];
      $in_cust_name=$_POST['in_cust_name'];
      $media_date=$_POST['media_date'];
	  $roll_name=$_POST['roll_name'];
      $media_particular=$_POST['media_particular'];
      $order_qty=$_POST['order_qty'];
      $plan_qty=$_POST['plan_qty'];
	  $steps=$_POST['steps'];
      $total_steps=$_POST['total_steps'];
	  $req_by=$_POST['req_by'];
	  $total_req=$_POST['total_req'];
	  $roll_size=$_POST['roll_size'];
	  $width=$_POST['width'];
	   $height=$_POST['height'];
	    $width_hid=$_POST['width_hid'];
		 $height_hid=$_POST['height_hid'];
	  $created_by=$_POST['created_by'];
	  $job_types=$_POST['job_types'];
	  $entrydates=date('Y-m-d',strtotime($_POST['entrydates']));
      $create_date1=date('Y-m-d');
	  $acadamic_yr=explode("-",$create_date1);
      $acdmc_yr_res=$acadamic_yr[0];
	// echo "insert into media_sub_list(jobcard_no,in_cust_name,media_date,media_particular,acad_yr,cr_date	 ,fabric_type,created_by,job_types,entrydates,roll_name,order_qty,plan_qty,steps,total_steps,req_by,tot_req_by,width,roll_size,height,width_hid,height_hid)values('$jobcard_no','$in_cust_name','$media_date','$media_particular','$acdmc_yr_res','$create_date1','$fabric_type','$created_by','$job_types','$entrydates','$roll_name','$order_qty','$plan_qty','$steps','$total_steps','$req_by','$total_req','$width','$roll_size','$height','$width_hid','$height_hid')";
$Insql1=mysql_query("insert into media_sub_list(jobcard_no,in_cust_name,media_date,media_particular,acad_yr,cr_date	 ,fabric_type,created_by,job_types,entrydates,roll_name,order_qty,plan_qty,steps,total_steps,req_by,tot_req_by,width,roll_size,height,width_hid,height_hid)values('$jobcard_no','$in_cust_name','$media_date','$media_particular','$acdmc_yr_res','$create_date1','$fabric_type','$created_by','$job_types','$entrydates','$roll_name','$order_qty','$plan_qty','$steps','$total_steps','$req_by','$total_req','$width','$roll_size','$height','$width_hid','$height_hid')");
include("media_sublist.php");
}

/******************************************** SUB DELETE*****************************************************************/
if($_POST['action']=="del_media_sublist")
{ 		 
		     $delete1="delete from media_sub_list where id='$_POST[id]'";
			 mysql_query($delete1);
			 include("media_sublist.php");
}
/******************************************** Main DELETE*****************************************************************/
if($_POST['action']=="delete_media")
{ 		 
  $delete2="delete from media_main where jobcard_no='$_POST[jobcard_no]'";
   mysql_query($delete2);
  $Delsql5="delete from media_sub_list where  jobcard_no='$_POST[jobcard_no]' ";
  mysql_query($Delsql5);
  include("media_entry_list.php");
  $msg="<span class='success'>Successfully Deleted </span>";
  echo $msg;
}
?>