<?php
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2011 by Philippe Brunier                     */
/*                                                                      */
/* 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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {
   include ("mainfile.php");
}
include("functions.php");
include("auth.php");

global $admin;
if ($admin) {
    include ("header.php");
    opentable();

    global $startdate;
    list($membres,$totala,$totalb,$totalc,$totald,$totalz)=req_stat();
    //LNL Email in outside table
    $result=sql_query("select email from ".$NPDS_Prefix."lnl_outside_users");
    if ($result) {$totalnl = sql_num_rows($result);} else {$totalnl = "0";}
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo translate("Administration BlackBoard");
    echo "&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"admin.php\" class=\"heada\">".translate("Administration Tools")."</a>";
    echo "</td></tr></table>\n";
    echo "<br />\n";
    include("abla.log.php");
    $timex=time()-$xdate;
    if ($timex>=86400) {
       $timex=round($timex/86400)." ".translate("Day(s)");
    } elseif ($timex>=3600) {
       $timex=round($timex/3600)." ".translate("Hour(s)");
    } elseif ($timex>=60) {
       $timex=round($timex/60)." ".translate("Minut(s)");
    } else {
       $timex=$timex." ".translate("Second(s)");
    }
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td colspan=\"2\" class=\"header\">".translate("General Stats")." - ".translate("Past Stat")." : $timex </td></tr>";
    echo "<tr class=\"ligna\"><td width=\"70%\">".translate("Nb of Pages")." : </td><td>".wrh($totalz)." (";
    if ($totalz>$xtotalz)
       echo "<span style=\"color:green;\">+";
    elseif ($totalz<$xtotalz)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totalz-$xtotalz)."</span>)</td></tr>";

    echo "<tr class=\"lignb\"><td width=\"70%\">".translate("Nb of members")." : </td><td>".wrh($membres)." (";
    if ($membres>$xmembres)
       echo "<span style=\"color:green;\">+";
    elseif ($membres<$xmembres)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($membres-$xmembres)."</span>)</td></tr>";

    echo "<tr class=\"ligna\"><td width=\"70%\">".translate("Nb of articles")." : </td><td>".wrh($totala)." (";
    if ($totala>$xtotala)
       echo "<span style=\"color:green;\">+";
    elseif ($totala<$xtotala)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totala-$xtotala)."</span>)</td></tr>";

    echo "<tr class=\"lignb\"><td width=\"70%\">".translate("Nb of forums")." : </td><td>".wrh($totalc)." (";
    if ($totalc>$xtotalc)
       echo "<span style=\"color:green;\">+";
    elseif ($totalc<$xtotalc)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totalc-$xtotalc)."</span>)</td></tr>";

    echo "<tr class=\"ligna\"><td width=\"70%\">".translate("Nb of topics")." : </td><td>".wrh($totald)." (";
    if ($totald>$xtotald)
       echo "<span style=\"color:green;\">+";
    elseif ($totald<$xtotald)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totald-$xtotald)."</span>)</td></tr>";

    echo "<tr class=\"lignb\"><td width=\"70%\">".translate("Nb of reviews")." : </td><td>".wrh($totalb)." (";
    if ($totalb>$xtotalb)
       echo "<span style=\"color:green;\">+";
    elseif ($totalb<$xtotalb)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totalb-$xtotalb)."</span>)</td></tr>";

    echo "<tr class=\"ligna\"><td width=\"70%\">".translate("Nb Outside Users for LNL")." : </td><td>".wrh($totalnl)." (";
    if ($totalnl>$xtotalnl)
       echo "<span style=\"color:green;\">+";
    elseif ($totalnl<$xtotalnl)
       echo "<span style=\"color:red;\">";
    else
       echo "<span>";
    echo wrh($totalnl-$xtotalnl)."</span>)</td></tr>";


    $xfile="<?php\n";
    $xfile.="\$xdate = ".time().";\n";
    $xfile.="\$xtotalz = $totalz;\n";
    $xfile.="\$xmembres = $membres;\n";
    $xfile.="\$xtotala = $totala;\n";
    $xfile.="\$xtotalc = $totalc;\n";
    $xfile.="\$xtotald = $totald;\n";
    $xfile.="\$xtotalb = $totalb;\n";
    $xfile.="\$xtotalnl = $totalnl;\n";
    echo "</table><br />\n";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td colspan=\"2\" class=\"header\">".translate("Download Stats")."</td></tr>";
    $num_dow=0;
    $result = sql_query("SELECT dcounter, dfilename FROM ".$NPDS_Prefix."downloads");
    while(list($dcounter, $dfilename) = sql_fetch_row($result)) {
       $rowcolor = tablos();
       $num_dow++;
       echo "<tr $rowcolor><td width=\"70%\"><span class=\"rouge\">".$xdownload[$num_dow][1]."</span> -/- $dfilename : </td><td><span class=\"rouge\">".$xdownload[$num_dow][2]."</span> -/- $dcounter</td></tr>";
       $xfile.="\$xdownload[$num_dow][1] = \"$dfilename\";\n";
       $xfile.="\$xdownload[$num_dow][2] = \"$dcounter\";\n";
    }
    echo "</table><br />\n";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
    echo "<tr>";
    echo "<td class=\"header\">&nbsp;</td>";
    echo "<td class=\"header\">".translate("Forum")."</td>";
    echo "<td class=\"header\" align=\"center\">".translate("Topics")."</td>";
    echo "<td class=\"header\" align=\"center\">".translate("Posts")."</td>";
    echo "<td class=\"header\" align=\"center\">".translate("Last Posts")."</td></tr>";

    $result = sql_query("SELECT * FROM ".$NPDS_Prefix."catagories ORDER BY cat_id");
    $num_for=0;
    while (list($cat_id, $cat_title) = sql_fetch_row($result)) {
       $sub_sql = "SELECT f.*, u.uname FROM ".$NPDS_Prefix."forums f, ".$NPDS_Prefix."users u WHERE f.cat_id = '$cat_id' AND f.forum_moderator = u.uid ORDER BY forum_index,forum_id";
       if (!$sub_result = sql_query($sub_sql))
          forumerror('0022');
       if ($myrow = sql_fetch_assoc($sub_result)) {
          echo "<tr align=\"left\" valign=\"top\"><td colspan=\"7\">".stripslashes($cat_title)."</td></tr>";
          do {
             $num_for++;
             $last_post = get_last_post($myrow['forum_id'], "forum", "infos",true);
             echo "<tr align=\"left\">";
             $total_topics = get_total_topics($myrow['forum_id']);
             echo "<td align=\"center\" width=\"5%\" style=\"vertical-align: middle;\"><img src=\"";
             if ($ibid=theme_image("forum/icons/folder.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/icons/folder.gif";}
             echo "$imgtmp\" border=\"\" alt=\"\" /></td>";
             $name = stripslashes($myrow['forum_name']);
             $xfile.="\$xforum[$num_for][1] = \"$name\";\n";
             $xfile.="\$xforum[$num_for][2] = $total_topics;\n";
             echo "<td width=\"30%\"><a href=\"viewforum.php?forum=".$myrow['forum_id']."\" class=\"noir\"><span class=\"rouge\">".$xforum[$num_for][1]."</span> -/- $name </a>\n";
             $desc = stripslashes($myrow['forum_desc']);
             echo "<br />$desc</td>\n";
             echo "<td align=\"center\" width=\"30%\" style=\"vertical-align: middle;\"><span class=\"rouge\">".$xforum[$num_for][2]."</span> -/- $total_topics</td>\n";
             $total_posts = get_total_posts($myrow['forum_id'], "", "forum",false);
             $xfile.="\$xforum[$num_for][3] = $total_posts;\n";
             echo "<td align=\"center\" width=\"15%\" style=\"vertical-align: middle;\"><span class=\"rouge\">".$xforum[$num_for][3]."</span> -/- $total_posts</td>\n";

             echo "<td align=\"center\" width=\"15%\" style=\"vertical-align: middle;\">$last_post</td>\n";
          } while($myrow = sql_fetch_assoc($sub_result));
       }
    }
    echo "</tr></table>";

    $file = fopen("abla.log.php", "w");
    $xfile.="?>\n";
    fwrite($file, $xfile);
    fclose($file);

    closetable();
    include ("footer.php");
} else {
    redirect_url("index.php");
}
?>