
PK 
<?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;
}
}else{
$sub_certno=0;
}
if(!$_POST[consignment_details_shw]){
$_POST[consignment_details_shw]=0;
}
if(!$_POST[days]){
$_POST[days]=0;
}
if(!$_POST[sub_c]){
$_POST[sub_c]=0;
}
if(!$_POST[parent_cert]){
$_POST[parent_cert]=0;
}
if(!$_POST[shiper_containerno_shw]){
$_POST[shiper_containerno_shw]=0;
}
if(!$_POST[date_start]){
$_POST[date_start]="0000-00-00";
}
// Form A
if(trim($formno)=="a" || trim($formno)=="d"){ // NSPM & BK
//$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') and parent_cert=0 order by certno desc ";
$q="select certno from certificates where (certypo='a' or certypo='b') and parent_cert=0 order by certno desc ";
}else{
$q="select certno from certificates where certypo='d' order by certno desc "; // certypo='e' or
}
//echo $q;
$q=mysql_query($q) or die(mysql_error());
if($r=mysql_fetch_array($q)){
$certno=$r[0];
}else{
if(trim($formno)=="a"){
$certno=0;
}elseif(trim($formno)=="d"){
$certno=0;
}
}
$certno=$certno+1;
if($_POST[parent_cert]){
$certno=getColumn("certificates", "certificateno", $_POST[parent_cert], "certno", $orderby=" certno desc");
}
//die($certno);
$din=date('D, d M Y + H:i:s a');
$fields="certificates set
issuedate= '$_POST[issuedate]',
namefumigant= '$_POST[namefumigant]',
dosagefumigant= '$_POST[dosagefumigant]',
datefumigantion= '$_POST[datefumigantion]',
fumi_completed= '$_POST[fumi_completed]',
durationfumigantion= '$_POST[durationfumigantion]',
airtemp= '$_POST[airtemp]',
declentry= '$_POST[declentry]',
contype= '$_POST[desc]',
airspace= '$_POST[airspace]',
conslinkno= '$_POST[conslinkno]',
portcountry= '$_POST[port]',
nameship= '$_POST[vessal]',
nameaddress= '$_POST[clntid]',
declarednameaddress='$_POST[clntid2]',
consignment= '$_POST[contype]',
quantitydeclared= '$_POST[quantitydeclared]',
desgood= '$_POST[packing]',
brand= '$_POST[brand]',
distmarks= '$_POST[distmarks]',
clnid= '$_POST[clntid]',
licetype= '$_POST[dtype]',
certypo= '$_POST[formno]',
ajtid= '$_POST[ajtname]',
ctime= '$din',
placefumigantion= '$_POST[placefumigantion]',
presstest= '$_POST[gsheet]',
gas_tight_value= '$_POST[gas_tight_value]',
decla= '$_POST[decla]',
country= '$_POST[country]',
shiper_containerno= '$_POST[shiper_containerno]',
shiper_containerno_shw= '$_POST[shiper_containerno_shw]',
consignment_details_shw= '$_POST[consignment_details_shw]',
consignment_details='$_POST[consignment_details]'
";
//$sql="INSERT INTO $fields";
if($_POST[cert_id]){
$sql="update $fields where certificateno='$_POST[cert_id]' ";
$msg="Certificate Updated Sucessfully ";
}else{
$sql="INSERT INTO $fields, certno='$certno', sub_certno='$sub_certno', parent_cert='$_POST[parent_cert]' ";
$msg="New Entry Sucessfully Entered";
}
//echo "<pre>$sql</pre>";
//die("");
}
// Form B
elseif(trim($formno)=="b"){ //AUS
if($formno=="b"){
$q="select certno from certificates where certypo='a' or certypo='b' order by certno desc "; //or certypo='c'
}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{
$certno=0;
}
$certno=$certno+1;
if($_POST[parent_cert]){
$certno=getColumn("certificates", "certificateno", $_POST[parent_cert], "certno", $orderby=" certno desc");
}
//die($certno);
// 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']."',
date_start='".$_POST['date_start']."',
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, 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"){ // ALP & BK
// Insert Certificate ALP
//$certno=getColumn("certificates", "certypo", $formno, "certno", $orderby=" certno desc");
if($formno=="c"){
$q="select certno from certificates where certypo='c' order by certno desc "; //certypo='a' or certypo='b' or
}else{
$q="select certno from certificates where certypo='e' order by certno desc "; //certypo='d' or
}
$q=mysql_query($q) or die(mysql_error());
if($r=mysql_fetch_array($q)){
$certno=$r[0];
}else{
if(trim($formno)=="c"){
$certno=0;
}elseif(trim($formno)=="e"){
$certno=0;
}
}
$certno=$certno+1;
//echo "$certno sssssssssssssssss";
if($_POST[parent_cert]){
$certno=getColumn("certificates", "certificateno", $_POST[parent_cert], "certno", $orderby=" certno desc");
}
//die($certno);
$din=date('D, d M Y + H:i:s a');
$fields="certificates set
issuedate= '$_POST[issuedate]',
namefumigant= '$_POST[namefumigant]',
dosagefumigant= '$_POST[dosagefumigant]',
datefumigantion= '$_POST[datefumigantion]',
fumi_completed= '$_POST[fumi_completed]',
durationfumigantion= '$_POST[durationfumigantion]',
airtemp= '$_POST[airtemp]',
declentry= '$_POST[declentry]',
contype= '$_POST[desc]',
airspace= '$_POST[airspace]',
conslinkno= '$_POST[conslinkno]',
portcountry= '$_POST[port]',
nameship= '$_POST[vessal]',
nameaddress= '$_POST[clntid]',
declarednameaddress='$_POST[clntid2]',
consignment= '$_POST[contype]',
quantitydeclared= '$_POST[quantitydeclared]',
desgood= '$_POST[packing]',
brand= '$_POST[brand]',
distmarks= '$_POST[distmarks]',
clnid= '$_POST[clntid]',
licetype= '$_POST[dtype]',
certypo= '$_POST[formno]',
ajtid= '$_POST[ajtname]',
ctime= '$din',
placefumigantion= '$_POST[placefumigantion]',
presstest= '$_POST[gsheet]',
gas_tight_value= '$_POST[gas_tight_value]',
decla= '$_POST[decla]',
country= '$_POST[country]',
shiper_containerno= '$_POST[shiper_containerno]',
shiper_containerno_shw= '$_POST[shiper_containerno_shw]',
consignment_details_shw= '$_POST[consignment_details_shw]',
consignment_details='$_POST[consignment_details]'
";
if($_POST[cert_id]){
$sql="update $fields where certificateno='$_POST[cert_id]' ";
$msg="Certificate Updated Sucessfully ";
}else{
$sql="INSERT INTO $fields, 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