<?php
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2013 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(); }
include ("publication.php");

$result = sql_query("select radminarticle, radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminarticle, $radminsuper) = sql_fetch_row($result);
if (($radminarticle!=1) and ($radminsuper!=1)) {
   Access_Error();
}

function puthome($ihome) {
    echo "<br /><b>".adm_translate("Publier dans la racine ?")."</b>&nbsp;&nbsp;";
    $sel1 = "checked=\"checked\"";
    $sel2 = "";
    if ($ihome == 1) {
        $sel1 = "";
        $sel2 = "checked=\"checked\"";
    }
    echo "<input type=\"radio\" name=\"ihome\" value=\"0\" $sel1 />".adm_translate("Oui")."&nbsp;";
    echo "<input type=\"radio\" name=\"ihome\" value=\"1\" $sel2 />".adm_translate("Non");
    echo "&nbsp;&nbsp; <span class=\"noir\">[ ".adm_translate("Ne s'applique que si la catégorie : <b>'Articles'</b> n'est pas sélectionnée.")." ]</span><br /><br />";

    $sel1 = "";
    $sel2 = "checked=\"checked\"";
    echo "<span class=\"rouge\"><b>".adm_translate("Seulement aux membres")."</b></span> :";
    if ($ihome<0) {
       $sel1 = "checked=\"checked\"";
       $sel2 = "";
    }
    if (($ihome>1) and ($ihome<=127)) {
       $Mmembers=$ihome;
       $sel1 = "checked=\"checked\"";
       $sel2 = "";
    }
    echo "<input type=\"radio\" name=\"members\" value=\"1\" $sel1 />".adm_translate("Oui")."&nbsp; /
    ".adm_translate("Groupe")." : ";
    // ---- Groupes
    $mX=liste_group();
    $tmp_groupe="";
    while (list($groupe_id, $groupe_name)=each($mX)) {
       if ($groupe_id=="0") {$groupe_id="";}
       if ($Mmembers==$groupe_id) {$sel3="selected=\"selected\"";} else {$sel3="";}
       $tmp_groupe.="<option value=\"$groupe_id\" $sel3>$groupe_name</option>\n";
      $nbg++;
    }
    echo "<select class=\"textbox_standard\" name=\"Mmembers\">".$tmp_groupe."</select>&nbsp;";
    // ---- Groupes
    echo "<input type=\"radio\" name=\"members\" value=\"0\" $sel2 />".adm_translate("Non");
}

function SelectCategory($cat) {
    global $NPDS_Prefix;

    $selcat = sql_query("select catid, title from ".$NPDS_Prefix."stories_cat");
    echo " <b>".adm_translate("Catégorie")."</b> ";
    echo "<select class=\"textbox_standard\" name=\"catid\">";
    if ($cat == 0) {
       $sel = "selected=\"selected\"";
    } else {
       $sel = "";
    }
    echo "<option name=\"catid\" value=\"0\" $sel>".adm_translate("Articles")."</option>";
    while(list($catidX, $title) = sql_fetch_row($selcat)) {
       if ($catidX==$cat) {
          $sel = "selected";
       } else {
          $sel = "";
       }
       echo "<option name=\"catid\" value=\"$catidX\" $sel>".aff_langue($title)."</option>";
    }
    echo "</select> [ <a href=\"admin.php?op=AddCategory\" class=\"noir\">".adm_translate("Ajouter")."</a> | <a href=\"admin.php?op=EditCategory\" class=\"noir\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=DelCategory\" class=\"rouge\">".adm_translate("Effacer")."</a> ]";
}

// CATEGORIES
function AddCategory () {
    include ("header.php");
    GraphicAdmin("");
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Ajouter une nouvelle Catégorie");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\">";
    echo "<b>".adm_translate("Nom : ")."</b> ";
    echo "<input class=\"textbox_standard\" type=\"text\" name=\"title\" size=\"50\" maxlength=\"255\" /> - ";
    echo "<input type=\"hidden\" name=\"op\" value=\"SaveCategory\" />";
    echo "<input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\" />";
    echo "</form>";
    closetable();
    include("footer.php");
}
function SaveCategory($title) {
    global $NPDS_Prefix;

    $title = preg_replace('#"#', '', $title);
    $check = sql_num_rows(sql_query("select catid from ".$NPDS_Prefix."stories_cat where title='$title'"));
    if ($check) {
        $what1 = adm_translate("Cette Catégorie existe déjà !");
        $what2 = "[ <a href=\"javascript:history.go(-1)\" class=\"noir\">".adm_translate("Retour en arrière, pour changer le Nom")."</a> ]";
    } else {
        $what1 = adm_translate("Nouvelle Catégorie ajoutée");
        $what2 = "[ <a href=\"admin.php\" class=\"noir\">".adm_translate("Retour à l'index d'administration")."</a> ]";
        $result = sql_query("insert into ".$NPDS_Prefix."stories_cat values (NULL, '$title', '0')");
    }
    include ("header.php");
    GraphicAdmin("");
    opentable();
    echo "<p align=\"center\"><b>$what1</b><br /><br />";
    echo "$what2</p><br />";
    closetable();
    include("footer.php");
}

function EditCategory($catid) {
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin("");
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo "".adm_translate("Edition des Catégories")."";
    echo "</td></tr></table>\n";
    $result = sql_query("select title from ".$NPDS_Prefix."stories_cat where catid='$catid'");
    list($title) = sql_fetch_row($result);
    if (!$catid) {
        $selcat = sql_query("select catid, title from ".$NPDS_Prefix."stories_cat");
        echo "<form action=\"admin.php\" method=\"post\"><b>";
        echo adm_translate("Sélectionner une Catégorie")." : </b>";
        echo "<select class=\"textbox_standard\" name=\"catid\">";
        echo "<option name=\"catid\" value=\"0\">".adm_translate("Articles")."</option>";
        while(list($catid, $title) = sql_fetch_row($selcat)) {
            echo "<option name=\"catid\" value=\"$catid\">".aff_langue($title)."</option>";
        }
        echo "</select>";
        echo "<input type=\"hidden\" name=\"op\" value=\"EditCategory\" />";
        echo " - <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Editer")."\" />";
        echo "</form>";
    } else {
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<b>".adm_translate("Nom : ")."</b> ";
        echo "<input class=\"textbox_standard\" type=\"text\" name=\"title\" size=\"50\" maxlength=\"255\" value=\"$title\" /> ";
        echo "<input type=\"hidden\" name=\"catid\" value=\"$catid\" />";
        echo "<input type=\"hidden\" name=\"op\" value=\"SaveEditCategory\" />";
        echo " - <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\" />";
        echo "</form>";
    }
    closetable();
    include("footer.php");
}
function SaveEditCategory($catid, $title) {
    global $NPDS_Prefix;

    $title = preg_replace('#"#', '', $title);
    $check = sql_num_rows(sql_query("select catid from ".$NPDS_Prefix."stories_cat where title='$title'"));
    if ($check) {
        $what1 = adm_translate("Cette Catégorie existe déjà !");
        $what2 = "[ <a href=\"javascript:history.go(-2)\" class=\"noir\">".adm_translate("Retour en arrière, pour changer le Nom")."</a> ]";
    } else {
        $what1 = adm_translate("Catégorie sauvegardée");
        $what2 = "[ <a href=\"admin.php\" class=\"noir\">".adm_translate("Retour à l'index d'administration")."</a> ]";
        $result = sql_query("update ".$NPDS_Prefix."stories_cat set title='$title' where catid='$catid'");
        global $aid; Ecr_Log("security", "SaveEditCategory($catid, $title) by AID : $aid", "");
    }
    include ("header.php");
    GraphicAdmin("");
    opentable();
    echo "<p align=\"center\"><b>$what1</b><br /><br />";
    echo "$what2</p><br />";
    closetable();
    include("footer.php");
}

