<?php

// +----------------------------------------------------------------------+
// | OpenConf                                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2008 Zakon Group LLC.  All Rights Reserved.       |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on    |
// | the OpenConf web site: www.OpenConf.com                              |
// +----------------------------------------------------------------------+

require_once "../include.php";
require_once "../include-submissions.inc";

printHeader("Retirer une soumission", 3);

// Withdraw allowed?
if (! $OC_statusAR['OC_withdraw_open']) {
	print '
<b>Les retraits des soumissions ne sont pas accessibles.<br/>Submission withdraws are not available.</b><p>
	';
	printFooter();
	exit;
}

// Is this a post?
if (isset($_POST['submit']) && ($_POST['submit'] == 'Retirer cette soumission')) {
	// Check for paper ID & password
	if (! isset($_POST['pid']) || 
		! preg_match("/^\d+$/", $_POST['pid']) ||
		! isset($_POST['pwd']) || 
		empty($_POST['pwd'])
	) {
		warn('Please go back and check the submission ID and password');
		printFooter();
		exit;
	}

	$pq = "SELECT `" . OCC_TABLE_PAPER . "`.`title`, `" . OCC_TABLE_PAPER . "`.`password`, `" . OCC_TABLE_AUTHOR . "`.`email` FROM `" . OCC_TABLE_PAPER . "`, `" . OCC_TABLE_AUTHOR . "` WHERE `" . OCC_TABLE_PAPER . "`.`paperid`='" . $_POST['pid'] . "' AND `" . OCC_TABLE_PAPER . "`.`paperid`=`" . OCC_TABLE_AUTHOR . "`.`paperid` AND `" . OCC_TABLE_PAPER . "`.`contactid`=`" . OCC_TABLE_AUTHOR . "`.`position`";
	$pr = ocsql_query($pq) or err("Unable to retrieve submission ".mysql_errno());
	if (mysql_num_rows($pr) != 1) {
		warn("Unable to find submission id " . safeHTMLstr($_POST['pid'])); 
		printFooter();
		exit;
	}
	$pl = mysql_fetch_array($pr);
	if ((hashPassword($_POST['pwd'], $pl['password']) != $pl['password']) && (md5($_POST['pwd']) != $pl['password']) && (!OCC_CHAIR_PWD_TRUMPS || (hashPassword($_POST['pwd'], $OC_configAR['OC_chair_pwd']) != $OC_configAR['OC_chair_pwd'])) && (!defined('OCC_SUPERCHAIR_PASSWORD') || (hashPassword($_POST['pwd'], OCC_SUPERCHAIR_PASSWORD) != OCC_SUPERCHAIR_PASSWORD))) {
		warn('Password entered is not valid for submission id ' . safeHTMLstr($_POST['pid']));
		printFooter();
		exit;
	}

	// Withdraw submission
	if (withdrawPaper($_POST['pid'], 'Author')) {
		deletePaper($_POST['pid']);
		print '<p>Votre soumission a été retirée.  Si vous n\'en aviez pas l\'intention, contactez l\'administrateur.</p><p>Your submission has been withdrawn. If this is not what you intended to do, please contact the Chair.</p>';
		// Notify via email
		$confirmmsg = 'La soumission suivante a été retirée sur demande de l\'auteur. Si ce n\'était pas dans votre intention, contactez l\'administrateur. -- The submission below has been widthdrawn at the author\'s request.  If you did not intend to withdraw the submission, please contact the Chair.
		
ID: ' . $_POST['pid'] . '
Titre: ' . $pl['title'] . '
';
		sendEmail($pl['email'], "Soumission retirée - n. " . $_POST['pid'], $confirmmsg, $OC_configAR['OC_notifyAuthorWithdraw']);
	} else {
		print '<p>We encountered a problem withdrawing your submission.  Please contac the Chair.</p>';
	}

	printFooter();
	exit;
} // if submit

// display sub id/password form
print '
<center>
<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
<table border=0 cellspacing=0 cellpadding=5>
<tr><td><b>Soumission n°</b></td><td><input name="pid" size="5" tabindex="1"> ( <a href="email_papers.php">id. oublié ?</a> )</td></tr>
<tr><td><b>Mot de passe :</b></td><td><input name="pwd" type="password" tabindex="2" size="20" maxlength="255"> ( <a href="reset.php">mot de passe oublié ?</a> )</td></tr>
</td></tr></table>
<p>
<input type="submit" name="submit" value="Retirer cette soumission" tabindex="3" onclick="return(confirm(\'Voulez-vous vraiment retirer cette soumission ?\nProceed with withdrawing submission?\'))" />
</form>
</center>
<p>
<script language="javascript">
<!--
document.forms[0].elements[0].focus();
// -->
</script>

';

printFooter();

exit;

?>
