<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x                                                 */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2007 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.       */
/************************************************************************/
function Access_Error () {
  include("admin/die.php");
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }

global $language, $NPDS_Prefix;
$hlpfile = "manuels/$language/weblinks.html";
$result = sql_query("select radminlink, radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminlink, $radminsuper) = sql_fetch_row($result);
if (($radminlink!=1) and ($radminsuper!=1)) {
   Access_Error();
}

// valeur du pas de pagination
$rupture=100;

function links() {
    global $NPDS_Prefix;
    global $hlpfile;
    include ("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    $result=sql_query("select * from ".$NPDS_Prefix."links_links");
    $numrows = sql_num_rows($result);
    $result = sql_query("select * from ".$NPDS_Prefix."links_modrequest where brokenlink=1");
    $totalbrokenlinks = sql_num_rows($result);
    $result2 = sql_query("select * from ".$NPDS_Prefix."links_modrequest where brokenlink=0");
    $totalmodrequests = sql_num_rows($result2);
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Liens");
    echo " - ".adm_translate("Il y a")." <b>$numrows</b> ".adm_translate("Liens")."</td></tr>";
    echo "<tr><td align=\"center\"><br />[ <a href=\"admin.php?op=LinksListBrokenLinks\" class=\"noir\">".adm_translate("Soumission de Liens brisés")." ($totalbrokenlinks)</a> -
    <a href=\"admin.php?op=LinksListModRequests\" class=\"noir\">".adm_translate("Proposition de modifications de Liens")." ($totalmodrequests)</a> ]";
    echo "</td></tr></table><br />\n";

    $result = sql_query("select lid, cid, sid, title, url, description, name, email, submitter from ".$NPDS_Prefix."links_newlink ORDER BY lid ASC LIMIT 0,1");
    $numrows = sql_num_rows($result);
    $adminform="";
    if ($numrows>0) {
       $adminform="adminForm";
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
       echo adm_translate("Liens en attente de validation");
       echo "</td></tr></table>\n";
       echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
       list($lid, $cid, $sid, $title, $url, $xtext, $name, $email, $submitter) = sql_fetch_row($result);
          $rowcolor = tablos();
          echo "<tr $rowcolor><td>";
          echo "<form action=\"admin.php\" method=\"post\" name=\"$adminform\">";
          echo adm_translate("Lien N° : ")."<b>$lid</b> - ".adm_translate("Auteur")." : $submitter <br /><br />";
          echo adm_translate("Titre de la Page : ")."<br /><input class=\"textbox\" type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\"><br /><br />";
          echo adm_translate("URL de la Page : ")."<br /><input class=\"textbox\" type=\"text\" name=\"url\" value=\"$url\" size=\"50\" maxlength=\"100\"> - [ <a href=\"$url\" target=\"_blank\" class=\"noir\">".adm_translate("Visite")."</a> ]<br /><br />";
          echo adm_translate("Description : ")."<br /><textarea class=\"textbox\" name=\"xtext\" cols=\"60\" rows=\"10\" style=\"width: 100%;\">$xtext</textarea><br /><br />";
          echo aff_editeur("xtext","false");
          echo adm_translate("Nom : ")."<input class=\"textbox_standard\" type=\"text\" name=\"name\" size=\"40\" maxlength=\"100\" value=\"$name\"> - ";
          echo adm_translate("E-mail : ")."<input class=\"textbox_standard\" type=\"text\" name=\"email\" size=\"40\" maxlength=\"100\" value=\"$email\"><br />";
          $result2=sql_query("select cid, title from ".$NPDS_Prefix."links_categories order by title");
          echo "<input type=\"hidden\" name=\"new\" value=\"1\">";
          echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
          echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">";
          echo "<br />".adm_translate("Catégorie : ")."<select class=\"textbox_standard\" name=\"cat\">";
          while(list($ccid, $ctitle) = sql_fetch_row($result2)) {
             $sel = "";
             if ($cid==$ccid AND $sid==0) {
                $sel = "selected";
             }
             echo "<option value=\"$ccid\" $sel>".aff_langue($ctitle)."</option>";
             $result3=sql_query("select sid, title from ".$NPDS_Prefix."links_subcategories where cid='$ccid' order by title");
             while (list($ssid, $stitle) = sql_fetch_row($result3)) {
                $sel = "";
                if ($sid==$ssid) {
                   $sel = "selected";
                }
                echo "<option value=\"$ccid-$ssid\" $sel>".aff_langue($ctitle)." / ".aff_langue($stitle)."</option>";
             }
          }
          echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\">";
          echo "</select> - <input type=\"hidden\" name=\"op\" value=\"LinksAddLink\"><input class=\"bouton_standard\" type=\"submit\" value=".adm_translate("Ajouter")."> - [ <a href=\"admin.php?op=LinksDelNew&amp;lid=$lid\" class=\"rouge\">".adm_translate("Effacer")."</a> ]";
          echo "</form></td></tr></table><br />";
       // Fin de List
    }

    // Add a New Link to Database
    $result = sql_query("select cid, title from ".$NPDS_Prefix."links_categories");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
       echo adm_translate("Ajouter un nouveau Lien");
       echo "</td></tr></table>\n";
       if ($adminform=="") {
          echo "<form method=\"post\" action=\"admin.php\" name=\"adminForm\">";
       } else {
          echo "<form method=\"post\" action=\"admin.php\">";
       }
       echo adm_translate("Titre de la Page : ")."<input class=\"textbox\" type=\"text\" name=\"title\" size=\"50\" maxlength=\"100\"><br /><br />
       ".adm_translate("URL de la Page : ")."<input class=\"textbox\" type=\"text\" name=\"url\" size=\"50\" maxlength=\"100\" value=\"http://\"><br /><br />";
       $result=sql_query("select cid, title from ".$NPDS_Prefix."links_categories order by title");
       echo adm_translate("Catégorie : ")."<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 ".$NPDS_Prefix."links_subcategories where cid='$cid' order by title");
         while(list($sid, $stitle) = sql_fetch_row($result2)) {
            echo "<option value=\"$cid-$sid\">".aff_langue($title)." / ".aff_langue($stitle)."</option>";
         }
       }
       echo "</select><br /><br />
       ".adm_translate("Description :  (255 caractères max)")."<br /><textarea class=\"textbox\" wrap=\"virtual\" name=\"xtext\" cols=\"70\" rows=\"10\" style=\"width: 100%;\"></textarea>";
       if ($adminform=="")
          echo aff_editeur("xtext","false");
       echo "<br /><br />";

       echo adm_translate("Nom : ")."<input class=\"textbox_standard\" type=\"text\" name=\"name\" size=\"30\" maxlength=\"60\"> -
       ".adm_translate("E-mail : ")."<input class=\"textbox_standard\" type=\"text\" name=\"email\" size=\"30\" maxlength=\"60\"><br /><br />
       <input type=\"hidden\" name=\"op\" value=\"LinksAddLink\">
       <input type=\"hidden\" name=\"new\" value=\"0\">
       <input type=\"hidden\" name=\"lid\" value=\"0\">
       <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter une URL")."\">
       </form>";
    }
    echo "<br />";

    // Add a Main category
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Ajouter une Catégorie principale");
    echo "</td></tr></table>\n";
    echo "<br />
    <form action=\"admin.php\" method=\"post\">
    ".adm_translate("Nom : ")."<input class=\"textbox\" type=\"text\" name=\"title\" size=\"30\" maxlength=\"100\"><br /><br />
    ".adm_translate("Description : ")."<br /><textarea class=\"textbox\" name=\"cdescription\" cols=\"60\" rows=\"7\" style=\"width: 100%;\"></textarea><br /><br />
    <input type=\"hidden\" name=\"op\" value=\"LinksAddCat\">
    <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\">
    </form>";
    echo "<br />";

    // Add a New Sub-Category
    $result = sql_query("select * from ".$NPDS_Prefix."links_categories");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
       echo adm_translate("Ajouter une Sous-catégorie");
       echo "</td></tr></table>\n";
       echo "<form method=\"post\" action=\"admin.php\">
       ".adm_translate("Nom : ")."<input class=\"textbox\" type=\"text\" name=\"title\" size=\"30\" maxlength=\"100\" style=\"width:70%;\">&nbsp;".adm_translate("dans")."&nbsp;";
       $result=sql_query("select cid, title from ".$NPDS_Prefix."links_categories order by title");
       echo "<select class=\"textbox_standard\" name=\"cid\">";
       while(list($ccid, $ctitle) = sql_fetch_row($result)) {
          echo "<option value=\"$ccid\">".aff_langue($ctitle)."</option>";
       }
       echo "</select>
       <input type=\"hidden\" name=\"op\" value=\"LinksAddSubCat\">
       <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\"><br />
       </form>";
    }
    echo "<br />";

    // Modify Category
    $result = sql_query("select * from ".$NPDS_Prefix."links_categories");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
       echo adm_translate("Modifier la Catégorie");
       echo "</td></tr></table>\n";
       echo "<form method=\"post\" action=\"admin.php\">";
       $result=sql_query("select cid, title from ".$NPDS_Prefix."links_categories order by title");
       echo adm_translate("Catégorie : ")."<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 ".$NPDS_Prefix."links_subcategories where cid='$cid' order by title");
          while(list($sid, $stitle) = sql_fetch_row($result2)) {
             echo "<option value=\"$cid-$sid\">".aff_langue($title)." / ".aff_langue($stitle)."</option>";
          }
       }
       echo "</select>
       <input type=\"hidden\" name=\"op\" value=\"LinksModCat\"> -
       <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Modifier")."\">
       </form>";
    }
    echo "<br />";

    // Modify Links
    $result=sql_query("select lid from ".$NPDS_Prefix."links_links");
    $numrow=sql_num_rows($result);
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Modifier les Liens")." ($numrow)";
    echo "</td></tr></table>\n";
    echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
    echo "<tr><td><b>ID</b></td><td><b>".adm_translate("Titre")."</b></td><td><b>URL</b></td></tr>";
    global $rupture,$deja_affiches;
    settype ($deja_affiches, "integer");
    if ($deja_affiches<0) {$sens=-1;} else {$sens=+1;}
    $deja_affiches=abs($deja_affiches);
    $result = sql_query("select lid, title, url from ".$NPDS_Prefix."links_links order by lid ASC LIMIT $deja_affiches,$rupture");
    while (list($lid, $title, $url) = sql_fetch_row($result)) {
       $rowcolor = tablos();
       echo "<tr $rowcolor>";
       echo "<td nowrap=\"nowrap\">$lid</td>";
       echo "<td width=\"75%\"><a href=\"admin.php?op=LinksModLink&amp;lid=$lid\" class=\"noir\">$title</a></td>";
       echo "<td nowrap=\"nowrap\">$url</td>";
       echo "</tr>";
    }
    $deja_affiches_plus=$deja_affiches+$rupture;
    $deja_affiches_moin=$deja_affiches-$rupture;
    echo "<tr><td colspan=\"3\">";
    $precedent=false;
    if ($deja_affiches>=$rupture)  {
       echo "<a href=\"admin.php?op=suite_links&amp;deja_affiches=-".$deja_affiches_moin."\" class=\"noir\">".adm_translate("Précédent")."</a>";
       $precedent=true;
    }
    if ($deja_affiches_plus<$numrow) {
       if ($precedent) echo "&nbsp;|&nbsp;";
       echo "<a href=\"admin.php?op=suite_links&amp;deja_affiches=".$deja_affiches_plus."\" class=\"noir\">".adm_translate("Suivant")."</a>";
    }
    echo "</td></r></table>";
    closetable();
    include ("footer.php");
}

