<?PHP
/************************************************************************/                                                                                                                                  /* DUNE by NPDS                                                         */
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2007 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) {
   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 $NPDS_Prefix;
    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 "<ul>
        <li>".translate("Submit a unique link only once.")."</li>
        <li>".translate("All links are posted pending verification.")."</li>
        <li>".translate("Username and IP are recorded, so please don't abuse the system.")."</li></ul>";
        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=sql_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) = sql_fetch_row($result)) {
           echo "<option value=\"$cid\">".aff_langue($title)."</option>";
           $result2=sql_query("select sid, title from ".$links_DB."links_subcategories where cid='$cid' order by title");
           while (list($sid, $stitle) = sql_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 = sql_query("select topicid, topictext from ".$NPDS_Prefix."topics order by topictext");
           echo "<option value=\"\">".translate("All Topics")."</option>\n";
           while(list($topicid, $topics) = sql_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 />";
        global $admin;
        if (!$admin)
           echo Q_spambot();
        echo "<input type=\"hidden\" name=\"op\" value=\"Add\">
        <input type=\"submit\" class=\"bouton_standard\" value=".translate("Add URL").">
        </form>";
    } else {
        echo "<p align=\"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 /></p>";
    }
    echo "</td></tr></table>";
    closetable();
    include("footer.php");
}

function Add($title, $url, $name, $cat, $description, $name, $email, $topicL, $asb_question, $asb_reponse) {
    global $ModPath, $ModStart, $links_DB, $troll_limit;

    global $user, $admin;
    if (!$user and !$admin) {
       //anti_spambot
       if (!R_spambot($asb_question, $asb_reponse, "")) {
          Ecr_Log("security", "Links Anti-Spam : url=".$url, "");
          redirect_url("index.php");
          die();
       }
    }

    $result = sql_query("select lid from ".$links_DB."links_newlink");
    $numrows = sql_num_rows($result);
    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)));
    sql_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 $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 = sql_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 = sql_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");
}
?>