function DelCategory($cat) {
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin("");
    opentable();
    $result = sql_query("select title from ".$NPDS_Prefix."stories_cat where catid='$cat'");
    list($title) = sql_fetch_row($result);
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Supprimer une Catégorie");
    echo "</td></tr></table>\n";
    if (!$cat) {
        $selcat = sql_query("select catid, title from ".$NPDS_Prefix."stories_cat");
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<b>".adm_translate("Sélectionner une Catégorie à supprimer")." : </b>";
        echo "<select class=\"textbox_standard\" name=\"cat\">";
        while(list($catid, $title) = sql_fetch_row($selcat)) {
            echo "<option name=\"cat\" value=\"$catid\">".aff_langue($title)."</option>";
        }
        echo "</select>";
        echo "<input type=\"hidden\" name=\"op\" value=\"DelCategory\" />";
        echo " - <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Effacer")."\" />";
        echo "</form>";
    } else {
        $result2 = sql_query("select * from ".$NPDS_Prefix."stories where catid='$cat'");
        $numrows = sql_num_rows($result2);
        if ($numrows == 0) {
            sql_query("delete from ".$NPDS_Prefix."stories_cat where catid='$cat'");
            global $aid; Ecr_Log("security", "DelCategory($cat) by AID : $aid", "");
            echo "<p align=\"center\"<br /><b><span class=\"noir\">".adm_translate("Suppression effectuée")."</span></b></p><br />";
        } else {
            echo "<span class=\"noir\"><br /><b>".adm_translate("Attention : ")."</b> ".adm_translate("la Catégorie")." <b>$title</b> ".adm_translate("a")." <b>$numrows</b> ".adm_translate("Articles !")."<br /><br />";
            echo adm_translate("Vous pouvez supprimer la Catégorie, les Articles et Commentaires")." ";
            echo adm_translate("ou les affecter à une autre Catégorie.")."<br /><br /></span>";
            echo "<p align=\"center\" class=\"noir\">".adm_translate("Que voulez-vous faire ?")." - ";
            echo "<b>[ <a href=\"admin.php?op=YesDelCategory&amp;catid=$cat\" class=\"rouge\">".adm_translate("Tout supprimer")."</a> | ";
            echo "<a href=\"admin.php?op=NoMoveCategory&amp;catid=$cat\" class=\"noir\">".adm_translate("Affecter à une autre Catégorie")."</a> ]</b></p>";
        }
    }
    closetable();
    include("footer.php");
}
function YesDelCategory($catid) {
    global $NPDS_Prefix;

    sql_query("delete from ".$NPDS_Prefix."stories_cat where catid='$catid'");
    $result = sql_query("select sid from ".$NPDS_Prefix."stories where catid='$catid'");
    while(list($sid) = sql_fetch_row($result)) {
        sql_query("delete from ".$NPDS_Prefix."stories where catid='$catid'");
        // commentaires
        if (file_exists("modules/comments/article.conf.php")) {
            include ("modules/comments/article.conf.php");
            sql_query("DELETE FROM ".$NPDS_Prefix."posts WHERE forum_id='$forum' and topic_id='$topic'");
        }
    }
    global $aid; Ecr_Log("security", "YesDelCategory($catid) by AID : $aid", "");
    Header("Location: admin.php");
}
function NoMoveCategory($catid, $newcat) {
    global $NPDS_Prefix;

    include ("header.php");
    GraphicAdmin("");
    opentable();
    $result = sql_query("select title from ".$NPDS_Prefix."stories_cat where catid='$catid'");
    list($title) = sql_fetch_row($result);
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Affectation d'Articles vers une nouvelle Catégorie");
    echo "</td></tr></table>\n";
    if (!$newcat) {
        echo "<br />".adm_translate("Tous les Articles dans")." <b>".aff_langue($title)."</b> ".adm_translate("seront affectés à")."<br /><br />";
        $selcat = sql_query("select catid, title from ".$NPDS_Prefix."stories_cat");
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<b>".adm_translate("Sélectionner la nouvelle Catégorie : ")."</b> ";
        echo "<select class=\"textbox_standard\" name=\"newcat\">";
        echo "<option name=\"newcat\" value=\"0\">".adm_translate("Articles")."</option>";
        while(list($newcat, $title) = sql_fetch_row($selcat)) {
                echo "<option name=\"newcat\" value=\"$newcat\">".aff_langue($title)."</option>";
        }
        echo "</select>";
        echo "<input type=\"hidden\" name=\"catid\" value=\"$catid\" />";
        echo "<input type=\"hidden\" name=\"op\" value=\"NoMoveCategory\" />";
        echo " - <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Affectation")."\" />";
        echo "</form>";
    } else {
        $resultm = sql_query("select sid from ".$NPDS_Prefix."stories where catid='$catid'");
        while(list($sid) = sql_fetch_row($resultm)) {
            sql_query("update ".$NPDS_Prefix."stories set catid='$newcat' where sid='$sid'");
        }
        sql_query("delete from ".$NPDS_Prefix."stories_cat where catid='$catid'");
        global $aid; Ecr_Log("security", "NoMoveCategory($catid, $newcat) by AID : $aid", "");
        echo "<p align=\"center\"><br /><b class=\"noir\">".adm_translate("La ré-affectation est terminée !")."</b></p><br />";
    }
    closetable();
    include("footer.php");
}

