<?php 		// Header and navigation bar
	require_once("/library/webserver/cgi-executables/lw3_ini.php");

	$email = $_POST['email'];
	
	if ($email) {
		$error = "Checking email!<br>";
		$link = mysql_connect("$manage_server","$user","$pw");
		if (! $link) {
			die("Could not connect to mysql");
		}

		$email = mysql_real_escape_string($email);
		
		// select a database
		$database = 'libraryworld';
		mysql_select_db($database) or die ("Couldn't open database");
		
		// Do the select
		$result = mysql_query( "SELECT user_id, username, password from users where email = '$email'");
		$num_rows = mysql_num_rows($result);
		$a_row = mysql_fetch_array($result);
		
		$l_userid = stripslashes($a_row['user_id']);
		$l_username = stripslashes($a_row['username']);
		$l_password = stripslashes($a_row['password']);
		
		// close the link
		mysql_close($link);
		
		if ($l_userid == '') {
			$error = "<font color=red>Error - unknown email address.</font><p>";
		}
		else {
			
			// email new users
			$to = $email;
			$from = 'webmaster@libraryworld.com';
			$subject = "Libraryworld.com Username and Password reminder";
			$msg = "You requested to be reminded of your username and password.\n\n" .
	          	"Your User Name is: $l_username\n" .
		 	  "Your Password is: $l_password\n\n" .
	          	"If you did not request to be reminded, do not worry your username and password are safe.   However, if you continue to receive these notices, please contact LibraryWorld support.\n";
	          
	       		# mail($to,$subject, $msg, "From: $from\r\n") or print "Could not send meail.";

			 $msg = str_replace("'","",$msg);
		       	 $msg = str_replace('"','',$msg);
			
			 $rtn = system("perl /usr/lib/cgi-bin/sendgrid.pl '$to' '$from' '$subject' '$msg'"); 

			
			header("Location:http://$hostname/assets4/docs/forget_confirm.php");
		
			exit;
			
		}
	}
?>


<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">
    <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="copyright" content="LibraryWorld Inc. -- 2009">
    <STYLE type="text/css">
	</STYLE>
    <title>LibraryWorld Tutorials</title>
    <link href="/css_lw2.css" rel="stylesheet" type="text/css">
  </head>

<body topmargin=0 leftmargin=0 rightmargin=0 marginheight=0 marginwidth=0
	onLoad="document.form1.term.select();document.form1.term.focus(); window.resizeTo(700,500);  " bgcolor="#EEEEEE"       
>

<!-- frame the main page --> 
<table bgcolor="WHITE" align=center width=600 height=400 border=0 cellborder=0 cellspacing=0> <tr><td valign=top>

<table width=100%><tr>
<td width=240 valign=top><img src="/images/lw_logo.gif" alt="libraryworld"  width="224" " border="0"></td>
<td valign=middle><font size=+1><b><?php echo "$title"?></b></font></td>
</tr></table>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
	<tr><td>
<!-- Main area - navigation in column one - content in column two -->
<table border=0 align=center width=95%>
<tr>
<td colspan="5" class="page_on_title">Username and Password Request </td>
</tr>
<tr><td>

<br> <center> 
<?php echo "$error"?>
Enter your email address and press send.<br> Your username and password will be sent to your email if it is a valid email address.<p>
<center> Or return to the home page. <a href="/cgi-bin/lw4.pl?command=home">Return</a><p>
<form method="post" action="forget.php">
<p>Email Address: <input type="text" name="email" value="" size="30"></p>
<input type="hidden" name="command" value="login" size="20"></p>
<p><input type="submit" value="Send"></p>
</form>

</td></tr></table>

</td></tr> </table>  <!-- End of Main Content  -->

</body>
</html>




