Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/modules/NS-Autolink/admin/modules/autolink.php
<?php // File: $Id: autolink.php,v 1.20 2001/12/05 23:16:53 nkame Exp $ $Name:  $
// ----------------------------------------------------------------------
// Autolink Tool for Post-Nuke
// Version 0.4b
// Copyright (C) 2001 by Jens Wallenhort (hide@address.com).
// http://www.nusite.de/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Jens Wallenhorst (hide@address.com)
// Purpose of file: "main file" for autolink
// ----------------------------------------------------------------------

if (!eregi("admin.php", $PHP_SELF)) { die ("Access Denied"); }
$hlpfile = "manual/autolink.html";

modules_get_language();

//main function and screen
function autolink() {
    global $hlpfile, $pntable, $dbconn, $autolinkpref;
    include ("header.php");
    $sel_autolinkpref[$GLOBALS['autolinkpref']] = ' checked';
    GraphicAdmin($hlpfile);

    // Admin options
    if (authorised(0, 'Autolinks::', '::', ACCESS_ADMIN)) {
        OpenTable();
    
        echo "<tr><td>";
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<table>";
        echo "<tr><td colspan=\"2\"><font class=\"pn-title\">AutoLink "._PREFERENCES."</font></td></tr>";
        echo "<tr><td><font class=\"pn-normal\">"._DEACTIVATE."</font></td><td><input type=\"radio\" name=\"newautolinkpref\" value=\"0\" $sel_autolinkpref[0]></td></tr>";
        echo "<tr><td><font class=\"pn-normal\">"._FSTORY."</font></td><td><input type=\"radio\" name=\"newautolinkpref\" value=\"1\" $sel_autolinkpref[1]></td></tr>";
        echo "<tr><td><font class=\"pn-normal\">News-"._INDEX." "._AND." "._FSTORY."</font></td><td><input type=\"radio\" name=\"newautolinkpref\" value=\"2\" $sel_autolinkpref[2]></td></tr>";
        echo "<tr><td><input type=\"hidden\" name=\"op\" value=\"AlSetPrefs\">";
        echo "<input type=\"submit\" value="._SAVE."></td></tr></form>";
        echo "</table>";
        echo "</td><td>";
        echo "<center><b>"._AUTOLINK."</b><br>";
        $result = $dbconn->Execute("SELECT COUNT(*) FROM $pntable[autolinks]");
        list($numrows) = $result->fields;

        echo "<font class=\"pn-normal\">"._THEREARE." <b>$numrows</b> "._LINKSIN."</font></center>";
        echo "</td></tr>";
    
        CloseTable();
        echo "<br>";
   }

    // New entry
    if (authorised(0, 'Autolinks::', '::', ACCESS_ADD)) {
        OpenTable();
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<font class=\"pn-sub\"><b>"._KEYWORD."</b><br></font>";
        echo "<input type=\"text\" name=\"keyword\" size=\"25\" maxlength=\"100\"><br>";
        echo "<font class=\"pn-sub\"><b>"._TITLE."</b><br></font>";
        echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\"><br>";
        echo "<font class=\"pn-sub\"><b>"._URL."</b><br></font>";
        echo "<input type=\"text\" name=\"url\" size=\"60\" maxlength=\"200\"><br>";
        echo "<font class=\"pn-sub\"><b>"._AUTOCOMMENTS."</b><br></font>";
        echo "<input type=\"text\" name=\"comment\"  size=\"60\" maxlength=\"200\"><br>";
        echo "<input type=\"hidden\" name=\"op\" value=\"AlAddLink\">";
        echo "<input type=\"submit\" value="._ADD."></form>";
        CloseTable();
    }
    
    // Search current
    if (authorised(0, 'Autolinks::', '::', ACCESS_EDIT)) {
        OpenTable();
        echo "<form action=\"admin.php\" method=\"post\">";
        echo "<font class=\"pn-sub\"><b>"._SEARCHON." "._KEYWORD.", "._URL.", "._TITLE.":</b><br></font>";
        echo "<input type=\"text\" name=\"lookup\" size=\"15\" maxlength=\"15\"><br>";
        echo "<input type=\"hidden\" name=\"op\" value=\"AlShowLinks\">";
        echo "<input type=\"submit\" value="._SEARCH."></form>";
        CloseTable();
    }

    include ("footer.php");
} // autolink

