<?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($submit))
	{
	if (strlen(trim($addon_name))==0) 
		{ 
		$err0=true; 
		} 
	else 
		{ 
		if (isset($aid))
			{
			$update="update ";
			$update.="addon_specs set ";
			$update.="addon_show_description='".addslashes(trim($addon_show_description))."', ";
			if ($addon_show_description==1)
				{
				$update.="addon_description='".addslashes(trim($addon_description))."', ";
				}
			else
				{
				$update.="addon_description='', ";
				}

			$update.="setup_activate='".addslashes(trim($setup_activate))."', ";
			if ($setup_activate==1)
				{
				$update.="setup_cost='".addslashes(trim($setup_cost))."', ";
				}
			else
				{
				$update.="setup_cost='', ";
				}

			$update.="addon_activate='".addslashes(trim($addon_activate))."', ";
			if ($addon_activate==1)
				{
				$update.="addon_cost='".addslashes(trim($addon_cost))."', ";
				$update.="addon_state='".addslashes(trim($addon_state))."', ";
				}
			else
				{
				$update.="addon_cost='', ";
				$update.="addon_state='', ";
				}

			if ($tick==0)
				{
				$update.="unique_ip='1', ";
				$update.="extra_webspace='0', ";
				$update.="private_ns='0', ";
				}
			else if ($tick==1)
				{
				$update.="unique_ip='0', ";
				$update.="extra_webspace='".addslashes(trim($extra_webspace))."', ";
				$update.="private_ns='0', ";
				}
			else if ($tick==3)
				{
				$update.="unique_ip='0', ";
				$update.="extra_webspace='0', ";
				$update.="private_ns='1', ";
				}
			else if ($tick==2)
				{
				$update.="unique_ip='0', ";
				$update.="extra_webspace='0', ";
				$update.="private_ns='0', ";
				}

			$update.="addon_name='".addslashes(trim($addon_name))."' ";
			$update.="where aid='".addslashes(trim($aid))."'";

			mysql_query($update);
			}
		else
			{
			$insert="insert into ";
			$insert.="addon_specs set ";
			$insert.="addon_show_description='".addslashes(trim($addon_show_description))."', ";
			if ($addon_show_description==1)
				{
				$insert.="addon_description='".addslashes(trim($addon_description))."', ";
				}

			$insert.="setup_activate='".addslashes(trim($setup_activate))."', ";
			if ($setup_activate==1)
				{
				$insert.="setup_cost='".addslashes(trim($setup_cost))."', ";
				}

			$insert.="addon_activate='".addslashes(trim($addon_activate))."', ";
			if ($addon_activate==1)
				{
				$insert.="addon_cost='".addslashes(trim($addon_cost))."', ";
				$insert.="addon_state='".addslashes(trim($addon_state))."', ";
				}

			if ($tick==0)
				{
				$insert.="unique_ip='1', ";
				$insert.="extra_webspace='0', ";
				$insert.="private_ns='0', ";
				}
			else if ($tick==1)
				{
				$insert.="unique_ip='0', ";
				$insert.="extra_webspace='".addslashes(trim($extra_webspace))."', ";
				$insert.="private_ns='0', ";
				}
			else if ($tick==3)
				{
				$insert.="unique_ip='0', ";
				$insert.="extra_webspace='0', ";
				$insert.="private_ns='1', ";
				}
			else if ($tick==2)
				{
				$insert.="unique_ip='0', ";
				$insert.="extra_webspace='0', ";
				$insert.="private_ns='0', ";
				}

			$insert.="addon_name='".addslashes(trim($addon_name))."'";

			mysql_query($insert);

			$aid=mysql_insert_id();
			}

		$done=true;
		}
	}

