<?php

/********************************************************************************
	- MemHT Portal -
	
	Copyright (C) 2007-2008 by Miltenovik Manojlo
	http://www.memht.com
	
	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, or
	(at your opinion) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, see <http://www.gnu.org/licenses/> (GPLv2)
	or write to the Free Software Foundation, Inc., 51 Franklin Street,
	Fifth Floor, Boston, MA02110-1301, USA.
		
********************************************************************************/

if (!defined("_LOAD_PAGE_")) {
	die("<table style='padding: 2px; border: 1px solid #999; background-color: #EEE; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>Error:</b> This file cannot be opened directly!</td></tr></table>");
}

if (isSet($_GET['op'])) { $op = inCode($_GET['op']); } else { $op= ""; }
if (isSet($_GET['id'])) { $id = inCode($_GET['id']); } else { $id= ""; }

function openBanner($id) {
	global $dblink;
	
	$id = intval($id);
	
	$query = "SELECT * FROM memht_banners_banner WHERE id='$id'";
	if ($dblink->get_num($query)>0) {
		$banner = $dblink->get_row($query);
		$url = outCode($banner['url']);
		
		$dblink->query("UPDATE memht_banners_banner SET click_done=click_done+1 WHERE id='$id'");
		
		$row = $dblink->get_row("SELECT * FROM memht_banners_banner WHERE id='$id'");
		$b_link_click = intval($row['link_click']);
		$b_click_done = intval($row['click_done']);
		$b_click_target = intval($row['click_target']);
		
		if ($b_link_click==1 AND $b_click_done>=$b_click_target AND $b_click_target!=0) {
			$dblink->query("UPDATE memht_banners_banner SET enabled=0 WHERE id='$id'");
			sendBannerEnd($lid);
		}
	} else {
		$url = "index.php";
	}
	echo "<div align='center'><b>"._OPENINGLINK_."</b></div>";
	echo "<meta http-equiv='refresh' content='0;URL=$url'>";
}

$pagerow = $dblink->get_row("SELECT * FROM memht_pagine WHERE nome='$page'");
$fullScreen = intval($pagerow['fullscreen']);

require_once("inc/inc_header.php");
	openTable();
	
	switch($op) {
		case "openBanner":
			openBanner($id);
		break;
	}
	
	closeTable();
require_once("inc/inc_footer.php");

?>