<?php
include_once("../../connection/setting_jaldhi_class.php");
include_once("../../../../connection/setting_jaldhi_class.php");

class data
{
var $var_1;
var $var_2;
var $var_3;
var $var_4;
var $var_5;
var $var_6;
var $var_7;
var $var_8;
var $var_9;
var $var_10;
var $var_11;
var $var_12;
var $var_13;
var $var_14;
var $var_15;
var $var_16;
var $var_17;
var $var_18;
var $var_19;
var $var_20;
var $var_21;
var $var_22;
var $var_23;
var $var_24;
var $var_25;
var $var_26;
var $var_27;
var $var_28;
var $var_29;
var $var_30;
var $var_31;
var $var_32;
var $var_33;
var $var_34;
var $var_35;
var $var_36;
var $var_37;
var $var_38;
var $var_39;
var $var_40;
var $var_41;
var $var_42;
var $var_43;
var $var_44;
var $var_45;
var $var_46;
var $var_47;
var $var_48;
var $var_49;
var $var_50;
var $var_51;
var $var_52;
var $var_53;
var $var_54;
var $var_55;
var $var_56;
var $var_57;
var $var_58;
var $var_59;
var $var_60;
var $var_61;
var $var_62;
var $var_63;
var $var_64;
var $var_65;
var $var_66;
var $var_67;
var $var_68;
var $var_69;
var $var_70;
var $var_71;
var $var_72;
var $var_73;
var $var_74;
var $var_75;
var $var_76;
var $var_77;
var $var_78;
var $var_79;
var $var_80;
var $var_81;
var $var_82;
var $var_83;
var $var_84;
var $var_85;
var $var_86;
var $var_87;
var $var_88;
var $var_90;
var $var_91;
var $var_92;
var $var_93;
var $var_94;
var $var_95;
var $var_96;
var $var_97;
var $var_98;
var $var_99;
var $var_100;
var $var_101;
var $var_102;
var $var_103;
var $var_104;
var $var_105;
var $var_106;
var $var_107;
var $var_108;
var $var_109;
var $var_110;
var $var_111;
var $var_112;
var $var_113;
var $var_114;
var $var_115;
var $var_116;
var $var_117;
var $var_118;
var $var_119;
var $var_120;
var $var_121;
var $var_122;
var $var_123;
var $var_124;
var $var_125;
var $var_126;
var $var_127;
var $var_128;
var $var_129;
var $var_130;
var $var_131;
var $var_132;
var $var_133;
var $var_134;
var $var_135;
var $var_136;
var $var_137;
var $var_138;
var $var_139;
var $var_140;
var $var_141;
var $var_142;
var $var_143;
var $var_144;
var $var_145;
var $var_146;
var $var_147;
var $var_148;
var $var_149;
var $var_150;
var $var_151;
var $var_152;
var $var_153;
var $var_154;
var $var_155;
var $var_156;
var $var_157;
var $var_158;
var $var_159;
var $var_160;
var $var_161;
var $var_162;
var $var_163;
var $var_164;
var $var_165;
var $var_166;
var $var_167;
var $var_168;
var $var_169;
var $var_170;
var $var_171;
var $var_172;
var $var_173;
var $var_174;
var $var_175;
var $var_176;
var $var_177;
var $var_178;
var $var_179;
var $var_180;
var $var_181;
var $var_182;
var $var_183;
var $var_184;
var $var_185;
var $var_186;
var $var_187;
var $var_188;
var $var_189;
var $var_190;
var $var_191;
var $var_192;
var $var_193;
var $var_194;
var $var_195;
var $var_196;
var $var_197;
var $var_198;
var $var_199;
var $var_200;
var $var_201;
var $var_202;
var $var_203;
var $var_204;
var $var_205;
var $var_206;
var $var_207;
var $var_208;
var $var_209;
var $var_210;
var $var_211;
var $var_212;
var $var_213;
var $var_214;
var $var_215;
var $var_216;
var $var_217;
var $var_218;
var $var_219;
var $var_220;
var $var_221;
var $var_222;
var $var_223;
var $var_224;
var $var_225;
var $var_226;
var $var_227;
var $var_228;
var $var_229;
var $var_230;
var $var_231;
var $var_232;
var $var_233;
var $var_234;
var $var_235;
var $var_236;
var $var_237;
var $var_238;
var $var_239;
var $var_240;
var $var_241;
var $var_242;
var $var_243;
var $var_244;
var $var_245;
var $var_246;
var $var_247;
var $var_248;
var $var_249;
var $var_250;
var $var_251;
var $var_252;
var $var_253;
var $var_254;
var $var_255;
var $var_256;
var $var_257;
var $var_258;
var $var_259;
var $var_260;
var $var_261;
var $var_262;
var $var_263;
var $var_264;
var $var_265;
var $var_266;
var $var_267;
var $var_268;
var $var_269;
var $var_270;
var $var_271;
var $var_272;
var $var_273;
var $var_274;
var $var_275;
var $var_276;
var $var_277;
var $var_278;
var $var_279;
var $var_280;
var $var_281;
var $var_282;
var $var_283;
var $var_284;
var $var_285;
var $var_286;
var $var_287;
var $var_288;
var $var_289;
var $var_290;
var $var_291;
var $var_292;
var $var_293;
var $var_294;
var $var_295;
var $var_296;
var $var_297;
var $var_298;
var $var_299;
var $var_300;
var $var_301;
var $var_302;
var $var_303;
var $var_304;
var $var_305;
var $var_306;
var $var_307;
var $var_308;
var $var_309;
var $var_310;
var $var_311;
var $var_312;
var $var_313;
var $var_314;
var $var_315;
var $var_316;
var $var_317;
var $var_318;
var $var_319;
var $var_320;
var $var_321;
var $var_322;
var $var_323;
var $var_324;
var $var_325;
var $var_326;
var $var_327;
var $var_328;
var $var_329;
var $var_330;
var $var_331;
var $var_332;
var $var_333;
var $var_334;
var $var_335;
var $var_336;
var $var_337;
var $var_338;
var $var_339;
var $var_340;
var $var_341;
var $var_342;
var $var_343;
var $var_344;
var $var_345;
var $var_346;
var $var_347;
var $var_348;
var $var_349;
var $var_350;
var $var_351;
var $var_352;

function getFun1(){return $this->var_1;}
function getFun2(){return $this->var_2;}
function getFun3(){return $this->var_3;}
function getFun4(){return $this->var_4;}
function getFun5(){return $this->var_5;}
function getFun6(){return $this->var_6;}
function getFun7(){return $this->var_7;}
function getFun8(){return $this->var_8;}
function getFun9(){return $this->var_9;}
function getFun10(){return $this->var_10;}
function getFun11(){return $this->var_11;}
function getFun12(){return $this->var_12;}
function getFun13(){return $this->var_13;}
function getFun14(){return $this->var_14;}
function getFun15(){return $this->var_15;}
function getFun16(){return $this->var_16;}
function getFun17(){return $this->var_17;}
function getFun18(){return $this->var_18;}
function getFun19(){return $this->var_19;}
function getFun20(){return $this->var_20;}
function getFun21(){return $this->var_21;}
function getFun22(){return $this->var_22;}
function getFun23(){return $this->var_23;}
function getFun24(){return $this->var_24;}
function getFun25(){return $this->var_25;}
function getFun26(){return $this->var_26;}
function getFun27(){return $this->var_27;}
function getFun28(){return $this->var_28;}
function getFun29(){return $this->var_29;}
function getFun30(){return $this->var_30;}
function getFun31(){return $this->var_31;}
function getFun32(){return $this->var_32;}
function getFun33(){return $this->var_33;}
function getFun34(){return $this->var_34;}
function getFun35(){return $this->var_35;}
function getFun36(){return $this->var_36;}
function getFun37(){return $this->var_37;}
function getFun38(){return $this->var_38;}
function getFun39(){return $this->var_39;}
function getFun40(){return $this->var_40;}
function getFun41(){return $this->var_41;}
function getFun42(){return $this->var_42;}
function getFun43(){return $this->var_43;}
function getFun44(){return $this->var_44;}
function getFun45(){return $this->var_45;}
function getFun46(){return $this->var_46;}
function getFun47(){return $this->var_47;}
function getFun48(){return $this->var_48;}
function getFun49(){return $this->var_49;}
function getFun50(){return $this->var_50;}
function getFun51(){return $this->var_51;}
function getFun52(){return $this->var_52;}
function getFun53(){return $this->var_53;}
function getFun54(){return $this->var_54;}
function getFun55(){return $this->var_55;}
function getFun56(){return $this->var_56;}
function getFun57(){return $this->var_57;}
function getFun58(){return $this->var_58;}
function getFun59(){return $this->var_59;}
function getFun60(){return $this->var_60;}
function getFun61(){return $this->var_61;}
function getFun62(){return $this->var_62;}
function getFun63(){return $this->var_63;}
function getFun64(){return $this->var_64;}
function getFun65(){return $this->var_65;}
function getFun66(){return $this->var_66;}
function getFun67(){return $this->var_67;}
function getFun68(){return $this->var_68;}
function getFun69(){return $this->var_69;}
function getFun70(){return $this->var_70;}
function getFun71(){return $this->var_71;}
function getFun72(){return $this->var_72;}
function getFun73(){return $this->var_73;}
function getFun74(){return $this->var_74;}
function getFun75(){return $this->var_75;}
function getFun76(){return $this->var_76;}
function getFun77(){return $this->var_77;}
function getFun78(){return $this->var_78;}
function getFun79(){return $this->var_79;}
function getFun80(){return $this->var_80;}
function getFun81(){return $this->var_81;}
function getFun82(){return $this->var_82;}
function getFun83(){return $this->var_83;}
function getFun84(){return $this->var_84;}
function getFun85(){return $this->var_85;}
function getFun86(){return $this->var_86;}
function getFun87(){return $this->var_87;}
function getFun88(){return $this->var_88;}
function getFun89(){return $this->var_89;}
function getFun90(){return $this->var_90;}
function getFun91(){return $this->var_91;}
function getFun92(){return $this->var_92;}
function getFun93(){return $this->var_93;}
function getFun94(){return $this->var_94;}
function getFun95(){return $this->var_95;}
function getFun96(){return $this->var_96;}
function getFun97(){return $this->var_97;}
function getFun98(){return $this->var_98;}
function getFun99(){return $this->var_99;}
function getFun100(){return $this->var_100;}
function getFun101(){return $this->var_101;}
function getFun102(){return $this->var_102;}
function getFun103(){return $this->var_103;}
function getFun104(){return $this->var_104;}
function getFun105(){return $this->var_105;}
function getFun106(){return $this->var_106;}
function getFun107(){return $this->var_107;}
function getFun108(){return $this->var_108;}
function getFun109(){return $this->var_109;}
function getFun110(){return $this->var_110;}
function getFun111(){return $this->var_111;}
function getFun112(){return $this->var_112;}
function getFun113(){return $this->var_113;}
function getFun114(){return $this->var_114;}
function getFun115(){return $this->var_115;}
function getFun116(){return $this->var_116;}
function getFun117(){return $this->var_117;}
function getFun118(){return $this->var_118;}
function getFun119(){return $this->var_119;}
function getFun120(){return $this->var_120;}
function getFun121(){return $this->var_121;}
function getFun122(){return $this->var_122;}
function getFun123(){return $this->var_123;}
function getFun124(){return $this->var_124;}
function getFun125(){return $this->var_125;}
function getFun126(){return $this->var_126;}
function getFun127(){return $this->var_127;}
function getFun128(){return $this->var_128;}
function getFun129(){return $this->var_129;}
function getFun130(){return $this->var_130;}
function getFun131(){return $this->var_131;}
function getFun132(){return $this->var_132;}
function getFun133(){return $this->var_133;}
function getFun134(){return $this->var_134;}
function getFun135(){return $this->var_135;}
function getFun136(){return $this->var_136;}
function getFun137(){return $this->var_137;}
function getFun138(){return $this->var_138;}
function getFun139(){return $this->var_139;}
function getFun140(){return $this->var_140;}
function getFun141(){return $this->var_141;}
function getFun142(){return $this->var_142;}
function getFun143(){return $this->var_143;}
function getFun144(){return $this->var_144;}
function getFun145(){return $this->var_145;}
function getFun146(){return $this->var_146;}
function getFun147(){return $this->var_147;}
function getFun148(){return $this->var_148;}
function getFun149(){return $this->var_149;}
function getFun150(){return $this->var_150;}
function getFun151(){return $this->var_151;}
function getFun152(){return $this->var_152;}
function getFun153(){return $this->var_153;}
function getFun154(){return $this->var_154;}
function getFun155(){return $this->var_155;}
function getFun156(){return $this->var_156;}
function getFun157(){return $this->var_157;}
function getFun158(){return $this->var_158;}
function getFun159(){return $this->var_159;}
function getFun160(){return $this->var_160;}
function getFun161(){return $this->var_161;}
function getFun162(){return $this->var_162;}
function getFun163(){return $this->var_163;}
function getFun164(){return $this->var_164;}
function getFun165(){return $this->var_165;}
function getFun166(){return $this->var_166;}
function getFun167(){return $this->var_167;}
function getFun168(){return $this->var_168;}
function getFun169(){return $this->var_169;}
function getFun170(){return $this->var_170;}
function getFun171(){return $this->var_171;}
function getFun172(){return $this->var_172;}
function getFun173(){return $this->var_173;}
function getFun174(){return $this->var_174;}
function getFun175(){return $this->var_175;}
function getFun176(){return $this->var_176;}
function getFun177(){return $this->var_177;}
function getFun178(){return $this->var_178;}
function getFun179(){return $this->var_179;}
function getFun180(){return $this->var_180;}
function getFun181(){return $this->var_181;}
function getFun182(){return $this->var_182;}
function getFun183(){return $this->var_183;}
function getFun184(){return $this->var_184;}
function getFun185(){return $this->var_185;}
function getFun186(){return $this->var_186;}
function getFun187(){return $this->var_187;}
function getFun188(){return $this->var_188;}
function getFun189(){return $this->var_189;}
function getFun190(){return $this->var_190;}
function getFun191(){return $this->var_191;}
function getFun192(){return $this->var_192;}
function getFun193(){return $this->var_193;}
function getFun194(){return $this->var_194;}
function getFun195(){return $this->var_195;}
function getFun196(){return $this->var_196;}
function getFun197(){return $this->var_197;}
function getFun198(){return $this->var_198;}
function getFun199(){return $this->var_199;}
function getFun200(){return $this->var_200;}
function getFun201(){return $this->var_201;}
function getFun202(){return $this->var_202;}
function getFun203(){return $this->var_203;}
function getFun204(){return $this->var_204;}
function getFun205(){return $this->var_205;}
function getFun206(){return $this->var_206;}
function getFun207(){return $this->var_207;}
function getFun208(){return $this->var_208;}
function getFun209(){return $this->var_209;}
function getFun210(){return $this->var_210;}
function getFun211(){return $this->var_211;}
function getFun212(){return $this->var_212;}
function getFun213(){return $this->var_213;}
function getFun214(){return $this->var_214;}
function getFun215(){return $this->var_215;}
function getFun216(){return $this->var_216;}
function getFun217(){return $this->var_217;}
function getFun218(){return $this->var_218;}
function getFun219(){return $this->var_219;}
function getFun220(){return $this->var_220;}
function getFun221(){return $this->var_221;}
function getFun222(){return $this->var_222;}
function getFun223(){return $this->var_223;}
function getFun224(){return $this->var_224;}
function getFun225(){return $this->var_225;}
function getFun226(){return $this->var_226;}
function getFun227(){return $this->var_227;}
function getFun228(){return $this->var_228;}
function getFun229(){return $this->var_229;}
function getFun230(){return $this->var_230;}
function getFun231(){return $this->var_231;}
function getFun232(){return $this->var_232;}
function getFun233(){return $this->var_233;}
function getFun234(){return $this->var_234;}
function getFun235(){return $this->var_235;}
function getFun236(){return $this->var_236;}
function getFun237(){return $this->var_237;}
function getFun238(){return $this->var_238;}
function getFun239(){return $this->var_239;}
function getFun240(){return $this->var_240;}
function getFun241(){return $this->var_241;}
function getFun242(){return $this->var_242;}
function getFun243(){return $this->var_243;}
function getFun244(){return $this->var_244;}
function getFun245(){return $this->var_245;}
function getFun246(){return $this->var_246;}
function getFun247(){return $this->var_247;}
function getFun248(){return $this->var_248;}
function getFun249(){return $this->var_249;}
function getFun250(){return $this->var_250;}
function getFun251(){return $this->var_251;}
function getFun252(){return $this->var_252;}
function getFun253(){return $this->var_253;}
function getFun254(){return $this->var_254;}
function getFun255(){return $this->var_255;}
function getFun256(){return $this->var_256;}
function getFun257(){return $this->var_257;}
function getFun258(){return $this->var_258;}
function getFun259(){return $this->var_259;}
function getFun260(){return $this->var_260;}
function getFun261(){return $this->var_261;}
function getFun262(){return $this->var_262;}
function getFun263(){return $this->var_263;}
function getFun264(){return $this->var_264;}
function getFun265(){return $this->var_265;}
function getFun266(){return $this->var_266;}
function getFun267(){return $this->var_267;}
function getFun268(){return $this->var_268;}
function getFun269(){return $this->var_269;}
function getFun270(){return $this->var_270;}
function getFun271(){return $this->var_271;}
function getFun272(){return $this->var_272;}
function getFun273(){return $this->var_273;}
function getFun274(){return $this->var_274;}
function getFun275(){return $this->var_275;}
function getFun276(){return $this->var_276;}
function getFun277(){return $this->var_277;}
function getFun278(){return $this->var_278;}
function getFun279(){return $this->var_279;}
function getFun280(){return $this->var_280;}
function getFun281(){return $this->var_281;}
function getFun282(){return $this->var_282;}
function getFun283(){return $this->var_283;}
function getFun284(){return $this->var_284;}
function getFun285(){return $this->var_285;}
function getFun286(){return $this->var_286;}
function getFun287(){return $this->var_287;}
function getFun288(){return $this->var_288;}
function getFun289(){return $this->var_289;}
function getFun290(){return $this->var_290;}
function getFun291(){return $this->var_291;}
function getFun292(){return $this->var_292;}
function getFun293(){return $this->var_293;}
function getFun294(){return $this->var_294;}
function getFun295(){return $this->var_295;}
function getFun296(){return $this->var_296;}
function getFun297(){return $this->var_297;}
function getFun298(){return $this->var_298;}
function getFun299(){return $this->var_299;}
function getFun300(){return $this->var_300;}
function getFun301(){return $this->var_301;}
function getFun302(){return $this->var_302;}
function getFun303(){return $this->var_303;}
function getFun304(){return $this->var_304;}
function getFun305(){return $this->var_305;}
function getFun306(){return $this->var_306;}
function getFun307(){return $this->var_307;}
function getFun308(){return $this->var_308;}
function getFun309(){return $this->var_309;}
function getFun310(){return $this->var_310;}
function getFun311(){return $this->var_311;}
function getFun312(){return $this->var_312;}
function getFun313(){return $this->var_313;}
function getFun314(){return $this->var_314;}
function getFun315(){return $this->var_315;}
function getFun316(){return $this->var_316;}
function getFun317(){return $this->var_317;}
function getFun318(){return $this->var_318;}
function getFun319(){return $this->var_319;}
function getFun320(){return $this->var_320;}
function getFun321(){return $this->var_321;}
function getFun322(){return $this->var_322;}
function getFun323(){return $this->var_323;}
function getFun324(){return $this->var_324;}
function getFun325(){return $this->var_325;}
function getFun326(){return $this->var_326;}
function getFun327(){return $this->var_327;}
function getFun328(){return $this->var_328;}
function getFun329(){return $this->var_329;}
function getFun330(){return $this->var_330;}
function getFun331(){return $this->var_331;}
function getFun332(){return $this->var_332;}
function getFun333(){return $this->var_333;}
function getFun334(){return $this->var_334;}
function getFun335(){return $this->var_335;}
function getFun336(){return $this->var_336;}
function getFun337(){return $this->var_337;}
function getFun338(){return $this->var_338;}
function getFun339(){return $this->var_339;}
function getFun340(){return $this->var_340;}
function getFun341(){return $this->var_341;}
function getFun342(){return $this->var_342;}
function getFun343(){return $this->var_343;}
function getFun344(){return $this->var_344;}
function getFun345(){return $this->var_345;}
function getFun346(){return $this->var_346;}
function getFun347(){return $this->var_347;}
function getFun348(){return $this->var_348;}
function getFun349(){return $this->var_349;}
function getFun350(){return $this->var_350;}
function getFun351(){return $this->var_351;}
function getFun352(){return $this->var_352;}
/*
* function used for connecting to the database
*/

function funConnect()
{	
  	$info = new clsSettings();  
	$admin_site_server	= $info->admin_site;
	$admin_site_user	= $info->admin_siteuser;				
	$admin_site_passwd	= $info->admin_sitepass;
	$admin_site_db		= $info->admin_sitedatabase;
	//mssql_get_last_message()
	$link = mysql_connect($admin_site_server, $admin_site_user, $admin_site_passwd)			
			or die ('I cannot connect to the database because: ' . mysql_error());
	
	/* checks to see if the connection actually works */ 			
	if (!$link)
	{ 
		$this->errno = 1; 
		return NULL; 
	}
	mysql_select_db($admin_site_db,$link) or die( "unable to select the database becoz of : " . mysql_error());	
	return $link;
}

function getLoginidWiseRecentFiveWorks()
{
	$connect = $this->funConnect();
	$sql = "select * from recent_work_master where LOGINID='".$_SESSION['uid']."' order by RECENT_WORKID desc limit 10";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$arr = array();
	if($rec > 0 )
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr[] = array("work" => $rows['WORK'] , "datetime" => date("d M Y H:i",strtotime($rows['WORK_DATE'])));
		}
		return $arr;
	}
	else
	{
		return $arr;
	}
}


function getCompanyNameBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from main_company where MCOMPANYID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCompareEstimateData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from freight_cost_estimete_master where COMID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getVesselIMOData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from vessel_imo_master where VESSEL_IMO_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getVesselOpenEntryDeta($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and OPENVESSEL_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getPortNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select PortName from port_master where PortId='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['PortName'];
}

function getAgencyLetterData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from generate_agency_letter where GEN_AGENCY_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getLoadPortCostData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from loadport_cost_master where GEN_AGENCY_ID='".$id."'"; 
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getLatestCostSheetID($comid)
{
	$connect = $this->funConnect();
	$sql = "select max(SHEET_NO) as max from freight_cost_analysis_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and FINAL_STATUS=1";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['max'];
}

function getVendorListNewBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from vendor_master where CODE='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function getCountryNameBasedOnID($id)
{
	$query = mysql_query("select COUNTRY_NAME from country_master where COUNTRYID='".$id."'");
	$rows = mysql_fetch_assoc($query);
	return $rows['COUNTRY_NAME'];
}

function getCountryData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from country_master where COUNTRYID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCountryArrayPortCostType()
{
	$sql = "select * from port_cost_type_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by NAME";
	$res = mysql_query($sql);
	$i = 1;$main_arr = array();
	while($rows = mysql_fetch_assoc($res))
	{
		if(!is_null($rows['COUNTRY_IDS']) && $rows['COUNTRY_IDS'] != "")
		{
			$c_arr = explode(",",$rows['COUNTRY_IDS']);
			$main_arr = array_merge($main_arr,$c_arr);
		}
	}
	$main_arr = array_unique($main_arr);
	sort($main_arr);
	return $main_arr;
}

