<?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 (strstr($ModPath,"..") || strstr($ModStart,"..") || stristr($ModPath, "script") || stristr($ModPath, "cookie") || stristr($ModPath, "iframe") || stristr($ModPath, "applet") || stristr($ModPath, "object") || stristr($ModPath, "meta") || stristr($ModStart, "script") || stristr($ModStart, "cookie") || stristr($ModStart, "iframe") || stristr($ModStart, "applet") || stristr($ModStart, "object") || stristr($ModStart, "meta")) {
   die();
}
global $links_DB;
include_once("modules/$ModPath/links.conf.php");
global $pdst; $pdst="0";

function menu($mainlink) {
   global $ModPath, $ModStart, $links_anonaddlinklock;

   echo "<p align=\"center\"><table border=\"0\" cellpadding=\"1\" cellspacing=\"2\" width=\"80%\">";
   echo "<tr>";
   if ($mainlink>0) {
      echo "<td align=\"center\" valign=\"middle\" class=\"HEADER\"><a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath\" class=\"BOX\">".translate("Links Main")."</a></td>";
   }
   if (autorisation($links_anonaddlinklock))
      echo "<td align=\"center\" class=\"HEADER\"><a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=AddLink\" class=\"BOX\">".translate("Add Link")."</a></td>";
   echo "<td align=\"center\" class=\"HEADER\"><a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=NewLinks\" class=\"BOX\">".translate("New links")."</a></td>";
   echo "</tr></table></p>";
}

function SearchForm() {
   global $ModPath, $ModStart;
   echo "<p align=\"center\"><table border=\"0\" cellpadding=\"1\" cellspacing=\"2\" width=\"80%\"><tr>";
   echo "<form action=\"modules.php?ModStart=$ModStart&ModPath=$ModPath&op=search\" method=\"post\">";
   echo "<td align=\"left\"><input type=\"text\" class=\"TEXTBOX_STANDARD\" size=\"25\" name=\"query\"></td>";
   global $links_topic;
   if ($links_topic) {
      echo "<td align=\"center\"><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>";
   }
   echo "<td align=\"right\"><input type=\"submit\" class=\"BOUTON_STANDARD\" value=".translate("Search")."></td>";
   echo "</tr></form></table></p>";
}

function mainheader() {
   $mainlink = 1;
   menu($mainlink);
   SearchForm();
}

function autorise_mod($lid,$aff) {
   global $ModPath, $ModStart, $links_DB;
   global $user, $admin;

   if ($admin) {
      $Xadmin = base64_decode($admin);
      $Xadmin = explode(":", $Xadmin);
      $result = mysql_query("select radminlink, radminsuper from authors where aid='$Xadmin[0]'");
      list($radminlink, $radminsuper) = mysql_fetch_row($result);
      if (($radminlink==1) or ($radminsuper==1)) {
         if ($aff) {
            echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=modifylinkrequest&amp;lid=$lid&amp;author=-9\" class=\"NOIR\"><span style=\"font-size: 10px;\">".translate("Modify")."</span></a> ";
         }
         return(true);
      } else {
         return(false);
      }
   } elseif ($user!="") {
      global $cookie;
      $resultX=mysql_query("select submitter from ".$links_DB."links_links where submitter='$cookie[1]' and lid='$lid'");
      list($submitter) = mysql_fetch_array($resultX);
      if ($submitter==$cookie[1]) {
         if ($aff) {
            echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=modifylinkrequest&amp;lid=$lid&amp;author=$cookie[1]\" class=\"NOIR\"><span style=\"font-size: 10px;\">".translate("Modify")."</span></a> ";
         }
         return(true);
      } else {
         return(false);
      }
   } else {
      return(false);
   }
}

