<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: links.php,v 1.14.2.12 2004/08/23 22:03:14 kirilt Exp $

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* 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.       */
/************************************************************************/

//2001-03-08 hombergs: Added missing translate calls
//2001-03-03 hombergs: Added missing translate calls

checkAccess( 'modules', array( 'link' ) );

/*********************************************************/
/* Links Modified Web Links                              */
/*********************************************************/

function links() {
    global $admin, $mpnTables,$phpEx;
    include ("header.$phpEx");

    OpenTable();
    echo "
    <center><a href=links.$phpEx><img src=images/links/web.gif border=0></a><br><br>";
    $result=mysql_query("select * from ".$mpnTables['links_links']);
    $numrows = mysql_num_rows($result);
    echo "<font size=2>".translate("There are")." <b>$numrows</b> ".translate("Links in our Database")."";
    echo "</td></tr></table></td></tr></table><br>";

// Temporarily 'homeless' links functions (to be revised in admin.php breakup)
    $result = mysql_query("select * from ".$mpnTables['links_modrequest']." where brokenlink=1");
    $totalbrokenlinks = mysql_num_rows($result);
    $result2 = mysql_query("select * from ".$mpnTables['links_modrequest']." where brokenlink=0");
    $totalmodrequests = mysql_num_rows($result2);


// List Links waiting for validation

    $result = mysql_query("select lid, cid, sid, title, url, description, name, email, submitter from ".$mpnTables['links_newlink']." order by lid");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
        OpenTable();
        echo "
        </center><font size=3><b>".translate("Links Waiting for Validation")."</b><br><br><font size=2>";
        while(list($lid, $cid, $sid, $title, $url, $description, $name, $email, $submitter) = mysql_fetch_row($result)) {

            // Kiril: Start New Sanitizer

            $sanity_ary = compact( 'title', 'url', 'description', 'name', 'email', 'submitter' );
            $_SERVER['SAN'] -> slashIT( $sanity_ary );
            extract( $sanity_ary );
            unset( $sanity_ary );

            // End New Sanitizer

            echo "<form action=admin.$phpEx method=post>";
            echo "<table border=0 width=300>\n";
            echo "<tr><td><font color=Blue>".translate("Link ID: ")."</td><td><font color=Black><b>$lid</b></td></tr>\n";
            echo "<tr><td>".translate("Submitter:")."</td><td>$submitter&nbsp;</td></tr>\n";
            echo "<tr><td>".translate("Page Title: ")."</td><td><input class='textbox' type='text' name='title' value=\"$title\" size=60 maxlength=100></td></tr>\n";
            echo "<tr><td>".translate("Page URL: ")."</td><td><input class='textbox' type='text' name='url' value=$url size=60 maxlength=100>&nbsp;[ <a target=_blank href=$url>".translate("Visit")."</a> ]</td></tr>\n";
            echo "<tr><td valign='top'>".translate("Description: ")."</td><td><textarea name='description' cols=60 rows=10>$description</textarea></td></tr>\n";
            echo "<tr><td>".translate("Name: ")."</td><td><input class='textbox' type='text' name='name' size=60 maxlength=100 value=\"$name\"></td></tr>\n";
            echo "<tr><td>".translate("Email: ")."</td><td><input class='textbox' type='text' name='email' size=60 maxlength=100 value=$email></td></tr>\n";
            $result2=mysql_query("select cid, title from ".$mpnTables['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 "<tr><td>".translate("Category: ")."</td><td><select name='cat'>\n";
            while(list($ccid, $ctitle) = mysql_fetch_row($result2)) {
                $ctitle = stripslashes( $ctitle );
                $sel = "";
                if ($cid==$ccid AND $sid==0) {
                    $sel = "selected";
                }
                echo "<option value=$ccid $sel>$ctitle</option>\n";
                $result3=mysql_query("select sid, title from ".$mpnTables['links_subcategories']." where cid=$ccid order by title");
                while(list($ssid, $stitle) = mysql_fetch_row($result3)) {
                    $stitle = stripslashes( $stitle );
                        $sel = "";
                    if ($sid==$ssid) {
                        $sel = "selected";
                    }
                    echo "<option value=$ccid-$ssid $sel>$ctitle / $stitle</option>\n";
                }

            }

            echo "</select>\n</td></tr>\n";
            echo "</table>\n<br />\n";
            echo "<input type='hidden' name='submitter' value=$submitter>";

            // Kiril: New Sanitizer

            echo "<input type='hidden' name='stripit_form' value='title|url|description|name|email' />\n";
            echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

            // End Sanitizer

            echo "<input type='hidden' name='op' value='LinksAddLink'>\n";
            echo "<input class='button' type='submit' value=\"".translate("Add")."\"> [ <a href=admin.$phpEx?op=LinksDelNew&lid=$lid>".translate("Delete")."</a> ]</form><br><hr noshade><br>";

        }
        echo "</td></tr></table></td></tr></table><br>";
    } else {
    }

// Add a New Main Category

    OpenTable();

    echo "<br><b><center>[ <a href=admin.$phpEx?op=LinksCleanVotes>".translate("Clean Links DB")."</a> |
    <a href=admin.$phpEx?op=LinksListBrokenLinks>".translate("Broken Link Reports")." ($totalbrokenlinks)</a> |
    <a href=admin.$phpEx?op=LinksListModRequests>".translate("Link Modification Requests")." ($totalmodrequests)</a> ]</center></b><br><br>
    </center><form method=post action=admin.$phpEx>
    <font size=3><b>".translate("Add a MAIN Category")."</b></font><br><br>
	<table border=0><tr><td class=w30>
    ".translate("Name: ")."</td><td><input class='textbox' type='text' name='title' size=30 maxlength=100></td></tr>\n<tr><td valign='top'>
    ".translate("Description: ")."</td><td><textarea name='cdescription' cols=60 rows=10></textarea></td></tr>\n</table>\n<br>\n
    <input type='hidden' name='op' value='LinksAddCat'>\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title|cdescription' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input class='button' type='submit' value=\"".translate("Add")."\"><br>
    </form></td></tr></table></td></tr></table><br>";

// Add a New Sub-Category

    $result = mysql_query("select * from ".$mpnTables['links_categories']);
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
        OpenTable();
        echo "
        </center><form method=post action=admin.$phpEx>
        <font size=3><b>".translate("Add a SUB-Category")."</b></font><br><br>
        ".translate("Name: ")."<input class='textbox' type='text' name='title' size=30 maxlength=100>&nbsp;".translate("in")."&nbsp;";

        $result=mysql_query("select cid, title from ".$mpnTables['links_categories']." order by title");
        echo "<select name=cid>";
        while(list($ccid, $ctitle) = mysql_fetch_row($result)) {
            $ctitle = stripslashes( $ctitle );
            echo "<option value=$ccid>$ctitle</option>";
        }
        echo "</select>\n";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input type='hidden' name='op' value='LinksAddSubCat'>
        <input class='button' type='submit' value=\"".translate("Add")."\"><br>
        </form></td></tr></table></td></tr></table><br>";
    } else {
    }

