<?php
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2010 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/headlines.html";
$result = sql_query("select radminhead, radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminhead, $radminsuper) = sql_fetch_row($result);
if (($radminhead!=1) AND ($radminsuper!=1)) {
   Access_Error();
}

function HeadlinesAdmin() {
    global $hlpfile;
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Grands Titres de sites de News");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>
        <td class=\"ongl\">".adm_translate("ID")."</td>
        <td class=\"ongl\">".adm_translate("Nom du site")."</td>
        <td class=\"ongl\">".adm_translate("URL")."</td>
        <td class=\"ongl\" align=\"center\">".adm_translate("Etat")."</td>
        <td class=\"ongl\" align=\"center\">".adm_translate("Fonctions")."</td></tr>\n";
    $result = sql_query("select hid, sitename, url, status from ".$NPDS_Prefix."headlines order by hid");
    while(list($hid, $sitename, $url, $status) = sql_fetch_row($result)) {
        $rowcolor = tablos();
        echo "<tr $rowcolor><td>$hid</td>
        <td><a href=\"$url\" target=\"_blank\" class=\"noir\">$sitename</a></td>
        <td>$url</td>";
        if($status == 1) {
            $status = "<b><span style=\"color: green;\">".adm_translate("Actif(s)")."</span></b>";
        } else {
            $status = "".adm_translate("Inactif(s)")."";
        }
        echo "
        <td align=\"center\">$status</td>
        <td align=\"center\"><a href=\"admin.php?op=HeadlinesEdit&amp;hid=$hid\" class=\"noir\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=HeadlinesDel&amp;hid=$hid&amp;ok=0\" class=\"rouge\">".adm_translate("Effacer")."</a></td></tr>\n";
    }
    echo "</table></form><br />\n";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Ajouter Grands Titres");
    echo "</td></tr></table>\n";
    echo "<br /><form action=\"admin.php\" method=\"post\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"30%\">
    ".adm_translate("Nom du site : ")." </td><td><input class=\"textbox_standard\" type=\"text\" name=\"xsitename\" size=\"35\" maxlength=\"30\" /></td></tr><tr><td>
    ".adm_translate("URL : ")." </td><td><input class=\"textbox\" type=\"text\" name=\"url\" size=\"50\" maxlength=\"100\" /></td></tr><tr><td>
    ".adm_translate("URL pour le fichier RDF/XML : ")." </td><td><input class=\"textbox\" type=\"text\" name=\"headlinesurl\" size=\"50\" maxlength=\"200\" /></td></tr><tr><td>
    ".adm_translate("Etat : ")." </td><td><select class=\"textbox_standard\" name=\"status\">
        <option name=\"status\" value=\"1\">".adm_translate("Actif(s)")."</option>
        <option name=\"status\" value=\"0\" selected=\"selected\">".adm_translate("Inactif(s)")."</option>
        </select></td></tr></table><br />
    <input type=\"hidden\" name=\"op\" value=\"HeadlinesAdd\" />
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\" />
    </form>";
    closetable();
    include("footer.php");
}

function HeadlinesEdit($hid) {
    global $hlpfile;
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin($hlpfile);
    $result = sql_query("select sitename, url, headlinesurl, status from ".$NPDS_Prefix."headlines where hid='$hid'");
    list($xsitename, $url, $headlinesurl, $status) = sql_fetch_row($result);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Editer paramètres Grand Titre");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
    <input type=\"hidden\" name=\"hid\" value=\"$hid\" />
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"30%\">
    ".adm_translate("Nom du site : ")." </td><td><input class=\"textbox_standard\" type=\"text\" name=\"xsitename\" size=\"35\" maxlength=\"30\" value=\"$xsitename\" /></td></tr><tr><td>
    ".adm_translate("URL : ")." </td><td><input class=\"textbox\" type=\"text\" name=\"url\" size=\"50\" maxlength=\"100\" value=\"$url\" /></td></tr><tr><td>
    ".adm_translate("URL pour le fichier RDF/XML : ")." </td><td><input class=\"textbox\" type=\"text\" name=\"headlinesurl\" size=\"50\" maxlength=\"200\" value=\"$headlinesurl\" /></td></tr><tr><td>
    ".adm_translate("Etat : ")." </td><td><select class=\"textbox_standard\" name=\"status\">";
    if ($status == 1) {
       $sel_a = "selected=\"selected\"";
    } else {
       $sel_i = "selected=\"selected\"";
    }
    echo "<option name=\"status\" value=\"1\" $sel_a>".adm_translate("Actif(s)")."</option>
          <option name=\"status\" value=\"0\" $sel_i>".adm_translate("Inactif(s)")."</option>
          </select></td></tr></table><br />
          <input type=\"hidden\" name=\"op\" value=\"HeadlinesSave\" />
          <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\" />
          </form>";
    closetable();
    include("footer.php");
}

function HeadlinesSave($hid, $xsitename, $url, $headlinesurl, $status) {
    global $NPDS_Prefix;

    $xsitename = str_replace(' ','',$xsitename);
    sql_query("update ".$NPDS_Prefix."headlines set sitename='$xsitename', url='$url', headlinesurl='$headlinesurl', status='$status' where hid='$hid'");
    Header("Location: admin.php?op=HeadlinesAdmin");
}

function HeadlinesAdd($xsitename, $url, $headlinesurl, $status) {
    global $NPDS_Prefix;

    $xsitename = str_replace(' ','',$xsitename);
    sql_query("insert into ".$NPDS_Prefix."headlines values (NULL, '$xsitename', '$url', '$headlinesurl', '$status')");
    Header("Location: admin.php?op=HeadlinesAdmin");
}

function HeadlinesDel($hid, $ok=0) {
    global $NPDS_Prefix;

    if ($ok==1) {
       sql_query("delete from ".$NPDS_Prefix."headlines where hid='$hid'");
       Header("Location: admin.php?op=HeadlinesAdmin");
    } else {
       global $hlpfile;
       include("header.php");
       GraphicAdmin($hlpfile);
       opentable();
       echo "<p align=\"center\"><br />";
       echo "<span class=\"rouge\">";
       echo "<b>".adm_translate("Etes-vous sûr de vouloir supprimer cette boîte de Titres ?")."</b><br /><br /></span>";
    }
    echo "[ <a href=\"admin.php?op=HeadlinesDel&amp;hid=$hid&amp;ok=1\" class=\"rouge\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=HeadlinesAdmin\" class=\"noir\">".adm_translate("Non")."</a> ]<br /><br />";
    closetable();
    include("footer.php");
}

switch ($op) {
    case "HeadlinesDel":
         HeadlinesDel($hid, $ok);
         break;

    case "HeadlinesAdd":
         HeadlinesAdd($xsitename, $url, $headlinesurl, $status);
         break;

    case "HeadlinesSave":
         HeadlinesSave($hid, $xsitename, $url, $headlinesurl, $status);
         break;

    case "HeadlinesAdmin":
         HeadlinesAdmin();
         break;

    case "HeadlinesEdit":
         HeadlinesEdit($hid);
         break;
}
?>