<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: adminfaq.php,v 1.6.2.6 2004/08/15 12:58:04 kirilt Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* ---                                                                  */
/* Based on PHP-Nuke Add-On                                             */
/* Copyright (c) 2001 by Richard Tirtadji AKA King Richard              */
/*                       (rtirtadji@hotmail.com)                        */
/*                       Hutdik Hermawan AKA hotFix                     */
/*                       (hutdik76@hotmail.com)                         */
/* http://www.nukeaddon.com                                             */
/* ---                                                                  */
/*                                                                      */
/* 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.       */
/************************************************************************/

checkAccess( 'modules', array( 'faq' ) );

$hlpfile = getHelpFile("faqs.html");

/*********************************************************/
/* Faq Admin Function                                    */
/*********************************************************/

function FaqAdmin() {
    global $hlpfile, $admin, $mpnTables,$phpEx;
    include ("config.$phpEx");
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "
    <center><font size=4><b>".translate("Faq")."</b></font></center>
    <form action=admin.$phpEx method=post>
    <center><table border=1 width=100%><tr>
    <th>".translate("ID")."</th>
    <th>".translate("Categories")."</th><th>".translate("Functions")."</th></tr>";

    $result = mysql_query("select id_cat, categories from ".$mpnTables['faqcategories']." order by id_cat");
    while(list($id_cat, $categories) = mysql_fetch_row($result)) {
    echo "
    <td>$id_cat</td>
    <td>" . stripslashes( $categories ) . "</td>
    <td><a href=admin.$phpEx?op=FaqCatGo&id_cat=$id_cat>" .translate("Question & Answer")."</a> | <a href=admin.$phpEx?op=FaqCatEdit&id_cat=$id_cat>".translate("Edit")."</a> | <a href=admin.$phpEx?op=FaqCatDel&id_cat=$id_cat&ok=0>".translate("Delete")."</a></td><tr>";
    }
    echo "</form></td></tr></table>
    <br><br>
    </center><font size=4><b>".translate("Add Categories")."</b><br><br>
    <font size=2>
    <form action=admin.$phpEx method=post>
    <table border=0 width=100%><tr><td>
    ".translate("Categories:")." </td><td><input type=text name=categories size=31></td></tr><tr><td>
    </td></tr></table>
    <input type=hidden name=op value=FaqCatAdd>
    <input class='button' type=submit value=".translate("Add").">
    </form>
    </td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}

function FaqCatGo($id_cat) {
    global $hlpfile, $admin, $mpnTables,$phpEx;
    include ("config.$phpEx");
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);

    $result = mysql_query("select categories from ".$mpnTables['faqcategories']." where id_cat='$id_cat'");
    list($categories) = mysql_fetch_row($result);
    $categories = stripslashes( $categories );

    $result = mysql_query("select id, question, answer from ".$mpnTables['faqanswer']." where id_cat='$id_cat' order by id");

    if ( mysql_num_rows( $result ) > 0 )
    {
        echo "
        <center><font size=4><b>".translate("Question and Answers In Category")."</b><br /> $categories</font></center><br /><br />

         <table border=1 width=100%><tr>
        <th>".translate("Question")."</th><th>".translate("Functions")."</th></tr>";

        while(list($id, $question, $answer) = mysql_fetch_row($result))
        {
            $question = stripslashes( $question );
            $answer = stripslashes( $answer );

			//2004-03-01 - AvW Replaced 'Q' and 'A' with 'Question' and 'Answer' for proper translation of the word A.
        echo "
        <tr><td>" . translate( 'Question' ) . ": $question</td><td rowspan=2><a href=admin.$phpEx?op=FaqCatGoEdit&id=$id>".translate("Edit")."</a> | <a href=admin.$phpEx?op=FaqCatGoDel&id=$id&ok=0>".translate("Delete")."</a></td></tr>
        <tr><td><p>" . translate( 'Answer' ) . ": $answer</p></td></tr>";
        }
        echo "</td></tr></table>\n";

        echo "<br /><br /><br />\n";
    }


    OpenTable();

    echo "<br><br>
    </center><font size=4><b>".translate("Add Question")."</b><br><br>
    <font size=2>

    <form action=admin.$phpEx method=post>
    <table border=0 width=100%><tr><td>
    ".translate("Question:")." </td><td><input type=text name=question size=31></td></tr><tr><td>
    ".translate("Answer:")." </td><td><textarea name=answer cols=60 rows=5></textarea></td></tr><tr><td>
    </td></tr></table>\n";

    // Kiril: New Sanitizer

        addFormatOption();

        echo "<input type='hidden' name='clickit_form' value='answer' />\n";
        echo "<input type='hidden' name='stripit_form' value='question' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer


    echo "<input type=hidden name=id_cat value=\"$id_cat\">
    <input type=hidden name=op value=FaqCatGoAdd>
    <input class='button' type=submit value=".translate("Add").">
    </form>";
    CloseTable();
    include("footer.$phpEx");
}

