<?php 
//
// This program generates an output script that you can edit
// and then run. The script that is produced invokes PHP for
// each review that is specified by this script.
//
// A sample invocation is:
//
// php DumpAllReviews.php-not-via-apache 1 1 0 > SCRIPT
//
// This will produce an output file in SCRIPT that contains commands
// like
//
// php DumpSingleReview.php-not-via-apache 13 1 1 > /tmp/REVIEWS/review-13.html
//
// The 1st argument (e.g. 1) is if SeeReviewerInfo should be set.
// The 2nd argument (e.g. 1) is if SeeAuthorInfo should be set.
// The 3rd argument (e.g. 0) is if ShowPCPapers should be set.
//
// See DumpSingleReview for more information
//
//
// This is a magic 
include('../Code/confHeader.inc');
//$Me -> goIfInvalid("../index.php");
//$Me -> goIfNotAssistant('../index.php');
$Conf -> connect();
include('../Code/confConfigReview.inc');


$SeeReviewerInfo=$argv[1];
$SeeAuthorInfo=$argv[2];
$ShowPCPapers=$argv[3];

print "SeeReviewerInfo=$SeeReviewerInfo, SeeAuthorInfo=$SeeAuthorInfo, ";
print "ShowPCPapers=$ShowPCPapers\n";

if ( $ShowPCPapers ) {
  $conflicts = $Conf->allMyConflicts($Me->contactId);
} else {
  $conflicts = $Conf->allPCConflicts();
}

$OUT="/tmp/REVIEWS";
print "mkdir $OUT\n";

?>

<html>
<body>


<?php 
$query="SELECT Paper.paperId, Paper.title, Paper.abstract, Paper.authorsResponse, "
    . " ContactInfo.firstName, ContactInfo.lastName, "
    . " ContactInfo.email, ContactInfo.affiliation, Paper.authorInformation "
    . " FROM Paper,ContactInfo "
    . " WHERE Paper.contactId=ContactInfo.contactId AND Paper.acknowledged=1 "
    . " ORDER BY paperId ";

$result=$Conf->qe($query);

if (DB::isError($result)) {
  $Conf->errorMsg("Error in retrieving paper list " . $result->getMessage());
  exit();
}
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
  $paperId=$row['paperId'];
  $printMe = 1;

  if (IsSet($paperReviewsToPrint) && ! $printThese[$paperId]) {
    $printMe = 0;
  }

  if ($conflicts[$paperId]) {
    $printMe = 0;
  }

  if ( $printMe ) {
    print "php DumpSingleReview.php-not-via-apache $paperId $SeeReviewerInfo $SeeAuthorInfo > $OUT/review-$paperId.html\n";
  }	
}
?>

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