PK

ADDRLIN : /home/anibklip/aaravpest.in/
FLL :
Current File : /home/anibklip/aaravpest.in/certificate_insert.php

<?php
//echo "<pre>"; print_r($_POST);echo "</pre>";
//die();

$formno = $_POST['formno'];
//echo "$_POST[sub_c] - $_POST[parent_cert] ";
if($_POST[sub_c]!="" && $_POST[parent_cert]!=""){
	$sql="SELECT * from certificates where parent_cert='$_POST[parent_cert]' order by sub_certno desc ";
	$result=mysql_query($sql) or die(mysql_error());
	if($row=mysql_fetch_array($result)){
		$sub_certno=$row[sub_certno]+1;
		//echo " sub_certno :".$sub_certno;
	}else{
		$sub_certno=1;
	}
}

// Form A
if(trim($formno)=="a"){
	//$certno=getColumn("certificates", "certypo", $formno, "certno", $orderby=" certno desc");
	if($formno=="a"){
		$q="select certno from certificates where certypo='a' or certypo='b' or certypo='c' order by certno desc ";
	}else{
		$q="select certno from certificates where certypo='d' or certypo='e' order by certno desc ";
	}
	$q=mysql_query($q) or die(mysql_error());
	if($r=mysql_fetch_array($q)){
		$certno=$r[0];
	}else{
		if(trim($formno)=="a"){
			$certno=5014;
		}elseif(trim($formno)=="d"){
			$certno=5014;
		}
		$certno=0;
	}
	$certno=$certno+1;
	
	$fields=" certificates set 
		issuedate				= '$_POST[issuedate]',
		desgood					= '$_POST[desgood]',               
		quantitydeclared		= '$_POST[quantitydeclared]',     
		distmarks				= '$_POST[distmarks]',            
		conslinkno				= '$_POST[conslinkno]',           
		portcountry				= '$_POST[portcountry]',          
		nameship				= '$_POST[nameship]',             
		countrydes				= '$_POST[countrydes]',           
		declentry				= '$_POST[declentry]',            
		nameaddress				= '$_POST[clntid]',               
		declarednameaddress		= '$_POST[clntid2]',              
		namefumigant			= '$_POST[namefumigant]',         
		datefumigantion			= '$_POST[datefumigantion]',      
		placefumigantion		= '$_POST[placefumigantion]',     
		dosagefumigant			= '$_POST[dosagefumigant]',       
		durationfumigantion		= '$_POST[durationfumigantion]',  
		airtemp					= '$_POST[airtemp]',              
		contype					= '$_POST[contype]',              
		presstest				= 'N-A',                          
		airspace				= 'N-A',                          
		discharge				= '$_POST[discharge]',            
		enclosure				= '$_POST[enclosure]',            
		commodity				= '$_POST[commodity]',            
		consignment				= '$_POST[consignment]',          
		wrapping				= '$_POST[wrapping]',             
		perforated				= '$_POST[perforated]',           
		height					= '$_POST[height]',               
		cstatus					= '0',                            
		ctime					= '$din',                         
		decla					= '$_POST[deck]',                 
		clnid					= '$_POST[clntid]',               
		ajtid					= '$_POST[ajtname]',              
		licetype				= '$_POST[dtype]',                
		certypo					= '$_POST[formno]',               
		sub_c					= '$sub_c',                       
		cancel_reason			= '0',                            
		consignment_link		= '$_POST[consignment_link]',     
		container20feet			= '$_POST[container20feet]',      
		container40feet			= '$_POST[container40feet]',      
		container40HC			= '$_POST[container40HC]',        
		containerLCL			= '$_POST[containerLCL]',         
		days					= '$_POST[days]',                 
		fumigation_conduct		=  '$_POST[fumigation_conduct]',
		cont_pressure		=  '$_POST[cont_pressure]',
		cont_airspace		=  '$_POST[cont_airspace]'
	";
	
	if($_POST[cert_id]){
		$sql="update $fields where certificateno='$_POST[cert_id]' ";
		$msg="Certificate Updated Sucessfully ";
	}else{
		$sql="INSERT INTO $fields, user_id='$_SESSION[user_id]', certno='$certno', sub_certno='$sub_certno', parent_cert='$_POST[parent_cert]' ";
		$msg="New Entry Sucessfully Entered";
	}
}
// Form B
elseif(trim($formno)=="b" || trim($formno)=="d"){		//AUS
	/*//$certno=getColumn("certificates", "certypo", $formno, "certno", $orderby=" certno desc");
	$q="select certno from certificates where certypo='a' or certypo='b' or certypo='c' order by certno desc ";
	$q=mysql_query($q) or die(mysql_error());
	if($r=mysql_fetch_array($q)){
		$certno=$r[0];
	}else{
		$certno=163;
	}*/

	if($formno=="b"){
		$q="select certno from certificates where certypo='a' or certypo='b' or certypo='c' order by certno desc ";
	}else{
		$q="select certno from certificates where certypo='d' or certypo='e' order by certno desc ";
	}
	$q=mysql_query($q) or die(mysql_error());
	if($r=mysql_fetch_array($q)){
		$certno=$r[0];
	}else{
		if(trim($formno)=="b"){
			$certno=0;
		}elseif(trim($formno)=="d"){
			$certno=0;
		}
	}

	$certno=$certno+1;

	// Insert Certificate

	$fields=" certificates set 
		issuedate='".$_POST['issuedate']."',
		desgood='".$_POST['desgood']."',
		quantitydeclared='".$_POST['quantitydeclared']."',
		portcountry='".$_POST['portcountry']."',
		conslinkno='".$_POST['conslinkno']."',
		countrydes='".$_POST['countrydes']."',
		declentry='".$_POST['declentry']."',
		nameaddress='".$_POST['clntid']."',
		declarednameaddress='".$_POST['clntid2']."',
		namefumigant='".$_POST['namefumigant']."',
		datefumigantion='".$_POST['datefumigantion']."',
		placefumigantion='".$_POST['placefumigantion']."',
		dosagefumigant='".$_POST['dosagefumigant']."',
		durationfumigantion='".$_POST['durationfumigantion']."',
		airtemp='".$_POST['airtemp']."',
		contype='".$_POST['contype']."',
		presstest='".$_POST['presstest']."',
		airspace='".$_POST['airspace']."',
		discharge='".$_POST['discharge']."',
		enclosure='".$_POST['enclosure']."',
		commodity='".$_POST['commodity']."',
		consignment='".$_POST['consignment']."',
		wrapping='".$_POST['wrapping']."',
		perforated='".$_POST['perforated']."',
		height='".$_POST['height']."',
		cstatus='0',
		ctime='".$din."',
		decla='".$deckl."',
		clnid='".$_POST['clntid']."',
		ajtid='".$_POST['ajtname']."',
		licetype='".$_POST['dtype']."',
		certypo='".$_POST['formno']."',
		sub_c='$sub_c',
		cancel_reason='0',
		distmarks='$_POST[distmarks]',
		container20feet='$_POST[container20feet]',
		container40feet='$_POST[container40feet]',
		container40HC='$_POST[container40HC]',
		containerLCL='$_POST[containerLCL]',
		days='$_POST[days]'
	";

	if($_POST[cert_id]){
		$sql="update $fields where certificateno='$_POST[cert_id]' ";
		//echo "<pre>$sql</pre>";
		$msg="Certificate Updated Sucessfully ";
	}else{
		$sql="INSERT INTO $fields, user_id='$_SESSION[user_id]', certno='$certno', sub_certno='$sub_certno', parent_cert='$_POST[parent_cert]' ";
		$msg="New Entry Sucessfully Entered";
	}
	//echo "<pre>$sql</pre>";
}
// Form C
elseif(trim($formno)=="c" || trim($formno)=="e"){
	// Insert Certificate	PPQ
	//$certno=getColumn("certificates", "certypo", $formno, "certno", $orderby=" certno desc");
	if($formno=="c"){
		$q="select certno from certificates where certypo='a' or certypo='b' or certypo='c' order by certno desc ";
	}else{
		$q="select certno from certificates where certypo='d' or certypo='e' order by certno desc ";
	}
	$q=mysql_query($q) or die(mysql_error());
	if($r=mysql_fetch_array($q)){
		$certno=$r[0];
	}else{
		if(trim($formno)=="c"){
			$certno=5014;
		}elseif(trim($formno)=="e"){
			$certno=5014;
		}
	}
	$certno=$certno+1;
	//echo "$certno sssssssssssssssss";

	$fields=" certificates set 
		issuedate=  '$_POST[issuedate]', 
		desgood=  '$_POST[desgood]', 
		quantitydeclared=  '$_POST[quantitydeclared]', 
		distmarks=  '$_POST[distmarks]', 
		conslinkno=  '$_POST[conslinkno]', 
		portcountry=  '$_POST[portcountry]', 
		nameship=  '$_POST[nameship]', 
		countrydes=  '$_POST[countrydes]', 
		declentry=  '$_POST[declentry]', 
		nameaddress=  '$_POST[clntid]', 
		declarednameaddress= '$_POST[clntid2]', 
		namefumigant=  '$_POST[namefumigant]', 
		datefumigantion= '$_POST[datefumigantion]', 
		placefumigantion= '$_POST[placefumigantion]', 
		dosagefumigant=  '$_POST[dosagefumigant]', 
		durationfumigantion= '$_POST[durationfumigantion]', 
		airtemp=  '$_POST[airtemp]', 
		contype=  '$_POST[contype]', 
		presstest=  'N-A', 
		airspace=  'N-A', 
		discharge=  '$_POST[discharge]', 
		enclosure=  '$_POST[enclosure]', 
		commodity=  '$_POST[commodity]', 
		consignment=  '$_POST[consignment]', 
		wrapping=  '$_POST[wrapping]', 
		perforated=  '$_POST[perforated]', 
		height=   '$_POST[height]', 
		cstatus=  '0', 
		ctime=   '$din', 
		decla=   '$_POST[deck]', 
		clnid=   '$_POST[clntid]', 
		ajtid=   '$_POST[ajtname]', 
		licetype=  '$_POST[dtype]', 
		certypo=  '$_POST[formno]', 
		sub_c=   '$sub_c', 
		cancel_reason=  '0', 
		consignment_link= '$_POST[consignment_link]', 
		container20feet= '$_POST[container20feet]', 
		container40feet= '$_POST[container40feet]', 
		container40HC=  '$_POST[container40HC]', 
		containerLCL=  '$_POST[containerLCL]', 
		days=   '$_POST[days]', 
		fumigation_conduct='$_POST[fumigation_conduct]',
		cont_pressure		=  '$_POST[cont_pressure]',
		cont_airspace		=  '$_POST[cont_airspace]'
	";

	if($_POST[cert_id]){
		$sql="update $fields where certificateno='$_POST[cert_id]' ";
		$msg="Certificate Updated Sucessfully ";
	}else{
		$sql="INSERT INTO $fields, user_id='$_SESSION[user_id]', certno='$certno', sub_certno='$sub_certno', parent_cert='$_POST[parent_cert]' ";
		$msg="New Entry Sucessfully Entered";
	}
}else{
	print "Something wrong with Form Type";
}

//echo "<pre>"; print_r($_POST);echo "</pre>";
// Lets Insert Now.

//echo "formno: $formno <pre>$sql</pre>";
$result=mysql_query($sql) or die(mysql_error().'<br><br>Error in creating Certificate');
if($_POST[cert_id]){
	$certificateno=$_POST[cert_id];
}else{
	$certificateno=mysql_insert_id();
}
print "no=".$certificateno."<br />";
?>


PK 99