<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* This module : MarqueTaPage  Copyright (c) 2008 by Philippe Brunier   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2008 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.       */
/************************************************************************/
include_once("lib/togglediv.class.php");

function marquetapage_add($uri, $topic, $action) {
   global $cookie, $NPDS_Prefix, $nuke_url;
   if (($action=="ad_tapage") and ($cookie[0])) {
      $drname=dirname($uri);
      if ($drname==".") {
         $uri=$nuke_url."/".$uri;
      } elseif($drname=="/") {
         $uri=$nuke_url.$uri;
      } else {
         $uri=$nuke_url.str_replace("/".basename($nuke_url),"",$uri);
      }
      sql_query("INSERT INTO ".$NPDS_Prefix."marquetapage (uid, uri, topic) VALUES ('$cookie[0]', '$uri', '$topic')");
      redirect_url($uri);
   }
   if (($action=="sp_tapage") and ($cookie[0])) {
      $result = sql_query("select uri from ".$NPDS_Prefix."marquetapage where uid='$cookie[0]' and uri='$uri'");
      if (sql_num_rows($result) > 0) {
         sql_query("DELETE FROM ".$NPDS_Prefix."marquetapage WHERE uid='$cookie[0]' and uri='$uri'");
         redirect_url($uri);
      }
   }
}

function marquetapage() {
   global $cookie;
   if ($cookie[0]!="") {
      global $REQUEST_URI, $title, $post, $NPDS_Prefix;
      $result=sql_query("select uri, topic from ".$NPDS_Prefix."marquetapage where uid='$cookie[0]' order by topic ASC");
      if (sql_num_rows($result)) {
         $Configure_ToggleDiv = new ToggleDiv(1);
         $tmp_toggle=$Configure_ToggleDiv->Img();
         $content=$Configure_ToggleDiv->Begin()."<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">";
         while(list($uri, $topic)=sql_fetch_row($result)) {
            $content.="<tr><td align=\"left\" width=\"95%\"><a href=\"$uri\" style=\"font-size: 10px;\">".$topic."</a></td>";
            $content.="<td align=\"right\"><a href=\"modules.php?ModPath=marquetapage&amp;ModStart=marquetapage&amp;op=supp&amp;uri=".urlencode($uri)."\"><img src=\"modules/marquetapage/del.gif\" border=\"0\" alt=\"\" title=\"\" align=\"center\" /></a></td></tr>";
         }
         $content.="</table>";
         $content.=$Configure_ToggleDiv->End();
      }
      global $block_title;
      if ($block_title=="")
         $boxTitle=$tmp_toggle." MarqueTaPage";
      else
         $boxTitle=$tmp_toggle." ".$block_title;
      $uri=urlencode($REQUEST_URI);
      if ($post) {$title.="/".$post;}
      if ($title=="") {$title_MTP=basename(urldecode($uri));} else {$title_MTP=$title;}
      $boxTitle.="&nbsp;&nbsp;|&nbsp;<a href=\"modules.php?ModPath=marquetapage&amp;ModStart=marquetapage&amp;op=add&amp;uri=$uri&amp;topic=".urlencode($title_MTP)."\"><img src=\"modules/marquetapage/add.gif\" border=\"0\" alt=\"".translate("Add")." ".translate("favourite")."\" title=\"".translate("Add")." ".translate("favourite")."\" align=\"bottom\" /></a>";
      themesidebox($boxTitle, $content);
   }
}

if ($op=="add") {
   marquetapage_add(removeHack($uri),removeHack($topic),"ad_tapage");
}
if ($op=="supp") {
   marquetapage_add(removeHack($uri),"","sp_tapage");
}
?>