{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
{/if}
<script>
{literal}
var tab_last = '1';
{/literal}
</script>
{if $ajax eq 0}
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$info.name}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
{if $info.help != ''}
    <div class="help_text" style="display:block;">
        <div class="close_help">
            <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
        </div>
        <div class="help_body">
            <span class="help_title">{$lang.help}:</span>{$info.help}
        </div>
    </div>
{/if}
<ul class="tabs">
    <li>
        <a {if $info.active == "reports"} class="current" {else} href="admin_abuse_reports.php"  {/if}>{$lang.admin_abuse_reports.razdel_name} ({$count.new_abuse}/{$count.all_abuse})</a>
    </li>
    <li>
        <a {if $info.active == "bad_words"} class="current" {else} href="admin_badwords.php" {/if}>{$lang.admin_menu.bad_words} ({$count.badwords})</a>
    </li>
    <li>
        <a {if $info.active == "ip_check"} class="current" {else} href="admin_block_ip.php" {/if}>{$lang.admin_menu.block_ip} ({$count.ip})</a>
    </li>
    <li>
        <a {if $info.active == "approve"} class="current" {else} href="admin_upload.php" {/if}>{$lang.admin_menu.uploads_approve} ({$count.approve})</a>
    </li>
</ul>
<div id="show_block" style="display:table;width:100%;">{/if}
	<div class="user_operation_line">
		<div class="uol_item" onclick="Ban()">
			<div class="uol_in_item">{$lang.admin_block_ip.ip_ban}</div>
		</div>
		<div class="uol_item" onclick="Active()">
			<div class="uol_in_item">{$lang.admin_block_ip.ip_activ}</div>
		</div>
		<div class="uol_item" onclick="delReportAll();">
			<div class="uol_in_item">{$lang.admin_block_ip.block_ip.delete}</div>
		</div>
	</div>  
	<div class="cr"></div>


	<div>
		<form id="upload_ip_db" action="{$server}/admin/admin_block_ip.php" method="POST" enctype="multipart/form-data">
			<div>{$lang.admin_block_ip.db_alert}</div>
			<div>{$lang.admin_block_ip.db_help}</div>
			<input type="file" name="ipdb" size="40" />&nbsp;
			<a class="admin_button" onclick="uploadIpDb()">{$lang.button.upload}<span></span></a>
			<span class="loading_span action_save" id="upload_ip_db_loading"></span>
			<span class="error action_save" id="upload_ip_db_status">{$lang.admin_block_ip.wait_upload}</span>
		</form>
	</div>
	<div class="cr">&nbsp;</div>
	<div>
		<label for="use_api_ip">{$lang.admin_block_ip.use_api_ip}</label><input type="checkbox" name="use_api_ip" id="use_api_ip" onchange="useApiIp()" {if $settings.use_api_ip}checked{/if} />
		<span id="use_api_ip_status" class="error action_save">{$lang.country.saved}</span>
	</div>
	<div class="cr">&nbsp;</div>

<div onclick="ShowEditor('1','admin_block_ip.php?sel=addform&ajax=1');" id="tab_1" class="user_status_elem" style="width: 120px; float: left;" align="center">
    <a>{$lang.admin_menu.new_ban} </a>
</div>
<div onclick="ShowEditor('2','admin_block_ip.php?ajax=1');" id="tab_2"  class="user_status_elem_active" style="width:120px; float: left;" align="center">
    {$lang.admin_menu.banned_ip} ({$ip_count})
</div>
  
	<div style="padding-bottom:10px; float: left; width: 100%" id="check_ip">
<div id="tooltip" onclick="hideToolTip()" style="text-align:center; background-color: #FFFFFF; border: 1px dotted; text-align: {$default_left}; position:absolute; display:none; padding:5px;"></div>
{literal}
<script type="text/javascript">
	$(function() {
		$('#tool_tip_4 *').tooltip();
	});
