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

// Start Form Handler

if (isset($delete))
	{
	$table=("
			<table width='100%' border='0' cellspacing='1' cellpadding='2'>
				<tr>
					<td><font color='#990000'><b>AutoPilot requries you remove this addon from the following orders before you can continue with this delete:</b></font></td>
				</tr>
				<tr>
					<td><hr color='#F0EFED'></td>
				</tr>
			");

	$q="select ";
	$q.="hosting_order.addon_choices, ";	// 0
	$q.="hosting_order.status, ";		// 1
	$q.="hosting_order.oid, ";			// 2
	$q.="user.first_name, ";				// 3
	$q.="user.last_name, ";				// 4
	$q.="hosting_order.domain_name ";	// 5
	$q.="from ";
	$q.="hosting_order, ";
	$q.="user ";
	$q.="where ";
	$q.="hosting_order.uid=user.uid ";
	$q.="order by ";
	$q.="hosting_order.oid asc";

	$row=mysql_query($q);
	while ($rs=mysql_fetch_row($row))
		{
		$addon_choices=stripslashes(trim($rs[0]));
		$status=stripslashes(trim($rs[1]));
		$xoid=stripslashes(trim($rs[2]));
		$first_name=stripslashes(trim($rs[3]));
		$last_name=stripslashes(trim($rs[4]));
		$domain_name=stripslashes(trim($rs[5]));

		if (trim($addon_choices)!="")
			{
			$ac=substr_count($addon_choices, "|");
			$explode=explode("|", $addon_choices);
			for ($i=0; $i<=($ac-1); $i++)
				{
				if ($explode[$i]===$delete) 
					{ 
					$error.=("
						<tr>
							<td><a href='".$http_admin."/client_view.php?sid=".$sid."&oid=".$xoid."'><img border='0' src='".$http_images."/icon_view.gif'></a>&nbsp;".$first_name." ".$last_name." [".$domain_name."]</td>
						</tr>
						"); 
					}
				}
			}

		unset($domain_name);
		unset($addon_choices);
		unset($status);
		unset($xoid);
		unset($first_name);
		unset($last_name);
		}
	$table.=$error;
	$table.=("
			<tr>
				<td><hr color='#F0EFED'></td>
			</tr>
		</table>
		");
	if (!isset($error)) { mysql_query("delete from addon_specs where aid='".addslashes(trim($delete))."'"); }
	}

// End Form Handler
include $server_admin_inc."/header.php";
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'>
	");
if (isset($error)) { echo $table; }
echo("
			<form action='".$PHP_SELF."' method='POST'>
			".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
			<input type='hidden' name='sid' value='".trim($sid)."'>
			<table width='100%' border='0' cellspacing='1' cellpadding='2'>
				<tr>
					<td align='center' valign='middle' bgcolor='#E5E7E9'><b>#</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Addon Name</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Addon Setup</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Addon Cost / Cycle</b></td>
					<td align='center' valign='middle' bgcolor='#E5E7E9'><b>Edit</b></td>
					<td align='center' valign='middle' bgcolor='#E5E7E9'><b>Delete</b></td>
				</tr>
				");

			$x=1;
			$y=1;
			$query="select ";
			$query.="aid, ";						// 0
			$query.="addon_name, ";					// 1
			$query.="addon_description, ";			// 2
			$query.="addon_show_description, ";		// 3
			$query.="setup_cost, ";					// 4
			$query.="setup_activate, ";				// 5
			$query.="addon_cost, ";					// 6
			$query.="addon_state, ";				// 7
			$query.="addon_activate ";				// 8
			$query.="from addon_specs ";
			$query.="where coupon='0' ";
			$query.="order by addon_name asc";

			$row=mysql_query($query);
			while ($rs=mysql_fetch_row($row))
				{
				$aid=stripslashes(trim($rs[0]));
				$addon_name=stripslashes(trim($rs[1]));
				$addon_description=stripslashes(trim($rs[2]));
				$addon_show_description=stripslashes(trim($rs[3]));
				$setup_cost=stripslashes(trim($rs[4]));
				$setup_activate=stripslashes(trim($rs[5]));
				$addon_cost=stripslashes(trim($rs[6]));
				$addon_state=stripslashes(trim($rs[7]));
				$addon_activate=stripslashes(trim($rs[8]));

				if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
				echo("
					<tr>
						<td align='center' valign='top' bgcolor='".$bgcolor."'>".$x.").</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;
					");
				if ($addon_show_description==1)
					{
					$addon_description=preg_replace("/[^A-Za-z0-9 ]/", "", strip_tags($addon_description));
					$addon_sub=preg_replace("/[^A-Za-z0-9 ]/", "", strip_tags($rs[1]));

					echo "<A HREF='javascript:void(0)' class='cleanlink3' onmouseover=\"return overlib('".$addon_description."', CAPTION, '".stripslashes($addon_sub)."');\" onmouseout='nd();'>".stripslashes($rs[1])."</a>";
					}
				else
					{
					echo stripslashes($rs[1]);
					}
				echo("
						</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;
					");
				if ($setup_activate==1)
					{
					echo $currency."".sprintf("%01.2f",$setup_cost)."".$currency_type;
					}
				else
					{
					echo "None";
					}
				echo("
						</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;
					");
				if ($addon_activate==1)
					{
					if ($addon_state==1) {$display="One time";}
					else if ($addon_state==2) {$display="Month";}
					else if ($addon_state==3) {$display="Year";}
					echo $currency."".sprintf("%01.2f",$addon_cost)."".$currency_type." / ".$display;
					}
				else
					{
					echo "None";
					}
				echo("
						</td>
						<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$http_admin."/addon_build.php?aid=".$rs[0]."&sid=".trim($sid)."'>click</a> ]</td>
						<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$PHP_SELF."?delete=".$rs[0]."&sid=".trim($sid)."'>click</a> ]</td>
					</tr>
					");
				$x++;
				}
	echo("
					<tr>
						<td colspan='6'><img src='".$http_images."/space.gif' width='1' height='8'></td>
					</tr>
				</table>
				</form>
				</td>
			</tr>
		</table>
		");
mysql_close($dblink);
include $server_admin_inc."/footer.php";
?>