//displays search results for links
function AlShowLinks($lookup) {
    global $hlpfile, $pntable, $dbconn;
    
    csrfcheck();

    // how many records match the search text?
    // fifers.  we only grab the max 'lid' because it is only used if one row is returned...
    $column = &$pntable['autolinks_column'];
    $result = $dbconn->Execute("SELECT MAX($column[lid]) as lid, count(*) FROM $pntable[autolinks] WHERE $column[keyword] LIKE '%$lookup%' OR $column[title] LIKE '%$lookup%' OR $column[url] LIKE '%$lookup%' ");
//ADODBtag list+row
    list($lid, $numrows) = $result->fields;
    // more than one match -> show list
    if ($numrows>1) {
        include ("header.php");
        GraphicAdmin($hlpfile);
        OpenTable();
    
        echo "<table border=\"1\">";
        $column = &$pntable['autolinks_column'];
        $result=$dbconn->Execute("SELECT $column[lid], $column[keyword], $column[url], $column[title], $column[comment] FROM $pntable[autolinks] WHERE $column[keyword] LIKE '%$lookup%' OR $column[title] LIKE '%$lookup%' OR $column[url] LIKE '%$lookup%' ORDER BY $column[title]");
    
//ADODBtag MoveNext while+list+row
        while(list($lid, $keyword,$url, $title, $comment) = $result->fields) {

            $result->MoveNext();
            if (authorised(0, 'Autolinks::', "$keyword::$lid", ACCESS_READ)) {
                echo "<tr valign=\"top\"><td>";
                if (authorised(0, 'Autolinks::', "$keyword::$lid", ACCESS_EDIT)) {
                    echo "<a href=\"admin.php?op=AlEditLink&lid=$lid\">$keyword</a>";
                } else {
                    echo "$keyword";
                }
                echo "</td><td>$title</td><td>$url</td><td>$comment</td></tr>";
            }
        }// while
    
        echo "</table>";
        CloseTable();
        exit();
    }// if
    // only one record -> show editing form
    else {
        pnRedirect('admin.php?op=AlEditLink&lid='.$lid);
        exit();
    }// elseif
    pnRedirect('admin.php?op=autolink');
    
}// AlShowLinks

// shows editing screen for a link entry
function AlEditLink($lid) {
    global $hlpfile, $pntable, $dbconn;

    csrfcheck();

    include ("header.php");
    GraphicAdmin($hlpfile);
    OpenTable();
    
    // select record
    $column = &$pntable['autolinks_column'];
    $result = $dbconn->Execute("SELECT $column[lid], $column[keyword],$column[url], $column[title], $column[comment] FROM $pntable[autolinks] WHERE $column[lid]=$lid");
//ADODBtag MoveNext while+list+row
    while(list($lid, $keyword,$url, $title, $comment) = $result->fields) {

        $result->MoveNext();
        if (authorised(0, 'Autolinks::', "$keyword::$lid", ACCESS_EDIT)) {
            echo "<form action=\"admin.php\" method=\"post\">";
            echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
            echo "<font class=\"pn-sub\"><b>Keyword</b><br></font>";
            echo "<input type=\"text\" name=\"keyword\" value=\"$keyword\" size=\"25\" maxlength=\"100\"><br>";
            echo "<font class=\"pn-sub\"><b>Title</b><br></font>";
            echo "<input type=\"text\" name=\"title\"  value=\"$title\" size=\"60\" maxlength=\"100\"><br>";
            echo "<font class=\"pn-sub\"><b>URL</b><br></font>";
            echo "<input type=\"text\" name=\"url\" value=\"$url\" size=\"60\" maxlength=\"200\"><br>";
            echo "<font class=\"pn-sub\"><b>"._AUTOCOMMENTS."</b><br></font>";
            echo "<input type=\"text\" name=\"comment\"  value=\"$comment\" size=\"60\" maxlength=\"200\"><br>";
            echo "<input type=\"hidden\" name=\"op\" value=\"AlUpdateLink\"><input type=\"submit\" value="._SAVE.">";
            echo " &nbsp; ";
            echo" </form>";
            if (authorised(0, 'Autolinks::', "$keyword::$lid", ACCESS_DELETE)) {
                echo "<form action=\"admin.php\" method=\"post\">";
                echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">";
                echo "<input type=\"hidden\" name=\"op\" value=\"AlDelLink\">";
                echo "<input type=\"submit\" value="._DELETE.">";
            }
        }
    }// while
}// AlEditLink