function LinksModLink($lid) {
    global $NPDS_Prefix;
    global $hlpfile;
    include ("header.php");
    GraphicAdmin($hlpfile);
    global $anonymous;
    $result = sql_query("select cid, sid, title, url, description, name, email, hits from ".$NPDS_Prefix."links_links where lid='$lid'");
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Modifier les Liens")." - ".adm_translate("Lien N° : ")."<b>$lid</b>";
    echo "</td></tr></table>\n";
    echo "<br />\n";
    list($cid, $sid, $title, $url, $xtext, $name, $email, $hits) = sql_fetch_row($result);
    $title = stripslashes($title); $xtext = stripslashes($xtext);
    echo "<form action=admin.php method=post name=adminForm>";
    echo adm_translate("Titre de la Page : ")."<br /><input class=\"textbox\" type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\"><br /><br />";
    echo adm_translate("URL de la Page : ")."<br /><input class=\"textbox\" type=\"text\" name=\"url\" value=\"$url\" size=\"40\" maxlength=\"100\"> -[ <a href=\"$url\" target=\"_blank\" class=\"noir\">".adm_translate("Visite")."</a> ]<br /><br />";
    echo adm_translate("Description : ")."<br /><textarea class=\"textbox\" wrap=\"virtual\" name=\"xtext\" cols=\"70\" rows=\"10\" style=\"width: 100%;\">$xtext</textarea>";
    echo aff_editeur("xtext","false");
    echo "<br /><br />";
    echo adm_translate("Nom : ")."<input class=\"textbox_standard\" type=\"text\" name=\"name\" size=\"30\" maxlength=\"100\" value=\"$name\"> - ";
    echo adm_translate("E-mail : ")."<input class=\"textbox_standard\" type=\"text\" name=\"email\" size=\"30\" maxlength=\"100\" value=\"$email\"><br /><br />";
    echo adm_translate("Nombre de Hits : ")."<input class=\"textbox_standard\" type=\"text\" name=\"hits\" value=\"$hits\" size=\"12\" maxlength=\"11\"> - ";
    $result2=sql_query("select cid, title from ".$NPDS_Prefix."links_categories order by title");
    echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
    echo adm_translate("Catégorie : ")."<select class=\"textbox_standard\" name=\"cat\">";
    while (list($ccid, $ctitle) = sql_fetch_row($result2)) {
       $sel = "";
       if ($cid==$ccid AND $sid==0) {
          $sel = "selected";
       }
       echo "<option value=\"$ccid\" $sel>".aff_langue($ctitle)."</option>";
       $result3=sql_query("select sid, title from ".$NPDS_Prefix."links_subcategories where cid='$ccid' order by title");
       while (list($ssid, $stitle) = sql_fetch_row($result3)) {
          $sel = "";
          if ($sid==$ssid) {
             $sel = "selected";
          }
          echo "<option value=\"$ccid-$ssid\" $sel>".aff_langue($ctitle)." / ".aff_langue($stitle)."</option>";
       }
    }

    echo "</select><br /><br /><input type=\"hidden\" name=\"op\" value=\"LinksModLinkS\"><input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Modifier")."\"> - [ <a href=\"admin.php?op=LinksDelLink&amp;lid=$lid\" class=\"rouge\">".adm_translate("Effacer")."</a> ]</form>";

    //Modify or Add Editorial
    $resulted2 = sql_query("select adminid, editorialtimestamp, editorialtext, editorialtitle from ".$NPDS_Prefix."links_editorials where linkid='$lid'");
    $recordexist = sql_num_rows($resulted2);
    if ($recordexist == 0) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
       echo adm_translate("Ajouter un Editorial")." :";
       echo "</td></tr></table>\n";
       echo "<form action=\"admin.php\" method=\"post\">";
       echo "<input type=\"hidden\" name=\"linkid\" value=\"$lid\">";
       echo adm_translate("Titre")." :<br /><input class=\"textbox\" type=\"text\" name=\"editorialtitle\" value=\"$editorialtitle\" size=\"50\" maxlength=\"100\"><br />";
       echo adm_translate("Texte complet")." :<br /><textarea class=\"textbox\" name=\"editorialtext\" cols=\"60\" rows=\"10\">$editorialtext</textarea><br /><br />";
       echo "<input type=\"hidden\" name=\"op\" value=\"LinksAddEditorial\"><input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ajouter")."\"><br />";
    } else {
      while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle) = sql_fetch_row($resulted2)) {
         $editorialtitle = stripslashes($editorialtitle);
         $editorialtext = stripslashes($editorialtext);
         echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
         echo "<b>".adm_translate("Modifier l'Editorial")."</b> - ".adm_translate("Auteur")." : $adminid : ".formatTimeStamp($editorialtimestamp);
         echo "</td></tr></table>\n";
         echo "<form action=\"admin.php\" method=\"post\">";
         echo "<input type=\"hidden\" name=\"linkid\" value=\"$lid\">";
         echo adm_translate("Titre")." :<br /><input class=\"textbox\" type=\"text\" name=\"editorialtitle\" value=\"$editorialtitle\" size=\"50\" maxlength=\"100\"><br /><br />";
         echo adm_translate("Texte complet")." :<br /><textarea class=\"textbox\" name=\"editorialtext\" cols=\"60\" rows=\"10\">$editorialtext</textarea><br /><br />";
         echo "<input type=\"hidden\" name=\"op\" value=\"LinksModEditorial\"><input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Modifier")."\"> - [ <a href=\"admin.php?op=LinksDelEditorial&amp;linkid=$lid\"  class=\"rouge\">".adm_translate("Effacer")."</a> ]<br />";
      }
    }
    echo "</form>";
    closetable();
    include ("footer.php");
}

