<?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.       */
/************************************************************************/
function Access_Error () {
  include("admin/die.php");
}
if (!stristr($_SERVER['PHP_SELF'],"admin.php")) { Access_Error(); }

global $language;
$hlpfile = "manuels/$language/referer.html";
$result = sql_query("select radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminsuper) = sql_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érents")." / 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 = sql_query("select url, count(url) as TheCount, substring(url,1,$filter) as filter from ".$NPDS_Prefix."referer GROUP BY filter order by TheCount DESC");
    while(list($url, $TheCount) = sql_fetch_row($hresult)) {
        $rowcolor = tablos();
        echo "<tr><td><a href=\"".$url."\" target=\"_blank\" class=\"noir\">";
        if ($filter!=2048)
           echo "<span class=\"header\">".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")."</a></p>";
    closetable();
    include ("footer.php");
}

function delreferer() {
    global $NPDS_Prefix;

    sql_query("delete from ".$NPDS_Prefix."referer");
    Header("Location: admin.php?op=AdminMain");
}

function archreferer($filter) {
    global $NPDS_Prefix;

    $file = fopen("slogs/referers.log", "w");
    $content = "===================================================\n";
    $content .="Date : ".date("d-m-Y")."-/- NPDS - HTTP Referers\n";
    $content .= "===================================================\n";
    $result=sql_query("select url from ".$NPDS_Prefix."referer");
    while(list($url)= sql_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;
}
?>