// NEWS
function displayStory ($qid) {
    global $NPDS_Prefix;
    global $tipath, $hlpfile, $language, $aid, $radminsuper;
    $hlpfile = "manuels/$language/newarticle.html";

    $result = sql_query("SELECT qid, uid, uname, subject, story, bodytext, topic, date_debval,date_finval,auto_epur FROM ".$NPDS_Prefix."queue where qid='$qid'");
    list($qid, $uid, $uname, $subject, $story, $bodytext, $topic, $date_debval,$date_finval,$epur) = sql_fetch_row($result);
    sql_free_result($result);
    $subject = stripslashes($subject);
    $story = stripslashes($story);
    $bodytext = stripslashes($bodytext);

    if ($topic<1) {$topic = 1;}
    $affiche=false;
    $result2=sql_query("select topictext, topicimage, topicadmin from ".$NPDS_Prefix."topics where topicid='$topic'");
    list ($topictext, $topicimage, $topicadmin)=sql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php?op=submissions");}

    include ('header.php');
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Prévisualiser l'Article");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    $rowcolor = tablos();
    echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
    echo "<td valign=\"top\"><b>".adm_translate("Langue de Prévisualisation")."</b> : ".aff_localzone_langue("local_user_language")."<br /><br />";
    $no_img=false;
    if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
       echo "<img src=\"$tipath$topicimage\" border=\"0\" align=\"right\" alt=\"\" />";
    } else {
       $no_img=true;
    }
    code_aff($subject, meta_lang($story), meta_lang($bodytext), "");
    if ($no_img) {
       echo "</td><td width=\"10%\" align=\"center\" valign=\"middle\"><b>".aff_langue($topictext)."</b>";
    }
    echo "</td></tr></table></td></tr></table><br />";
    opentable2();
    echo "<b>".adm_translate("Utilisateur")."</b> : <input class=\"textbox_standard\" type=\"text\" name=\"author\" size=\"50\" value=\"$uname\" />&nbsp;";
    if ($ibid=theme_image("forum/icons/posticon.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/icons/posticon.gif";}
    echo "<a href=\"replypmsg.php?send=".urlencode($uname)."\" target=\"_blank\"><img src=\"$imgtmp\" border=\"0\" alt=\"".adm_translate("Diffusion d'un Message Interne")."\" /></a><br /><br />";

    echo "<b>".adm_translate("Titre")."</b>&nbsp;&nbsp;: <input class=\"textbox\" type=\"text\" name=\"subject\" size=\"50\" value=\"$subject\" /><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"textbox_standard\" name=\"topic\">";
    $toplist = sql_query("select topicid, topictext, topicadmin from ".$NPDS_Prefix."topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Tous les Sujets")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = sql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected=\"selected\" "; }
          echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    SelectCategory($cat);
    echo "<br />";
    puthome($ihome);
    closetable2();

    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$story</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte étendu")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");
    echo "<br /><b>".adm_translate("Notes")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"7\" name=\"notes\" style=\"width: 100%;\"></textarea>";
    echo aff_editeur("notes", "true");

    $deb_day=substr($date_debval,8,2);
    $deb_month=substr($date_debval,5,2);
    $deb_year=substr($date_debval,0,4);
    $deb_hour=substr($date_debval,11,2);
    $deb_min=substr($date_debval,14,2);
    //
    $fin_day=substr($date_finval,8,2);
    $fin_month=substr($date_finval,5,2);
    $fin_year=substr($date_finval,0,4);
    $fin_hour=substr($date_finval,11,2);
    $fin_min=substr($date_finval,14,2);
    //
    publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    echo "<br />
    <input type=\"hidden\" name=\"qid\" value=\"$qid\" />
    <input type=\"hidden\" name=\"uid\" value=\"$uid\" />
    <select class=\"textbox_standard\" name=\"op\">
    <option value=\"DeleteStory\">".adm_translate(" Effacer l'Article ")."</option>
    <option value=\"PreviewAgain\" selected=\"selected\">".adm_translate(" Re-prévisualiser ")."</option>
    <option value=\"PostStory\">".adm_translate("Poster un Article ")."</option>
    </select>
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ok")."\" />
    </form>";
    closetable();
    include ('footer.php');
}

