<?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.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, or        //
//  (at your option) 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, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //
// ORIGINAL FILE INFO
######################################################################
# Partner-Addon for PHP-NUKE Version 1.0 Beta
# ===========================
#
# Author: Dietrich Bojko (webmaster@jimmy-net.de)
# http://www.jimmy-net.de
######################################################################
include("header.php");

function index(){
	global $xoopsDB, $xoopsConfig, $xoopsTheme;
	$myts =& MyTextSanitizer::getInstance();
	if ( $xoopsConfig['startpage'] == "partners" ) {
		$xoopsOption['show_rblock'] =1;
		include(XOOPS_ROOT_PATH."/header.php");
		make_cblock();
		echo "<br />";
	} else {
		$xoopsOption['show_rblock'] =0;
		include(XOOPS_ROOT_PATH."/header.php");
	}

	$result = $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("click")."");
	$numrows = $xoopsDB->getRowsNum($result);
	OpenTable();
	echo "<div><h4>"._PA_PARTNERS."</h4><br />";
	if ( $numrows > 0 ) {
		echo "<table border='0' cellpadding='0' cellspacing='0' valign='top' width='100%'><tr><td class='bg2'>
    		<table width='100%' border='0' cellpadding='4' cellspacing='1'>";
 		while (list($num, $hits, $url, $image, $text) = $xoopsDB->fetchRow($result)) { 
			echo "<tr><td class='bg3' align='center'><a href='".XOOPS_URL."/modules/partners/index.php?op=click&amp;id=".$num."' target='_blank'><img src='".$myts->makeTboxData4Show($image)."' border='0' /></td><td class='bg3'>".$text."</td><td class='bg3' align='center'>";
			printf(_PA_NUMHITS,$hits);
			echo "</td></tr>";
  		}   
		echo "</table></td></tr></table>";
	}
	echo "<br /><br /><br />
	<a href='mailto:".$xoopsConfig['adminmail']."'><b>"._PA_BECOMEAPARTNER."</b></a><br /><br />
	</div>";
	CloseTable();

	include(XOOPS_ROOT_PATH."/footer.php");
}

function clickpartner($id){
	global $xoopsDB;
	$res = $xoopsDB->queryF("UPDATE ".$xoopsDB->prefix("click")." SET hits=hits+1 WHERE num=$id");
	$res = $xoopsDB->fetchArray($xoopsDB->query("SELECT url from ".$xoopsDB->prefix("click")." WHERE num=$id"));
	echo "<html><head><meta http-equiv='Refresh' content='0; URL=".$res['url']."'></head><body></body></html>";
	exit();
} 

switch($HTTP_GET_VARS['op']){
	case "click":
		clickpartner(intval($HTTP_GET_VARS['id']));
		break;
	default:
		index();
		break;
}
?>