<?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");
}

    $aid = substr("$aid", 0,25);
    $result = $db->sql_query("select radminsuper from ".TABLE_AUTHORS." where aid='$aid'");
    list($radminsuper) = $db->sql_fetchrow($result);
    $radminsuper = $db->XMFbin($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();
       // GraphicAdmin();
       if ( $wysiwyg == 'fck' ) {
   	include_once('FCKeditor/fckeditor.php');
   	}
        Max_OpenTable();
        echo "<center><font class='title'><b>"._ARTICLEADMIN."</b></font></center>";
        Max_CloseTable();

        echo "<br />";

        $result1 = $db->sql_query("SELECT catid, title, hometext, bodytext, topic, notes, ihome, alanguage, acomm FROM ".TABLE_STORIES." where sid='$sid' ");
        list($catid, $subject, $hometext, $bodytext, $topic, $notes, $ihome, $alanguage, $acomm) = $db->sql_fetchrow($result1);
        $catid = $db->XMFnum($catid);
        $subject = stripslashes($subject);
        $hometext = stripslashes($hometext);
        $bodytext = stripslashes($bodytext);
        $notes = stripslashes($notes);
        $ihome = $db->XMFbin($ihome);
        $acomm = $db->XMFbin($acomm);
        $result2=$db->sql_query("select topicimage from ".TABLE_TOPICS." where topicid='$topic'");
        list($topicimage) = $db->sql_fetchrow($result2);
        Max_OpenTable();
        echo "<center><font class=\"option\"><b>"._EDITARTICLE."</b></font></center><br />"
            ."<table width=\"80%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"$bgcolor2\" align=\"center\"><tr><td>"
            ."<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\" bgcolor=\"$bgcolor1\"><tr><td>"
            ."<img src=\"images/topics/$topicimage\" border=\"0\" align=\"right\">";
        themepreview($subject, $hometext, $bodytext, $notes);
        echo "</td></tr></table></td></tr></table><br /><br />"
            ."<form action=\"".$admin_file.".php\" method=\"post\">"
            ."<b>"._TITLE."</b><br />"
            ."<input type=\"text\" name=\"subject\" size=\"50\" value=\"$subject\"><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>";
        echo "<br /><br />";
        // Copyright (c) 2000-2005 by NukeScripts Network
        if($Version_Num) {
            $asql = "SELECT associated FROM ".TABLE_STORIES." WHERE sid='$sid'";
            $aresult = $db->sql_query($asql);
            $arow = $db->sql_fetchrow($aresult);
            $asso_t = explode("-", $arow[associated]);
            echo "<table border='0' width='100%' cellspacing='0'><tr><td width='20%'><b>"._ASSOTOPIC."</b></td><td width='100%'>"
                ."<table border='1' cellspacing='3' cellpadding='8'><tr>";
            $sql = "SELECT topicid, topictext FROM ".TABLE_TOPICS." ORDER BY topictext";
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if ($a == 3) {
                    echo "</tr><tr>";
                    $a = 0;
                }
                for ($i=0; $i<sizeof($asso_t); $i++) {
                    if ($asso_t[$i] == $row[topicid]) {
                        $checked = "CHECKED";
                        break;
                    }
                }
                echo "<td><input type='checkbox' name='assotop[]' value='$row[topicid]' $checked>$row[topictext]</td>";
                $checked = "";
                $a++;
            }
            echo "</tr></table></td></tr></table><br /><br />";
        }
        // Copyright (c) 2000-2005 by NukeScripts Network
        $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 name=\"alanguage\" value=\"$languageslist[$i]\" ";
                    if($languageslist[$i]==$alanguage) echo "selected";
                    echo ">".ucfirst($languageslist[$i])."\n</option>";
                }
            }
            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 />";
if ( $wysiwyg == 'fck' ) {
$oFCKeditor = new FCKeditor(hometext) ;
$oFCKeditor->InstanceName = "hometext" ;
$oFCKeditor->Value = "$hometext" ;
$oFCKeditor->Create() ;
} else {
    echo "<textarea wrap=\"virtual\" cols=\"100\" rows=\"30\" name=\"hometext\">$hometext</textarea>";
}

echo "<br /><br /><b>"._EXTENDEDTEXT."</b><br />";
if ( $wysiwyg == 'fck' ) {
$oFCKeditor = new FCKeditor(bodytext) ;
$oFCKeditor->InstanceName = "bodytext" ;
$oFCKeditor->Value = "$bodytext" ;
$oFCKeditor->Create() ;
} else {
echo "<textarea wrap=\"virtual\" cols=\"100\" rows=\"30\" name=\"bodytext\">$bodytext</textarea>";
}

echo "<br /><font class=\"content\">"._AREYOUSURE."</font><br /><br />"
            ."<b>"._NOTES."</b><br />";

if ( $wysiwyg == 'fck' ) {
$oFCKeditor = new FCKeditor(notes) ;
$oFCKeditor->InstanceName = "notes" ;
$oFCKeditor->Value = "$notes" ;
$oFCKeditor->Create() ;
} else {
 echo "<textarea wrap=\"virtual\" cols=\"100\" rows=\"20\" name=\"notes\">$notes</textarea>";
 }
echo "<br /><br /><input type=\"hidden\" NAME=\"sid\" size=\"50\" value=\"$sid\">"
            ."<input type=\"hidden\" name=\"op\" value=\"ChangeStory\">"
            ."<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();
    }