function index() {
   global $ModPath, $ModStart, $links_DB;
   include ("modules/$ModPath/links.conf.php");
   include("header.php");
   // Include cache manager
   global $SuperCache;
   if ($SuperCache) {
      $cache_obj = new cacheManager();
      $cache_obj->startCachingPage();
   }
   if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache)) {
      OpenTable();
      $mainlink = 0;
      menu($mainlink);
      SearchForm();

      $filen="modules/$ModPath/links.ban_01.php";
      if (file_exists($filen)) {include($filen);}

      echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr>";
      $result=mysql_query("select cid, title, cdescription from ".$links_DB."links_categories order by title");
      if ($result) {
         $count = 0;
         while (list($cid, $title, $cdescription) = mysql_fetch_row($result)) {
            $cresult = mysql_query("select lid from ".$links_DB."links_links where cid='$cid'");
            $cnumrows = mysql_num_rows($cresult);
            echo "<td valign=\"top\" width=\"200\" class=\"ONGL\">
            <a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid\" class=\"NOIR\">".aff_langue($title)."</a> <span style=\"font-size: 10px;\">[$cnumrows]</span>";
            categorynewlinkgraphic($cid);
            if ($cdescription) {
                echo "<br /><span style=\"font-size: 10px;\">".aff_langue($cdescription)."</span><br />";
            } else {
                echo "<br />";
            }
            $result2 = mysql_query("select sid, title from ".$links_DB."links_subcategories where cid='$cid' order by title $subcat_limit");
            $space = 0;
            while (list($sid, $stitle) = mysql_fetch_row($result2)) {
               if ($space>0) {
                  echo "<br />";
               }
               $cresult3 = mysql_query("select lid from ".$links_DB."links_links where sid='$sid'");
               $cnumrows="-: ".mysql_num_rows($cresult3);
               if ($cnumrows=="-: 0") {$cnumrows="";}
               echo "&nbsp;<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid\" class=\"NOIR\">".aff_langue($stitle)."</a> <span style=\"font-size: 10px;\">$cnumrows</span>";
               $space++;
            }
            if ($count<1) {
               echo "</td><td width=\"20\">&nbsp;</td>";
            }
            $count++;
            if ($count==2) {
               echo "</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr>";
               $count = 0;
            }
         }
      }
      echo "</td></tr></table>";
      $result=mysql_query("select lid from ".$links_DB."links_links");
      if ($result) {
         $numrows = mysql_num_rows($result);
         echo "<br /><br /><p align=\"center\"><span style=\"font-size: 10px;\">".translate("There are")." <b>$numrows</b> ".translate("Links in our Database")." -::- ";
         if ($ibid=theme_image("links/newred.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newred.gif";}
         echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added Today")."\" border=\"0\" /> -:-";
         if ($ibid=theme_image("links/newgreen.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newgreen.gif";}
         echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added in the last 3 days")."\" border=\"0\" /> -:-";
         if ($ibid=theme_image("links/newblue.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newblue.gif";}
         echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added this week")."\" border=\"0\" />";
         echo "</span></p>";
      }
      CloseTable();
   }
   if ($SuperCache) {
      $cache_obj->endCachingPage();
   }
   global $admin;
   if ($admin) {
      opentable();
      $result = mysql_query("select requestid from ".$links_DB."links_modrequest where brokenlink=1");
      if ($result) {
         $totalbrokenlinks = mysql_num_rows($result);
         $result2 = mysql_query("select requestid from ".$links_DB."links_modrequest where brokenlink=0");
         $totalmodrequests = mysql_num_rows($result2);
         $result = mysql_query("select lid from ".$links_DB."links_newlink");
         $num = mysql_num_rows($result);
         echo "<p align=\"center\"><span style=\"font-size: 10px;\">-: ".translate("Waiting Links")." : $num / $totalbrokenlinks / $totalmodrequests";
         echo " :: <a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath/admin\" class=\"NOIR\">Admin</a> :: Ref Tables => <b>$links_DB</b> :-</span></p>";
      } else {
         echo "<p align=\"center\"><span style=\"font-size: 10px;\"> -: [ <a href=\"modules.php?ModStart=create_tables&amp;ModPath=$ModPath/admin/\" class=\"NOIR\">".translate("Create")."</a> Tables : $links_DB ] :-</span></p>";
      }
      closetable();
   }
   include("footer.php");
}

function FooterOrderBy($cid, $sid, $orderbyTrans, $linkop) {
   global $ModPath, $ModStart;
   echo "<p align=\"center\"><span style=\"font-size: 10px;\">".translate("Sort links by")." : ";
   if ($linkop=="viewlink") {
      echo translate("Title")." (<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid&amp;orderby=titleA\" class=\"NOIR\">A</a>\<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid&amp;orderby=titleD\" class=\"NOIR\">D</a>)
          ".translate("Date")." (<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid&amp;orderby=dateA\" class=\"NOIR\">A</a>\<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid&amp;orderby=dateD\" class=\"NOIR\">D</a>)";
   } else {
      echo translate("Title")." (<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid&amp;orderby=titleA\" class=\"NOIR\">A</a>\<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid&amp;orderby=titleD\" class=\"NOIR\">D</a>)
          ".translate("Date")." (<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid&amp;orderby=dateA\" class=\"NOIR\">A</a>\<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid&amp;orderby=dateD\" class=\"NOIR\">D</a>)";
   }
   echo "<br />".translate("Sites currently sorted by")." : $orderbyTrans</span></p>";
}

function viewlink($cid, $min, $orderby, $show) {
   global $ModPath, $ModStart, $links_DB;
   global $admin, $perpage, $show;

   include("header.php");
   // Include cache manager
   global $SuperCache;
   if ($SuperCache) {
      $cache_obj = new cacheManager();
      $cache_obj->startCachingPage();
   }
   if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache)) {
      OpenTable();
      if (!isset($min)) $min=0;
      if (!isset($max)) $max=$min+$perpage;
      if (isset($orderby)) $orderby = convertorderbyin($orderby);
      else $orderby = "title ASC";
      if ($show!="") $perpage = $show;
      else $show=$perpage;
      mainheader();

      $filen="modules/$ModPath/links.ban_02.php";
      if (file_exists($filen)) {include($filen);}
      $result=mysql_query("select title from ".$links_DB."links_categories where cid='$cid'");
      list($title) = mysql_fetch_row($result);
      echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td class=\"HEADER\">\n";
      echo aff_langue($title)." : ".translate("SubCategories");
      echo "</td></tr></table>\n";

      $subresult=mysql_query("select sid, title from ".$links_DB."links_subcategories where cid='$cid' order by title");
      $numrows = mysql_num_rows($subresult);
      if ($numrows != 0) {
         echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
         while(list($sid, $title) = mysql_fetch_row($subresult)) {
            $rowcolor = tablos();
            $result2 = mysql_query("select lid from ".$links_DB."links_links where sid='$sid'");
            $numrows="-: ".mysql_num_rows($result2);
            if ($numrows=="-: 0") {$numrows="";}
            echo "<tr><td width=\"5%\">&nbsp;</td><td class=\"ONGL\"><a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid\" class=\"NOIR\">".aff_langue($title)."</a> $numrows</td></tr>";
         }
         echo "</table>";
      }
      $orderbyTrans = convertorderbytrans($orderby);
      settype($min,"integer");
      settype($perpage,"integer");
      $result=mysql_query("select lid, url, title, description, date, hits, topicid_card from ".$links_DB."links_links where cid='$cid' AND sid=0 order by $orderby limit $min,$perpage");
      $fullcountresult=mysql_query("select lid, title, description, date, hits from ".$links_DB."links_links where cid='$cid' AND sid=0");
      $totalselectedlinks = Mysql_num_rows($fullcountresult);
      echo "<br />\n";
      include_once("modules/$ModPath/links-view.php");
      echo "<br />\n";

      $orderby = convertorderbyout($orderby);
      //Calculates how many pages exist.  Which page one should be on, etc...
      $linkpagesint = ($totalselectedlinks / $perpage);
      $linkpageremainder = ($totalselectedlinks % $perpage);

      if ($linkpageremainder != 0) {
         $linkpages = ceil($linkpagesint);
         if ($totalselectedlinks < $perpage) {
            $linkpageremainder = 0;
         }
      } else {
         $linkpages = $linkpagesint;
      }
      //Page Numbering
      if ($linkpages!=1 && $linkpages!=0) {
         echo "<p align=\"center\">";
         echo translate("Select page")." :&nbsp&nbsp";
         $prev=$min-$perpage;
         $counter = 1;
         $currentpage = ($max / $perpage);
         while ($counter<=$linkpages ) {
            $cpage = $counter;
            $mintemp = ($perpage * $counter) - $perpage;
            if ($counter == $currentpage) echo "<span class=\"ROUGE\">$counter</span>&nbsp";
            else echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\" class=\"NOIR\">$counter</a>&nbsp";
            $counter++;
         }
      }
      echo "</p><br />";
      FooterOrderBy($cid, $sid, $orderbyTrans, "viewlink");
      CloseTable();
   }
   if ($SuperCache) {
      $cache_obj->endCachingPage();
   }
   include("footer.php");
}

function viewslink($sid, $min, $orderby, $show) {
   global $ModPath, $ModStart, $links_DB;
   global $admin, $perpage;

   include("header.php");
   // Include cache manager
   global $SuperCache;
   if ($SuperCache) {
      $cache_obj = new cacheManager();
      $cache_obj->startCachingPage();
   }
   if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache)) {
      OpenTable();
      mainheader();

      $filen="modules/$ModPath/links.ban_03.php";
      if (file_exists($filen)) {include($filen);}

      if (!isset($min)) $min=0;
      if (!isset($max)) $max=$min+$perpage;
      if(isset($orderby)) $orderby = convertorderbyin($orderby);
      else $orderby = "title ASC";
      if ($show!="") $perpage = $show;
      else $show=$perpage;

      $result = mysql_query("select cid, title from ".$links_DB."links_subcategories where sid='$sid'");
      list($cid, $stitle) = mysql_fetch_row($result);

      $result2 = mysql_query("select cid, title from ".$links_DB."links_categories where cid='$cid'");
      list($cid, $title) = mysql_fetch_row($result2);

      echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td class=\"HEADER\">\n";
      echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath\" class=\"BOX\">".translate("Main")."</a> / <a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlink&amp;cid=$cid\" class=\"BOX\">".aff_langue($title)."</a> / ".aff_langue($stitle);
      echo "</td></tr></table>";

      $orderbyTrans = convertorderbytrans($orderby);
      settype($min,"integer");
      settype($perpage,"integer");
      $result=mysql_query("select lid, url, title, description, date, hits, topicid_card from ".$links_DB."links_links where sid='$sid' order by $orderby limit $min,$perpage");
      $fullcountresult=mysql_query("select lid, title, description, date, hits from ".$links_DB."links_links where sid='$sid'");
      $totalselectedlinks = Mysql_num_rows($fullcountresult);
      echo "<br />\n";
      include_once("modules/$ModPath/links-view.php");
      echo "<br />\n";

      $orderby = convertorderbyout($orderby);
      //Calculates how many pages exist.  Which page one should be on, etc...
      $linkpagesint = ($totalselectedlinks / $perpage);
      $linkpageremainder = ($totalselectedlinks % $perpage);

      if ($linkpageremainder != 0) {
         $linkpages = ceil($linkpagesint);
         if ($totalselectedlinks < $perpage) {
            $linkpageremainder = 0;
         }
      } else {
         $linkpages = $linkpagesint;
      }
      //Page Numbering
      if ($linkpages!=1 && $linkpages!=0) {
         echo "<p align=\"center\">";
         echo translate("Select page")." :&nbsp&nbsp";
         $prev=$min-$perpage;
         $counter = 1;
         $currentpage = ($max / $perpage);
         while ($counter<=$linkpages ) {
            $cpage = $counter;
            $mintemp = ($perpage * $counter) - $perpage;
            if ($counter == $currentpage) echo "<FONT class=\"ROUGE\">$counter</FONT>&nbsp";
            else echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewslink&amp;sid=$sid&amp;min=$mintemp&amp;orderby=$orderby&amp;show=$show\" class=\"NOIR\">$counter</a>&nbsp";
            $counter++;
         }
      }
      echo "</p><br />";
      FooterOrderBy($cid, $sid, $orderbyTrans, "viewslink");
      CloseTable();
   }
   if ($SuperCache) {
      $cache_obj->endCachingPage();
   }
   include("footer.php");
}