function LinksListBrokenLinks() {
    global $NPDS_Prefix;
    global $hlpfile, $anonymous;
    $resultBrok = sql_query("select requestid, lid, modifysubmitter from ".$NPDS_Prefix."links_modrequest where brokenlink='1' order by requestid");
    $totalbrokenlinks = sql_num_rows($resultBrok);
    if ($totalbrokenlinks==0) {
       header("location: admin.php?op=links");
    }
    include ("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Liens cassés rapportés par un ou plusieurs Utilisateurs")." ($totalbrokenlinks)";
    echo "</td></tr></table><br />\n";

    echo "- ".adm_translate("Ignorer (Efface toutes les <b>demandes</b> pour un Lien donné)")."<br />
    - ".adm_translate("Effacer (Efface les <b>Liens cassés</b> et <b>les avis</b> pour un Lien donné)");

    if ($totalbrokenlinks==0) {
       echo "<br /><br /><p align=\"center\" class=\"rouge\">".adm_translate("Aucun lien brisé rapporté.")."</span>";
    } else {
       echo "<br /><br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr><td class=\"ongl\">\n";
       echo "<tr>
             <td class=\"ongl\"><b>".adm_translate("Liens")."</b></td>
             <td class=\"ongl\"><b>".adm_translate("Auteur")."</b></td>
             <td class=\"ongl\"><b>".adm_translate("Propriétaire")."</b></td>
             <td class=\"ongl\" align=center><b>".adm_translate("Ignorer")."</b></td>
             <td class=\"ongl\" align=center><b>".adm_translate("Effacer")."</b></td>
             </tr>";

       while (list($requestid, $lid, $modifysubmitter)=sql_fetch_row($resultBrok)) {
          $result2 = sql_query("select title, url, submitter from ".$NPDS_Prefix."links_links where lid='$lid'");
          if ($modifysubmitter != $anonymous) {
             $result3 = sql_query("select email from ".$NPDS_Prefix."users where uname='$modifysubmitter'");
             list ($email)=sql_fetch_row($result3);
          }
          list ($title, $url, $owner)=sql_fetch_row($result2);
          $result4 = sql_query("select email from ".$NPDS_Prefix."users where uname='$owner'");
          list($owneremail)=sql_fetch_row($result4);
          $rowcolor=tablos();
          echo "<tr $rowcolor><td><a href=$url target=\"_blank\" class=\"noir\">$title</a></td>";
          if ($email=='') {
             echo "<td>$modifysubmitter";
          } else {
             echo "<td><a href=\"mailto:$email\" class=\"noir\">$modifysubmitter</a>";
          }
          echo "</td>";
          if ($owneremail=='') {
             echo "<td>$owner";
          } else {
             echo "<td><a href=\"mailto:$owneremail\" class=\"noir\">$owner</a>";
          }
          echo "</td>
               <td align=\"center\"><a href=\"admin.php?op=LinksIgnoreBrokenLinks&amp;lid=$lid\" class=\"noir\">X</a></td>
               <td align=\"center\"><a href=admin.php?op=LinksDelBrokenLinks&amp;lid=$lid\" class=\"rouge\">X</a></td>
               </tr>";
       }
    }
    echo "</table>";
    closetable();
    include ("footer.php");
}

