<?
include('../Code/confHeader.inc');
$Me -> goIfInvalid("../index.php");
$Me -> goIfNotAuthor("../index.php");
$Conf -> goIfInvalidActivity("authorRespondToReviews", "../index.php");
$Conf -> connect();
?>

<html>

<? $Conf->header("Submit Response to paper reviews for #$paperId") ?>

<body>

<p>
You can submit responses to your paper review
<? echo $Conf->printTimeRange('authorRespondToReviews') ?>. <br>
You can continue modifying or  updating the stored response until then.
You will receive email messages each time a new review is finalized, but you
should periodically submit your response as you revise the response to
insure you do not miss the response deadline.  </p>


<?

$Conf->infoMsg("The \"author response\" should be addressed to the program committee. "
	       . "The program committee will use this information in conjunction "
	       . "with the reviews to reach a final determination concerning the paper. "
	       . "You should keep your response brief and to the point, since each "
	       . "program committee member is responsible for many papers. "
	       . "You should also understand that the authors response is a mechanism "
	       . "to identify small problems or clearly biased or incorrect reviews. "
	       . "It is not a mechanism to augment the "
	       . "content or form of the paper --- the conference deadline has passed "
	       . "and the program committee must evaluate the papers on the merits of "
	       . "what is included in the paper, not on additional information submitted "
	       . "at this time.");


if ( ! $Me -> amPaperAuthor($paperId, $Conf) ) {
  $Conf->errorMsg("You aren't supposed to be able to respond for paper #$paperId. "
		  . "If you think this is in error, contact the program chair. ");
  exit;
}

//
// Make certain that the author has submitted all their reviews
// prior to viewing their own reviews

$missingReviews = $Conf->listMissingReviews($Me->contactId);

if ($missingReviews) {
  $Conf->errorMsg("Before you can submit a response for your paper, "
		  . " you must finish reviewing the papers you were "
		  . " asked to review, or you must tell the program "
		  . " committee member that you can not finish your "
		  . " reviews. ");
  exit();
}



//
// Process any submissions
//
if (IsSet($submit)) {
  $Conf->infoMsg("Updating the response ");
  $set = "authorsResponse='" . addslashes($authorsResponse) . "'";
  $query="UPDATE Paper SET $set WHERE paperId='$paperId' and contactId='$Me->contactId'";
  $result = $Conf->qe($query);

  if ( !DB::isError($result) ) {
    $Conf->confirmMsg("Successfully updated response");
  } else {
    $Conf->errorMsg("Error in updating response: " . $result->getMessage());
    $Conf->log("Error in updating response for  $paperId: " . $result->getMessage(), $Me);
  }
}

//
// Check to see if they've already submitted a review for this paper,
// and if so, provide them the values from their prior review
//
$query = "SELECT authorsResponse FROM Paper WHERE paperId='$paperId'";

$result=$Conf->qe($query);
if (!DB::isError($result)) {
  if ( $row=$result->fetchRow() ) {
    $authorsResponse = stripslashes($row[0]);
  }
} else {
  $Conf->errorMsg("Error in query: " . $result->getMessage());
}
?>

<form METHOD="POST" ACTION="<?echo $PHP_SELF?>">
<table border=1 align=center bgcolor=<?echo $Conf->bgOne?>>
<tr> <td align=center>
<INPUT TYPE=submit NAME=submit VALUE="Submit your response to the reviews">
<INPUT TYPE=hidden NAME=paperId VALUE=<?echo $paperId?>>
</td> </tr>
<tr> <th> Response </th> </tr>
<tr> <td>
<textarea NAME=authorsResponse rows=30 cols=70><?echo $authorsResponse?></textarea>
</td> </tr>
<tr><td align=center>
<INPUT TYPE=submit NAME=submit VALUE="Submit your response to the reviews">
</td></tr>
</table>
</form>
</body>

<? $Conf->footer() ?>
</html>
