<?php
require_once("../include/config.php");
require_once("../include/startup.php");
	
if($G_memberid > 0)
{
		
$obj  			= new Company();
$factory_obj   = new Factories();
$branch_obj  	= new Branches();
$objinfo  		= new AllTables();

$memberid 		= $G_memberid;
$companyid 		= (int)($_GET['companyid']);

			
	if($_POST['SUBMIT'])
	{ 
		 //Information
	 	$memberid 									= $_POST['txtmemberid'];
	 	$NewProduct['membercompanyid']     	= $companyid;
	 	$NewProduct['memberid']					= $memberid;
	 	$NewProduct['companyname']				= sanitize($_POST['txtcompanyname'],SQL);
	 	
	 	//Address		
		$NewProduct['Addline1'] 					= sanitize($_POST['Addline1'],SQL);
	 	$NewProduct['Addline2'] 					= sanitize($_POST['txtAddline1'],SQL);
	 	$NewProduct['head_CityName'] 				= sanitize($_POST['txthead_CityName1'],SQL);
	 	$state 											= explode("-",sanitize($_POST['txtstate'],SQL));
	 	$NewProduct['head_Stateid1'] 				= $state[0];
	 	$NewProduct['head_StateidName'] 			= $state[1];
	 	$Country											= explode("-",sanitize($_POST['txtcountry'],SQL));
	 	$NewProduct['Country'] 						= $Country[1];
		$NewProduct['head_Pin'] 					= sanitize($_POST['txtpincode1'],SQL);
		
	
	   //Contact Information
	 	$NewProduct['head_TelNo'] 	      		= sanitize($_POST['txthead_TelNo'],SQL);
		$NewProduct['head_mobNo'] 	     		 	= sanitize($_POST['head_mobNo'],SQL);
		$NewProduct['head_Email'] 	      		= sanitize($_POST['head_Email'],SQL);
		$NewProduct['head_FaxNo'] 	      		= sanitize($_POST['head_FaxNo'],SQL);
	 	$NewProduct['comp_website'] 	      	= sanitize($_POST['txtWebsite'],SQL);
	   $NewProduct['comp_contact_personname'] = sanitize($_POST['txtcomp_contactname'],SQL);
	
	   //Information
	 	$NewProduct['gstapplicable']					= $_POST['txtgstapplicable'];
	 	$NewProduct['gstno'] 							= sanitize($_POST['txtgstno1'],SQL);
	 	$NewProduct['Tan_No'] 							= sanitize($_POST['txttanno'],SQL);
	 	$NewProduct['panno']								= sanitize($_POST['txtpanno'],SQL);
	 	$NewProduct['memberapprovalstatus']			= sanitize($_POST['txtstatus'],SQL);
	 	$NewProduct['upload_logo']						= sanitize($_POST['galleryimagename'],SQL);
	 	$NewProduct['upload_header']						= sanitize($_POST['galleryimagenameforheader'],SQL);
	 	
		$wherecomp = "membercompanyid = ".$companyid."";
		$editData	= $obj -> EditCompany($NewProduct,$wherecomp);
		if($editData)
		{
				$redirect_url = DOC_ROOT."admin/viewcompany.php";
				header("Location: $redirect_url");
    			exit;
		}
	
	}	
	else 
	{
		$sql = "select * from user_company where membercompanyid = $companyid";
		
		$sqllist = $obj->getCompany('','',$sql);
		
		$productdatacount=count($sqllist);
	
		for($i=0;$i<$productdatacount;$i++)
		{
			
			   $companyname 								= $sqllist[$i]['companyname'];
				$gstapplicable 							= $sqllist[$i]['gstapplicable'];
				$gstno										= $sqllist[$i]['gstno'];
	         $Tan_No										= $sqllist[$i]['Tan_No'];
				$panno										= $sqllist[$i]['panno'];
				$billing_address							= $sqllist[$i]['billing_address'];
				$taxnotapplicable							= $sqllist[$i]['taxnotapplicable'];
				$gstnotapplicable							= $sqllist[$i]['gstnotapplicable'];
				$Addline1									= $sqllist[$i]['Addline1'];
				$Addline2									= $sqllist[$i]['Addline2'];
				$head_CityName								= $sqllist[$i]['head_CityName'];
				$head_Stateid1								= $sqllist[$i]['head_Stateid1'];
				$head_StateidName							= $sqllist[$i]['head_StateidName'];
				$GCountry									= $sqllist[$i]['Country'];
				$head_Pin									= $sqllist[$i]['head_Pin'];
		      $head_TelNo									= $sqllist[$i]['head_TelNo'];
		      $head_mobNo									= $sqllist[$i]['head_mobNo'];
		      $head_FaxNo									= $sqllist[$i]['head_FaxNo'];
		      $comp_contact_personname				= $sqllist[$i]['comp_contact_personname'];
	 			$comp_website								= $sqllist[$i]['comp_website'];
		      $head_Email									= $sqllist[$i]['head_Email'];
		      $upload_logo								= $sqllist[$i]['upload_logo'];
		      $upload_header								= $sqllist[$i]['upload_header'];
				if($memberapprovalstatus == '1')
		      {
					$valselect1      = "selected";
		      }
		      elseif($memberapprovalstatus == '0')
		      {
					$valselect0      = "selected";
		      }
		}
		require_once("edit-company1.html");
	}
		
		require_once("header1.html");
		require_once("leftnav.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;
}   

	
	
?>