// Add a New Link to Database
    $result = mysql_query("select cid, title from ".$mpnTables['links_categories']);
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
        OpenTable();
        echo "
        </center><form method=post action=admin.$phpEx>
        <font size=3><b>".translate("Add a New Link")."</b></font><br>\n<br>\n";
		echo "<table border=0>\n<tr><td class=w30>
        ".translate("Page Title: ")."</td><td><input class='textbox' type='text' name='title' size=50 maxlength=100></td></tr>\n<tr><td>
        ".translate("Page URL: ")."</td><td><input class='textbox' type='text' name=url size=50 maxlength=100 value=\"http://\"></td></tr>\n<tr><td>";
        $result=mysql_query("select cid, title from ".$mpnTables['links_categories']." order by title");
        echo "".translate("Category: ")."</td><td><select name=cat>";
        while(list($cid, $title) = mysql_fetch_row($result)) {
            $title = stripslashes( $title );
            echo "<option value=$cid>$title</option>";
            $result2 = mysql_query("select sid, title from " . $mpnTables['links_subcategories'] . " where cid=$cid order by title");
            while(list($sid, $stitle) = mysql_fetch_row($result2)) {
                $stitle = stripslashes( $stitle );
                    echo "<option value=$cid-$sid>$title / $stitle</option>\n";
            }
        }
        echo "</select></td></tr>\n<tr><td valign='top'>
        ".translate("Description:<br>(255 characters max)")."</td><td><textarea class='textbox' name='description' cols=60 rows=5></textarea></td></tr><tr><td>
        ".translate("Name: ")."</td><td><input class='textbox' type='text' name='name' size=30 maxlength=60></td></tr>\n<tr><td>
        ".translate("E-Mail: ")."</td><td><input class='textbox' type='text' name='email' size=30 maxlength=60></td></tr>\n</table>\n";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title|url|cat|description|name|email' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input type='hidden' name='op' value='LinksAddLink'>
        <input type='hidden' name='new' value=0>
        <input type='hidden' name='lid' value=0><br />
        <input class='button' type='submit' value=\"".translate("Add URL")."\"><br>
        </form></td></tr></table></td></tr></table><br>";

    } else {
    }

// Modify Category

    $result = mysql_query("select * from ".$mpnTables['links_categories']);
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
        OpenTable();
        echo "
        </center><form method=post action=admin.$phpEx>
        <font size=3><b>".translate("Modify Category")."</b></font><br><br>";
        $result=mysql_query("select cid, title from ".$mpnTables['links_categories']." order by title");
        echo "".translate("Category: ")."<select name=cat>";
        while(list($cid, $title) = mysql_fetch_row($result)) {
            $title = stripslashes( $title );
            echo "<option value=$cid>$title</option>";
            $result2=mysql_query("select sid, title from ".$mpnTables['links_subcategories']." where cid=$cid order by title");
            while(list($sid, $stitle) = mysql_fetch_row($result2)) {
                $stitle = stripslashes( $stitle );
                    echo "<option value=$cid-$sid>$title / $stitle</option>";
            }
        }
        echo "</select>\n";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='title|cat' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input type='hidden' name='op' value='LinksModCat'>
        <input class='button' type='submit' value=\"".translate("Modify")."\">
        </form></td></tr></table></td></tr></table><br>";
    } else {
    }

// Modify Links

    $result = mysql_query("select * from ".$mpnTables['links_links']);
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
        OpenTable();
        echo "
        </center><form method=post action=admin.$phpEx>
        <font size=3><b>".translate("Modify Links")."</b></font><br>\n<br>\n
        ".translate("Link ID: ")."<input class='textbox' type='text' name='lid' size=12 maxlength=11>\n";

        // Kiril: New Sanitizer

        echo "<input type='hidden' name='stripit_form' value='lid' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

        // End Sanitizer

        echo "<input type='hidden' name='op' value='LinksModLink'>
        <input class='button' type='submit' value=\"".translate("Modify")."\">
        </form></td></tr></table></td></tr></table><br>";
    } else {
    }

    include ("footer.$phpEx");
}

