<?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: automated.php,v 1.9.2.11 2004/08/15 12:58:04 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.       */
/************************************************************************/

checkAccess( 'articles', array( 'article', 'right' ) );

$hlpfile = getHelpFile("automated.html");

/*********************************************************/
/* Automated News Publishing Programming                 */
/*********************************************************/

function puthome($ihome) {
    echo "<br><b>".translate("Publish in Home?")."</b>&nbsp;&nbsp;";
    if (($ihome == 0) OR ($ihome == "")) {
    $sel1 = "checked";
    $sel2 = "";
    }
    if ($ihome == 1) {
    $sel1 = "";
    $sel2 = "checked";
    }
    echo "<input type=radio name=\"ihome\" value=0 $sel1>".translate("Yes")."&nbsp;";
    echo "<input type=radio name=\"ihome\" value=1 $sel2>".translate("No")."";
    echo "&nbsp;&nbsp;<font size=2>[ " .translate("Only works if <i>Articles</i> category isn't selected")." ]</font><br>";
}

function SelectCategory($cat) {
    global $mpnTables,$phpEx;
    $selcat = mysql_query("select catid, title from ".$mpnTables['stories_cat']);
    $a = 1;
    echo "<b>" .translate("Category")."&#058;</b>&nbsp;";

    echo "<select name=\"catid\">";

    $sel = ( $cat == 0 ) ? ( 'selected="yes"' ) : ( NULL );

    echo "<option name=\"catid\" value=\"0\" $sel>" . translate( 'Articles' ) . "</option>";

    while( list( $catid, $title ) = mysql_fetch_row( $selcat ) )
    {

        $sel = ( $a == $cat ) ? ( 'selected="yes"' ) : ( NULL );

        echo "<option name=\"catid\" value=\"$a\" $sel>$title</option>";

        $a++;
    }

    echo '</select>' . "\n";

    if ( _ADMIN_TRUSTED || $GLOBALS['ainf']['article'] )
    {
        echo " [ <a href=admin.$phpEx?op=AddCategory>" .translate("Add")."</a> | <a href=>" .translate("Edit")."</a> | <a href=>" .translate("Delete")."</a> ]";
    }
}