function getLoadPortCostSlaveData($id,$port_costid,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from loadport_cost_slave where LP_COST_ID='".$id."' and PC_TYPE_ID='".$port_costid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getPortCostsBasedOnCountryID($countryid)
{
	$connect = $this->funConnect();
	
	$coaid = $this->getCompareEstimateData($_SESSION['comid'],'COAID');
	if($coaid!='')
	{
		$sqlcoa = "select * from coa_master where COAID='".$coaid."'";
		$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
		$rowscoa   = mysql_fetch_assoc($resultcoa);
		$currency = $rowscoa['CURRENCY'];
	}
	else
	{
		$currency = "USD";
	}
	
	$arr = array();
	if(in_array($countryid,$this->getCountryArrayPortCostType()))
	{ 
	echo '<div class="box-body table-responsive">';
	echo '<table id="" class="table table-bordered table-striped">';
	echo '<tr>';
	echo '<th width="25%" align="left" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Port Cost Type</th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">('.$currency.')</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">('.$currency.')</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Operator)</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Agent)</span></th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	$sql = "select * from port_cost_type_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by NAME";
	$res = mysql_query($sql);
	$i = 1;
	while($rows = mysql_fetch_assoc($res))
	{
		if(!is_null($rows['COUNTRY_IDS']) && $rows['COUNTRY_IDS'] != "")
		{
			$c_arr = explode(",",$rows['COUNTRY_IDS']);
			if(in_array($countryid,$c_arr))
			{
				$lp_costid = $this->getLoadPortCostData($_SESSION['uid'],"LP_COST_ID");
				
				echo '<tr>';
				echo '<td align="left">'.$rows['NAME'].'<input type="hidden" name="txtPortCostID_'.$i.'" id="txtPortCostID_'.$i.'" class="form-control" readonly="true" value="'.$rows['PC_TYPE_ID'].'" /></td>';
				if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 1)
				{
				echo '<td align="center"><input type="text" name="txtEstmdCost_'.$i.'" id="txtEstmdCost_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_LC").'" onkeyup="calculateEstmdCostUSD('.$i.');" /></td>';
				}
				else
				{
				echo '<td align="center"><input type="text" name="txtEstmdCost_'.$i.'" id="txtEstmdCost_'.$i.'" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_LC").'" onkeyup="calculateEstmdCostUSD('.$i.');" /></td>';
				}
				echo '<td align="center"><input type="text" name="txtEstmdCostUSD_'.$i.'" id="txtEstmdCostUSD_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_USD").'" onkeyup="calculateEstmdCostUSD('.$i.');"/></td>';
				echo '<td align="center"><input type="text" name="txtActualCost_'.$i.'" id="txtActualCost_'.$i.'" class="form-control"  readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_LC").'"/></td>';	
				echo '<td align="center"><input type="text" name="txtActualCostUSD_'.$i.'" id="txtActualCostUSD_'.$i.'" class="form-control"  readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_USD").'" /></td>';
				echo '<td align="center"><textarea class="form-control areasize" name="txtRemarksOperator_'.$i.'" id="txtRemarksOperator_'.$i.'" readonly="true" >'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_OPERATOR").'</textarea></td>';
				echo '<td align="center"><textarea class="form-control areasize" name="txtRemarksAgent_'.$i.'" id="txtRemarksAgent_'.$i.'">'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_AGENTS").'</textarea></td>';
				echo '</tr>';
				$i++;
			}
		}
	}
	echo '</tbody>';
	
	echo '<tfoot>';
	echo '<tr>';
	echo '<th align="left" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >TOTAL<input type="hidden" name="txtRec" id="txtRec" value="'.($i-1).'"/></th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCost" id="txtttlEstmdCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ESTMD_COST_LC").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCostUSD" id="txtttlEstmdCostUSD" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ESTMD_COST_USD").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCost" id="txtttlActualCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ACTUAL_COST_LC").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCostUSD" class="form-control" id="txtttlActualCostUSD" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ACTUAL_COST_USD").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" colspan="3">Advance Requested 1&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;">';
	if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 1){
	echo '<input type="text" name="txtAdvRequestedCost1" id="txtAdvRequestedCost1" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_1").'" placeholder="0.00" />';
	}else{
	echo '<input type="text" name="txtAdvRequestedCost1" id="txtAdvRequestedCost1" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_1").'" placeholder="0.00" />';
	}
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" colspan="3">Advance Requested 2&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;">';
	if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 1){
	echo '<input type="text" name="txtAdvRequestedCost2" id="txtAdvRequestedCost2" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_2").'" placeholder="0.00" />';
	}else{
	echo '<input type="text" name="txtAdvRequestedCost2" id="txtAdvRequestedCost2" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_2").'" placeholder="0.00" />';
	}
	
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '</tfoot>';
	
	echo '</table></div>';
	}
}

