PK

ADDRLIN : /home/anibklip/aaravpest.in/2025-26/
FLL :
Current File : /home/anibklip/aaravpest.in/2025-26/xxcertificate_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;
    }
} 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;
}

//echo "formno: $formno <br>";
// Form A
if (trim($formno) == "f") {
    //$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' or certypo='f' 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 = 0;
        } elseif (trim($formno) == "d") {
            $certno = 0;
        }
        $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]'
    // 	";

    $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, 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
    if ($_SESSION[user_id] == 2) {
        if ($formno == "b") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='b' order by certno desc ";
        }
    } else {
        if ($formno == "b") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='b' order by certno desc ";
        } else {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='a' or  order by certno desc ";
        }
    }
    //echo "$q <br>";
    $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) == "b") {
            $certno = 0;
        }
    }
    if ($certno < 0) {
        $certno = $certno + 1;
    }

    $certno = $certno + 1;
    echo "certno: $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'] . "',
		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 h
elseif(trim($formno)=="h"){		// AUS NEW
    if ($_SESSION['user_id'] == 2) {
        if ($formno == "h") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and (certypo='h' or certypo='b') order by certno desc ";
        }
    } else {
        if ($formno == "h") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and (certypo='h' or certypo='b') order by certno desc ";
        } else {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='a' or  order by certno desc ";
        }
    }
    // echo "$q <br>";

    /* if($formno=="h"){
		$q="SELECT certno from certificates where certypo='a' or certypo='b' or certypo='h' or certypo='c' or certypo='f' order by certno desc ";
	}else{
		$q="SELECT certno from certificates where (certypo='d' or certypo='e' or certypo='g') order by certno desc ";
	} */
	// $q="SELECT certno from certificates where certypo='b' or certypo='h' order by certno desc ";
	$q=mysql_query($q) or die(mysql_error());
	if($r=mysql_fetch_array($q)){
		$certno=$r[0];
	}
	$certno=$certno+1;
    // echo "<br>$certno";//die;

	if($_POST['parent_cert']){
		$certno=getColumn("certificates", "certificateno", $_POST['parent_cert'], "certno", $orderby=" certno desc");
	}

    if($_POST['desgood']){
        $desgood = implode(",", $_POST['desgood']);
    }else{
        $desgood = "";
    }

	$fields=" certificates set 
		certypo						= '".$_POST['formno']."',
		sub_c						= '$sub_c',
		issuedate					= '".$_POST['issuedate']."',
		enclosure_type				= '".$_POST['enclosure_type']."',
		enclosure_type_others	    = '".$_POST['enclosure_type_others']."',
		dosagefumigant_trmnt		= '".$_POST['dosagefumigant_trmnt']."',
		durationfumigantion_trmnt	= '".$_POST['durationfumigantion_trmnt']."',
		airtemp_trmnt				= '".$_POST['airtemp_trmnt']."',
		streetaddress_trmnt			= '".$_POST['streetaddress_trmnt']."',
		city_trmnt					= '".$_POST['city_trmnt']."',
		country_trmnt				= '".$_POST['country_trmnt']."',
		postcode_trmnt				= '".$_POST['postcode_trmnt']."',
		datefumigantion_start		= '".$_POST['datefumigantion_start']."',
		timefumigantion_start		= '".$_POST['timefumigantion_start']."',
		datefumigantion_end			= '".$_POST['datefumigantion_end']."',
		timefumigantion_end			= '".$_POST['timefumigantion_end']."',
		seal_no			            = '".$_POST['seal_no']."',

		desgood						= '".$desgood."',
		desgood_others		    	= '".$_POST['desgood_others']."',
		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']."',
		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>"; print_r($_POST);echo "</pre>";
	// echo "<pre>$sql</pre>";die();
}
// Form C
elseif (trim($formno) == "c" || trim($formno) == "e") {
    // Insert Certificate	PPQ
    if ($_SESSION['user_id'] == 2 || $_SESSION['user_id'] == 11) {
        if ($formno == "c") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='c' order by certno desc ";
        } else {
            $q = "SELECT certno from certificates where (user_id='11' or user_id='2')  and certypo='e' order by certno desc ";
        }
    } else {
        if ($formno == "c") {
            $q = "SELECT certno from certificates where user_id='$_SESSION[user_id]' and certypo='c' order by certno desc ";
        } else {
            $q = "SELECT certno from certificates where (user_id='11' or user_id='2') and (certypo='c' or certypo='e') order by certno desc ";
        }
    }
	// echo "$q <br>";

	$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;
        }
    }
    if ($certno < 0) {
        $certno = $certno + 1;
    }

    $certno = $certno + 1;

	// echo "certno: $certno "; die;

    $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>aaa Error in creating Certificate');
if ($_POST[cert_id]) {
    $certificateno = $_POST[cert_id];
} else {
    $certificateno = mysql_insert_id();
}
// print "no=".$certificateno."<br />";


PK 99