{$ADMIN_HEADER}
{literal}
<script language="javascript" type="text/javascript">
/********************** Display Control to User **********************/
function setUserControl(str)
{
var lblBanTypeAddress = document.getElementById('lblBanTypeAddress');
var UserControl = document.getElementById('user-control');
var RangeControl = document.getElementById('range');
if(str != '')
{
if(UserControl.style.display=='none')
{
UserControl.style.display = '';
}
}
else
{
}
if(str == 1)
{
RangeControl.style.display = 'none';
lblBanTypeAddress.innerHTML = 'IP Address <label class="star">*</label>';
}
else if(str == 2)
{
RangeControl.style.display = 'none';
lblBanTypeAddress.innerHTML = 'HostName <label class="star">*</label>';
}
else if(str == 3)
{
RangeControl.style.display = '';
lblBanTypeAddress.innerHTML = 'IP Range <label class="star">*</label>';
}
}
/********************** Form Validation Start **********************/
function FormValidate()
{
var error = '';
var focus = '';
var flag = 1;
var BanListType = document.getElementById('ddlBanList');
if(BanListType)
{
if(BanListType.selectedIndex == 0 || BanListType.options[BanListType.selectedIndex].value == '')
{
error = error+'Please Select Ban List Type.'+'\r\n';
if(flag == 1)
{
focus = 'ddlBanList';
flag = 0;
}
}
}
if(BanListType.selectedIndex != 0 || BanListType.options[BanListType.selectedIndex].value != '')
{
var BanTypeAddress = document.getElementById('txtBanListAddress');
if(BanListType.options[BanListType.selectedIndex].value == 3)
var BanTypeAddressRange = document.getElementById('txtBanListRange');
if(BanTypeAddress)
{
if(BanTypeAddress.value == '')
{
if(BanListType.options[BanListType.selectedIndex].value == 1)
error = error+'Please Enter IP Address.'+'\r\n';
else if(BanListType.options[BanListType.selectedIndex].value == 2)
error = error+'Please Enter Host Name.'+'\r\n';
else if(BanListType.options[BanListType.selectedIndex].value == 3)
error = error+'Please Enter IP Address Range.'+'\r\n';
if(flag == 1)
{
focus = 'txtBanListAddress';
flag = 0;
}
}
else
{
if(BanListType.options[BanListType.selectedIndex].value == 1 || BanListType.options[BanListType.selectedIndex].value == 3)
{
var result = validateIP(BanTypeAddress.value);
if(!result && BanListType.options[BanListType.selectedIndex].value == 1)
error = error+'Invalid IP Address.'+'\r\n';
else if(!result && BanListType.options[BanListType.selectedIndex].value == 3)
error = error+'Invalid Start IP Address.'+'\r\n';
}
else if(BanListType.options[BanListType.selectedIndex].value == 2)
{
var result = is_valid_URL(BanTypeAddress.value);
if(!result)
error = error+'Invalid Host Name.'+'\r\n';
}
if(flag == 1)
{
focus = 'txtBanListAddress';
flag = 0;
}
}
}
if(BanTypeAddressRange)
{
if(BanTypeAddressRange.value == '' && BanTypeAddress.value != '')
{
error = error+'Please Enter End IP Address'+'\r\n';
if(flag == 1)
{
focus = 'txtBanListRange';
flag = 0;
}
}
else if(BanTypeAddressRange.value != '')
{
var result = validateIP(BanTypeAddressRange.value);
if(!result)
{
error = error+'Invalid Ending IP Address.'+'\r\n';
if(flag == 1)
{
focus = 'txtBanListRange';
flag = 0;
}
}
else
{
var IPAddress1 = BanTypeAddress.value.split('.');
var IPAddress2 = BanTypeAddressRange.value.split('.');
var temp = 0;
var temp1 = 0;
temp = toBin(IPAddress1[0]) + toBin(IPAddress1[1]) + toBin(IPAddress1[2]) + toBin(IPAddress1[3]);
temp1 = toBin(IPAddress2[0]) + toBin(IPAddress2[1]) + toBin(IPAddress2[2]) + toBin(IPAddress2[3]);
if(temp >= temp1)
{
error = error+'Please Enter Valid IP Address Range.'+'\r\n';
if(flag == 1)
{
focus = 'txtBanListRange';
flag = 0;
}
}
}
}
}
}
if(error != '')
{
alert(error);
var FocusControl = document.getElementById(focus);
FocusControl.focus();
return false;
}
else
{
return true;
}
}
/********************** Form Validation End **********************/
function toBin(inVal) {
base = 2 ;
num = parseInt(inVal);
binNum = num.toString(base);
// pad leading spaces with "0"
binNum = padTextPrefix(binNum, "0", 8) ;
return binNum
}
function padTextPrefix (InString, PadChar, DefLength) {
if (InString.length >= DefLength)
return (InString);
OutString = InString
for (Count = InString.length; Count < DefLength; Count++) {
OutString = PadChar + OutString;
}
return (OutString);
}
/********************** Check for valid IP Address **********************/
function validateIP(url) {
if (url.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
var myArray = url.split(/\./);
if (myArray[0] > 255 || myArray[1] > 255 || myArray[2] > 255 || myArray[3] > 255)
return false;
if (myArray[0] == 0 && myArray[1] == 0 && myArray[2] == 0 && myArray[3] == 0)
return false;
return true;
}
else
return false;
}
/********************** Check for valid URL Address **********************/
function is_valid_URL(url) {
//var regexp = "/^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\/:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/";
//var regexp = /^(http[s]?:\/\/|ftp:\/\/)?(www\.)?[a-zA-Z0-9-\.]+\.(com|net|org|edu|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|tv|([a-z]{2}))$/;
//return(regexp.test(url));
return true;
}
</script>
{/literal}
<body onload="setUserControl('{$data[0].bantype}');">
<div id="content" class="setdiv">
<div id="full-contentdiv">
<div class="righttop">
<h2 align="center">
{if $IsEdit neq ''}
Edit Banned IPs
{assign var="action" value="update"}
{else}
Add New Banned IPs
{assign var="action" value="insert"}
{/if}
</h2>
</div>
<div class="whole-page clear">
<form name="frmUserBanList" action="admin_banlist_m.php?action={$action}" method="post">
<div class="formformat">
<table border="0" width="65%" align="center" cellpadding="0" cellspacing="0" style="border-bottom:none;">
<input type="hidden" id="hdnID" name="hdnID" value="{$data[0].id}">
<tr>
<td class="right-side-text" width="20%">
<label>Select Ban List <label class="star">*</label></label>
</td>
<td class="left-side-text" width="30%" >
<select id="ddlBanList" name="ddlbanList" class="selectcss" onchange="setUserControl(this.value)">
<option selected id="" value="">Select</option>
<option value="1" {if $data[0].bantype eq 1}selected{/if}>IPAddress</option>
<option value="2" {if $data[0].bantype eq 2}selected{/if}>HostName</option>
<option value="3" {if $data[0].bantype eq 3}selected{/if}>Range</option>
</select>
</td>
</tr>
</table>
<!--<tr>
<td colspan="2" > -->
{if $data[0].bantype eq 3}
{assign var="BanListAddress" value=" "|explode:$data[0].hostaddress}
{else}
{assign var="BanListAddress" value=$data[0].hostaddress}
{/if}
<table id="user-control" style="display:none;border-top:none;" width="65%" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="right-side-text" width="20%"><label id="lblBanTypeAddress"></lable>
</td>
<td class="left-side-text" width="20%">
<input type="text" id="txtBanListAddress" style="float:left;" name="txtBanListAddress" maxlength="45" value="{if $data[0].bantype eq 3}{$BanListAddress[0]}{else}{$BanListAddress}{/if}">
<div id="range" style="display:none;float:left;margin-left:6px;">
To <input type="text" id="txtBanListRange" name="txtBanListRange" maxlength="45" value="{if $data[0].bantype eq 3}{$BanListAddress[2]}{/if}">
</div>
</td>
</tr>
<tr>
<td class="right-side-text" width="20%"><label>Is Active <label class="star">*</label></label></td>
<td class="left-side-text" width="30%" >
<select id="ddlIsActive" name="ddlIsActive" class="selectcss">
<option selected value="1">Yes</option>
<option value="0" {if $data[0].isactive eq 0}selected{/if}>No</option>
</select>
</td>
</tr>
<tr>
<td class="right-side-text" width="20%"></td>
<td class="buttontd" width="30%">
<input type="submit" name="submit" value="Submit" class="btncss" onclick="return FormValidate();">
<input type="button" name="btnBack" value="Cancel" class="btncss" onclick="window.history.go(-1);">
</td>
</tr>
</table>
<!-- </td>
</tr>-->
</div>
</form>
</div>
</div>
</div>
{literal}
<script language="javascript" type="text/javascript">
/********************** Display Control to User **********************/
function editmode()
{
var UserControl = document.getElementById('user-control');
var RangeControl = document.getElementById('range');
if(UserControl.style.display=='')
{
UserControl.style.display = 'none';
}
if(document.frmUserBanList.txtBanListAddress)
document.frmUserBanList.txtBanListAddress.value="";
if(document.frmUserBanList.txtBanListAddress)
document.frmUserBanList.txtBanListAddress.value="";
document.getElementById('ddlBanList').selectedIndex=0;
document.getElementById('ddlBanList').selected=true;
setUserControl('');
}
</script>
{/literal}
{$ADMIN_FOOTER}