function getCheckNullValue($var){
	
	if($var == ""){
		return 0;
	}else{
		return $var;
	}
}

function insertLoadPortCostDetails()
{
	$connect = $this->funConnect();
	$upstatus 			          = addslashes(trim($_REQUEST['upstatus']));
	$date			   	     	  = date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$preparedby			          = addslashes(trim($_REQUEST['txtPreparedBy']));
	$bank_details	              = addslashes(trim($_REQUEST['txtBDetails']));
	$authorizedby	              = addslashes(trim($_REQUEST['txtAuthorizedBy']));
	
	
	$ttl_estmd_cost                = addslashes(trim($_REQUEST['txtttlEstmdCost']));
	$ttl_estmd_cost_usd	           = addslashes(trim($_REQUEST['txtttlEstmdCostUSD']));
	$ttl_actual_cost               = addslashes(trim($_REQUEST['txtttlActualCost']));
	$ttl_actual_cost_usd           = addslashes(trim($_REQUEST['txtttlActualCostUSD']));
	
	$adv_req1		               = addslashes(trim($_REQUEST['txtAdvRequestedCost1']));
	$adv_req2			           = addslashes(trim($_REQUEST['txtAdvRequestedCost2']));
	$e_rate	   			           = addslashes(trim($_REQUEST['txtERate']));
	
	$rdoExchange	               = addslashes(trim($_REQUEST['rdoExchange']));
	$txtAgentRemarks               = addslashes(trim($_REQUEST['txtAgentRemarks']));
	
	$txtCRM 				= addslashes(trim($_REQUEST['txtCRM']));
	$txtCRM1 				= addslashes(trim($_REQUEST['txtCRM1']));
	$name1 = implode(',',$this->getUploadName($_FILES['attach_file']));
	$upload = $this->getUpload($_FILES['attach_file']);
	$upload = implode(',',$upload);
	
	if($txtCRM != '' && $upload != ''){ $upload1 = $txtCRM.','.$upload;}
	else if($txtCRM == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRM != '' && $upload == ''){ $upload1 = $txtCRM;}
	
	if($txtCRM1 != '' && $name1 != ''){ $name2 = $txtCRM1.','.$name1;}
	else if($txtCRM1 == '' && $name1 != ''){ $name2 = $name1;}
	else if($txtCRM1 != '' && $name1 == ''){ $name2 = $txtCRM1;}
	
	$rec = $_REQUEST['txtRec'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$query = "select * from loadport_cost_master where GEN_AGENCY_ID='".$_SESSION['uid']."'";
	$qres = mysql_query($query);
	$qrec = mysql_num_rows($qres);
	//echo $qrec;die();
	if($qrec == 0)
	{
		$sql = "insert into loadport_cost_master (GEN_AGENCY_ID,DATE,EXCHANGE_RATE,TTL_ESTMD_COST_LC,TTL_ESTMD_COST_USD,TTL_ACTUAL_COST_LC,TTL_ACTUAL_COST_USD,ADV_REQUESTED_1,ADV_REQUESTED_2,BANK_DETAILS,PREPARED_BY,AUTHORIZED_BY, ATTACHMENTS, ATTACHMENTS_NAME, RDO_EXCHANGE, AGENT_REMARKS, STATUS) values ('".$this->getCheckNullValue($_SESSION['uid'])."','".$date."','".$this->getCheckNullValue($e_rate)."','".$this->getCheckNullValue($ttl_estmd_cost)."','".$this->getCheckNullValue($ttl_estmd_cost_usd)."','".$this->getCheckNullValue($ttl_actual_cost)."','".$this->getCheckNullValue($ttl_actual_cost_usd)."','".$this->getCheckNullValue($adv_req1)."','".$this->getCheckNullValue($adv_req2)."','".$bank_details."','".$preparedby."','".$authorizedby."', '".$upload1."', '".addslashes($name2)."', '".$rdoExchange."', '".$txtAgentRemarks."', '".$upstatus."')";
				
		mysql_query($sql,$connect) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(LP_COST_ID) as max from loadport_cost_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$max = $myrows['max'];
		
		for($i=1;$i<=$rec;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PC_TYPE_ID, ESTMD_COST_LC, ESTMD_COST_USD ,ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR, REMARKS_AGENTS) values ('".$max."','".$this->getCheckNullValue($_REQUEST['txtPortCostID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCostUSD_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCostUSD_'.$i])."','".addslashes(trim($_REQUEST['txtRemarksOperator_'.$i]))."','".addslashes(trim($_REQUEST['txtRemarksAgent_'.$i]))."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$max = $qrows['LP_COST_ID'];
		
		$sql = "update loadport_cost_master set DATE='".$date."', FINAL_EXCHANGE_RATE='".$this->getCheckNullValue($e_rate)."', TTL_ESTMD_COST_LC='".$this->getCheckNullValue($ttl_estmd_cost)."', TTL_ESTMD_COST_USD='".$this->getCheckNullValue($ttl_estmd_cost_usd)."', TTL_ACTUAL_COST_LC='".$this->getCheckNullValue($ttl_actual_cost)."', TTL_ACTUAL_COST_USD='".$this->getCheckNullValue($ttl_actual_cost_usd)."', ADV_REQUESTED_1='".$this->getCheckNullValue($adv_req1)."', ADV_REQUESTED_2='".$this->getCheckNullValue($adv_req2)."', BANK_DETAILS='".$bank_details."', PREPARED_BY='".$preparedby."', AUTHORIZED_BY='".$authorizedby."',  ATTACHMENTS='".$upload1."', ATTACHMENTS_NAME='".addslashes($name2)."', RDO_EXCHANGE='".$rdoExchange."', AGENT_REMARKS='".$txtAgentRemarks."', STATUS='".$upstatus."' where GEN_AGENCY_ID='".$_SESSION['uid']."' and LP_COST_ID='".$qrows['LP_COST_ID']."'";
		mysql_query($sql,$connect);
		mysql_query("commit");
		
		$delquery = "delete from loadport_cost_slave where LP_COST_ID='".$max."'";
		mysql_query($delquery,$connect);
		mysql_query("commit");		
		
		for($i=1;$i<=$rec;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PC_TYPE_ID, ESTMD_COST_LC, ESTMD_COST_USD ,ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR, REMARKS_AGENTS) values ('".$max."','".$this->getCheckNullValue($_REQUEST['txtPortCostID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCostUSD_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCostUSD_'.$i])."','".addslashes(trim($_REQUEST['txtRemarksOperator_'.$i]))."','".addslashes(trim($_REQUEST['txtRemarksAgent_'.$i]))."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	}
return $msg;
}

function getPDAPortCostsBasedOnCountryID($countryid)
{
	$connect = $this->funConnect();
	$arr = array();
	echo '<div class="box-body table-responsive">';
	echo '<table cellpadding="1" cellspacing="1" border="0" width="100%" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th width="25%" align="left" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Port Cost Type</th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Operator)</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Agent)</span></th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	$sql = "select * from port_cost_type_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by NAME";
	$res = mysql_query($sql);
	$i = 1;
	while($rows = mysql_fetch_assoc($res))
	{
		if(!is_null($rows['COUNTRY_IDS']) && $rows['COUNTRY_IDS'] != "")
		{
			$c_arr = explode(",",$rows['COUNTRY_IDS']);
			if(in_array($countryid,$c_arr))
			{
				$lp_costid = $this->getLoadPortCostData($_SESSION['uid'],"LP_COST_ID");
				echo '<tr>';
				echo '<td align="left">'.$rows['NAME'].'<input type="hidden" name="txtPortCostID_'.$i.'" id="txtPortCostID_'.$i.'" class="form-control" readonly="true" value="'.$rows['PC_TYPE_ID'].'" /></td>';
				echo '<td align="center"><input type="text" name="txtEstmdCost_'.$i.'" id="txtEstmdCost_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_LC").'" /></td>';
				echo '<td align="center" ><input type="text" name="txtEstmdCostUSD_'.$i.'" id="txtEstmdCostUSD_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_USD").'" /></td>';
				if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 2)
				{
				echo '<td align="center" ><input type="text" name="txtActualCost_'.$i.'" id="txtActualCost_'.$i.'" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_LC").'" onkeyup="calculateEstmdCostUSD('.$i.');"  /></td>';	
				}
				else
				{
				echo '<td align="center" ><input type="text" name="txtActualCost_'.$i.'" id="txtActualCost_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_LC").'" onkeyup="calculateEstmdCostUSD('.$i.');"/></td>';	
				}
				echo '<td align="center" ><input type="text" name="txtActualCostUSD_'.$i.'" id="txtActualCostUSD_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_USD").'" onkeyup="calculateEstmdCostUSD('.$i.');"/></td>';
				echo '<td align="center"><textarea class="form-control areasize" name="txtRemarksOperator_'.$i.'" id="txtRemarksOperator_'.$i.'" cols="12" rows="1" readonly="true" >'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_OPERATOR").'</textarea></td>';
				echo '<td align="center" ><textarea class="form-control areasize" name="txtRemarksAgent_'.$i.'" id="txtRemarksAgent_'.$i.'" cols="12" rows="1">'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_AGENTS").'</textarea></td>';
				echo '</tr>';
				$i++;
			}
		}
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '<tr>';
	echo '<th align="left" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >TOTAL<input type="hidden" name="txtRec" id="txtRec" value="'.($i-1).'"/></th>';
	echo '<th align="center" width="8%" valign="middle" class="input-text" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCost" id="txtttlEstmdCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ESTMD_COST_LC").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCostUSD" id="txtttlEstmdCostUSD" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ESTMD_COST_USD").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCost" id="txtttlActualCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ACTUAL_COST_LC").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCostUSD" id="txtttlActualCostUSD" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"TTL_ACTUAL_COST_USD").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;color:#fff;font-size:12px; color:#fff;" colspan="3">Advance Requested 1&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;color:#fff;font-size:10px;">';
	if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 1){
	echo '<input type="text" name="txtAdvRequestedCost1" id="txtAdvRequestedCost1" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_1").'" placeholder="0.00" />';
	}else{
	echo '<input type="text" name="txtAdvRequestedCost1" id="txtAdvRequestedCost1" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_1").'" placeholder="0.00" />';
	}
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;color:#fff;font-size:12px; color:#fff;" colspan="3">Advance Requested 2&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;color:#fff;font-size:10px;">';
	if($this->getLoadPortCostData($_SESSION['uid'],"STATUS") == 1){
	echo '<input type="text" name="txtAdvRequestedCost2" id="txtAdvRequestedCost2" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_2").'" placeholder="0.00" />';
	}else{
	echo '<input type="text" name="txtAdvRequestedCost2" id="txtAdvRequestedCost2" class="form-control" autocomplete="off" value="'.$this->getLoadPortCostData($_SESSION['uid'],"ADV_REQUESTED_2").'" placeholder="0.00" />';
	}
	
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '</tfoot>';
	echo '</table>';
	echo '</div>';
}

function getSOFdata($comid,$port,$portid,$serialno,$field)
{
	$connect 				= $this->funConnect();	
	$sql1 = "select ".$field." from sof_master where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."'";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	return $rows1[$field];
}

function insertPreArrivalDetails()
{
	$connect = $this->funConnect();
	
	$comid          	= $_REQUEST['comid'];
	$tabid		          	= $_REQUEST['txttabid'][0];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$serialno		        = $_REQUEST['txtSerialno_'.$tabid];
	$submitid		        = addslashes(trim($_REQUEST['txtsubmitid_'.$tabid]));
	
	$txtcheckbox	        = addslashes(trim($_REQUEST['txtcheckbox_'.$tabid]));
	$txtPA_1	        	= addslashes(trim($_REQUEST['txtPA_1_'.$tabid]));
	$txtPA_2	        	= addslashes(trim($_REQUEST['txtPA_2_'.$tabid]));
	$txtPA_3	        	= addslashes(trim($_REQUEST['txtPA_3_'.$tabid]));
	
	$txtETA_1	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_1_'.$tabid]));
	$txtETA_2	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_2_'.$tabid]));
	$txtETA_3	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_3_'.$tabid]));
	$txtETA_4	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_4_'.$tabid]));
	$txtETA_5	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_5_'.$tabid]));
	
	$txtETA_6	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_6_'.$tabid]));
	$txtETA_7	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_7_'.$tabid]));
	$txtETA_8	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_8_'.$tabid]));
	$txtETA_9	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_9_'.$tabid]));
	$txtETA_10	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_10_'.$tabid]));
	$txtETA_11	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_11_'.$tabid]));
	$txtETA_12	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_12_'.$tabid]));
	
	$txtTBID12	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtTBID12_'.$tabid]));
	
	$msg = 2;
	
	$sql = "select * from sof_slave_4 where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql1 = "insert into sof_slave_4 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, CARGO_DECL, STOW_PLAN_QTY, SP_DEPT_DRAFT, SP_ARR_DRAFT, ETA_30_DAYS, ETA_25_DAYS, ETA_20_DAYS, ETA_15_DAYS, ETA_10_DAYS, ETA_7_DAYS, ETA_5_DAYS, ETA_3_DAYS, ETA_2_DAYS, ETA_1_DAYS, ACTUAL_ARRIVAL, NOR_TENDERED, RANDOMID) values ('".$comid."', 'AGENT', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".$this->getCheckNullValue($txtcheckbox)."', '".$this->getCheckNullValue($txtPA_1)."', '".$txtPA_2."', '".$txtPA_3."', '".$txtETA_1."', '".$txtETA_2."', '".$txtETA_3."', '".$txtETA_4."', '".$txtETA_5."', '".$txtETA_6."', '".$txtETA_7."', '".$txtETA_8."', '".$txtETA_9."', '".$txtETA_10."', '".$txtETA_11."', '".$txtETA_12."', '".$serialno."')";
		mysql_query($sql1);
		
		for($i=1;$i<=$txtTBID12;$i++)
		{
			if(addslashes(trim($_REQUEST['txtDate12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtETCD12_'.$tabid.'_'.$i])) != '')
			{
				$sql2 = "insert into sof_slave_5 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, PRE_DATE, ENGAGEMENT_QTY, LOAD_LAST, TTL_LOAD, BALANCE, ETCD, RANDOMID) values ('".$comid."', 'AGENT', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".date("Y-m-d",strtotime($_REQUEST['txtDate12_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtETCD12_'.$tabid.'_'.$i]))."', '".$serialno."')";
				mysql_query($sql2);
			}
		}
	}
	else
	{ 
		$rows = mysql_fetch_assoc($res);
		
		$sql1 = "update sof_slave_4 set CARGO_DECL='".$this->getCheckNullValue($txtcheckbox)."', STOW_PLAN_QTY='".$this->getCheckNullValue($txtPA_1)."', SP_DEPT_DRAFT='".$txtPA_2."', SP_ARR_DRAFT='".$txtPA_3."', ETA_30_DAYS='".$txtETA_1."' , ETA_25_DAYS='".$txtETA_2."', ETA_20_DAYS='".$txtETA_3."', ETA_15_DAYS='".$txtETA_4."', ETA_10_DAYS='".$txtETA_5."', ETA_7_DAYS='".$txtETA_6."', ETA_5_DAYS='".$txtETA_7."', ETA_3_DAYS='".$txtETA_8."', ETA_2_DAYS='".$txtETA_9."', ETA_1_DAYS='".$txtETA_10."', ACTUAL_ARRIVAL='".$txtETA_11."', NOR_TENDERED='".$txtETA_12."' where SOFSLAVEID='".$rows['SOFSLAVEID']."'"; 
		mysql_query($sql1);
		
		$sql2 = "delete from sof_slave_5 where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."'";
		mysql_query($sql2);
		
		for($i=1;$i<=$txtTBID12;$i++)
		{ 
			if(addslashes(trim($_REQUEST['txtDate12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtETCD12_'.$tabid.'_'.$i])) != '')
			{
				$sql3 = "insert into sof_slave_5 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, PRE_DATE, ENGAGEMENT_QTY, LOAD_LAST, TTL_LOAD, BALANCE, ETCD, RANDOMID) values ('".$comid."', 'AGENT', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".date("Y-m-d",strtotime($_REQUEST['txtDate12_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtETCD12_'.$tabid.'_'.$i]))."', '".$serialno."')";
				mysql_query($sql3);
			}
		}
	}
	
	return $msg; 
}


function updationSOFRecords()
{
	$connect = $this->funConnect();
	
	$comid          	    = $_REQUEST['comid'];
	$tabid		          	= $_REQUEST['txttabid'][0];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$serialno		        = $_REQUEST['txtSerialno_'.$tabid];
	$submitid		        = addslashes(trim($_REQUEST['txtsubmitid_'.$tabid]));
	
	$terminalid	            = addslashes(trim($_REQUEST['selTerminal_'.$tabid]));	
	
	if($port == 'LP')
	{$loaded_qty	            = addslashes(trim($_REQUEST['txtTTLQty_'.$tabid]));}
	else{ $loaded_qty	            = 0;}
	
	if($port == 'DP')
	{$disch_qty	            = addslashes(trim($_REQUEST['txtTTLQty_'.$tabid]));
	}else{$disch_qty	            = 0;}
	
	$txtNarration           = addslashes(trim($_REQUEST['txtNarration_'.$tabid]));
	$txtTurnTime            = addslashes(trim($_REQUEST['txtTurnTime_'.$tabid]));
	
	$txtNOM	             	= addslashes(trim($_REQUEST['txtNOM_'.$tabid]));
	$txtNOR	             	= addslashes(trim($_REQUEST['txtNOR_'.$tabid]));
	$txtNOS	             	= addslashes(trim($_REQUEST['txtNOS_'.$tabid]));
	$txtLP	             	= addslashes(trim($_REQUEST['txtLP_'.$tabid]));
	$txtDP	             	= addslashes(trim($_REQUEST['txtDP_'.$tabid]));
	$txtCargo_Desc	        = addslashes(trim($_REQUEST['txtCargo_Desc_'.$tabid]));
	$txtCargo_Qty	        = addslashes(trim($_REQUEST['txtCargo_Qty_'.$tabid]));
	$txtTerminal	        = addslashes(trim($_REQUEST['txtTerminal_'.$tabid]));
	$txtVAPS	        	= addslashes(trim($_REQUEST['txtVAPS_'.$tabid]));
	$txtVAPS_1	        	= addslashes(trim($_REQUEST['txtVAPS_1_'.$tabid]));
	$txtVA		        	= addslashes(trim($_REQUEST['txtVA_'.$tabid]));
	$txtVA_1		        = addslashes(trim($_REQUEST['txtVA_1_'.$tabid]));
	$txtNT		        	= addslashes(trim($_REQUEST['txtNT_'.$tabid]));
	$txtNT_1		        = addslashes(trim($_REQUEST['txtNT_1_'.$tabid]));
	$txtNR		        	= addslashes(trim($_REQUEST['txtNR_'.$tabid]));
	$txtNR_1		        = addslashes(trim($_REQUEST['txtNR_1_'.$tabid]));
	$txtNA		        	= addslashes(trim($_REQUEST['txtNA_'.$tabid]));
	$txtNA_1		        = addslashes(trim($_REQUEST['txtNA_1_'.$tabid]));
	$txtAA		        	= addslashes(trim($_REQUEST['txtAA_'.$tabid]));
	$txtAA_1		        = addslashes(trim($_REQUEST['txtAA_1_'.$tabid]));
	$txtPBFB		        = addslashes(trim($_REQUEST['txtPBFB_'.$tabid]));
	$txtPBFB_1		        = addslashes(trim($_REQUEST['txtPBFB_1_'.$tabid]));
	$txtVAF		       	 	= addslashes(trim($_REQUEST['txtVAF_'.$tabid]));
	$txtFPG		       	 	= addslashes(trim($_REQUEST['txtFPG_'.$tabid]));
	$txtCC		       	 	= addslashes(trim($_REQUEST['txtCC_'.$tabid]));
	$txtIDSC		       	= addslashes(trim($_REQUEST['txtIDSC_'.$tabid]));
	$txtIDSC1		       	= addslashes(trim($_REQUEST['txtIDSC1_'.$tabid]));
	$txtHIC		       		= addslashes(trim($_REQUEST['txtHIC_'.$tabid]));
	$txtHIC1		       	= addslashes(trim($_REQUEST['txtHIC1_'.$tabid]));
	$txtHP		       		= addslashes(trim($_REQUEST['txtHP_'.$tabid]));
	$txtOHSC		       	= addslashes(trim($_REQUEST['txtOHSC_'.$tabid]));
	$txtOHSC1		       	= addslashes(trim($_REQUEST['txtOHSC1_'.$tabid]));
	$txtLC		       		= addslashes(trim($_REQUEST['txtLC_'.$tabid]));
	$txtLC1		       		= addslashes(trim($_REQUEST['txtLC1_'.$tabid]));
	$txtCLAPDS		       	= addslashes(trim($_REQUEST['txtCLAPDS_'.$tabid]));
	$txtDC		       		= addslashes(trim($_REQUEST['txtDC1_'.$tabid]));
	$txtVS		       		= addslashes(trim($_REQUEST['txtVS_'.$tabid]));
	$txtFDSS		       	= addslashes(trim($_REQUEST['txtFDSS_'.$tabid]));
	$txtFDSC		       	= addslashes(trim($_REQUEST['txtFDSC_'.$tabid]));
	
	$txtRemarks1		    = addslashes(trim($_REQUEST['txtRemarks1_'.$tabid]));
	$txtRemarks2		    = addslashes(trim($_REQUEST['txtRemarks2_'.$tabid]));
	$txtRemarks3		    = addslashes(trim($_REQUEST['txtRemarks3_'.$tabid]));
	$txtRemarks4		    = addslashes(trim($_REQUEST['txtRemarks4_'.$tabid]));
	$txtRemarks5		    = addslashes(trim($_REQUEST['txtRemarks5_'.$tabid]));
	$txtRemarks6		    = addslashes(trim($_REQUEST['txtRemarks6_'.$tabid]));
	$txtRemarks7		    = addslashes(trim($_REQUEST['txtRemarks7_'.$tabid]));
	$txtRemarks8		    = addslashes(trim($_REQUEST['txtRemarks8_'.$tabid]));
	$txtRemarks9		    = addslashes(trim($_REQUEST['txtRemarks9_'.$tabid]));
	$txtRemarks10		    = addslashes(trim($_REQUEST['txtRemarks10_'.$tabid]));
	$txtSat				    = addslashes(trim($_REQUEST['txtSat_'.$tabid]));
	$txtSun				    = addslashes(trim($_REQUEST['txtSun_'.$tabid]));
	$txtHol				    = addslashes(trim($_REQUEST['txtHol_'.$tabid]));
	$txtRRemarks			= addslashes(trim($_REQUEST['txtRRemarks_'.$tabid]));
	$txtCRemarks			= addslashes(trim($_REQUEST['txtCRemarks_'.$tabid]));
	$txtMRemarks			= addslashes(trim($_REQUEST['txtMRemarks_'.$tabid]));
	
	foreach($_FILES["mul_file"]['name'] as $key=>$value)
	{
		$filename =$_FILES['mul_file']['name'][$key];
		$tmpFile = $_FILES["mul_file"]["tmp_name"];
		$name[$key] = $filename;
		move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
	}
	 
	$filename = implode(",",$name);
	
	$txtCID     			= $_REQUEST['txtCID_'.$tabid];
	$txtTID     			= $_REQUEST['txtTID_'.$tabid];
	$txtSID     			= $_REQUEST['txtSID_'.$tabid];
	
	$bl_date	            = date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_1']));
	$bl_qty		            = $_REQUEST['txtTTLBLQty_'.$tabid];
	
	$arr = array("0","HATCH OPENING AND CLOSING","GRAB FIXING","HATCH WISE COMMENCEMENT AND COMPLETION OF CARGO WORK","PORT WORKING / RECESS HOURS","CRANE DELAYS - DELAYS/DETENTION/STOPPAGE OF WORK DUE TO CRANE /GRAB BREAKDOWN","DELAYS/DETENTION/STOPPAGE OF WORK ON SHIPS ACCOUNT (OTHER THAN GEAR)","DELAYS/DETENTION/STOPPAGE OF WORK ON SHORE ACCOUNT","BARGE TIMINGS - CARGO BARGE ARRIVAL / DEPARTURE TIMINGS","RAIN AND BAD WEATHER DELAYS (PRE BERTHING)","RAIN AND BAD WEATHER DELAYS (AT BERTH)","1");

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query = "select * from sof_master where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."'";
	$qres = mysql_query($query) or die($query);
	$qrec = mysql_num_rows($qres);
	
	if($qrec == 0)
	{
		$sql = "insert into sof_master (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, BL_DATE, LOADED_QTY, DISCH_QTY, BL_QTY_LOADED, SUBMITID, NAME_OF_MASTER, NAME_OF_SHIPPER, NAME_OF_STEVEDORES, LOAD_PORT, DISCHARGE_PORT, CARGO_DESC, CARGO_QTY, TERMINAL, VAPS, VA, NT, NR, NA, AA, PBFB, VAF, FPG, CC, IDSC, IDSC_1, HIC, HIC_1, HP, OHSC, OHSC_1, LC, LC1, CLAPDS, DC, VS, REMARKS_1, REMARKS_2, REMARKS_3, REMARKS_4, REMARKS_5, REMARKS_6, REMARKS_7, REMARKS_8, REMARKS_9, REMARKS_10, SATURDAYS, SUNDAYS, HOLIDAYS, SHIPPER_REMARKS, CHARTERER_REMARKS, MASTER_REMARKS, UPLOAD, FDSS, FDSC, VAPS_1, VA_1, NT_1, NR_1, NA_1, AA_1, PBFB_1, RANDOMID) values ('".$comid."', 'AGENT', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".$bl_date."', '".$this->getCheckNullValue($loaded_qty)."', '".$this->getCheckNullValue($disch_qty)."', '".$this->getCheckNullValue($bl_qty)."', '".$this->getCheckNullValue($submitid)."', '".$txtNOM."', '".$txtNOR."', '".$txtNOS."', '".$txtLP."', '".$txtDP."', '".$txtCargo_Desc."', '".$txtCargo_Qty."', '".$txtTerminal."', '".$txtVAPS."', '".$txtVA."', '".$txtNT."', '".$txtNR."', '".$txtNA."', '".$txtAA."', '".$txtPBFB."', '".$txtVAF."', '".$txtFPG."', '".$txtCC."', '".$txtIDSC."', '".$txtIDSC1."', '".$txtHIC."', '".$txtHIC1."', '".$txtHP."', '".$txtOHSC."', '".$txtOHSC1."', '".$txtLC."', '".$txtLC1."', '".$txtCLAPDS."', '".$txtDC."', '".$txtVS."', '".$txtRemarks1."', '".$txtRemarks2."', '".$txtRemarks3."', '".$txtRemarks4."', '".$txtRemarks5."', '".$txtRemarks6."', '".$txtRemarks7."', '".$txtRemarks8."', '".$txtRemarks9."', '".$txtRemarks10."', '".$txtSat."', '".$txtSun."', '".$txtHol."', '".$txtRRemarks."', '".$txtCRemarks."', '".$txtMRemarks."', '".trim($filename)."', '".$txtFDSS."', '".$txtFDSC."', '".$this->getCheckNullValue($txtVAPS_1)."', '".$txtVA_1."', '".$txtNT_1."', '".$txtNR_1."', '".$txtNA_1."', '".$txtAA_1."', '".$txtPBFB_1."', '".$serialno."')"; 
		mysql_query($sql,$connect) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(SOFID) as max from sof_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into sof_slave_3 (SOFID, ENTITY_NAME, ENTITY_VALUE) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3,$connect) or die($sql3);
				mysql_query("commit");
			}
		}
		
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtBLDate_'.$tabid.'_'.$i] != "")
			{
				$sql2 = "insert into sof_slave_1 (SOFID, BL_DATE, BL_GROSS_QTY, BL_QTY, CARGO) values ('".$maxid."', '".date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue($_REQUEST['txtQty_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtBLQty_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtCargo_'.$tabid.'_'.$i])."')";
				
				mysql_query($sql2,$connect) or die($sql2);
				mysql_query("commit");
			}
		}
		
		
		for($j=1; $j<12; $j++)
		{
			$txtTBID     			= $_REQUEST['txtTBID'.$j.'_'.$tabid];
			$txtCRM     			= explode(",",$_REQUEST['txtCRM'.$j.'_'.$tabid]);
			
			for($i=0;$i<$txtTBID;$i++)
			{
				if($_REQUEST['txtROW_ID'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != 0)
				{
					if($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != "")
					{
						$sql1 = "insert into sof_slave (SOFID, ACTIVITYID, START_DATETIME, FINISH_DATETIME, DURATION, LAY_TIME_COUNT, PORT_TIME_COUNT, NOTES, GROUP_NAME) values ('".$maxid."','".addslashes(trim($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDStart'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDEnd'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."', '".$_REQUEST['txtDiff'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','0','0','".addslashes($_REQUEST['txtNotes'.$j.'_'.$tabid.'_'.$txtCRM[$i]])."', '".$arr[$j]."')";
						
						mysql_query($sql1,$connect) or die($sql1);
						mysql_query("commit");
					}
				}
			}
		}
		
		for($i=1 ; $i<=$txtSID ;$i++)
		{
			$sql2 = "insert into sof_slave_2(SOFID, ACTIVITYID, ARRIVAL_COND, DEPARTURE_COND) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtMI_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAC_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtDC_'.$tabid.'_'.$i]))."')";
			mysql_query($sql2,$connect) or die($sql2);
			mysql_query("commit");
		}
	}
	else
	{
		$txtCRMFILE2=$_REQUEST["txtCRMFILE2"];
		$qrows = mysql_fetch_assoc($qres);
		
		
		foreach($_FILES["mul_file"]['name'] as $key=>$value)
		{
			$filename =$_FILES['mul_file']['name'][$key];
			$tmpFile = $_FILES["mul_file"]["tmp_name"];
			$name[$key] = $filename;
			move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
		}
		 
		$filename = implode(",",$name);
	
		if($txtCRMFILE2 != '' && $filename != ''){ $filename = $txtCRMFILE2.','.$filename;}
	    else if($txtCRMFILE2 == '' && $filename != ''){ $filename = $filename;}
	    else if($txtCRMFILE2 != '' && $filename == ''){ $filename = $txtCRMFILE2;}
 
		
		$sql = "update sof_master set BL_DATE='".$bl_date."', LOADED_QTY='".$this->getCheckNullValue($loaded_qty)."', DISCH_QTY='".$this->getCheckNullValue($disch_qty)."', BL_QTY_LOADED='".$this->getCheckNullValue($bl_qty)."', SUBMITID='".$this->getCheckNullValue($submitid)."', NAME_OF_MASTER='".$txtNOM."', NAME_OF_SHIPPER='".$txtNOR."', NAME_OF_STEVEDORES='".$txtNOS."', LOAD_PORT='".$txtLP."', DISCHARGE_PORT='".$txtDP."', CARGO_DESC='".$txtCargo_Desc."', CARGO_QTY='".$txtCargo_Qty."', TERMINAL='".$txtTerminal."', VAPS='".$txtVAPS."', VA='".$txtVA."', NT='".$txtNT."', NR='".$txtNR."', NA='".$txtNA."', AA='".$txtAA."', PBFB='".$txtPBFB."', VAF='".$txtVAF."', FPG='".$txtFPG."', CC='".$txtCC."', IDSC='".$txtIDSC."', IDSC_1='".$txtIDSC1."', HIC='".$txtHIC."', HIC_1='".$txtHIC1."', HP='".$txtHP."', OHSC='".$txtOHSC."', OHSC_1='".$txtOHSC1."', LC='".$txtLC."', LC1='".$txtLC1."', CLAPDS='".$txtCLAPDS."', DC='".$txtDC."', VS='".$txtVS."', REMARKS_1='".$txtRemarks1."', REMARKS_2='".$txtRemarks2."', REMARKS_3='".$txtRemarks3."', REMARKS_4='".$txtRemarks4."', REMARKS_5='".$txtRemarks5."', REMARKS_6='".$txtRemarks6."', REMARKS_7='".$txtRemarks7."', REMARKS_8='".$txtRemarks8."', REMARKS_9='".$txtRemarks9."', REMARKS_10='".$txtRemarks10."', SATURDAYS='".$txtSat."', SUNDAYS='".$txtSun."', HOLIDAYS='".$txtHol."', SHIPPER_REMARKS='".$txtRRemarks."', CHARTERER_REMARKS='".$txtCRemarks."', MASTER_REMARKS='".$txtMRemarks."', UPLOAD='".$filename."', FDSS='".$txtFDSS."', FDSC='".$txtFDSC."', VAPS_1='".$this->getCheckNullValue($txtVAPS_1)."', VA_1='".$txtVA_1."', NT_1='".$txtNT_1."', NR_1='".$txtNR_1."', NA_1='".$txtNA_1."', AA_1='".$txtAA_1."', PBFB_1='".$txtPBFB_1."' where SOFID='".$qrows['SOFID']."'";
		mysql_query($sql,$connect) or die($sql);
		mysql_query("commit");
		
		$delquery = "delete from sof_slave where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery);
		mysql_query("commit");
		
		$delquery_1 = "delete from sof_slave_1 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_1);
		mysql_query("commit");
		
		$delquery_2 = "delete from sof_slave_2 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_2);
		mysql_query("commit");
		
		$delquery_3 = "delete from sof_slave_3 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_3);
		mysql_query("commit");
		
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into sof_slave_3 (SOFID, ENTITY_NAME, ENTITY_VALUE) values ('".$qrows['SOFID']."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3,$connect) or die($sql3);
				mysql_query("commit");
			}
		}
		
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtBLDate_'.$tabid.'_'.$i] != "")
			{
				$sql2 = "insert into sof_slave_1 (SOFID, BL_DATE, BL_GROSS_QTY, BL_QTY, CARGO) values ('".$qrows['SOFID']."', '".date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue($_REQUEST['txtQty_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtBLQty_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtCargo_'.$tabid.'_'.$i])."')"; 
				mysql_query($sql2,$connect) or die($sql2);
				mysql_query("commit");
			}
		}
				
		for($j=1; $j<12; $j++)
		{
			$txtTBID     			= $_REQUEST['txtTBID'.$j.'_'.$tabid];
			$txtCRM     			= explode(",",$_REQUEST['txtCRM'.$j.'_'.$tabid]);
			
			for($i=0 ; $i<$txtTBID ;$i++)
			{
				if($_REQUEST['txtROW_ID'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != 0)
				{
					if($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != "")
					{
						$sql1 = "insert into sof_slave (SOFID, ACTIVITYID, START_DATETIME, FINISH_DATETIME, DURATION, LAY_TIME_COUNT, PORT_TIME_COUNT, NOTES, GROUP_NAME) values ('".$qrows['SOFID']."','".$_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDStart'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDEnd'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."', '".$_REQUEST['txtDiff'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','0','0','".addslashes($_REQUEST['txtNotes'.$j.'_'.$tabid.'_'.$txtCRM[$i]])."', '".$arr[$j]."')";
						mysql_query($sql1,$connect) or die($sql1);
						mysql_query("commit");
					}
				}
			}
		}
		
		for($i=1 ; $i<=$txtSID ;$i++)
		{
			$sql2 = "insert into sof_slave_2(SOFID, ACTIVITYID, ARRIVAL_COND, DEPARTURE_COND) values ('".$qrows['SOFID']."', '".$_REQUEST['txtMI_'.$tabid.'_'.$i]."', '".$_REQUEST['txtAC_'.$tabid.'_'.$i]."', '".$_REQUEST['txtDC_'.$tabid.'_'.$i]."')";
			mysql_query($sql2,$connect) or die($sql2);
			mysql_query("commit");
		}
	}	
	return $msg; 
}

function viewAdminRecords($id)
{ 
	$connect = $this->funConnect();
	$query = "SELECT * FROM generate_agency_letter where GEN_AGENCY_ID=".$id; 
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{ 
		$this->var_1 = $rows['MCOMPANYID'];
		$this->var_2 = $rows['ADDRESS'];
		$this->var_3 = $rows['PHONE_NO'];
		$this->var_4 = $rows['EMAILID'];
		$this->var_5 = $rows['CONTACT_PERSON'];
		$this->var_6 = $rows['STATUS'];
		$this->var_7 = $rows['USERNAME'];
		$this->var_8 = $rows['PASSWORD'];
		$this->var_9 = $rows['RANDOMID'];
	}
}

function updateUserProfileRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	
	$user_name 			= addslashes(trim($_REQUEST['txtUserName']));
	$password 			= addslashes(trim($_REQUEST['txtPassword']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update generate_agency_letter set PASSWORD='".$password."'  where GEN_AGENCY_ID='".$id."'";
	
	mysql_query($sql) or die(mysql_error());	
	mysql_query("commit"); 
	
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Password changed successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
		
	if(mysql_error($connect))
	{
		$msg = 1;
		mysql_query("ROLLBACK");
	}
	else
	{
		mysql_query("commit"); 
	}
		
	return $msg;
}


function getPreArrivaldata($comid,$port,$portid,$serialno,$field)
{
	$connect 				= $this->funConnect();	
	$sql1 = "select ".$field." from sof_slave_4 where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$serialno."' ";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	return $rows1[$field];
}


function getCompareTableData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from freight_cost_estimate_compare where COMID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getUpload($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
				$name[$key] = $filename;
				move_uploaded_file($upload['tmp_name'][$key], '../../attachment/'.$filename);
			}
		}
	}
	else
	{
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']);
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
			$name = $filename;
			move_uploaded_file($upload['tmp_name'], '../../attachment/'.$filename);
		}
	}
	
	return $name;
}

function getUploadName($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = $upload['name'][$key];
				$name[$key] = $filename;
			}
		}
	}
	else
	{
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']);
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = $upload['name'];
			$name = $filename;
		}
	}
	
	return $name;
}

} // class data ends
?>