function fiche_detail ($Xlid, $Xsid) {
    include("header.php");
    // Include cache manager
    global $SuperCache;
    if ($SuperCache) {
       $cache_obj = new cacheManager();
       $cache_obj->startCachingPage();
    }
    if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache)) {
       OpenTable();
       $browse_key=$Xlid;
       $sid=$Xsid;
       $link_fiche_detail="fiche_detail";
       $inter="cid";
       include ("modules/sform/links/link_detail.php");
       CloseTable();
    }
    if ($SuperCache) {
       $cache_obj->endCachingPage();
    }
    include("footer.php");
}

function categorynewlinkgraphic($cat) {
    global $OnCatNewLink, $locale, $links_DB;
    if ($OnCatNewLink=="1") {
       $newresult = mysql_query("select date from ".$links_DB."links_links where cid='$cat' order by date desc limit 1");
       list($time)=mysql_fetch_row($newresult);

       setlocale (LC_TIME, aff_langue($locale));
       ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
       $count = round((time()- mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]))/86400,0);
       popgraphics($count);
    }
}

function popgraphics($count) {
   echo "&nbsp";
   if ($ibid=theme_image("links/newred.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newred.gif";}
   if ($count<1) echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added Today")."\" border=\"0\" />";
   if ($ibid=theme_image("links/newgreen.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newgreen.gif";}
   if ($count<=3 && $count>=1) echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added in the last 3 days")."\" border=\"0\" />";
   if ($ibid=theme_image("links/newblue.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/links/newblue.gif";}
   if ($count<=7 && $count>3) echo "<img src=\"$imgtmp\" alt=\"".translate("New Links in this Category Added this week")."\" border=\"0\" />";
}

function newlinkgraphic($datetime, $time) {
   global $locale;
   setlocale (LC_TIME, aff_langue($locale));
   ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
   $count = round((time()- mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]))/86400,0);
   popgraphics($count);
}

function detecteditorial($lid, $ttitle) {
   global $ModPath, $ModStart, $links_DB;
   $resulted2 = mysql_query("select adminid from ".$links_DB."links_editorials where linkid='$lid'");
   $recordexist = Mysql_num_rows($resulted2);
   if ($recordexist != 0) echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=viewlinkeditorial&amp;lid=$lid&amp;ttitle=$ttitle\" class=\"NOIR\">".translate("EDITO")."</a> ";
}

//Reusable Link Sorting Functions
function convertorderbyin($orderby) {
    if ($orderby == "titleA")                       $orderby = "title ASC";
    if ($orderby == "dateA")                        $orderby = "date ASC";
    if ($orderby == "titleD")                       $orderby = "title DESC";
    if ($orderby == "dateD")                        $orderby = "date DESC";
    return $orderby;
}

function convertorderbytrans($orderby) {
    if ($orderby == "title ASC")                    $orderbyTrans = "".translate("Title (A to Z)")."";
    if ($orderby == "title DESC")                   $orderbyTrans = "".translate("Title (Z to A)")."";
    if ($orderby == "date ASC")                     $orderbyTrans = "".translate("Date (Old Links Listed First)")."";
    if ($orderby == "date DESC")                    $orderbyTrans = "".translate("Date (New Links Listed First)")."";
    return $orderbyTrans;
}

function convertorderbyout($orderby) {
    if ($orderby == "title ASC")                   $orderby = "titleA";
    if ($orderby == "date ASC")                    $orderby = "dateA";
    if ($orderby == "title DESC")                  $orderby = "titleD";
    if ($orderby == "date DESC")                   $orderby = "dateD";
    return $orderby;
}

function visit($lid) {
    global $links_DB;
    mysql_query("update ".$links_DB."links_links set hits=hits+1 where lid='$lid'");
    $result = mysql_query("select url from ".$links_DB."links_links where lid='$lid'");
    list($url) = mysql_fetch_row($result);
    Header("Location: $url");
}

function viewlinkeditorial($lid, $ttitle) {
    global $ModPath, $ModStart, $links_DB;
    include("header.php");
    OpenTable();
    mainheader();

    $result=mysql_query("SELECT adminid, editorialtimestamp, editorialtext, editorialtitle FROM ".$links_DB."links_editorials WHERE linkid = '$lid'");
    $recordexist = Mysql_num_rows($result);

    $displaytitle = stripslashes($ttitle);
    echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\" class=\"HEADER\"><tr><td>\n";
    echo translate("EDITO")." : ".aff_langue($displaytitle);
    echo "</td></tr></table>\n";
    echo "<br />\n";
    if ($recordexist!= 0) {
       while (list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle)=mysql_fetch_row($result)) {
          $editorialtitle = stripslashes($editorialtitle); $editorialtext = stripslashes($editorialtext);
          $formatted_date=formatTimestamp($editorialtimestamp);
          echo "<table width=\"85%\" border=\"0\" cellspacing=\"1\" cellpadding=\"7\" align=\"center\" class=\"HEADER\">
                <tr><td align=\"center\">
                <b>'".aff_langue($editorialtitle)."'</b><br /><br />
                ".translate("Editorial by")." $adminid - $formatted_date</td></tr>
                <tr><td align=\"left\"><hr noshade class=\"ONGL\">".aff_langue($editorialtext)."</td></tr></table>";
       }
    } else {
       echo "<br /><p align=\"center\">".translate("No editorial is currently available for this website.")."</p><br />";
    }
    echo "<br />";
    $result = mysql_query("select url from ".$links_DB."links_links where lid='$lid'");
    list($url) = mysql_fetch_row($result);
    if ($url!="")
       echo "<a href=\"modules.php?ModStart=$ModStart&amp;ModPath=$ModPath&amp;op=visit&amp;lid=$lid\" target=\"_blank\" class=\"NOIR\">".translate("Visit this Website")."</a>";
    CloseTable();
    mysql_free_result;
    include("footer.php");
}