function LinksDelBrokenLinks($lid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_modrequest where lid='$lid'");
    sql_query("delete from ".$NPDS_Prefix."links_links where lid='$lid'");
    Header("Location: admin.php?op=LinksListBrokenLinks");
}

function LinksIgnoreBrokenLinks($lid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_modrequest where lid='$lid' and brokenlink='1'");
    Header("Location: admin.php?op=LinksListBrokenLinks");
}

function LinksListModRequests() {
    global $NPDS_Prefix;
    global $hlpfile;
    $resultLink = sql_query("select requestid, lid, cid, sid, title, url, description, modifysubmitter from ".$NPDS_Prefix."links_modrequest where brokenlink='0' order by requestid");
    $totalmodrequests = sql_num_rows($resultLink);
    if ($totalmodrequests==0) {
       header("location: admin.php?op=links");
    }
    include ("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
    echo adm_translate("Requête de modification d'un Lien Utilisateur")." ($totalmodrequests)";
    echo "</td></tr></table>\n";
    while(list($requestid, $lid, $cid, $sid, $title, $url, $description, $modifysubmitter)=sql_fetch_row($resultLink)) {
       $result2 = sql_query("select cid, sid, title, url, description, submitter from ".$NPDS_Prefix."links_links where lid='$lid'");
       list($origcid, $origsid, $origtitle, $origurl, $origdescription, $owner)=sql_fetch_row($result2);
       $result3 = sql_query("select title from ".$NPDS_Prefix."links_categories where cid='$cid'");
       $result4 = sql_query("select title from ".$NPDS_Prefix."links_subcategories where cid='$cid' and sid='$sid'");
       $result5 = sql_query("select title from ".$NPDS_Prefix."links_categories where cid='$origcid'");
       $result6 = sql_query("select title from ".$NPDS_Prefix."links_subcategories where cid='$origcid' and sid='$origsid'");
       $result7 = sql_query("select email from ".$NPDS_Prefix."users where uname='$modifysubmitter'");
       $result8 = sql_query("select email from ".$NPDS_Prefix."users where uname='$owner'");
       list($cidtitle)=sql_fetch_row($result3);
       list($sidtitle)=sql_fetch_row($result4);
       list($origcidtitle)=sql_fetch_row($result5);
       list($origsidtitle)=sql_fetch_row($result6);
       list($modifysubmitteremail)=sql_fetch_row($result7);
       list($owneremail)=sql_fetch_row($result8);
       $title = stripslashes($title);
       $description = stripslashes($description);
       if ($owner=="") { $owner="administration"; }
       if ($origsidtitle=="") { $origsidtitle= "-----"; }
       if ($sidtitle=="") { $sidtitle= "-----"; }
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">\n";
       $rowcolor=tablos();
       echo "<tr $rowcolor><td><hr noshade class=\"ongl\">
             <table width=\"100%\"><tr>
             <td valign=\"top\" width=\"45%\"><span class=\"noir\"><b>".adm_translate("Original")."</b></span></td>
             <td rowspan=\"5\" valign=\"top\" align=\"left\" valign=\"top\"><span class=\"noir\"><b>".adm_translate("Description:")."</b></span><br />$origdescription</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Titre :")." $origtitle</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("URL : ")." <a href=\"$origurl\" target=\"_blank\" class=\"noir\">$origurl</a></td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Catégorie :")." $origcidtitle</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Sous-catégorie :")." $origsidtitle</td></tr>
             </table>
             </td></tr>";
       $rowcolor=tablos();
       echo "<tr $rowcolor><td>
             <table width=\"100%\"><tr>
             <td valign=\"top\" width=\"45%\"><b>".adm_translate("Proposé")."</b></td>
             <td rowspan=\"5\" valign=\"top\" align=\"left\" valign=\"top\"><span class=\"noir\"><b>".adm_translate("Description:")."</b></span><br />$description</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Titre :")." $title</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("URL : ")." <a href=\"$url\" target=\"_blank\" class=\"noir\">$url</a></td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Catégorie :")." $cidtitle</td></tr>
             <tr><td valign=\"top\" width=\"45%\">".adm_translate("Sous-catégorie :")." $sidtitle</td></tr>
             </table>
             </td></tr>";
       echo "</table>";
       echo "<table width=\"100%\" callspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td class=\"header\">\n";
       if ($modifysubmitteremail=="") {
          echo adm_translate("Auteur")." :  $modifysubmitter</td>";
       } else {
          echo adm_translate("Auteur")." : <a href=\"mailto:$modifysubmitteremail\" class=\"box\">$modifysubmitter</a></td>";
       }
       echo "<td class=\"header\">";
       if ($owneremail=="") {
          echo adm_translate("Propriétaire")." :  $owner</td>";
       } else {
          echo adm_translate("Propriétaire")." : <a href=\"mailto:$owneremail\" class=\"box\">$owner</a></td>";
       }
       echo "<td align=\"right\">[ <a href=\"admin.php?op=LinksChangeModRequests&amp;requestid=$requestid\" class=\"rouge\">".adm_translate("Accepter")."</a> | <a href=\"admin.php?op=LinksChangeIgnoreRequests&amp;requestid=$requestid\" class=\"noir\">".adm_translate("Ignorer")."</a> ]</td>
       </tr></table><hr noshade class=\"ongl\"><br />\n";
    }
    closetable();
    include ("footer.php");
}