function LinksModLink($lid) {
    global $mpnTables,$phpEx,$anonymous;
    include ("header.$phpEx");

    $result = mysql_query("select cid, sid, title, url, description, name, email, hits from ".$mpnTables['links_links']." where lid=$lid");
    OpenTable();
    echo "
    </center><font size=3><b>".translate("Modify Links")."</b><br><br></font>";
    while(list($cid, $sid, $title, $url, $description, $name, $email, $hits) = mysql_fetch_row($result)) {

        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'description', 'name', 'email' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

        //$title = stripslashes($title); $description = stripslashes($description);


        echo "<form action=admin.$phpEx method=post>";
        echo "<table border=0>\n";
    echo "<tr><td class=w30><font color=Blue>".translate("Link ID: ")."</td><td><font color=Black><b>$lid</b></td></tr>\n";
    echo "<tr><td>".translate("Page Title: ")."</td><td><input class='textbox' type='text' name='title' value=\"$title\" size=50 maxlength=100></td></tr>\n";
    echo "<tr><td>".translate("Page URL: ")."</td><td><input class='textbox' type='text' name='url' value=$url size=50 maxlength=100>&nbsp;[ <a href=$url>" .translate("Visit")."</a> ]</td></tr>\n";
    echo "<tr><td valign='top'>".translate("Description: ")."</td><td><textarea name='description' cols=60 rows=10>$description</textarea></td></tr>\n";
    echo "<tr><td>".translate("Name: ")."</td><td><input class='textbox' type='text' name='name' size=50 maxlength=100 value=\"$name\"></td></tr>\n";
    echo "<tr><td>".translate("E-Mail: ")."</td><td><input class='textbox' type='text' name='email' size=50 maxlength=100 value=\"$email\"></td></tr>\n";
    echo "<tr><td>".translate("Hits: ")."</td><td><input class='textbox' type='text' name='hits' value=$hits size=12 maxlength=11></td></tr>\n";
    $result2=mysql_query("select cid, title from ".$mpnTables['links_categories']." order by title");
    echo "<input type='hidden' name='lid' value=$lid>";
    echo "<tr><td>".translate("Category: ")."</td><td><select name=cat>";
    while(list($ccid, $ctitle) = mysql_fetch_row($result2)) {
        $ctitle = stripslashes( $ctitle );
        $sel = "";
        if ($cid==$ccid AND $sid==0) {
        $sel = "selected";
       }
        echo "<option value=$ccid $sel>$ctitle</option>\n";
        $result3=mysql_query("select sid, title from ".$mpnTables['links_subcategories']." where cid=$ccid order by title");
        while(list($ssid, $stitle) = mysql_fetch_row($result3)) {
            $stitle = stripslashes( $stitle );
                $sel = "";
        if ($sid==$ssid) {
            $sel = "selected";
        }
        echo "<option value=$ccid-$ssid $sel>$ctitle / $stitle</option>\n";
        }
    }

    echo "</select>\n";
    echo "</td></tr>\n</table>\n<br />\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title|url|cat|description|name|email|hits' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input type='hidden' name='op' value='LinksModLinkS'><input class='button' type='submit' value=\"".translate("Modify")."\"> [ <a href=admin.$phpEx?op=LinksDelLink&lid=$lid>".translate("Delete")."</a> ]</form><br>";

    echo "<hr>";

    //Modify or Add Editorial
        global $admin;

        $resulted2 = mysql_query("select adminid, editorialtimestamp, editorialtext, editorialtitle from ".$mpnTables['links_editorials']." where linkid=$lid");
        $recordexist = Mysql_num_rows($resulted2);

        // if returns 'bad query' status 0 (add editorial)
        if ($recordexist == 0) {
            echo "<br><font size=3><b>" .translate("Add Editorial")."</b><font size=2><br><br>";
            echo "<form action=admin.$phpEx method=post>";
            echo "<input type='hidden' name=linkid value=$lid>";
            echo "<table border=0>\n";
            echo "<tr><td class=w30>" .translate("Editorial Title:")."</td><td><input class='textbox' type='text' name='editorialtitle' value=\"\" size=60 maxlength=100></td></tr>\n";
            echo "<tr><td valign='top'>" .translate("Editorial Text:")."</td><td><textarea name='editorialtext' cols=60 rows=10></textarea></td></tr>\n";
            echo "</table>\n<br />\n";
            // Kiril: New Sanitizer

            echo "<input type='hidden' name='stripit_form' value='editorialtitle|editorialtext' />\n";
            echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

            // End Sanitizer

                echo "</select><input type='hidden' name='op' value='LinksAddEditorial'>";
                echo "<input class='button' type='submit' value=\"" .translate("Add")."\"><br><br><br>";

        }
        // if returns 'cool' then status 1 (modify editorial)
        else {
            while(list($adminid, $editorialtimestamp, $editorialtext, $editorialtitle) = mysql_fetch_row($resulted2)) {
            $editorialtitle = stripslashes($editorialtitle); $editorialtext = stripslashes($editorialtext);
                $formatted_date = strftime(translate("datestring4"),strtotime($editorialtimestamp));
            echo "<br><b>" .translate("Modify Editorial")."</b>  [ <a href=admin.$phpEx?op=LinksDelEditorial&linkid=$lid>" .translate("Delete")."</a> ]<br><br>";
            echo "<form action=admin.$phpEx method=post>";
            echo "<table border=0>\n";
            echo "<tr><td class=w30>" .translate("Author:")."</td><td>$adminid</td></tr>\n";
            echo "<tr><td>" .translate("Date written:")."</td><td>$formatted_date</td></tr>\n";
            echo "<tr><td>" .translate("Editorial Title:")."</td><td><input class='textbox' type='text' name='editorialtitle' value=\"$editorialtitle\" size=50 maxlength=100></td></tr>\n";
            echo "<tr><td valign='top'>" .translate("Editorial Text:")."</td><td><textarea name='editorialtext' cols=60 rows=10>$editorialtext</textarea></td></tr>\n";
            echo "</select>\n";
            echo "</table>\n<br />\n";
                // Kiril: New Sanitizer

                echo "<input type='hidden' name='stripit_form' value='editorialtitle|editorialtext' />\n";
                echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

                // End Sanitizer

                echo "<input type='hidden' name=linkid value=$lid>";
                echo "<input type='hidden' name='op' value='LinksModEditorial'>";
                echo "<input class='button' type='submit' value=\"".translate("Modify")."\"><br><br><br>";
                }
        }

    echo "<hr>";

    // Show Comments
    $result5=mysql_query("SELECT ratingdbid, ratinguser, ratingcomments, ratingtimestamp FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid AND ratingcomments != '' ORDER BY ratingtimestamp DESC");
    $totalcomments = Mysql_num_rows($result5);
    echo "<table valign='top' width='100%'>";
    echo "<tr><td colspan=7><b>" .translate("Link Comments (total comments:")." $totalcomments)</b><br><br></td></tr>";
    echo "<tr><td width=20 colspan=1><b>" .translate("User")."  </b></td><td colspan=5><b>" .translate("Comment")."  </b></td><td><b><center>" .translate("Delete")."</center></b></td><br></tr>";
    if ($totalcomments == 0) echo "<tr><td colspan=7><center><font color=cccccc>" .translate("No Comments")."<br></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $ratinguser, $ratingcomments, $ratingtimestamp)=mysql_fetch_row($result5)) {
        $ratingcomments = stripslashes($ratingcomments);
            $formatted_date = strftime(translate("datestring4"),strtotime($ratingtimestamp));
            echo "<tr><td valign='top' bgcolor=$colorswitch>$ratinguser</td><td valign='top' colspan=5 bgcolor=$colorswitch>$ratingcomments</td><td bgcolor=$colorswitch><center><b><a href=admin.$phpEx?op=LinksDelComment&lid=$lid&rid=$ratingdbid>X</a></b></center></td><br></tr>";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }


    // Show Registered Users Votes
    $result5=mysql_query("SELECT ratingdbid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid AND ratinguser != 'outside' AND ratinguser != '$anonymous' ORDER BY ratingtimestamp DESC");
    $totalvotes = Mysql_num_rows($result5);
    echo "<tr><td colspan=7><br><br><b>" .translate("Registered User Votes (total votes:")." $totalvotes)</b><br><br></td></tr>";
    echo "<tr><td><b>" .translate("User")."  </b></td><td><b>" .translate("IP Address")."  </b></td><td><b>" .translate("Rating")."  </b></td><td><b>" .translate("User AVG Rating")."  </b></td><td><b>" .translate("Total Ratings")."  </b></td><td><b>" .translate("Date")."  </b></td></font></b><td><b><center>" .translate("Delete")."</center></b></td><br></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>" .translate("No Registered User Votes")."<br></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $ratinguser, $rating, $ratinghostname, $ratingtimestamp)=mysql_fetch_row($result5)) {
            $formatted_date = strftime(translate("datestring4"),strtotime($ratingtimestamp));

        //Individual user information
        $result2=mysql_query("SELECT rating FROM ".$mpnTables['links_votedata']." WHERE ratinguser = '$ratinguser'");
            $usertotalcomments = Mysql_num_rows($result2);
            $useravgrating = 0;
            while(list($rating2)=mysql_fetch_row($result2)) $useravgrating = $useravgrating + $rating2;
            $useravgrating = $useravgrating / $usertotalcomments;
            $useravgrating = number_format($useravgrating, 1);
            echo "<tr><td bgcolor=$colorswitch>$ratinguser</td><td bgcolor=$colorswitch>$ratinghostname</td><td bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$useravgrating</td><td bgcolor=$colorswitch>$usertotalcomments</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.$phpEx?op=LinksDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br>";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    // Show Unregistered Users Votes
    $result5=mysql_query("SELECT ratingdbid, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid AND ratinguser = '$anonymous' ORDER BY ratingtimestamp DESC");
    $totalvotes = Mysql_num_rows($result5);
    echo "<tr><td colspan=7><b><br><br>" .translate("Unregistered User Votes (total votes:")." $totalvotes)</b><br><br></td></tr>";
    echo "<tr><td colspan=2><b>" .translate("IP Address")."  </b></td><td colspan=3><b>" .translate("Rating")."  </b></td><td><b>" .translate("Date")."  </b></font></td><td><b><center>" .translate("Delete")."</center></b></td><br></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>" .translate("No Unregistered User Votes")."<br></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $rating, $ratinghostname, $ratingtimestamp)=mysql_fetch_row($result5)) {
        $formatted_date = strftime(translate("datestring4"),strtotime($ratingtimestamp));
        echo "<td colspan=2 bgcolor=$colorswitch>$ratinghostname</td><td colspan=3 bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.$phpEx?op=LinksDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br>";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    // Show Outside Users Votes
    $result5=mysql_query("SELECT ratingdbid, rating, ratinghostname, ratingtimestamp FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid AND ratinguser = 'outside' ORDER BY ratingtimestamp DESC");
    $totalvotes = Mysql_num_rows($result5);
    echo "<tr><td colspan=7><b><br><br>" .translate("Outside User Votes (total votes:")." $totalvotes)</b><br><br></td></tr>";
    echo "<tr><td colspan=2><b>" .translate("IP Address")."  </b></td><td colspan=3><b>" .translate("Rating")."  </b></td><td><b>" .translate("Date")."  </b></td></font></b><td><b><center>" .translate("Delete")."</center></b></td><br></tr>";
    if ($totalvotes == 0) echo "<tr><td colspan=7><center><font color=cccccc>" .translate("No Outside Votes")." $sitename<br></font></center></td></tr>";
    $x=0;
    $colorswitch="dddddd";
    while(list($ratingdbid, $rating, $ratinghostname, $ratingtimestamp)=mysql_fetch_row($result5)) {
        $formatted_date = strftime(translate("datestring4"),strtotime($ratingtimestamp));
        echo "<tr><td colspan=2 bgcolor=$colorswitch>$ratinghostname</td><td colspan=3 bgcolor=$colorswitch>$rating</td><td bgcolor=$colorswitch>$formatted_date  </font></b></td><td bgcolor=$colorswitch><center><b><a href=admin.$phpEx?op=LinksDelVote&lid=$lid&rid=$ratingdbid>X</a></b></center></td></tr><br>";
        $x++;
        if ($colorswitch=="dddddd") $colorswitch="ffffff";
            else $colorswitch="dddddd";
        }

    echo "<tr><td colspan=6><br></td></tr>";
    echo "</table>";

    }
    echo "</form></td></tr></table></td></tr></table><br>";
    include ("footer.$phpEx");
}

