<?php
session_start();
 header("Content-type: text/html; charset=windows-1256");
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_UserAccess.php");
include("function.inc.php");
include("form_Customergrid.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536)
		or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querymodule="select ifnull(module_visit,0) as module_visit from module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$PActionMode   = $_GET['PActionMode'];if ($PActionMode == ""){$PActionMode = $_POST["PActionMode"];}

$frm   = $_GET['frm'];if ($frm == ""){$frm = $_POST["frm"];}
$txtId = $_GET['txtId'];if ($txtId == ""){$txtId = $_POST["txtId"];}
$customer_officeId = $_GET['customer_officeId'];if ($customer_officeId == ""){$customer_officeId = $_POST["customer_officeId"];}
$contactinfo_id = $_GET['contactinfo_id'];if ($contactinfo_id == ""){$contactinfo_id = $_POST["contactinfo_id"];}
$customer_officeId2 = $_GET['customer_officeId2'];if ($customer_officeId2 == ""){$customer_officeId2 = $_POST["customer_officeId2"];}
$contactinfo_id2 = $_GET['contactinfo_id2'];if ($contactinfo_id2 == ""){$contactinfo_id2 = $_POST["contactinfo_id2"];}
$customerproject_id = $_GET['customerproject_id'];if ($customerproject_id == ""){$customerproject_id = $_POST["customerproject_id"];}
$actionmode = $_GET['actionmode'];if ($actionmode == ""){$actionmode = $_POST["actionmode"];}
$PCustomerCode = $_GET['PCustomerCode'];if ($PCustomerCode == ""){$PCustomerCode = $_POST["PCustomerCode"];}
$mode = $_GET['mode'];if ($mode == ""){$mode = $_POST["mode"];}


	if($txtgroupname == '') $txtgroupname = "NULL";
	else $txtgroupname = "'".$txtgroupname."'";
	if($txtdescname == '') $txtdescname = "NULL";
	else $txtdescname = "'".$txtdescname."'";
	if($txtEmail == '') $txtEmail = "NULL";
	else $txtEmail = "'".$txtEmail."'";
	
	/*
	if($txtAddress == '') $txtAddress = "NULL";
	else $txtAddress = "'".$txtAddress."'";	
	*/
	 
	
	
	// by rod
	
	if ($_POST['txtaddressencoded'] == '' )
	{
		$txtaddressencoded = "NULL";
		
    }
  
   else
	   
	{
		
		 
		$txtaddressencoded = ereg_replace("'","\'" , trim($_POST['txtaddressencoded']));
		$txtaddressencoded = "'" .$txtaddressencoded . "'";
		
		
		
    }

    // .ereg_replace("'", "\'", trim( "'" .$_POST['txtaddressencoded']."'")).
	
	// end by rod
	
	
	if($txtWebsite == '') $txtWebsite = "NULL";
	else $txtWebsite = "'".$txtWebsite."'";	
	
	
if($txtCustomerSpecial == '')	$txtCustomerSpecial=0;
	
if($actionmode == 'deleteCustomer'){
	$querycheck = "select * from visit where customer_code='$PCustomerCode' ";
	$rescheck = mysql_query($querycheck,$connection);
	$numrw = mysql_num_rows($rescheck);
	if($numrw > 0){
	$message = "Cannot Delete Customer Already in Use!";
	header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Customer&message=".$message);
	exit;	
	} else {
		$querydel1 = "delete from CustomerContactInfo where customeroffice_id in
					(select customer_officeId from Customer_Offices where Customer_Code='$PCustomerCode')";
		$res1 = mysql_query($querydel1,$connection);			
		$querydel2 = "delete from Customer_Offices where Customer_Code='$PCustomerCode'";
		$res2 = mysql_query($querydel2,$connection);
		$querydel3 = "delete from customer_project where Customer_Code='$PCustomerCode'";
		$res3 = mysql_query($querydel4,$connection);
		$querydel4 = "delete from customer where Customer_Code='$PCustomerCode'";
		$res4 = mysql_query($querydel4,$connection);
	header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PLedgerNo=".$PLedgerNo."&message=".$message);	
	exit;
	}

}
 	
else if(($actionmode == 'submitmain' || $actionmode == 'confirmMaininfo' ) && $PCustomerCode != ''){
	if($txtmaincontact == '') $txtmaincontact = "NULL";
	else $txtmaincontact = "'".$txtmaincontact."'";
	

	
	
	if($customer_officeId == ''){
		$queryins = "insert into Customer_Offices (Customer_Code, office_address, office_contact) ".
					" values ('$PCustomerCode','$txtmainaddress',$txtmaincontact)";
		//echo $queryins;exit;	
		$resins = mysql_query($queryins,$connection);
		if($resins) $customer_officeId = mysql_insert_id(); 	
		else $message=mysql_error(); 
	} else {
		$queryupdate = "update Customer_Offices set ".
					   "office_address='$txtmainaddress', ".
					   "office_contact=$txtmaincontact ".
					   "where customer_officeId=$customer_officeId";
		//echo $queryins;exit;	
		$resupdate = mysql_query($queryupdate,$connection);
		if(!$resupdate) $message=mysql_error(); 
	}
	if($actionmode == 'confirmMaininfo'){
		
		if($txtctfathername == '') $txtctfathername = "NULL";
		else $txtctfathername = "'".$txtctfathername."'";
		if($txtctphone2 == '') $txtctphone2 = "NULL";
		else $txtctphone2 = "'".$txtctphone2."'";
		if($txtctphone3 == '') $txtctphone3 = "NULL";
		else $txtctphone3 = "'".$txtctphone3."'";
		
		if($txtctemail1 == '') $txtctemail1 = "NULL";
		else $txtctemail1 = "'".$txtctemail1."'";
		if($txtctemail2 == '') $txtctemail2 = "NULL";
		else $txtctemail2 = "'".$txtctemail2."'";
		
		if($txtctwebsite == '') $txtctwebsite = "NULL";
		else $txtctwebsite = "'".$txtctwebsite."'";
				
		if($contactinfo_id == ''){
		$queryins = "insert into CustomerContactInfo (customeroffice_id, contact_firstname, contact_fathername, contact_lastname, 
					contact_position, contact_phone1, contact_phone2, contact_phone3, contact_email1, contact_email2, contact_website) ".
					" values ($customer_officeId,'$txtctfirstname',$txtctfathername,'$txtctlastname','$txtctposition',".
					" '$txtctphone1',$txtctphone2,$txtctphone3,$txtctemail1,$txtctemail2,$txtctwebsite)";
	
		$resins = mysql_query($queryins,$connection);
		if(!$resins) $message=mysql_error(); 
	} else {
		$queryupdate = "update CustomerContactInfo set ".
					"contact_firstname='$txtctfirstname', ".
					"contact_fathername=$txtctfathername, ".
					"contact_lastname='$txtctlastname', ".
					"contact_position='$txtctposition', ".
					"contact_phone1='$txtctphone1', ".
					"contact_phone2=$txtctphone2, ".
					"contact_phone3=$txtctphone3, ".
					"contact_email1=$txtctemail1, ".
					"contact_email2=$txtctemail2, ".
					"contact_website=$txtctwebsite where  contactinfo_id=$contactinfo_id";
		//echo $queryins;exit;	
		$resupdate = mysql_query($queryupdate,$connection);
		if(!$resupdate) $message=mysql_error(); 
	}
	}
if($actionmode == 'submitmain')
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Main%20Office&message=".$message);
else{
	//echo $message;
	//echo "[BRK]";
	$contactinfo_id='';
	echo mainContactInfo($customer_officeId,$contactinfo_id,$grid_color1,$grid_color2,$connection);
	exit;
}
}
else if($actionmode == 'deleteMaininfo'){ 
	if($contactinfo_id !=''){
		$querydel = "delete from CustomerContactInfo where contactinfo_id = $contactinfo_id";
		$resdel = mysql_query($querydel,$connection); 
	} 
	$contactinfo_id='';
	echo mainContactInfo($customer_officeId,$contactinfo_id,$grid_color1,$grid_color2,$connection);
	exit;
}
else if($actionmode == 'deletemain' && $PCustomerCode != ''){ 
	if($customer_officeId !=''){
		$querydel1 = "delete from CustomerContactInfo where customeroffice_id in (select customer_officeId 
		from Customer_Offices where mainoffice_id = $customer_officeId)";
		$resdel1 = mysql_query($querydel1,$connection); 
		$querydel2 = "delete from CustomerContactInfo where customeroffice_id = $customer_officeId";
		$resdel2 = mysql_query($querydel3,$connection); 
		$querydel3 = "delete from Customer_Offices where mainoffice_id = $customer_officeId";
		$resdel3 = mysql_query($querydel3,$connection); 
		$queryde4 = "delete from Customer_Offices where customer_officeId = $customer_officeId";
		$resde4 = mysql_query($queryde4,$connection); 
	} 
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Main%20Office&message=".$message);
	
}
else if( $actionmode == 'UpdateMaininfo'){
	echo mainContactInfo($customer_officeId,$contactinfo_id,$grid_color1,$grid_color2,$connection);
	exit;
}
	