function previewStory($qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min,  $epur) {
    global $NPDS_Prefix;
    global $tipath, $hlpfile, $language, $aid, $radminsuper;
    $hlpfile = "manuels/$language/newarticle.html";
    $subject = stripslashes(str_replace("\"","&quot;",$subject));
    $hometext = stripslashes($hometext);
    $bodytext = stripslashes($bodytext);
    $notes = stripslashes($notes);

    if ($topic<1) {$topic = 1;}
    $affiche=false;
    $result2=sql_query("select topictext, topicimage, topicadmin from ".$NPDS_Prefix."topics where topicid='$topic'");
    list ($topictext, $topicimage, $topicadmin)=sql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php?op=submissions");}

    include ('header.php');
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Prévisualiser l'Article");
    echo "</td></tr></table>\n";
    global $local_user_language;
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    $rowcolor = tablos();
    echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
    echo "<td valign=\"top\"><b>".adm_translate("Langue de Prévisualisation")."</b> : ".aff_localzone_langue("local_user_language")."<br /><br />";
    $no_img=false;
    if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
       echo "<img src=\"$tipath$topicimage\" border=\"0\" align=\"right\" alt=\"\" />";
    } else {
       $no_img=true;
    }
    code_aff($subject, meta_lang($hometext), meta_lang($bodytext), meta_lang($notes));
    if ($no_img) {
       echo "</td><td width=\"10%\" align=\"center\" valign=\"middle\"><b>".aff_langue($topictext)."</b>";
    }
    echo "</td></tr></table></td></tr></table><br />";
    opentable2();
    echo "<b>".adm_translate("Utilisateur")."</b> : <input class=\"textbox_standard\" type=\"text\" name=\"author\" size=\"50\" value=\"$author\" /><br /><br />";
    echo "<b>".adm_translate("Titre")."</b>&nbsp;&nbsp;: <input class=\"textbox\" type=\"text\" name=\"subject\" size=\"50\" value=\"$subject\" /><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"textbox_standard\" name=\"topic\">";
    $toplist = sql_query("select topicid, topictext, topicadmin from ".$NPDS_Prefix."topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Tous les Sujets")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = sql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected=\"selected\" "; }
          echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    SelectCategory($catid);
    echo "<br />";
    if (($members==1) and ($Mmembers=="")) {$ihome="-127";}
    if (($members==1) and (($Mmembers>1) and ($Mmembers<=127))) {$ihome=$Mmembers;}
    puthome($ihome);
    closetable2();

    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$hometext</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte étendu")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");
    echo "<br /><b>".adm_translate("Notes")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"7\" name=\"notes\" style=\"width: 100%;\">$notes</textarea>";
    echo aff_editeur("notes", "true");

    publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    echo "<input type=\"hidden\" name=\"qid\" value=\"$qid\" />
    <input type=\"hidden\" name=\"uid\" value=\"$uid\" />
    <br /><select class=\"textbox_standard\" name=\"op\">
    <option value=\"DeleteStory\">".adm_translate(" Effacer l'Article ")."</option>
    <option value=\"PreviewAgain\" selected=\"selected\">".adm_translate(" Re-prévisualiser ")."</option>
    <option value=\"PostStory\">".adm_translate("Poster un Article ")."</option>
    </select>
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ok")."\" /></form>";
    closetable();
    include ('footer.php');
}

