<?php
$loc = 2;	//developer switch

//this document uses the variable x to control the display of informtion
// x = "" populates a drop-down with all companies in the database, from which the user selects the one they wish to edit.
// x = 1 populates the drop-down with companies who's name begins with their user's search
// x = 2 assumes they've selected a company for editing and that a GET variable, client_ID will contain their chosen company.  
// x = 3 displays the client edit fields, but leaves them all empty so that a new client may be added to the database
// x = 4 accepts client data and adds or updates it based on the presence of Client_ID 

//$User_ID = $HTTP_COOKIE_VARS["user[User_ID]"];
$Admin = $_COOKIE["Admin"];
$User_ID = $_COOKIE["User_ID"];
//$User_ID = $x;


	$db = mysql_connect("localhost", "newalexandria", "523i12"); //connect to DB
	mysql_select_db("newalexandria",$db);	//make active

	$x = $_GET['x'];
	
	// select rec
	if ($x == 4) {
			$sql = "SELECT * FROM users WHERE login = '".$_GET['Login']."'";
			$result = mysql_query($sql);
			if (mysql_affected_rows($db)==0) {
				$sql = "INSERT INTO users (Name, Password, Login) VALUES ('".$_GET['Name']."', '".$_GET['Password']."', '".$_GET['Login']."')";
			} else {
				$x = 3;
			}
	}

		$result = mysql_query($sql);

		?>
		<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
				"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
		<html lang="en">
		<head>
			<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
			<title>Edit Users</title>
			<link rel="Stylesheet" type="text/css" href="style.css">
			<meta name="generator" content="BBEdit 6.5.3">
		
		</head>
		
		<body bgcolor="#ffffff" style="	background-image: none;">
		<?php
			if ($x == "") { 
		?>
		Greetings!  To participate in the collective dreaming please create an account.  Accounts give a home to all of a person's online dreams, and allow permuted dreams to have a genealogy.<BR><BR>
		<form action="users.php" method="get">

		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>User Name</td>
				<td>&nbsp;</td>
				<td><input type="text" name="Name" size="30" maxlength="100" value="<?php echo $_GET['Name'] ?>"></td>
			</tr>
			<tr>
				<td>Login</td>
				<td>&nbsp;</td>
				<td><input type="text" name="Login" size="30" maxlength="40" value="<?php echo $_GET['Login'] ?>"></td>
			</tr>
			<tr>
				<td>Password</td>
				<td>&nbsp;</td>
				<td><input type="password" name="Password" size="30" maxlength="40" value="<?php echo $_GET['Password'] ?>"></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td><input type="submit" value="Create"></td>
			</tr>
		</table>
		<input type="hidden" name="x" value="4">
		
		</form>
		<?php  
		} elseif (($x == 4) || ($x == 3)) {  
			if ((mysql_errno() == 0) && ($x == 4)) {
				echo "You account has been setup.<BR><BR>";
				echo '<a href="login.php">Login</a> and share your dreams';
			} elseif ($x == 3) {
				echo "The account name ".$_GET['Name'].'was selected already, <a href="users.php?Name='.$_GET['Name'].'">please choose another</a>.<BR><BR>';
			} else {
				echo $sql."<BR><BR>";
				echo (mysql_errno() == 0)."<BR><BR>";
				echo "<p>There was a problem; Error ".mysql_errno().": ".mysql_error()."</p>\nIf a solution is not obvious to you then please contact the administrator.";
			} 
		} 
		?>
		<BR><BR><BR><a href="index.php">Home</a>
		
		<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1203790-1";
urchinTracker();
</script></body></html>
		<?php	

?>