<?PHP
/***************************************************************************/
/* BLOC-NOTES engine for NPDS V  / Net Portal Dynamic System               */
/*                                                                         */
/* This version name NPDS Copyright (c) 2002-2004 by Philippe Brunier      */
/*                                                                         */
/* This BLOC-NOTES version Copyright (c) 2003-2004 by Arnaud Latourrette   */
/*                                                                         */
/* 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 ($uriBlocNote) {
   if ($typeBlocNote=="shared") {
      $bnid=md5($nomBlocNote);
   } elseif ($typeBlocNote=="context") {
      if ($nomBlocNote=="\$username") {
         global $cookie, $admin;
         $nomBlocNote=$cookie[1];
         $cur_admin=explode(":",base64_decode($admin));
         if ($cur_admin) {
            $nomBlocNote=$cur_admin[0];
         }
      }
      if (stristr(urldecode($uriBlocNote),"article.php")) {
         $bnid=md5($nomBlocNote.substr(urldecode($uriBlocNote),0,strpos(urldecode($uriBlocNote),"&")));
      } else {
         $bnid=md5($nomBlocNote.urldecode($uriBlocNote));
      }
   } else {
      $bnid="";
   }

   if ($bnid) {
      if ($supBlocNote=="RAZ") {
         @mysql_query("DELETE FROM ".$NPDS_Prefix."blocnotes WHERE bnid='$bnid'");
      } else {
         @mysql_query("LOCK TABLES ".$NPDS_Prefix."blocnotes WRITE");
         $result = mysql_query("select texte from ".$NPDS_Prefix."blocnotes where bnid='$bnid'");
         if (mysql_num_rows($result) > 0) {
            if ($texteBlocNote!="") {
                mysql_query("UPDATE ".$NPDS_Prefix."blocnotes SET texte='".removeHack($texteBlocNote)."' WHERE bnid='$bnid'");
            } else {
                mysql_query("DELETE FROM ".$NPDS_Prefix."blocnotes WHERE bnid='$bnid'");
            }
         } else {
            if ($texteBlocNote!="") {
               mysql_query("INSERT INTO ".$NPDS_Prefix."blocnotes (bnid, texte) VALUES ('$bnid', '".removeHack($texteBlocNote)."')");
            }
         }
         @mysql_query("UNLOCK TABLES");
      }
   }
   header ("location: ".urldecode($uriBlocNote));
} else {
   header ("location: index.php");
}
?>