<?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/faqs.html";
$result = sql_query("select radminfaq, radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminfaq, $radminsuper) = sql_fetch_row($result);
if (($radminfaq!=1) and ($radminsuper!=1)) {
   Access_Error();
}

function FaqAdmin() {
    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("Faq");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr>
        <td class=\"ongl\">".adm_translate("ID")."</td>
        <td class=\"ongl\">".adm_translate("Catégories")."</td><td class=\"ongl\">&nbsp;</td></tr>";
    $result = sql_query("select id_cat, categories from ".$NPDS_Prefix."faqcategories order by id_cat ASC");
    while(list($id_cat, $categories) = sql_fetch_row($result)) {
        $rowcolor = tablos();
        echo "<tr $rowcolor>
        <td>$id_cat</td>
        <td>".aff_langue($categories)."</td>
        <td align=\"right\"><a href=\"admin.php?op=FaqCatGo&amp;id_cat=$id_cat\" class=\"noir\">".adm_translate("Questions & Réponses")."</a> | <a href=\"admin.php?op=FaqCatEdit&amp;id_cat=$id_cat\" class=\"noir\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=FaqCatDel&amp;id_cat=$id_cat&amp;ok=0\" class=\"rouge\">".adm_translate("Effacer")."</a></td><tr>";
    }
    echo "</table>";
    echo "</form>";
    echo "<br />";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Ajouter des Catégories");
    echo "</td></tr></table>\n
    <form action=\"admin.php\" method=\"post\">
    ".adm_translate("Catégories :")." <input class=\"textbox_standard\" type=\"text\" name=\"categories\" size=\"65\" maxlength=\"255\" />
    <input type=\"hidden\" name=\"op\" value=\"FaqCatAdd\" />
     - <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\" />
    </form>";
    closetable();
    include("footer.php");
}

function FaqCatGo($id_cat) {
    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("Ajouter une question");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">
    <b>".adm_translate("Question : ")."</b><br /><input class=\"textbox\" type=\"text\" name=\"question\" size=\"70\" maxlength=\"255\" /><br /><br />
    <b>".adm_translate("Réponse : ")."</b><br /><textarea class=\"textbox\" name=\"answer\" cols=\"70\" rows=\"15\" style=\"width: 100%;\"></textarea>";
    echo aff_editeur("answer","false");
    echo "<br /><br />";
    echo "<input type=\"hidden\" name=\"id_cat\" value=\"$id_cat\" />
    <input type=\"hidden\" name=\"op\" value=\"FaqCatGoAdd\" />
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\" />&nbsp;&nbsp;[ <a href=\"admin.php?op=FaqAdmin\" class=\"noir\">".adm_translate("Retour en arrière")."</a> ]
    </form>";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Questions & Réponses");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr>
    <td class=\"ongl\">".adm_translate("Question : ")." </td><td class=\"ongl\">&nbsp;</td></tr>";
    $result = sql_query("select id, question, answer from ".$NPDS_Prefix."faqanswer where id_cat='$id_cat' order by id");
    while(list($id, $question, $answer) = sql_fetch_row($result)) {
        $rowcolor = tablos();
        echo "<tr $rowcolor><td>".aff_langue($question)."</td><td width=\"10%\" rowspan=\"2\" align=\"center\"><a href=\"admin.php?op=FaqCatGoEdit&amp;id=$id\" class=\"noir\">".adm_translate("Editer")."</a><br /><a href=\"admin.php?op=FaqCatGoDel&amp;id=$id&amp;ok=0\" class=\"rouge\">".adm_translate("Effacer")."</a></td></tr>
        <tr $rowcolor><td class=\"noir\">";
        $answer=aff_code(aff_langue($answer));
        echo meta_lang($answer);
        echo "</td></tr>";
    }
    echo "</table></form>";
    closetable();
    include("footer.php");
}

function FaqCatEdit($id_cat) {
    global $hlpfile;
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin($hlpfile);
    $result = sql_query("select categories from ".$NPDS_Prefix."faqcategories where id_cat='$id_cat'");
    list($categories) = sql_fetch_row($result);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Editer les Catégories");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
    <input type=\"hidden\" name=\"old_id_cat\" value=\"$id_cat\" />
    ID : <input class=\"textbox_standard\" type=\"text\" name=\"id_cat\" value=\"$id_cat\" size=\"4\" />&nbsp;&nbsp;
    ".adm_translate("Catégories :")." <input class=\"textbox_standard\" type=\"text\" name=\"categories\" size=\"65\" value=\"$categories\" />\n";
    echo " - <input type=\"hidden\" name=\"op\" value=\"FaqCatSave\" />
    <input class=\"bouton_standard\" type=\"submit\" value=".adm_translate("Sauver les modifications")." />";
    echo "</form>";
    closetable();
    include("footer.php");
}