function postStory($type_pub, $qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $date_debval,$date_finval,$epur) {
    global $NPDS_Prefix;
    global $aid, $ultramode;
    if ($uid == 1) $author = "";
    if ($hometext == $bodytext) $bodytext = "";
    $subject = stripslashes(FixQuotes(str_replace("\"","&quot;",$subject)));
    $hometext = stripslashes(FixQuotes($hometext));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $notes = stripslashes(FixQuotes($notes));
    if (($members==1) and ($Mmembers=="")) {$ihome="-127";}
    if (($members==1) and (($Mmembers>1) and ($Mmembers<=127))) {$ihome=$Mmembers;}

    if ($type_pub=="pub_immediate") {
       $date_debval="";
       $result = sql_query("insert into ".$NPDS_Prefix."stories values (NULL, '$catid', '$aid', '$subject', now(), '$hometext', '$bodytext', '0', '0', '$topic','$author', '$notes', '$ihome', '0', '$date_finval','$epur')");
       Ecr_Log("security", "postStory (pub_immediate, $subject) by AID : $aid", "");
    } else {
       $result = sql_query("insert into ".$NPDS_Prefix."autonews values (NULL, '$catid', '$aid', '$subject', now(), '$hometext', '$bodytext', '$topic', '$author', '$notes', '$ihome','$date_debval','$date_finval','$epur')");
       Ecr_Log("security", "postStory (autonews, $subject) by AID : $aid", "");
    }
    if (($uid!=1) and ($uid!="")) {
       sql_query("update ".$NPDS_Prefix."users set counter=counter+1 where uid='$uid'");
    }
    sql_query("update ".$NPDS_Prefix."authors set counter=counter+1 where aid='$aid'");
    if ($ultramode) {
       ultramode();
    }
    deleteStory($qid);

    if ($type_pub=="pub_immediate") {
       global $subscribe;
       if ($subscribe) {
          subscribe_mail("topic",$topic,"",$subject,"");
       }
       // Réseaux sociaux
          if (file_exists('modules/npds_twi/npds_to_twi.php')) {include ('modules/npds_twi/npds_to_twi.php');}
          if (file_exists('modules/npds_fbk/npds_to_fbk.php')) {include ('modules/npds_twi/npds_to_fbk.php');}
       // Réseaux sociaux
    }
    // Cluster Paradise
    if (file_exists("modules/cluster-paradise/cluster-activate.php")) {include ("modules/cluster-paradise/cluster-activate.php");}
    if (file_exists("modules/cluster-paradise/cluster-M.php")) {include ("modules/cluster-paradise/cluster-M.php");}
    // Cluster Paradise
    redirect_url("admin.php?op=submissions");
}