function LinksDelComment($lid, $rid) {
    global $mpnTables,$phpEx;
    mysql_query("UPDATE ".$mpnTables['links_votedata']." SET ratingcomments='' WHERE ratingdbid = $rid");
    mysql_query("UPDATE ".$mpnTables['links_links']." SET totalcomments = (totalcomments - 1) WHERE lid = $lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksModLink&lid=' . $lid );

}

function LinksDelVote($lid, $rid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_votedata']." where ratingdbid=$rid");
    $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid");
    $totalvotesDB = mysql_num_rows($voteresult);
    include ("voteinclude.$phpEx");
    mysql_query("UPDATE ".$mpnTables['links_links']." SET linkratingsummary=$finalrating,totalvotes=$totalvotesDB,totalcomments=$truecomments WHERE lid = $lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksModLink&lid=' . $lid );

}

function LinksListBrokenLinks() {
    global $mpnTables,$phpEx;
    include ("header.$phpEx");

    $result = mysql_query("select requestid, lid, modifysubmitter from ".$mpnTables['links_modrequest']." where brokenlink=1 order by requestid");
    $totalbrokenlinks = mysql_num_rows($result);
    echo "<center><font size=3><b>".translate("User Reported Broken Links")." ($totalbrokenlinks)</b></font></center><br><br><center>
    ".translate("Ignore (Deletes all <b><i>requests</i></b> for a given link)")."<br>
    ".translate("Delete (Deletes <b><i>broken link</i></b> and <b><i>requests</i></b> for a given link)")."</center><br><br><br>";
    echo "<table align=center width=450>";
    if ($totalbrokenlinks==0) {
    echo "<center><font size=3>".translate("No reported broken links.")."</font></center><br><br><br>";
    }
    else {
        $colorswitch="dddddd";
        echo "
        <tr>
          <td><b>Link</b></td>
          <td><b>" .translate("Submittor")."</b></td>
          <td><b>" .translate("Link Owner")."</b></td>
          <td><b>" .translate("Ignore")."</b></td>
          <td><b>" .translate("Delete")."</b></td>
        </tr>";

        while(list($requestid, $lid, $modifysubmitter)=mysql_fetch_row($result)) {
            $result2 = mysql_query("select title, url, submitter from ".$mpnTables['links_links']." where lid=$lid");

        if ($modifysubmitter != '$anonymous') {
            $result3 = mysql_query("select email from ".$mpnTables['users']." where uname='$modifysubmitter' && uid > 1");
            list($email)=mysql_fetch_row($result3);
            $email = stripslashes( $email );
        }
            list($title, $url, $owner)=mysql_fetch_row($result2);

            // Kiril: New Sanitizer

            echo "<input type='hidden' name='stripit_form' value='title|url|owner' />\n";
            echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

            // End Sanitizer


                $result4 = mysql_query("select email from ".$mpnTables['users']." where uname='$owner' && uid > 1");
                list($owneremail)=mysql_fetch_row($result4);

                $owneremail = stripslashes( $owneremail );

                echo "
                <tr>
                  <td bgcolor=$colorswitch><a href=$url>$title</a>
                  </td>";
                  if ($email=='') { echo "<td bgcolor=$colorswitch>$modifysubmitter"; }
                  else { echo "<td bgcolor=$colorswitch><a href=mailto:$email>$modifysubmitter</a>"; }
                  echo "
                  </td>";
                  if ($owneremail=='') { echo "<td bgcolor=$colorswitch>$owner"; }
                  else { echo "<td bgcolor=$colorswitch><a href=mailto:$owneremail>$owner</a>"; }
                  echo "
                  </td>
                  <td bgcolor=$colorswitch><center><a href=admin.$phpEx?op=LinksIgnoreBrokenLinks&lid=$lid>X</a></center>
                  </td>
                  <td bgcolor=$colorswitch><center><a href=admin.$phpEx?op=LinksDelBrokenLinks&lid=$lid>X</a></center>
                  </td>
                </tr>";
                if ($colorswitch=="dddddd") $colorswitch="ffffff";
                else $colorswitch="dddddd";

        }

    }
    echo "</table>";
    include ("footer.$phpEx");
}

function LinksDelBrokenLinks($lid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_modrequest']." where lid=$lid");
    mysql_query("delete from ".$mpnTables['links_links']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksListBrokenLinks' );

}

function LinksIgnoreBrokenLinks($lid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_modrequest']." where lid=$lid and brokenlink=1");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksListBrokenLinks' );

}

function LinksListModRequests() {
    global $mpnTables,$phpEx;
    include ("header.$phpEx");

    $result = mysql_query("select requestid, lid, cid, sid, title, url, description, modifysubmitter from ".$mpnTables['links_modrequest']." where brokenlink=0 order by requestid");
    $totalmodrequests = mysql_num_rows($result);
    echo "<center><font size=3><b>".translate("User Link Modification Requests")." ($totalmodrequests)</b></font></center><br><br><br>";
    echo "<table width='95%'><tr><td>";
    while(list($requestid, $lid, $cid, $sid, $title, $url, $description, $modifysubmitter)=mysql_fetch_row($result)) {


    $result2 = mysql_query("select cid, sid, title, url, description, submitter from ".$mpnTables['links_links']." where lid=$lid");
    list($origcid, $origsid, $origtitle, $origurl, $origdescription, $owner)=mysql_fetch_row($result2);




    $result3 = mysql_query("select title from ".$mpnTables['links_categories']." where cid=$cid");
    $result4 = mysql_query("select title from ".$mpnTables['links_subcategories']." where cid=$cid and sid=$sid");
    $result5 = mysql_query("select title from ".$mpnTables['links_categories']." where cid=$origcid");
    $result6 = mysql_query("select title from ".$mpnTables['links_subcategories']." where cid=$origcid and sid=$origsid");
    $result7 = mysql_query("select email from ".$mpnTables['users']." where uname='$modifysubmitter' && uid > 1");
    $result8 = mysql_query("select email from ".$mpnTables['users']." where uname='$owner' && uid > 1");
    list($cidtitle)=mysql_fetch_row($result3);
    list($sidtitle)=mysql_fetch_row($result4);
    list($origcidtitle)=mysql_fetch_row($result5);
    list($origsidtitle)=mysql_fetch_row($result6);
    list($modifysubmitteremail)=mysql_fetch_row($result7);
    list($owneremail)=mysql_fetch_row($result8);

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'title', 'url', 'description', 'modifysubmitter', 'origtitle', 'origurl', 'origdescription', 'owner', 'cidtitle', 'sidtitle', 'origcidtitle', 'origsidtitle', 'modifysubmitteremail', 'owneremail' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer

        if ($owner=="") { $owner="administration"; }
        if ($origsidtitle=="") { $origsidtitle= "-----"; }
        if ($sidtitle=="") { $sidtitle= "-----"; }
        echo "
        <table border=1 bordercolor='black' cellpadding=5 cellspacing=0 align='center' width=450>
          <tr>
           <td>
           <table width='100%' bgcolor=dddddd>
             <tr>
               <td valign='top' width='45%'><b>".translate("Original")."</b></td>
               <td rowspan=5 valign=top align='left'><font size=1><br>".translate("Description:")."<br>$origdescription</font></td>
             </tr>
             <tr><td valign='top' width='45%'><font size=1>".translate("Title:")." $origtitle</td></tr>
             <tr><td valign='top' width='45%'><font size=1>".translate("URL:")." <a href=$origurl>$origurl</a></td></tr>
         <tr><td valign='top' width='45%'><font size=1>".translate("Cat:")." $origcidtitle</td></tr>
         <tr><td valign='top' width='45%'><font size=1>".translate("Subcat:")." $origsidtitle</td></tr>
           </table>
           </td>
          </tr>
          <tr>
            <td>
           <table width='100%'>
             <tr>
               <td valign='top' width='45%'><b>".translate("Proposed")."</b></td>
               <td rowspan=5 valign='top' align='left'><font size=1><br>".translate("Description:")."<br>$description</font></td>
             </tr>
             <tr><td valign='top' width='45%'><font size=1>".translate("Title:")." $title</td></tr>
             <tr><td valign='top' width='45%'><font size=1>".translate("URL:")." <a href=$url>$url</a></td></tr>
         <tr><td valign='top' width='45%'><font size=1>".translate("Cat:")." $cidtitle</td></tr>
         <tr><td valign='top' width='45%'><font size=1>".translate("Subcat:")." $sidtitle</td></tr>
           </table>
            </td>
          </tr>
        </table>
        <table align='center' width=450>
          <tr>";
            if ($modifysubmitteremail=="") { echo "<td align=left><font size=1>".translate("Submitter").":  $modifysubmitter</font></td>"; }
            else { echo "<td align='left'><font size=1>".translate("Submitter").":  <a href=mailto:$modifysubmitteremail>$modifysubmitter</a></font></td>"; }
            if ($owneremail=="") { echo "<td align='center'><font size=1>".translate("Owner").":  $owner</font></td>"; }
            else { echo "<td align='center'><font size=1>".translate("Owner").": <a href=mailto:$owneremail>$owner</a></font></td>"; }

            echo "
            <td align='right'><font size=1>( <a href=admin.$phpEx?op=LinksChangeModRequests&requestid=$requestid>".translate("Accept")."</a> / <a href=admin.$phpEx?op=LinksChangeIgnoreRequests&requestid=$requestid>".translate("Ignore")."</a> )</font></td>
          </tr>
        </table><br><br>";
    }

    echo "</td></tr></table>";

    include ("footer.$phpEx");
}

function LinksChangeModRequests($requestid) {
    global $mpnTables,$phpEx;
    $result = mysql_query("select lid, cid, sid, title, url, description from ".$mpnTables['links_modrequest']." where requestid=$requestid");
    while(list($lid, $cid, $sid, $title, $url, $description)=mysql_fetch_row($result)) {
          /*$title = stripslashes(FixQuotes($title));
          $description = stripslashes(FixQuotes($description));*/
          mysql_query("UPDATE ".$mpnTables['links_links']." SET cid='$cid',sid='$sid',title='$title',url='$url',description='$description' WHERE lid='$lid'");

    }
    mysql_query("delete from ".$mpnTables['links_modrequest']." where requestid='$requestid'");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksListModRequests' );

}

function LinksChangeIgnoreRequests($requestid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_modrequest']." where requestid=$requestid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=LinksListModRequests' );
}

function LinksCleanVotes() {
    global $mpnTables,$phpEx;
    $totalvoteresult = mysql_query("select distinct ratinglid FROM ".$mpnTables['links_votedata']);
    while(list($lid)=mysql_fetch_row($totalvoteresult)) {

        $voteresult = mysql_query("select rating, ratinguser, ratingcomments FROM ".$mpnTables['links_votedata']." WHERE ratinglid = $lid");
        $totalvotesDB = mysql_num_rows($voteresult);
        include ("voteinclude.$phpEx");
            mysql_query("UPDATE ".$mpnTables['links_links']." SET linkratingsummary=$finalrating,totalvotes=$totalvotesDB,totalcomments=$truecomments WHERE lid = $lid");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );
}

function LinksModLinkS($lid, $title, $url, $description, $name, $email, $hits, $cat) {
    global $mpnTables,$phpEx;
    $cat = explode("-", $cat);
    if ($cat[1]=="") {
        $cat[1] = 0;
    }
/*    $title = stripslashes(FixQuotes($title));
    $url = stripslashes(FixQuotes($url));
    $description = stripslashes(FixQuotes($description));
    $name = stripslashes(FixQuotes($name));
    $email = stripslashes(FixQuotes($email));*/

    mysql_query("update ".$mpnTables['links_links']." set cid='$cat[0]', sid='$cat[1]', title='$title', url='$url', description='$description', name='$name', email='$email', hits='$hits' where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );
}

function LinksDelLink($lid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_links']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );
}

function LinksModCat($cat) {
    global $mpnTables, $phpEx;
    include ("header.$phpEx");

    $cat = explode("-", $cat);
    if ($cat[1]=="") {
        $cat[1] = 0;
    }
    OpenTable();
    echo "
    <font size=3><b>".translate("Modify Category")."</b></font><br><br>";
    if ($cat[1]==0) {
    $result=mysql_query("select title, cdescription from ".$mpnTables['links_categories']." where cid=$cat[0]");
    list($title,$cdescription) = mysql_fetch_row($result);

    $cdescription = stripslashes($cdescription);
    $title = stripslashes($title);

    echo "<form action=admin.php method=post>\n
    <table border=0>\n
    <tr><td class=w30>".translate("Name: ")."</td><td><input class='textbox' type='text' name='title' value=\"$title\" size=51 maxlength=50></td></tr>\n
    <tr><td valign='top'>".translate("Description: ")."</td><td><textarea name='cdescription' cols=60 rows=10>$cdescription</textarea></td></tr>\n
    </table>\n
    <input type='hidden' name='sub' value=\"0\"\n>
    <input type='hidden' name='cid' value=$cat[0]\n>
    <input type='hidden' name='op' value='LinksModCatS'\n>
    <table border=0><tr><td>\n";

    // Kiril: New Sanitizer

    echo "<input type='hidden' name='stripit_form' value='title|cdescription' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input class='button' type='submit' value='".translate("Save Changes")."'></td><td></form>
    <form action=admin.$phpEx method=post>
    <input type='hidden' name='sub' value=\"0\">
    <input type='hidden' name='cid' value=$cat[0]>
    <input type='hidden' name='op' value='LinksDelCat'>
    <input class='button' type='submit' value=\"".translate("Delete")."\"></form></td></tr></table>";

    } else {
    $result=mysql_query("select title from ".$mpnTables['links_categories']." where cid=$cat[0]");
    list($ctitle) = mysql_fetch_row($result);
    $ctitle = stripslashes($ctitle);
    $result2=mysql_query("select title from ".$mpnTables['links_subcategories']." where sid=$cat[1]");
    list($stitle) = mysql_fetch_row($result2);
    $stitle = stripslashes($stitle);
    echo "<form action=admin.$phpEx method=post>
    ".translate("Category Name: ")."$ctitle<br>
    ".translate("Sub-Category Name: ")."<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'>
    <table border=0><tr><td>\n";

    // Kiril: New Sanitizer

   echo "<input type='hidden' name='stripit_form' value='title' />\n";
    echo "<input type='hidden' name='mpn_sectype' value='2' />\n";

    // End Sanitizer

    echo "<input class='button' type=submit value=\"".translate("Save Changes")."\"></form></td><td>
    <form action=admin.$phpEx method=post>
    <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=LinksDelCat>
    <input class='button' type='submit' value=\"".translate("Delete")."\"></form></td></tr></table>";
    }
    echo "</td></tr></table></td></tr></table><br>";
    include("footer.$phpEx");
}

function LinksModCatS($cid, $sid, $sub, $title, $cdescription) {
    global $mpnTables,$phpEx;
    if ($sub==0) {
    mysql_query("update ".$mpnTables['links_categories']." set title='$title', cdescription='$cdescription' where cid=$cid");
    } else {
    mysql_query("update ".$mpnTables['links_subcategories']." set title='$title' where sid=$sid");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );
}

function LinksDelCat($cid, $sid, $sub, $ok=0) {
    global $mpnTables,$phpEx;
    if($ok==1) {
    if ($sub>0) {
            mysql_query("delete from ".$mpnTables['links_subcategories']." where sid=$sid");
        mysql_query("delete from ".$mpnTables['links_links']." where sid=$sid");
    } else {
        mysql_query("delete from ".$mpnTables['links_categories']." where cid=$cid");
        mysql_query("delete from ".$mpnTables['links_subcategories']." where cid=$cid");
        mysql_query("delete from ".$mpnTables['links_links']." where cid=$cid AND sid=0");
    }

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );

    } else {

    include("header.$phpEx");

    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this Category and ALL its Links?")."</b><br><br><font color=Black>";
    }
    echo "[ <a href=admin.$phpEx?op=LinksDelCat&cid=$cid&sid=$sid&sub=$sub&ok=1>".translate("Yes")."</a> | <a href=admin.$phpEx?op=links>".translate("No")."</a> ]<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");
}


