<?php
/**
 * This file is part of 
 * pragmaMx - Web Content Management System.
 * Copyright by pragmaMx Developer Team - http://www.pragmamx.org
 *
 * pragmaMx 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 3 of the License, or
 * (at your option) any later version.
 *
 * $Revision: 1.17.2.1 $
 * $Author: tora60 $
 * $Date: 2008/02/02 10:40:53 $
 *
 * this file based on:
 * Enhanced with NukeStats Module Version 1.0
 * Copyright ©2002 by Harry Mangindaan (sens@indosat.net) and
 * Sudirman (sudirman@akademika.net)
 * http://www.nuketest.com
 * php-nuke Web Portal System - http://phpnuke.org/
 * Thatware - http://thatware.org/
 */

defined('mxMainFileLoaded') or die('access denied');

if (!defined('PMX_VERSION')) {
    mxErrorScreen('pragmaMx >= 0.1.10 is required');
}

$module_name = basename(dirname(__FILE__));
mxGetLangfile($module_name);
$pagetitle = _STATS;

$now = getdate();


function mk_percbar($pperc)
{
    // ,200,10,"#000000","#000000","$bgcolor1",false)
    $width = 260;
    $height = 12;
    $color = $GLOBALS['bgcolor2'];
    $bordercolor = $GLOBALS['bgcolor2'];
    $bgcolor = $GLOBALS['bgcolor1'];

    $pperc = round($pperc, 0);
    $ipperc = 100 - $pperc;

    if ($pperc == 100) {
        $what = '<table border="1" cellspacing="0" cellpadding="0" style="border-width: 1px; border-style: solid; border-color: ' . $bordercolor . '; width: ' . $width . 'px; height: ' . $height . 'px;"><tr><td width="100%" style="background-color: ' . $color . '; border-style: solid; border-width: 1px; border-color: ' . $bgcolor . ';"><img src="images/pixel.gif" alt="" width="100%" height="' . (ceil($height / 2)) . '" border="0" /></td></tr></table>';
    } elseif ($pperc == 0) {
        $what = '<table border="1" cellspacing="0" cellpadding="0" style="border-width: 1px; border-style: solid; border-color: ' . $bordercolor . '; width: ' . $width . 'px; height: ' . $height . 'px;"><tr><td width="100%" style="background-color: ' . $bgcolor . '; border-style: solid; border-width: 1px; border-color: ' . $bgcolor . ';"><img src="images/pixel.gif" alt="" width="100%" height="' . (ceil($height / 2)) . '" border="0" /></td></tr></table>';
    } else {
        $what = '<table border="1" cellspacing="0" cellpadding="0" style="border-width: 1px; border-style: solid; border-color: ' . $bordercolor . '; width: ' . $width . 'px; height: ' . $height . 'px;"><tr><td width="' . $pperc . '%" style="background-color: ' . $color . '; border-style: solid; border-width: 1px; border-color: ' . $bgcolor . ';"><img src="images/pixel.gif" alt="" width="' . $pperc . '" height="' . (ceil($height / 2)) . '" border="0" /></td><td width="' . $ipperc . '%" style="background-color: ' . $bgcolor . '; border-style: solid; border-width: 1px; border-color: ' . $bgcolor . ';"><img src="images/pixel.gif" alt="" width="' . $ipperc . '" height="' . (ceil($height / 2)) . '" border="0" /></td></tr></table>';
    }
    return $what;
}