function FaqCatEdit($id_cat)
{
    global $hlpfile, $admin, $mpnTables,$phpEx;
    include ("config.$phpEx");
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);

    $result = mysql_query("select categories from ".$mpnTables['faqcategories']." where id_cat='$id_cat'");
    list($categories) = mysql_fetch_row($result);

    $categories = stripslashes( $categories );

    OpenTable();
    echo "
    <center><font size=4><b>".translate("Edit Categories")."</b></font></center>
    <form action=admin.$phpEx method=post>
    <input type=hidden name=id_cat value=$id_cat>
    <table border=0 width=100%><tr><td>
    ".translate("Categories:")." </td><td><input type=text name=categories size=31 value=\"$categories\"></td></tr><tr><td>
    </td></tr></table>\n";

    // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='categories' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type=hidden name=op value=FaqCatSave>
    <input class='button' type=submit value=".translate("Save Changes").">
    </form>
    </td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}

function FaqCatGoEdit($id) {
    global $hlpfile, $admin, $mpnTables,$phpEx;
    include ("config.$phpEx");
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);


    $result = mysql_query("select question, answer, id_cat from ".$mpnTables['faqanswer']." where id='$id'");

    list($question, $answer, $id_cat) = mysql_fetch_row($result);

    $question = stripslashes( $question );
    $answer = stripslashes( $answer );


    $result = mysql_query("select categories from ".$mpnTables['faqcategories']." where id_cat='$id_cat'");

    list($categories) = mysql_fetch_row($result);
    $categories = stripslashes( $categories );

    echo "<center><font size=4><b>".translate("Edit Question and Answer In Category")."</b><br /> $categories</font></center>\n";

    echo "<br /><br /><br />\n";

    OpenTable();

    echo "<form action=admin.$phpEx method=post>
    <input type=hidden name=id value=$id>
    <table border=0 width=100%><tr><td>
    ".translate("Question:")." </td><td><input type=text name=question size=31 value=\"$question\"></td></tr><tr><td>
    ".translate("Answer:")." </td><td><textarea name=answer cols=60 rows=5>$answer</textarea></td></tr><tr><td>
    </td></tr></table>\n";

    // Kiril: New Sanitizer

// 2004-03-01 - AvW added format option to the faq edit dialog
        addFormatOption();
        echo "<input type='hidden' name='clickit_form' value='answer' />\n";
// 2004-03-01 - AvW - end of changes

        echo "<input type='hidden' name='stripit_form' value='question|answer' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer


    echo "<input type=hidden name=op value=FaqCatGoSave>
    <input class='button' type=submit value=".translate("Save Changes").">
    </form>
    </td></tr></table></td></tr></table>";
    include("footer.$phpEx");
}


function FaqCatSave($id_cat, $categories)
{

    global $mpnTables,$phpEx;

    //$categories = stripslashes(FixQuotes($categories));

    mysql_query("update ".$mpnTables['faqcategories']." set categories='$categories' where id_cat='$id_cat'");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqAdmin' );

}

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

   // $question = stripslashes(FixQuotes($question));
   // $answer = stripslashes(FixQuotes($answer));

    mysql_query("update ".$mpnTables['faqanswer']." set question='$question', answer='$answer' where id='$id'");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqAdmin' );

}

function FaqCatAdd($categories)
{
    global $mpnTables,$phpEx;

    //$categories = stripslashes(FixQuotes($categories));

    mysql_query("insert into ".$mpnTables['faqcategories']." values (NULL, '$categories')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqAdmin' );
}

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

    //$question = stripslashes(FixQuotes($question));
    //$answer = stripslashes(FixQuotes($answer));

    mysql_query("insert into ".$mpnTables['faqanswer']." values (NULL, '$id_cat', '$question', '$answer')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqCatGo&id_cat=' . $id_cat );

}

function FaqCatDel($id_cat, $ok=0)
{
    global $mpnTables,$phpEx;
    if($ok==1) {
    mysql_query("delete from ".$mpnTables['faqcategories']." where id_cat=$id_cat");
    mysql_query("delete from ".$mpnTables['faqanswer']." where id_cat=$id_cat");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqAdmin' );


    } else {
    include("header.$phpEx");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this Faq and all its question?")."</b><br><br><font color=Black>";
    }
    echo "[ <a href=admin.$phpEx?op=FaqCatDel&id_cat=$id_cat&ok=1>".translate("Yes")."</a> | <a href=admin.$phpEx?op=FaqAdmin>".translate("No")."</a> ]<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");
}

function FaqCatGoDel($id, $ok=0) {
    global $mpnTables,$phpEx;
    if($ok==1) {
    mysql_query("delete from ".$mpnTables['faqanswer']." where id=$id");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=FaqAdmin' );


    } else {
    include("header.$phpEx");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this Question?")."</b><br><br><font color=Black>";
    }
    echo "[ <a href=admin.$phpEx?op=FaqCatGoDel&id=$id&ok=1>".translate("Yes")."</a> | <a href=admin.$phpEx?op=FaqAdmin>".translate("No")."</a> ]<br><br>";
    CloseTable();
    include("footer.$phpEx");
}

?>
