<?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;
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 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;
	
	$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 getUserRightsForPl($loginid,$moduleid,$linkid)
{
	$connect = $this->funConnect();

	$sql = "SELECT DIS_PL FROM login WHERE LOGINID='".$loginid."'";

	$res = mysql_query($sql);

	$rows = mysql_fetch_assoc($res);

	$arr = unserialize($rows['DIS_PL']);
	return $arr;
}


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 getCompanyData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from main_company where MCOMPANYID=".$id;
	$res = mysql_query($sql) or die(mysql_error());
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}







function getUserStatusBasedOnID($id)
{
	if($id == 1){return 'Active';}
	if($id == 2){return 'In-Active';}
}

function getUserStatusList()
{
$state = array( 1 =>'Active' , 2 =>'In-Active');
$selStatus = @$_REQUEST['selStatus'];
echo "<option value=''>--Select from list--</option>";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selStatus){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


///---------------------masters---------------------------------

function displayBusinessTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="business_type_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="45%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from business_type_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['BUSINESSTYPEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatebusiness_type.php?id='.$rows['BUSINESSTYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertBusinessTypeMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into business_type_master (NAME,STATUS) values ('".$txtName."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Business Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewBusinessTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM business_type_master where BUSINESSTYPEID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}

function updateBusinessTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update business_type_master set NAME='".$txtName."',STATUS='".$selStatus."' where BUSINESSTYPEID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Business Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



function displayShipyardList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="shipyard_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Shipyard</th>';
	echo '<th align="left" valign="middle" width="45%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from builder_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['BUILDER_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateShipyard.php?id='.$rows['BUILDER_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
	
}


function VesselAllocation()
{
	$connect = $this->funConnect();
	$arr     = $_REQUEST['checkIMObox'];
	$msg     = 0;
 
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
 
	for($i=0;$i<count($arr);$i++)
	{
		$sql = "select * from vessel_allocation_master where VESSEL_IMO_ID='".$arr[$i]."' ";
		$res = mysql_query($sql);
		$rec = mysql_num_rows($res);
		if($rec == 0)
		{
			$product  = implode(",",$_REQUEST['selCProduct_'.$arr[$i]]);
			$sql2     = "insert into vessel_allocation_master (VESSEL_IMO_ID,TRANS_DATE,MODULE_ID,MCOMPANYID) values ('".$arr[$i]."','".date("Y-m-d",time())."','".$product."','".$_SESSION['company']."')";
			mysql_query($sql2)or die($sql2);
			
			$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
			mysql_query($sql3) or die($sql3);
		}else{
			
			$product   = implode(",",$_REQUEST['selCProduct_'.$arr[$i]]);
			$sql2 = "update vessel_allocation_master set MODULE_ID='".$product."'  where VESSEL_IMO_ID='".$arr[$i]."' and MCOMPANYID='".$_SESSION['company']."' ";
			mysql_query($sql2)or die($sql2);
			
			$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
			mysql_query($sql3) or die($sql3);
		}
	}
	mysql_query("commit");
	return $msg; 
}


function InsertShipyardMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtBuilder 				= addslashes(trim($_REQUEST['txtBuilder']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into builder_master (NAME,STATUS) values ('".$txtBuilder."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Builder added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateShipyardMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtBuilder 				= addslashes(trim($_REQUEST['txtBuilder']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update builder_master set NAME='".$txtBuilder."',STATUS='".$selStatus."' where BUILDER_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Builder updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewShipyardRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM builder_master where BUILDER_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}



function displayCapRatingList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="cap_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >CAP Rating</th>';
	echo '<th align="left" valign="middle" width="45%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from cap_rating_master order by CAP_RATING";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CAP_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CAP_RATING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCAP_Rating.php?id='.$rows['CAP_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertCapRatingMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtCAPRating 			= addslashes(trim($_REQUEST['txtCAPRating']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into cap_rating_master (CAP_RATING,STATUS) values ('".$txtCAPRating."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cap Rating added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateCAPRatingMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCAPRating 				= addslashes(trim($_REQUEST['txtCAPRating']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update cap_rating_master set CAP_RATING='".$txtCAPRating."',STATUS='".$selStatus."' where CAP_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cap Rating updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCAPRatingRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM cap_rating_master where CAP_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['CAP_RATING'];
		$this->var_2 = $rows['STATUS'];
	}
}



function displayCargoTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="cargoType_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="40%"  >Cargo Type Name</th>';
	echo '<th align="left" valign="middle" width="40%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from cargotype_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCargo_Type.php?id='.$rows['CARGOTYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
			}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertCargoTypeDetails()
{
	$connect = $this->funConnect();
	$name 		= addslashes(trim($_REQUEST['txtCTName']));
	$desc 		= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into cargotype_master (NAME,DESCRIPTION,STATUS) values ('".$name."','".$desc."','".$selStatus."')";
	mysql_query($sql,$connect) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function updateCargoTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCTName 				= addslashes(trim($_REQUEST['txtCTName']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update cargotype_master set NAME='".$txtCTName."',DESCRIPTION='".$txtDesc."',STATUS='".$selStatus."' where CARGOTYPEID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCargoTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM cargotype_master where CARGOTYPEID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['STATUS'];
	}
}



function displayCompanyTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="companyType_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="40%"  >Company Type</th>';
	echo '<th align="left" valign="middle" width="40%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from company_type_master order by NAME";
	$res = mysql_query($sql)  or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCompany_Type.php?id='.$rows['COMPANYTYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertCompanyTypeDetails()
{
	$connect = $this->funConnect();
	$name 					= addslashes(trim($_REQUEST['txtCTName']));
	$desc 					= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into company_type_master (NAME,DESCRIPTION,STATUS) values ('".$name."','".$desc."','".$selStatus."')";
	mysql_query($sql,$connect) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Company Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function updateCompanyTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCTName 				= addslashes(trim($_REQUEST['txtCTName']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update company_type_master set NAME='".$txtCTName."',DESCRIPTION='".$txtDesc."',STATUS='".$selStatus."'  where COMPANYTYPEID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Company Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCompanyTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM company_type_master where COMPANYTYPEID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['STATUS'];
	}
}







function displayClassSocList()
{
 $this->funConnect();
 echo '<div class="box-body table-responsive">';
 echo '<table id="soc_list" class="table table-bordered table-striped">';
 echo '<thead>';
 echo '<tr>';
 echo '<th align="center" valign="middle" width="5%" >#</th>';
 echo '<th align="left" valign="middle" width="45%"  >Classification Society Name</th>';
 echo '<th align="left" valign="middle" width="45%"  >Status</th>';
 echo '<th align="center" valign="middle" width="5%" >Details</th>';
 echo '</tr>';
 echo '</thead>';
 $sql = "select * from classification_soc_master order by NAME";
 $res = mysql_query($sql);
 $rec = mysql_num_rows($res);
 $i = 1;
 if($rec == 0)
 {
  echo '<tbody>';

  echo '</tbody>';
 }else{
 echo '<tbody>';
  while($rows = mysql_fetch_assoc($res))
   {
    $this->id = $rows['CLA_SOC_ID'];
    echo '<tr>';
    echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
    echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
    echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
    echo '<td align="center" valign="middle" class="input-text"><a href="updateClass_Soc.php?id='.$rows['CLA_SOC_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>'; 
    echo '</tr>';
    $i++;
  }
 echo '</tbody>';
 }
 echo '</table></div>';
}

function InsertClassSocMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtCSName 				= addslashes(trim($_REQUEST['txtCSName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into classification_soc_master (NAME,STATUS) values ('".$txtCSName."','".$selStatus."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Classification Society added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateClassSocMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCSName 				= addslashes(trim($_REQUEST['txtCSName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update classification_soc_master set NAME='".$txtCSName."',STATUS='".$selStatus."'  where CLA_SOC_ID='".$id."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Classification Society updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewClassSocMasterRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM classification_soc_master where CLA_SOC_ID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}







function displayCPTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="cp_type_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="45%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from cp_type_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CP_TYPE_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCP_Type.php?id='.$rows['CP_TYPE_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertCPTypeMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtCPName 				= addslashes(trim($_REQUEST['txtCPName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into cp_type_master (NAME,STATUS) values ('".$txtCPName."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','CP Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateCPTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCPName 				= addslashes(trim($_REQUEST['txtCPName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update cp_type_master set NAME='".$txtCPName."',STATUS='".$selStatus."' where CP_TYPE_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','CP Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCPTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM cp_type_master where CP_TYPE_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}


function displayFlagList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="flag_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Flag Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from flag_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
	
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['FLAG_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateFlag.php?id='.$rows['FLAG_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertFlagMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtFName 				= addslashes(trim($_REQUEST['txtFName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into flag_master (NAME,STATUS) values ('".$txtFName."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	mysql_query("commit");
	
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Flag added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateFlagMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtFName 				= addslashes(trim($_REQUEST['txtFName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update flag_master set NAME='".$txtFName."',STATUS='".$selStatus."'  where FLAG_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Flag updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewFlagRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM flag_master where FLAG_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}


function displayFixtureTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="fixture_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="35%"  >Name</th>';
	echo '<th align="left" valign="middle" width="35%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from fixture_type_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['FIXTURETYPE_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateFixtureType.php?id='.$rows['FIXTURETYPE_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertFixtureTypeRecords()
{
	$connect				= $this->funConnect();
 	$txtFName 				= addslashes(trim($_REQUEST['txtFName']));
	$txtDesc			    = addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into fixture_type_master (NAME,DESCRIPTION,STATUS) values ('".$txtFName."','".$txtDesc."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fixture Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateFixtureTypeRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtFName 				= addslashes(trim($_REQUEST['txtFName']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update fixture_type_master set NAME='".$txtFName."',DESCRIPTION='".$txtDesc."',STATUS='".$selStatus."' where FIXTURETYPE_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fixture Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewFixtureTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM fixture_type_master where FIXTURETYPE_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['STATUS'];
	}
}


function displayFreightTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="freighttype_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="35%"  >Freight Type Name</th>';
	echo '<th align="left" valign="middle" width="35%"  >Description</th>';	
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from freighttype_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateFreight.php?id='.$rows['FREIGHTTYPE_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertFreightTypeDetails()
{
	$connect = $this->funConnect();
	$name 		= addslashes(trim($_REQUEST['txtFTName']));
	$desc 		= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into freighttype_master (NAME,DESCRIPTION,STATUS) values ('".$name."','".$desc."','".$selStatus."')";
	mysql_query($sql,$connect) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Freight Type added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function updateFreightMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtFTName 				= addslashes(trim($_REQUEST['txtFTName']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update freighttype_master set NAME='".$txtFTName."',DESCRIPTION='".$txtDesc."',STATUS='".$selStatus."' where FREIGHTTYPE_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Freight Type updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewFreightRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM freighttype_master where FREIGHTTYPE_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['STATUS'];
	}
}



function deletePortMasterRecords()
{
	$connect = $this->funConnect();
	$id = $_REQUEST['txtID'];
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "delete from port_master where PortId='".$id."'";
	mysql_query($sql);
	
	$sql1 = "delete from distance_master where FROMPORTID='".$id."' or TOPORTID='".$id."'";
	mysql_query($sql1);
	
	mysql_query("commit"); 
	return $msg;
}

function displayPortList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="port_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="18%"  >Port Name</th>';
	echo '<th align="left" valign="middle" width="18%"  >Port Code</th>';
	echo '<th align="left" valign="middle" width="18%"  >Country Key</th>';
	echo '<th align="left" valign="middle" width="18%"  >Country Name</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from port_master order by PortId desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['PortId'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PortName'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PortCode'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['COUNTRY_KEY'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getCountryNameBasedOnID($rows['COUNTRY_NAME']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><!--<a href="updatePort.php?id='.$rows['PortId'].'" title="Edit Details" ><img src="../images/edit.png" width="14" height="14" /></a>--><a title="Delete record" href="#'.$i.'" onclick="return getDelete('.$rows['PortId'].');" ><i class="fa fa-times" style="color:red;"></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function InsertPortMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtPName 				= addslashes(trim($_REQUEST['txtPName']));
	$txtPCode 				= addslashes(trim($_REQUEST['txtPCode']));
	$country_key			= addslashes(trim($_REQUEST['txtCKey']));
	$country 				= addslashes(trim($_REQUEST['selCountry']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into port_master (PortName ,Quantity ,DraftLoad ,PortRateLoad ,PortCostLoad, PortRateDischarge, PortCostDischarge ,DraftDischarge,DraftTransit,PortRateTransit,PortCostTransit,STATUS,UpdStatus,PortCode,COUNTRY_KEY,COUNTRY_NAME) values ('".$txtPName."','0','0','0','0','0','0','0','0','0','0','1','0','".$txtPCode."','".$country_key."','".$country."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updatePortMasterRecords()
{
	$connect				= $this->funConnect();	
	$country_key			= addslashes(trim(strtoupper($_REQUEST['txtCKey'])));
	$country 				= addslashes(trim($_REQUEST['selCountry']));
	$id = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update port_master set COUNTRY_KEY='".$country_key."',COUNTRY_NAME='".$country."'  where PortId='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewPortRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM port_master where PortId=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['PortName'];
		$this->var_3 = $rows['STATUS'];
		$this->var_4 = $rows['PortCode'];
		$this->var_5 = $rows['COUNTRY_KEY'];
		$this->var_6 = $rows['COUNTRY_NAME'];
	}
}


function displayCountryList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="country_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="20%"  >Name</th>';
	echo '<th align="left" valign="middle" width="20%"  >Currency</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from country_master order by COUNTRY_NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CountryId'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['COUNTRY_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CURRENCY_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCountry.php?id='.$rows['COUNTRYID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertCountryMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	$c_name 				= addslashes(trim($_REQUEST['txtCName']));
	//$c_rate 				= addslashes(trim($_REQUEST['txtCRate']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into country_master (COUNTRY_NAME,STATUS,CURRENCY_NAME) values ('".$txtName."','".$selStatus."','".$c_name."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Country added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateCountryMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	$c_name 				= addslashes(trim($_REQUEST['txtCName']));
	//$c_rate 				= addslashes(trim($_REQUEST['txtCRate']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update country_master set COUNTRY_NAME='".$txtName."',STATUS='".$selStatus."',CURRENCY_NAME='".$c_name."'  where COUNTRYID='".$id."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Country updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function getCountryList()
{
	$this->funConnect();
	$query = mysql_query("select * from country_master where STATUS = 1 order by COUNTRY_NAME ");
	echo "<option value = ''>--Select from list--</option>";
	$selCountry = @$_REQUEST['selCountry'];
	while($rows = mysql_fetch_assoc($query))
		{
		     $key= $rows['COUNTRYID'];
		     $value= $rows['COUNTRY_NAME'];
		     echo "<option value=$key";
		     if($key == $selCountry){ echo " selected";}
		     echo ">".$value."</option>";
		}
}

function viewCountryRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM country_master where COUNTRYID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['COUNTRY_NAME'];
		$this->var_2 = $rows['STATUS'];
		$this->var_3 = $rows['CURRENCY_NAME'];
	}
}


function getCountryNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$query = "SELECT COUNTRY_NAME FROM country_master where COUNTRYID=".$id;
	$result = mysql_query($query);
	$rows = mysql_fetch_assoc($result);
	return $rows['COUNTRY_NAME'];
}







function displayDistanceList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="distance_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th>From Port</th>';
	echo '<th>To Port</th>';
	echo '<th>Shortest Dis(NM)</th>';
	echo '<th>250nm Dis(NM)</th>';
	echo '<th>600nm Dis(NM)</th>';
	echo '<th>Longest Dis(NM)</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select (select PortName from port_master where port_master.PortId=distance_master.FROMPORTID) as FROMPORTID, (select PortName from port_master where port_master.PortId=distance_master.TOPORTID) as TOPORTID, SHORT_DIS, NM250_DIS, NM600_DIS, LONG_DIS from distance_master";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
	
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td>'.$rows['FROMPORTID'].'</td>';
				echo '<td>'.$rows['TOPORTID'].'</td>';
				echo '<td>'.$rows['SHORT_DIS'].'</td>';
				echo '<td>'.$rows['NM250_DIS'].'</td>';
				echo '<td>'.$rows['NM600_DIS'].'</td>';
				echo '<td>'.$rows['LONG_DIS'].'</td>';
				echo '</tr>';
				$i++;
		}
	  echo '</tbody>';
	}
	echo "</table>";
}



function getPortList()
{
	$this->funConnect();
	$query = mysql_query("select * from port_master where STATUS = 1 order by PortName ");
	echo "<option value = ''>---Select from list---</option>";
	$selDPort = @$_REQUEST['selDPort'];
	while($rows = mysql_fetch_assoc($query))
		{
		     $key= $rows['PortId'];
		     $value= $rows['PortName'];
		     echo "<option value=$key";
		     if($key == $selDPort){ echo " selected";}
		     echo ">".$value."</option>";
		}
}

function InsertDistanceMasterRecords()
{
	$connect				= $this->funConnect();
 	$selFPort 				= addslashes(trim($_REQUEST['selFPort']));
	$selTPort 				= addslashes(trim($_REQUEST['selTPort']));
	$short_Dis 				= addslashes(trim($_REQUEST['txtShortDis']));
	$selRoute 				= addslashes(trim($_REQUEST['selRoute']));
	$nm250_Dis 				= addslashes(trim($_REQUEST['txt250nmDis']));
	$nm600_Dis 				= addslashes(trim($_REQUEST['txt600nmDis']));
	$long_Dis 				= addslashes(trim($_REQUEST['txtLongDis']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql1 = "select * from distance_master where FROMPORTID=".$selFPort." and TOPORTID=".$selTPort;
	$result1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($result1);
	if($rec1 == 0)
	{
		$sql3 = "select * from distance_master where FROMPORTID=".$selTPort." and TOPORTID=".$selFPort;
		$result3 = mysql_query($sql3);
		$rec3 = mysql_num_rows($result3);
		if($rec3 == 0)
		{
			$sql = "insert into distance_master (FROMPORTID, TOPORTID, SHORT_DIS, NM250_DIS, NM600_DIS, LONG_DIS, STATUS, ROUTE) values ('".$selFPort."','".$selTPort."','".$short_Dis."','".$nm250_Dis."','".$nm600_Dis."','".$long_Dis."','".$selStatus."','".$selRoute."')";
			mysql_query($sql);
		}
		else
		{
			$sql4 = "update distance_master set SHORT_DIS='".$short_Dis."',NM250_DIS='".$nm250_Dis."',NM600_DIS='".$nm600_Dis."',LONG_DIS='".$long_Dis."',STATUS='".$selStatus."', ROUTE='".$selRoute."' where FROMPORTID=".$selTPort." and TOPORTID=".$selFPort;
			mysql_query($sql4);
			$workType = "added";
		}
	}
	else
	{
		$sql2 = "update distance_master set SHORT_DIS='".$short_Dis."',NM250_DIS='".$nm250_Dis."',NM600_DIS='".$nm600_Dis."',LONG_DIS='".$long_Dis."',STATUS='".$selStatus."', ROUTE='".$selRoute."' where FROMPORTID=".$selFPort." and TOPORTID=".$selTPort;
		mysql_query($sql2);
		$workType = "updated";
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Distance ".$workType." successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

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 getPortListCountryWise()
{
	$this->funConnect();
	$query = mysql_query("select * from port_master where STATUS = 1 order by PortName ");
	echo "<option value = ''>---Select from list---</option>";
	$selDPort = @$_REQUEST['selDPort'];
	while($rows = mysql_fetch_assoc($query))
		{
		     $key= $rows['PortId'];
		     $value= $rows['PortName']." , ".$this->getCountryNameBasedOnID($rows['COUNTRY_NAME']);
		     echo "<option value=$key";
		     if($key == $selDPort){ echo " selected";}
		     echo ">".$value."</option>";
		}
}


function getDistanceRouteName($id)
{
	if($id == 1){return 'Suez Canal';}
	if($id == 2){return 'Cape of Good Hope';}
	if($id == 3){return 'Panama';}
}


function getDistanceRoute()
{
$state = array( 1 =>'Suez Canal', 2 =>'Cape of Good Hope', 3 =>'Panama');
echo "<option value = '' >---Select from list---</option>";
	@$selRoute = @$_REQUEST['selRoute'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selRoute){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function displayCertificateList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="certificate_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Certificate Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from certificate_master order by CERTIFICATE";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CERTIFICATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCertificate.php?id='.$rows['CERTIFICATEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertCertificateDetails()
{
	$connect = $this->funConnect();
	$name 					= addslashes(trim($_REQUEST['txtCName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into certificate_master (CERTIFICATE,STATUS) values ('".$name."','".$selStatus."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Certificate added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function updateCertificateMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCName 					= addslashes(trim($_REQUEST['txtCName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update certificate_master set CERTIFICATE='".$txtCName."',STATUS='".$selStatus."' where CERTIFICATEID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Certificate Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCertificateRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM certificate_master where CERTIFICATEID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['CERTIFICATE'];
		$this->var_2 = $rows['STATUS'];
	}
}






function displayRankList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="rank_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="35%"  >Name</th>';
	echo '<th align="left" valign="middle" width="35%"  >Code</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from rank_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['RANKID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CODE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateRank.php?id='.$rows['RANKID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertRankRecords()
{
	$connect				= $this->funConnect();
 	$txtRName 				= addslashes(trim($_REQUEST['txtRName']));
	$txtRCode 				= addslashes(trim($_REQUEST['txtRCode']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into rank_master (NAME, CODE,STATUS) values ('".$txtRName."', '".$txtRCode."', '".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Rank Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateRankMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtRName 				= addslashes(trim($_REQUEST['txtRName']));
	$txtRCode 				= addslashes(trim($_REQUEST['txtRCode']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update rank_master set NAME='".$txtRName."', CODE='".$txtRCode."', STATUS='".$selStatus."' where RANKID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Rank Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewRankRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM rank_master where RANKID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['CODE'];
		$this->var_3 = $rows['STATUS'];
	}
}




function displayUnitList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="unit_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Unit Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from unit_code_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['UN_CO_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateUnit.php?id='.$rows['UN_CO_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function InsertUnitMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtUName 				= addslashes(trim($_REQUEST['txtUName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into unit_code_master (NAME,STATUS) values ('".$txtUName."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Unit Code Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateUnitMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtUName 				= addslashes(trim($_REQUEST['txtUName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update unit_code_master set NAME='".$txtUName."',STATUS='".$selStatus."' where UN_CO_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Unit Code Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewUnitRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM unit_code_master where UN_CO_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}


function displayPortCallPurposeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="port_call_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from port_call_purpose_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['PORT_CALLID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateport_call_purpose.php?id='.$rows['PORT_CALLID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertPortCallPurposeMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into port_call_purpose_master (NAME,STATUS) values ('".$txtName."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Call Purpose Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updatePortCallPurposeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update port_call_purpose_master set NAME='".$txtName."',STATUS='".$selStatus."' where PORT_CALLID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Call Purpose Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function viewPortCallPurposeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM port_call_purpose_master where PORT_CALLID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}


function displayVendorTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vendor_type_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Vendor Type</th>';
	echo '<th align="left" valign="middle" width="45%"  >Vendor Type Prefix</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from vendor_type_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['VENDOR_TYPEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VENDOR_PREFIX'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatevendor_type.php?id='.$rows['VENDOR_TYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertVendorTypeRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$txtNamePrefix 			= strtoupper(addslashes(trim($_REQUEST['txtNamePrefix'])));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	$sql = "insert into vendor_type_master (NAME,VENDOR_PREFIX,STATUS) values ('".$txtName."','".$txtNamePrefix."','".$selStatus."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Vendor Type Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateVendorTypeRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$txtNamePrefix			= strtoupper(addslashes(trim($_REQUEST['txtNamePrefix'])));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vendor_type_master set NAME='".$txtName."',VENDOR_PREFIX='".$txtNamePrefix."',STATUS='".$selStatus."' where VENDOR_TYPEID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Vendor Type Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewVendorTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vendor_type_master where VENDOR_TYPEID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
		$this->var_3 = $rows['VENDOR_PREFIX'];
	}
}



function displayChartererPartyList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="charterer_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="18%"  >CP Name</th>';
	echo '<th align="left" valign="middle" width="18%"  >Cargo Type</th>';
	echo '<th align="left" valign="middle" width="18%"  >CP Type</th>';
	echo '<th align="left" valign="middle" width="18%"  >CP Ref</th>';
	echo '<th align="left" valign="middle" width="10%"  >PDF</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from charterer_party_master order by NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		//echo '<tr>';
//		echo '<td align="center" colspan="8" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
//		echo '</tr>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CP_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getCargoTypeNameBasedOnID($rows['CARGOTYPEID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getCPTypeNameBasedOnID($rows['CP_TYPE_ID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CP_REF'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"><a title="PDF" href="../attachment/'.$rows['CP_PDF'].'" target="_blank">'.$rows['CP_PDF'].'</a></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateCP_Master.php?id='.$rows['CP_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function getCargoTypeNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from cargotype_master where CARGOTYPEID='".$id."'";
	$res = mysql_query($sql) or die(mysql_error());
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function getCPTypeNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from cp_type_master where CP_TYPE_ID='".$id."'";
	$res = mysql_query($sql) or die(mysql_error());
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function insertChartererPartyDetails()
{
	$connect = $this->funConnect();
	$txtCPName 			= addslashes(trim($_REQUEST['txtCPName']));
	$selCType 			= addslashes(trim($_REQUEST['selCType']));
	$selCPType 			= addslashes(trim($_REQUEST['selCPType']));
	$txtCPRef 			= addslashes(trim($_REQUEST['txtCPRef']));
	$selStatus 			= addslashes(trim($_REQUEST['selStatus']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into charterer_party_master (NAME,CARGOTYPEID,CP_TYPE_ID,CP_REF,CP_PDF,STATUS) values ('".$txtCPName."','".$selCType."','".$selCPType."','".$txtCPRef."','".$_SESSION['fileid']."','".$selStatus."')";
	mysql_query($sql,$connect) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Charterer Party Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	unset($_SESSION['fileid']);
	return $msg; 
}

function getCargoTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from cargotype_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selCType = @$_REQUEST['selCType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CARGOTYPEID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getCPTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from cp_type_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selCPType = @$_REQUEST['selCPType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CP_TYPE_ID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCPType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function updateChartererPartyMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtCPName 			= addslashes(trim($_REQUEST['txtCPName']));
	$selCType 			= addslashes(trim($_REQUEST['selCType']));
	$selCPType 			= addslashes(trim($_REQUEST['selCPType']));
	$txtCPRef 			= addslashes(trim($_REQUEST['txtCPRef']));
	$txtUpload 			= addslashes(trim($_REQUEST['txtUpload']));
	$selStatus 			= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	if($_SESSION['fileid'] == '')
	{
	$sql1 = "update charterer_party_master set NAME='".$txtCPName."', CARGOTYPEID='".$selCType."', CP_TYPE_ID='".$selCPType."', CP_REF='".$txtCPRef."' ,STATUS='".$selStatus."' where CP_ID='".$id."'";
	mysql_query($sql1) or die(mysql_error());
	}
	else
	{
	$sql = "update charterer_party_master set NAME='".$txtCPName."', CARGOTYPEID='".$selCType."', CP_TYPE_ID='".$selCPType."', CP_REF='".$txtCPRef."', CP_PDF='".$_SESSION['fileid']."',STATUS='".$selStatus."' where CP_ID='".$id."'";
	mysql_query($sql) or die(mysql_error());
	unlink('../attachment/'.$txtUpload);
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Charterer Party Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	unset($_SESSION['fileid']);
	return $msg;
}

function viewChartererPartyRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM charterer_party_master where CP_ID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['CARGOTYPEID'];
		$this->var_3 = $rows['CP_TYPE_ID'];
		$this->var_4 = $rows['CP_REF'];
		$this->var_5 = $rows['CP_PDF'];
		$this->var_6 = $rows['STATUS'];
	}
}




function displayZoneList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="zone_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="35%"  >Zone Name</th>';
	echo '<th align="left" valign="middle" width="35%"  >Zone Code</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from zone_master order by ZONENAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['ZoneId'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['ZoneName'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['ZoneCode'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateZone.php?id='.$rows['ZoneId'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertZoneMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtZName 				= addslashes(trim($_REQUEST['txtZName']));
	$txtZCode			    = addslashes(trim($_REQUEST['txtZCode']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into zone_master (ZoneName,STATUS,ZoneCode) values ('".$txtZName."','".$selStatus."','".$txtZCode."')";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Zone Added successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateZoneMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtZName 				= addslashes(trim($_REQUEST['txtZName']));
	$txtZCode			 	= addslashes(trim($_REQUEST['txtZCode']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update zone_master set ZoneName='".$txtZName."',STATUS='".$selStatus."',ZoneCode='".$txtZCode."' where ZoneId='".$id."'";
	mysql_query($sql) or die(mysql_error());
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Zone Updated successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewZoneRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM zone_master where ZoneId=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['ZoneName'];
		$this->var_2 = $rows['ZoneCode'];
		$this->var_3 = $rows['STATUS'];
	}
}



function displayVesselList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vessel_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="15%"  >Vessel Name</th>';
	echo '<th align="left" valign="middle" width="15%"  >Vessel Type</th>';
	echo '<th align="left" valign="middle" width="15%"  >Year Built</th>';
	echo '<th align="center" valign="middle" width="8%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from vessel_imo_master where MCOMPANYID='".$_SESSION['company']."' order by VESSEL_NAME";
	$res = mysql_query($sql) or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.strtoupper($rows['VESSEL_NAME']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselTypeBasedOnID($rows['VESSEL_TYPE']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['YEARBUILT'].'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatevessel.php?id='.$rows['VESSEL_IMO_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function insertVesselParticularDetails()
{
	$connect = $this->funConnect();
	$vessel_name 		= addslashes(trim($_REQUEST['txtVName']));
	$vessel_type		= addslashes(trim($_REQUEST['selVType']));
	$builder		    = 0;
	$hull_type			= 0;
	$dwt	 			= addslashes(trim($_REQUEST['txtDWT']));
	$year_built			= addslashes(trim($_REQUEST['txtYBDate']));
	
	$owner				= addslashes(trim($_REQUEST['txtOwner']));
	$coating			= addslashes(trim($_REQUEST['txtCoating']));
	$selBType			= addslashes(trim($_REQUEST['selBType']));
	
	$draftm				= addslashes(trim($_REQUEST['txtDraft']));
	$cranesize			= addslashes(trim($_REQUEST['txtCraneSize']));
	$grabsize			= addslashes(trim($_REQUEST['txtGrabSize']));
	
	$txtIMONo			= addslashes(trim($_REQUEST['txtIMONo']));
	$selFlag			= addslashes(trim($_REQUEST['selFlag']));
	$txtLOA				= addslashes(trim($_REQUEST['txtLOA']));
	$txtEX_Breadth		= addslashes(trim($_REQUEST['txtEX_Breadth']));
	$txtGRT				= addslashes(trim($_REQUEST['txtGRT']));
	$txtGrain			= addslashes(trim($_REQUEST['txtGrain']));
	$txtBale			= addslashes(trim($_REQUEST['txtBale']));
	$txtNOH				= addslashes(trim($_REQUEST['txtNOH']));
	$txtNOHA			= addslashes(trim($_REQUEST['txtNOHA']));
	$txtHatch_Size		= addslashes(trim($_REQUEST['txtHatch_Size']));
	$txtCargo_Gear		= addslashes(trim($_REQUEST['txtCargo_Gear']));
	$txtPI				= addslashes(trim($_REQUEST['txtPI']));
	$selCLASS_SOC		= addslashes(trim($_REQUEST['selCLASS_SOC']));
	$txtRemarks			= addslashes(trim($_REQUEST['txtRemarks']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
		//insert query here.............
		$sql = "insert into vessel_imo_master (VESSEL_NAME,VESSEL_TYPE,BUILDER,HULL_TYPE,DWT,YEARBUILT,ALLOCATE_STATUS,OWNER,COATING ,TRANS_DATE, BUSINESSTYPEID,MCOMPANYID,DRAFTM,CRANESIZE,GRABSIZE,IMO_NO,FLAG,LOA,EXT_BREADTH,GRT_NRT,GRAIN,BALE,NOH,NOHA,HATCH_SIZE,CARGO_GEAR,P_I,CLA_SOC_ID,REMARKS) values ('".$vessel_name."','".$vessel_type."','".$builder."','".$hull_type."','".$dwt."','".$year_built."','0','".$owner."','".$coating."','".date("Y-m-d",time())."','".$selBType."','".$_SESSION['company']."','".$draftm."','".$cranesize."','".$grabsize."','".$txtIMONo."','".$selFlag."','".$txtLOA."','".$txtEX_Breadth."','".$txtGRT."','".$txtGrain."','".$txtBale."','".$txtNOH."','".$txtNOHA."','".$txtHatch_Size."','".$txtCargo_Gear."','".$txtPI."','".$selCLASS_SOC."','".$txtRemarks."')";
		mysql_query($sql) or die($sql);
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Added successfully.',NOW())";
	mysql_query($sql3) or die($sql3);
		mysql_query("commit");
		return $msg; 
}



function getVesselTypeBasedOnID($id)
{
	$this->funConnect();
	$sql = "select VESSELTYPE from vessel_type_master where VESSELTYPEID=".$id;
	$res = mysql_query($sql) or die(mysql_error());
	$rows = mysql_fetch_assoc($res);
	return $rows['VESSELTYPE'];
}

function getVesselTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from vessel_type_master where STATUS = 1 and VesselTypeId NOT IN (6,7,8,9,10,11,12) order by VesselType ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVType = @$_REQUEST['selVType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['VesselTypeId'];
		 $value= $rows['VesselType'];
		 echo "<option value='".$key."' ";
		 if($key == @$selVType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getCountryNameList()
{
	$this->funConnect();
	$query = mysql_query("select * from country_master where STATUS=1 order by COUNTRY_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['COUNTRYID'];
		 $value= $rows['COUNTRY_NAME'];
		 echo"<option value = ".$key." " .">";
		 echo " ".$value." " ."</option>" ;
		}
}


function getClaSocList()
{
	$this->funconnect();
	$query = mysql_query("select * from classification_soc_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CLA_SOC_ID'];
		 $value= $rows['NAME'];
		 echo"<option value = ".$key." " .">";
		 echo " ".$value." " ."</option>" ;
		}
}



function getBusinessTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from business_type_master where STATUS = 1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selBType = @$_REQUEST['selBType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BUSINESSTYPEID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selBType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}



function viewVesselRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vessel_imo_master where VESSEL_IMO_ID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['REGID'];
		$this->var_2 = $rows['VESSEL_NAME'];
		$this->var_3 = $rows['VESSEL_TYPE'];
		$this->var_4 = $rows['BUILDER'];
		$this->var_5 = $rows['HULL_TYPE'];
		$this->var_6 = $rows['DWT'];
		$this->var_7 = $rows['YEARBUILT'];
		$this->var_8 = $rows['OWNER'];
		$this->var_9 = $rows['COATING'];
		$this->var_10 = $rows['BUSINESSTYPEID'];
		$this->var_11 = $rows['DRAFTM'];
		$this->var_12 = $rows['CRANESIZE'];
		$this->var_13 = $rows['GRABSIZE'];
		$this->var_14 = $rows['IMO_NO'];
		$this->var_15 = $rows['FLAG'];
		$this->var_16 = $rows['LOA'];
		$this->var_17 = $rows['EXT_BREADTH'];
		$this->var_18 = $rows['GRT_NRT'];
		$this->var_19 = $rows['GRAIN'];
		$this->var_20 = $rows['BALE'];
		$this->var_21 = $rows['NOH'];
		$this->var_22 = $rows['NOHA'];
		$this->var_23 = $rows['HATCH_SIZE'];
		$this->var_24 = $rows['CARGO_GEAR'];
		$this->var_25 = $rows['P_I'];
		$this->var_26 = $rows['CLA_SOC_ID'];
		$this->var_27 = $rows['REMARKS'];
	}
}


function updateVesselMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtVName 				= addslashes(trim($_REQUEST['txtVName']));
	$selVType 				= addslashes(trim($_REQUEST['selVType']));
	$selBuilder 			= 0;
	$selHullType 			= 0;
	$txtDWT 				= addslashes(trim($_REQUEST['txtDWT']));
	$txtYBDate 				= addslashes(trim($_REQUEST['txtYBDate']));
	$txtOwner 				= addslashes(trim($_REQUEST['txtOwner']));
	$txtCoating 			= addslashes(trim($_REQUEST['txtCoating']));
	$selBType				= addslashes(trim($_REQUEST['selBType']));
	
	$draftm				= addslashes(trim($_REQUEST['txtDraft']));
	$cranesize			= addslashes(trim($_REQUEST['txtCraneSize']));
	$grabsize			= addslashes(trim($_REQUEST['txtGrabSize']));
	
	$txtIMONo			= addslashes(trim($_REQUEST['txtIMONo']));
	$selFlag			= addslashes(trim($_REQUEST['selFlag']));
	$txtLOA				= addslashes(trim($_REQUEST['txtLOA']));
	$txtEX_Breadth		= addslashes(trim($_REQUEST['txtEX_Breadth']));
	$txtGRT				= addslashes(trim($_REQUEST['txtGRT']));
	$txtGrain			= addslashes(trim($_REQUEST['txtGrain']));
	$txtBale			= addslashes(trim($_REQUEST['txtBale']));
	$txtNOH				= addslashes(trim($_REQUEST['txtNOH']));
	$txtNOHA			= addslashes(trim($_REQUEST['txtNOHA']));
	$txtHatch_Size		= addslashes(trim($_REQUEST['txtHatch_Size']));
	$txtCargo_Gear		= addslashes(trim($_REQUEST['txtCargo_Gear']));
	$txtPI				= addslashes(trim($_REQUEST['txtPI']));
	$selCLASS_SOC		= addslashes(trim($_REQUEST['selCLASS_SOC']));
	$txtRemarks			= addslashes(trim($_REQUEST['txtRemarks']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vessel_imo_master set VESSEL_TYPE='".$selVType."',BUILDER='".$selBuilder."',HULL_TYPE='".$selHullType."',DWT='".$txtDWT."',YEARBUILT='".$txtYBDate."',OWNER='".$txtOwner."',COATING='".$txtCoating."',BUSINESSTYPEID='".$selBType."',DRAFTM='".$draftm."',CRANESIZE='".$cranesize."',GRABSIZE='".$grabsize."',IMO_NO='".$txtIMONo."',FLAG='".$selFlag."',LOA='".$txtLOA."',EXT_BREADTH='".$txtEX_Breadth."',GRT_NRT='".$txtGRT."',GRAIN='".$txtGrain."',BALE='".$txtBale."',NOH='".$txtNOH."',NOHA='".$txtNOHA."',HATCH_SIZE='".$txtHatch_Size."',CARGO_GEAR='".$txtCargo_Gear."',P_I='".$txtPI."',CLA_SOC_ID='".$selCLASS_SOC."',REMARKS='".$txtRemarks."'  where  VESSEL_IMO_ID='".$id."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Updated successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function viewAdminRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM login where LOGINID=".$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'];
	}
}

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 login set PASSWORD='".$password."'  where LOGINID='".$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 insertUserDetails()
{


 $connect = $this->funConnect();
 
 $company_id   = $_SESSION['company'];
 $c_person    = addslashes(trim($_REQUEST['txtName']));
 $address   = addslashes(trim($_REQUEST['txtAddress'])); 
 $phone_no    = addslashes(trim($_REQUEST['txtPhoneNo']));
 $emailid    = addslashes(trim($_REQUEST['txtEmailid']));
 $user_name    = addslashes(trim($_REQUEST['txtUName']));
 $password    = addslashes(trim($_REQUEST['txtPassword']));
 $status    = addslashes(trim($_REQUEST['selStatus']));
 $selUserType    = addslashes(trim($_REQUEST['selUserType']));
 
 $msg = 0;
 mysql_query("Set Autocommit=0");
 mysql_query("START TRANSACTION");
 
 $query = "SELECT * FROM login WHERE USERNAME='".$user_name."'";
 $res   = mysql_query($query);
 $rec   = mysql_num_rows($res);

 if($_REQUEST['chk_rm_user'] != ""){

	$rmUser=$_REQUEST['chk_rm_user'];
}else{
	$rmUser=0;
}


	if($_REQUEST['chk_sopf_user'] != ""){

		$sopfUser=$_REQUEST['chk_sopf_user'];
	}else{
		$sopfUser=0;
	}





 
 if($rec == 0)
 { 
  
  $sql = "INSERT INTO login (MCOMPANYID, CONTACT_PERSON, ADDRESS, PHONE_NO, EMAILID, USER_TYPE, STATUS, USERNAME, PASSWORD, LOGIN_STATUS,RM_USER,SOPF_USER) values ('".$company_id."','".$c_person."','".$address."','".$phone_no."','".$emailid."','".$selUserType."','".$status."','".$user_name."','".$password."','OFFLINE','".$rmUser."','".$sopfUser."')";
  
  mysql_query($sql) or die(mysql_error());
  mysql_query("commit");
  
  $mysql  = "SELECT max(LOGINID) as max FROM login";
  $myres  = mysql_query($mysql);
  $myrows = mysql_fetch_assoc($myres);
  
  $sql2 = "INSERT INTO audit_trail (LOGINID, USERNAME, PASSWORD, DATE_ON) values ('".$myrows['max']."', '".$user_name."', '".$password."', '".date('Y-m-d',time())."')";
  
  mysql_query($sql2) or die(mysql_error());
  
  for($i=1;$i<=29;$i++)
  {
   $link_auth = "";
   if($_REQUEST['checkbox_'.$i.'_1'] != "")
   {
    $link_auth .= $_REQUEST['checkbox_'.$i.'_1'];
   }
   if($_REQUEST['checkbox_'.$i.'_2'] != "")
   {
	   if($link_auth!=''){$link_auth.= ',';}
    $link_auth .= $_REQUEST['checkbox_'.$i.'_2'];
   }
   if($_REQUEST['checkbox_'.$i.'_3'] != "")
   {
	   if($link_auth!=''){$link_auth.= ',';}
    $link_auth .= $_REQUEST['checkbox_'.$i.'_3'];
   }
   
   if($link_auth != "")
   {
    for($k=1;$k<=29;$k++)
    {
     $sql1 = "INSERT into user_rights (LOGINID,MODULEID,LINKID,LINK_AUTH) values ('".$myrows['max']."','".$k."','".$i."','".$link_auth."')";
     mysql_query($sql1) or die(mysql_error());
     mysql_query("commit");
    }
   }
  }
  
 }else{
  $msg = 1;
 }
 
 $sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Shipping User Details added successfully.',NOW())";
 mysql_query($sql3) or die(mysql_error());
 mysql_query("commit");

 return $msg; 
}

function displayUserCreationList()
{
	$connect = $this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="user_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="middle" width="10%"  >Company Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Name</th>';
	echo '<th align="left" valign="middle" width="15%"  >User Type</th>';	
	echo '<th align="left" valign="middle" width="10%"  >E-mail ID</th>';
	echo '<th align="left" valign="middle" width="10%"  >User Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Password</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '<th align="center" valign="middle" width="5%" >Pdf</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM login WHERE USER_TYPE in ('internal_user', 'mgmt_user','rm_user') and MCOMPANYID='".$_SESSION['company']."' order by CONTACT_PERSON,STATUS";
	$res = mysql_query($sql)  or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getCompanyData($rows['MCOMPANYID'],"COMPANY_NAME").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CONTACT_PERSON'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['USER_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EMAILID'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['USERNAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PASSWORD'].'</td>';
				/*&nbsp;|&nbsp;<a href="master_user_rights.php?id='.$rows['LOGINID'].'" title="Edit Master Rights" ><i class="fa fa-edit "></i></a>*/
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_user.php?id='.$rows['LOGINID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';
				echo '<td align="center" valign="middle" class="input-text"><a title="Generate PDF for Audit Trail" href="#Pdf" onclick="getPdf('.$rows['LOGINID'].');" ><i class="fa fa-download"></i></a>&nbsp;|&nbsp;<a title="Generate PDF for Access Log" href="#Pdf" onclick="getPdf1('.$rows['LOGINID'].');" ><i class="fa fa-download"></i></a></td>';
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function viewUserRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM login WHERE LOGINID=".$id;
	$result = mysql_query($query);
	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['MODULES'];
		$this->var_10 = $rows['USER_TYPE'];
		$this->var_11 = $rows['RM_USER'];

		$this->var_12 = $rows['DIS_PL'];

		$this->var_13 = $rows['SOPF_USER'];
	}
}

function getUserRights($loginid,$moduleid,$linkid)
{
	$connect = $this->funConnect();
	$sql = "SELECT LINK_AUTH FROM user_rights WHERE LOGINID='".$loginid."' and MODULEID='".$moduleid."' and LINKID='".$linkid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$arr = explode(",",$rows['LINK_AUTH']);
	return $arr;
}

function updateUserRecords()
{



	$connect			= $this->funConnect();
	$id 				= $_REQUEST['id'];
 	$c_person 			= addslashes(trim($_REQUEST['txtName']));
	$address			= addslashes(trim($_REQUEST['txtAddress']));	
	$phone_no 			= addslashes(trim($_REQUEST['txtPhoneNo']));
	$emailid 			= addslashes(trim($_REQUEST['txtEmailid']));
	$user_name 			= addslashes(trim($_REQUEST['txtUName']));
	$password 			= addslashes(trim($_REQUEST['txtPassword']));
	$status 			= addslashes(trim($_REQUEST['selStatus']));
	$selUserType    = addslashes(trim($_REQUEST['selUserType']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	if($_REQUEST['chk_rm_user'] != ""){

		$rmUser=$_REQUEST['chk_rm_user'];
	}else{
		$rmUser=0;
	}

	if($_REQUEST['chk_sopf_user'] != ""){

		$sopfuser=$_REQUEST['chk_sopf_user'];
	}else{
		$sopfuser=0;
	}


	$countUserPl    = addslashes(trim($_REQUEST['countUserPl']));

	$disPL=array();
	$o=1;
	for($p=1;$p<=$countUserPl;$p++){
		if($_REQUEST['checkboxForPl_'.$o.'_'.$p.''] != ""){

			$disPL[]=$_REQUEST['user_'.$p.''];
		}else{
			$disPL[]=0;
		}

		$o++;

	}


	// echo '<pre>';

	// print_r($_REQUEST);
	// die();




	
	
	// echo '<pre>';

	// print_r($disPL);
	// die();


	$msg = 0;

	$sql = "UPDATE login set ADDRESS='".$address."',PHONE_NO='".$phone_no."',EMAILID='".$emailid."', USER_TYPE='".$selUserType."', CONTACT_PERSON='".$c_person."', STATUS='".$status."', USERNAME='".$user_name."', PASSWORD='".$password."', LOGIN_STATUS='OFFLINE', RM_USER='".$rmUser."', DIS_PL='".serialize($disPL)."', SOPF_USER='".$sopfuser."'  WHERE LOGINID='".$id."'";
	
	mysql_query($sql) or die($sql);	
	mysql_query("commit"); 
	
	$sql2 = "INSERT into audit_trail (LOGINID, USERNAME, PASSWORD, DATE_ON) values ('".$id."', '".$user_name."', '".$password."', '".date('Y-m-d',time())."')";
	mysql_query($sql2) or die($sql2);
	
	$del_query = "delete FROM user_rights WHERE LOGINID=".$id;
	mysql_query($del_query) or die($del_query);	
	mysql_query("commit");
	
	for($i=1;$i<=29;$i++)
	{
		$link_auth = "";
		if($_REQUEST['checkbox_'.$i.'_1'] != "")
		{
			$link_auth.= $_REQUEST['checkbox_'.$i.'_1'];
		}
		if($_REQUEST['checkbox_'.$i.'_2'] != "")
		{
			if($link_auth!=''){$link_auth.= ',';}
			$link_auth.= $_REQUEST['checkbox_'.$i.'_2'];
		}
		
		if($_REQUEST['checkbox_'.$i.'_3'] != "")
		{
			if($link_auth!=''){$link_auth.= ',';}
			$link_auth.= $_REQUEST['checkbox_'.$i.'_3'];
		}
	
		if($link_auth != "")
			{
				for($k=1;$k<=29;$k++)
				{
					$sql1 = "INSERT into user_rights (LOGINID,MODULEID,LINKID,LINK_AUTH) values ('".$id."','".$k."','".$i."','".$link_auth."')";
					mysql_query($sql1)  or die($sql1);
					mysql_query("commit");
				}
			}
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Shipping User Details updated successfully.',NOW())";
	mysql_query($sql3) or die($sql3);
	mysql_query("commit");
	
	return $msg;
}




function updateUserRightsRecords()
{
	$connect		= $this->funConnect();
	$id           	= $_REQUEST['id'];
 	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	
	$del_query = "delete FROM internal_user_rights WHERE LOGINID=".$id;
	mysql_query($del_query);	
	mysql_query("commit");
	
	for($i=1;$i<=4;$i++)
	{
		if($_REQUEST['checkbox_'.$i] != ""){$link_auth = $_REQUEST['checkbox_'.$i];}else{$link_auth = "";}
		if($link_auth != "")
		{
		for($k=1;$k<=6;$k++)
			{
				$sql1 = "INSERT into internal_user_rights (LOGINID,MODULEID,LINKID,LINK_AUTH) values ('".$id."','".$k."','".$i."','".$link_auth."')";
				mysql_query($sql1,$connect);
				mysql_query("commit");
			}
		}
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Shipping User Rights Details updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	
	return $msg;
}

function getInternalUserRights($loginid,$moduleid,$linkid)
{
	$connect = $this->funConnect();
	$sql = "SELECT LINK_AUTH FROM internal_user_rights WHERE LOGINID='".$loginid."' and MODULEID='".$moduleid."' and LINKID='".$linkid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$arr = explode(",",$rows['LINK_AUTH']);
	return $arr;
}

function getExternalUserTypeList()
{
$state = array( 'Traders'=>'Trading Desk','Broker'=>'Broker' );
$selUType = @$_REQUEST['selUType'];
echo "<option value=''>--Select from list--</option>";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		echo "<option value=$key";
		if($key == $selUType){ echo " selected";}
		echo ">".$value."</option>";
		}
}

function getProductListForUser()
{
$state = array( 5 =>'COD &ndash; In', 6 =>'COD &ndash; Out');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function displayOtherUserCreationList()
{
	$connect = $this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="other_user_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="middle" width="10%"  >Company Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Name</th>';
	echo '<th align="left" valign="middle" width="15%"  >Address</th>';	
	echo '<th align="left" valign="middle" width="10%"  >E-mail ID</th>';
	echo '<th align="left" valign="middle" width="10%"  >User Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Password</th>';
	echo '<th align="left" valign="middle" width="10%"  >User Type</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="2%" >Details</th>';
	echo '<th align="center" valign="middle" width="7%" >Pdf</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM login WHERE USER_TYPE in ('Broker','Finance','Traders') AND MCOMPANYID='".$_SESSION['company']."' ORDER BY CONTACT_PERSON,STATUS";
	$res = mysql_query($sql)  or die(mysql_error());
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getCompanyData($rows['MCOMPANYID'],"COMPANY_NAME").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CONTACT_PERSON'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['ADDRESS'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EMAILID'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['USERNAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PASSWORD'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['USER_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getUserStatusBasedOnID($rows['STATUS']).'</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_other_user.php?id='.$rows['LOGINID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';
				echo '<td align="center" valign="middle" class="input-text"><a title="Generate PDF for Audit Trail" href="#Pdf" onclick="getPdf('.$rows['LOGINID'].');" ><i class="fa fa-download"></i></a>&nbsp;|&nbsp;<a title="Generate PDF for Access Log" href="#Pdf" onclick="getPdf1('.$rows['LOGINID'].');" ><i class="fa fa-download"></i></a></td>';
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertOtherUserDetails()
{
	$connect 			= $this->funConnect();
	$company_id			= $_SESSION['company'];
	$c_person 			= addslashes(trim($_REQUEST['txtName']));
	$address			= addslashes(trim($_REQUEST['txtAddress']));	
	$phone_no 			= addslashes(trim($_REQUEST['txtPhoneNo']));
	$emailid 			= addslashes(trim($_REQUEST['txtEmailid']));
	$user_name 			= addslashes(trim($_REQUEST['txtUName']));
	$password 			= addslashes(trim($_REQUEST['txtPassword']));
	$status 			= addslashes(trim($_REQUEST['selStatus']));
	
	$user_type 			= addslashes(trim($_REQUEST['selUType']));
	$product      		= implode(",",$_REQUEST['selCProduct']);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$query = "SELECT * FROM login WHERE USERNAME='".$user_name."'";
	$res = mysql_query($query);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql = "INSERT INTO login (MCOMPANYID,CONTACT_PERSON,ADDRESS,PHONE_NO,EMAILID,USER_TYPE,STATUS,USERNAME,PASSWORD,MODULES) values ('".$company_id."','".$c_person."','".$address."','".$phone_no."','".$emailid."','".$user_type."','".$status."','".$user_name."','".$password."','".$product."')";
		mysql_query($sql,$connect);
		mysql_query("commit");
		
		$sql1 = "SELECT max(LOGINID) as max FROM login";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$sql2 = "INSERT INTO audit_trail (LOGINID, USERNAME, PASSWORD, DATE_ON) values ('".$rows1['max']."', '".$user_name."', '".$password."', '".date('Y-m-d',time())."')";
		mysql_query($sql2);
		mysql_query("commit");
		
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other User Details added successfully.',NOW())";
		mysql_query($sql3) or die(mysql_error());
		mysql_query("commit");
	}
	else
	{
		$msg = 1;
	}

	return $msg; 
}

function viewOtherUserRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM login WHERE LOGINID=".$id;
	$result = mysql_query($query);
	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['MODULES'];
		$this->var_10 = $rows['USER_TYPE'];
	}
}

function getProductListForUserForUpdate($modules)
{
	$this->funConnect();
	$product_id = '5,6,7';
	$arr = explode(",",$product_id);
	$m_arr = explode(",",$modules);
	for($i=0;$i<count($arr);$i++)
	{
		 $key= $arr[$i];
		 $value= $this->getProductShortNameBasedOnID($arr[$i]);
		 echo "<option value='".$key."' ";
		 if (in_array($key, $m_arr)) { echo " selected";}
		 echo ">".$value."</option>";
	}
}

function getProductShortNameBasedOnID($id)
{
	if($id == 1){return 'CMW';}
	if($id == 2){return 'COW &ndash; In';}
	if($id == 3){return 'COW &ndash; Out';}
	if($id == 4){return 'CMD';}
	if($id == 5){return 'COD &ndash; In';}
	if($id == 6){return 'COD &ndash; Out';}
	if($id == 7){return 'Vessel Relet';}
}

function updateOtherUserRecords()
{
	$connect			= $this->funConnect();
	$id 				= $_REQUEST['id'];
 	$c_person 			= addslashes(trim($_REQUEST['txtName']));
	$address			= addslashes(trim($_REQUEST['txtAddress']));	
	$phone_no 			= addslashes(trim($_REQUEST['txtPhoneNo']));
	$emailid 			= addslashes(trim($_REQUEST['txtEmailid']));
	$user_name 			= addslashes(trim($_REQUEST['txtUName']));
	$password 			= addslashes(trim($_REQUEST['txtPassword']));
	$status 			= addslashes(trim($_REQUEST['selStatus']));
	
	$user_type 			= addslashes(trim($_REQUEST['selUType']));
	$product      		= implode(",",$_REQUEST['selCProduct']);

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "UPDATE login SET ADDRESS='".$address."',PHONE_NO='".$phone_no."',EMAILID='".$emailid."',CONTACT_PERSON='".$c_person."',STATUS='".$status."',USERNAME='".$user_name."',PASSWORD='".$password."',MODULES='".$product."',USER_TYPE='".$user_type."'  WHERE LOGINID='".$id."'";
	
	mysql_query($sql);	
	mysql_query("commit"); 
	
	$sql2 = "INSERT INTO audit_trail (LOGINID, USERNAME, PASSWORD, DATE_ON) values ('".$id."', '".$user_name."', '".$password."', '".date('Y-m-d',time())."')";
	mysql_query($sql2);
	mysql_query("commit");
	
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other User Details updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	
	return $msg;
}


function VesselAllocationTab()
{
	$connect = $this->funConnect();
	$value     = $_REQUEST['numvsl'];
	$msg     = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	for($i=1;$i<=$value;$i++)
	{
		if(isset($_REQUEST['checkIMObox1_'.$i]))
		{
			$sql = "select * from vessel_allocation_master where VESSEL_IMO_ID='".$_REQUEST['checkIMObox1_'.$i]."' ";
			$res = mysql_query($sql);
			$rec = mysql_num_rows($res);
			if($rec == 0)
			{
				$product   = implode(",",$_REQUEST['selCProduct1_'.$i]);
				$sql2     = "insert into vessel_allocation_master (VESSEL_IMO_ID,TRANS_DATE,MODULE_ID,MCOMPANYID) values ('".$_REQUEST['checkIMObox1_'.$i]."','".date("Y-m-d",time())."','".$product."','".$_SESSION['company']."')";
				//echo $sql2;
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
			}else{
				$product   = implode(",",$_REQUEST['selCProduct1_'.$i]);
				$sql2 = "update vessel_allocation_master set MODULE_ID='".$product."'  where VESSEL_IMO_ID='".$_REQUEST['checkIMObox1_'.$i]."' and MCOMPANYID='".$_SESSION['company']."' ";
				//echo $sql2;
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
	}//die();
	mysql_query("commit");
	return $msg; 
}


function displayBankingDetailList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="banking_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle">#</th>';
	echo '<th align="left" valign="middle">Name Of Beneficiary</th>';
	echo '<th align="left" valign="middle">Address</th>';
	echo '<th align="left" valign="middle">Status</th>';
	echo '<th align="center" valign="middle">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from banking_details order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle">'.$i.'.</td>';
				echo '<td align="left" valign="middle">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle">'.$rows['ADDRESS'].'</td>';
				echo '<td align="left" valign="middle">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['BD_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['BD_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle"><a href="updatebankingdetails.php?id='.$rows['BD_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function changeBankingDetailStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	//echo $tblid;die;
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update banking_details set STATUS='".$tblstatus."' where BD_ID='".$tblid."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Banking Detail Record Status Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function insertBankingDetails()
{
	$connect = $this->funConnect();
	$txtNOB 		= addslashes(trim($_REQUEST['txtNOB']));
	$txtAdd 		= addslashes(trim($_REQUEST['txtAdd']));
	$txtBAcc_No 	= addslashes(trim($_REQUEST['txtBAcc_No']));
	$txtBBank 		= addslashes(trim($_REQUEST['txtBBank']));
	$txtBBank_SCode = addslashes(trim($_REQUEST['txtBBank_SCode']));
	$txtIBAN_No 	= addslashes(trim($_REQUEST['txtIBAN_No']));
	$txtIFSC_No 	= addslashes(trim($_REQUEST['txtIFSC_No']));
	$txtFed_Aba 	= addslashes(trim($_REQUEST['txtFed_Aba']));
	$txtCID 		= addslashes(trim($_REQUEST['txtCID']));
	$txtCBN 		= addslashes(trim($_REQUEST['txtCBN']));
	$txtSCN 		= addslashes(trim($_REQUEST['txtSCN']));
	$txtRef 		= addslashes(trim($_REQUEST['txtRef']));
	$txtBID 		= addslashes(trim($_REQUEST['txtBID']));
	$txtBAdd 		= addslashes(trim($_REQUEST['txtBAdd']));
	$txtBBANCB 		= addslashes(trim($_REQUEST['txtBBANCB']));
	$txtCorresAdd   = addslashes(trim($_REQUEST['txtCorresAdd']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into banking_details (NAME, ADDRESS, AC_NO, MODULEID, MCOMPANYID, BANK, BANK_SWIFT_CODE, IBAN_NO, FED_ABA, C_BANK_NAME, C_SWIFT_CODE, REFERENCE, B_ADDRESS, B_ACNO, CORRES_ADDRESS, IFSC) values ('".$txtNOB."','".$txtAdd."','".$txtBAcc_No."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$txtBBank."','".$txtBBank_SCode."','".$txtIBAN_No."','".$txtFed_Aba."','".$txtCBN."','".$txtSCN."','".$txtRef."','".$txtBAdd."', '".$txtBBANCB."', '".$txtCorresAdd."', '".$txtIFSC_No."')";
	mysql_query($sql);
	mysql_query("commit");
	
	$sql1 = "select max(BD_ID) as max from banking_details";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	//echo $txtCID,$txtBID;
	for($i=1;$i<=$txtCID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtBDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtBDValue_'.$i])) != '')
		{
			$sql2 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$rows1['max']."', '".addslashes(trim($_REQUEST['txtBDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtBDValue_'.$i]))."', 1)";
			mysql_query($sql2);
		}
	}
	
	for($i=1;$i<=$txtBID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtCDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtCDValue_'.$i])) != '')
		{
			$sql3 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$rows1['max']."', '".addslashes(trim($_REQUEST['txtCDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtCDValue_'.$i]))."', 2)";
			mysql_query($sql3);
		}
	}
    $sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Banking Detail Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}


function viewBankingDetailsRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM banking_details where BD_ID='".$id."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['ADDRESS'];
		$this->var_3 = $rows['AC_NO'];
		$this->var_4 = $rows['BANK'];
		$this->var_5 = $rows['BANK_SWIFT_CODE'];
		$this->var_6 = $rows['IBAN_NO'];
		$this->var_7 = $rows['FED_ABA'];
		$this->var_8 = $rows['C_BANK_NAME'];
		$this->var_9 = $rows['C_SWIFT_CODE'];
		$this->var_10 = $rows['REFERENCE'];
		$this->var_11 = $rows['B_ADDRESS'];
		$this->var_12 = $rows['B_ACNO'];
		$this->var_13 = $rows['CORRES_ADDRESS'];
		$this->var_14 = $rows['IFSC'];
	}
}

function updateBankingDetailsRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtNOB 		= addslashes(trim($_REQUEST['txtNOB']));
	$txtAdd 		= addslashes(trim($_REQUEST['txtAdd']));
	$txtBAcc_No 	= addslashes(trim($_REQUEST['txtBAcc_No']));
	$txtBBank 		= addslashes(trim($_REQUEST['txtBBank']));
	$txtBBank_SCode = addslashes(trim($_REQUEST['txtBBank_SCode']));
	$txtIBAN_No 	= addslashes(trim($_REQUEST['txtIBAN_No']));
	$txtIFSC_No 	= addslashes(trim($_REQUEST['txtIFSC_No']));
	$txtFed_Aba 	= addslashes(trim($_REQUEST['txtFed_Aba']));
	$txtCID 		= addslashes(trim($_REQUEST['txtCID']));
	$txtCBN 		= addslashes(trim($_REQUEST['txtCBN']));
	$txtSCN 		= addslashes(trim($_REQUEST['txtSCN']));
	$txtRef 		= addslashes(trim($_REQUEST['txtRef']));
	$txtBID 		= addslashes(trim($_REQUEST['txtBID']));
	$txtBAdd 		= addslashes(trim($_REQUEST['txtBAdd']));
	$txtBBANCB 		= addslashes(trim($_REQUEST['txtBBANCB']));
	$txtCorresAdd   = addslashes(trim($_REQUEST['txtCorresAdd']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update banking_details set NAME='".$txtNOB."',ADDRESS='".$txtAdd."',AC_NO='".$txtBAcc_No."',BANK='".$txtBBank."',BANK_SWIFT_CODE='".$txtBBank_SCode."',IBAN_NO='".$txtIBAN_No."',FED_ABA='".$txtFed_Aba."',C_BANK_NAME='".$txtCBN."',C_SWIFT_CODE='".$txtSCN."',REFERENCE='".$txtRef."',B_ADDRESS='".$txtBAdd."',B_ACNO='".$txtBBANCB."', CORRES_ADDRESS='".$txtCorresAdd."', IFSC='".$txtIFSC_No."' where BD_ID='".$id."' ";
	mysql_query($sql);
	
	$sql1 = "delete from banking_details_slave where BD_ID='".$id."'";
	mysql_query($sql1);
	
	for($i=1;$i<=$txtCID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtBDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtBDValue_'.$i])) != '')
		{
			$sql2 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$id."', '".addslashes(trim($_REQUEST['txtBDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtBDValue_'.$i]))."', 1)";
			mysql_query($sql2);
		}
	}
	
	for($i=1;$i<=$txtBID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtCDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtCDValue_'.$i])) != '')
		{
			$sql3 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$id."', '".addslashes(trim($_REQUEST['txtCDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtCDValue_'.$i]))."', 2)";
			mysql_query($sql3);
		}
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Banking Details Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function getUserTypeList()
{
$state = array('internal_user' =>'Internal User', 'mgmt_user' =>'Management User', 'rm_user' =>'Risk Management User');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value='".$key."'";
		if($key == $_REQUEST['selUserType']){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function updateApprovalMatricRecords()
{
    $connect = $this->funConnect();
 
    $txtROWID    = addslashes(trim($_REQUEST['txtROWID']));
 
    $msg = 0;
    mysql_query("Set Autocommit=0");
    mysql_query("START TRANSACTION");
 
    $sqldel = "delete from approval_matrix where MCOMPANYID='".$_SESSION['company']."'";
	//echo $sqldel;die;
	mysql_query($sqldel) or die($sqldel);
	mysql_query("commit");
 
	for($i=1;$i<=$txtROWID;$i++)
	{
		 $sql1 = "INSERT into approval_matrix (LOGINID, MCOMPANYID, INI_FREIGHT_CHK_CRETR, INI_FREIGHT_CHK_APP_1, INI_FREIGHT_CHK_APP_2, FINL_FREIGHT_CHK_CRETR, FINL_FREIGHT_CHK_APP_1, FINL_FREIGHT_CHK_APP_2, HIRE_INVOICE_CHK_CRETR, HIRE_INVOICE_CHK_APP_1, HIRE_INVOICE_CHK_APP_2, HIRE_STSTMENT_CHK_CRETR, HIRE_STSTMENT_CHK_APP_1, HIRE_STSTMENT_CHK_APP_2, HIRE_STSTMENT_CHK_ACC, PDA_CHK_CRETR, PDA_CHK_APP_1, PDA_CHK_APP_2, FDA_CHK_CRETR, FDA_CHK_APP_1, FDA_CHK_APP_2, FDA_CHK_ACC, OTHER_PAYMENT_CHK_CRETR, OTHER_PAYMENT_CHK_APP_1, OTHER_PAYMENT_CHK_APP_2, LAYTIME_CHK_CRETR, LAYTIME_CHK_APP_1, LAYTIME_CHK_APP_2, LAYTIME_CHK_OPEN, INI_FREIGHT_CHK_ACC, FINL_FREIGHT_CHK_ACC, HIRE_INVOICE_CHK_ACC, PDA_CHK_ACC, OTHER_PAYMENT_CHK_ACC, SOA_CHK_CRETR, SOA_CHK_APP_1, SOA_CHK_APP_2, SOA_CHK_ACC,PAYMENT_UNLOCK,GEN_CHK_CRETR,GEN_CHK_APP_1,GEN_CHK_APP_2,GEN_CHK_ACC) values ('".$_REQUEST['txtLOGINID_'.$i]."', '".$_SESSION['company']."', '".$this->getNullValues($_REQUEST['checkbox_1_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_2_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_3_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_4_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_5_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_6_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_7_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_8_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_9_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_10_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_11_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_12_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_13_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_14_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_15_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_16_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_17_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_18_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_19_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_20_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_21_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_22_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_23_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_24_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_25_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_26_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_27_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_28_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_29_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_30_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_31_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_32_'.$i])."'   , '".$this->getNullValues($_REQUEST['checkbox_33_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_34_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_35_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_36_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_37_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_38_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_39_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_40_'.$i])."', '".$this->getNullValues($_REQUEST['checkbox_41_'.$i])."')";
		 mysql_query($sql1) or die($sql1);
		 mysql_query("commit");
	}
 
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Approval Matrix data added/updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");

    return $msg; 
}


function getNullValues($values)
{
    if($values =='' || !isset($values))
	{
	    $values = 0;
	}
    return $values;
}

} // class data ends
?>