</script>
{/literal}
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr class="table_header" style="width: 100%">				
				<td width="270px"><input type="checkbox" id="select_all" name="select_all" onclick="PutAll()" /> {$lang.admin_block_ip.ip_address}&nbsp;/&nbsp;{$lang.admin_block_ip.ip_range}&nbsp;/&nbsp;{$lang.admin_block_ip.ip_country}</td>
				<td width="200px">{$lang.admin_block_ip.ip_block_date}</td>	
                <td width="80">{$lang.admin_block_ip.ip_ban}</td>			
				<td width="100px">{$lang.admin_block_ip.action}</td>
			</tr>
			{if $data}
			{section name=i loop=$data}
			<tr {if $smarty.section.i.index mod 2 eq 1}class="even"{else}class="odd"{/if}>				
				<td class="main_content_text" ><input type="checkbox" name="delete" value="{$data[i].id}" >{$data[i].ip}</td>
				<td class="main_content_text" >{$data[i].date}</td>
                <td style="padding-left: 12px;">{if $data[i].ban == 1} <img src="{$site_root}{$template_root}/images/success.png"/>{/if}</td>				
				<td class="main_content_text" align="right" style="padding-right: 20px">
					<div class="block_action" style="float:left;">
                        <img src="{$site_root}{$template_root}/images/edit.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.edit}');return false" onclick="javascript: location.href='{$action}?sel=addform&id={$data[i].id}'" style="cursor: pointer;" />&nbsp;&nbsp;&nbsp;&nbsp;
                        <img src="{$site_root}{$template_root}/images/photo_delete.png"  onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" height="15" onclick="Delete({$data[i].id})" style="cursor: pointer;" />
                    </div>
                </td>
			</tr>            
			{/section}
			{else}
		<tr height="40">
			<td class="main_error_text" align="left" colspan="11" bgcolor="#FFFFFF">{$lang.interests_spr.empty}</td>
		</tr>
			{/if}
            <tr class="table_header">
                <td colspan="11">
                    &nbsp;&nbsp;
                    {if $links}
                    {foreach item=item from=$links.pages}
                        &nbsp;<a onclick="PageList('bad_words', '{$item.link}');" class="page_link" {if $item.selected} style=" font-weight: bold; text-decoration: none;" {/if}>{$item.name}</a>&nbsp;
                    {/foreach}
                    {/if}
                    <div class="page_navigation">
                    {if $links.previous}
                        <a onclick="PageList('bad_words', '{$links.previous}');">< {$lang.content.previous} {$per_page}</a>
                    {/if}
                    {if $links.next}
                        <a onclick="PageList('bad_words', '{$links.next}');">{$lang.content.next} {$per_page} ></a>
                    {/if}
                    </div>
                </td>
            </tr>
		</table>
<script type="text/javascript">
{literal}
		function showToolTip(e,text){
			if(document.all)e = event;
			var obj = document.getElementById('tooltip');
			obj.innerHTML = text;
			obj.style.display = 'block';
			var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;
			var leftPos = e.clientX - $('#tooltip').width()-10;
			if(leftPos<0)leftPos = 0;
			obj.style.left = leftPos + 'px';
			obj.style.top = e.clientY - obj.offsetHeight -10 + st + 'px';
		}
		function hideToolTip(){
			document.getElementById('tooltip').style.display = 'none';
		}
{/literal}		
</script>
		
	</div>
 
<script type="text/javascript">
{literal}
	$(document).ready(function(){
		$('#upload_ip_db').ajaxForm({
			data: {
				sel: 'upload_ipdb',
				ajax: 1
			},
			beforeSubmit: function(){
				$('#upload_ip_db_status').show();
				$('#upload_ip_db_loading').show();
			},
			success: function(data){
				if(data.status == 'success'){
					$('input[name=ipdb]').val('');
				}
				$('#upload_ip_db_loading').hide();
				ShowAjaxError(data.msg, '', data.status);
				$('#upload_ip_db_status').text(data.msg);
			},
			dataType: 'json'
		});
	});
	
	function uploadIpDb(){
		if(!$('#upload_ip_db_loading').is(':visible')){
			$('#upload_ip_db').submit();
		}
	}

function Ban(){
    $('input[name=delete]:checked').each(function(){
    Unban($(this).val(), 1);	  
    });
}
function Active(){
    $('input[name=delete]:checked').each(function(){
    Unban($(this).val(), 0);	  
    });
}

function Unban(id, val) {	
	str = 'sel=unban&id='+id+'&val='+val+"&ajax=1";		
    $.post ('admin_block_ip.php', str, function(data){
        $('#check_ip').html(data);
    })
}
function Delete(id){    
	par = 'ajax=1&sel=del&id='+id;
	$.post('admin_block_ip.php', par, function(data){		
			 $('#show_block').html(data);
	});
}

function delReportAll(){    
	$('input[name=delete]:checked').each(function(){
	   Delete($(this).val());	  
     });
}

function PageList(id_div, par) {
        ajaxLoadingImage(1, 'check_ip');
        $.post("admin_block_ip.php", par, function(data){
            ajaxLoadingImage(0, 'check_ip');
            $('#check_ip').html(data);
        });
    }
    
    
function PutAll() {
         var o=document.getElementsByName('select_all')	
         var i
         if (o[0].checked){                    
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                o[i].checked = true
            }            
         }
         else{
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                o[i].checked = false
            }            
         }             
}

	function useApiIp(){
		var use_api_ip = $('#use_api_ip').is(':checked') ? 1 : 0;
		$.post(
			'',
			{
				sel: 'use_api_ip',
				use_api_ip: use_api_ip,
				ajax: 1
			},
			function(data){
				if(data == '1'){
					ShowAjaxError('{/literal}{$lang.country.saved}{literal}', '', 'success');
					//$('#use_api_ip_status').show();
					if(use_api_ip){
						$('#use_api_ip').attr('checked','checked');
					}else{
						$('#use_api_ip').removeAttr('checked');
					}
					//setTimeout(function(){$('#use_api_ip_status').fadeOut()}, 3000);
				}
			}
		);
	}
{/literal}
</script>
{if $ajax eq 0}
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}