// deletes a link entry
function AlDelLink($lid) {
    global $pntable, $dbconn;

    csrfcheck();

    $column = &$pntable['autolinks_column'];

    $result = $dbconn->Execute("SELECT $column[keyword]
                              FROM $pntable[autolinks]
                              WHERE $column[lid] = $lid");
//ADODBtag list+row
    list($keyword) = $result->fields;
    $result->Close();
    if (!authorised(0, 'Autolinks::', "$keyword::$lid", ACCESS_DELETE)) {
        include 'header.php';
        echo _ALINKSDELNOAUTH;
        include 'footer.php';
        return;
    }
    $dbconn->Execute("DELETE FROM $pntable[autolinks] WHERE $column[lid]=$lid");
    pnRedirect("admin.php?op=autolink");
}// AlDelLink


// updates a link entry
function AlUpdateLink($lid, $keyword,$url, $title, $comment) {
    global $pntable, $dbconn;

    csrfcheck();

    $column = &$pntable['autolinks_column'];

    // NB: use *OLD* keyword for auth
    $result = $dbconn->Execute("SELECT $column[keyword]
                              FROM $pntable[autolinks]
                              WHERE $column[lid] = $lid");
//ADODBtag list+row
    list($oldkeyword) = $result->fields;
    $result->Close();
    if (!authorised(0, 'Autolinks::', "$oldkeyword::$lid", ACCESS_EDIT)) {
        include 'header.php';
        echo _ALINKSEDITNOAUTH;
        include 'footer.php';
        return;
    }

    $column = &$pntable['autolinks_column'];
    $dbconn->Execute("UPDATE $pntable[autolinks] SET $column[keyword]='$keyword',$column[url]='$url',$column[title]='$title',$column[comment]='$comment' WHERE $column[lid]=$lid");

    pnRedirect("admin.php?op=autolink");
}// AlUpdateLink

// adds a link entry
function AlAddLink($keyword, $title, $url, $comment) {
    global $pntable, $dbconn;

    csrfcheck();

    if (!authorised(0, 'Autolinks::', "$keyword::", ACCESS_ADD)) {
        include 'header.php';
        echo _ALINKSADDNOAUTH;
        include 'footer.php';
        return;
    }

    $column = &$pntable['autolinks_column'];
    $dbconn->Execute("INSERT INTO $pntable[autolinks] ($column[keyword], $column[title], $column[url], $column[comment]) VALUES ('$keyword', '$title', '$url', '$comment')");

    pnRedirect("admin.php?op=autolink");
}// AlAddLink


// sets preferences
function AlSetPrefs($newautolinkpref) {

    csrfcheck();

    if (!authorised(0, 'Autolinks::', '::', ACCESS_ADMIN)) {
        include 'header.php';
        echo _ALINKSCONFIGNOAUTH;
        include 'footer.php';
    } else {
        $configContent = file (WHERE_IS_PERSO.'config.php');
        $configContent = preg_replace ('/(pnconfig\[\'?autolinkpref\'?\] =|autolinkpref =) [0-9](;)/','\1 '.$newautolinkpref.'\2',$configContent);
        $newConfigFile = join ('', $configContent);
        if ($fh = fopen(WHERE_IS_PERSO."config.php","w")) {
            fwrite($fh,$newConfigFile);
            fclose($fh);
        } 

        pnRedirect("admin.php?op=autolink");
    }
}// AlSetPrefs



if (!authorised(0, 'Autolinks::', '::', ACCESS_ADD)) {
    include 'header.php';
    echo _ALINKSNOAUTH;
    include 'footer.php';
} else {

    switch ($op) {
    
        //mainfile
        case "autolink":
             autolink();
             break;
    
        // adds a link
        case "AlAddLink":
                AlAddLink($keyword, $title, $url, $comment);
            break;
    
        // displays link editing form
        case "AlEditLink":
            AlEditLink($lid);
            break;

        // deletes a link
        case "AlDelLink":
                AlDelLink($lid);
            break;

        // displays search results for links
        case "AlShowLinks":
            AlShowLinks($lookup);
            break;
    
        //updates the database entry for a link
        case "AlUpdateLink":
                AlUpdateLink($lid, $keyword,$url, $title, $comment) ;
            break;

        //set the preferences
        case "AlSetPrefs":
                AlSetPrefs($newautolinkpref) ;
            break;
    }
}

?>
Return current item: ProNuke. Postnuke To Oracle