<?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                                 */
/************************************************************************/
/********************************************************/
/* NSN News                                             */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright  2000-2005 by NukeScripts Network         */
/********************************************************/

global $db, $admin_file;
if(!$admin_file OR $admin_file == "") { $admin_file = "admin"; }
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
    redirect_url("../../".$admin_file.".php");
    die();
}
$aid = substr("$aid", 0,25);
$row = $db->sql_fetchrow($db->sql_query("SELECT `title`, `admins` FROM `".TABLE_MODULES."` WHERE `title`='News'"));
$row2 = $db->sql_fetchrow($db->sql_query("SELECT `name`, `radminsuper` FROM `".TABLE_AUTHORS."` WHERE `aid`='$aid'"));
$admins = explode(",", $row['admins']);
$auth_user = 0;
for ($i=0; $i < sizeof($admins); $i++) {
    if ($row2['name'] == "$admins[$i]" AND $row['admins'] != "") { $auth_user = 1;        }
}

include_once ("modules/News/includes/functions.php");
$ne_config = ne_get_configs();
if ($row['radminsuper'] == 1) { $radminsuper = 1; }
if ($row2['radminsuper'] == 1 || $auth_user == 1) {


function themepreview($title, $hometext, $bodytext="", $notes="") {
	echo "<b>$title</b><br /><br />$hometext";
	if ($bodytext != "") {
	br('2');
		echo "$bodytext";
	}
	if ($notes != "") {
	br('2');
		echo "<b>"._NOTE."</b> <i>$notes</i>";
	}
}

function ne_save_config($config_name, $config_value){
    global $prefix, $db;
    $db->sql_query("UPDATE ".$prefix."_nsnne_config SET config_value='$config_value' WHERE config_name='$config_name'");
}


function menunews() {
global $admin_file, $db, $prefix;
Max_opentable();
echo "<center><a href='".$admin_file.".php?op=homenews'><fonr size='3'>"._ARTICLEADMIN."</font></a></center>";
Max_CloseTable();

br('1');

$num_autonews = $db->sql_numrows($db->sql_query("SELECT anid FROM ".TABLE_AUTONEWS." "));
$num_queue = $db->sql_numrows($db->sql_query("SELECT qid FROM ".TABLE_QUEUE." "));


Max_opentable();
echo "<table width='100%'><td width='33%' align='center' VALIGN='TOP'>"
	."<b>"._ARTICLEAD."</b><br /><br />"
	."<a href='".$admin_file.".php?op=adminStory'>"._ADDARTICLE."</a><br />";
if ($num_queue == 0) {
echo  "<FONT size='2'>"._NE_NOSUBMISSION."</font><br />";
} elseif ($num_queue == 1) {
echo  "<a href='".$admin_file.".php?op=submissions'><FONT COLOR='RED' size='2'>"._NE_SUBMISSION."</font></a><br />";
} else {
echo  "<a href='".$admin_file.".php?op=submissions'><FONT COLOR='RED' size='2'>"._NE_SUBMISSIONS."</font></a><font size='1'> ( $num_queue )</font><br />";
}

if ($num_autonews == 0) {
echo "<FONT size='2'>"._NE_NOPROGRAM."</font><br /><br />";
} elseif ($num_autonews == 1) {
echo "<FONT COLOR='RED' size='2'>"._NE_PROGRAM."</FONT><br /><br />";
} else {
echo "<FONT COLOR='RED' size='2'>"._NE_PROGRAMS."</a><font size='1'> ( $num_autonews )</font><br /><br />";
}
echo "<a href='".$admin_file.".php?op=NENewsConfig'>"._NE_NEWSCONFIG."</a><br />";
echo "</td><td width='33%' align='center' VALIGN='TOP'>"
	."<b>"._LAST." "._ARTICLES."</b><br /><br />"
	."<a href='".$admin_file.".php?op=lastarticles&var=10'>"._LAST." 10 "._ARTICLES."</a><br />"
	."<a href='".$admin_file.".php?op=lastarticles&var=20'>"._LAST." 20 "._ARTICLES."</a><br />"
	."<a href='".$admin_file.".php?op=lastarticles&var=50'>"._LAST." 50 "._ARTICLES."</a><br />"
	."<a href='".$admin_file.".php?op=lastarticles&var=100'>"._LAST." 100 "._ARTICLES."</a><br />";
echo "</td><td width='33%' align='center' VALIGN='TOP'>"
	."<b>"._TOPICSMANAGER . "</b><br /><br />"
	."<a href='".$admin_file.".php?op=topicadd'>"._ADDATOPIC."</a><br />"
	."<a href='".$admin_file.".php?op=topicmodify'>"._EDITTOPIC."</a><br />"
	."<a href='".$admin_file.".php?op=topicdelunused'>"._REMOVEPICTURES."</a><br />";
echo "</td></table>";
Max_CloseTable();
br('1');


// submit news
if ($num_queue) {
	Max_OpenTable();
	echo "<center><b>"._SUBMITNEWS."</b></center><br />";
	$count = 0;
	$result4 = $db->sql_query("SELECT qid, uname, subject, timestamp, alanguage FROM ".TABLE_QUEUE." ORDER BY qid ASC");
	while ($row4 = $db->sql_fetchrow($result4)) {
		$qid = $db->XMFnum($row4['qid']);
		$subject = stripslashes($row4['subject']);
		$uname = stripslashes($row4['uname']);
		$timestamp = $row4['timestamp'];
		$alanguage = $db->XMFlang($row4['alanguage']);
		if ($alanguage == "") {
			$alanguage = ""._ALL."";
		}
		if ($qid != "") {
			if ($count == 0) {
				echo "<table border=\"1\" width=\"100%\">";
				$count = 1;
			}


$row = $db->sql_fetchrow($db->sql_query("SELECT radminsuper FROM ".TABLE_AUTHORS." WHERE aid='$aid'"));
$radminsuper = $db->XMFnum($row['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;
		}
	}
			if (($radminarticle==1) OR ($radminsuper==1)) {
				if (($radminarticle==1) AND ($aid == $said) OR ($radminsuper==1)) {
					echo "<tr><td nowrap>&nbsp;<a href=\"".$admin_file.".php?op=DisplayStory&amp;qid=$qid\"><img src=\"images/edit.gif\" alt=\""._EDIT."\" title=\""._EDIT."\" border=\"0\" width=\"17\" height=\"17\"></a>  <a href=\"".$admin_file.".php?op=DeleteStory&amp;qid=$qid\"><img src=\"images/delete.gif\" alt=\""._DELETE."\" title=\""._DELETE."\" border=\"0\" width=\"17\" height=\"17\"></a>&nbsp;</td><td width=\"100%\">&nbsp;$subject&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td align=\"center\">&nbsp;$uname&nbsp;</td><td nowrap>&nbsp;$timestamp&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
				} else {
					echo "<tr><td>&nbsp;("._NOFUNCTIONS.")&nbsp;</td><td width=\"100%\">&nbsp;$title&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td align=\"center\">&nbsp;$uname&nbsp;</td><td nowrap>&nbsp;$time&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
				}
			} else {
				echo "<tr><td width=\"100%\">&nbsp;$subject&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td nowrap>&nbsp;$timestamp&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
			}
		}
	}
	if ($count == 1) {
		echo "</table>";
	}
	Max_CloseTable();
br('1');
}
// automated news
if ($num_autonews) {
	Max_OpenTable();
	echo "<center><b>"._AUTOMATEDARTICLES."</b></center><br />";
	$count = 0;
	$result5 = $db->sql_query("SELECT anid, aid, title, time, alanguage FROM ".TABLE_AUTONEWS." $queryalang ORDER BY time ASC");
	while ($row5 = $db->sql_fetchrow($result5)) {
		$anid = $db->XMFnum($row5['anid']);
		$aid = $row5['aid'];
		$said = substr("$aid", 0,25);
		$title = stripslashes($row5['title']);
		$time = $row5['time'];
		$alanguage = $db->XMFlang($row5['alanguage']);
		if ($alanguage == "") {
			$alanguage = ""._ALL."";
		}
		if ($anid != "") {
			if ($count == 0) {
				echo "<table border=\"1\" width=\"100%\">";
				$count = 1;
			}
			$time = ereg_replace(" ", "@", $time);

$row = $db->sql_fetchrow($db->sql_query("SELECT radminsuper FROM ".TABLE_AUTHORS." WHERE aid='$aid'"));
$radminsuper = $db->XMFnum($row['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;
		}
	}
			if (($radminarticle==1) OR ($radminsuper==1)) {
				if (($radminarticle==1) AND ($aid == $said) OR ($radminsuper==1)) {
					echo "<tr><td nowrap>&nbsp;<a href=\"".$admin_file.".php?op=autoEdit&amp;anid=$anid\"><img src=\"images/edit.gif\" alt=\""._EDIT."\" title=\""._EDIT."\" border=\"0\" width=\"17\" height=\"17\"></a>  <a href=\"".$admin_file.".php?op=autoDelete&amp;anid=$anid\"><img src=\"images/delete.gif\" alt=\""._DELETE."\" title=\""._DELETE."\" border=\"0\" width=\"17\" height=\"17\"></a>&nbsp;</td><td width=\"100%\">&nbsp;$title&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td nowrap>&nbsp;$time&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
				} else {
					echo "<tr><td>&nbsp;("._NOFUNCTIONS.")&nbsp;</td><td width=\"100%\">&nbsp;$title&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td nowrap>&nbsp;$time&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
				}
			} else {
				echo "<tr><td width=\"100%\">&nbsp;$title&nbsp;</td><td align=\"center\">&nbsp;$alanguage&nbsp;</td><td nowrap>&nbsp;$time&nbsp;</td></tr>"; /* Multilingual Code : added column to display language */
			}
		}
	}
	if (($anid == "") AND ($count == 0)) {
		echo "<center><i>"._NOAUTOARTICLES."</i></center>";
	}
	if ($count == 1) {
		echo "</table>";
	}
	Max_CloseTable();
 br('1');
}

}

function homenews() {
incoh();
menunews();
incof();
}

/*********************************************************/
/* Story/News Functions                                  */
/*********************************************************/

function puthome($ihome, $acomm) {
    echo "<br /><b>"._PUBLISHINHOME."</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>"._YES."&nbsp;"
        ."<input type=\"radio\" name=\"ihome\" value=\"1\" $sel2>"._NO.""
        ."&nbsp;&nbsp;<font class=\"content\">[ "._ONLYIFCATSELECTED." ]</font><br />";

    echo "<br /><b>"._ACTIVATECOMMENTS."</b>&nbsp;&nbsp;";
    if (($acomm == 0) OR ($acomm == "")) {
        $sel1 = "checked";
        $sel2 = "";
    }
    if ($acomm == 1) {
        $sel1 = "";
        $sel2 = "checked";
    }
    echo "<input type=\"radio\" name=\"acomm\" value=\"0\" $sel1>"._YES."&nbsp;"
        ."<input type=\"radio\" name=\"acomm\" value=\"1\" $sel2>"._NO."</font><br /><br />";

}

function putpoll($pollTitle, $optionText) {
  //  Max_OpenTable();
    echo "<center><font class='title'><b>"._ATTACHAPOLL."</b></font><br />"
        ."<font class=\"tiny\">"._LEAVEBLANKTONOTATTACH."</font><br />"
        ."<br /><br />"._POLLTITLE.": <input type=\"text\" name=\"pollTitle\" size=\"50\" maxlength=\"100\" value=\"$pollTitle\"><br /><br />"
        ."<font class=\"content\">"._POLLEACHFIELD."<br />"
        ."<table border=\"0\">";
    for($i = 1; $i <= 12; $i++)        {
        echo "<tr>"
            ."<td>"._OPTION." $i:</td><td><input type=\"text\" name=\"optionText[$i]\" size=\"50\" maxlength=\"50\" value=\"$optionText[$i]\"></td>"
            ."</tr>";
    }
    echo "</table>";
  //  Max_CloseTable();
}

function selectcategory($num) {
    global $db, $prefix, $admin_file;
    $selcat = $db->sql_query("select `catid`, `title` from `".TABLE_STORIES_CAT."` order by `title`");
    $a = 1;
    echo "<b>"._CATEGORY."</b> ";
    echo "<select name=\"catid\">";
    if ($cat == 0) {
        $sel = "selected";
    } else {
        $sel = "";
    }
    echo "<option name=\"catid\" value=\"0\" $sel>"._ARTICLES."</option>";
    while(list($catid, $title) = $db->sql_fetchrow($selcat)) {
        $catid = $db->XMFnum($catid);
        if ($catid == $cat) {
            $sel = "selected";
        } else {
            $sel = "";
        }
        echo "<option name=\"catid\" value=\"$catid\" $sel>$title</option>";
        $a++;
    }
    echo "</select> [ <a href=\"".$admin_file.".php?op=AddCategory\">"._ADD."</a> | <a href=\"".$admin_file.".php?op=EditCategory\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=DelCategory\">"._DELETE."</a> ]";
}
if($admintest && $adminsecu)  {
switch($op) {

    case 'homenews':homenews();break;
    case 'lastarticles';include_once('modules/News/admin/includes/lastarticles.php');break;
    case 'EditCategory':include_once('modules/News/admin/includes/EditCategory.php');break;
    case 'subdelete':include_once('modules/News/admin/includes/subdelete.php');break;
    case 'DelCategory':include_once('modules/News/admin/includes/DelCategory.php');break;
    case 'YesDelCategory':include_once('modules/News/admin/includes/YesDelCategory.php');break;
    case 'NoMoveCategory':include_once('modules/News/admin/includes/NoMoveCategory.php');break;
    case 'SaveEditCategory':include_once('modules/News/admin/includes/SaveEditCategory.php');break;
    case 'AddCategory':include_once('modules/News/admin/includes/AddCategory.php');break;
    case 'SaveCategory':include_once('modules/News/admin/includes/SaveCategory.php');break;
    case 'DisplayStory':include_once('modules/News/admin/includes/DisplayStory.php');break;
    case 'previewStory':include_once('modules/News/admin/includes/previewStory.php');break;
    case 'PreviewAgain':include_once('modules/News/admin/includes/previewStory.php');break;
    case 'PostStory':include_once('modules/News/admin/includes/PostStory.php');break;
    case 'EditStory':include_once('modules/News/admin/includes/EditStory.php');break;
    case 'RemoveStory':include_once('modules/News/admin/includes/RemoveStory.php');break;
    case 'ChangeStory':include_once('modules/News/admin/includes/ChangeStory.php');break;
    case 'DeleteStory':include_once('modules/News/admin/includes/DeleteStory.php');break;
    case 'adminStory':include_once('modules/News/admin/includes/adminStory.php');break;
    case 'PreviewAdminStory':include_once('modules/News/admin/includes/PreviewAdminStory.php');break;
    case 'PostAdminStory':include_once('modules/News/admin/includes/PostAdminStory.php');break;
    case 'autoDelete':include_once('modules/News/admin/includes/autoDelete.php');break;
    case 'autoEdit':include_once('modules/News/admin/includes/autoEdit.php');break;
    case 'autoSaveEdit':include_once('modules/News/admin/includes/autoSaveEdit.php');break;
    case 'submissions':include_once('modules/News/admin/includes/submissions.php');break;
    case 'NENewsConfig':include_once('modules/News/admin/includes/NENewsConfig.php');break;
    case 'NENewsConfigSave':include_once('modules/News/admin/includes/NENewsConfigSave.php');break;

}
}
} else {
        incoh();
        Max_OpenTable();
        echo "<center><b>"._ERROR."</b><br /><br />You do not have administration permission for module \"$module_name\"</center>";
        Max_CloseTable();
        incof();
}