<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* 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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}

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

   global $user, $Default_Theme;
   if (!$user) {
        Header("Location: user.php");
   } else {
      $userX = base64_decode($user);
      $userdata = explode(":", $userX);
      if ($userdata[9]!="") {
         if (!$file=@opendir("themes/$userdata[9]")) {
            $tmp_theme=$Default_Theme;
         } else {
            $tmp_theme=$userdata[9];
         }
      } else {
         $tmp_theme=$Default_Theme;
      }
      include("themes/$tmp_theme/theme.php");
      include("meta/meta.php");
      echo import_css($tmp_theme, $language, $site_font);
      echo "<title>".translate("Bookmark")."</title>\n";
      include("lib/formhelp.java.php");

      $fic="users_private/".$userdata[1]."/mns/carnet.txt";
      if (file_exists($fic)) {
         $fp=fopen($fic,"r");
            if (filesize($fic)>0)
               $contents=fread($fp, filesize($fic));
         fclose($fp);
         if (substr($contents,0,5)!="CRYPT") {
            $fp=fopen($fic,"w");
               fwrite($fp, "CRYPT".encrypt($contents));
            fclose($fp);
         } else {
            $contents=decrypt(substr($contents,5),substr($userdata[2],8,8));
         }
         echo "</head>\n<body topmargin=\"2\" bottommargin=\"2\" leftmargin=\"2\" rightmargin=\"2\" bgcolor=\"white\">";
         echo "<table width=\"100%\">";
         $contents=explode("\n",$contents);
         foreach($contents as $tab) {
            $tabi=explode(";",$tab);
            if ($tabi[0]!="") {
               $rowcolor=tablos();
               echo "<tr $rowcolor><td nowrap=\"nowrap\">&nbsp;<a href=\"javascript: DoAdd(1,'to_user','$tabi[0],')\";><b>$tabi[0]</b></a></td><td nowrap=\"nowrap\"><a href=\"mailto:$tabi[1]\" class=\"NOIR\"><b>$tabi[1]</a></td><td nowrap=\"nowrap\">$tabi[2]&nbsp;</td></tr>\n";
            }
         }
         echo "</table>";
      } else {
         echo "<table width=\"100%\"><tr><td>";
         echo "<span class=\"NOIR\">".translate("You can upload a file <b>carnet.txt</b> in your Mini-Web site.<br /><br />the data structure of any line :<br />&nbsp;&nbsp;<b>name_of_the_member;email;comments</b>")."</span>";
         echo "</td></tr></table>";
      }
      echo "</body></html>";
}
?>