function LinksDelNew($lid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_newlink']." where lid=$lid");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );
}

function LinksAddCat($title, $cdescription) {
    global $mpnTables,$phpEx;
    $result = mysql_query("select cid from ".$mpnTables['links_categories']." where title='$title'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.$phpEx");
    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color='Red'>";
    echo "<b>".translate("ERROR: The Category")." $title ".translate("already exist!")."</b><br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer$phpEx");
    } else {
    mysql_query("insert into ".$mpnTables['links_categories']." values (NULL, '$title', '$cdescription')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );

    }
}

function LinksAddSubCat($cid, $title) {
    global $mpnTables,$phpEx;
    $result = mysql_query("select cid from ".$mpnTables['links_subcategories']." where title='$title' AND cid='$cid'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.$phpEx");
    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("ERROR: The SubCategory")." $title ".translate("already exist!")."</b><br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");
    } else {
    mysql_query("insert into ".$mpnTables['links_subcategories']." values (NULL, '$cid', '$title')");

    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?op=links' );

    }
}

function LinksAddEditorial($linkid, $editorialtitle, $editorialtext) {
    global $aid, $mpnTables,$phpEx;
    //$editorialtext = stripslashes(FixQuotes($editorialtext));
    mysql_query("insert into ".$mpnTables['links_editorials']." values ($linkid, '$aid', now(), '$editorialtext', '$editorialtitle')");
    include("header.$phpEx");
    OpenTable();
    echo "<center><br>";
    echo "<font size=3>";
    echo "".translate("Editorial added to the Database")."<br><br>";
    echo "$linkid  $adminid, $editorialtitle, $editorialtext";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");

}

