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

<html>

<? $Conf->header("Delete Paper #$paperId") ?>

<body>
<?

if (!IsSet($paperId) || $paperId == 0) {
  $Conf->errorMsg("No paper was selected for deleting?" );
  exit;
} 

if (! $Me -> amPaperAuthor($paperId, $Conf) ) {
  $Conf->errorMsg("You are not the author of paper #$paperId.<br>"
		  ."You can't finalize it.");
  exit;
}

$query = "SELECT Paper.title, Paper.abstract, Paper.authorInformation, "
. " LENGTH(PaperStorage.paper) as size, PaperStorage.mimetype "
. " FROM Paper, PaperStorage WHERE "
. " Paper.contactId='$Me->contactId' "
. " AND Paper.paperId=$paperId "
. " AND PaperStorage.paperId=$paperId";

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

if ( DB::isError($result) ) {
    $Conf->errorMsg("That's odd - paper #$paperId isn't suitable for deleting. "
		    . $result->getMessage());
    exit();
} 
 
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
$title = $Conf->safeHtml($row['title']);
$abstract = $Conf->safeHtml($row['abstract']);
$authorInfo = $Conf->safeHtml($row['authorInformation']);
$paperLength = $row['size'];
$mimetype = $row['mimetype'];
?>
<body>
<table align=center border=1 bgcolor="<?echo $Conf->bgOne?>" >
   <tr> <h3> <b> Paper # <? echo $paperId ?>
	<a href="<? echo $Conf->makeDownloadPath($paperId, $mimetype) ?>">
	(Download paper of type <? echo $mimetype ?>) </a> </b> <h3> <tr>
   <tr> <td> Title: </td> <td> <? echo $title ?> </td> </tr>
   <tr> <td> Author Information: </td> <td> <? echo $authorInfo ?> </td> </tr>
   <tr> <td> Abstract: </td> <td> <? echo $abstract ?> </td> </tr>
</table>

<?
if ( IsSet($DeletePaper) ) {
  $Conf->deletePaper($paperId);
  $Me -> updateContactRoleInfo($Conf);
  $Conf->infoMsg( "It looks like your paper should have been deleted. " );
  

} else {
  print "<center>";
  print "<FORM METHOD=POST ACTION=$PHP_SELF>\n";
  print "<INPUT type=hidden name=paperId value='$paperId' >\n";
  print "<INPUT type=submit name=DeletePaper value='Click here to delete this paper' >\n";
  print "</FORM>";
  print "</center>";
}
?>
<br> <br>
<?
$Conf->infoMsg("Note: if you delete your paper and it is after the "
	       . " 'paper start' date, you can not start a new paper. "
	       . " If you are trying to simply upload a new copy of your "
	       . " paper, go to the paper list and select the 'upload' option. "
	       . " If you are trying to modify author or abstract information, "
	       . " go to the paper list and select the 'modify' option. ");
?>
<center>
<?
  $Conf->textButton("Click here to go to the paper list",
		    "../Author/PaperActions.php");
?>
</center>

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