<?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: qotd.php,v 1.5.2.6 2004/08/15 12:58:22 kirilt Exp $




######################################################################
# PHP-NUKE: Web Portal System
# ===========================
#
# Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
# http://phpnuke.org
#
# This module is the main administration part
#
# 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.
######################################################################
# PHP-NUKE 4.4: Quote of the day Add-On
# =====================================
#
#        Brought to you by Erik Slooff
#
# Copyright (c) 2000 by Erik Slooff (erik@slooff.com)
#
# http://www.slooff.com
#
######################################################################


// Basic function to display the admin stuff for the Quote Add-on
function QotdAdmin() {
    global $admin,$phpEx;
    OpenTable();
    echo "</center><font size=4><b>" .translate("Add Quote")."</b><br>
    <a href =\"admin.$phpEx?fct=qotd&op=QotdDisplay&page=1\">" .translate("Modify Quotes")."</a></font><br><br>
    <font size=2>
    <form action=admin.$phpEx?fct=qotd method=post>
    <table border=0 width=100%><tr><td>
    " .translate("Quote text:")." </td><td><textarea class=textbox name=qquote cols=60 rows=5></textarea></td></tr><tr><td>
    " .translate("Author:")." </td><td><input class=textbox type=text name=qauthor size=31 maxlength=128></td></tr><tr><td>
    </td></tr></table>
    <input type=hidden name=op value=QotdAdd>\n";


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

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

// need to do some work here
// change this function...
function QotdAdd($qquote, $qauthor) {
    global $mpnTables,$phpEx;
    $time = date("Y-m-d");
    mysql_query("insert into ".$mpnTables['quotes']." (quote, author) values ('$qquote', '$qauthor')");

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

}

function QotdDisplay($page) {
    global $keyword, $mpnTables,$phpEx;
    OpenTable();
    $keyword2 = ereg_replace(" ", "%", $keyword);
        $whereclause = "where quote like \"%".$keyword2."%\"";
    if ($keyword == "") $whereclause = "";
    $result = mysql_query("SELECT COUNT(*) as help FROM ".$mpnTables['quotes']." $whereclause");
    list($numrecords) = mysql_fetch_row($result);
    $entriesperpage = 20;
    $totalpages = ceil($numrecords / $entriesperpage);
    if ($numrecords > 0) {
        echo "</center><font size=4><b>" .translate("Modify Quotes")."</b></font><br><br>
        <table><tr><td>
        <form action=admin.$phpEx method=post>
        " .translate("Search for quote:")." <input class=textbox type=text name=keyword size=31 maxlength=128 value=\"$keyword\">
        <input type=hidden name=page value=1>
        <input type=hidden name=op value=QotdDisplay>
        <input type=hidden name=fct value=\"qotd\">
        <input class='button' type=submit value=\"" .translate("Search")."\">
        </form></td><td><form action=admin.$phpEx method=post>
        <input type=hidden name=page value=1>
        <input type=hidden name=op value=QotdDisplay>
        <input type=hidden name=fct value=\"qotd\">
        <input class='button' type=submit value=\"" .translate("Reset Search")."\">
        </form></td></tr></table>
        <font size=2>
        <table border width=\"100%\">";
        echo "<tr><td>" .translate("Quote")."</td><td>" .translate("Author")."</td><td>" .translate("Action")."</td></tr>";
        $start = $entriesperpage * ($page - 1);
        $result = mysql_query("SELECT qid, quote, author FROM ".$mpnTables['quotes']." $whereclause order by qid limit $start, $entriesperpage");
        while(list($qqid, $qquote, $qauthor) = mysql_fetch_array($result))
        {
            $qquote = stripslashes( $qquote );
            $qauthor = stripslashes( $qauthor );

            echo "<tr><td>".substr($qquote,0,50)."</td><td>".substr($qauthor,0,50)."</td>";
            echo "<td><a href=\"admin.$phpEx?fct=qotd&op=QotdEdit&qid=$qqid&page=$page\">" .translate("Edit")."</a> | <a href=\"admin.$phpEx?fct=qotd&op=QotdDelete&qid=$qqid&page=$page\">" .translate("Delete")."</a></td>";
            echo "</tr>";
        }
        echo "</table><br>";
        if ($page > 1) {
            $prevpage = $page - 1;
        } else {
            $prevpage = 0;
        }
        if ($page < $totalpages) {
            $nextpage = $page + 1;
        } else {
            $nextpage = 0;
        }
        echo "<table border=0 width=\"100%\"><tr><td align=\"center\" width=\"33%\">";
        if ($prevpage != 0) {
            echo "<a href=\"admin.$phpEx?fct=qotd&op=QotdDisplay&page=$prevpage&keyword=$keyword\">" .translate("Previous Page")."</a>";
        } else {
            echo " ";
        }
        echo "</td><td align=\"center\" width=\"33%\">";
        echo "<a href=\"admin.$phpEx?fct=qotd\">" .translate("back")."</a>";
        echo "</td><td align=\"center\" width=\"33%\">";
        if ($nextpage !=0) {
            echo "<a href=\"admin.$phpEx?fct=qotd&op=QotdDisplay&page=$nextpage&keyword=$keyword\">" .translate("Next Page")."</a>";
        } else {
            echo " ";
        }
        echo "</td></tr></table>";
    } else {
        echo translate("No quotes found");
    }
    echo "</td></tr></table></td></tr></table>";

}

function QotdDelete($qid,$page) {
    global $phpEx;
    OpenTable();
    echo "</center><font size=4><b>" .translate("Delete Quote")."</b><br><br>";
    echo "<center>";
    echo "<font size=3 color=Red>";
    echo "<b>".translate("WARNING: Are you sure you want to delete this quote?")."</b><br><br><font color=Black>";
    echo "[ <a href=admin.$phpEx?fct=qotd&op=QotdDeleteOk&qid=$qid&page=$page>".translate("Yes")."</a> | <a href=admin.$phpEx?fct=qotd&op=QotdDisplay&page=$page>".translate("No")."</a> ]<br><br>";
    echo "</td></tr></table></td></tr></table>";
}

function QotdDeleteOk($qid,$page) {
    global $mpnTables,$phpEx;
    mysql_query("DELETE FROM ".$mpnTables['quotes']." where qid='$qid'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=qotd&op=QotdDisplay&page=' . $page );

}

function QotdEdit($qid,$page) {
    global $mpnTables,$phpEx;
    $result = mysql_query("SELECT quote, author FROM ".$mpnTables['quotes']." WHERE qid = '$qid'");
    list($quote,$author) = mysql_fetch_row($result);
    OpenTable();
    echo "</center><font size=4><b>" .translate("Edit Quote")."</b><br><br>
    <font size=2>
    <form action=admin.$phpEx?fct=qotd method=post>
    <table border=0 width=100%><tr><td>
    " .translate("Quote text:")." </td><td><textarea class=\"textbox\" name=\"qquote\" cols=\"60\" rows=\"5\">$quote</textarea></td></tr><tr><td>
    " .translate("Author:")." </td><td><input class=\"textbox\" type=\"text\" name=\"qauthor\" size=\"31\" maxlength=\"128\" value=\"$author\"></td></tr><tr><td>
    </td></tr></table>
    <input type=hidden name=op value=QotdSave>
    <input type=hidden name=page value=$page>
    <input type=hidden name=qqid value=$qid>\n";

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

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

function QotdSave($qqid,$qquote,$qauthor,$page) {
    global $mpnTables,$phpEx;
    mysql_query("UPDATE ".$mpnTables['quotes']." set quote='$qquote', author='$qauthor' WHERE qid='$qqid'");

        $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?fct=qotd&op=QotdDisplay&page=' . $page );
}

?>