function editStory ($sid) {
    if (($sid=="") or ($sid=="0")) {
       header("location: admin.php");
    }
    global $NPDS_Prefix;
    global $tipath, $hlpfile, $language, $aid, $radminsuper;
    $hlpfile = "manuels/$language/newarticle.html";

    $result = sql_query("SELECT catid, title, hometext, bodytext, topic, notes, ihome, date_finval,auto_epur FROM ".$NPDS_Prefix."stories where sid='$sid'");
    list($catid, $subject, $hometext, $bodytext, $topic, $notes, $ihome, $date_finval,$epur) = sql_fetch_row($result);
    $subject = stripslashes($subject);
    $hometext = stripslashes($hometext);
    if ($ibid=theme_image("pick.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/pick.gif";}
    $hometext=str_replace("<img src=\"".$imgtmp."\" border=\"0\" align=\"center\" alt=\"\" /> :: ","",$hometext);
    $bodytext = stripslashes($bodytext);
    $notes = stripslashes($notes);

    $affiche=false;
    $result2=sql_query("select topictext, topicimage, topicadmin from ".$NPDS_Prefix."topics where topicid='$topic'");
    list ($topictext, $topicimage, $topicadmin)=sql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php");}

    include ('header.php');
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Editer un Article");
    echo "</td></tr></table><br />\n";
    $result=sql_query("select topictext, topicimage from ".$NPDS_Prefix."topics where topicid='$topic'");
    list($topictext, $topicimage) = sql_fetch_row($result);

    $rowcolor = tablos();
    echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
    echo "<td valign=\"top\"><b>".aff_local_langue("<b>".adm_translate("Langue de Prévisualisation")."</b> : ","","local_user_language");
    $no_img=false;
    if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
       echo "<img src=\"$tipath$topicimage\" border=\"0\" align=\"right\" alt=\"\" />";
    } else {
       $no_img=true;
    }
    global $local_user_language;
    code_aff($subject, $hometext, $bodytext, $notes);
    if ($no_img) {
       echo "</td><td width=\"10%\" align=\"center\" valign=\"middle\"><b>".aff_langue($topictext)."</b>";
    }
    echo "</td></tr></table></td></tr></table><br />";

    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    opentable2();
    echo "<b>".adm_translate("Titre")."</b>&nbsp;&nbsp;: <input class=\"textbox\" type=\"text\" name=\"subject\" size=\"50\" value=\"$subject\" /><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"textbox_standard\" name=\"topic\">";
    $toplist = sql_query("select topicid, topictext, topicadmin from ".$NPDS_Prefix."topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Tous les Sujets")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = sql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected=\"selected\""; }
          echo "<option value=\"$topicid\" $sel>".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    SelectCategory($catid);
    echo "<br />";
    puthome($ihome);
    closetable2();

    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$hometext</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte complet")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");
    echo "<br /><b>".adm_translate("Notes")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"7\" name=\"notes\" style=\"width: 100%;\">$notes</textarea>";
    echo aff_editeur("notes", "true");

    echo "<br /><b>".adm_translate("Changer la date ? : ")."</b> ".adm_translate("Oui")." <input type=\"checkbox\" name=\"Cdate\" value=\"true\" /> - ";
    echo "<b>".adm_translate("Remettre cet article en première position ? : ")."</b> ".adm_translate("Oui")." <input type=\"checkbox\" name=\"Csid\" value=\"true\" /><br />";

    if ($date_finval!="") {
       $fin_day=substr($date_finval,8,2);
       $fin_month=substr($date_finval,5,2);
       $fin_year=substr($date_finval,0,4);
       $fin_hour=substr($date_finval,11,2);
       $fin_min=substr($date_finval,14,2);
    } else {
       $fin_day="01";
       $fin_month="01";
       $fin_year=date("Y")+99;
       $fin_hour="00";
       $fin_min="00";
    }
    publication(-1,-1,-1,-1,-1, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    global $theme;
    echo "<br /><input type=\"hidden\" name=\"sid\" value=\"$sid\" />
    <input type=\"hidden\" name=\"op\" value=\"ChangeStory\" />
    <input type=\"hidden\" name=\"theme\" value=\"$theme\" />
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate(" Modifier l'Article")."\" />
    </form>";
    closetable();
    include ('footer.php');
}

function deleteStory($qid) {
   global $NPDS_Prefix;

   $result=sql_query("delete from ".$NPDS_Prefix."queue where qid='$qid'");
   global $aid; Ecr_Log("security", "deleteStoryfromQueue($qid) by AID : $aid", "");
}

function removeStory ($sid, $ok=0) {
    if (($sid=="") or ($sid=="0")) {
       header("location: admin.php");
    }
    global $NPDS_Prefix;
    global $ultramode, $aid, $radminsuper;
    $result=sql_query("select topic from ".$NPDS_Prefix."stories where sid='$sid'");
    list($topic)=sql_fetch_row($result);
    $affiche=false;
    $result2=sql_query("select topicadmin from ".$NPDS_Prefix."topics where topicid='$topic'");
    list ($topicadmin, $topicname)=sql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php");}

    if ($ok) {
       sql_query("DELETE FROM ".$NPDS_Prefix."stories where sid='$sid'");
       // commentaires
       if (file_exists("modules/comments/article.conf.php")) {
           include ("modules/comments/article.conf.php");
           sql_query("DELETE FROM ".$NPDS_Prefix."posts WHERE forum_id='$forum' and topic_id='$topic'");
       }
       global $aid; Ecr_Log("security", "removeStory ($sid, $ok) by AID : $aid", "");
       if ($ultramode) {
          ultramode();
       }
       Header("Location: admin.php");
    } else {
       global $hlpfile, $language;
       $hlpfile = "manuels/$language/newarticle.html";
       include ('header.php');
       GraphicAdmin($hlpfile);
       opentable();
       echo "<p align=\"center\"><span class=\"rouge\">".adm_translate("Etes-vous sûr de vouloir effacer l'Article N°")." $sid ".adm_translate("et tous ses Commentaires ?")."</span>";
       echo "<br /><br />[ <a href=\"admin.php?op=RemoveStory&amp;sid=$sid&amp;ok=1\" class=\"rouge\">".adm_translate("Oui")."</a> | <a href=\"admin.php\" class=\"noir\">".adm_translate("Non")."</a> ]</p><br />";
       closetable();
       include("footer.php");
    }
}

