<? include("settings.php"); ?>
<?
	if (isset($_REQUEST['paper_number']) && $_REQUEST['paper_number']!=""){
		$bind = array(":search1"=>$_REQUEST['paper_number'], ":search2"=>$_REQUEST['registrant_email']);
		// Send email out to contact person first
		
		$results = $db->select("tbl_abstract","abstract_number = :search1 AND registrant_email = :search2",$bind);
		$result = $results[0];
		
		$registrant_salutation = $result['registrant_salutation'];
		$registrant_firstname = $result['registrant_firstname'];
		$registrant_lastname = $result['registrant_lastname'];
		$emailaddress = $result['registrant_email'];
		$paper_number = $result['abstract_number'];
		$paper_title = $result['abstract_title'];
		$bind = array(
			":search1"=>$result['topic_id']
		);
		$topicresults = $db->select("tbl_topic","topic_id = :search1",$bind);
		$topic = $topicresults[0]['topic'];
		if ($result['abstract_op']=="OR")
			$abstract_op = "Oral";
		else
			$abstract_op = "Poster";
		
		switch ($_REQUEST['submission_type']){
			case "New":
				$email = "submission";
				break;
			case "Revision":
				$email = "revision";
				break;
			case "Full":
				$email = "full";
				break;
		}
		$bind = array(":search1"=>$email);
		$emails = $db->select("tbl_email", "email_description = :search1", $bind);
		$emailtemplate = $emails[0];
		$subject = $emailtemplate['email_subject'];
		$message = $emailtemplate['email_content'];
		
		$mail->ClearAddresses();
		
		$mail->IsHTML(true);
		
		$message = str_replace("@registrant_salutation@",$registrant_salutation,$message);
		$message = str_replace("@registrant_firstname@",$registrant_firstname,$message);
		$message = str_replace("@registrant_lastname@",$registrant_lastname,$message);
		$message = str_replace("@paper_number@",$paper_number,$message);
		$message = str_replace("@paper_title@",$paper_title,$message);
		$message = str_replace("@abstract_op@",$abstract_op,$message);
		$message = str_replace("@topic@",$topic,$message);

		$mail->IsHTML(true);
		$mail->SetFrom("secretariat@nanoman2024.com","Nanoman 2024 Event Secretariat");
		$mail->AddAddress($emailaddress);
		$mail->Subject = $subject;
		$mail->Body = $message;
		//$mail->Send(); // send message
		if(!$mail->send()) 
		{
			echo "Mailer Error: " . $mail->ErrorInfo;
		} 
		else 
		{
			echo "Email Sent<br/><br/>";
		}
		
	}
?>