<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: top.php,v 1.4.2.3 2004/04/18 12:45:45 ajvwaay Exp $



/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.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.       */
/************************************************************************/
//- Stats
//- January 14th, 2001
//- by Philip Mayer
//- webmaster@phildorado.net
//- parts (c) Brett Jungblut (brett@jungblut.net) & Dourk (mailto:dork@mindless.com)
/************************************************************************/
//Top xx von: - Artikel
//            - Kommentare
//            - Kategorien
//            - Sections
//            - Autoren
//            - Umfragen
//            - Nachrichtenschreiber
//            - Reviews
//            - Links / myLinks
//            - Downloads
//            - Bücher (wenn bookcorner addon vorhanden)
//            - Beiträge - Forum
//            - Antworten - Forum
//            - Beitrage User - Forum
//            - Smilies - Forum
//
//erweitert etc. pp. von erbse@mynuke.de, http://www.erbse.f2s.com
//                       26.08.2001
/************************************************************************/

// K O N F I G - S T A R T

$mylinks=0; // Wenn das mylinks Addon installiert ist, den Wert auf 1 setzen (Default=0)

// K O N F I G - E N D E


//include_once("mainfile.php");
include("header.php");

OpenTable();
$topi = $top;
echo '<center><h3>' . translate("Top ") . $top . translate(" of ") . $sitename . '</h3></center>';

/* Top 10 read stories */
$result = mysql_query("SELECT sid, title, time, counter FROM ".$mpnTables['stories']." WHERE counter > 0 ORDER BY counter DESC LIMIT 0, $topi");
if (mysql_numrows($result) > 0) {
    OpenTab();
    echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Articles") . '</b></center></font></td></tr><tr>';
    $lugar=1;
    $count=1;
    while(list($sid, $title, $time, $counter) = mysql_fetch_row($result)) {
        $row = changefarbe($count);
        echo "<td bgcolor=$row>$lugar: <a href=article.php?sid=$sid>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$counter </b>" . translate("Read(s)") . "</td></tr><tr>";
        $lugar++;
        $count++;
    }
    bitteauffuellen($lugar);
    CloseTable();
    echo '<br><br>';
}

// Top 10 commented stories
$result = mysql_query("SELECT sid, title, comments FROM " . $mpnTables['stories'] . " WHERE comments > 0 ORDER BY comments DESC LIMIT 0, $topi");
if (mysql_numrows($result) > 0) {
    OpenTab();
    echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Commented Articles") . "</b></center></font></td></tr><tr>";
    $count=1;
    $lugar=1;
    while(list($sid, $title, $comments) = mysql_fetch_row($result)) {
        $row = changefarbe($count);
        echo "<td bgcolor=$row>$lugar: <a href=article.php?sid=$sid>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$comments</b> " . translate("Comment(s)") . "</td></tr><tr>";
        $lugar++;
        $count++;
    }
    bitteauffuellen($lugar);
    CloseTable();
    echo '<br><br>';
}

// Top 10 categories
$result = mysql_query("SELECT catid, title, counter FROM ".$mpnTables['stories_cat']." WHERE counter > 0 ORDER BY counter DESC LIMIT 0, $topi");
if (mysql_numrows($result) > 0) {
    OpenTab();
    echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Categories")."</b></center></font></td></tr><tr>";
    $count=1;
    $lugar=1;
    while(list($catid, $title, $counter) = mysql_fetch_row($result)) {
        $row = changefarbe($count);
        echo "<td bgcolor=$row>$lugar: <a href=categories.php?op=newindex&catid=$catid>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$counter</b> " . translate("read(s)") . "</td></tr><tr>";
        $lugar++;
        $count++;
    }
    bitteauffuellen($lugar);
    CloseTable();
    echo "<br><br>";
}

// Top 10 articles in special sections
$result = mysql_query("SELECT artid, secid, title, content, counter FROM ".$mpnTables['seccont']." WHERE counter > 0 ORDER BY counter DESC limit 0, $topi");
if (mysql_numrows($result) > 0) {
    OpenTab();
    echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Sections") . "</b></center></font></td></tr><tr>";
    $count=1;
    $lugar=1;
    while(list($artid, $secid, $title, $content, $counter) = mysql_fetch_row($result)) {
        $row = changefarbe($count);
        echo "<td bgcolor=$row>$lugar: <a href=sections.php?op=viewarticle&artid=$artid>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$counter</b> ". translate("reads(s)") . "</td></tr><tr>";
        $lugar++;
        $count++;
    }
    bitteauffuellen($lugar);
    CloseTable();
    echo "<br><br>";
}

