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

if (isset($submit))
	{
	$query2="insert ";
	$query2.="into ";
	$query2.="tld_chart ";
	$query2.="set ";
	$query2.="tld='".addslashes(trim($tld))."', ";
	$query2.="cost='".addslashes(trim($cost))."', ";
	$query2.="reg_period='".addslashes(trim($reg_period))."'";

	mysql_query($query2);
	}

if (isset($submit_edit))
	{
	$query2="update ";
	$query2.="tld_chart ";
	$query2.="set ";
	$query2.="tld='".addslashes(trim($tld))."', ";
	$query2.="cost='".addslashes(trim($cost))."', ";
	$query2.="reg_period='".addslashes(trim($reg_period))."' ";
	$query2.="where ";
	$query2.="tld_id='".addslashes(trim($tld_id))."'";

	mysql_query($query2);
	}

if (isset($delete))
	{
	$query2="delete ";
	$query2.="from ";
	$query2.="tld_chart ";
	$query2.="where ";
	$query2.="tld_id='".addslashes(trim($delete))."'";

	mysql_query($query2);
	}

include $server_admin_inc."/header.php";

echo("
	<form action='".$PHP_SELF."' method='POST'>
	<input type='hidden' name='sid' value='".$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>Add New Valid Extension (TLD,SLD) and Cost</b></td>
				</tr>
				<tr>
					<td colspan='2'><img src='".$http_images."/space.gif' width='15' height='6'></td>
				</tr>
			</table>
			<table width='100%' cellpadding='4' cellspacing='1' border='0'>
				<tr>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Enter TLD or SLD</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Enter Cost</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Action</b></td>
				</tr>
				<tr>
					<td align='left' valign='middle' bgcolor='#ECEEF0'>&nbsp;<b>.</b>&nbsp;<input ".$input_style." size='12' maxlength='8' type='text' name='tld'>&nbsp;&nbsp;<font color='#990000'>ex. com , com.au</font></td>
					<td align='left' valign='middle' bgcolor='#ECEEF0'>&nbsp;".$currency."&nbsp;<input ".$input_style." size='12' maxlength='8' type='text' name='cost'>&nbsp;&nbsp;".$currency_type."</td>
					<td align='left' valign='middle' bgcolor='#ECEEF0'>&nbsp;<input ".$button_style." type='submit' name='submit' value='Add New'></td>
				</tr>
			</table>
			</form>
	");

$y=1;
$query0="select ";
$query0.="tld_id, ";
$query0.="tld, ";
$query0.="cost, ";
$query0.="count(*), ";
$query0.="reg_period ";
$query0.="from ";
$query0.="tld_chart ";
$query0.="group by tld_id ";
$query0.="order by ";
$query0.="tld asc";

$ct=mysql_fetch_row(mysql_query($query0));

if ($ct[0]>0)
	{
?>
<script language="JavaScript">
<!--
function verify_delete(theForm)
	{
	if(confirm("Really Delete?")) { return true; }
	else { return false }
	}
//-->
</script> 
<?PHP
	echo("
			<table width='100%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td colspan='2'><img src='".$http_images."/space.gif' width='15' height='2'></td>
				</tr>
				<tr>
					<td colspan='2'><img src='".$http_images."/menu_arrow.gif'> <b>Manage Valid Extensions (TLD,SLD) and Cost</b></td>
				</tr>
				<tr>
					<td colspan='2'><img src='".$http_images."/space.gif' width='15' height='6'></td>
				</tr>
			</table>
				<table width='100%' cellpadding='4' cellspacing='1' border='0'>
					<tr>
						<td align='center' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Delete</b></td>
						<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Edit TLD or SLD</b></td>
						<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Edit Cost</b></td>
						<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Registration Period</b></td>
						<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Action</b></td>
					</tr>
			");

	$row0=mysql_query($query0);
	while ($rs0=mysql_fetch_row($row0))
		{
		if ($y==1) { $bgcolor="#F2F4F6"; $y=0; } else { $bgcolor="#ECEEF0"; $y=1; }
		
		$tld_id=stripslashes(trim($rs0[0]));
		$tld=stripslashes(trim($rs0[1]));
		$cost=sprintf("%01.2f", $rs0[2]);
		$reg_period=stripslashes(trim($rs0[4]));

		echo("
					<form action='".$PHP_SELF."' method='POST' onsubmit='return verify_delete(this)'>
					<input type='hidden' name='sid' value='".$sid."'>
					<input type='hidden' name='delete' value='".$tld_id."'>
					<tr>
						<td align='center' valign='middle' bgcolor='#E5E7E9'><input type='image' alt='Click here to delete the invoices checked below.' src='".$http_images."/x.gif' onmouseover='this.src=\"".$http_images."/x_.gif\"' onmouseout='this.src=\"".$http_images."/x.gif\"'></td>
					</form>
					<form action='".$PHP_SELF."' method='POST'>
					<input type='hidden' name='sid' value='".$sid."'>
					<input type='hidden' name='tld_id' value='".$tld_id."'>
						<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;.&nbsp;<input ".$input_style." size='12' maxlength='8' type='text' name='tld' value='".$tld."'></td>
						<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;".$currency."&nbsp;<input ".$input_style." size='12' maxlength='8' type='text' name='cost' value='".$cost."'>&nbsp;&nbsp;".$currency_type."</td>
						<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;<select name='reg_period' ".$input_style.">
						<option value='1'".(($reg_period==1)?" selected":"").">1 Year</option>
						<option value='2'".(($reg_period==2)?" selected":"").">2 Years</option>	
						<option value='3'".(($reg_period==3)?" selected":"").">5 Years</option>	
						<option value='4'".(($reg_period==4)?" selected":"").">10 Years</option>	
						</select></td>
						<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;<input ".$button_style." type='submit' name='submit_edit' value='Save Changes'></td>
					</tr>
					</form>
			");
		}

	echo "</table>";
	}
echo("
			</td>
		</tr>
	</table>
	</form>
	");

include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>