function FaqCatGoEdit($id) {
    global $hlpfile;
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin($hlpfile);
    $result = sql_query("select question, answer, id_cat from ".$NPDS_Prefix."faqanswer where id='$id'");
    list($question, $answer, $id_cat) = sql_fetch_row($result);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Editer Question & Réponse");
    echo "</td></tr></table>\n";

    $rowcolor = tablos();
    echo "<p align=\"center\"><table border=\"0\" width=\"90%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\">";
    echo "<tr $rowcolor><td valign=\"top\">".aff_local_langue("<b>".adm_translate("Langue de Prévisualisation")."</b> : ","","local_user_language")."</td></tr>";
    global $local_user_language;
    echo "<tr class=\"lignb\"><td><b class=\"header\">&nbsp;".preview_local_langue($local_user_language, $question)."&nbsp;</b><p align=\"justify\">";
    $answer=aff_code($answer);
    echo meta_lang(preview_local_langue($local_user_language, $answer))."</p>";
    echo "</td></tr></table></td></tr></table></p><br />";

    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">
    <input type=\"hidden\" name=\"id\" value=\"$id\">";
    echo "<b>".adm_translate("Question : ")."</b><br /><input class=\"textbox\" type=\"text\" name=\"question\" size=\"70\"  maxlength=\"255\" value=\"$question\" /><br /><br />
    <b>".adm_translate("Réponse : ")."</b><br /><textarea class=\"textbox\" name=\"answer\" cols=\"70\" rows=\"15\" style=\"width: 100%;\">$answer</textarea>";
    echo aff_editeur("answer","false");
    echo "<br /><br />";
    echo "<input type=\"hidden\" name=\"op\" value=\"FaqCatGoSave\" />
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\" />&nbsp;&nbsp;[ <a href=\"admin.php?op=FaqCatGo&amp;id_cat=$id_cat\" class=\"noir\">".adm_translate("Retour en arrière")."</a> ]
    </form>";
    closetable();
    include("footer.php");
}

function FaqCatSave($old_id_cat, $id_cat, $categories) {
    global $NPDS_Prefix;

    $categories = stripslashes(FixQuotes($categories));
    if ($old_id_cat!=$id_cat) {
       sql_query("update ".$NPDS_Prefix."faqanswer set id_cat='$id_cat' where id_cat='$old_id_cat'");
    }
    sql_query("update ".$NPDS_Prefix."faqcategories set id_cat='$id_cat', categories='$categories' where id_cat='$old_id_cat'");
    Header("Location: admin.php?op=FaqAdmin");
}

function FaqCatGoSave($id, $question, $answer) {
    global $NPDS_Prefix;

    $question = stripslashes(FixQuotes($question));
    $answer = stripslashes(FixQuotes($answer));
    sql_query("update ".$NPDS_Prefix."faqanswer set question='$question', answer='$answer' where id='$id'");
    Header("Location: admin.php?op=FaqCatGoEdit&id=$id");
}

function FaqCatAdd($categories) {
    global $NPDS_Prefix;

    $categories = stripslashes(FixQuotes($categories));
    sql_query("insert into ".$NPDS_Prefix."faqcategories values (NULL, '$categories')");
    Header("Location: admin.php?op=FaqAdmin");
}

function FaqCatGoAdd($id_cat, $question, $answer) {
    global $NPDS_Prefix;

    $question = stripslashes(FixQuotes($question));
    $answer = stripslashes(FixQuotes($answer));
    sql_query("insert into ".$NPDS_Prefix."faqanswer values (NULL, '$id_cat', '$question', '$answer')");
    Header("Location: admin.php?op=FaqCatGo&id_cat=$id_cat");
}

function FaqCatDel($id_cat, $ok=0) {
    global $NPDS_Prefix;

    if($ok==1) {
        sql_query("delete from ".$NPDS_Prefix."faqcategories where id_cat='$id_cat'");
        sql_query("delete from ".$NPDS_Prefix."faqanswer where id_cat='$id_cat'");
        Header("Location: admin.php?op=FaqAdmin");
    } else {
        global $hlpfile;
        include("header.php");
        GraphicAdmin($hlpfile);
        opentable();
        echo "<p align=\"center\"><br />";
        echo "<span class=\"rouge\"><b>".adm_translate("ATTENTION : êtes-vous sûr de vouloir effacer cette FAQ et toutes ses questions ?")."</b></span><br /><br />";
    }
    echo "[ <a href=\"admin.php?op=FaqCatDel&amp;id_cat=$id_cat&amp;ok=1\" class=\"rouge\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=FaqAdmin\" class=\"noir\">".adm_translate("Non")."</a> ]<br /><br /></p>";
    closetable();
    include("footer.php");
}

function FaqCatGoDel($id, $ok=0) {
    global $NPDS_Prefix;

    if($ok==1) {
        sql_query("delete from ".$NPDS_Prefix."faqanswer where id='$id'");
        Header("Location: admin.php?op=FaqAdmin");
    } else {
        global $hlpfile;
        include("header.php");
        GraphicAdmin($hlpfile);
        opentable();
        echo "<p align=\"center\"><br />";
        echo "<span class=\"rouge\"><b>".adm_translate("ATTENTION : êtes-vous sûr de vouloir effacer cette question ?")."</b></span><br /><br />";
    }
    echo "[ <a href=\"admin.php?op=FaqCatGoDel&amp;id=$id&amp;ok=1\" class=\"rouge\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=FaqAdmin\" class=\"noir\">".adm_translate("Non")."</a> ]<br /><br /></p>";
    closetable();
    include("footer.php");
}
?>