include $server_admin_inc."/header.php";
$ct=mysql_fetch_row(mysql_query("select count(*) from addon_groups"));
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 ($ct[0]<=0)
	{
	echo("
				<table width='100%' cellpadding='2' cellspacing='1' border='0'>
					<tr>
						<td align='left' valign='middle'><img src='".$http_images."/menu_arrow.gif'><b>No Addon Groups Defined.</b></td>
					</tr>
					<tr>
						<td align='left' valign='middle'><img src='".$http_images."/space.gif' width='1' height='2'></td>
					</tr>
					<tr>
						<td align='left' valign='middle'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/error_arrow.gif'>Please use <a href='".$http_admin."/addon_group_editor.php?sid=".$sid."'>Addon Group Editor</a> to continue.</td>
					</tr>
				</table>
		");
	}
else
	{
	if (isset($done))
		{
		echo("
			<table width='725' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'>The addon was ".((isset($aid))?"edited":"created")." successfully!</td>
				</tr>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><a href='".$http_admin."/addon_build.php?sid=".trim($sid)."'>Add New Addons</a>.</td>
				</tr>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><a href='".$http_admin."/addon_edit.php?sid=".trim($sid)."'>Choose Addons to edit</a>.</td>
				</tr>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Make edits to <b>this addon</b> below:</td>
				</tr>
				<tr>
					<td align='left' valign='top'><hr align='left' valign='top' color='#F0EFED' width='725'></td>
				</tr>
			</table>
			");
		}
	if (isset($aid))
		{
		$query="select ";
		$query.="addon_name, ";					// 0
		$query.="addon_description, ";			// 1
		$query.="addon_show_description, ";		// 2
		$query.="setup_cost, ";					// 3
		$query.="setup_activate, ";				// 4
		$query.="addon_cost, ";					// 5
		$query.="addon_state, ";				// 6
		$query.="addon_activate, ";				// 7
		$query.="addon_pay_methods, ";			// 8
		$query.="unique_ip, ";					// 9
		$query.="extra_webspace, ";				// 10
		$query.="private_ns ";					// 11
		$query.="from addon_specs ";
		$query.="where aid='".addslashes(trim($aid))."'";

		$rs=mysql_fetch_row(mysql_query($query));

		$addon_name=stripslashes(trim($rs[0]));
		$addon_description=stripslashes(trim($rs[1]));
		$addon_show_description=stripslashes(trim($rs[2]));
		$setup_cost=stripslashes(trim($rs[3]));
		$setup_activate=stripslashes(trim($rs[4]));
		$addon_cost=stripslashes(trim($rs[5]));
		$addon_state=stripslashes(trim($rs[6]));
		$addon_activate=stripslashes(trim($rs[7]));
		$addon_pay_methods=stripslashes(trim($rs[8]));
		$unique_ip=stripslashes(trim($rs[9]));
		$extra_webspace=stripslashes(trim($rs[10]));
		$private_ns=stripslashes(trim($rs[11]));

		if ($unique_ip==1) { $tick=0; }
		else if ($private_ns==1) { $tick=3; }
		else if ($extra_webspace!=0) { $tick=1; }
		else { $tick=2; }
		}

	if (isset($err0))
		{
		echo("
				<table width='100%' cellpadding='4' cellspacing='1' border='0'>
					<tr>
						<td><img src='".$http_images."/error_arrow.gif'> You must enter an <b>Addon Name</b> to continue.</td>
					</tr>
					<tr>
						<td><img src='".$http_images."/space.gif' width='1' height='4'></td>
					</tr>
				</table>
			");
		}
	echo("
				<form action='".$PHP_SELF."' method='POST' name='form1'>
				<input type='hidden' name='sid' value='".$sid."'>
				".((isset($aid))?"<input type='hidden' name='aid' value='".$aid."'>":"")."
				<table width='100%' cellpadding='4' cellspacing='1' border='0'>
					<tr>
						<td width='25%' align='left' valign='middle'>Addon Name:</td>
						<td width='75%' align='left' valign='middle'><input ".$input_style." type='text' size='30' name='addon_name' value='".((isset($addon_name))?"".$addon_name."":"")."'></td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='top'>Addon Description:</td>
						<td width='75%' align='left' valign='middle'><font color='#990000'>Show the description below?</font> <input onclick='document.form1.addon_description.disabled=false;' type='radio' name='addon_show_description' value='1'".((isset($addon_show_description))?"".(($addon_show_description==1)?" checked":"")."":" checked")."> Yes&nbsp;&nbsp;&nbsp;<input onclick='document.form1.addon_description.disabled=true;' type='radio' name='addon_show_description' value='0'".((isset($addon_show_description))?"".(($addon_show_description==0)?" checked":"")."":" checked")."> No<br><textarea name='addon_description' rows='3' cols='62' ".$input_style."".((isset($addon_show_description))?"".(($addon_show_description==0)?" disabled":"")."":"disabled").">".((isset($addon_description))?"".$addon_description."":"")."</textarea></td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'>Setup Cost</td>
						<td width='75%' align='left' valign='middle'>".$currency." <input ".$input_style." type='text' size='6' name='setup_cost' value='".((isset($setup_cost))?"".(($setup_cost==0)?"":"".$setup_cost."")."":"")."'".((isset($setup_cost))?"".((trim($setup_cost)=="")?"disabled":"".(($setup_activate==1)?"":" disabled")."")."":" disabled").">".$currency_type."&nbsp;&nbsp;<font color='#990000'>Activate this setup fee?</font>&nbsp;<input onclick='document.form1.setup_cost.disabled=false;' type='radio' name='setup_activate' value='1'".((isset($setup_activate))?"".(($setup_activate==1)?" checked":"")."":" checked").">&nbsp;Yes&nbsp;&nbsp;&nbsp;<input onclick='document.form1.setup_cost.disabled=true;' type='radio' name='setup_activate' value='0'".((isset($setup_activate))?"".(($setup_activate==0)?" checked":"")."":" checked").">&nbsp;No</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'>Total Cost Per Cycle:</td>
						<td width='75%' align='left' valign='middle'>".$currency." <input ".$input_style." type='text' size='6' name='addon_cost' value='".((isset($addon_cost))?"".(($addon_cost==0)?"":"".$addon_cost."")."":"")."'".((isset($addon_cost))?"".((trim($addon_cost)=="")?"disabled":"".(($addon_activate==1)?"":" disabled")."")."":" disabled").">".$currency_type." Per <select name='addon_state' ".$input_style." ".((isset($addon_state))?"".((trim($addon_state)=="")?"disabled":"")."":" disabled").">
							<option value='1'".((isset($addon_state))?"".(($addon_state==1)?" selected":"")."":"").">One time fee</option>
							<option value='2'".((isset($addon_state))?"".(($addon_state==2)?" selected":"")."":"").">Month</option>
							<option value='3'".((isset($addon_state))?"".(($addon_state==3)?" selected":"")."":"").">Year</option>
						</select>&nbsp;&nbsp;<font color='#990000'>Activate this Cost Per Cycle?</font>&nbsp;<input onclick='document.form1.addon_state.disabled=false; document.form1.addon_cost.disabled=false;' type='radio' name='addon_activate' value='1'".((isset($addon_activate))?"".(($addon_activate==1)?" checked":"")."":" checked").">&nbsp;Yes&nbsp;&nbsp;&nbsp;<input onclick='document.form1.addon_cost.disabled=true; document.form1.addon_state.disabled=true;' type='radio' name='addon_activate' value='0'".((isset($addon_activate))?"".(($addon_activate==0)?" checked":"")."":" checked").">&nbsp;No</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><input type='radio' name='tick' value='0'".((isset($tick))?"".(($tick==0)?" checked":"")."":"")."> This addon is for a Unique IP Address.</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><input type='radio' name='tick' value='1'".((isset($tick))?"".(($tick==1)?" checked":"")."":"").">This addon is for an extra <input ".$input_style." type='text' name='extra_webspace' size='6' maxlength='15' value='".((isset($extra_webspace))?"".(($extra_webspace!=0)?"".$extra_webspace."":"")."":"")."'> <font color='#990000'>MB</font> of extra webspace.</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><input type='radio' name='tick' value='3'".((isset($tick))?"".(($tick==3)?" checked":"")."":"")."> This addon is for Private Nameservers.</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><input type='radio' name='tick' value='2'".((isset($tick))?"".(($tick==2)?" checked":"")."":" checked").">This addon is <font color='#990000'>not</font> a unique IP, for extra webspace or for Private Nameservers.</td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><img src='".$http_images."/space.gif' width='1' height='12'></td>
					</tr>
					<tr>
						<td width='25%' align='left' valign='middle'></td>
						<td width='75%' align='left' valign='middle'><input ".$button_style." type='submit' name='submit' value='".((isset($aid))?"Edit This Addon Now":"Create This Addon Now")."'></td>
					</tr>
				</table>
				</form>
		");
	}
echo("
			</td>
		</tr>
	</table>
	");
include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>