<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* Manage other configuration and customisation files                   */
/* by Hotfirenet 2004                                                   */
/*                                                                      */
/* 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/configfiles.html";
$result = mysql_query("select radminsuper from authors where aid='$aid'");
list($radminsuper) = mysql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}

function ConfigFiles($contents, $files) {
   global $hlpfile, $language, $max_car;
   include ("header.php");
   GraphicAdmin($hlpfile);
   OpenTable();

   if ($contents=="") {
      echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">\n"
          . "<tr>\n"
          . "<td class=\"HEADER\">".adm_translate("Editer les fichiers de configuration")."</td>\n"
          . "</tr>\n"
          . "</table>\n"
          . "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">"
          . "<tr><td colspan=\"3\"><span class=\"NOIR\" style=\"font-size: 12px;\"><b>/modules/include</b></span></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=header_before\" class=\"NOIR\">Header_Before</a></td><td>".adm_translate("Ce fichier est appelé avant que de commencer la génération de la page HTML")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=header_before\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=header_head\" class=\"NOIR\">Header_Head</a></td><td>".adm_translate("Ce fichier est appelé entre le HEAD et /HEAD lors de la génération de la page HTML")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=header_head\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=body_onload\" class=\"NOIR\">Body_Onload</a></td><td>".adm_translate("Ce fichier est appelé dans l'évement ONLOAD de la balise BODY => JAVASCRIPT")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=body_onload\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=header_after\" class=\"NOIR\">Header_After</a></td><td>".adm_translate("Ce fichier est appelé à la fin du header du thème")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=header_after\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=footer_before\" class=\"NOIR\">Footer_Before</a></td><td>".adm_translate("Ce fichier est appelé avant le début du footer du thème")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=footer_before\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=footer_after\" class=\"NOIR\">Footer_After</a></td><td>".adm_translate("Ce fichier est appelé après la fin de la génération de la page HTML")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=footer_after\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=new_user\" class=\"NOIR\">New_User</a></td><td>".adm_translate("Ce fichier permet d'envoyer un MI personnalisé lorsqu'un nouveau membre s'inscrit")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=new_user\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=user\" class=\"NOIR\">User</a></td><td>".adm_translate("Ce fichier permet l'affichage d'informations complémentaires dans la page de login")."</td><td><a href=\"admin.php?op=delete_configfile&amp;file=user\" class=\"ROUGE\">".adm_translate("Supprimer")."</a></td></tr>\n"
          . "<tr><td colspan=\"3\">&nbsp;</td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=extend-modules\" class=\"NOIR\">Extend-Modules</a></td><td colspan=\"2\">".adm_translate("Ce fichier permet la configuration des modules complémentaires de l'administration")." ( admin/ )</td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=cache.config\" class=\"NOIR\">Cache.Config</a></td><td colspan=\"2\">".adm_translate("Ce fichier permet la configuration technique de SuperCache")." ( / )</td></tr>\n"
          . "<tr><td>&nbsp;<a href=\"admin.php?op=ConfigFiles_load&amp;files=upload.conf\" class=\"NOIR\">Upload.Conf</a></td><td colspan=\"2\">".adm_translate("Ce fichier permet la configuration des fonctions d'upload")." ( /modules/upload/ )</td></tr>\n"
          . "</table><br />\n";
   } else {
      echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">\n"
          . "<tr>\n"
          . "<td class=\"HEADER\">".adm_translate("Modification de")." : $files</td>\n"
          . "</tr>\n"
          . "</table>\n"
          . "<br />\n"
          . "<form action=\"admin.php?op=ConfigFiles_save\" method=\"post\">\n"
          . "<p align=\"center\">\n"
          . "<textarea class=\"textbox\" name=\"Xtxt\" rows=\"20\" cols=\"70\">\n";
      echo htmlspecialchars($contents);
      echo "</textarea>\n"
          . "<br /><br />\n"
          . "<input type=\"hidden\" name=\"Xfiles\" value=\"$files\">"
          . "<input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"confirm\" value=\"".adm_translate("Sauver les modifications")."\"> - \n"
          . "<a href=\"admin.php?op=ConfigFiles\" class=\"NOIR\">".adm_translate("Abandonner")."</a></p>\n"
          . "</form>\n";
   }
   CloseTable();
   include ("footer.php");
}

function ConfigFiles_save($Xtxt, $Xfiles) {
   if ($Xfiles == "header_before") {
      $fp=fopen("modules/include/header_before.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "header_head") {
      $fp=fopen("modules/include/header_head.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "body_onload") {
      $fp=fopen("modules/include/body_onload.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "header_after") {
      $fp=fopen("modules/include/header_after.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "footer_before") {
      $fp=fopen("modules/include/footer_before.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "footer_after") {
      $fp=fopen("modules/include/footer_after.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }

   elseif ($Xfiles == "new_user") {
      $fp=fopen("modules/include/new_user.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "user") {
      $fp=fopen("modules/include/user.inc","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "extend-modules") {
      $fp=fopen("admin/extend-modules.txt","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "cache.config") {
      $fp=fopen("cache.config.php","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   elseif ($Xfiles == "upload.conf") {
      $fp=fopen("modules/upload/upload.conf.php","w");
      fputs($fp,stripslashes($Xtxt));
      fclose($fp);
   }
   header("location: admin.php?op=ConfigFiles");
}

function delete_configfile($fileX) {
   global $hlpfile;
   include("header.php");
   GraphicAdmin($hlpfile);
   OpenTable();
   echo "<p align=\"center\"><b>".adm_translate("Supprimer le fichier")." $fileX ?</b> ";
   echo "[ <a href=\"admin.php?op=ConfigFiles_delete&amp;file=$fileX\" class=\"ROUGE\">".adm_translate("Oui")."</a>&nbsp;|&nbsp;<a href=\"admin.php?op=ConfigFiles\" class=\"NOIR\">".adm_translate("Non")."</a> ]</p>";
   closetable();
   include("footer.php");
}
function ConfigFiles_delete($modele) {
   if ($modele=="header_before") {
      @unlink("modules/include/header_before.inc");
   } elseif ($modele=="header_head")  {
      @unlink("modules/include/header_head.inc");
   } elseif ($modele=="body_onload")  {
      @unlink("modules/include/body_onload.inc");
   } elseif ($modele=="header_after")  {
      @unlink("modules/include/header_after.inc");
   } elseif ($modele=="footer_before")  {
      @unlink("modules/include/footer_before.inc");
   } elseif ($modele=="footer_after")  {
      @unlink("modules/include/footer_after.inc");
   } elseif ($modele=="new_user")  {
      @unlink("modules/include/new_user.inc");
   } elseif ($modele=="user")  {
      @unlink("modules/include/user.inc");
   }
   header("location: admin.php?op=ConfigFiles");
}

function copy_sample($fileX) {
   global $hlpfile;
   include("header.php");
   GraphicAdmin($hlpfile);
   OpenTable();
   echo "<p align=\"center\"><b>".adm_translate("Créer le fichier en utilisant le modèle")." ?</b> ";
   echo "[ <a href=\"admin.php?op=ConfigFiles_create&amp;modele=$fileX\" class=\"ROUGE\">".adm_translate("Oui")."</a>&nbsp;|&nbsp;<a href=\"admin.php?op=ConfigFiles\" class=\"NOIR\">".adm_translate("Non")."</a> ]</p>";
   closetable();
   include("footer.php");
}
function ConfigFiles_create($modele) {
   @umask("0000");
   if ($modele=="header_before") {
      @copy("modules/include/sample.header_before.inc","modules/include/header_before.inc");
      @chmod("modules/include/header_before.inc",0766);
   } elseif ($modele=="header_head")  {
      @copy("modules/include/sample.header_head.inc","modules/include/header_head.inc");
      @chmod("modules/include/header_head.inc",0766);
   } elseif ($modele=="body_onload")  {
      @copy("modules/include/sample.body_onload.inc","modules/include/body_onload.inc");
      @chmod("modules/include/body_onload.inc",0766);
   } elseif ($modele=="header_after")  {
      @copy("modules/include/sample.header_after.inc","modules/include/header_after.inc");
      @chmod("modules/include/header_after.inc",0766);
   } elseif ($modele=="footer_before")  {
      copy("modules/include/sample.footer_before.inc","modules/include/footer_before.inc");
      chmod("modules/include/footer_before.inc",0766);
   } elseif ($modele=="footer_after")  {
      @copy("modules/include/sample.footer_after.inc","modules/include/footer_after.inc");
      @chmod("modules/include/footer_after.inc",0766);
   } elseif ($modele=="new_user")  {
      @copy("modules/include/sample.new_user.inc","modules/include/new_user.inc");
      @chmod("modules/include/new_user.inc",0766);
   } elseif ($modele=="user")  {
      @copy("modules/include/sample.user.inc","modules/include/user.inc");
      @chmod("modules/include/user.inc",0766);
   }
   header("location: admin.php?op=ConfigFiles");
}

switch ($op) {
    case "ConfigFiles_load":
       if ($files == "header_before") {
          if (file_exists("modules/include/header_before.inc")) {
             $fp=fopen("modules/include/header_before.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/header_before.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "header_head") {
          if (file_exists("modules/include/header_head.inc")) {
             $fp=fopen("modules/include/header_head.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/header_head.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "body_onload") {
         if (file_exists("modules/include/body_onload.inc")) {
            $fp=fopen("modules/include/body_onload.inc","r");
            $Xcontents=fread($fp,filesize("modules/include/body_onload.inc"));
            fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "header_after") {
          if (file_exists("modules/include/header_after.inc")) {
             $fp=fopen("modules/include/header_after.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/header_after.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "footer_before") {
          if (file_exists("modules/include/footer_before.inc")) {
             $fp=fopen("modules/include/footer_before.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/footer_before.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "footer_after") {
          if (file_exists("modules/include/footer_after.inc")) {
             $fp=fopen("modules/include/footer_after.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/footer_after.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }

       elseif ($files == "new_user") {
          if (file_exists("modules/include/new_user.inc")) {
             $fp=fopen("modules/include/new_user.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/new_user.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }
       elseif ($files == "user") {
          if (file_exists("modules/include/user.inc")) {
             $fp=fopen("modules/include/user.inc","r");
             $Xcontents=fread($fp,filesize("modules/include/user.inc"));
             fclose($fp);
          } else {
             copy_sample($files);
          }
       }

       elseif ($files == "extend-modules") {
          if (file_exists("admin/extend-modules.txt")) {
             $fp=fopen("admin/extend-modules.txt","r");
             $Xcontents=fread($fp,filesize("admin/extend-modules.txt"));
             fclose($fp);
          }
       }
       elseif ($files == "cache.config") {
          if (file_exists("cache.config.php")) {
             $fp=fopen("cache.config.php","r");
             $Xcontents=fread($fp,filesize("cache.config.php"));
             fclose($fp);
          }
       }
       elseif ($files == "upload.conf") {
          if (file_exists("modules/upload/upload.conf.php")) {
             $fp=fopen("modules/upload/upload.conf.php","r");
             $Xcontents=fread($fp,filesize("modules/upload/upload.conf.php"));
             fclose($fp);
          }
       }

       ConfigFiles($Xcontents, $files);
       break;

    case "ConfigFiles_save":
        ConfigFiles_save($Xtxt, $Xfiles);
        break;

    case "ConfigFiles_create":
        ConfigFiles_create($modele);
        break;

    case "delete_configfile":
        delete_configfile($file);
        break;
    case "ConfigFiles_delete":
        ConfigFiles_delete($file);
        break;

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