else if(($actionmode == 'submitbranch' || $actionmode == 'confirmBranchinfo' ) && $PCustomerCode != ''){
	if($txtbranchcontact == '') $txtbranchcontact = "NULL";
	else $txtbranchcontact = "'".$txtbranchcontact."'";
	

	
	
	if($customer_officeId2 == ''){
		$queryins = "insert into Customer_Offices (Customer_Code, office_address, office_contact,mainoffice_id) ".
					" values ('$PCustomerCode','$txtbranchaddress',$txtbranchcontact,$txtparentaddress)";
		//echo $queryins;exit;	
		$resins = mysql_query($queryins,$connection);
		if($resins) $customer_officeId2 = mysql_insert_id(); 	
		else $message=mysql_error(); 
	} else {
		$queryupdate = "update Customer_Offices set ".
					   "office_address='$txtbranchaddress', ".
					   "office_contact=$txtbranchcontact, ".
					   "mainoffice_id = $txtparentaddress ".
					   "where customer_officeId=$customer_officeId2";
		//echo $queryins;exit;	
		$resupdate = mysql_query($queryupdate,$connection);
		if(!$resupdate) $message=mysql_error(); 
	}
	if($actionmode == 'confirmBranchinfo'){
		
		if($txtctfathername2 == '') $txtctfathername2 = "NULL";
		else $txtctfathername2 = "'".$txtctfathername2."'";
		if($txtctphone22 == '') $txtctphone22 = "NULL";
		else $txtctphone22 = "'".$txtctphone22."'";
		if($txtctphone32 == '') $txtctphone32 = "NULL";
		else $txtctphone32 = "'".$txtctphone32."'";
		
		if($txtctemail12 == '') $txtctemail12 = "NULL";
		else $txtctemail12 = "'".$txtctemail12."'";
		if($txtctemail22 == '') $txtctemail22 = "NULL";
		else $txtctemail22 = "'".$txtctemail22."'";
		
		if($txtctwebsite2 == '') $txtctwebsite2 = "NULL";
		else $txtctwebsite2 = "'".$txtctwebsite2."'";
				
		if($contactinfo_id2 == ''){
		$queryins = "insert into CustomerContactInfo (customeroffice_id, contact_firstname, contact_fathername, contact_lastname, 
					contact_position, contact_phone1, contact_phone2, contact_phone3, contact_email1, contact_email2, contact_website) ".
					" values ($customer_officeId2,'$txtctfirstname2',$txtctfathername2,'$txtctlastname2','$txtctposition2',".
					" '$txtctphone12',$txtctphone22,$txtctphone32,$txtctemail12,$txtctemail22,$txtctwebsite2)";
	
		$resins = mysql_query($queryins,$connection);
		if(!$resins) $message=mysql_error(); 
	} else {
		$queryupdate = "update CustomerContactInfo set ".
					"contact_firstname='$txtctfirstname2', ".
					"contact_fathername=$txtctfathername2, ".
					"contact_lastname='$txtctlastname2', ".
					"contact_position='$txtctposition2', ".
					"contact_phone1='$txtctphone12', ".
					"contact_phone2=$txtctphone22, ".
					"contact_phone3=$txtctphone32, ".
					"contact_email1=$txtctemail12, ".
					"contact_email2=$txtctemail22, ".
					"contact_website=$txtctwebsite2 where  contactinfo_id=$contactinfo_id2";
		//echo $queryins;exit;	
		$resupdate = mysql_query($queryupdate,$connection);
		if(!$resupdate) $message=mysql_error(); 
	}
	}