function LinksChangeModRequests($Xrequestid) {
    global $NPDS_Prefix;
    $result = sql_query("select requestid, lid, cid, sid, title, url, description from ".$NPDS_Prefix."links_modrequest where requestid='$Xrequestid'");
    while (list($requestid, $lid, $cid, $sid, $title, $url, $description)=sql_fetch_row($result)) {
       $title = stripslashes($title);
       $description = stripslashes($description);
       sql_query("UPDATE ".$NPDS_Prefix."links_links SET cid='$cid', sid='$sid', title='$title', url='$url', description='$description' WHERE lid = '$lid'");
    }
    sql_query("delete from ".$NPDS_Prefix."links_modrequest where requestid='$Xrequestid'");
    Header("Location: admin.php?op=LinksListModRequests");
}

function LinksChangeIgnoreRequests($requestid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_modrequest where requestid='$requestid'");
    Header("Location: admin.php?op=LinksListModRequests");
}

function LinksModLinkS($lid, $title, $url, $xtext, $name, $email, $hits, $cat) {
    global $NPDS_Prefix;
    $cat = explode("-", $cat);
    if ($cat[1]=="") { $cat[1] = 0; }
    $title = stripslashes(FixQuotes($title));
    $url = stripslashes(FixQuotes($url));
    $xtext = stripslashes(FixQuotes($xtext));
    $name = stripslashes(FixQuotes($name));
    $email = stripslashes(FixQuotes($email));
    sql_query("update ".$NPDS_Prefix."links_links set cid='$cat[0]', sid='$cat[1]', title='$title', url='$url', description='$xtext', name='$name', email='$email', hits='$hits' where lid='$lid'");
    Header("Location: admin.php?op=links");
}

