<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 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.       */
/************************************************************************/
function Access_Error () {
  if (file_exists("meta/meta.php"))
     include ("meta/meta.php");
  echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
  echo "Access Denied / Acc&egrave;s Refus&eacute;";
  if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
  echo "</span>";
  echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
  echo "</span></p></body></html>";
  die();
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }
global $pdst; $pdst="0";

global $language;
$hlpfile = "manuels/$language/referer.html";
$result = mysql_query("select radminsuper from authors where aid='$aid'");
list($radminsuper) = mysql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}

function hreferer($filter) {
    global $hlpfile;
    include ("header.php");
    GraphicAdmin($hlpfile);
    OpenTable();
    settype($filter,"integer");
    if (!$filter) {$filter=2048;}
    echo "<form action=\"admin.php\" method=\"post\"><input type=\"hidden\" name=\"op\" value=\"hreferer\">";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Sites Référants")." / filtre : <input type=\"text\" class=\"TEXTBOX_STANDARD\" name=\"filter\" size=\"5\" value=\"$filter\">";
    echo "</td></tr></table></form>\n";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
    echo "<tr><td class=\"ONGL\" colspan=\"3\">".adm_translate("Qui parle de nous ?")."</td></tr>";
    $hresult = mysql_query("select rid, url, count(url) as TheCount, substring(url,1,$filter) as filter from referer GROUP BY filter order by rid");
    while(list($rid, $url, $TheCount) = mysql_fetch_row($hresult)) {
        $rowcolor = tablos();
        echo "<tr $rowcolor><td>$rid</TD>";
        echo "<td><a href=\"$url\" target=\"_blank\" class=\"NOIR\">";
        if ($filter!=2048)
           echo "<span class=\"TITRE\">".substr($url,0,$filter)."</span>".substr($url,$filter);
        else
           echo $url;

        echo "</a></td><td align=\"right\">$TheCount</td></tr>";
    }
    echo "</table><br />";
    echo "<p align=\"center\"><a href=\"admin.php?op=delreferer\" class=\"ROUGE\">".adm_translate("Effacer les Référants")."</a>&nbsp;&nbsp;-::-&nbsp;&nbsp;<a href=\"admin.php?op=archreferer&amp;filter=$filter\" class=\"NOIR\">".adm_translate("Archiver les Référants")."</p>";
    closetable();
    include ("footer.php");
}

function delreferer() {
    mysql_query("delete from referer");
    Header("Location: admin.php?op=AdminMain");
}

function archreferer($filter) {
    $file = fopen("logs/referers.log", "w");
    $content = "===================================================\n";
    $content .="Date : ".date("d-m-Y")."-/- NPDS - HTTP Referers\n";
    $content .= "===================================================\n";
    $result=mysql_query("select url from referer");
    while(list($url)= mysql_fetch_row($result)) {
       $content .= "$url\n";
    }
    $content .= "===================================================\n";
    fwrite($file, $content);
    fclose($file);
    Header("Location: admin.php?op=hreferer&filter=$filter");
}

switch($op) {
   case "hreferer":
        hreferer($filter);
        break;

   case "archreferer":
        archreferer($filter);
        break;

   case "delreferer":
        delreferer();
        break;
}
?>