if($actionmode == 'submitbranch'){
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Branches&message=".$message);
exit;
}else{
	//echo $message;
	//echo "[BRK]";
	$contactinfo_id='';
	echo branchContactInfo($customer_officeId2,$contactinfo_id2,$grid_color1,$grid_color2,$connection);
	exit;
}
}
else if($actionmode == 'deletebranch' && $PCustomerCode != ''){ 
	if($customer_officeId2 !=''){ 
		$querydel1 = "delete from CustomerContactInfo where customeroffice_id = $customer_officeId2";
		$resdel1 = mysql_query($querydel1,$connection); 
		$querydel = "delete from Customer_Offices where customer_officeId = $customer_officeId2";
		$resdel = mysql_query($querydel,$connection); 
	} 
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Branches&message=".$message);
	
}
else if( $actionmode == 'UpdateBranchinfo'){
	echo branchContactInfo($customer_officeId2,$contactinfo_id2,$grid_color1,$grid_color2,$connection);
	exit;
}
else if($actionmode == 'deleteBranchinfo'){ 
	if($contactinfo_id2 !=''){
		$querydel = "delete from CustomerContactInfo where contactinfo_id = $contactinfo_id2";
		$resdel = mysql_query($querydel,$connection); 
	} 
	$contactinfo_id2='';
	echo branchContactInfo($customer_officeId2,$contactinfo_id2,$grid_color1,$grid_color2,$connection);
	exit;
}
else if($actionmode == 'submitproject' && $PCustomerCode != ''){
	
	if($txtprojectaddress == '') $txtprojectaddress = "NULL";
	else $txtprojectaddress = "'".$txtprojectaddress."'";
	
	if($txtprojectcontact == '') $txtprojectcontact = "NULL";
	else $txtprojectcontact = "'".$txtprojectcontact."'";
	if($txtprojectphone == '') $txtprojectphone = "NULL";
	else $txtprojectphone = "'".$txtprojectphone."'";
	if($txtprojectconsname == '') $txtprojectconsname = "NULL";
	else $txtprojectconsname = "'".$txtprojectconsname."'";
	if($txtprojectconsdetail == '') $txtprojectconsdetail = "NULL";
	else $txtprojectconsdetail = "'".$txtprojectconsdetail."'";
	if($txtprojectsituation == '') $txtprojectsituation = "NULL";
	else $txtprojectsituation = "'".$txtprojectsituation."'";
	if($txtprojectiron == '') $txtprojectiron = "NULL";
	else $txtprojectiron = "'".$txtprojectiron."'";
	if($txtprojectcompetitor == '') $txtprojectcompetitor = "NULL";
	else $txtprojectcompetitor = "'".$txtprojectcompetitor."'";
	if($txtprojectparent == '') $txtprojectparent = "NULL";
	//else $txtprojectparent = "'".$txtprojectparent."'";
	
	
	if($customerproject_id == ''){
		$queryins = "insert into customer_project(customerproject_desc, customerproject_address,customerproject_contact,
					customerproject_phone, customerproject_consultantname, customerproject_consultantdetail, 
					customerproject_situation, customerproject_ironname, customerproject_competitorname, customerproject_parent, 
					customer_code ) values ".
					"('$txtprojectdesc', $txtprojectaddress, $txtprojectcontact, ".
					"$txtprojectphone, $txtprojectconsname, $txtprojectconsdetail, ".
					"$txtprojectsituation, $txtprojectiron, $txtprojectcompetitor, $txtprojectparent, ".
					"'$PCustomerCode' )";
		$resins = mysql_query($queryins,$connection);			
	} else{
		$queryupdate = "update customer_project set ".
						"customerproject_desc = '$txtprojectdesc', ".
						"customerproject_address = $txtprojectaddress, ".
						"customerproject_contact = $txtprojectcontact, ".
						"customerproject_phone = $txtprojectphone, ".
						"customerproject_consultantname = $txtprojectconsname, ".
						"customerproject_consultantdetail = $txtprojectconsdetail, ".
						"customerproject_situation = $txtprojectsituation, ".
						"customerproject_ironname = $txtprojectiron, ".
						"customerproject_competitorname = $txtprojectcompetitor, ".						
						"customerproject_parent = $txtprojectparent ".
					 "where customerproject_id=$customerproject_id";
					// echo $queryupdate; exit;
		$resupdate = mysql_query($queryupdate,$connection);				 
	}
	header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Projects&message=".$message);
}else 
	if($actionmode == 'deleteProject'){
	if($customerproject_id != ''){
		$queryup = "update customer_project set customerproject_parent = null where customerproject_parent=$customerproject_id";
		$resup = mysql_query($queryup,$connection);
		$querydel = "delete from customer_project where customerproject_id=$customerproject_id";
		$resdel = mysql_query($querydel,$connection);
	}
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$PCustomerCode."&PLedgerNo=$PCustomerCode&PActionMode=Edit&vTabFocus=Projects&message=".$message);	
}else
	if($actionmode == 'uploadpicture'){
	$filename="uploads/";
							
		if (!file_exists($filename)) {
							
			mkdir("./uploads/", 0700);
		} 
				
	move_uploaded_file($_FILES['photos']["tmp_name"][0],"uploads/".$_FILES['photos']["name"][0]);

	$_FILES['photos']['name'][0]=preg_replace('/\s+/', '', $_FILES['photos']['name'][0]);
	
	$query="update CustomerContactInfo set contact_photo='".$_FILES['photos']["name"][0]."' where contactinfo_id='$contactinfo_id' "; 
	//echo$query;exit;
	$result  = mysql_query($query, $connection) or die(mysql_error());	//echo$connection;exit;
	echo mainContactInfo($customer_officeId,$contactinfo_id,$grid_color1,$grid_color2,$connection);
	exit;
}
else{ 
if ($PCustomerCode == '') { 
		if ($txtCode != '') {
			$sub_query = " Select Count(Customer_Code) From Customer ".
						 " Where Customer_Code = '".$txtCode."'";
			$sub_result = selectData($connection, $sub_query);
			if ($sub_result[0] != 0) $ErrorExists = 1;
		}
		
		if ($ErrorExists == 1) {
			$PActionMode = 'Add';
			$message = 'Insert not allowed. Duplicate Code: '.$txtCode;
		}	
			
		
		
		if ($txtCode != "" && $ErrorExists == 0){
		
			fbegin();
			
			$cust_discount_per = "'" .$txtdiscountper . "'";
			
			if($txtLedgerClientCard != '')
			$query = " INSERT INTO Customer (Customer_Code, Customer_Name, Customer_Telephone1, Customer_Telephone2, Customer_Email, Customer_Address, Customer_special,customer_card, ".
					 " customer_group, customer_description , customer_website,customer_discountper ) ".	
					 " VALUES ( '".$txtCode."', '".ereg_replace("'", "\'", trim($txtName))."', '".$txtPhone1."', '".$txtPhone2."', ".
					 "         $txtEmail, " .$txtaddressencoded .",$txtCustomerSpecial, '$txtLedgerClientCard', ".
					 " $txtgroupname, $txtdescname , $txtWebsite,$cust_discount_per)";
			else 
			$query = " INSERT INTO Customer (Customer_Code, Customer_Name, Customer_Telephone1, Customer_Telephone2, Customer_Email, Customer_Address, Customer_special, ".
					 " customer_group, customer_description , customer_website,customer_discountper  ) ".
					 " VALUES ( '".$txtCode."', '".ereg_replace("'", "\'", trim($txtName))."', '".$txtPhone1."', '".$txtPhone2."', ".
					 " $txtEmail, " .$txtaddressencoded.",$txtCustomerSpecial, ".
					 " $txtgroupname, $txtdescname , $txtWebsite,$cust_discount_per)";				
			//echo $query."<br>";exit;	


     //       echo $query; exit;			
			$result=mysql_query($query,$connection);
			
			
			if ($result){
				fcommit();
				//if($mode == 'uploadpicture')  uploadpicture($txtCode,$frm,$item,$txtId,$message,$connection);
				$PActionMode = '';
				$PLedgerNo   = $txtCode;
				
				
				header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PLedgerNo=".$PLedgerNo."&message=".$message);	
			}else{
				$PActionMode = 'Add';
				$message  = mysql_error(); 
				frollback();
			}
	
		}
	} else {
		fbegin();
		if($txtRewardedPoints == '') $txtRewardedPoints=0;
			$cust_discount_per = "'" .$txtdiscountper . "'";
		$query = " UPDATE Customer SET  customer_discountper = $cust_discount_per ,".
		         " Customer_Name = '".ereg_replace("'", "\'", trim($txtName))."', Customer_Telephone1 = '".$txtPhone1."', Customer_Telephone2 = '".$txtPhone2."', ".
				 " Customer_Email = $txtEmail, Customer_Address = " .$txtaddressencoded ." , customer_website = $txtWebsite ".
				
				 ", Customer_special=$txtCustomerSpecial ";
		if($txtCustomerSpecial == 1) 	$query =$query.", Customer_point = $txtRewardedPoints ";	 
		if($txtLedgerClientnbr != '')	$query =$query.",ledger_number='$txtLedgerClientnbr' ";
		if($txtLedgerClientCard != '')  $query =$query.",customer_card='$txtLedgerClientCard' ";
		$query =$query.",customer_group=$txtgroupname ";
		$query =$query.",customer_description=$txtdescname ";		 
		$query =$query." WHERE Customer_Code = '".$PCustomerCode."'";
						 
		//echo $query."<br>";			 
		$result=mysql_query($query,$connection);
		
			
			
		if ($result){
							
			
			fcommit();
		//	if($mode == 'uploadpicture')  {
				//uploadpicture($PCustomerCode,$frm,$item,$txtId,$message,$connection);
			//	}	
			$PActionMode = '';
			$PCustomerCode = '';
			$PLedgerNo   = $txtCode;	
			header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PLedgerNo=".$PLedgerNo."&message=".$message);	
		}else{
			$PActionMode = 'Edit';
			$message  = mysql_error(); 
			frollback();
		}
	}
		
}
	function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}

function selectData($conn, $query){
	$result = mysql_query($query, $conn);
	$cur = mysql_fetch_row($result);		
	return $cur;
}

function uploadpicture($customercode,$frm,$item,$txtId,$message,$connection){
		$filename="uploads/";
							
		if (!file_exists($filename)) {
							
			mkdir("./uploads/", 0700);
		}
						
	move_uploaded_file($_FILES['photo']["tmp_name"],"uploads/".$_FILES['photo']["name"]);

	$_FILES['photo']['name']=preg_replace('/\s+/', '', $_FILES['photo']['name']);
	
	$query="update customer set customer_card='".$_FILES['photo']["name"]."' where customer_code='$customercode' "; 
	//echo$query;exit;
	$result  = mysql_query($query, $connection) or die(mysql_error());	//echo$connection;exit;
header ("Location: ./List_Customers.php?frm=".$frm."&item=".$item."&txtId=".$txtId."&PCustomerCode=".$customercode."&PLedgerNo=$customercode&PActionMode=Edit&vTabFocus=Customer&message=".$message);
exit;
}
//header ("Location: ./List_Customers.php");
?>