function autoStory() {
    global $hlpfile, $admin, $aid, $mpnTables,$phpEx;
    include ("header.$phpEx");
    GraphicAdmin($hlpfile);

    $ihome = null;

    $result = mysql_query("select anid, title, time from ".$mpnTables['autonews']." order by time ASC");

    if ( @mysql_data_seek( $result, 0 ) )
    {
        echo '<h2>' . translate ( 'Programmed Articles' ) . '</h2><br />' . "\n";

        OpenTable();

        echo "<table border=1 width=100%>";

        while(list($anid, $title, $time) = mysql_fetch_row($result)) {
        if ($anid != "") {
            $time = strftime(translate("datestring3"),strtotime($time));
                echo "<tr><td>&nbsp;<b>(<a href=admin.$phpEx?op=autoEdit&anid=$anid>".translate("Edit")."</a>-<a href=admin.$phpEx?op=autoDelete&anid=$anid>".translate("Delete")."</a>)</b>&nbsp;</td><td width=100%>&nbsp;$title&nbsp;</td><td>&nbsp;$time&nbsp;</td></tr>";
        }
        }
        if ($anid=="") {
        echo "</td></tr></table>";
        } else {
        echo "</table>";
        }

        CloseTable();
        echo "<br>";
    }


    $today = getdate();
    $tday = $today['mday'];
    if ($tday < 10){
    $tday = "0$tday";
    }
    $tmonth = $today['month'];
    $ttmon = $today['mon'];
    if ($ttmon < 10){
    $ttmon = "0$ttmon";
    }
    $tyear = $today['year'];
    $thour = $today['hours'];
    if ($thour < 10){
    $thour = "0$thour";
    }
    $tmin = $today['minutes'];
    if ($tmin < 10){
    $tmin = "0$tmin";
    }
    $tsec = $today['seconds'];
    if ($tsec < 10){
    $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";

    echo '<h2>' . translate ( 'New Automated Article' ) . '</h2><br />' . "\n";

    OpenTable();

    echo "<form action=\"admin.$phpEx\" method=\"post\" name=\"coolsus\">";
    echo "<p><b>".translate("Title")."</b><br>";
    echo "<input class=textbox type=text name=subject size=50 value=\"\"><BR>";
    echo "<BR>";
    echo "<p><b>".translate("Topic")."&#058;</b>&nbsp;";

    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
    echo "<SELECT class=textbox NAME=\"topic\">";
    echo "<OPTION VALUE=\"\">".translate("Select Topic")."</option>\n";
    while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
    if ($topicid==$topic) {
        $sel = "selected ";
    }
        echo "<option $sel value=\"$topicid\">$topics</option>\n";
    $sel = "";
    }
    echo "</select>&nbsp;&nbsp;";
    $cat = 0;
    SelectCategory($cat);
    echo "<br>";
    puthome($ihome);
    echo "
    <P><B>".translate("The Story")."</B><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=hometext></textarea><BR>";
    HTMLbuttons( 1 );
    echo "<P><B>".translate("Extended Text")."</B><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=bodytext></textarea><BR>";
    HTMLbuttons( 2 );

    echo "<input type='hidden' name='clickit_form' value='hometext|bodytext' />\n";

    echo "<br><FONT size=2>".translate("(Are you sure you included a URL? Did ya test them for typos?)")."</FONT><P>
    </select>";
    echo "<font size=3><b>".translate("When do you want to publish this story?")."</b></font><br><br>";
    echo "".translate("Now is:")." $date<br><br>";
    $day = 1;
    echo "".translate("Day:")." <select name=day>";
    while ($day <= 31) {
    if ($tday==$day) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=day $sel>$day</option>";
    $day++;
    }
    echo "</select>";
    $month = 1;
    echo "".translate("Month:")." <select name=month>";
    while ($month <= 12) {
    if ($ttmon==$month) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=month $sel>$month</option>";
    $month++;
    }
    echo "</select>";
    $date = getdate();
    $year = $date['year'];
    echo "".translate("Year:")." <input type=text name=year value=$year size=5 maxlength=4>";
    echo "<br>".translate("Hour:")." <select name=hour>";
    $hour = 0;
    $cero = "0";
    while ($hour <= 23) {
    $dummy = $hour;
    if ($hour < 10) {
        $hour = "$cero$hour";
    }
    echo "<option name=hour>$hour</option>";
    $hour = $dummy;
    $hour++;
    }
    echo "</select>";
    echo " : <select name=min>";
    $min = 0;
    while ($min <= 59) {
    if (($min == 0) OR ($min == 5)) {
        $min = "0$min";
    }
    echo "<option name=min>$min</option>";
    $min = $min + 5;
    }
    echo "</select>";
    echo " : 00<br><br>";

    addFormatOption();

    echo "<select class=textbox name=op>
    <option value=autoPreviewStory SELECTED>".translate("PreviewAdminStory")."</option>
    <option value=autoSaveStory>".translate("PostAdminStory")."</option>
    </select>
    <INPUT class='button' type=submit value=\"".translate("Go!")."\">";

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

function autoPreviewStory($year, $day, $month, $hour, $min, $subject, $hometext, $bodytext, $topic, $catid, $ihome) {
    global $aid, $admin, $language, $hlpfile, $tipath, $mpnTables,$phpEx;
    include ("header.$phpEx");
    if ($topic<1) {
        $topic = 1;
    }
    GraphicAdmin($hlpfile);

    OpenTable();
    echo "<center><b>".translate("Programmed Articles")."</b></center><br><br>";
    echo "<table border=1 width=100%>";
    $result = mysql_query("select anid, title, time from ".$mpnTables['autonews']." order by time ASC");
    while(list($anid, $title, $time) = mysql_fetch_row($result)) {
        if ($anid != "") {
            $time = ereg_replace(" ", "@", $time);
            echo "<tr><td>&nbsp;<b>(<a href=admin.$phpEx?op=autoEdit&anid=$anid>".translate("Edit")."</a>-<a href=admin.$phpEx?op=autoDelete&anid=$anid>".translate("Delete")."</a>)</b>&nbsp;</td><td width=100%>&nbsp;$title&nbsp;</td><td>&nbsp;$time&nbsp;</td></tr>";
        }
    }
    if ($anid=="") {
        echo "</td></tr></table>";
    } else {
        echo "</table>";
    }

    CloseTable();
    echo "<br>";


    $today = getdate();
    $tday = $today['mday'];
    if ($tday < 10){
        $tday = "0$tday";
    }
    $tmonth = $today['month'];
    $tyear = $today['year'];
    $thour = $today['hours'];
    if ($thour < 10){
        $thour = "0$thour";
    }
    $tmin = $today['minutes'];
    if ($tmin < 10){
        $tmin = "0$tmin";
    }
    $tsec = $today['seconds'];
    if ($tsec < 10){
        $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";
    echo "
    <font size=4><b><center>".translate("Preview Automated Story")."</b></font><br><br><br>
    <form action=\"admin.$phpEx\" method=\"post\" name=\"coolsus\">
    </b></center>";

    // Kiril: Start New Sanitizer

    $sanity_ary    = compact( 'hometext', 'bodytext' );
    $_SERVER['SAN'] -> adjustFormat( $sanity_ary, 3, 10 );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer


    if ($topic=="") {
        $topicimage="AllTopics.gif";
        $warning = "<center><blink><b>".translate("Please Select A Topic")."</b></blink></center>";
    } else {
        $warning = "";
        $result = mysql_query("select topicimage from ".$mpnTables['topics']." where topicid='$topic'");
        list($topicimage) = mysql_fetch_row($result);
    }

    if(!$bodytext) {
    $space = "<P>";
    } else {
    $space = "<P>---<P>";
    }

    echo "<center><br /><br />$warning<br /><br />\n";

    echo "<table border=0 width=100% cellpadding=8 cellspacing=1><tr><td>\n";

    echo "<br /><br />\n";

    echo "<img src = \"".$tipath.$topicimage."\" border=0 align=\"right\" style=\"margin: 8px;\">";

    // REFERENCE: themepreview( $title, $hometext, $bodytext = '', $notes = '', $space = '' )

    themepreview( $subject, $hometext1, $bodytext1, $space );

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

    echo "</center>\n";

    echo "<br /><br />\n";

    OpenTable();

    echo "<p><b>".translate("Title")."</b><br>
    <input class=textbox type=text name=subject size=50 value=\"$subject\"><BR>
    <p><b>".translate("Topic")."</b> <select name=topic>";
    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
    echo "<OPTION VALUE=\"\">".translate("All Topics")."</option>\n";
    while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
    if ($topicid==$topic) { $sel = "selected "; }
        echo "<option $sel value=\"$topicid\">$topics</option>\n";
    $sel = "";
    }
    echo "</select>";
    $cat = $catid;
    SelectCategory($cat);
    echo "<br>";
    puthome($ihome);
    echo "
    <p><b>".translate("The Story")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=hometext>$hometext</textarea><BR>";
    HTMLbuttons( 1 );
    echo "<BR><p><b>".translate("Extended Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=bodytext>$bodytext</textarea><BR>";
    HTMLbuttons( 2 );

    echo "<input type='hidden' name='clickit_form' value='hometext|bodytext' />\n";


    echo "<BR><font size=3><b>".translate("When do you want to publish this story?")."</b></font><br><br>";
    echo "".translate("Now is:")." $date<br><br>";
    $xday = 1;
    echo "".translate("Day:")." <select name=day>";
    while ($xday <= 31) {
    if ($xday == $day) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=day $sel>$xday</option>";
    $xday++;
    }
    echo "</select>";
    $xmonth = 1;
    echo "".translate("Month:")." <select name=month>";
    while ($xmonth <= 12) {
    if ($xmonth == $month) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=month $sel>$xmonth</option>";
    $xmonth++;
    }
    echo "</select>";
    echo "".translate("Year:")." <input type=text name=year value=$year size=5 maxlength=4>";
    echo "<br>".translate("Hour:")." <select name=hour>";
    $xhour = 0;
    $cero = "0";
    while ($xhour <= 23) {
    $dummy = $xhour;
    if ($xhour < 10) {
        $xhour = "$cero$xhour";
    }
    if ($xhour == $hour) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=hour $sel>$xhour</option>";
    $xhour = $dummy;
    $xhour++;
    }
    echo "</select>";
    echo " : <select name=min>";
    $xmin = 0;
    while ($xmin <= 59) {
    if (($xmin == 0) OR ($xmin == 5)) {
        $xmin = "0$xmin";
    }
    if ($xmin == $min) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=min $sel>$xmin</option>";
    $xmin = $xmin + 5;
    }
    echo "</select>";
    echo " : 00<br><br>\n";

    addFormatOption();

    echo "<select class=textbox name=op>
    <option value=autoPreviewStory SELECTED>".translate("Preview Again")."</option>
    <option value=autoSaveStory>".translate("Save Auto Story")."</option>
    </select>
    <INPUT class='button' type=submit value=".translate("Go!").">
    </form></td></tr></table></td></tr></table>";
    include ("footer.$phpEx");

}

function autoSaveStory($year, $day, $month, $hour, $min, $subject, $hometext, $bodytext, $topic, $catid, $ihome) {
    global $aid, $admin, $ultramode, $mpnTables,$phpEx, $myts;
    if ($day < 10) {
    $day = "0$day";
    }
    if ($month < 10) {
    $month = "0$month";
    }
    $sec = "00";
    $date = "$year-$month-$day $hour:$min:$sec";
    $notes = "";
    $author = $aid;

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'subject', 'hometext', 'bodytext' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary, TRUE );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer

    $result = mysql_query("insert into ".$mpnTables['autonews']." values (NULL, '$catid', '$aid', '$subject', '$date', '$hometext', '$bodytext', '$topic', '$author', '$notes', '$ihome')");
    if (!$result) {
    echo mysql_errno(). ": ".mysql_error(). "<br>";
    exit();
    }
    $result = mysql_query("update ".$mpnTables['authors']." set counter=counter+1 where aid='$aid'");
    if ($ultramode) {
    ultramode();
    }

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

}

function QautoStory ($qid) {
    global $user, $subject, $story, $tipath, $mpnTables,$phpEx;
    include ("header.$phpEx");

    if (!isset($hlpfile))
    {
        $hlpfile = null;
    }

    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<center><b>".translate("Programmed Articles")."</b></center><br><br>";
    echo "<table border=1 width=100%>";
    $result = mysql_query("select anid, title, time from ".$mpnTables['autonews']." order by time ASC");
    while(list($anid, $title, $time) = mysql_fetch_row($result)) {
    if ($anid != "") {
        $time = ereg_replace(" ", "@", $time);
            echo "<tr><td>&nbsp;<b>(<a href=admin.$phpEx?op=autoEdit&anid=$anid>".translate("Edit")."</a>-<a href=admin.$phpEx?op=autoDelete&anid=$anid>".translate("Delete")."</a>)</b>&nbsp;</td><td width=100%>&nbsp;$title&nbsp;</td><td>&nbsp;$time&nbsp;</td></tr>";
    }
    }
    if ($anid=="") {
    echo "</td></tr></table>";
    } else {
    echo "</table>";
    }

    CloseTable();
    echo "<br>";
    $result = mysql_query("SELECT qid, uid, uname, subject, story, topic FROM ".$mpnTables['queue']." where qid=$qid");
    list($qid, $uid, $uname, $subject, $story, $topic) = mysql_fetch_row($result);
    mysql_free_result($result);

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'subject', 'story' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );

    $story1 = $story;

    $_SERVER['SAN'] -> adjustFormat( $story1, 3, 10 );

    unset( $sanity_ary );

    // End New Sanitizer

    $today = getdate();
    $tday = $today['mday'];
    if ($tday < 10){
    $tday = "0$tday";
    }
    $tmonth = $today['month'];
    $ttmon = $today['mon'];
    if ($ttmon < 10){
    $ttmon = "0$ttmon";
    }
    $tyear = $today['year'];
    $thour = $today['hours'];
    if ($thour < 10){
    $thour = "0$thour";
    }
    $tmin = $today['minutes'];
    if ($tmin < 10){
    $tmin = "0$tmin";
    }
    $tsec = $today['seconds'];
    if ($tsec < 10){
    $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";




    if ($topic=="") {
        $topicimage="AllTopics.gif";
        $warning = "<center><blink><b>".translate("Please Select A Topic")."</b></blink></center>";
    } else {
        $warning = "";
        $result = mysql_query("select topicimage from ".$mpnTables['topics']." where topicid='$topic'");
        list($topicimage) = mysql_fetch_row($result);
    }

    if(!empty($bodytext)) {
    $space = "<P>";
    } else {
    $space = "<P>---<P>";
    }

    echo "<center><br /><br />$warning<br /><br />\n";

    echo "<table border='0' width='100%' cellpadding='8' cellspacing='1'><tr><td>\n";

    echo "<br /><br />\n";

    echo "<img src = \"".$tipath.$topicimage."\" border='0' align=\"right\" style=\"margin: 8px;\">";

    // REFERENCE: themepreview( $title, $hometext, $bodytext = '', $notes = '', $space = '' )

    themepreview( $subject, $story1 );

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

    echo "</center>\n";

    OpenTable();

    echo "<form action=\"admin.$phpEx\" method=\"post\" name=\"coolsus\">
    <p><b>".translate("Name")."</b><br>
    <input class='textbox' type='text' NAME='author' SIZE='50' value=$uname>
    <p><b>".translate("Subject")."</b><br>
    <input class='textbox' type='text' name='subject' size='50' value=\"$subject\">";


    echo "<p><b>" . translate("Topic") . "</b> <select name='topic'>";
    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
        echo "<OPTION VALUE=\"\">".translate("Select Topic")."</option>\n";
        while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
        if ($topicid==$topic) { $sel = "selected "; }
            echo "<option $sel value=\"$topicid\">$topics</option>\n";
        $sel = "";
        }
    echo "</select>";
    $cat = 0;
    SelectCategory($cat);
    echo "<br />";

    if (!isset($ihome))
    {
        $ihome = null;
    }

    puthome($ihome);
    echo "
    <p><b>".translate("Intro Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=hometext>$story</textarea><br>";
    HTMLbuttons( 1 );
    echo "<p><b>".translate("Full Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=28 name=bodytext></textarea><BR>";
    HTMLbuttons( 2 );
    echo "<br><FONT size=2>".translate("(Did you check URLs?)")."</FONT><P>
    <p><b>".translate("Notes")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=10 name=notes></textarea><br>";
    HTMLbuttons( 3 );

    echo "<input type='hidden' name='clickit_form' value='hometext|bodytext|notes' />\n";


    echo "<input type=hidden NAME=qid SIZE=50 value=$qid>
    <input type=hidden NAME=uid SIZE=50 value=$uid>";
    echo "<br><font size=3><b>".translate("When do you want to publish this story?")."</b></font><br><br>";
    echo "".translate("Now is:")." $date<br><br>";
    $day = 1;
    echo "".translate("Day:")." <select name=day>";
    while ($day <= 31) {
    if ($tday==$day) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=day $sel>$day</option>";
    $day++;
    }
    echo "</select>";
    $month = 1;
    echo "".translate("Month:")." <select name=month>";
    while ($month <= 12) {
    if ($ttmon==$month) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=month $sel>$month</option>";
    $month++;
    }
    echo "</select>";
    $date = getdate();
    $year = $date['year'];
    echo "".translate("Year:")." <input type=text name=year value=$year size=5 maxlength=4>";
    echo "<br>".translate("Hour:")." <select name=hour>";
    $hour = 0;
    $cero = "0";
    while ($hour <= 23) {
    $dummy = $hour;
    if ($hour < 10) {
        $hour = "$cero$hour";
    }
    echo "<option name=hour>$hour</option>";
    $hour = $dummy;
    $hour++;
    }
    echo "</select>";
    echo " : <select name=min>";
    $min = 0;
    while ($min <= 59) {
    if (($min == 0) OR ($min == 5)) {
        $min = "0$min";
    }
    echo "<option name=min>$min</option>";
    $min = $min + 5;
    }
    echo "</select>";
    echo " : 00<br><br>";

    addFormatOption();

    echo "<select name=op>
        <option value=DeleteStory>".translate("DeleteStory")."</option>
        <option value=QautoPreview SELECTED>".translate("PreviewAgain")."</option>
        <option value=QautoSave>".translate("PostStory")."</option>
    </select>
    <INPUT class='button' type=submit value=".translate("Go!").">
    </form></td></tr></table></td></tr></table>";
    include ("footer.$phpEx");
}

function QautoPreview($year, $day, $month, $hour, $min, $qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome) {
    global $user, $boxstuff, $tipath, $mpnTables,$phpEx;
    include ("header.$phpEx");

    if (!isset($hlpfile))
    {
        $hlpfile = null;
    }

    GraphicAdmin($hlpfile);

    OpenTable();
    echo "<center><b>".translate("Programmed Articles")."</b></center><br><br>";
    echo "<table border=1 width=100%>";
    $result = mysql_query("select anid, title, time from ".$mpnTables['autonews']." order by time ASC");
    while(list($anid, $title, $time) = mysql_fetch_row($result)) {
    if ($anid != "") {
        $time = ereg_replace(" ", "@", $time);
            echo "<tr><td>&nbsp;<b>(<a href=admin.$phpEx?op=autoEdit&anid=$anid>".translate("Edit")."</a>-<a href=admin.$phpEx?op=autoDelete&anid=$anid>".translate("Delete")."</a>)</b>&nbsp;</td><td width=100%>&nbsp;$title&nbsp;</td><td>&nbsp;$time&nbsp;</td></tr>";
    }
    }
    if ($anid=="") {
    echo "</td></tr></table>";
    } else {
    echo "</table>";
    }

    CloseTable();

    $today = getdate();
    $tday = $today['mday'];
    if ($tday < 10){
    $tday = "0$tday";
    }
    $tmonth = $today['month'];
    $tyear = $today['year'];
    $thour = $today['hours'];
    if ($thour < 10){
    $thour = "0$thour";
    }
    $tmin = $today['minutes'];
    if ($tmin < 10){
    $tmin = "0$tmin";
    }
    $tsec = $today['seconds'];
    if ($tsec < 10){
    $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";

    // Kiril: Start New Sanitizer

    $hometext1 = $hometext;
    $bodytext1 = $bodytext;
    $notes1    = $notes;

    $sanity_ary = compact( 'hometext1', 'bodytext1', 'notes1' );
    $_SERVER['SAN'] -> adjustFormat( $sanity_ary, 3, 10 );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer


    if ($topic=="") {
        $topicimage="AllTopics.gif";
        $warning = "<center><blink><b>".translate("Please Select A Topic")."</b></blink></center>";
    } else {
        $warning = "";
        $result = mysql_query("select topicimage from ".$mpnTables['topics']." where topicid='$topic'");
        list($topicimage) = mysql_fetch_row($result);
    }

    if(!$bodytext) {
    $space = "<P>";
    } else {
    $space = "<P>---<P>";
    }

    echo "<center><br /><br />$warning<br /><br />\n";

    echo "<table border=0 width=100% cellpadding=8 cellspacing=1><tr><td>\n";

    echo "<br /><br />\n";

    echo "<img src = \"".$tipath.$topicimage."\" border=0 align=\"right\" style=\"margin: 8px;\">";

    // REFERENCE: themepreview( $title, $hometext, $bodytext = '', $notes = '', $space = '' )

    themepreview( $subject, $hometext1, $bodytext1, $notes1, $space );

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

    echo "</center>\n";

    echo "<br /><br />\n";

    OpenTable();

    echo "<form action=\"admin.$phpEx\" method=\"post\" name=\"coolsus\">
    <p><b>".translate("Name")."</b><br>
    <input class=textbox type=text NAME=author SIZE=50 value=$author>
    <p><b>".translate("Subject")."</b><br>
    <input class=textbox type=text name=subject size=50 value=\"$subject\">";


    echo "<p><b>".translate("Topic")."</b> <select name=topic>";
    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
        echo "<OPTION VALUE=\"\">".translate("All Topics")."</option>\n";
        while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
        if ($topicid==$topic) { $sel = "selected "; }
            echo "<option $sel value=\"$topicid\">$topics</option>\n";
        $sel = "";
        }
    echo "</select>";
    $cat = $catid;
    SelectCategory($cat);
    echo "<br>";
    puthome($ihome);
    echo "
    <p><b>".translate("Intro Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=hometext>$hometext</textarea><br>";
    HTMLbuttons( 1 );
    echo "<p><b>".translate("Full Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=bodytext>$bodytext</textarea><BR>";
    HTMLbuttons( 2 );
    echo "<br><FONT size=2>".translate("(Did you check URLs?)")."</FONT><P>
    <p><b>".translate("Notes")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=10 name=notes>$notes</textarea><br>";
    HTMLbuttons( 3 );

    echo "<input type='hidden' name='clickit_form' value='hometext|bodytext|notes' />\n";


    echo "<input type=hidden NAME=qid SIZE=50 value=$qid>
    <input type=hidden NAME=uid SIZE=50 value=$uid>";
    echo "<br><font size=3><b>".translate("When do you want to publish this story?")."</b></font><br><br>";
    echo "".translate("Now is:")." $date<br><br>";
    $xday = 1;
    echo "".translate("Day:")." <select name=day>";
    while ($xday <= 31) {
    if ($xday == $day) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=day $sel>$xday</option>";
    $xday++;
    }
    echo "</select>";
    $xmonth = 1;
    echo "".translate("Month:")." <select name=month>";
    while ($xmonth <= 12) {
    if ($xmonth == $month) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=month $sel>$xmonth</option>";
    $xmonth++;
    }
    echo "</select>";
    echo "".translate("Year:")." <input type=text name=year value=$year size=5 maxlength=4>";
    echo "<br>".translate("Hour:")." <select name=hour>";
    $xhour = 0;
    $cero = "0";
    while ($xhour <= 23) {
    $dummy = $xhour;
    if ($xhour < 10) {
        $xhour = "$cero$xhour";
    }
    if ($xhour == $hour) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=hour $sel>$xhour</option>";
    $xhour = $dummy;
    $xhour++;
    }
    echo "</select>";
    echo " : <select name=min>";
    $xmin = 0;
    while ($xmin <= 59) {
    if (($xmin == 0) OR ($xmin == 5)) {
        $xmin = "0$xmin";
    }
    if ($xmin == $min) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=min $sel>$xmin</option>";
    $xmin = $xmin + 5;
    }
    echo "</select>";
    echo " : 00<br><br>\n";

    addFormatOption();

    echo "<select name=op>
        <option value=DeleteStory>".translate("DeleteStory")."</option>
        <option value=QautoPreview SELECTED>".translate("PreviewAgain")."</option>
        <option value=QautoSave>".translate("PostStory")."</option>
    </select>
    <INPUT class='button' type=submit value=".translate("Go!")."></FORM>
    </td></tr></table></td></tr></table>";
    include ("footer.$phpEx");
}

function QautoSave($year, $day, $month, $hour, $min, $qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome) {
    global $aid, $ultramode, $mpnTables,$phpEx;
    if ($day < 10) {
    $day = "0$day";
    }
    if ($month < 10) {
    $month = "0$month";
    }
    $sec = "00";
    $date = "$year-$month-$day $hour:$min:$sec";
    if ($uid == 1) $author = "";
    if ($hometext == $bodytext) $bodytext = "";


    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'subject', 'hometext', 'bodytext', 'notes' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary, TRUE );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer


    $result = mysql_query("insert into ".$mpnTables['autonews']." values (NULL, '$catid', '$aid', '$subject', '$date', '$hometext', '$bodytext', '$topic', '$author', '$notes', '$ihome')");
    if (!$result) {
        echo mysql_errno(). ": ".mysql_error(). "<br>";
        return;
    }
    if ($uid > 1)
    {
        mysql_query("update ".$mpnTables['users']." set counter=counter+1 where uid='$uid'");
    }
        mysql_query("update ".$mpnTables['authors']." set counter=counter+1 where aid='$aid'");
    if ($ultramode) {
            ultramode();
    }
    mysql_query("delete from ".$mpnTables['queue']." where qid=$qid");

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


}

function autoDelete($anid) {
    global $mpnTables,$phpEx;
    mysql_query("delete from ".$mpnTables['autonews']." where anid=$anid");

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

function autoEdit($anid) {
    global $aid, $admin, $hlpfile, $tipath, $mpnTables,$phpEx;
    include ("header.$phpEx");
    $result = mysql_query("select catid, aid, title, time, hometext, bodytext, topic, informant, notes, ihome from ".$mpnTables['autonews']." where anid=$anid");
    list($catid, $aid, $title, $time, $hometext, $bodytext, $topic, $informant, $notes, $ihome) = mysql_fetch_row($result);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    GraphicAdmin($hlpfile);

    //OpenTable();

    $today = getdate();
    $tday = $today['mday'];
    if ($tday < 10){
    $tday = "0$tday";
    }
    $tmonth = $today['month'];
    $tyear = $today['year'];
    $thour = $today['hours'];
    if ($thour < 10){
    $thour = "0$thour";
    }
    $tmin = $today['minutes'];
    if ($tmin < 10){
    $tmin = "0$tmin";
    }
    $tsec = $today['seconds'];
    if ($tsec < 10){
    $tsec = "0$tsec";
    }
    $date = "$tmonth $tday, $tyear @ $thour:$tmin:$tsec";
    echo "
    <font size=4><b><center>".translate("Edit Automated Story")."</b></font><br><br><br>
    <form action=\"admin.$phpEx\" method=post>
    </b></center>";

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'title', 'hometext', 'bodytext', 'notes' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary );
    extract( $sanity_ary );

    $title1    = $title;
    $hometext1 = $hometext;
    $bodytext1 = $bodytext;
    $notes1    = $notes;

    $sanity_ary    = compact( 'hometext1', 'bodytext1', 'notes1' );
    $_SERVER['SAN'] -> adjustFormat( $sanity_ary, 3, 10 );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer

    if ($topic=="") {
        $topicimage="AllTopics.gif";
        $warning = "<center><blink><b>".translate("Please Select A Topic")."</b></blink></center>";
    } else {
        $warning = "";
        $result = mysql_query("select topicimage from ".$mpnTables['topics']." where topicid='$topic'");
        list($topicimage) = mysql_fetch_row($result);
    }

    if(!$bodytext) {
    $space = "<P>";
    } else {
    $space = "<P>---<P>";
    }

    echo "<center><br /><br />$warning<br /><br />\n";

    echo "<table border=0 width=100% cellpadding=8 cellspacing=1><tr><td>\n";

    echo "<br /><br />\n";

    echo "<img src = \"".$tipath.$topicimage."\" border=0 align=\"right\" style=\"margin: 8px;\">";

    // REFERENCE: themepreview( $title, $hometext, $bodytext = '', $notes = '', $space = '' )

    themepreview( $title1, $hometext1, $bodytext1, $notes1, $space );

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

    echo "</center>\n";

    echo "<br /><br />\n";

    OpenTable();

/*
    $title = stripslashes($title);
    $hometext = oops_br2nl(stripslashes($hometext));
    $bodytext = oops_br2nl(stripslashes($bodytext));
    $notes = oops_br2nl(stripslashes($notes));
    if(!$bodytext) {
    $space = "<P>";
    } else {
    $space = "<P>---<P>";
    }

    $result=mysql_query("select topicimage from ".$mpnTables['topics']." where topicid=$topic");
    list($topicimage) = mysql_fetch_row($result);
    echo "<center><br>
    <table border=0 width=75% cellpadding=0 cellspacing=1 bgcolor=000000><tr><td>
    <table border=0 width=100% cellpadding=8 cellspacing=1 bgcolor=FFFFFF><tr><td>";
    echo "";
    echo "<img src = \"".$tipath.$topicimage."\" alt = \"\" border = \"0\" align = \"right\">\n";
    $hometext1 = oops_nl2br(stripslashes($hometext));
    $bodytext1 = oops_nl2br(stripslashes($bodytext));
    $notes1 = oops_nl2br(stripslashes($notes));
    themepreview($title, $hometext1, $space, $bodytext1);
    echo "</td></tr></table></td></tr></table></center>*/


    echo "<p><b>".translate("Title")."</b><br>
    <input class=textbox type=text name=title size=50 value=\"$title\"><BR>
    <p><b>".translate("Topic")."</b> <select name=topic>";
    $toplist = mysql_query("select topicid, topictext from ".$mpnTables['topics']." order by topictext");
    echo "<OPTION VALUE=\"\">".translate("All Topics")."</option>\n";
    while(list($topicid, $topics) = mysql_fetch_row($toplist)) {
    if ($topicid==$topic) { $sel = "selected "; }
        echo "<option $sel value=\"$topicid\">$topics</option>\n";
    $sel = "";
    }
    echo "</select>";
    $cat = $catid;
    SelectCategory($cat);
    echo "<br>";
    puthome($ihome);
    echo "
    <p><b>".translate("The Story")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=hometext>$hometext</textarea><BR><BR>
    <p><b>".translate("Extended Text")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=20 name=bodytext>$bodytext</textarea><BR><BR>";

    if ($aid != $informant) {
        echo "<p><b>".translate("Notes")."</b><br>
    <textarea class=textbox wrap=virtual cols=70 rows=10 name=notes>$notes</textarea><BR><BR>";
    }
    echo "<font size=3><b>".translate("When do you want to publish this story?")."</b></font><br><br>";
    echo "".translate("Now is:")." $date<br><br>";
    $xday = 1;
    echo "".translate("Day:")." <select name=day>";
    while ($xday <= 31) {
    if ($xday == $datetime[3]) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=day $sel>$xday</option>";
    $xday++;
    }
    echo "</select>";
    $xmonth = 1;
    echo "".translate("Month:")." <select name=month>";
    while ($xmonth <= 12) {
    if ($xmonth == $datetime[2]) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=month $sel>$xmonth</option>";
    $xmonth++;
    }
    echo "</select>";
    echo "".translate("Year:")." <input type=text name=year value=$datetime[1] size=5 maxlength=4>";
    echo "<br>".translate("Hour:")." <select name=hour>";
    $xhour = 0;
    $cero = "0";
    while ($xhour <= 23) {
    $dummy = $xhour;
    if ($xhour < 10) {
        $xhour = "$cero$xhour";
    }
    if ($xhour == $datetime[4]) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=hour $sel>$xhour</option>";
    $xhour = $dummy;
    $xhour++;
    }
    echo "</select>";
    echo " : <select name=min>";
    $xmin = 0;
    while ($xmin <= 59) {
    if (($xmin == 0) OR ($xmin == 5)) {
        $xmin = "0$xmin";
    }
    if ($xmin == $datetime[5]) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=min $sel>$xmin</option>";
    $xmin = $xmin + 5;
    }
    echo "</select>";
    echo " : 00<br><br>\n";

    addFormatOption();

    echo "<input type='hidden' name='clickit_form' value='hometext|bodytext|notes' />\n";

    echo "
    <input type=hidden name=anid value=$anid>
    <input type=hidden name=op value=autoSaveEdit>
    <INPUT class='button' type=submit value=\"".translate("Save Changes")."\">
    </form></td></tr></table></td></tr></table>";
    include ("footer.$phpEx");

}

function autoSaveEdit($anid, $year, $day, $month, $hour, $min, $title, $hometext, $bodytext, $topic, $notes, $catid, $ihome) {
    global $aid, $admin, $ultramode, $mpnTables,$phpEx;
    if ($day < 10) {
    $day = "0$day";
    }
    if ($month < 10) {
    $month = "0$month";
    }
    $sec = "00";
    $date = "$year-$month-$day $hour:$min:$sec";

    // Kiril: Start New Sanitizer

    $sanity_ary = compact( 'title', 'hometext', 'bodytext', 'notes' );
    $_SERVER['SAN'] -> slashIT( $sanity_ary, TRUE );

    extract( $sanity_ary );
    unset( $sanity_ary );

    // End New Sanitizer


    $result = mysql_query("update ".$mpnTables['autonews']." set catid='$catid', title='$title', time='$date', hometext='$hometext', bodytext='$bodytext', topic='$topic', notes='$notes', ihome='$ihome' where anid=$anid");
    if (!$result) {
    echo mysql_errno(). ": ".mysql_error(). "<br>";
    exit();
    }
    if ($ultramode) {
    ultramode();
    }

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

switch($op)
{
    case "autoStory":
        autoStory();
        break;

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

    case "autoDelete":
        autodelete($anid);
        break;

    case "QautoPreview":
        QautoPreview($year, $day, $month, $hour, $min, $qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome);
        break;

    case "QautoStory":
        QautoStory($qid);
        break;

    case "QautoSave":
        QautoSave($year, $day, $month, $hour, $min, $qid, $uid, $author, $subject, $hometext, $bodytext, $topic, $notes, $catid, $ihome);
        break;

    case "autoSaveStory":
        autoSaveStory($year, $day, $month, $hour, $min, $subject, $hometext, $bodytext, $topic, $catid, $ihome);
        break;

    case "autoPreviewStory":
        autoPreviewStory($year, $day, $month, $hour, $min, $subject, $hometext, $bodytext, $topic, $catid, $ihome);
        break;

    case "autoEdit":
        autoEdit($anid);
        break;

    case "autoSaveEdit":
        autoSaveEdit($anid, $year, $day, $month, $hour, $min, $title, $hometext, $bodytext, $topic, $notes, $catid, $ihome);
        break;

    DEFAULT:
        autoStory();
        break;

}

?>
