<?php

$User_ID = $_COOKIE["User_ID"];
$br = Chr(13).Chr(10);

if (strlen($User_ID)>0) { ?>

<html><head><title>Dream Loom</title>

<link type="text/css" rel="stylesheet" href="style.css"> 
</head>

<body>
<?php
	//$db = mysql_connect("127.0.0.1", "root", "523i12");	//connect to DB
	$db = mysql_connect("localhost", "newalexandria", "523i12"); //connect to DB
	mysql_select_db("newalexandria",$db);	//make active

	if (strlen($_GET['Sel_User_ID']) > 0) {
		$sql = "SELECT * FROM users WHERE User_ID = ".$_GET['Sel_User_ID'];
	} else {
		$sql = "SELECT * FROM users ORDER BY Name";
	}
//	echo $sql;
	$result = mysql_query($sql);
	
    if (mysql_affected_rows()>0) { 
		if (strlen($_GET['Sel_User_ID']) == 0) { 
			echo "<h3>Choose Dreamer</h3>";
			while ($curRow = mysql_fetch_array($result)) {
				echo '<A HREF="dream-view-UI.php?Sel_User_ID='.$curRow['User_ID'].'">'.$curRow['Name'].'</A><BR />';
			}
		} else {
			$curRow = mysql_fetch_array($result);
			echo "<h3>Dreamer</h3>";
			echo $curRow['Name'].'<BR />';
		}
	}



if (strlen($_GET['Sel_User_ID']) > 0) {

	$sql = "SELECT UD.Dream_ID, F.words FROM usersdreams UD INNER JOIN dreams D ON UD.Dream_ID = D.Dream_ID INNER JOIN fragments F on D.Name_Fragment_ID = F.Fragment_ID WHERE User_ID = ".$_GET['Sel_User_ID']." ORDER BY sort";
	$result = mysql_query($sql);
	
//	echo $sql."<BR>";
?>
<h3>Choose Dream</h3>
<?php
		if (mysql_affected_rows()==0) { 
			echo "<i>This user has stated no dreams</i>";
		}
		while ($curRow = mysql_fetch_array($result)) {
				echo '<A HREF="dream.php?Dream_ID='.$curRow['Dream_ID'].'">'.$curRow['words'].'</A><BR />'.$br;
		 }
	}
?>


<BR><BR><BR><a href="dream-view-UI.php">View a different user</a>
<BR><a href="home.php">back</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 
// email graphic for help linked to apology page for hidden email.  
//'lick for frustration' linked to db - rest assured your click has had incremental impact upon a register in our database.

} else { 
	Header("Location: index.php");
}
?>