function LinksModEditorial($linkid, $editorialtitle, $editorialtext) {
    global $mpnTables,$phpEx;
    //$editorialtext = stripslashes(FixQuotes($editorialtext));
    mysql_query("update ".$mpnTables['links_editorials']." set editorialtext='$editorialtext', editorialtitle='$editorialtitle' where linkid=$linkid");
    include("header.$phpEx");

    OpenTable();
    echo "<center><br>";
    echo "<font size=3>";
    echo "".translate("Editorial Modified")."<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";

}

function LinksDelEditorial($linkid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['links_editorials']." where linkid=$linkid");
    include("header.$phpEx");

    OpenTable();
    echo "<center><br>";
    echo "<font size=3>";
    echo "".translate("Editorial removed from Database")."<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";

}

function LinksLinkCheck() {
    global $mpnTables,$phpEx;
    include ("header.$phpEx");

    OpenTable();
    echo "<tr><td colspan=2 width='100%'><center><font size=3><b>".translate("Link Validation")."</b></font></center>
    <br><br><center><a href=admin.$phpEx?op=LinksValidate&cid=0&sid=0>".translate("Check ALL Links")."</a></center><br><br></td><td>";

    echo "<tr><td valign=top><center><b>".translate("Check Categories<br>") . "</b>" . translate("(includes subcategories)") . "<br><br><font size=1>";
    $result = mysql_query("select cid, title from ".$mpnTables['links_categories']." order by title");
    while(list($cid, $title) = mysql_fetch_row($result)) {
        $transfertitle = str_replace (" ", "_", $title);
        echo "<a href=admin.$phpEx?op=LinksValidate&cid=$cid&sid=0>$title</a>()<br>";
    }
    echo "</font></center></td>";
    echo "<td valign=top><center><b>".translate("Check Subcategories")."</b><br><br><br><font size=1>";
    $result = mysql_query("select sid, cid, title from ".$mpnTables['links_subcategories']." order by title");
    while(list($sid, $cid, $title) = mysql_fetch_row($result)) {
        $transfertitle = str_replace (" ", "_", $title);
        $result2 = mysql_query("select title from ".$mpnTables['links_categories']." where cid = $cid");
        while(list($ctitle) = mysql_fetch_row($result2)) {echo "<a href=admin.$phpEx?op=LinksValidate&cid=0&sid=$sid>$ctitle";}
        echo "/$title</a>()<br>";
    }
    echo "</font></center><br><br></td>";
    echo "</table></table>";
    include ("footer.$phpEx");

}

