<?php

	include ("frames_header.php"); 
	include ("connection.php");
	
    if ( (!isset($_SESSION["login"]))or(!isset($_SESSION["pass"])) ) {
	    print "<strong>you need to <a href=\"login.php\">login</a> as an authorised curator to proceed.</strong>";
	    print '</center></body></html>';
		return;
	}
				
	$id = $_POST["id"];
	$region_name = trim($_POST["region"]);
	
	//VERIFY IF REG EXISTS EXISTS...
	$khoueiry = "SELECT \"PROMOTER_ID\"  FROM \"PROMOTER\" WHERE \"STABLE_ID\"='".$region_name."'";
	$stmt = pg_query($c,$khoueiry);		
	if($row=pg_fetch_array($stmt)){
		$chg_id = $row["PROMOTER_ID"];
		$khoueiry="UPDATE \"PROMOTER\" SET \"BASE_REG_ID\"=$chg_id WHERE \"PROMOTER_ID\"=$id";						
  		pg_query($c,$khoueiry) or die(pg_last_error($c));   	
		
		echo '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';
		
	} else {
		echo '<p>Did not find region '.$_POST["region"].' in the database</p>';	  
	}		     

	include ("frames_footer.php"); 

?>