<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* Cluster Paradise - Manage Data-Cluster / Mod by Tribal-Dolphin       */
/*                                                                      */
/* 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 V_secur_cluster($Xkey) {
   global $ModPath;
   $trouve=false;
   if (file_exists("modules/$ModPath/data-cluster-E.php")) {
      include("modules/$ModPath/data-cluster-E.php");
      $cpt=0;
      while (each($part) and !$trouve) {
         if (md5($part[$cpt]["WWW"].$part[$cpt]["KEY"])==decrypt($Xkey,$part[$cpt]["KEY"])) {
            $trouve=true;
         } else {
            $cpt=$cpt+1;
         }
      }
   }
   if ($trouve) {
      return ($part[$cpt]);
   } else {
      return (false);
   }
}

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;
}

if ($tmp=V_secur_cluster($key)) {
   if (($Xop=="NEWS") and ($tmp[SUBSCRIBE]=="NEWS") and ($tmp[OP]=="IMPORT")) {
      // vérifie que le membre existe bien sur le site
      $author=decrypt(removeHack($Xauthor),$tmp[KEY]);
      $result = mysql_query("SELECT name FROM users WHERE uname='$author'");
      list($name) = mysql_fetch_row($result);
      if ($name==$author) {$pasfinA=true;} else {$pasfinA=false;}

      // vérifie que le l'auteur existe bien et ne dispose que des droits minimum
      $aid=decrypt(removeHack($Xaid),$tmp[KEY]);
      $result = mysql_query("select radminarticle from authors where aid='$aid'");
      list($radminarticle) = mysql_fetch_row($result);
      if ($radminarticle==1) {$pasfinB=true;} else {$pasfinB=false;}

      // vérifie que la catégorie existe : sinon met la catégorie générique
      $catid=decrypt(removeHack($Xcatid),$tmp[KEY]);
      $result = mysql_query("select catid from stories_cat where title='$catid'");
      list($catid) = mysql_fetch_row($result);
      
     // vérifie que le Topic existe : sinon met le Topic générique
      $topic=decrypt(removeHack($Xtopic),$tmp[KEY]);
      $result = mysql_query("select topicid from topics where topictext='$topic'");
      list($topic) = mysql_fetch_row($result);

      // OK on fait la mise à jour
      if ($pasfinA and $pasfinB) {
         $subject=decrypt(removeHack($Xsubject),$tmp[KEY]);
         $hometext=decrypt(removeHack($Xhometext),$tmp[KEY]);
         $bodytext=decrypt(removeHack($Xbodytext),$tmp[KEY]);
         $notes=decrypt(removeHack($Xnotes),$tmp[KEY]);
         $ihome=decrypt(removeHack($Xihome),$tmp[KEY]);
         $result = mysql_query("insert into stories values (NULL, '$catid', '$aid', '$subject', now(), '$hometext', '$bodytext', '0', '0', '$topic', '$author', '$notes', '$ihome', '0', NULL, '0')");
         mysql_query("update users set counter=counter+1 where uid='$author'");
         mysql_query("update authors set counter=counter+1 where aid='$aid'");
         if ($ultramode) {
            ultramode();
         }
      }
   }
}
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">
     <!--
     self.close();
     //-->
     </script>";
?>
