<?php
function SetBookmarks($set=BM_AUTO)
 {
  $user = $this->GetUser();
 
  if ($set || !($bookmarks=$this->GetBookmarks()))
  {
    $bookmarks = $user["bookmarks"] ? $user["bookmarks"] : $this->GetDefaultBookmarks($user["lang"]);
    if ($set==BM_DEFAULT) $bookmarks = $this->GetDefaultBookmarks($user["lang"]);
    $dummy = $this->Format($bookmarks, "wacko");
    $this->ClearLinkTable();
    $this->StartLinkTracking();
    $dummy = $this->Format($dummy, "post_wacko");
    $this->StopLinkTracking();
    $bmlinks = $this->GetLinkTable();
    $bookmarks = explode("\n", $bookmarks);
    for ($i=0;$i<count($bmlinks);$i++) $bmlinks[$i] = $this->NpjTranslit($bmlinks[$i]);
    $_SESSION["bookmarks"] = $bookmarks;
    $_SESSION["bookmarklinks"] = $bmlinks;
    $_SESSION["bookmarksfmt"] = $this->Format(implode(" | ", $bookmarks), "wacko");
  }

  if (!empty( $_REQUEST["addbookmark"] ) && $user)
  {
    $bookmark="((".$this->GetPageTag().($user["lang"]!=$this->pagelang?" @@".$this->pagelang:"")."))";
    if (!in_array($bookmark,$bookmarks)) 
    {
     $bookmarks[] = $bookmark;
    
     $this->Query("update ".$this->config["user_table"]." set ".
            "bookmarks = '".quote(implode("\n", $bookmarks))."' ".
            "where name = '".quote($user["name"])."' limit 1");

     $this->SetUser($this->LoadUser($user["name"]));
    }
    $_SESSION["bookmarks"] = $bookmarks;
//$_SESSION["bookmarksfmt"] = $this->Format($this->Format(implode(" | ", $bookmarks), "wacko"), "post_wacko");
    $_SESSION["bookmarksfmt"] = $this->Format(implode(" | ", $bookmarks), "wacko");
    $bmlinks = $bookmarks; //ADW
    for ($i=0;$i<count($bmlinks);$i++) $bmlinks[$i] = trim($this->NpjTranslit($bmlinks[$i]),"()"); //ADW
    $_SESSION["bookmarklinks"] = $bmlinks; //ADW
  }

  if (!empty( $_REQUEST["removebookmark"] ) && $user)
  {
   foreach ($bookmarks as $bm)
   {
    $dummy = $this->Format($bm, "wacko");
    $this->ClearLinkTable();
    $this->StartLinkTracking();
    $dummy = $this->Format($dummy, "post_wacko");
    $this->StopLinkTracking();
    $bml = $this->GetLinkTable();
    if ($this->GetPageSuperTag()!=$this->NpjTranslit($bml[0])) $newbm[] = $bm;
   }
   $bookmarks = $newbm;
   $this->Query("update ".$this->config["user_table"]." set ".
          "bookmarks = '".quote(implode("\n", $bookmarks))."' ".
          "where name = '".quote($user["name"])."' limit 1");

   $this->SetUser($this->LoadUser($user["name"]));
   $_SESSION["bookmarks"] = $bookmarks;
//$_SESSION["bookmarksfmt"] = $this->Format($this->Format(implode(" | ", $bookmarks), "wacko"), "post_wacko");
    $_SESSION["bookmarksfmt"] = $this->Format(implode(" | ", $bookmarks), "wacko");
    $bmlinks = $bookmarks; //ADW
    for ($i=0;$i<count($bmlinks);$i++) $bmlinks[$i] = trim($this->NpjTranslit($bmlinks[$i]),"()"); //ADW
    $_SESSION["bookmarklinks"] = $bmlinks; //ADW
  }
 }
 ?>