<?php
	//connection
	include ("frames_header.php");
	include("connection.php");
    if ( (!isset($_SESSION["login"]))or(!isset($_SESSION["pass"])) ) {
	    print "<center><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"];
	$comments=$_POST["comments"];

	//Mise a jour
	pg_query($c,"begin") or die("<strong>Error</strong> ".pg_last_error($c));	
	
	if($_POST["propagate"]==1){
		$to_propagate = array($id);
		while(count($to_propagate)>0){			
			$cur = array_pop($to_propagate);			
			$khoueiry="update \"PROMOTER\" set \"COMMENTS\"='$comments' where \"PROMOTER_ID\"='$cur'";
			pg_query($c,$khoueiry) or die("<strong>Error</strong> ".pg_last_error($c));					
			$khoueiry = "SELECT \"PROMOTER_ID\" FROM \"PROMOTER\" WHERE \"PROMOTER_ID\"!=\"BASE_REG_ID\" AND \"BASE_REG_ID\"=$cur";	
			$stmt = pg_query($c,$khoueiry) or die("<strong>Error</strong> ".pg_last_error($c));
			while($row=pg_fetch_array($stmt)){	
				array_push($to_propagate,$row["PROMOTER_ID"]);
			}
			
		}
		
	} else {		
		$khoueiry="update \"PROMOTER\" set \"COMMENTS\"='$comments' where \"PROMOTER_ID\"='$id'";
		pg_query($c,$khoueiry) or die("<strong>Error</strong> ".pg_last_error($c));	
	}

	pg_query($c,"commit") or die("<strong>Error</strong> ".pg_last_error($c));
		
	echo '<SCRIPT LANGUAGE="JavaScript"> javascript:opener.location.reload(); self.close(); </script>';
				
	include ("frames_footer.php"); 

?>
