<?php
require_once("../include/config.php");
require_once("../include/startup.php");

if($G_memberid > 0)
{
		$obj  = new AllTables();
		
		require_once("header1.html");
		require_once("leftnav.html");
		require_once("footer1.html");
		
		if($_POST['SUBMIT'])
		{
				$unitid 								= $_POST['unitid'];
				$data1['unitname']				= $_POST['txtunitname'];
				$data1['unitname_plural']		= $_POST['txtunitname_plural'];	
				$wherecondition = " unitid = $unitid ";
				$addresult     = $obj -> EditInfo($data1,$wherecondition,'product_units');
				if($addresult)
				{
					$redirect_url = DOC_ROOT."admin/unit-master.php";
					header("Location: $redirect_url");
	    			exit;
				}
		}
		else 
		{
				$unitid 	= intval($_GET['unitid']);
				$sqltext ="SELECT * FROM  product_units where unitid = $unitid";
		
				$unitdata = $obj->getInfo('',$sqltext);
				
				if(is_array($unitdata))
				{
					$unitdatacount=count($unitdata);
				}
				for($i=0;$i<$unitdatacount;$i++)
				{
					 	$unitname 							= $unitdata[$i]['unitname'];
					   $unitname_plural 					= $unitdata[$i]['unitname_plural'];
					   	
				}
				require_once("edit-unit1.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;
}   




	
	
?>
