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

function mod_main($title, $description) {
    global $NPDS_Prefix;

    $title = stripslashes(FixQuotes($title));
    $description = stripslashes(FixQuotes($description));
    sql_query("update ".$NPDS_Prefix."reviews_main set title='$title', description='$description'");
    Header("Location: admin.php?op=reviews");
}

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

    include ("header.php");
    GraphicAdmin($hlpfile);
    $resultrm = sql_query("select title, description from ".$NPDS_Prefix."reviews_main");
    list($title, $description) = sql_fetch_row($resultrm);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Titre de la Page des Critiques");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">
          <input type=\"text\" class=\"textbox\" name=\"title\" value=\"$title\" size=\"40\" maxlength=\"100\" /><br /><br />
          ".adm_translate("Description de la Page des Critiques : ")."<br />
          <textarea class=\"textbox\" name=\"description\" rows=\"15\" cols=\"40\">$description</textarea><br /><br />
          <input type=\"hidden\" name=\"op\" value=\"mod_main\" />
          <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\" />
          </form>";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Critiques en attente de validation");
    echo "</td></tr></table>\n";
    $result = sql_query("select * from ".$NPDS_Prefix."reviews_add order by id");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
        while(list($id, $date, $title, $text, $reviewer, $email, $score, $url, $url_title) = sql_fetch_row($result)) {
           $title = stripslashes($title);
           $text = stripslashes($text);
           echo "<form action=\"admin.php\" method=\"post\">";
           echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"2\" width=\"100%\">";
           echo "<tr><td width=\"30%\">".adm_translate("Ajouter la critique N° : ")."</td><td><b>$id</b></td></tr>";
           echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
           echo "<tr><td>".adm_translate("Date :")."</td><td><input class=\"textbox_standard\" type=\"text\" name=\"date\" value=\"$date\" size=\"15\" maxlength=\"10\" /></td></tr>";
           echo "<tr><td>".adm_translate("Nom du produit :")."</td><td><input class=\"textbox\" type=\"text\" name=\"title\" value=\"$title\" size=\"25\" maxlength=\"40\" /></td></tr>";
           echo "<tr><td>".adm_translate("Texte : ")."</td><td><textarea class=\"textbox\" name=\"text\" rows=\"6\" cols=\"40\">$text</textarea></td></tr>";
           echo "<tr><td>".adm_translate("Le critique : ")."</td><td><input class=\"textbox\" type=\"text\" name=\"reviewer\" value=\"$reviewer\" size=\"25\" maxlength=\"20\" /></td></tr>";
           echo "<tr><td>".adm_translate("E-mail : ")."</td><td><input class=\"textbox\" type=\"text\" name=\"email\" value=\"$email\" size=\"40\" maxlength=\"30\" /></td></tr>";
           echo "<tr><td>".adm_translate("Note : ")."</td><td><input class=\"textbox_standard\" type=\"text\" name=\"score\" value=\"$score\" size=\"3\" maxlength=\"2\" /></td></tr>";
           if ($url != "") {
              echo "<tr><td>".adm_translate("Liens relatifs : ")."</td><td><input class=\"textbox\" type=\"text\" name=\"url\" value=\"$url\" size=\"25\" maxlength=\"100\" /></td></tr>";
              echo "<tr><td>".adm_translate("Titre du lien : ")."</td><td><input class=\"textbox\" type=\"text\" name=\"url_title\" value=\"$url_title\" size=\"25\" maxlength=\"50\" /></td></tr>";
           }
           echo "<tr><td>".adm_translate("Image de garde : ")."</td><td><input class=\"textbox\" type=\"text\" name=\"cover\" size=\"25\" maxlength=\"100\" /><br /><i>150*150 pixel => images/covers</i></td></tr></table>";
           echo "<input type=\"hidden\" name=\"op\" value=\"add_review\"><input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter cette critique")."\" /> - [ <a href=\"admin.php?op=deleteNotice&amp;id=$id&amp;op_back=reviews\" class=\"rouge\">".adm_translate("Supprimer cette Critique")."</a> ]</form><br />";
        }
    } else {
        echo "<br />".adm_translate("Aucune critique à ajouter")."<br />";
    }
    echo "<hr noshade=\"noshade\" class=\"ongl\" /><p align=\"center\"><a href=\"reviews.php?op=write_review\" class=\"noir\">".adm_translate("Cliquer ici pour proposer une Critique.")."</a></p><hr noshade class=\"ongl\">";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Effacer / Modifier une Critique");
    echo "</td></tr></table>\n";
    echo "<br />";
    echo adm_translate("Vous pouvez simplement Effacer / Modifier les Critiques en naviguant sur")." <a href=\"reviews.php\" class=\"noir\">reviews.php</a> ".adm_translate("en tant qu'Administrateur.")."<br />";
    closetable();
    sql_free_result($result);
    include ("footer.php");
}

function add_review($id, $date, $title, $text, $reviewer, $email, $score, $cover, $url, $url_title) {
    global $NPDS_Prefix;

    $title = stripslashes(FixQuotes($title));
    $text = stripslashes(FixQuotes($text));
    $reviewer = stripslashes(FixQuotes($reviewer));
    $email = stripslashes(FixQuotes($email));
    sql_query("insert into ".$NPDS_Prefix."reviews values (NULL, '$date', '$title', '$text', '$reviewer', '$email', '$score', '$cover', '$url', '$url_title', '1')");
    sql_query("delete from ".$NPDS_Prefix."reviews_add WHERE id = '$id'");
    Header("Location: admin.php?op=reviews");
}

switch ($op){
    case "reviews":
         reviews();
         break;

    case "add_review":
         add_review($id, $date, $title, $text, $reviewer, $email, $score, $cover, $url, $url_title);
         break;

    case "mod_main":
         mod_main($title, $description);
         break;
}
?>