<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
    Header("Location: index.php");
}

    $sid = $db->XMFnum($sid);
    $aid = substr("$aid", 0,25);
    $result = $db->sql_query("select radminsuper from ".TABLE_AUTHORS." where aid='$aid'");
    $rar = $db->sql_fetchrow($result);
    $radminsuper = $db->XMFbin($rar['radminsuper']);
        $result = $db->sql_query("SELECT admins FROM ".TABLE_MODULES." WHERE title='News'");
        $row2 = $db->sql_fetchrow($db->sql_query("SELECT name FROM ".TABLE_AUTHORS." WHERE aid='$aid'"));
        while ($row = $db->sql_fetchrow($result)) {
                $admins = explode(",", $row['admins']);
                $auth_user = 0;
                for ($i=0; $i < sizeof($admins); $i++) {
                        if ($row2['name'] == "$admins[$i]") {
                                $auth_user = 1;
                        }
                }
                if ($auth_user == 1) {
                        $radminarticle = 1;
                }
        }
    $result2 = $db->sql_query("select aid from ".TABLE_STORIES." where sid='$sid'");
    list($aaid) = $db->sql_fetchrow($result2);
    $aaid = substr("$aaid", 0,25);
    if (($radminarticle == 1) AND ($aaid == $aid) OR ($radminsuper == 1)) {
    incoh();
    $result = $db->sql_query("select catid, aid, title, time, hometext, bodytext, topic, informant, notes, ihome, alanguage, acomm from ".TABLE_AUTONEWS." where anid='$anid'");
    list($catid, $aid, $title, $time, $hometext, $bodytext, $topic, $informant, $notes, $ihome, $alanguage, $acomm) = $db->sql_fetchrow($result);
        $catid = $db->XMFnum($catid);
        $aid = substr("$aid", 0,25);
        $informant = substr("$informant", 0,25);
        $ihome = $db->XMFbin($ihome);
        $acomm = $db->XMFbin($acomm);
    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);
    menunews();
    Max_OpenTable();
    echo "<center><font class='title'><b>"._ARTICLEADMIN."</b></font></center>";
    Max_CloseTable();
    echo "<br />";
    Max_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 "<center><font class=\"option\"><b>"._AUTOSTORYEDIT."</b></font></center><br /><br />"
        ."<form action=\"".$admin_file.".php\" method=\"post\">";
    $title = stripslashes($title);
    $hometext = stripslashes($hometext);
    $bodytext = stripslashes($bodytext);
    $notes = stripslashes($notes);
    $result=$db->sql_query("select topicimage from ".TABLE_TOPICS." where topicid='$topic'");
    list($topicimage) = $db->sql_fetchrow($result);
    echo "<table border=\"0\" width=\"75%\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"$bgcolor2\" align=\"center\"><tr><td>"
        ."<table border=\"0\" width=\"100%\" cellpadding=\"8\" cellspacing=\"1\" bgcolor=\"$bgcolor1\"><tr><td>"
        ."<img src=\"images/topics/$topicimage\" border=\"0\" align=\"right\">";
    themepreview($title, $hometext, $bodytext);
    echo "</td></tr></table></td></tr></table>"
        ."<br /><br /><b>"._TITLE."</b><br />"
        ."<input type=\"text\" name=\"title\" size=\"50\" value=\"$title\"><br /><br />"
        ."<b>"._TOPIC."</b> <select name=\"topic\">";
    $toplist = $db->sql_query("select topicid, topictext from ".TABLE_TOPICS." order by topictext");
    echo "<option value=\"\">"._ALLTOPICS."</option>\n";
    while(list($topicid, $topics) = $db->sql_fetchrow($toplist)) {
        $topicid = $db->XMFnum($topicid);
    if ($topicid==$topic) { $sel = "selected "; }
        echo "<option $sel value=\"$topicid\">$topics</option>\n";
        $sel = "";
    }
    echo "</select><br /><br />";
    $cat = $catid;
    SelectCategory($cat);
    echo "<br />";
    puthome($ihome, $acomm);
    if ($multilingual == 1) {
        echo "<br /><b>"._LANGUAGE.": </b>"
            ."<select name=\"alanguage\">";
        $handle=opendir('language');
        while ($file = readdir($handle)) {
            if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
                $langFound = $matches[1];
                $languageslist .= "$langFound ";
            }
        }
        closedir($handle);
        $languageslist = explode(" ", $languageslist);
        sort($languageslist);
        for ($i=0; $i < sizeof($languageslist); $i++) {
            if($languageslist[$i]!="") {
                echo "<option value=\"$languageslist[$i]\" ";
                if($languageslist[$i]==$alanguage) echo "selected";
                echo ">".ucfirst($languageslist[$i])."</option>\n";
            }
        }
        if ($alanguage == "") {
            $sellang = "selected";
        } else {
                $sellang = "";
        }
        echo "<option value=\"\" $sellang>"._ALL."</option></select>";
    } else {
        echo "<input type=\"hidden\" name=\"alanguage\" value=\"\">";
    }
    echo "<br /><br /><b>"._STORYTEXT."</b><br />"
        ."<textarea wrap=\"virtual\" cols=\"100\" rows=\"30\" name=\"hometext\">$hometext</textarea><br /><br />"
        ."<b>"._EXTENDEDTEXT."</b><br />"
        ."<textarea wrap=\"virtual\" cols=\"100\" rows=\"30\" name=\"bodytext\">$bodytext</textarea><br />"
        ."<font class=\"content\">"._ARESUREURL."</font><br /><br />";
    if ($aid != $informant) {
            echo "<b>"._NOTES."</b><br />
        <textarea wrap=\"virtual\" cols=\"100\" rows=\"20\" name=\"notes\">$notes</textarea><br /><br />";
    }
    echo "<br /><b>"._CHNGPROGRAMSTORY."</b><br /><br />"
        .""._NOWIS.": $date<br /><br />";
    $xday = 1;
    echo ""._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 ""._UMONTH.": <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 ""._YEAR.": <input type=\"text\" name=\"year\" value=\"$datetime[1]\" size=\"5\" maxlength=\"4\">";
    echo "<br />"._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 />
    <input type=\"hidden\" name=\"anid\" value=\"$anid\">
    <input type=\"hidden\" name=\"op\" value=\"autoSaveEdit\">
    <input type=\"submit\" value=\""._SAVECHANGES."\">
    </form>";
    Max_CloseTable();
    incof();
    } else {
        incoh();
        GraphicAdmin();
        Max_OpenTable();
        echo "<center><font class='title'><b>"._ARTICLEADMIN."</b></font></center>";
        Max_CloseTable();
        echo "<br />";
        Max_OpenTable();
        echo "<center><b>"._NOTAUTHORIZED1."</b><br /><br />"
            .""._NOTAUTHORIZED2."<br /><br />"
            .""._GOBACK."";
        Max_CloseTable();
        incof();
    }