<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* NukeSentinel(tm)                                     */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright © 2000-2005 by NukeScripts Network         */
/********************************************************/

if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}

@set_time_limit(600);
$perpage = 200;
if(!$ab_config['page_delay'] OR $ab_config['page_delay'] < 1) { $pagedelay = 5; } else { $pagedelay = $ab_config['page_delay']; }
$totalselected = $db->sql_numrows($db->sql_query("SELECT `ip_lo` FROM `".TABLE_NSNST_PROTECTED_RANGES."`"));
if (!isset($min)) {
  $min=0;
  $pagesint = ($totalselected / $perpage);
  $pages = ceil($pagesint);
  $pagetitle = _AB_NUKESENTINEL.": "._AB_IP2CUPDATEPROTECTEDRANGES;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  OpenMenu();
  ipbanmenu();
  CarryMenu();
  ip2cmenu();
  CloseMenu();
  Max_CloseTable();
  br('1');
  Max_OpenTable();
  echo _AB_IP2CUPDATEPROTECTEDRANGES01."<br />\n";
  echo _AB_IP2CUPDATEPROTECTEDRANGES02."<br />\n";
  echo _AB_IP2CINSECTIONS."<br />\n";
  echo _AB_YOUHAVE."$pages"._AB_SECTIONSTOGO."<br />\n";
  echo _AB_IP2CUPDATE04C."<br />\n";
  echo "<br />\n";
  echo "<form method='post' action='".$admin_file.".php'>\n";
  echo "<input type='hidden' name='op' value='ABIP2CountryUpdateProtectedRanges'>\n";
  echo "<input type='hidden' name='min' value='$min'>\n";
  echo "<input type='submit' value=\""._AB_LETSGETSTART."\">\n";
  echo "</form>\n";
  Max_CloseTable();
  incof();
} else if($min < $totalselected) {
  $db->sql_query("UPDATE `".TABLE_NSNST_CONFIG."` SET `config_value`='1' WHERE `config_name`='site_switch'");
  $ab_config['site_switch'] = 1;
  $result = $db->sql_query("SELECT `ip_lo` FROM `".TABLE_NSNST_PROTECTED_RANGES."` LIMIT $min, $perpage");
  while(list($xip_lo) = $db->sql_fetchrow($result)) {
    list($xc2c) = $db->sql_fetchrow($db->sql_query("SELECT `c2c` FROM `".$prefix."_nsnst_ip2country` WHERE `ip_lo`<='$xip_lo' AND `ip_hi`>='$xip_lo'"));
    if(!$xc2c) { $xc2c = "00"; }
    $db->sql_query("UPDATE `".TABLE_NSNST_PROTECTED_RANGES."` SET `c2c`='$xc2c' WHERE `ip_lo`='$xip_lo'");
  }
  $max=$min+$perpage;
  $pagesint = ($totalselected / $perpage);
  $pages = ceil($pagesint);
  $currentpage = ($max / $perpage);
  $pagetitle = _AB_NUKESENTINEL.": "._AB_IP2CUPDATEPROTECTEDRANGES;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  echo "<META HTTP-EQUIV=\"refresh\" content=\"$pagedelay;URL=".$admin_file.".php?op=ABIP2CountryUpdateProtectedRanges&min=$max\">";
  echo "<b>"._AB_SECTION." $currentpage "._AB_OF." $pages "._AB_COMPLETED."</b><br />\n";
  if($currentpage < $pages) {
    echo "<b>"._AB_SECTION." ".($currentpage+1)." "._AB_WILLSTART."</b><br />\n";
  }
  Max_CloseTable();
  incof();
} else {
  $db->sql_query("UPDATE `".TABLE_NSNST_CONFIG."` SET `config_value`='0' WHERE `config_name`='site_switch'");
  $ab_config['site_switch'] = 0;
  $pagetitle = _AB_NUKESENTINEL.": "._AB_IP2CUPDATEPROTECTEDRANGES;
  incoh();
  title($pagetitle);
  Max_OpenTable();
  OpenMenu();
  ipbanmenu();
  CarryMenu();
  ip2cmenu();
  CloseMenu();
  Max_CloseTable();
  echo "<br />\n";
  Max_OpenTable();
  echo "<center><b>"._AB_IP2CUPDATEPROTECTEDRANGES." "._AB_COMPLETED."</b><br />\n";
  Max_CloseTable();
  incof();
}
