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

// Start Form Handler

if (isset($delete))
	{
	$update="update plan_specs set ";
	$update.="com_type='0', ";
	$update.="com_rate_onetime='0', ";
	$update.="com_rate_month='0' ";
	$update.="where pid='".addslashes(trim($delete))."' ";
	
	mysql_query($update);
	}

// End Form Handler

include $server_admin_inc."/header.php";

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)."'>
<!--- Start Main --->
<table width='700' border='0' cellspacing='1' cellpadding='2'>
		<tr>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>#</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Package Group</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Package Name</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Commission Type</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'><b>Commission Amount</b></td>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>Edit</b></td>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>Delete</b></td>
		</tr>
	");
$query="select ";
$query.="plan_specs.pid, ";					// 0
$query.="plan_specs.package_name, ";		// 1
$query.="plan_specs.web_space, ";			// 2
$query.="plan_specs.bandwidth, ";			// 3
$query.="plan_groups.name, ";				// 4
$query.="plan_specs.com_type, ";			// 5
$query.="plan_specs.com_rate_month, ";		// 6
$query.="plan_specs.com_rate_onetime, ";	// 7
$query.="plan_specs.monthly_cost, ";		// 8
$query.="plan_specs.quarterly_cost, ";		// 9
$query.="plan_specs.semi_annual_cost, ";	// 10
$query.="plan_specs.annual_cost ";			// 11
$query.="from ";
$query.="plan_specs, ";
$query.="plan_groups ";
$query.="where ";
$query.="plan_specs.gid=plan_groups.gid ";
$query.="order by ";
$query.="plan_groups.name, ";
$query.="plan_specs.package_name ";
$query.="asc";

$x=1;
$y=1;
$row=mysql_query($query);
while ($rs=mysql_fetch_row($row))
	{
	$monthly_cost=stripslashes(trim($rs[8]));
	$quarterly_cost=stripslashes(trim($rs[9]));
	$semi_annual_cost=stripslashes(trim($rs[10]));
	$annual_cost=stripslashes(trim($rs[11]));
	
	if ($monthly_cost!="-1") { $base=$monthly_cost; }
	else if ($quarterly_cost!="-1") { $base=$quarterly_cost; }
	else if ($semi_annual_cost!="-1") { $base=$semi_annual_cost; }
	else if ($annual_cost!="-1") { $base=$annual_cost; }

	else if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
	# $monthly_cost=$rs[8];
	$com_monthly=$rs[6];
	echo("
		<tr>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>".$x.").</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".stripslashes($rs[4])."</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".stripslashes($rs[1])."</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".(($rs[5]==0)?"No Plan Defined":"".(($rs[5]==1)?"One Time":"Percent")."")."</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".(($rs[5]==1)?"".$currency."".$rs[7]."".$currency_type."":"".(($rs[6]!=0)?"&nbsp;&nbsp;".$rs[6]."%&nbsp;&nbsp;&nbsp;[".affiliate_month_percentage($currency, $currency_type, $base, $com_monthly)." / Month]":"N/A")."")."</td>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$http_admin."/affiliate_plan.php?pid=".$rs[0]."&sid=".trim($sid)."'>click</a> ]</td>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$http_admin."/affiliate_plan_edit.php?delete=".$rs[0]."&sid=".trim($sid)."'>click</a> ]</td>
		</tr>
		");
	
	unset($monthly_cost);
	unset($quarterly_cost);
	unset($semi_annual_cost);
	unset($annual_cost);
	$x++;
	}

$uy=1;
$row=mysql_query("select plan_specs.pid, plan_specs.package_name, plan_specs.web_space, plan_specs.bandwidth, plan_groups.name, plan_specs.com_type, plan_specs.com_rate_month, plan_specs.com_rate_onetime, plan_specs.monthly_cost from plan_specs, plan_groups where plan_groups.gid='0' and plan_specs.gid=plan_groups.gid order by plan_groups.name, plan_specs.package_name asc");
while ($rs=mysql_fetch_row($row))
	{
	if ($uy==1) {$bgcolor="#F2F4F6"; $uy=0;} else {$bgcolor="#ECEEF0"; $uy=1;}
	echo("
		<tr>
			<td align='center' valign='middle' bgcolor='".$bgcolor."'><a href='".$http_admin."/plan_build.php?pid=".$rs[0]."'><img border='0' src='".$http_images."/".(($uy==1)?"exec_ECEEF0.gif":"exec_F2F4F6.gif")."' alt='Click for Details'></a></td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>Undefined</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".stripslashes($rs[1])."</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".(($rs[5]==0)?"No Plan Defined":"".(($rs[5]==1)?"Percent":"One Time")."")."</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>".(($rs[6]==0)?"N/A":"".$currency."".(($rs[5]==1)?"".$rs[7]."":"".$rs[6]."")."".$currency_type."")."</td>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$http_admin."/affiliate_plan.php?pid=".$rs[0]."'>click</a> ]</td>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>[ <a href='".$http_admin."/affiliate_plan_edit.php?delete=".$rs[0]."&sid=".trim($sid)."'>click</a> ]</td>
		</tr>
		");
	}
echo("
		<tr>
			<td colspan='6'><img src='".$http_images."/space.gif' width='1' height='8'></td>
		</tr>
</table>
</form>
<!--- End Main --->
	");
// End Main Process
mysql_close($dblink);
include $server_admin_inc."/footer.php";
?>