function stat_Main()
{
    global $prefix, $user_prefix, $bgcolor1, $module_name;
    include("header.php");
    $result = sql_query("select type, var, count from " . $prefix . "_counter ORDER BY type desc");
    while (list($type, $var, $count) = sql_fetch_row($result)) {
        if (($type == "total") && ($var == "hits")) {
            $total = $count;
        } elseif ($type == "browser") {
            if ($var == "Netscape") {
                $netscape[] = mxValueToString($count, 0);
                $netscape[] = substr(100 * $count / $total, 0, 5);
                $netscape[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "MSIE") {
                $msie[] = mxValueToString($count, 0);
                $msie[] = substr(100 * $count / $total, 0, 5);
                $msie[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Konqueror") {
                $konqueror[] = mxValueToString($count, 0);
                $konqueror[] = substr(100 * $count / $total, 0, 5);
                $konqueror[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Opera") {
                $opera[] = mxValueToString($count, 0);
                $opera[] = substr(100 * $count / $total, 0, 5);
                $opera[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Lynx") {
                $lynx[] = mxValueToString($count, 0);
                $lynx[] = substr(100 * $count / $total, 0, 5);
                $lynx[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Mozilla") {
                $mozilla[] = mxValueToString($count, 0);
                $mozilla[] = substr(100 * $count / $total, 0, 5);
                $mozilla[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Bot") {
                $bot[] = mxValueToString($count, 0);
                $bot[] = substr(100 * $count / $total, 0, 5);
                $bot[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Other") {
                $b_other[] = mxValueToString($count, 0);
                $b_other[] = substr(100 * $count / $total, 0, 5);
                $b_other[] = mxValueToString(100 * $count / $total, 3);
            }
        } elseif ($type == "os") {
            if ($var == "Windows") {
                $windows[] = mxValueToString($count, 0);
                $windows[] = substr(100 * $count / $total, 0, 5);
                $windows[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Mac") {
                $mac[] = mxValueToString($count, 0);
                $mac[] = substr(100 * $count / $total, 0, 5);
                $mac[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Linux") {
                $linux[] = mxValueToString($count, 0);
                $linux[] = substr(100 * $count / $total, 0, 5);
                $linux[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "FreeBSD") {
                $freebsd[] = mxValueToString($count, 0);
                $freebsd[] = substr(100 * $count / $total, 0, 5);
                $freebsd[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "SunOS") {
                $sunos[] = mxValueToString($count, 0);
                $sunos[] = substr(100 * $count / $total, 0, 5);
                $sunos[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "IRIX") {
                $irix[] = $count;
                $irix[] = substr(100 * $count / $total, 0, 5);
                $irix[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "BeOS") {
                $beos[] = mxValueToString($count, 0);
                $beos[] = substr(100 * $count / $total, 0, 5);
                $beos[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "OS/2") {
                $os2[] = mxValueToString($count, 0);
                $os2[] = substr(100 * $count / $total, 0, 5);
                $os2[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "AIX") {
                $aix[] = mxValueToString($count, 0);
                $aix[] = substr(100 * $count / $total, 0, 5);
                $aix[] = mxValueToString(100 * $count / $total, 3);
            } elseif ($var == "Other") {
                $os_other[] = mxValueToString($count, 0);
                $os_other[] = substr(100 * $count / $total, 0, 5);
                $os_other[] = mxValueToString(100 * $count / $total, 3);
            }
        }
    }
    title("" . $GLOBALS['sitename'] . " " . _STATS);
    OpenTable();
    echo "<center><p>" . _WERECEIVED . " <b>" . mxValueToString($total, 0) . "</b> " . _PAGESVIEWS . " " . $GLOBALS['startdate'] . "</p>"
     . "<p>[&nbsp;<a href=\"modules.php?name=$module_name&amp;op=Stats\">" . _VIEWDET . "</a>&nbsp;]</p></center>"
     . "<br />";
    $bigxy = 0;
    if ($bigxy < $msie[1])$bigxy = $msie[1];
    if ($bigxy < $mozilla[1])$bigxy = $mozilla[1];
    if ($bigxy < $netscape[1])$bigxy = $netscape[1];
    if ($bigxy < $opera[1])$bigxy = $opera[1];
    if ($bigxy < $konqueror[1])$bigxy = $konqueror[1];
    if ($bigxy < $lynx[1])$bigxy = $lynx[1];
    if ($bigxy < $bot[1])$bigxy = $bot[1];
    if ($bigxy < $b_other[1])$bigxy = $b_other[1];
    OpenTable2();
    echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\">\n";
    echo "<tr><td colspan=\"3\"><center><b>" . _BROWSERS . "</b></center><br /></td></tr>\n";
    if ($msie[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/explorer.gif\" border=\"0\" alt=\"\" />&nbsp;MSIE: </td><td>" . mk_percbar(round((100 * $msie[1]) / $bigxy, 0)) . "</td><td nowrap> $msie[2]% ($msie[0])</td></tr>\n";
    if ($mozilla[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/mozilla.gif\" border=\"0\" alt=\"\" />&nbsp;Mozilla: </td><td>" . mk_percbar(round((100 * $mozilla[1]) / $bigxy, 0)) . "</td><td nowrap> $mozilla[2]% ($mozilla[0])</td></tr>\n";
    if ($netscape[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/netscape.gif\" border=\"0\" alt=\"\" />&nbsp;Netscape: </td><td>" . mk_percbar(round((100 * $netscape[1]) / $bigxy, 0)) . "</td><td nowrap> $netscape[2]% ($netscape[0])</td></tr>\n";
    if ($opera[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/opera.gif\" border=\"0\" alt=\"\" />&nbsp;Opera: </td><td>" . mk_percbar(round((100 * $opera[1]) / $bigxy, 0)) . "</td><td nowrap> $opera[2]% ($opera[0])</td></tr>\n";
    if ($konqueror[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/konqueror.gif\" border=\"0\" alt=\"\" />&nbsp;Konqueror: </td><td>" . mk_percbar(round((100 * $konqueror[1]) / $bigxy, 0)) . "</td><td nowrap> $konqueror[2]% ($konqueror[0])</td></tr>\n";
    if ($lynx[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/lynx.gif\" border=\"0\" alt=\"\" />&nbsp;Lynx: </td><td>" . mk_percbar(round((100 * $lynx[1]) / $bigxy, 0)) . "</td><td nowrap> $lynx[2]% ($lynx[0])</td></tr>\n";
    if ($bot[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/altavista.gif\" border=\"0\" alt=\"\" />&nbsp;" . _SENGINE . ": </td><td>" . mk_percbar(round((100 * $bot[1]) / $bigxy, 0)) . "</td><td nowrap> $bot[2]% ($bot[0])</td></tr>\n";
    if ($b_other[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/question.gif\" border=\"0\" alt=\"\" />&nbsp;" . _UNKNOWN . ": </td><td>" . mk_percbar(round((100 * $b_other[1]) / $bigxy, 0)) . "</td><td nowrap> $b_other[2]% ($b_other[0])</td></tr>\n";
    echo "</table>\n";
    CloseTable2();
    echo "<br /><br />\n";
    $bigxy = 0;
    if ($bigxy < $linux[1]) $bigxy = $linux[1];
    if ($bigxy < $windows[1]) $bigxy = $windows[1];
    if ($bigxy < $mac[1]) $bigxy = $mac[1];
    if ($bigxy < $freebsd[1]) $bigxy = $freebsd[1];
    if ($bigxy < $sunos[1]) $bigxy = $sunos[1];
    if ($bigxy < $irix[1]) $bigxy = $irix[1];
    if ($bigxy < $beos[1]) $bigxy = $beos[1];
    if ($bigxy < $os2[1]) $bigxy = $os2[1];
    if ($bigxy < $aix[1]) $bigxy = $aix[1];
    if ($bigxy < $os_other[1]) $bigxy = $os_other[1];
    OpenTable2();
    echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\">\n";
    echo "<tr><td colspan=\"3\"><center><b>" . _OPERATINGSYS . "</b></center><br /></td></tr>\n";
    if ($linux[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/linux.gif\" border=\"0\" alt=\"\" />&nbsp;Linux:</td><td>" . mk_percbar(round((100 * $linux[1]) / $bigxy, 0)) . "</td><td nowrap> $linux[2]% ($linux[0])</td></tr>\n";
    if ($windows[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/windows.gif\" border=\"0\" alt=\"\" />&nbsp;Windows:</td><td>" . mk_percbar(round((100 * $windows[1]) / $bigxy, 0)) . "</td><td nowrap> $windows[2]% ($windows[0])</td></tr>\n";
    if ($mac[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/mac.gif\" border=\"0\" alt=\"\" />&nbsp;Mac/PPC:</td><td>" . mk_percbar(round((100 * $mac[1]) / $bigxy, 0)) . "</td><td nowrap> $mac[2] % ($mac[0])</td></tr>\n";
    if ($freebsd[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/bsd.gif\" border=\"0\" alt=\"\" />&nbsp;FreeBSD:</td><td>" . mk_percbar(round((100 * $freebsd[1]) / $bigxy, 0)) . "</td><td nowrap> $freebsd[2]% ($freebsd[0])</td></tr>\n";
    if ($sunos[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/sun.gif\" border=\"0\" alt=\"\" />&nbsp;SunOS:</td><td>" . mk_percbar(round((100 * $sunos[1]) / $bigxy, 0)) . "</td><td nowrap> $sunos[2]% ($sunos[0])</td></tr>\n";
    if ($irix[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/irix.gif\" border=\"0\" alt=\"\" />&nbsp;IRIX:</td><td>" . mk_percbar(round((100 * $irix[1]) / $bigxy, 0)) . "</td><td nowrap> $irix[2]% ($irix[0])</td></tr>\n";
    if ($beos[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/be.gif\" border=\"0\" alt=\"\" />&nbsp;BeOS:</td><td>" . mk_percbar(round((100 * $beos[1]) / $bigxy, 0)) . "</td><td nowrap> $beos[2]% ($beos[0])</td></tr>\n";
    if ($os2[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/os2.gif\" border=\"0\" alt=\"\" />&nbsp;OS/2:</td><td>" . mk_percbar(round((100 * $os2[1]) / $bigxy, 0)) . "</td><td nowrap> $os2[2]% ($os2[0])</td></tr>\n";
    if ($aix[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/aix.gif\" border=\"0\" alt=\"\" />&nbsp;AIX:</td><td>" . mk_percbar(round((100 * $aix[1]) / $bigxy, 0)) . "</td><td nowrap> $aix[2]% ($aix[0])</td></tr>\n";
    if ($os_other[0] > 0) echo "<tr><td nowrap><img src=\"modules/$module_name/statpic/question.gif\" border=\"0\" alt=\"\" />&nbsp;" . _UNKNOWN . ":</td><td>" . mk_percbar(round((100 * $b_other[1]) / $bigxy, 0)) . "</td><td nowrap> $os_other[2]% ($os_other[0])</td></tr>\n";
    echo "</table>\n";
    CloseTable2();
    echo "<br /><br />\n";

    $result = sql_query("SHOW TABLES;");
    while (list($tablename) = sql_fetch_row($result)) {
        if (ereg($prefix, $tablename) || ereg($user_prefix, $tablename)) {
            $tables[] = $tablename;
        }
    }

    list($unum) = sql_fetch_row(sql_query("select count(uid) from " . $user_prefix . "_users where user_stat=1")); #-1; # Anonymous abziehen
    list($anum) = sql_fetch_row(sql_query("select count(aid) from " . $prefix . "_authors"));
    list($snum) = sql_fetch_row(sql_query("select count(sid) from ${prefix}_stories WHERE `time` <= now()"));
    $unum = mxValueToString($unum[0], 0);
    $anum = mxValueToString($anum[0], 0);
    $snum = mxValueToString($snum[0], 0);
    $cnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_comments")), 0);
    $secnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_sections")), 0);
    $secanum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_seccont")), 0);
    $subnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_queue")), 0);
    $tnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_topics")), 0);
    $catnum = mxValueToString(sql_num_rows(sql_query("select * from ${prefix}_stories_cat")), 0);
    $faqnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_faqanswer")), 0);
    $faqnumcat = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_faqcategories")), 0);
    $ephemnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_ephem")), 0);
    $links = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_links")), 0);
    $cat1 = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_categories")), 0);
    $numlinkcom = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_editorials")), 0);
    $numlinkbew = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_votedata")), 0);
    $linkwaitmod = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_modrequest")), 0);
    $numreviews = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_reviews")), 0);
    $comreviews = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_reviews_comments")), 0);
    $numdownloads = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_downloads WHERE cid > 0")), 0);
    $catdown = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_categories")), 0);
    $numdowncom = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_editorials")), 0);
    $numdownbew = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_votedata")), 0);
    $actpoll = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_poll_desc WHERE pollactive=1")), 0);
    $pollcom = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_pollcomments")), 0);
    $linkswait = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_links_newlink")), 0);
    $downloadwait = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_newdownload")), 0);
    $downloadwaitmod = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_downloads_modrequest")), 0);
    $privmess = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_priv_msgs")), 0);
    $aktivbanners = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_banner")), 0);

    if (in_array($prefix . "_events", $tables)) {
        $events = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_events WHERE activ=1;")), 0);
    }
    if (in_array($prefix . "_eBoard_forums", $tables)) {
        $numfor = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_eBoard_forums")), 0);
    } elseif (in_array($prefix . "_eboard_forums", $tables)) {
        $numfor = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_eboard_forums")), 0);
    } elseif (in_array($prefix . "_xmb_forums", $tables)) {
        $numfor = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_xmb_forums")), 0);
    }
    if (in_array($prefix . "_nukebook", $tables)) {
        $guestnum = mxValueToString(sql_num_rows(sql_query("select * from " . $prefix . "_nukebook")), 0);
    }
	
    OpenTable2();
    echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\">\n";
    echo "<tr><td colspan=\"2\"><center><b>" . _MISCSTATS . "</b></center><br /></td></tr>\n";
    if ($snum) echo "<tr><td><img src=\"modules/$module_name/statpic/news.gif\" border=\"0\" alt=\"\" />&nbsp;" . _STORIESPUBLISHED . "</td><td><b>$snum</b></td></tr>\n";
    if ($tnum) echo "<tr><td><img src=\"modules/$module_name/statpic/topics.gif\" border=\"0\" alt=\"\" />&nbsp;" . _SACTIVETOPICS . "</td><td><b>$tnum</b></td></tr>\n";
    if ($catnum) echo "<tr><td><img src=\"modules/$module_name/statpic/star.gif\" border=\"0\" alt=\"\" />&nbsp;" . _NEWSCAT . ":</td><td><b>$catnum</b></td></tr>\n";
    if ($cnum) echo "<tr><td><img src=\"modules/$module_name/statpic/comments.gif\" border=\"0\" alt=\"\" />&nbsp;" . _COMMENTSPOSTED . "</td><td><b>$cnum</b></td></tr>\n";
    if ($secnum) echo "<tr><td><img src=\"modules/$module_name/statpic/sections.gif\" border=\"0\" alt=\"\" />&nbsp;" . _SSPECIALSECT . "</td><td><b>$secnum</b></td></tr>\n";
    if ($secanum) echo "<tr><td><img src=\"modules/$module_name/statpic/articles.gif\" border=\"0\" alt=\"\" />&nbsp;" . _ARTICLESSEC . "</td><td><b>$secanum</b></td></tr>\n";
    if ($faqnum) echo "<tr><td><img src=\"modules/$module_name/statpic/articles.gif\" border=\"0\" alt=\"\" />&nbsp;" . _FAQART . ":</td><td><b>$faqnum</b></td></tr>\n";
    if ($faqnumcat) echo "<tr><td><img src=\"modules/$module_name/statpic/sections.gif\" border=\"0\" alt=\"\" />&nbsp;" . _FAQCAT . ":</td><td><b>$faqnumcat</b></td></tr>\n";
    if ($ephemnum) echo "<tr><td><img src=\"modules/$module_name/statpic/articles.gif\" border=\"0\" alt=\"\" />&nbsp;" . _EPHEMS . ":</td><td><b>$ephemnum</b></td></tr>\n";
    if (isset($events)) echo "<tr><td><img src=\"modules/$module_name/statpic/articles.gif\" border=\"0\" alt=\"\" />&nbsp;" . _KTERMS . ":</td><td><b>$events</b></td></tr>\n";
    if (isset($guestnum)) echo "<tr><td><img src=\"modules/$module_name/statpic/articles.gif\" border=\"0\" alt=\"\" />&nbsp;" . _GBTERMS . ":</td><td><b>$guestnum</b></td></tr>\n";
    if ($links) echo "<tr><td><img src=\"modules/$module_name/statpic/topics.gif\" border=\"0\" alt=\"\" />&nbsp;" . _LINKSINLINKS . "</td><td><b>$links</b></td></tr>\n";
    if ($cat1) echo "<tr><td><img src=\"modules/$module_name/statpic/sections.gif\" border=\"0\" alt=\"\" />&nbsp;" . _LINKSCAT . "</td><td><b>$cat1</b></td></tr>\n";
    if ($numlinkcom) echo "<tr><td><img src=\"modules/$module_name/statpic/comments.gif\" border=\"0\" alt=\"\" />&nbsp;" . _LINKCOMM . ":</td><td><b>$numlinkcom</b></td></tr>\n";
    if ($numlinkbew) echo "<tr><td><img src=\"modules/$module_name/statpic/users.gif\" border=\"0\" alt=\"\" />&nbsp;" . _LINKVOT . ":</td><td><b>$numlinkbew</b></td></tr>\n";
    if ($numreviews) echo "<tr><td><img src=\"modules/$module_name/statpic/topics.gif\" border=\"0\" alt=\"\" />&nbsp;" . _REWV . ":</td><td><b>$numreviews</b></td></tr>\n";
    if ($comreviews) echo "<tr><td><img src=\"modules/$module_name/statpic/comments.gif\" border=\"0\" alt=\"\" />&nbsp;" . _REWVCOMM . ":</td><td><b>$comreviews</b></td></tr>\n";
    if ($numdownloads) echo "<tr><td><img src=\"modules/$module_name/statpic/download.gif\" border=\"0\" alt=\"\" />&nbsp;" . _DOWNA . ":</td><td><b>$numdownloads</b></td></tr>\n";
    if ($catdown) echo "<tr><td><img src=\"modules/$module_name/statpic/sections.gif\" border=\"0\" alt=\"\" />&nbsp;" . _DOWNB . ":</td><td><b>$catdown</b></td></tr>\n";
    if ($numdowncom) echo "<tr><td><img src=\"modules/$module_name/statpic/comments.gif\" border=\"0\" alt=\"\" />&nbsp;" . _DOWNC . ":</td><td><b>$numdowncom</b></td></tr>\n";
    if ($numdownbew) echo "<tr><td><img src=\"modules/$module_name/statpic/users.gif\" border=\"0\" alt=\"\" />&nbsp;" . _DOWND . ":</td><td><b>$numdownbew</b></td></tr>\n";
    if ($actpoll) echo "<tr><td><img src=\"modules/$module_name/statpic/star.gif\" border=\"0\" alt=\"\" />&nbsp;" . _SURACT . ":</td><td><b>$actpoll</b></td></tr>\n";
    if ($pollcom) echo "<tr><td><img src=\"modules/$module_name/statpic/comments.gif\" border=\"0\" alt=\"\" />&nbsp;" . _SURCOMM . ":</td><td><b>$pollcom</b></td></tr>\n";
    if (isset($numfor)) echo "<tr><td><img src=\"modules/$module_name/statpic/star.gif\" border=\"0\" alt=\"\" />&nbsp;" . _FORACT . ":</td><td><b>$numfor</b></td></tr>\n";
    if ($aktivbanners) echo "<tr><td><img src=\"modules/$module_name/statpic/star.gif\" border=\"0\" alt=\"\" />&nbsp;" . _ACTBANN . ":</td><td><b>$aktivbanners</b></td></tr>\n";
    
// ACHTUNG auf richtigen Prefix der DB achten !!! Muss geaendert werden !!!!
$count_cpg_pictures = sql_query("SELECT count(*)as countpic FROM mxbaaf8f_cpg1419_pictures");
$amount_cpg_pictures = sql_fetch_assoc($count_cpg_pictures);
		
		echo "<tr><td><img src=\"modules/$module_name/statpic/cam.gif\" border=\"0\" alt=\"\" /> Bilder in der Gallerie:</td><td><strong>" . $amount_cpg_pictures['countpic'] . "</strong></td></tr>\n";
		
		echo "</table>\n";
    CloseTable2();
    echo "<br /><br />\n";
    OpenTable2();
    echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\">\n";
    echo "<tr><td colspan=\"2\"><center><b>" . _PERS . ":</b></center><br /></td></tr>\n";
    echo "<tr><td><img src=\"modules/$module_name/statpic/authors.gif\" border=\"0\" alt=\"\" />&nbsp;" . _ACTIVEAUTHORS . "</td><td><b>$anum</b></td></tr>\n";
    echo "<tr><td><img src=\"modules/$module_name/statpic/users.gif\" border=\"0\" alt=\"\" />&nbsp;" . _REGUSERS . "</td><td><b>$unum</b></td></tr>\n";
    if ($privmess && MX_IS_ADMIN) echo "<tr><td><img src=\"modules/$module_name/statpic/friend.gif\" border=\"0\" alt=\"\" />&nbsp;" . _PRIMESS . ":</td><td><b>$privmess</b></td></tr>\n";
    if ($subnum) echo "<tr><td><img src=\"modules/$module_name/statpic/waiting.gif\" border=\"0\" alt=\"\" />&nbsp;" . _NEWSWAITING1 . "</td><td><b>$subnum</b></td></tr>\n";
    echo "<tr><td><img src=\"modules/$module_name/statpic/sections.gif\" border=\"0\" alt=\"\" />&nbsp;" . _NUKEVERSION . "</td><td><b>" . MX_VERSION . "</b></td></tr>\n";
    echo "</table>";
    CloseTable2();
    CloseTable();
    include("footer.php");
}

function Stats()
{
    global $now, $prefix, $module_name;
    $result = sql_query("select count from " . $prefix . "_counter ORDER BY type desc");
    list($total) = sql_fetch_row($result);
    include ("header.php");
    title("" . $GLOBALS['sitename'] . " " . _STATS);
    OpenTable();
    echo "<center><p>" . _WERECEIVED . " <b>" . mxValueToString($total, 0) . "</b> " . _PAGESVIEWS . " " . $GLOBALS['startdate'] . "</p>";
    echo "<p>[&nbsp;<a href=\"modules.php?name=$module_name\">" . _RETURNBASICSTATS . "</a>&nbsp;]</p>";
    echo "<p>" . _TODAYIS . ": " . mx_strftime(_DATESTRING) . "</p>";

    $result = sql_query("SELECT year, month, Sum(hits)
												FROM " . $prefix . "_stats
												WHERE (((hits)>0))
												GROUP BY year, month;");
    $maxhit = 0;
    $maxyear = $now['year'];
    $maxmonth = $now['mon'];
    while (list($year, $month, $hits) = sql_fetch_row($result)) {
        if ($maxhit < $hits) {
            $maxhit = $hits;
            $maxyear = $year;
            $maxmonth = $month;
        }
    }
    echo _MOSTMONTH . ": " . getmonth($maxmonth) . " " . $maxyear . " (" . mxValueToString($maxhit, 0) . " " . _HITS . ")<br />";

    $result = sql_query("SELECT year, month, date, Sum(hits)
												FROM " . $prefix . "_stats
												WHERE (((hits)>0))
												GROUP BY year, month, date;");
    $maxhit = 0;
    $maxyear = $now['year'];
    $maxmonth = $now['mon'];
    $maxday = $now['mday'];
    while (list($year, $month, $date, $hits) = sql_fetch_row($result)) {
        if ($maxhit < $hits) {
            $maxhit = $hits;
            $maxyear = $year;
            $maxmonth = $month;
            $maxday = $date;
        }
    }
    echo _MOSTDAY . ": " . mx_strftime(_DATESTRING, mktime(0, 0, 0, $maxmonth, $maxday, $maxyear)) . " (" . mxValueToString($maxhit, 0) . " " . _HITS . ")<br />";

    $result = sql_query("select year, month, date, hour, hits from " . $prefix . "_stats ORDER BY hits DESC limit 0,1");
    list($year, $month, $date, $hour, $hits) = sql_fetch_row($result);
    $hour = ($hour < 10) ? "0$hour:00 - 0$hour:59" : "$hour:00 - $hour:59";
    // mktime ( int Stunde, int Minute, int Sekunde, int Monat, int Tag, int Jahr [, int is_dst])
    echo _MOSTHOUR . ": $hour " . _ON . " " . mx_strftime(_DATESTRING, mktime(0, 0, 0, $month, $date, $year)) . " (" . mxValueToString($hits, 0) . " " . _HITS . ")<br /><br />"
     . "</center>";

    echo "<br /><br />";
    showYearStats();
    echo "<br /><br />";
    showMonthStats($now['year']);
    echo "<br /><br />";
    showDailyStats($now['year'], $now['mon']);
    echo "<br /><br />";
    showHourlyStats($now['year'], $now['mon'], $now['mday']);
    echo "<br /><br /><center>[&nbsp;<a href=\"modules.php?name=$module_name\">" . _RETURNBASICSTATS . "</a>&nbsp;]</center><br /><br />";
    closetable();
    include ("footer.php");
}

function YearlyStats($year)
{
    global $now, $module_name;
    include ("header.php");
    title("" . $GLOBALS['sitename'] . " " . _STATS);
    opentable();
    showMonthStats($year);
    echo '<br />';
    echo "<center>[&nbsp;<a href=\"modules.php?name=$module_name\">" . _BACKTOMAIN . "</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">" . _BACKTODETSTATS . "</a>&nbsp;]</center>";
    closetable();
    include ("footer.php");
}

function MonthlyStats($year, $month)
{
    global $now, $module_name;
    include ("header.php");
    title("" . $GLOBALS['sitename'] . " " . _STATS);
    opentable();
    showDailyStats($year, $month);
    echo '<br />';
    echo "<center>[&nbsp;<a href=\"modules.php?name=$module_name\">" . _BACKTOMAIN . "</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">" . _BACKTODETSTATS . "</a>&nbsp;]</center>";
    closetable();
    include ("footer.php");
}

function DailyStats($year, $month, $date)
{
    global $module_name;
    include ("header.php");
    title("" . $GLOBALS['sitename'] . " " . _STATS);
    opentable();
    showHourlyStats($year, $month, $date);
    echo '<br />';
    echo "<center>[&nbsp;<a href=\"modules.php?name=$module_name\">" . _BACKTOMAIN . "</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">" . _BACKTODETSTATS . "</a>&nbsp;]</center>";
    closetable();
    include ("footer.php");
}

function showYearStats()
{
    global $prefix, $bgcolor1, $bgcolor2, $bgcolor2, $module_name, $now;
    $result = sql_query("select sum(hits) as TotalHitsYear from " . $prefix . "_stats");
    list($TotalHitsYear) = sql_fetch_row($result);
    $result = sql_query("SELECT year, Sum(hits) AS hits
												FROM " . $prefix . "_stats
												GROUP BY year
												order by year");
    echo "<center><b>" . _YEARLYSTATS . "</b></center><br />";
    echo "<table align=\"center\" bgcolor=\"$bgcolor2\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
    echo "<tr><td width=\"40%\" bgcolor=\"$bgcolor2\">" . _YEAR . "</td><td bgcolor=\"$bgcolor2\">" . _SPAGESVIEWS . "</td></tr>";
    while (list($year, $hits) = sql_fetch_row($result)) {
        echo "<tr bgcolor=\"$bgcolor1\"><td>";
        if ($year != $now['year']) {
            echo "<a href=\"modules.php?name=$module_name&amp;op=YearlyStats&amp;year=$year\">$year</a>";
        } else {
            echo $year;
        }
        echo "</td><td>";
        if ($hits[0] > 0) echo mk_percbar(round(100 * $hits / $TotalHitsYear, 0)) . " (" . mxValueToString($hits, 0) . ")";
        echo "</td></tr>";
    }
    sql_free_result($result);
    echo "</table>";
}

function showMonthStats($year)
{
    global $prefix, $bgcolor1, $bgcolor2, $module_name, $now;
    $resultmonth = sql_query("select sum(hits) as TotalHitsMonth from " . $prefix . "_stats where year='" . intval($year) . "'");
    list($TotalHitsMonth) = sql_fetch_row($resultmonth);
    sql_free_result($resultmonth);
    $result = sql_query("SELECT month, Sum(hits) AS hits, year
												FROM " . $prefix . "_stats
												GROUP BY year, month
												HAVING (((year)=" . $year . "))
												ORDER BY month;");
    echo "<center><b>" . _MONTLYSTATS . " " . $year . "</b></center><br />";
    echo "<table align=\"center\" bgcolor=\"$bgcolor2\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
    echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">" . _UMONTH . "</td><td bgcolor=\"$bgcolor2\">" . _SPAGESVIEWS . "</td></tr>";
    while (list($month, $hits) = sql_fetch_row($result)) {
        echo "<tr bgcolor=\"$bgcolor1\"><td>";
        echo "<a href=\"modules.php?name=$module_name&amp;op=MonthlyStats&amp;year=" . $year . "&amp;month=$month\">";
        echo getmonth($month);
        echo "</a>";
        echo "</td><td>";
        if ($hits[0] > 0) echo mk_percbar(round(100 * $hits / $TotalHitsMonth, 0)) . " (" . mxValueToString($hits, 0) . ")";
        echo "</td></tr>";
    }
    sql_free_result($result);
    echo "</table>";
}

function showDailyStats($year, $month)
{
    global $prefix, $bgcolor1, $bgcolor2, $module_name, $now;
    $resulttotal = sql_query("select sum(hits) as TotalHitsDate from " . $prefix . "_stats where year='" . intval($year) . "' and month='" . intval($month) . "'");
    list($TotalHitsDate) = sql_fetch_row($resulttotal);
    sql_free_result($resulttotal);
    $result = sql_query("SELECT year, month, date, Sum(hits) AS hits
												FROM " . $prefix . "_stats
												GROUP BY year, month, date
												HAVING (((year)=$year) AND ((month)=$month))
												order by date");
    $total = sql_num_rows($result);
    echo "<center><b>" . _DAILYSTATS . " " . getmonth($month) . ", $year</b></center><br />";
    echo "<table align=\"center\" bgcolor=\"$bgcolor2\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
    echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">" . _DATE . "</td><td bgcolor=\"$bgcolor2\">" . _SPAGESVIEWS . "</td></tr>";
    while (list($year, $month, $date, $hits) = sql_fetch_row($result)) {
        echo "<tr bgcolor=\"$bgcolor1\"><td>";
        echo "<a href=\"modules.php?name=$module_name&amp;op=DailyStats&amp;year=$year&amp;month=$month&amp;date=$date\">";
        echo $date;
        echo "</a>";
        echo "</td><td>";
        if ($hits == 0) {
            $WidthIMG = 0;
            $d_percent = 0;
        } else {
            $WidthIMG = round(100 * $hits / $TotalHitsDate, 0);
            $d_percent = mxValueToString(100 * $hits / $TotalHitsDate, 2);
        }
        if ($hits[0] > 0) echo mk_percbar(round(100 * $hits / $TotalHitsDate, 0)) . " $d_percent% (" . mxValueToString($hits, 0) . ")"
             . "</td></tr>";
    }
    sql_free_result($result);
    echo "</table>";
}

function showHourlyStats($year, $month, $date)
{
    global $prefix, $bgcolor1, $bgcolor2, $module_name;
    $resulttotal = sql_query("select sum(hits) as TotalHitsHour from " . $prefix . "_stats where year='" . intval($year) . "' and month='" . intval($month) . "' and date='" . intval($date) . "'");
    list ($TotalHitsHour) = sql_fetch_row($resulttotal);
    sql_free_result($resulttotal);
    echo "<center><b>" . _HOURLYSTATS . " " . mx_strftime(_DATESTRING, mktime(0, 0, 0, $month, $date, $year)) . "</b></center><br />";
    echo "<table align=\"center\" bgcolor=\"$bgcolor2\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
    echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">" . _HOUR . "</td><td bgcolor=\"$bgcolor2\" width=\"70%\">" . _SPAGESVIEWS . "</td></tr>";
    for ($k = 0;$k <= 23;$k++) {
        $result = sql_query("select hour,hits from " . $prefix . "_stats where year='" . intval($year) . "' and month='" . intval($month) . "' and date='" . intval($date) . "' and hour='$k'");
        if (sql_num_rows($result) == 0) {
            $hits = 0;
        } else {
            list($hour, $hits) = sql_fetch_row($result);
        }
        echo "<tr><td bgcolor=\"$bgcolor1\">";
        $a = ($k < 10) ? "0$k" : $k;
        echo "$a:00 - $a:59";
        $a = "";
        echo "</td><td bgcolor=\"$bgcolor1\">";
        if ($hits == 0) {
            $WidthIMG = 0;
            $d_percent = 0;
        } else {
            $WidthIMG = round(100 * $hits / $TotalHitsHour, 0);
            $d_percent = mxValueToString(100 * $hits / $TotalHitsHour, 2);
        }
        if ($hits[0] > 0) echo mk_percbar(round(100 * $hits / $TotalHitsHour, 0)) . " $d_percent% (" . mxValueToString($hits, 0) . ")"
             . "</td></tr>";
    }
    sql_free_result($result);
    echo "</table>";
}

function getmonth($month)
{
    if ($month == 1) return _JANUARY;
    else if ($month == 2) return _FEBRUARY;
    else if ($month == 3) return _MARCH;
    else if ($month == 4) return _APRIL;
    else if ($month == 5) return _MAY;
    else if ($month == 6) return _JUNE;
    else if ($month == 7) return _JULY;
    else if ($month == 8) return _AUGUST;
    else if ($month == 9) return _SEPTEMBER;
    else if ($month == 10) return _OCTOBER;
    else if ($month == 11) return _NOVEMBER;
    else if ($month == 12) return _DECEMBER;
}

switch ($op) {
    default:
        stat_Main();
        break;

    case "Stats":
        Stats();
        break;

    case "YearlyStats":
        YearlyStats($year);
        break;

    case "MonthlyStats":
        MonthlyStats($year, $month);
        break;

    case "DailyStats":
        DailyStats($year, $month, $date);
        break;
}

?>