<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* This module : MarqueTaPage  Copyright (c) 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.       */
/************************************************************************/
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);
      }
      @mysql_query("INSERT INTO ".$NPDS_Prefix."marquetapage (uid, uri, topic) VALUES ('$cookie[0]', '$uri', '$topic')");
      header("location: $uri");
   }
   if (($action=="sp_tapage") and ($cookie[0])) {
      $result = mysql_query("select uri from ".$NPDS_Prefix."marquetapage where uid='$cookie[0]' and uri='$uri'");
      if (mysql_num_rows($result) > 0) {
         @mysql_query("DELETE FROM ".$NPDS_Prefix."marquetapage WHERE uid='$cookie[0]' and uri='$uri'");
         header("location: $uri");
      }
   }
}

function marquetapage() {
   global $cookie;
   if ($cookie[0]!="") {
      global $REQUEST_URI, $title, $post, $NPDS_Prefix;
      $result=mysql_query("select uri, topic from ".$NPDS_Prefix."marquetapage where uid='$cookie[0]' order by topic ASC");
      if (mysql_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)=mysql_fetch_array($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=\"middle\"></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");
}
?>