<?php
    include("connection.php");
?>

<html>
<SCRIPT>
    function reload(){
        opener.location.reload();
	}
</SCRIPT>

<body bgcolor="#871F1F" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000" onUnload="javascript: self.reload();">
<?php

	$mode=$_GET["mode"];
	$grant=$_GET["grant"];
	$id=$_GET["id"];
	$user=$_GET["user"];


    if( (strlen($mode)>0)and(strlen($grant)>0)and(strlen($id)>0)and(strlen($user)>0) ){
        if($mode=="add"){
		
			//modif de l'utilisateur dans oracle
			/*
			$requete="GRANT \"$grant\" TO \"$user\"";
			$resultset = OCIParse($connection, $requete);
			//OCIExecute($resultset,OCI_DEFAULT);
			if(! OCIExecute($resultset,OCI_DEFAULT) ){
				OCIRollback($connection);
				print "ERROR: can't modify permissions";
				return;
			}
			*/
		pg_query($c,"begin");
			$requete="ALTER GROUP \"CURATOR_ANISEED\" ADD USER \"$user\"";
			$resultset = pg_query($c,$requete) or die("<strong>Error </strong>".pg_last_error($c));
			

			
            //modif de l'utilisateur dans aniseed
			$requete="update \"AUTHOR\" set \"IS_CURATOR\"='y' where \"AUTHOR_ID\"=$id";
			$resultset = pg_query($c,$requete)or die("<strong>Error </strong>".pg_last_error($c));
			//OCIExecute($resultset,OCI_DEFAULT);
			/*if(! OCIExecute($resultset,OCI_DEFAULT) ){
				OCIRollback($connection);
				print "ERROR: can't modify user";
				return;
			}*/

			
			// Validation de la transaction
			//$committed = OCICommit($connection);
		pg_query($c,"commit");
		
			// Verification de la validation : si une erreur est survenue, afficher le message d'erreur
			/*if(!$committed) {
				$error = OCIError($connection);
				echo 'ERROR:'.$error['message'];
				print '</body></html>';
				return;
			}*/
			
		}else if($mode=="rem"){
		
			//modif de l'utilisateur dans oracle
			/*$requete="REVOKE \"$grant\" FROM \"$user\"";
			$resultset = OCIParse($connection, $requete);
			//OCIExecute($resultset,OCI_DEFAULT);
			if(! OCIExecute($resultset,OCI_DEFAULT) ){
				OCIRollback($connection);
				print "ERROR: can't revoke permissions";
				return;
			}*/
		pg_query($c,"begin");	
			$requete="ALTER GROUP \"CURATOR_ANISEED\" DROP USER \"".$user."\"";
			$resultset=pg_query($c,$requete)or die("<strong>Error </strong>".pg_last_error($c));

			
            //modif de l'utilisateur dans aniseed
			$requete="update \"AUTHOR\" set \"IS_CURATOR\"='' where \"AUTHOR_ID\"=$id";
			$resultset=pg_query($c,$requete)or die("<strong>Error </strong>".pg_last_error($c));
			/*$resultset = OCIParse($connection, $requete);
			//OCIExecute($resultset,OCI_DEFAULT);
			if(! OCIExecute($resultset,OCI_DEFAULT) ){
				OCIRollback($connection);
				print "ERROR: can't modify user";
				return;
			}*/

			
			// Validation de la transaction
			//$committed = OCICommit($connection);
		pg_query($c,"commit");
		
			// Verification de la validation : si une erreur est survenue, afficher le message d'erreur
			/*if(!$committed) {
				$error = OCIError($connection);
				echo 'ERROR:'.$error['message'];
				print '</body></html>';
				return;
			}*/
			
		}
	}else{
	    print"<center><strong>Error: missing parameter</strong></center>";
		print '</body></html>';
		return;
	}
	
	print '<center><H1>User update done</H1><br>';
	print '<input name="Exit" type="button" value="-= Close window =-" onClick="javascript:self.close();"></center>';


?>
</body>
</html>