function LinksValidate($cid, $sid) {
    global $mpnTables,$phpEx;
   include ("header.$phpEx");


   $ttitle = getTitle( $lid , translate( 'Validating Category (and all subcategories) For' ) );
   $transfertitle = str_replace ("_", "", $ttitle);
   //Check ALL Links

   echo "<table width='95%' border=1 bordercolor=AAAAAA>";
   if ($cid==0 && $sid==0) {
    echo "<tr><td colspan=3><center><b>".translate("Check ALL Links")."</b><br>".translate("(please be patient)")."</center><br><br></td></tr>";
    $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['links_links']." order by title");
   }
   //Check Categories & Subcategories
   if ($cid!=0 && $sid==0) {
    echo "<tr><td colspan=3><center><b>".translate("Validating Category (and all subcategories)").":  $transfertitle</b><br>(please be patient)</center><br><br></tr></td>";
    $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['links_links']." where cid=$cid order by title");
   }
   //Check Only Subcategory
   if ($cid==0 && $sid!=0) {
    echo "<tr><td colspan=3><center><b>".translate("Validating Subcategory").": $transfertitle</b><br>".translate("(please be patient)")."</center><br><br></tr></td>";
    $result = mysql_query("select lid, title, url, name, email, submitter from ".$mpnTables['links_links']." where sid=$sid order by title");
   }

    while(list($lid, $title, $url, $name, $email, $submitter) = mysql_fetch_row($result))
    {

        // Kiril: Start New Sanitizer

        $sanity_ary = compact( 'title', 'url', 'name', 'email', 'submitter' );
        $_SERVER['SAN'] -> slashIT( $sanity_ary );
        extract( $sanity_ary );
        unset( $sanity_ary );

        // End New Sanitizer

        if (!$fp){
            echo "<tr><td>";
            echo "<b><font color=\"red\">$title</font></b>";
            echo "</td>";
            echo "<td>";
            echo "<a href=$url>$rippedurl</a>";
            echo "</td>";
            echo "<td>";
            echo "$rippedurlright";
            echo "</td></tr>";
        }
        if ($fp){
            echo "<tr><td>";
            echo "<b>$title</b>";
            echo "</td>";
            echo "<td>";
            echo "<a href=$url>$rippedurl</a>";
            echo "</td>";
            echo "<td>";
            echo "$rippedurlright";
            echo "</td></tr>";
        }
    }

    echo "</table>";

   include ("footer.$phpEx");

}

