<?php

include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

// картинка
if (isset($_GET['img_url']) && $img_url = @urldecode($_GET['img_url'])) {
    if ($img_url)
        header('Location: ' . $img_url);
    exit;
}

// внешняя ссылка
if (isset($_GET['ext_url']) && $ext_url = @urldecode($_GET['ext_url'])) {
    if (isset($_SESSION['adm_auth']))
        unset($_SESSION['adm_auth']);
    if ($ext_url)
        header('Location: ' . $ext_url);
    exit;
}

// рекламная ссылка
if (isset($_GET['rekl_id']) && $_GET['rekl_id']) {
    $rekl_id = (int) $_GET['rekl_id'];
    $q = mysql_query("SELECT * FROM `rekl` WHERE `id` = '$rekl_id' LIMIT 1");
    if (mysql_num_rows($q)) {
        $rekl = mysql_fetch_assoc($q);
        mysql_query("UPDATE `rekl` SET `count` = `count` + 1 WHERE `id` = '$rekl[id]'");
        if (isset($_SESSION['adm_auth']))
            unset($_SESSION['adm_auth']);
        header('Location: ' . $rekl['link']);
    }
    exit;
}

header('Location: /err.php');
?>