// Top 10 Polls
$result = mysql_query("SELECT p.pollID, p.pollTitle, c.pollID, SUM(c.optionCount) AS total FROM ".$mpnTables['poll_desc']." p, ".$mpnTables['poll_data']." c WHERE p.pollID = c.pollID GROUP BY p.pollID ORDER BY total DESC LIMIT 0, $topi");
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Polls")."</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
    while ($data = mysql_fetch_array($result)) {
        $pollID = $data[0];
        $pollTitle = $data[1];
        $total = $data[3];
                $row = changefarbe($count);
                echo "<td bgcolor=$row>$lugar: <a href=pollBooth.php?op=results&pollID=$pollID>" . muchtxt($pollTitle) . "</a></td><td bgcolor='$row' width=40%><b>$total</b> ". translate("Vote(s)") . "</td></tr><tr>";
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

// Top 10 authors
$result = mysql_query("SELECT count(informant) as total, informant FROM ".$mpnTables['stories']." WHERE informant != 'Anonymous' AND informant != '' GROUP BY informant ORDER BY total DESC LIMIT 0, $topi");
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Article Authors")."</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
    while(list($total, $informant) = mysql_fetch_row($result)) {
        $row = changefarbe($count);
                echo "<td bgcolor=$row>$lugar: <a href=user.php?op=userinfo&uname=$informant>" . muchtxt($informant) . "</a></td><td bgcolor='$row' width=40%><b>$total</b> " . translate("Article post(s)") . "</td></tr><tr>";
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

// Top 10 reviews
$result = mysql_query("select id, title, hits from ".$mpnTables['reviews']." where hits>0 order by hits DESC limit 0,$topi");
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Reviews") . "</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
        while(list($id, $title, $hits) = mysql_fetch_row($result)) {
            $row = changefarbe($count);
                echo "<td bgcolor=$row>$lugar: <a href=reviews.php?op=showcontent&id=$id>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$hits</b> " . translate("view(s)") . "</td></tr><tr>";
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

// top 10 Links

if ($mylinks==0) {
        $result=mysql_query("select lid, title, hits from ".$mpnTables['links_links']." where hits>0 order by hits DESC limit 0,$topi");
} else {
        $result = mysql_query("select lid, title, hits from ".$mpnTables['mylinks_links']." where hits>0 order by hits DESC limit 0,$topi");
}
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Links") . "</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
        while(list($lid, $title, $hits)=mysql_fetch_row($result)) {
                $title = stripslashes($title);
                $row = changefarbe($count);
                if ($mylinks==0) {
                        echo "<td bgcolor=$row>$lugar: <a href=links.php?op=visit&lid=$lid target=new>" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$hits</b> " . translate("visit(s)"). "</td></tr><tr>";
                } else {
                        echo "<td bgcolor=$row>$lugar: <a href=mylinks.php?op=visit&lid=$lid target=new>$title</a></td><td bgcolor='$row' width=40%><b>$hits</b> " . translate("visit(s)"). "</td></tr><tr>";
                }
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

// Top 10 downloads
$result = mysql_query("select lid, title, hits from ".$mpnTables['downloads_downloads']." order by hits DESC limit 0,$topi");
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Downloads")."</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
        while(list($lid, $title, $hits) = mysql_fetch_row($result)) {
            $row = changefarbe($count);
                echo "<td bgcolor=$row>$lugar: <a href=\"download.php?op=viewdownloaddetails&lid=$lid&ttitle=$title\">" . muchtxt($title) . "</a></td><td bgcolor='$row' width=40%><b>$hits</b> " . translate("download(s)") . "</td></tr><tr>";
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

/*
// Top 10 bookcorner
$result = mysql_query("select cid, hits, title from ".$mpnTables['books']." where hits>0 order by hits DESC limit 0,$topi");
if (mysql_numrows($result)>0) {
   OpenTab();
   echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>les $topi des livres/CD les plus visités</b></center></font></td></tr><tr>";
   $count=1;
   $lugar=1;
   while(list($cid, $hits, $title) = mysql_fetch_row($result)) {
    $row = changefarbe($count);
    echo "<td bgcolor=$row>$lugar: <a href=bookcorner.php?op=viewbook&cid=$cid>$title</a></td><td bgcolor='$row' width=40%><b>$hits</b> Visite(s)</td></tr><tr>";
    $lugar++;
    $count++;
   }
   bitteauffuellen($lugar);
 CloseTable();
 echo "<br><br>";
}
mysql_free_result($result);
*/

//top - poster
$result = mysql_query("select s.posts, s.uid, u.uname from ".$mpnTables['users_status']." s, ".$mpnTables['users']." u where s.uid=u.uid && u.uid > 1 && s.posts>0 order by posts DESC Limit 0,$topi");
echo mysql_error();
if (mysql_numrows($result)>0) {
        $count=1;
        $lugar=1;
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Forum Authors") . "</b></center></font></td></tr><tr>";
        while ($row1 = mysql_fetch_array($result)) {
                $posts = $row1['posts'];
            $user = $row1['uname'];
            $user_id = $row1['uid'];
            $row = changefarbe($count);
            echo"<td bgcolor=$row>$lugar: <a href=searchbb.php?addterms=any&forum=all&username=$user&sortby=u.uname&submit=Suchen>" . muchtxt($user) . "</a></td><td bgcolor=$row width=40%><b>$posts</b> " . translate("Post(s)") . "</td></tr><tr>";
                $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

//meisten gelesen
$query = "SELECT t.topic_title, p.topic_id, t.forum_id, t.topic_views, p.post_id, f.forum_name ";
$query .= "from ".$mpnTables['forums']." f, ".$mpnTables['forumtopics']." t, ".$mpnTables['posts']." p ";
$query .= 'where t.forum_id = f.forum_id and p.topic_id = t.topic_id and forum_type != 1 group by t.topic_id ';
$query .= "order by t.topic_views desc limit 0,$topi";
$result = mysql_query($query);
if (mysql_numrows($result)>0) {
        OpenTab();
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Forum Posts") . "</b></center></font></td></tr><tr>";
        $count=1;
        $lugar=1;
        while ($row1 = mysql_fetch_array($result)) {
            $row = changefarbe($count);
            echo "<td bgcolor=$row>$lugar: <a href=viewtopic.php?topic=" . $row1['topic_id'] . "&forum=" . $row1['forum_id'] . ">" . muchtxt(stripslashes($row1['topic_title'])) . "</a></td><td bgcolor='$row' width=40%><b>" . $row1['topic_views'] . "</b> " . translate("view(s)") . "</td></tr>";
            $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

//meisten antworten
$query = 'SELECT count(t.topic_id) as count, t.topic_title, p.topic_id, t.forum_id, f.forum_name ';
$query .= "from ".$mpnTables['forums']." f, ".$mpnTables['forumtopics']." t, ".$mpnTables['posts']." p ";
$query .= 'WHERE t.forum_id = f.forum_id and p.topic_id = t.topic_id and forum_type != 1 ';
$query .= "GROUP BY t.topic_id ORDER BY count DESC LIMIT 0,$topi";
$result = mysql_query($query);
if (mysql_numrows($result)>0) {
        OpenTab();
        $count=1;
        $lugar=1;
        echo "<tr><td colspan=2 align=center><font color=$textcolor2><center><b>" . translate("Top ") . $topi . translate(" Forum Replies") . "</b></center></font></td></tr><tr>";
        while ($row1 = mysql_fetch_array($result)) {
            $read=$row1['count']-1;
            $row = changefarbe($count);
            echo "<td bgcolor=$row>$lugar: <a href=viewtopic.php?topic=" . $row1['topic_id'] . "&forum=" . $row1['forum_id'] . ">" . muchtxt(stripslashes($row1['topic_title'])) . "</a></td><td bgcolor='$row' width=40%><b>$read</b> " . translate(" replies") . "</td></tr>";
            $lugar++;
                $count++;
        }
        bitteauffuellen($lugar);
        CloseTable();
        echo "<br><br>";
}

/*
// top Smileys:
$query = "SELECT * FROM ".$mpnTables['smiles']." GROUP BY smile_url";
$all_smileys = mysql_query($query);
$topten = array();
while ($aktsmile = mysql_fetch_array($all_smileys))  {
    $aktcount = 0;
    $query2 = "SELECT post_text FROM ".$mpnTables['posts']."
              WHERE post_text LIKE '%$aktsmile[smile_url]%'";
    $all_posts = mysql_query($query2);
    while ($aktpost = mysql_fetch_array($all_posts)) {
         $aktcount = $aktcount + substr_count ($aktpost[post_text], $aktsmile[smile_url]);
    }
    $topten[$aktsmile[smile_url]] = $aktcount;
}
arsort ($topten);
reset ($topten);
if ($topten) {
   OpenTab();
   $count=1;
   $lugar=1;
   echo "<tr><td colspan=3 align=center><font color=$textcolor2><center><b>$topi smilies les plus utilisés</b></center></font></td></tr><tr>";
   while ((list ($key, $val) = each ($topten)) AND ($lugar<=$topi)) {
     if ($val!=0) {
        $row = changefarbe($count);
        echo "<td bgcolor=$row>$lugar: <img src=images/forum/smilies/$key width=15 height=15></td><td bgcolor='$row' width=40%><b>$val</b> x Utilisé(s)</td></tr>";
        $lugar++;
        $count++;
     }
   }
   bitteauffuellen($lugar);
 CloseTable();
 echo "<br><br>";
}
*/

CloseTable();

include("footer.php");

function changefarbe($count) {
    global $bgcolor1,$bgcolor3,$count;
    if ($count==2) {
        $row=$bgcolor1;
        $count=0;
    } else {
        $row=$bgcolor3;
    }
    return($row);
}

function OpenTab() {
    global $bgcolor2;
    echo "<table width=\"90%\" border=0 cellspacing=1 cellpadding=0 bgcolor=\"#000000\" align=\"center\"><tr><td>";
    echo "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$bgcolor2\">";
}

function bitteauffuellen($lugar) { // ;-))
    global $topi,$count;
    if ($lugar<$topi) {
        for($x = $lugar; $x <= $topi; $x++) {
            $row = changefarbe($count);
            echo "<td bgcolor=$row>$x: .....</td><td bgcolor='$row' width=40%>.....</td></tr><tr>";
            $count++;
        }
    }
}

function muchtxt($string) {
        $alpha = strlen($string);
        if ($alpha > 40) {
                $beta = $alpha - 40;
                $string = substr("$string", 0, -$beta).'...';
                return $string;
        } else {
                return $string;
        }
}

?>
