<?PHP
include "../inc/var.php";
include "../inc/connect.php";
include $server_inc."/whm_functions.php";
include $server_inc."/client_functions.php";
include $server_inc."/login_functions.php";

include $server_admin_inc."/header.php";

// Start Form Handler
if (isset($submit))
	{
	mysql_query("update server_config set install_order='0', ogcreate='".addslashes(trim($rs2[1]))."'");

	/*
	1 = Next Active Server
	0 = Installed Server
	*/

	mysql_query("update server_config set install_order='1', ogcreate='".addslashes(trim($rs2[1]))."' where whm_id='".addslashes(trim($whm_id))."'");
	}

// Start Form Handler
if (isset($disable))
	{
	mysql_query("update server_config set install_order='0', ogcreate='".addslashes(trim($rs2[1]))."'");
	}

// End Form Handler

$ctx=mysql_fetch_row(mysql_query("select count(*) from server_config"));
$cty=mysql_fetch_row(mysql_query("select count(*) from server_config where active_server='1'"));
$ct=mysql_fetch_row(mysql_query("select count(*) from server_config where install_order='0'"));

// build query order
if ($cty[0]==1)
	{
	$query_order="active_server desc, install_order desc";
	}
else
	{
	$query_order="manual_install_active desc, install_order desc";
	}

echo ("
	<table width='725' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='11' height='1'></td>
			<td width='99%' align='left' valign='top'>
	");
if ($ctx[0]==$ct[0])
	{
	echo("
		<table width='100%' cellpadding='2' cellspacing='0' border='0'>
			<tr>
				<td><img src='".$http_images."/menu_arrow.gif'>Automatic server rotation is currently <b>disabled</b>. To enable this service, please define a server rotation below.</td>
			</tr>
		</table>
		");
	}
else
	{
	echo("
		<table width='100%' border='0' cellspacing='1' cellpadding='4'>
			<tr>
				<td width='50%' align='left' valign='middle'><img src='".$http_images."/menu_arrow.gif'>Automatic server rotation is currently <b>enabled</b>.</td>
				<td width='50%' align='right' valign='middle'>[<a href='".$http_admin."/server_position.php?sid=".trim($sid)."&disable=5'>disable server rotation</a>]&nbsp;&nbsp;</td>
			</tr>
		</table>
		");
	}
echo("
<!--- Start Main --->
<table width='100%' border='0' cellspacing='1' cellpadding='6'>
		<tr>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>#</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Server Name</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Server Role</b></td>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>Rotation Role</b></td>
		</tr>
	");

$x=1;
$y=1;
# $row=mysql_query("select server_name, max_accounts, active_server, manual_install_active, UNIX_TIMESTAMP(ogcreate), whm_id, ogcreate, server_ip, install_order from server_config order by ".addslashes(trim($query_order))."");
$row=mysql_query("select server_name, max_accounts, active_server, manual_install_active, ogcreate, whm_id, ogcreate, server_ip, install_order from server_config order by ".addslashes(trim($query_order))."");
while ($rs=mysql_fetch_row($row))
	{
	if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
	echo("
	<form action='".$PHP_SELF."' method='POST'>
	<input type='hidden' name='whm_id' value='".$rs[5]."'>
	<input type='hidden' name='ogcreate' value='".$rs[6]."'>
	<input type='hidden' name='sid' value='".trim($sid)."'>
		<tr>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>".$x.").</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>
			<table width='100%' cellpadding='0' cellspacing='0' border='0'>
				<tr>
					<td width='10%' align='left' valign='middle'><a href='".$http_admin."/server_config.php?whm_id=".trim($rs[5])."&sid=".trim($sid)."'><img border='0' src='".$http_images."/icon_view.gif'></a></td>
					<td width='90%' align='left' valign='middle'><a href='".$http_admin."/server_config.php?whm_id=".trim($rs[5])."&sid=".trim($sid)."'>".(($rs[8]==1)?"<font color='#990000'>".stripslashes($rs[0])."</font>":"".stripslashes($rs[0])."")."</a></td>
				</tr>
			</table>
			</td>
		");
if (trim($rs[2])=="0")
	{
	// not an active server
	if (trim($rs[3])=="0")
		{
		if ($rs[8]==1)
			{
			$role="<font color='#990000'>Installed Server</font>";
			}
		else if ($rs[8]==2)
			{
			$role="Server Full";
			}
		else
			{
			$role="Installed Server";
			}
		}
	else
		{
		// the ns default
		if ($rs[8]==1)
			{
			$role="<font color='#990000'>Manual Default</font>";
			}
		else if ($rs[8]==2)
			{
			$role="Server Full";
			}
		else
			{
			$role="Manual Default";
			}
		}
	}
else
	{
	// active server
	if ($rs[8]==1)
		{
		$role="<font color='#990000'>Active Server</font>";
		}
	else if ($rs[8]==2)
		{
		$role="Server is Full";
		}
	else
		{
		$role="Active Server";
		}
	}
echo("
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".$role."</td>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>
		");
	if ($role=="Manual Default")
		{
		echo"Accounts are manually installed here.";
		}
	else if ($role=="Active Server")
		{
		echo"New accounts install here.";
		}
	else if ($rs[8]==1)
		{
		echo"<font color='#990000'>Next Active Server</font>";
		}
	else if ($rs[8]==2)
		{
		echo"This server is full.";
		}
	else
		{
		echo"<input ".$button_style." type='submit' name='submit' value='Make Next Active Server'>";
		}
	echo("
			</td>
		</tr>
		</form>
		");
	$x++;
	}
echo("
	<tr>
		<td colspan='4'><img src='".$http_images."/space.gif' width='1' height='8'></td>
	</tr>
</table>

		</td>
	</tr>
</table>
<!--- End Main --->
	");
// End Main Process
mysql_close($dblink);
include $server_admin_inc."/footer.php";
?>