$rUnique=$_SESSION["rUnique"];
$CaseId=$_SESSION["CaseId"];
$rInstance=$_SESSION["Instance"];
$OldVal=$_REQUEST["OldVal"];
$qID=$_REQUEST["qst"];
$NewVal=$_REQUEST[$qID];
CleanText($NewVal);
$UserId=$_SESSION["UserId"];
$Reason=$_REQUEST["Reason"];
CleanText($Reason);

$sql="update Responses set rValue=`".$NewVal."`, rOK=3 where rUnique=`$rUnique`";
ExecuteSQL($sql);

$sql="insert into Changes (rUnique,OldValue,NewValue,uID,Reason) " .
	"select `".$rUnique."`,`".$OldVal."`,`".$NewVal."`,`".$UserId."`,`".$Reason."`";
ExecuteSQL($sql);

$sql="select distinct fID from FormQuestions where qID=`".$qID."`";
$frm=ShowQueryResultScalar($sql);

$_SESSION[`DE_MODE`]="E";
SaveGo($frm);
$_SESSION[`DE_MODE`]="O";

$rUnique=ShowQueryResultScalar("select rUnique from Responses where Caseid=`$CaseId` and rOK=0");
if ($rUnique=="") SetForm(EditResolutionLoop);
$_SESSION["rUnique"]=$rUnique;
$_SESSION["Instance"]=ShowQueryResultScalar("select rInstance from Responses where rUnique=`$rUnique`");
$sql="select rValue from Responses where CaseID=`$CaseId` and qID=`VisitDate` and rInstance=".$_SESSION[`Instance`];
$_SESSION[`VisitDate`]=ShowQueryResultScalar($sql);

$stat=1;