function LinksDelLink($lid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_links where lid='$lid'");
    Header("Location: admin.php?op=links");
}

function LinksModCat($cat) {
    global $NPDS_Prefix;
    global $hlpfile;
    include ("header.php");
    GraphicAdmin($hlpfile);
    $cat = explode("-", $cat);
    if ($cat[1]=="") { $cat[1] = 0; }
    opentable();
    if ($cat[1]==0) {
        echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
        echo adm_translate("Modifier la Catégorie");
        echo "</td></tr></table><br />\n";
        $result=sql_query("select title, cdescription from ".$NPDS_Prefix."links_categories where cid='$cat[0]'");
        list($title,$cdescription) = sql_fetch_row($result);
        $cdescription = stripslashes($cdescription);
        echo "<form action=\"admin.php\" method=\"get\">
        ".adm_translate("Nom : ")."<input class=\"textbox\" type=\"text\" name=\"title\" value=\"$title\" size=\"51\" maxlength=\"50\"><br /><br />
        ".adm_translate("Description : ")."<br /><textarea class=\"textbox\" name=\"cdescription\" cols=\"60\" rows=\"10\">$cdescription</textarea><br />
        <input type=\"hidden\" name=\"sub\" value=\"0\">
        <input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">
        <input type=\"hidden\" name=\"op\" value=\"LinksModCatS\">
        <br /><input class=\"bouton_standard\" type=\"submit\" value=".adm_translate("Sauver les modifications")."> -
        <a href=\"admin.php?op=LinksDelCat&amp;sub=0&amp;cid=$cat[0]\" class=\"rouge\">".adm_translate("Effacer")."</a></form>";
    } else {
        $result=sql_query("select title from ".$NPDS_Prefix."links_categories where cid='$cat[0]'");
        list($ctitle) = sql_fetch_row($result);
        $result2=sql_query("select title from ".$NPDS_Prefix."links_subcategories where sid='$cat[1]'");
        list($stitle) = sql_fetch_row($result2);
        echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
        echo adm_translate("Modifier la Catégorie")." - ".adm_translate("Nom de la Catégorie : ").aff_langue($ctitle);
        echo "</td></tr></table><br />\n";
        echo "<form action=\"admin.php\" method=\"get\">
        ".adm_translate("Nom de la Sous-catégorie : ")."<input class=\"textbox\" type=\"text\" name=\"title\" value=\"$stitle\" size=\"51\" maxlength=\"50\"><br />
        <input type=\"hidden\" name=\"sub\" value=\"1\">
        <input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">
        <input type=\"hidden\" name=\"sid\" value=\"$cat[1]\">
        <input type=\"hidden\" name=\"op\" value=\"LinksModCatS\">
        <br /><input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\"> -
        <a href=\"admin.php?op=LinksDelCat&amp;sub=1&amp;cid=$cat[0]&amp;sid=$cat[1]\" class=\"rouge\">".adm_translate("Effacer")."</a></form>";
    }
    closetable();
    include("footer.php");
}