function changeStory($sid, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $Cdate, $Csid, $date_finval,$epur,$theme) {
    global $NPDS_Prefix;
    global $aid, $ultramode;
    $subject = stripslashes(FixQuotes(str_replace("\"","&quot;",$subject)));
    $hometext = stripslashes(FixQuotes($hometext));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $notes = stripslashes(FixQuotes($notes));
    if (($members==1) and ($Mmembers=="")) {$ihome="-127";}
    if (($members==1) and (($Mmembers>1) and ($Mmembers<=127))) {$ihome=$Mmembers;}

    if ($Cdate) {
       sql_query("update ".$NPDS_Prefix."stories set catid='$catid', title='$subject', hometext='$hometext', bodytext='$bodytext', topic='$topic', notes='$notes', ihome='$ihome',time=now(), date_finval='$date_finval', auto_epur='$epur', archive='0' where sid='$sid'");
    } else {
       sql_query("update ".$NPDS_Prefix."stories set catid='$catid', title='$subject', hometext='$hometext', bodytext='$bodytext', topic='$topic', notes='$notes', ihome='$ihome', date_finval='$date_finval', auto_epur='$epur' where sid='$sid'");
    }
    if ($Csid) {
       if ($ibid=theme_image("pick.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/pick.gif";}
       sql_query("update ".$NPDS_Prefix."stories set hometext='<img src=\"".$imgtmp."\" border=\"0\" align=\"center\" alt=\"\" /> :: $hometext' where sid='$sid'");
       list($Lsid)=sql_fetch_row(sql_query("select sid from ".$NPDS_Prefix."stories order by sid Desc"));
       $Lsid++;
       sql_query("update ".$NPDS_Prefix."stories set sid='$Lsid' where sid='$sid'");
      // commentaires
      if (file_exists("modules/comments/article.conf.php")) {
          include ("modules/comments/article.conf.php");
          sql_query("update ".$NPDS_Prefix."posts set topic_id='$Lsid' WHERE forum_id='$forum' and topic_id='$topic'");
      }
      $sid=$Lsid;
    }
    global $aid; Ecr_Log("security", "changeStory($sid, $subject, hometext..., bodytext..., $topic, notes..., $catid, $ihome, $members, $Mmembers, $Cdate, $Csid, $date_finval,$epur,$theme) by AID : $aid", "");
    if ($ultramode) {
       ultramode();
    }
    // Cluster Paradise
    if (file_exists("modules/cluster-paradise/cluster-activate.php")) {include ("modules/cluster-paradise/cluster-activate.php");}
    if (file_exists("modules/cluster-paradise/cluster-M.php")) {include ("modules/cluster-paradise/cluster-M.php");}
    // Cluster Paradise
    // Réseaux sociaux
       if (file_exists('modules/npds_twi/npds_to_twi.php')) {include ('modules/npds_twi/npds_to_twi.php');}
       if (file_exists('modules/npds_fbk/npds_to_fbk.php')) {include ('modules/npds_twi/npds_to_fbk.php');}
    // Réseaux sociaux
    redirect_url("admin.php?op=EditStory&sid=$sid");
}

function adminStory() {
    global $NPDS_Prefix;
    global $hlpfile, $language, $aid, $radminsuper;
    $hlpfile = "manuels/$language/newarticle.html";
    include ('header.php');
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Nouvel Article");
    echo "</td></tr></table>\n";
    echo "<br />";
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    opentable2();
    echo "<b>".adm_translate("Titre")."</b>&nbsp;&nbsp;: <input class=\"textbox\" type=\"text\" name=\"subject\" size=\"50\" value=\"\" /><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"textbox_standard\" name=\"topic\">";
    $toplist = sql_query("select topicid, topictext, topicadmin from ".$NPDS_Prefix."topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Sélectionner un Sujet")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = sql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected=\"selected\""; }
          echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    echo "&nbsp;";
    $cat = 0;
    SelectCategory($cat);
    echo "<br />";
    puthome($ihome);
    closetable2();

    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$hometext</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte étendu")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");

    publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    echo "<input type=\"hidden\" name=\"author\" value=\"$aid\" />";
    echo "<br /><input type=\"hidden\" name=\"op\" value=\"PreviewAdminStory\" />
    <input class=\"bouton_standard\" type=\"submit\" name=\"submit\" value=\"".adm_translate("Prévisualiser")."\" />
    </form>";
    closetable();
    include ('footer.php');
}