function formatTimestampShort($time) {
   global $datetime, $locale, $gmt;
   setlocale (LC_TIME, aff_langue($locale));
   ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
   $datetime = strftime("".translate("linksdatestring")."", mktime($datetime[4]+$gmt,$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
   if (cur_charset!="utf-8") {
      $datetime = ucfirst($datetime);
   }
   return($datetime);
}

switch($op) {

    case "menu":
        $pdst="1";
        menu($mainlink);
        break;

    case "AddLink":
        include_once("modules/$ModPath/links-1.php");
        AddLink();
        break;
    case "Add":
        include_once("modules/$ModPath/links-1.php");
        Add($title, $url, $name, $cat, $xtext, $name, $email, $topicL);
        break;

    case "NewLinks":
        include_once("modules/$ModPath/links-2.php");
        NewLinks($newlinkshowdays);
        break;
    case "NewLinksDate":
        include_once("modules/$ModPath/links-2.php");
        NewLinksDate($selectdate);
        break;

    case "viewlink":
        $pdst="1";
        viewlink($cid, $min, $orderby, $show);
        break;
    case "viewslink":
        $pdst="1";
        viewslink($sid, $min, $orderby, $show);
        break;

    case "brokenlink":
        include_once("modules/$ModPath/links-3.php");
        brokenlink($lid);
        break;
    case "brokenlinkS":
        include_once("modules/$ModPath/links-3.php");
        brokenlinkS($lid, $modifysubmitter);
        break;

    case "modifylinkrequest":
        include_once("modules/$ModPath/links-3.php");
        modifylinkrequest($lid, $modifylinkrequest_adv_infos, $author);
        break;
    case "modifylinkrequestS":
        include_once("modules/$ModPath/links-3.php");
        modifylinkrequestS($lid, $cat, $title, $url, $xtext, $modifysubmitter, $topicL);
        break;

    case "visit":
        visit($lid);
        break;

    case "search":
        include_once("modules/$ModPath/links-1.php");
        links_search($query, $topicL, $min, $max);
        break;

    case "viewlinkeditorial":
            viewlinkeditorial($lid, $ttitle);
        break;
    case "fiche_detail":
            fiche_detail ($lid,$sid);
        break;

    default:
        $pdst="1";
        index();
        break;
}
?>