function LinksAddLink($new, $lid, $title, $url, $cat, $description, $name, $email, $submitter) {
    global $sitename, $adminmail, $mpnTables, $phpEx;
    global $smtp, $mailmethod;

    require_once('class.phpmailer.php');
    $mail = new phpmailer();

    /* SET MAIL DELIVERY OPTIONS */
    $mail->IsHTML(true);
    if ($mailmethod == "0") {
        $mail->IsMail();
    } else {
        $mail->IsSMTP();
        $mail->Host = $smtp;
    }

    include("config.$phpEx");
    $result = mysql_query("select url from ".$mpnTables['links_links']." where url='$url'");
    $numrows = mysql_num_rows($result);
    if ($numrows>0) {
    include("header.$phpEx");

    OpenTable();
    echo "<center><br>";
    echo "<font size=3 color='Red'>";
    echo "<b>".translate("ERROR: This URL is already listed in the Database!")."</b><br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    include("footer.$phpEx");
    } else {

    // Check For Empty

    $check_ary = array( $_POST['title'], $_POST['url'], $_POST['description'], $_POST['name'], $_POST['email'] );

    $verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 3 );

    if ( in_array( (bool)FALSE, $verify_check_ary ) )
    {
        goBack( translate( 'You Failed To Include Required Information' ) );
        exit;
    }

    // Check URL

    if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['url'], 1 ) )
    {
        goBack( translate( 'Invalid URL' ) );
        exit;
    }

    // Check Email

    if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['email'], 2 ) )
    {
        goBack( translate( 'Invalid Email' ) );
        exit;
    }

    unset( $check_ary, $verify_check_ary );

    $cat = explode("-", $cat);
    if (!isset($cat[1])) {
        $cat[1] = 0;
    }
    if (isset($cat[1]) && $cat[1]=="") {
        $cat[1] = 0;
    }

    mysql_query("insert into ".$mpnTables['links_links']." values (NULL, '$cat[0]', '$cat[1]', '$title', '$url', '$description', now(), '$name', '$email', '0','$submitter',0,0,0)");
    include("header.$phpEx");

    OpenTable();
    echo "<center><br>";
    echo "<font size=3>";
    echo "".translate("New Link added to the Database")."<br><br>";
    echo "</TD></TR></TABLE></TD></TR></TABLE>";
    if ($new==1) {
    mysql_query("delete from ".$mpnTables['links_newlink']." where lid=$lid");
    if ($email=="") {
    } else {
        $subject = "".translate("Your Link at")." $sitename";
        $message = "".translate("Hello")." $name:\n\n".translate("We approved your link submission for our search engine.")."\n\n".translate("Page Name: ")."$title\n".translate("Page URL: ")."$url\n".translate("Description: ")."$description\n\n\n".translate("You can browse our search engine at:") . " " . _MPN_ROOT_URI . "links.$phpEx\n\n".translate("Thanks for your submission!")."\n\n$sitename ".translate("team.")."";
        $from = "$adminmail";

        $mail->From = $adminmail;
        $mail->FromName = $sitename . translate(' Mailer');
        $mail->AddAddress($email);
        $mail->Subject = stripslashes($subject);
        $mail->Body = nl2br( stripslashes($message) );
        $mail->AltBody = strip_tags( stripslashes($message) );
        $mail->Send();
    }
    }
    include("footer.$phpEx");
    }
}

function getTitle( $lid, $prefix )
{
    global $mpnTables;

    $sql = "SELECT title FROM " . $mpnTables['links_links'] . " WHERE lid = '$lid'";

    $result = mysql_query( $sql );

    if ( ! ( $tmp = mysql_fetch_row( $result ) ) )
    {
        $title = $prefix . ' ' . translate( 'This Link' );
    }
    else
    {
        $title = $tmp[0];
    }

    mysql_free_result( $result );

    return stripslashes( $title );
}


switch ($op) {

        case "links":
            links();
            break;

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

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

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

        case "LinksAddLink":
            if (!isset($cat))
            {
                $cat = '';
            }

            LinksAddLink($new, $lid, $title, $url, $cat, $description, $name, $email, $submitter);
            break;

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

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

        case "LinksLinkCheck":
            LinksLinkCheck();
            break;

        case "LinksValidate":
            LinksValidate($cid, $sid);
            break;

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

        case "LinksCleanVotes":
            LinksCleanVotes();
            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, $description, $name, $email, $hits, $cat);
            break;

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

        case "LinksDelVote":
            LinksDelVote($lid, $rid);
            break;

        case "LinksDelComment":
            LinksDelComment($lid, $rid);
            break;

}

?>