function previewAdminStory($subject, $hometext, $bodytext, $topic, $catid, $ihome, $members, $Mmembers, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min,  $epur) {
    global $NPDS_Prefix;
    global $tipath, $hlpfile, $language, $aid, $radminsuper;
    $hlpfile = "manuels/$language/newarticle.html";
    $subject = stripslashes(str_replace("\"","&quot;",$subject));
    $hometext = stripslashes($hometext);
    $bodytext = stripslashes($bodytext);

    if ($topic<1) {$topic = 1;}
    $affiche=false;
    $result2=sql_query("select topictext, topicimage, topicadmin from ".$NPDS_Prefix."topics where topicid='$topic'");
    list ($topictext, $topicimage, $topicadmin)=sql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php");}

    include ('header.php');
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Prévisualiser l'Article");
    echo "</td></tr></table><br />\n";
    global $local_user_language;
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    $rowcolor = tablos();
    echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
    echo "<td valign=\"top\"><b>".adm_translate("Langue de Prévisualisation")."</b> : ".aff_localzone_langue("local_user_language")."<br /><br />";
    $no_img=false;
    $no_img=false;
    if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
       echo "<img src=\"$tipath$topicimage\" border=\"0\" align=\"right\" alt=\"\" />";
    } else {
       $no_img=true;
    }
    code_aff($subject, $hometext, $bodytext, "");
    if ($no_img) {
       echo "</td><td width=\"10%\" align=\"center\" valign=\"middle\"><b>".aff_langue($topictext)."</b>";
    }
    echo "</td></tr></table></td></tr></table><br />";
    opentable2();
    echo "<b>".adm_translate("Titre")."</b>&nbsp;&nbsp;: <input class=\"textbox\" type=\"text\" name=\"subject\" size=\"50\" value=\"$subject\" /><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"textbox_standard\" name=\"topic\">";
    $toplist = sql_query("select topicid, topictext, topicadmin from ".$NPDS_Prefix."topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Tous les Sujets")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = sql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected=\"selected\""; }
          echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    $cat = $catid;
    SelectCategory($catid);
    echo "<br />";
    if (($members==1) and ($Mmembers=="")) {$ihome="-127";}
    if (($members==1) and (($Mmembers>1) and ($Mmembers<=127))) {$ihome=$Mmembers;}
    puthome($ihome);
    closetable2();

    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$hometext</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte étendu")."</b> :<br />
    <textarea class=\"textbox\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");

    publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    echo "<input type=\"hidden\" name=\"author\" value=\"$aid\" />";
    echo "<br /><select class=\"textbox_standard\" name=\"op\">
    <option value=\"PreviewAdminStory\" selected>".adm_translate("Prévisualiser")."</option>
    <option value=\"PostStory\">".adm_translate("Poster un Article Admin")."</option>
    </select> -
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ok")."\" /></form>";
    closetable();
    include ('footer.php');
}

switch ($op) {
   case "EditCategory":
        EditCategory($catid);
        break;
   case "DelCategory":
        DelCategory($cat);
        break;
   case "YesDelCategory":
        YesDelCategory($catid);
        break;
   case "NoMoveCategory":
        NoMoveCategory($catid, $newcat);
        break;
   case "SaveEditCategory":
        SaveEditCategory($catid, $title);
        break;
   case "AddCategory":
        AddCategory();
        break;
   case "SaveCategory":
        SaveCategory($title);
        break;

   case "DisplayStory":
        displayStory($qid);
        break;
   case "PreviewAgain":
        previewStory($qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min,  $epur);
        break;
   case "PostStory":
        if (!$date_debval) {
           if (strlen($deb_day)==1) {
              $deb_day = "0$deb_day";
           }
           if (strlen($deb_month)==1) {
              $deb_month = "0$deb_month";
           }
           $date_debval = "$deb_year-$deb_month-$deb_day $deb_hour:$deb_min:00";
        }
        if (!$date_finval) {
           if (strlen($fin_day)==1) {
              $fin_day = "0$fin_day";
           }
           if (strlen($fin_month)==1) {
              $fin_month = "0$fin_month";
           }
           $date_finval = "$fin_year-$fin_month-$fin_day $fin_hour:$fin_min:00";
        }
        if ($date_finval<$date_debval) {
           $date_finval = $date_debval;
        }
        $temp_new=mktime(substr($date_debval,11,2), substr($date_debval,14,2),0,substr($date_debval,5,2),substr($date_debval,8,2),substr($date_debval,0,4));
        $temp=time();
        if ($temp>$temp_new) {
           postStory("pub_immediate",$qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $date_debval,$date_finval,$epur);
        } else {
           postStory("pub_automated",$qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $date_debval,$date_finval,$epur);
        }
        break;

   case "DeleteStory":
        deleteStory($qid);
        Header("Location: admin.php?op=submissions");
        break;

   case "EditStory":
        editStory($sid);
        break;
   case "ChangeStory":
        if (!$date_finval) {
           if (strlen($fin_day)==1) {
              $fin_day = "0$fin_day";
           }
           if (strlen($fin_month)==1) {
              $fin_month = "0$fin_month";
           }
           $date_finval = "$fin_year-$fin_month-$fin_day $fin_hour:$fin_min:00";
        }
        changeStory($sid, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $members, $Mmembers, $Cdate, $Csid, $date_finval,$epur, $theme);
        break;
   case "RemoveStory":
        removeStory($sid, $ok);
        break;

   case "adminStory":
        adminStory();
        break;
   case "PreviewAdminStory":
        previewAdminStory($subject, $hometext, $bodytext, $topic, $catid, $ihome, $members, $Mmembers, $deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min,  $epur);
        break;
}
?>