if ($Mode == "List" && !ValidId($EditId) && $EditId != "new") {
    if ($GrpId > 0) {
        $GrpName = $Db->ReturnValue("SELECT NAME FROM " . PFX . "_tracker_visitor_agent_grp WHERE ID={$GrpId}");
        $PageTitle = str_replace("{GRP}", "<B>{$GrpName}</B>", $Lang['Title2']);
    }
    $ProgPath[2]['Name'] = $PageTitle;
    $ProgPath[2]['Url'] = getURL("user_agent", "GrpId={$GrpId}", "admin");
    $Where = "WHERE GRP_ID={$GrpId} ";
    $CntWhere = "GRP_ID={$GrpId} ";
    if (ValidVar($Srch)) {
        $Where .= " AND USER_AGENT LIKE '%{$Srch}%'";
        $CntWhere .= " AND USER_AGENT LIKE '%{$Srch}%'";
    }
    $Cnt = $Db->CNT(PFX . "_tracker_visitor_agent", $CntWhere);
    $Limit = $SearchRegId ? $Cnt : 50;
    $Pages = new PageNums($Cnt, 50);
    $Pages->Args = "&GrpId={$GrpId}";
    if ($RegSearchGrp) {
        $Pages->Args .= "&RegSearchGrp={$RegSearchGrp}";
    }
    if ($RegCheck) {
        $Pages->Args .= "&RegCheck=1";
        if ($R1) {
            $Pages->Args .= "&R1={$R1}";
        }
        if ($R2) {
            $Pages->Args .= "&R2={$R2}";
        }
    }
    if ($RegSearchGrp || $RegCheck) {
        $Pages->Limit = $Cnt > 0 ? $Cnt : 1;
function UpdateStats()
{
    global $Lang, $Logs, $Db, $Pages, $CurrentProgress, $AdditionalHead, $UnCountried, $UnCCnt;
    $PerPage = 100;
    $Pages = new PageNums($UnCCnt, $PerPage);
    $Pages->NoPrev = true;
    $Pages->NoPrevPrev = true;
    $Pages->NoNextNext = true;
    $Pages->NoPageLink = true;
    $Pages->Calculate();
    $Pages->Args = "&DoConvert=1&UnCCnt={$UnCCnt}";
    $CurrentProgress = ($Pages->PageCurrent + 1) * ceil(100 / $Pages->Pages);
    if ($CurrentProgress > 100) {
        $CurrentProgress = 100;
    }
    $AdditionalHead = "<meta http-equiv=\"refresh\" content=\"1;url=" . getURL("countries", "DoConvert=1&UnCCnt={$UnCCnt}&PS=" . ($Pages->PageStart + $Pages->Limit) . "&PC=" . ($Pages->PageCurrent + 1), "admin") . "\">";
    $Query = "\n\t\t\tSELECT V.ID,  I.IP\n\t\t\t\tFROM " . PFX . "_tracker_visitor V \n\t\t\t\tINNER JOIN " . PFX . "_tracker_ip I\n\t\t\t\t\tON I.ID=V.LAST_IP_ID \n\t\t\t\tWHERE V.FIRST_COUNTRY_ID = 0  AND V.LAST_IP_ID>0\n\t\t\t\tLIMIT 0, " . $Pages->Limit;
    $Sql = new Query($Query);
    while ($Row = $Sql->Row()) {
        $IpLong = sprintf("%u\n", ip2long($Row->IP));
        if (!$IpLong) {
            return 0;
        }
        global $Db;
        $Query = "\n\t\t\tSELECT C.ID\n\t\t\t\tFROM " . PFX . "_tracker_country_ip CI\n\t\t\t\tINNER JOIN " . PFX . "_tracker_country C\n\t\t\t\t\tON C.CODE=CI.COUNTRY_CODE\n\t\t\t\tWHERE {$IpLong} BETWEEN CI.IP_START AND CI.IP_END\n\t\t";
        $CountryId = $Db->ReturnValue($Query);
        if (!$CountryId) {
            continue;
        }
        $Query = "UPDATE " . PFX . "_tracker_visitor SET FIRST_COUNTRY_ID = '{$CountryId}' WHERE ID = " . $Row->ID;
        $Db->Query($Query);
    }
    if ($CurrentProgress == 100) {
        $Logs->Msg($Lang['ConvertDone']);
        $Pages = new PageNums(0, 0);
        $AdditionalHead = false;
    }
}