<?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";

printHeader("Email Submissions",3);

if (isset($_POST['submit']) && ($_POST['submit'] == "Email Submissions") && (!empty($_POST['email']))) { 
	// check for valid email
	if (!validEmail($_POST['email'])) {
		print '<center><span class="warn">Email address entered is invalid</span></center>';
		printFooter();
		exit;
	}
	$q = "SELECT " . OCC_TABLE_PAPER . ".paperid, " . OCC_TABLE_PAPER . ".title FROM " . OCC_TABLE_PAPER . ", " . OCC_TABLE_AUTHOR . " WHERE " . OCC_TABLE_AUTHOR . ".email='" . safeSQLstr(oc_strtolower($_POST['email'])) . "' AND " . OCC_TABLE_AUTHOR . ".paperid=" . OCC_TABLE_PAPER . ".paperid ORDER BY " . OCC_TABLE_PAPER . ".paperid";
	$r = ocsql_query($q) or err("Error checking for submissions ".mysql_errno());
	if (($rnum=mysql_num_rows($r)) == 0) { 
		print '<center><span class="warn">We did not find any submissions where the contact author\'s email is ' . $_POST['email'] . '.</span></center><p>';
		printFooter();
		exit;
	}
	else {
		$msg = '
Per your request, here is a list of submissions made to the ' . $OC_configAR['OC_confName'] . ' OpenConf system with you listed as the contact:
';

		while ($e = mysql_fetch_array($r)) {
			$msg .= '
ID:    ' . $e['paperid'] . '
Title: ' . $e['title'] . '
			';
		}
		sendEmail($_POST['email'], "List of submissions made", $msg, $OC_configAR['OC_notifyAuthorEmailPapers']);
		print 'We have emailed the list of submissions for which you are the contact author.<p>';
		printFooter();
		exit;
	}
}
else {
	print "<b>Please enter your email address below and click on <i>Email Submissions</i>.  We will then email you a list of submissions for which you are the contact author.</b><p>\n";
}

print '
<center>
<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
<table border=0>
<tr><td><b>Email:</b></td><td><input size=20 name="email" value="' . varValue('email', $_POST) . '"></td></tr>
<tr><th align="center" colspan=2><br><input type="submit" name="submit" value="Email Submissions"></th></tr>
</table>
</form>
</center>
<p>
';

printFooter();

?>
