<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System !                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* New Links.php Module with SFROM extentions                           */
/*                                                                      */
/* 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 (!eregi("modules.php", $PHP_SELF)) { die(); }

function error_head($class) {
   global $pdst; $pdst=1;
   include("header.php");
   $mainlink = 1;
   opentable();
   menu($mainlink);
   SearchForm();
   opentable();
   echo "<p class=\"$class\" align=\"center\">";
}
function error_foot() {
   echo "</p>";
   closetable();
   closetable();
   include("footer.php");
}

function AddLink() {
    global $ModPath, $ModStart, $links_DB;
    global $links_anonaddlinklock;
    include("header.php");
    OpenTable();
    $mainlink = 1;
    global $user;
    mainheader();
    echo "<br /><TABLE WIDTH=100% CELLSPACING=2 CELLPADDING=2 BORDER=0><tr><td>";
    if (autorisation($links_anonaddlinklock)) {
        echo "
        <LI>".translate("Submit a unique link only once.")."
        <LI>".translate("All links are posted pending verification.")."
        <LI>".translate("Username and IP are recorded, so please don't abuse the system.");
        echo "<form method=post action=modules.php name=adminForm>
              <input type=hidden name=ModPath value=$ModPath>
              <input type=hidden name=ModStart value=$ModStart>";
        echo "<TABLE WIDTH=100% CELLSPACING=2 CELLPADDING=2 BORDER=0>";
        echo "<tr><td WIDTH=15%>".translate("Title:")."</td><td><input class=textbox type=text name=title size=50 maxlength=100></td></tr>";
        global $links_url;
        if (($links_url) or ($links_url==-1))
           echo "<tr><td WIDTH=15%>URL :</td><td><input class=textbox type=text name=url size=50 maxlength=100 value=\"http://\"></td></tr>";
        $result=mysql_query("select cid, title from ".$links_DB."links_categories order by title");
        echo "<tr><td WIDTH=15%>".translate("Category: ")."</td><td><select CLASS=\"TEXTBOX_STANDARD\" name=cat>";
        while (list($cid, $title) = mysql_fetch_row($result)) {
           echo "<option value=$cid>".aff_langue($title)."</option>";
           $result2=mysql_query("select sid, title from ".$links_DB."links_subcategories where cid='$cid' order by title");
           while (list($sid, $stitle) = mysql_fetch_row($result2)) {
              echo "<option value=$cid-$sid>".aff_langue("$title / $stitle")."</option>";
           }
        }
        echo "</select></td></tr>";
        global $links_topic;
        if ($links_topic) {
           echo "<tr><td WIDTH=15%>".translate("Topics")." : </td><td><select CLASS=\"TEXTBOX_STANDARD\" name=topicL>";
           $toplist = mysql_query("select topicid, topictext from topics order by topictext");
           echo "<OPTION VALUE=\"\">".translate("All Topics")."</option>\n";
           while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
             echo "<option value=\"$topicid\">$topics</option>\n";
           }
           echo "</select></td></tr>";
        }
        echo "</table><br />
        ".translate("Description: (255 characters max)")."<br /><textarea class=\"textbox\" wrap=\"virtual\" name=\"xtext\" cols=\"60\" rows=\"10\" style=\"width: 100%;\"></textarea>";
        echo aff_editeur("xtext","false");
        echo "<br />";
        global $cookie;
        echo "<TABLE WIDTH=100% CELLSPACING=2 CELLPADDING=2 BORDER=0>";
        echo "<TR><TD WIDTH=15%>".translate("Your Name: ")."</TD><TD><input type=text CLASS=\"TEXTBOX_STANDARD\" name=name size=40 maxlength=60 value=\"$cookie[1]\"></TD></TR>
        <TR><TD WIDTH=15%>".translate("Your Email: ")."</TD><TD><input type=text CLASS=\"TEXTBOX_STANDARD\" name=email size=40 maxlength=60></TD></TR>
        </TABLE><br />
        <input type=hidden name=op value=Add>
        <input type=submit CLASS=\"BOUTON_STANDARD\" value=".translate("Add URL").">
        </form>";
    } else {
        echo "<center>".translate("You are not a registered user or you have not logged in.")."<br /><br />
        ".translate("If you were registered you could add links on this website.")."<br /></center>";
    }
    echo "</td></tr></table>";
    CloseTable();
    include("footer.php");
}

function Add($title, $url, $name, $cat, $description, $name, $email, $topicL) {
    global $ModPath, $ModStart, $links_DB, $troll_limit;
    $result = mysql_query("select lid from ".$links_DB."links_newlink");
    $numrows = mysql_num_rows($result);
    echo $numrows, $troll_limit;
    if ($numrows>=$troll_limit) {
       error_head("ROUGE");
       echo translate("ERROR: This URL is already listed in the Database!")."<br />";
       error_foot();
       exit();
    }
    global $user;
    if (isset($user)) {
       global $cookie;
       $submitter = $cookie[1];
    }
    if ($title=="") {
       error_head("ROUGE");
       echo translate("ERROR: You need to type a TITLE for your URL!")."<br />";
       error_foot();
       exit();
    }
    if ($email=="") {
       error_head("ROUGE");
       echo translate("ERROR: Invalid email")."<br />";
       error_foot();
       exit();
    }
    global $links_url;
    if (($url=="") and ($links_url==1)) {
       error_head("ROUGE");
       echo translate("ERROR: You need to type a URL for your URL!")."<br />";
       error_foot();
       exit();
    }
    if ($description=="") {
       error_head("ROUGE");
       echo translate("ERROR: You need to type a DESCRIPTION for your URL!")."<br />";
       error_foot();
       exit();
    }
    $cat = explode("-", $cat);
    if ($cat[1]=="") {
       $cat[1] = 0;
    }
    $title = removeHack(stripslashes(FixQuotes($title)));
    $url = removeHack(stripslashes(FixQuotes($url)));
    $description = removeHack(stripslashes(FixQuotes($description)));
    $name = removeHack(stripslashes(FixQuotes($name)));
    $email = removeHack(stripslashes(FixQuotes($email)));
    mysql_query("insert into ".$links_DB."links_newlink values (NULL, '$cat[0]', '$cat[1]', '$title', '$url', '$description', '$name', '$email', '$submitter', '$topicL')");
    error_head("NOIR");
    echo translate("We received your Link submission. Thanks!")."<br />";
    echo translate("You'll receive and E-mail when it's approved.")."<br /><br />";
    error_foot();
}

function links_search($query, $topicL, $min, $max) {
    global $pdst; $pdst=1;
    global $ModPath, $ModStart, $links_DB;

    $offset=10;
    if (!isset($min)) $min=0;
    if (!isset($max)) $max=$min+$offset;
    include ("header.php");

    OpenTable();
    mainheader();
    $filen="modules/$ModPath/links.ban_02.php";
    if (file_exists($filen)) {include($filen);}
    $query = removeHack(stripslashes(htmlspecialchars($query, ENT_QUOTES))); // Romano et NoSP

    if ($topicL!="") {
       $result = mysql_query("select lid, url, title, description, date, hits, topicid_card, cid, sid from ".$links_DB."links_links where topicid_card='$topicL' and (title LIKE '%$query%' OR description LIKE '%$query%') order by lid ASC LIMIT $min,$offset");
    } else {
       $result = mysql_query("select lid, url, title, description, date, hits, topicid_card, cid, sid from ".$links_DB."links_links where title LIKE '%$query%' OR description LIKE '%$query%' order by lid ASC LIMIT $min,$offset");
    }
    if ($result) {
      include_once("modules/$ModPath/links-view.php");
      $prev=$min-$offset;
      if ($prev>=0) {
          echo "$min <a href=\"modules.php?ModPath=$ModPath&amp;ModStart=$ModStart&amp;op=search&min=$prev&amp;query=$query&amp;topicL=$topicL\" class=\"NOIR\">";
          echo translate("previous matches")."</a>&nbsp;&nbsp;";
       }
       if ($x>=($offset-1)) {
          echo "<a href=\"modules.php?ModPath=$ModPath&amp;ModStart=$ModStart&amp;op=search&amp;min=$max&amp;query=$query&amp;topicL=$topicL\" class=\"NOIR\">";
          echo translate("next matches")."</a>";
       }
    }
    CloseTable();
    include("footer.php");
}
?>