<?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";

if (isset($whm_id))
	{
	// START CONNECTION STRING ----------------------

	// get the server IP
	$rsip=mysql_fetch_row(mysql_query("select server_ip, server_name, reseller from server_config where whm_id='".addslashes(trim($whm_id))."'"));
	$server_ip=trim($rsip[0]);
	$server_name=trim($rsip[1]);
	$xreseller=trim($rsip[2]);

	// read in logins
	$temp=@read_log($whm_id, $below_public);
	list($xwhm_username, $xwhm_password)=split("[|]", $temp);

	// END CONNECTION STRING ------------------------
	}

if (isset($rebuild))
	{
	write_csv($server_ip, $xwhm_username, $xwhm_password, $below_public, 1, 1, $whm_id);

	$rebuild_csv=true;
	}

if (isset($xrebuild))
	{
	write_csv($server_ip, $xwhm_username, $xwhm_password, $below_public, 1, 1, $whm_id);
	}

include $server_admin_inc."/header.php";

if (!isset($whm_id))
	{
	echo("
		<form action='".$PHP_SELF."' method='POST'>
		<input type='hidden' name='sid' value='".trim($sid)."'>
		<table width='725' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
				<td width='99%' align='left' valign='top'>
				<table width='100%' cellpadding='2' cellspacing='0' border='0'>
					<tr>
						<td colspan='2'><img src='".$http_images."/menu_arrow.gif'> <b>Account Import Utilities</b></td>
					</tr>
					<tr>
						<td colspan='2'><img src='".$http_images."/space.gif' width='15' height='6'></td>
					</tr>
					<tr>
						<td colspan='2'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/error_arrow.gif'> In order to use this tool you must first choose a server to work with from the list below.</td>
					</tr>
					<tr>
						<td width='20%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Choose a Server:</td>
						<td width='80%' align='left' valign='top'><select name='whm_id' ".$input_style.">
					");
				$row1=mysql_query("select whm_id, server_name from server_config order by server_name asc");
				while ($rs1=mysql_fetch_row($row1))
					{
					echo"<option value='".$rs1[0]."'".((isset($whm_id))?"".(($whm_id==$rs1[0])?" selected":"")."":"").">".$rs1[1]."</option>\n";
					}
				echo("
						</select>&nbsp;&nbsp;&nbsp;<input ".$button_style." type='submit' name='go' value='Manage Server'></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</form>
		");

	include $server_admin_inc."/footer.php";
	mysql_close($dblink);
	die;
	}

if (!file_exists($below_public."/whm_csv_".$whm_id.".log"))
	{
	echo("
		<table width='725' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
				<td width='99%' align='left' valign='top'>
				<table width='100%' cellpadding='2' cellspacing='0' border='0'>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Account Import Utilities</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/csv.php?sid=".trim($sid)."'><font color='#990000'>Work With Another Server</font></a>]</td>
					</tr>
					<tr>
						<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='2'></td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'> You are currently working with the server: <b>".$server_name."</b></td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='8'></td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/error_arrow.gif' width='15' height='9'><font color='#990000'>No CSV File Imported.</font></td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='8'></td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><a href='".$http_admin."/csv.php?sid=".$sid."&xrebuild=5&whm_id=".trim($whm_id)."'>Click here to import a CSV file from the active / manual default server.</a></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		");

	include $server_admin_inc."/footer.php";
	mysql_close($dblink);
	die;
	}

echo("
	<table width='725' cellpadding='0' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
			<td width='99%' align='left' valign='top'>
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Account Import Utilities</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/csv.php?sid=".trim($sid)."'><font color='#990000'>Work With Another Server</font></a>]</td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='2'></td>
				</tr>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'> You are currently working with the server: <b>".$server_name."</b></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='8'></td>
				</tr>	
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv.php?sid=".$sid."&rebuild=5&whm_id=".trim($whm_id)."'>Rebuild CSV File</a></td>
				</tr>	
	");
if (isset($rebuild_csv))
	{
	echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/drop_arrow.gif'> <font color='#990000'>CSV Rebuilt Successfully!</font></td>
				</tr>
		");
	}
echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_edit.php?sid=".$sid."&rebuild=5&whm_id=".trim($whm_id)."'>Remove Entries from CSV File</a></td>
				</tr>	
	");
if ($xreseller!=1)
	{
	echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_change_owner.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Change ownership of an account.</a></td>
				</tr>
		");
	}
echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/pb_to_ap.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Generate P*rlBill to AutoPilot User SQL</a></td>
				</tr>	
				<tr>
					<td colspan='2'><hr color='#F3F3F3'></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_user.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Create a new user.</a></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_delete_user.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Delete an existing user.</a></td>
				</tr>		
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_add_user_accounts.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Add accounts to an exsiting user from CSV file.</a></td>
				</tr>	
				<tr>
					<td colspan='2'><hr color='#F3F3F3'></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_reseller_user.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Create a new reseller.</a></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_user_2_reseller.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Mark existing user as a reseller.</a></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_pri_2_user.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Define master domain for existing reseller from the database.</a></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='4'><img src='".$http_images."/error_arrow.gif'> <a href='".$http_admin."/csv_add_reseller_accounts.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Add accounts to an existing reseller from CSV file.</a></td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
	");
include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>