<?PHP
/************************************************************************/
/* Upload / meta fonction and automation for NPDS .                     */
/* This version name NPDS Copyright (c) 2001-2005 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.       */
/*                                                                      */
/* Copyright Dev 2003                                                   */
/************************************************************************/
if (!eregi("modules.php", $PHP_SELF)) { die(); }
global $Titlesitename;

function keyED($txt,$encrypt_key) {
   $encrypt_key = md5($encrypt_key);
   $ctr=0;
   $tmp = "";
   for ($i=0;$i<strlen($txt);$i++) {
       if ($ctr==strlen($encrypt_key) ) $ctr=0;
       $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
       $ctr++;
   }
   return $tmp;
}
function decrypt($txt,$key) {
   $txt = keyED(base64_decode($txt),$key);
   $tmp = "";
   for ($i=0;$i<strlen($txt);$i++) {
       $md5 = substr($txt,$i,1);
       $i++;
       $tmp.= (substr($txt,$i,1) ^ $md5);
   }
   return $tmp;
}
function encrypt($txt) {
   global $userdata;
   $key=substr($userdata[2],8,8);
   srand( (double)microtime()*1000000);
   $encrypt_key = md5(rand(0,32000) );
   $ctr=0;
   $tmp = "";
   for ($i=0;$i<strlen($txt);$i++) {
       if ($ctr==strlen($encrypt_key) ) $ctr=0;
       $tmp.= substr($encrypt_key,$ctr,1) .
       (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1) );
       $ctr++;
   }
   return base64_encode(keyED($tmp,$key) );
}

/*****************************************************/
/* Include et definition                             */
/*****************************************************/
   include_once("modules/upload/lang/upload.lang-$language.php");
   include_once("modules/upload/include_minisite/upload.conf.minisite.php");
   if ($userdata[9]!="") {
      if (!$file=@opendir("themes/$userdata[9]")) {
         $theme=$Default_Theme;
      } else {
         $theme=$userdata[9];
      }
   } else {
      $theme=$Default_Theme;
   }

   $fic_edition="";
   $userinfo=getusrinfo($user);
   if (!$userinfo[mns]) {Access_error();}
   if (($rep_upload_minisite!="") and ($DOCUMENTROOT!="")) {
      $fic_edition=$DOCUMENTROOT.$rep_upload_minisite.$op;
      if (!stristr($op,".*://") and !stristr($op,"..") and !stristr($op,"../") and !stristr($op, "script") and !stristr($op, "cookie") and !stristr($op, "iframe") and  !stristr($op, "applet") and !stristr($op, "object") and !stristr($op, "meta")) {
         $fic_edition=removeHack($DOCUMENTROOT.$rep_upload_minisite.$op);
      } else {
         Access_error();
      }
   } else {
      Access_error();
   }

   if ($submitS) {
      $file = fopen($fic_edition, "w");
      if ($op=="carnet.txt") {
         if (substr($story,0,5)!="CRYPT") {
            $story="CRYPT".encrypt($story);
         }
      }
      fwrite($file, removeHack(StripCSlashes($story)));
      fclose($file);
   }
/*****************************************************/
/* Entete                                            */
/*****************************************************/
   include("meta/meta.php");
   echo import_css($theme, $language, $site_font);
   echo "<title>$Titlesitename - $uname</title>";
   global $tiny_mce;
   if ($tiny_mce)
      echo aff_editeur("tiny_mce","begin");
   echo "</head>\n<body>";
   echo "<form name=\"adminForm\" method=\"post\" action=\"$PHP_SELF\" enctype=\"multipart/form-data\">";
   echo "<input type=\"hidden\" name=\"ModPath\" value=\"$ModPath\">\n<input type=\"hidden\" name=\"ModStart\" value=\"$ModStart\">\n";
   echo "<input type=\"hidden\" name=\"op\" value=\"$op\">";
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
   echo "<tr><td colspan=\"2\"><textarea name=\"story\" rows=\"25\" cols=\"70\" style=\"width: 100%;\" class=\"TEXTBOX\">";

   // lecture du fichier
   $file = fopen($fic_edition, "r");
   if (filesize($fic_edition)>0)
      $fic_tmp=fread($file, filesize($fic_edition));
   if ($op=="carnet.txt") {
      if (substr($fic_tmp,0,5)=="CRYPT") {
         $fic_tmp=decrypt(substr($fic_tmp,5),substr($userdata[2],8,8));
      }
   }
   echo StripCSlashes($fic_tmp);
   fclose($file);
   // lecture du fichier

   echo "</textarea></td></tr><tr>";
   $suffix = strtoLower(substr(strrchr($op, '.' ),1));
   if (($suffix=="htm") or ($suffix=="html")) {
   if ($tiny_mce) {
      echo "<td>".aff_editeur("story","false")."</td>";
      echo aff_editeur("tiny_mce","end");
   } else {
      echo "<td>".aff_editeur("custom","story&minisite=true&membre=$userdata[1]")."</td>";
   }
   }
   echo "<td align=\"right\"><input type=\"submit\" name=\"submitS\" value=\"".translate("Submit")."\" class=\"BOUTON_STANDARD\"></td></tr>";
   echo "</table></form></body></html>\n";
?>