<?php

include "db_functions.php";
include "navs.html";

?>
<SCRIPT LANGUAGE="JavaScript">
	function clickdelete(id)	
	{
		answer = confirm("Delete subscriber with id: " + id)
		if (answer)
		{
			sortform.deleteid.value=id;
			sortform.submit();
		}
	}
	
	function clicksort(n)
	{
		if (n = sortform.orderby.value)
		{
			if (sortform.aord.value = "ASC")
			{
				alert("it was ASC")
				sortform.aord.value = "DESC"
			}
			else
			{
				alert("it was not ASC")
				sortform.aord.value = "ASC"
			}
		}
		sortform.orderby.value = n
		sortform.submit()
	}
</SCRIPT>	

<DIV STYLE="position: absolute; top: 138px; left: 280px; z-index:4; font-family: sans-serif; font-size: 8pt;">
<TABLE STYLE="font-family: sans-serif; font-size: 8pt;" CELLPADDING=2 CELLSPACING=2 BORDER=0 BGCOLOR=#2161C6>	

<?php
	
	if (empty($flag))
	{
?>	
		<TR>
			<TD>
				<FORM METHOD=POST ACTION="list.php">
					<TABLE STYLE="font-family: sans-serif; font-size: 8pt;" CELLPADDING=0 CELLSPACING=0 WIDTH=400 BORDER=0 ALIGN=CENTER>		<TR>
						<TD>Password: </TD><TD><INPUT TYPE="password" NAME="pd"></TD>
					</TR>
					<TR>
						<TD colspan=2>
							<BR>
							<INPUT TYPE="HIDDEN" NAME="flag" VALUE="1">
							<INPUT TYPE="HIDDEN" NAME="orderby" VALUE="2">
							<INPUT TYPE="HIDDEN" NAME="greg" VALUE="joe">
							<INPUT TYPE="HIDDEN" NAME="aord" VALUE="ASC">
							<INPUT TYPE="submit" name="submit" value="Submit">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</TD>
					</TR>
					</TABLE>
				</FORM>
			</TD>
		</TR>				
								
<?php
	}
	else if (($pd == "drcnews") or ($_SESSION['loggedin']=1))
	{
		session_start();
		// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
		if (!isset($_SESSION['loggedin'])) 
		{
			$_SESSION['loggedin'] = 1;
		}
	echo "greg: $greg<BR><br>\n";
	echo "aord: $aord<BR><br>\n";
?>
		<FORM METHOD=POST ACTION="list.php" NAME="sortform">
		<INPUT TYPE="hidden" NAME="orderby" VALUE="<?php echo $orderby ?>">
		<INPUT TYPE="hidden" NAME="deleteid" VALUE="0">
		<INPUT TYPE="HIDDEN" NAME="aord" VALUE="<?php echo $aord ?>">
		<TR STYLE="font-weight: bold; ">
			<TD BGCOLOR=#EFEBDE>DEL</TD>
<?php		
		$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
		if ($db == false)
		{
			return mysql_errno().": ".mysql_error()."<br>";
		}
		$result = mysql_db_query(DB_NAME, "select * from signups", $db) or die(mysql_error());
		$i = 0;
		$header_row = "";
		$part1 = "<TD onClick='clicksort(";
		$part2 = ");' BGCOLOR=#EFEBDE>";
		while ($i < mysql_num_fields($result)) 
		{
		    $info = mysql_fetch_field($result);  //get field names
		    $i++;
		    $sorted = "";
		    if ($orderby == $i)
		    {
		    	$sorted = " *";
		    }
		    $header_row = $header_row.$part1.$i.$part2.$info->name."</TD>\n";
		    echo $part1.$i.$part2.$info->name.$sorted."</TD>\n";
		}

?>
		</TR>
		<INPUT TYPE="HIDDEN" NAME="flag" VALUE="1">
		</FORM>
<?php
		if ($deleteid <> 0)
		{
			DeleteQuery("signups", "id = $deleteid");		
		}
		
		//if ($orderby == "None")
		//{
		//	$orderby = "";
		//}
		//else
		//{
			$orderby = "ORDER BY $orderby $aord";
			echo "orderby: $orderby<BR><BR>\n";
		//}

		$values = SelectQuery ("signups", "*", "", "", $orderby);
	
		if (!is_array($values))
		{
			echo "Error: $values<br>\n";
			exit;
		}
	
		$one = $values[1];
	    $nArraySize = count($one); 
	    $t = count($values);
	    echo "$t<br><br>\n";
		while (list(,$v) = each ($values))
		{
			echo "<TR>\n";
			//echo "<TD BGCOLOR=#EFEBDE onClick='sortform.deleteid.value=$v[0]; sortform.submit();'>DEL</TD>\n";
			echo "<TD BGCOLOR=#EFEBDE onClick='clickdelete($v[0]);'>DEL</TD>\n";
			for($index=0; $index < $nArraySize; $index++)
			{
				echo "<TD BGCOLOR=#EFEBDE>$v[$index]</TD>\n";
			}
			echo "</TR>\n";
		}
		
		//$elist = rtrim ($elist, ", ");
		
		//echo $elist."|<br>";
	}
	else
	{
		echo "Bad password.<br>\n";
	}
?> 

</TABLE>
</DIV>
