<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* Manage the EDITO (static/edito.txt) of your web site                 */
/*                                                                      */
/* 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 () {
  if (file_exists("meta/meta.php"))
     include ("meta/meta.php");
  echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
  echo "Access Denied / Acc&egrave;s Refus&eacute;";
  if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
  echo "</span>";
  echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
  echo "</span></p></body></html>";
  die();
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }
global $pdst; $pdst="0";

global $language;
$hlpfile = "manuels/$language/edito.html";
$result = mysql_query("select radminsuper from authors where aid='$aid'");
list($radminsuper) = mysql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}

function edito($edito_type, $contents, $Xaff_jours, $Xaff_jour, $Xaff_nuit) {
    global $hlpfile, $language;
    include ("header.php");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Edito");
    echo "</td></tr></table>\n";
    echo "<br />\n";
    if ($contents=="") {
       echo "</td></tr><tr><td align=\"center\">";
       echo "<form action=\"admin.php?op=Edito_load\" method=\"post\">";
       echo "<select class=\"TEXTBOX\" name=\"edito_type\" onChange='submit()'>";
       echo "<option value=\"0\">".adm_translate("Modifier l'Editorial")." ...</option>\n";
       echo "<option value=\"G\">".adm_translate("Anonyme")."</option>\n";
       echo "<option value=\"M\">".adm_translate("Membre")."</option>\n";
       echo "</select></form>";
    } else {
       if ($edito_type=="G") {
          $edito_typeL=" ".adm_translate("Anonyme");
       } elseif ($edito_type=="M") {
          $edito_typeL=" ".adm_translate("Membre");;
       }
       if (strpos($contents,"[/jour]")>0) {
          $contentJ=substr($contents,strpos($contents,"[jour]")+6,strpos($contents,"[/jour]")-6);
          $contentN=substr($contents,strpos($contents,"[nuit]")+6,strpos($contents,"[/nuit]")-19-strlen($contentJ));
       }
       if (!$contentJ and !$contentN and !strpos($contents,"[/jour]")) $contentJ=$contents;
       echo "<b>".adm_translate("Edito")." :$edito_typeL</b>\n";
       echo "<p align=\"center\">";
       echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
       echo adm_translate("Le jour")." :: ";
       echo aff_editeur("XeditoJ","false");
       echo "<br />";
       echo "<textarea class=\"textbox\" name=\"XeditoJ\" rows=\"20\" cols=\"70\" style=\"width: 100%;\">\n";
       echo htmlspecialchars($contentJ);
       echo "</textarea><br /><br />\n";
       echo adm_translate("La nuit")." :: ";
       echo aff_editeur("XeditoN","false");
       echo "<br />";
       echo "<textarea class=\"textbox\" name=\"XeditoN\" rows=\"20\" cols=\"70\" style=\"width: 100%;\">\n";
       echo htmlspecialchars($contentN);
       echo "</textarea><br /><br />\n";
       echo adm_translate("Afficher pendant")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"aff_jours\" maxlength=\"3\" size=\"4\" value=\"$Xaff_jours\"> ".adm_translate("jour(s)")." :: ";
       echo adm_translate("Le jour")." : <input type=\"checkbox\" name=\"aff_jour\" value=\"checked\" $Xaff_jour> / ".adm_translate("La nuit")." : <input type=\"checkbox\" name=\"aff_nuit\" value=\"checked\" $Xaff_nuit> - ";

       echo "<input type=\"hidden\" name=\"op\" value=\"Edito_save\">";
       echo "<input type=\"hidden\" name=\"edito_type\" value=\"$edito_type\">";
       echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"edito_confirm\" value=\"".adm_translate("Sauver les modifications")."\"> - \n";
       echo "<a href=\"admin.php?op=Edito\" class=\"NOIR\">".adm_translate("Abandonner")."</a></p>\n";
       echo "</form>\n";
    }
    CloseTable();
    include ("footer.php");
}

function edito_mod_save($edito_type, $XeditoJ, $XeditoN, $aff_jours, $aff_jour, $aff_nuit) {
    if ($aff_jours<=0) {$aff_jours="999";}
    if ($edito_type=="G") {
       $fp=fopen("static/edito.txt","w");
       fputs($fp,"[jour]".stripslashes($XeditoJ)."[/jour][nuit]".stripslashes($XeditoN)."[/nuit]");
       fputs($fp,"aff_jours=".$aff_jours);
       fputs($fp,"&aff_jour=".$aff_jour);
       fputs($fp,"&aff_nuit=".$aff_nuit);
       fputs($fp,"&aff_date=".time());
       fclose($fp);
    }  elseif ($edito_type=="M") {
       $fp=fopen("static/edito_membres.txt","w");
       fputs($fp,"[jour]".stripslashes($XeditoJ)."[/jour][nuit]".stripslashes($XeditoN)."[/nuit]");
       fputs($fp,"aff_jours=".$aff_jours);
       fputs($fp,"&aff_jour=".$aff_jour);
       fputs($fp,"&aff_nuit=".$aff_nuit);
       fputs($fp,"&aff_date=".time());
       fclose($fp);
    }
    redirect_url("admin.php?op=Edito");
}

switch ($op) {

    case "Edito_save":
        edito_mod_save($edito_type, $XeditoJ, $XeditoN, $aff_jours, $aff_jour, $aff_nuit);
        break;

    case "Edito_load":
        if ($edito_type=="G") {
           if (file_exists("static/edito.txt")) {
              $fp=fopen("static/edito.txt","r");
              if (filesize("static/edito.txt")>0)
                 $Xcontents=fread($fp,filesize("static/edito.txt"));
              fclose($fp);
           }
        } elseif ($edito_type=="M") {
           if (file_exists("static/edito_membres.txt")) {
              $fp=fopen("static/edito_membres.txt","r");
              if (filesize("static/edito_membres.txt")>0)
                 $Xcontents=fread($fp,filesize("static/edito_membres.txt"));
              fclose($fp);
           }
        }
        $Xcontents=ereg_replace("<!--","",$Xcontents);
        $Xcontents=ereg_replace("/-->","",$Xcontents);
        if ($Xcontents=="") {
           $Xcontents="Edito ...";
        } else {
           $ibid=strstr($Xcontents,"aff_jours");
           parse_str($ibid);
        }
        if ($aff_jours) {
           $Xcontents=substr($Xcontents,0,strpos($Xcontents,"aff_jours"));
        } else {
           $aff_jours=20;
           $aff_jour="checked";
           $aff_nuit="checked";
        }
        edito($edito_type, $Xcontents, $aff_jours, $aff_jour, $aff_nuit);
        break;

    default:
        edito("","","","","");
        break;
}
?>