function LinksModCatS($cid, $sid, $sub, $title, $cdescription) {
    global $NPDS_Prefix;
    if ($sub==0) {
        sql_query("update ".$NPDS_Prefix."links_categories set title='$title', cdescription='$cdescription' where cid='$cid'");
    } else {
        sql_query("update ".$NPDS_Prefix."links_subcategories set title='$title' where sid='$sid'");
    }
    Header("Location: admin.php?op=links");
}

function LinksDelCat($cid, $sid, $sub, $ok=0) {
    global $NPDS_Prefix;
    if ($ok==1) {
        if ($sub>0) {
           sql_query("delete from ".$NPDS_Prefix."links_subcategories where sid='$sid'");
           sql_query("delete from ".$NPDS_Prefix."links_links where sid='$sid'");
        } else {
           sql_query("delete from ".$NPDS_Prefix."links_categories where cid='$cid'");
           sql_query("delete from ".$NPDS_Prefix."links_subcategories where cid='$cid'");
           sql_query("delete from ".$NPDS_Prefix."links_links where cid='$cid' AND sid=0");
        }
        Header("Location: admin.php?op=links");
    } else {
        message_error("<span class=\"rouge\"><b>".adm_translate("ATTENTION : Etes-vous sûr de vouloir effacer cette Catégorie et tous ses Liens ?")."</b></span><br /><br />
        [ <a href=\"admin.php?op=LinksDelCat&amp;cid=$cid&amp;sid=$sid&amp;sub=$sub&amp;ok=1\" class=\"rouge\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=links\" class=\"noir\">".adm_translate("Non")."</a> ]");
    }
}

function LinksDelNew($lid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_newlink where lid='$lid'");
    Header("Location: admin.php?op=links");
}

function LinksAddCat($title, $cdescription) {
    global $NPDS_Prefix;
    $result = sql_query("select cid from ".$NPDS_Prefix."links_categories where title='$title'");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
        message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : La Catégorie")." $title ".adm_translate("existe déjà !")."</b></span>");
    } else {
        sql_query("insert into ".$NPDS_Prefix."links_categories values (NULL, '$title', '$cdescription')");
        Header("Location: admin.php?op=links");
    }
}

function LinksAddSubCat($cid, $title) {
    global $NPDS_Prefix;
    $result = sql_query("select cid from ".$NPDS_Prefix."links_subcategories where title='$title' AND cid='$cid'");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
        message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : La Sous-catégorie")." $title ".adm_translate("existe déjà !")."</b></span>");
    } else {
        sql_query("insert into ".$NPDS_Prefix."links_subcategories values (NULL, '$cid', '$title')");
        Header("Location: admin.php?op=links");
    }
}

function LinksAddEditorial($linkid, $editorialtitle, $editorialtext) {
    global $NPDS_Prefix;
    global $aid;
    $editorialtext = stripslashes(FixQuotes($editorialtext));
    sql_query("insert into ".$NPDS_Prefix."links_editorials values ('$linkid', '$aid', now(), '$editorialtext', '$editorialtitle')");
    message_error("<span class=\"noir\"><b>".adm_translate("Editorial ajouté à la base de données")."</b></span>");
}

function LinksModEditorial($linkid, $editorialtitle, $editorialtext) {
    global $NPDS_Prefix;
    $editorialtext = stripslashes(FixQuotes($editorialtext));
    sql_query("update ".$NPDS_Prefix."links_editorials set editorialtext='$editorialtext', editorialtitle='$editorialtitle' where linkid='$linkid'");
    message_error("<span class=\"noir\"><b>".adm_translate("Editorial modifié")."</b></span>");
}

