<?
	require_once($_SERVER['DOCUMENT_ROOT']."/superdarn2008/scripts/dbConnect.php");
	$MAIN_LOC = "http://www.tiger.latrobe.edu.au/superdarn2008/modpaperdetails.php";
	$HEADER_LOC = "http://www.tiger.latrobe.edu.au/superdarn2008/modpaper.php";

	
	session_start();
	
	/** *********************************************
	  *	Process the call for papers form
	  *
	 ** ****************************************** */
	if($_POST)
	{
		if( isset($_POST['PaperID']) && isset($_POST['password']) )
		{
			//All fields were successfully filled in
			$errorFlag = 0;

			//Let's begin to prepare the data for DB insertion
			if(get_magic_quotes_gpc()) {
        $cPaperID			= stripslashes(trim($_POST['PaperID']));
        $cPasswd			= stripslashes(trim($_POST['password']));
			} else {
        $cPaperID			= trim($_POST['PaperID']);
      	$cPasswd			= trim($_POST['password']);
			}
			unset($_POST);
			
			
			//Validate data fields
			if($cPaperID === "" || $cPasswd === "")
			{
				$errorFlag = 1;
			}

			//If submitted data is valid, let's continue and begin database insertion
			if($errorFlag == 0)
			{
				$db = connect_and_open("webuser", "sdarn08", "sDarn08");
				
				//Let's validate the login
				$sql = sprintf("SELECT PaperID, Password from PaperContact where PaperID = '%s' and Password = '%s'",
								mysql_real_escape_string($cPaperID, $db),
								mysql_real_escape_string($cPasswd, $db) );

				if (mysql_num_rows(run_query($sql, $db)) == 1)
				{
					
					//Store the details as a session
					$_SESSION['pid'] = $cPaperID;
					$_SESSION['pwd'] = $cPasswd;
					$_SESSION['modSYS'] = 1;

					//- ALL TABLES FILLED WITH NO ERROR
					dcon_and_close($db);

					header("Location: $MAIN_LOC");
					exit();
					
					
				}
				else
				{
					header("Location: $HEADER_LOC?e=1");
      		exit();
				}
      }
      else
      {
      	$_SESSION['modSYS'] = 0;
      	if($errorFlag == 1)
      	{
      		header("Location: $HEADER_LOC?e=1");
      		exit();
      	}
      }
    }
    else
    {
      	$_SESSION['modSYS'] = 0;
      	header("Location: $HEADER_LOC?e=1");
      	exit();
    }

	}
	else
	{	/** ****************************************
			* NO SUBMIT - THEREFORE NORMAL PAGE DISPLAY
			*
			* ****************************************
		**/
		$_SESSION['modSYS'] = 0;
		HTML_top();
	
		HTML_Display();
		
		HTML_bottom();
	}	//end else of not submit


	/**	********************************
	  *	THE TOP HTML STUFF
	  *
	  ** ***************************** */
	function HTML_top()
	{ ?>
		<html>
			<head>
				<title>SuperDARN 2008 - Modification of Presentation Title / Contact Details</title>
				<link rel="stylesheet" href="../assets/css/LTUtypespecs.css" type="text/css">
				
				<script type="text/javascript">
		      function errorCheck(thisform)
					{
						//create variables for script
						var sPaperID = -1;
						var sPass = -1;
						var requiredFieldsErrorMessage = "";
						var alertMessage = "";
						
						//gather values of applicant's name
						sPaperID	= document.forms['modPaper'].elements['PaperID'].value;
						sPass	= document.forms['modPaper'].elements['password'].value;
												
						if (sPaperID == "") {
							requiredFieldsErrorMessage = requiredFieldsErrorMessage + "- PaperID field must be entered\n";
						}
						if (sPass == "") {
							requiredFieldsErrorMessage = requiredFieldsErrorMessage + "- Password field must be entered\n";
						}
						
						//Error message displays
						if (requiredFieldsErrorMessage)
						{
							if(requiredFieldsErrorMessage) {
								alertMessage = "Oops! There's a little trouble with the information you have provided.\n\n";
								alertMessage = alertMessage + "The following conditions must be met in order to procede:\n"
								alertMessage = alertMessage + requiredFieldsErrorMessage;
							}
		
							alert(alertMessage);
						}
						else {
							document.forms['modPaper'].submit();
						}
					}
	 			</script>
		</head>

		<body bgcolor="#FFFFFF" text="#333333" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#DB0000" vlink="#666666" alink="#990000">

		<table name="mainarea" width="100%" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0"><tr><td>

			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
			    <td height="43" bgcolor="#FFFFFF" valign="top" align="left">
			          <table width="100%" border="0" cellspacing="0" cellpadding="0">
					        <tr>
					          <td bgcolor="#000000" width="150"><a href="http://www.newcastle.edu.au/school/math-physical-science/"><img src="../assets/images/logo_scitech_newcastle.gif" alt="Welcome to Newcastle University" border="0" width="147" height="38"></a></td>
					          <td bgcolor="#000000" width="99%"><img src="../assets/images/masthead_newcastle.gif" width="450" height="47" alt="School of Mathematical and Physical Sciences"></td>
					          <td valign="top" align="right" width="150"><a href="http://www.latrobe.edu.au"><img src="../assets/images/logo_latrobe.gif" width="150" height="47" border="0"></A></td>
					        </tr>
					      </table>
			    </td>
			  </tr>
			  <tr>
			    <td bgcolor="#FFFFFF" valign="top" align="left" height="99%">
			    	<table border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" width="100%">
			  			<tr>
			    			<td width="147" valign="top" align="center"> <img src="../assets/images/devices/spacer.gif" width="147" height="1">
			    			<br><br>

								<table width="137" border="0" cellpadding="2" align="center" cellspacing="0">
		   		    		<tr valign="top" align="left">
				       	    <td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
		    		   	    <td width="118">
		       			    <p class="TextMidGreySmallBold"><a href="index.html" class="LinkRedSmallBold">Home</a></p></td>
		   	        	</tr>
		   	        	<tr valign="top" align="left">
										<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
										<td width="118">
										<p class="TextMidGreySmallBold"><a href="first.html" class="LinkRedSmallBold">Announcements</a></p></td>
		            	</tr>
		   	        	<tr valign="top" align="left">
										<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
										<td width="118">
										<p class="TextMidGreySmallBold"><a href="program.html" class="LinkRedSmallBold">Workshop Program</a></p></td>
		            	</tr>
		   	        	<tr valign="top" align="left">
										<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
										<td width="118">
										<p class="TextMidGreySmallBold"><a href="regoform.html" class="LinkRedSmallBold">Registration Form</a></p></td>
									</tr>
		            	<tr valign="top" align="left">
		       	 				<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
		       	 				<td width="118">
		        				<p class="TextMidGreySmallBold"><a href="organisers.html" class="LinkRedSmallBold">Conference Organisers</a></p></td>
		  	        	</tr>
		            	<tr valign="top" align="left">
		            		<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
		            		<td width="118">
		            		<p class="TextMidGreySmallBold"><a href="travelinfo.html" class="LinkRedSmallBold">Travel Information</a></p></td>
		            	</tr>
		            	<tr valign="top" align="left">
										<td width="7"><img src="../assets/images/arrow_greydark.gif" width="7" height="10"></td>
										<td width="118">
										<p class="TextMidGreySmallBold"><a href="contactus.html" class="LinkRedSmallBold">Contact Us</a></p></td>
									</tr>

								<td width="7" height="10"></td>
								<td width="118" height="10"></td>
				  		</tr>
				  	</table>

		     <!-- #EndLibraryItem -->
		      <table WIDTH="92%" BORDER="0">
		        <tr>
		         <td ALIGN="center"><span CLASS="TextDarkGreyMedium"><SPAN CLASS="TextDarkGreyMedium"><span CLASS="TextDarkGreyMedium"><SPAN CLASS="TextDarkGreySmall">
		         <span CLASS="TextDarkGreySmall"><SPAN CLASS="TextDarkGreySmall"><SPAN CLASS="TextDarkGreySmall">
		         <!-- #BeginLibraryItem "/Library/Contact%20SN&M.lbi" -->
		         <LINK REL="stylesheet" HREF="./assets/css/LTUtypespecs.css" TYPE="TEXT/CSS">
		         <SPAN CLASS="TextDarkGreyMedium"><SPAN CLASS="TextDarkGreyMedium"><SPAN CLASS="TextDarkGreyMedium">
		         <p>&nbsp;</p>
		         <SPAN CLASS="TextDarkGreySmall">
		         School of<BR>
		         Mathematical &<BR>
		         Physical Sciences<BR>
		         Newscastle University<BR>
		         NSW 2308 AUSTRALIA <BR>
		         Tel: +61 2 4921 5539<BR>
		         Fax: +61 2 4921 6898<BR>
		         </SPAN>
		         <A HREF="mailto:webmaster_ee@latrobe.edu.au" CLASS="LinkRedSmall">Email us </A></SPAN><BR>
		         </TD>
		       </TR>
		     </TABLE>
		      <br>
		          </td>
		          <td width="1" valign="bottom" background="./assets/images/line_dotted_v.gif" align="left"><img src="./assets/images/spacer_white10h.gif" width="1" height="10"></td>
		          <td width="10" valign="top" align="left"><img src="./assets/images/spacer.gif" width="10" height="1"></td>
		          <td width="99%" valign="top" align="left"> <img src="./assets/images/spacer.gif" width="1" height="1"><br>
		            <a name="top"></a>
		            <table width="98%" border="0" cellspacing="0" cellpadding="0">
		         </table>
		        <br>

		<!--- Main contents -->
		<table width="85%" cellpadding="0" cellspacing="0" border="0">
		<tr>
		<td><a href="http://superdarn.jhuapl.edu/"><IMG SRC="../images/sd_sm.gif" WIDTH=112 HEIGHT=129 BORDER=0 ALIGN="left" ALT="SuperDARN" HSPACE=10></a><a href="../index.html"><IMG SRC="../images/logo_5.jpg" WIDTH=128 HEIGHT=126 BORDER=0 ALIGN="right" ALT="TIGER" HSPACE=10></a>
		<center>
		<br>
<?
	}

	/**	********************************
	  *	THE BOTTOM HTML STUFF
	  *
	  ** ***************************** */
	function HTML_bottom()
	{ ?>
		<p>&nbsp;</p>
		<p>&nbsp;</p>


		<!-- Footer section -->
		            <span class="TextFootNotes">Content Approved by: Principal Investigator: Prof. P.L. Dyson<br>
		            Page maintained by: <a href="mailto:webmaster_ee@latrobe.edu.au">Webmaster</a><br>
		            Last Updated: 31th January, 2008</span>
					<span class=TextDarkGreyMedium></span>

		            <span class=TextFootNotes></span><span class="TextFootNotes"></span> <br><br>
		            <font size="1"><a href="#top" class="LinkRedSmall">return to top</a></font><br>
		          </td>

		  <tbody>
		  </tbody>
		  </table>

			    <p><br>
		            <span class="TextDarkGreySmallBold"><br>
		            </span>
		            </p>
		            <p>
		            <br>
		          </td>
		        </tr>
		      </table>
		    </td>
		  </tr>
		  <tr>
		   <td height="15" bgcolor="#FFFFFF" valign="bottom" align="left">&nbsp; </td>
		  </tr>
		</table>

		<table width="100%" border="0" cellspacing="0" cellpadding="0" height="17">
			<tr>
		    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
		    	<form method="get" action="http://www.latrobe.edu.au/cgi-bin/htsearch">
				    	<a href="http://www.latrobe.edu.au/search" class="navtext">
							&nbsp;Search&nbsp;
							</a>
						</td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
				    	&nbsp;<img src="./assets/images/nav_divider_off.gif" width="1" height="17" alt="">&nbsp;
						</td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
							<input type="hidden" name="restrict" value="melkor.latrobe.edu.au/cs">
							<input type="text" name="words" value="Search Here" size="12" class="search" ONBLUR="if (value =='') {value = 'Search Here'}" ONFOCUS="if (value == 'Search Here') {value =''}">
						</td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
				    	&nbsp;<img src="./assests/images/nav_divider_off.gif" width="1" height="17" alt="">&nbsp;
						</td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
				    	<a href="http://www.latrobe.edu.au/contact" class="navtext">
							&nbsp;Contact LTU&nbsp;
							</a>
				    </td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
				    	&nbsp;<img src="./assets/images/nav_divider_off.gif" width="1" height="17" alt="">&nbsp;
						</td>
				    <td nowrap bgcolor="#000000" nowrap valign="middle" align="left">
				    	<a href="http://www.latrobe.edu.au/sitemap/" class="navtext">
							&nbsp;Sitemap&nbsp;
							</a>
				    </td>
						<td bgcolor="#CCCCCC" nowrap valign="middle" align="left" width="99%">
					</form>
					<table border="0" cellspacing="0" cellpadding="0" height="17" width="100%">
						<tr>
							<td nowrap width="10" valign="middle" align="left"><img src="./assets/images/spacer.gif" width="10" height="1" alt=""></td>
							<td nowrap class="TextFootNotes" valign="middle" align="left"><a href="http://www.latrobe.edu.au/copyright/disclaimer.html"><span class="TextFootNotes" style="color: #666666 ; font-family: Verdana, Geneva, Tahoma, Arial; font-size: 10px; font-style: italic; text-decoration:none;">Copyright &copy; 2008 La Trobe University, Credits &amp; Disclaimer</span></a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<!-- End nav_bottom -->
		</body></html>
<?
	}
	

	/**	********************************
	  *	THE FORM AND MAIN ENTRY STUFF
	  *
	  ** ***************************** */
	
	function HTML_Display()
	{ ?>
		<? if(isset($_GET['e']) && $_GET['e'] == 1)	{ $e = 1; unset($_GET); } /* error checking */ ?>
		
		<font face="Arial,Times" size="+2">SuperDARN 2008 Annual Meeting</font><br>
		<font FACE="Arial,Times" SIZE="+1">Newcastle, NSW.   Australia, 1st &#150; 6th of June 2008</font><br>
		<font FACE="Arial,Times" SIZE="+3">Modification Of Submitted Presentation Title</font>
		</center></td>
		</tr>
		</table>
		<p>&nbsp;</p>
	
		<form action="<?= $_SERVER['PHP_SELF']; ?>" method="POST" name="modPaper" onSubmit="javascript:errorCheck(modPaper); return false;">
			<table width="99%" cellspacing="1" cellpadding="1" border="0">
				<tr>
					<td class="TextDarkGreyMediumBold">&nbsp;</td>
					<td class="TextDarkGreyMedium" width="90%">&nbsp;</td>
				</tr>
<?
				if($e == 1)
				{
					?>
					<tr>
						<td class="TextDarkGreyMediumBold">&nbsp;</td>
						<td class="TextDarkGreyMedium" width="90%"><font color="red">Errors were detected in the login form</font></td>
					</tr>
					<tr>
						<td class="TextDarkGreyMediumBold">&nbsp;</td>
						<td class="TextDarkGreyMedium" width="90%">&nbsp;</td>
					</tr>
					<?
				}
?>
				<tr>
	 				<? if($e == 1) { ?>	 				
	 					<td width="157" class="TextDarkGreyMediumBold"><label for="PaperID"><font color="red">Paper ID: </font></label></td>
	 				<? } else {	 ?>
	 					<td width="157" class="TextDarkGreyMediumBold"><label for="PaperID">Paper ID: </label></td>
	 				<? } ?>
	 					<td width="439" class="textdarkgreymedium"><input type="text" name="PaperID" id="PaperID" size="40"></td>
				</tr>
				<tr>
	   			<? if($e == 1) { ?>	 				
	 					<td class="TextDarkGreyMediumBold"><label for="password"><font color="red">Password: </font></label></td>
	 				<? } else {	 ?>
	 					<td class="TextDarkGreyMediumBold"><label for="password">Password: </label></td>
	 				<? } ?>
	   			<td class="textdarkgreymedium"><input type="password" name="password" id="password" size="40"></td>
				</tr>
				<tr>
					<td class="TextDarkGreyMediumBold">&nbsp;</td>
					<td class="TextDarkGreyMedium" width="90%">&nbsp;</td>
				</tr>
				<tr>
					<td class="TextDarkGreyMediumBold">&nbsp;</td>
					<td class="TextDarkGreyMedium" width="90%"><input type="submit" name="logBut" value="Login"></td>
				</tr>
				<tr>
					<td class="TextDarkGreyMediumBold">&nbsp;</td>
					<td class="TextDarkGreyMedium" width="90%">&nbsp;</td>
				</tr>
			</table>
		</form> <?
	}
?>