<?php
require_once("../include/config.php");
require_once("../include/startup.php");
	
if($G_memberid > 0)
{
		require_once("header1.html");
		require_once("leftnav.html");

		
$obj  			= new Company();
$factory_obj   = new Factories();
$branch_obj  	= new Branches();
$objinfo  		= new AllTables();
//print_r($_GET);
		 $memberfactoryid 	= (int)($_GET['memberfactoryid']);
	
	
	//get client factory address
	$menu			=	new Factories();
		$sql="Select * from member_factories where memberfactoryid=$memberfactoryid";
			 $factorylist		=	$menu->getFactories('',$sql);

		
		//print_r($factorydata);
		$factorydata = count($factorylist);
		//print_r($factorylist);
		for($i=0;$i<$factorydata;$i++)
	{
		$factoryaddress 		= $factorylist[$i]['factoryaddress'];
		$factoryaddressline2 = $factorylist[$i]['factoryaddressline2'];
		$factorycity 			= $factorylist[$i]['factorycity'];
		$factorypincode 		= $factorylist[$i]['factorypincode'];
		$factorygstno 			= $factorylist[$i]['factorygstno'];
		}
		
	if($_POST['SUBMIT'])
		{
			
			 	
				
				$factarray['memberfactoryid'] 				= $memberfactoryid;
				
				$factarray['factoryaddress'] 					= trim(sanitize($_POST['txtfactadd_'.$i],SQL));
				$factarray['factoryaddressline2'] 			= trim(sanitize($_POST['txtfactadd2_'.$i],SQL));
			
				$factarray['factorycity'] 						= trim(sanitize($_POST['txtfactcity_'.$i],SQL));
				$factarray['factorypincode'] 					= trim(sanitize($_POST['txtfactpin_'.$i],SQL));
				
				//$factarray['factorystate'] 					= $_POST['txtfactstate_'.$i];
				//$factarray['factorytelno'] 					= trim(sanitize($_POST['txtfacttel_'.$i],SQL));
				//$factarray['factoryfaxno'] 					= trim(sanitize($_POST['txtfactfax_'.$i],SQL));
				//$factarray['factoryemail'] 					= trim(sanitize($_POST['txtfactemail_'.$i],SQL));
				$factarray['factorygstno'] 					= trim(sanitize($_POST['txtfactgstno_'.$i],SQL));
				//print_r($factarray);
				$wherefactory = "memberfactoryid = ".$memberfactoryid."";
			
				$addfactory     = $factory_obj ->EditFactories($factarray,$wherefactory);
				require_once("edit-company.php");
			
		}
		
				
		
		
		require_once("edit-mycompany-factories1.html");
		require_once("footer1.html");


}
else if (!headers_sent($filename, $linenum)) 
{
				$redirect_url = DOC_ROOT."login.php";
				header("Location: $redirect_url");
    				exit;
					// You would most likely trigger an error here.
}
else 
{
				echo "Headers already sent in $filename on line $linenum\n" .
          			"Cannot redirect, for now please click this <a ";
    				exit;
}   

	
	
?>