function LinksDelEditorial($linkid) {
    global $NPDS_Prefix;
    sql_query("delete from ".$NPDS_Prefix."links_editorials where linkid='$linkid'");
    message_error("<span class=\"noir\"><b>".adm_translate("Editorial supprimé de la base de données")."</b></span>");
}

function message_error($ibid) {
    global $hlpfile;
    include("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    echo "<p align=\"center\"><br />";
    echo $ibid;
    echo "<br /><br /><a href=\"admin.php?op=links\" class=\"noir\">".adm_translate("Retour en arrière")."</a>";
    echo "<br /></p>";
    closetable();
    include("footer.php");
}

function LinksAddLink($new, $lid, $title, $url, $cat, $xtext, $name, $email, $submitter) {
    global $NPDS_Prefix;
    $result = sql_query("select url from ".$NPDS_Prefix."links_links where url='$url'");
    $numrows = sql_num_rows($result);
    if ($numrows>0) {
        message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : cette URL est déjà présente dans la base de données !")."</b></span>");
    } else {
       // Check if Title exist
       if ($title=="") {
           message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : vous devez saisir un TITRE pour votre Lien !")."</b></span>");
       }
       // Check if URL exist
       if ($url=="") {
          message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : vous devez saisir une URL pour votre Lien !")."</b></span>");
       }
       // Check if Description exist
       if ($xtext=="") {
          message_error("<span class=\"rouge\"><b>".adm_translate("Erreur : vous devez saisir une DESCRIPTION pour votre Lien !")."</b></span>");
       }
       $cat = explode("-", $cat);
       if ($cat[1]=="") {
          $cat[1] = 0;
       }
       $title = stripslashes(FixQuotes($title));
       $url = stripslashes(FixQuotes($url));
       $xtext = stripslashes(FixQuotes($xtext));
       $name = stripslashes(FixQuotes($name));
       $email = stripslashes(FixQuotes($email));
       sql_query("insert into ".$NPDS_Prefix."links_links values (NULL, '$cat[0]', '$cat[1]', '$title', '$url', '$xtext', now(), '$name', '$email', '0','$submitter',0,0,0,'')");
       if ($new==1) {
          sql_query("delete from ".$NPDS_Prefix."links_newlink where lid='$lid'");
          if ($email!="") {
             global $sitename, $nuke_url;
             $subject = "".adm_translate("Votre Lien")." : $sitename";
             $message = "".adm_translate("Bonjour")." $name :\n\n".adm_translate("Nous avons approuvé votre contribution à notre moteur de recherche.")."\n\n".adm_translate("Titre de la Page : ")."$title\n".adm_translate("URL de la Page : ")."$url\n".adm_translate("Description : ")."$description\n\n\n".adm_translate("Vous pouvez utiliser notre moteur de recherche sur : ")." $nuke_url/links.php\n\n".adm_translate("Merci pour votre Contribution !")."\n\n";
             include("signat.php");
             send_email($email, $subject, $message, "", false, "text");
          }
       }
       message_error("<span class=\"noir\"><b>".adm_translate("Nouveau Lien ajouté dans la base de données")."</b></span>");
    }
}

switch ($op) {
    case "links":
    case "suite_links":
         links();
         break;

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

    case "LinksAddCat":
         LinksAddCat($title, $cdescription);
         break;

    case "LinksAddSubCat":
         LinksAddSubCat($cid, $title);
         break;

    case "LinksAddLink":
         LinksAddLink($new, $lid, $title, $url, $cat, $xtext, $name, $email, $submitter);
         break;

    case "LinksAddEditorial":
         LinksAddEditorial($linkid, $editorialtitle, $editorialtext);
         break;

    case "LinksModEditorial":
         LinksModEditorial($linkid, $editorialtitle, $editorialtext);
         break;

    case "LinksDelEditorial":
         LinksDelEditorial($linkid);
         break;

    case "LinksListBrokenLinks":
         LinksListBrokenLinks();
         break;

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

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

    case "LinksListModRequests":
         LinksListModRequests();
         break;

    case "LinksChangeModRequests":
         LinksChangeModRequests($requestid);
         break;

    case "LinksChangeIgnoreRequests":
         LinksChangeIgnoreRequests($requestid);
         break;

    case "LinksDelCat":
         LinksDelCat($cid, $sid, $sub, $ok);
         break;

    case "LinksModCat":
         LinksModCat($cat);
         break;

    case "LinksModCatS":
         LinksModCatS($cid, $sid, $sub, $title, $cdescription);
         break;

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

    case "LinksModLinkS":
         LinksModLinkS($lid, $title, $url, $xtext, $name, $email, $hits, $cat);
         break;

    case "LinksDelLink":
         LinksDelLink($lid);
         break;
}
?>