Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/PortalSources/NewsManagement.php
<?php
/*
*****************************************************************

 NewsManagement.php
 
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version:                  LSP 2.0 "Enigma 2"
Software by:                         Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by:       Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at:    http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it 
under the terms of the provided license as published by Lunabyte Systems.

This program is distributed in the hope that it is and will be useful,                  
but WITHOUT ANY WARRANTIES; without even any implied warranty of           
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        

See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/

if (!defined('ENIGMA'))
	die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');

function NewsManageHub()
{
	global $context, $txt, $user_info;

	isAllowedTo('manage_news');

	loadPTemplate('NewsManagement');
	loadPLanguage('News');

	$context['page_title'] = !empty($txt['news_124']) ? $txt['news_124'] : 'LSP News Category Management';

	// Load the common admin stuff... select 'Block_Management'.
	if ($user_info['is_admin'])
		adminIndex('News_Management');



	$sa = (!empty($_POST['sa'])) ? $_POST['sa'] :
		!empty($_REQUEST['sa']) ? $_REQUEST['sa'] :
		!empty($_GET['sa']) ? $_GET['sa'] : '';

	$subActions = array(
			'ancat2',
			'delncat',
			'encat',
			'encat2',
		);

	if (in_array($sa, $subActions))
		$sa();
	elseif (isset($subActions[$sa]))
		$subActions[$sa]();
	else
		ancat();
		
	unset($subActions);
}

function ancat()
{
	global $db_prefix, $txt, $context, $settings;

	$context['ncat'] = array();

	$request = db_query("
		SELECT *
		FROM {$db_prefix}news_categories", __FILE__, __LINE__);

	while ($result = mysql_fetch_assoc($request))
		$context['ncat'][] = array(
			'ID_CATEGORY'	=> $result['ID_CATEGORY'],
			'sub'		=> $result['sub'],
			'name'		=> $result['name'],
			'image'		=> $result['image'],
		);

	mysql_free_result ($request);

	if (empty($context['encat']['image']))
		$context['encat']['image'] = 'blank';

	if (empty($context['encat']['name ']))
		$context['encat']['name'] = 'Our News';

	$imgdir = $settings['theme_dir'] . '/images/News';

	// Start dir class engine, get News cat Images
	$d = dir($imgdir);
	while ( false !== ($obj = $d->read()) )
	{
		if ($obj != '.' && $obj != '..')
		{
			if (is_file($imgdir.'/'.$obj))
			{
				$context['NewsImage'][] = $obj;
			}
		}
	}
	$d->close();

	natcasesort ($context['NewsImage']);

	$context['sub_template'] = 'News_ancat';
}

function encat()
{
	global $db_prefix, $context, $settings;

	$id = (int) $_GET['id'];
	$context['encat'] = array();
	$context['id'] = $id;

	$request = db_query("
			SELECT *
			FROM {$db_prefix}news_categories
			WHERE ID_CATEGORY = '$id'", __FILE__, __LINE__);

	$context['encat'] = mysql_fetch_assoc($request);
	mysql_free_result ($request);

	if (empty($context['encat']['image']))
		$context['encat']['image'] = 'blank';

	$imgdir = $settings['theme_dir'] . '/images/News';

	// Start dir class engine, get News cat Images
	$d = dir($imgdir);
	while ( false !== ($obj = $d->read()) )
	{
		if ($obj != '.' && $obj != '..')
		{
			if (is_file($imgdir.'/'.$obj))
			{
				$context['NewsImage'][] = $obj;
			}
		}
	}
	$d->close();

	natcasesort ($context['NewsImage']);

	$context['sub_template'] = 'News_encat';
}

function ancat2()
{
	global $db_prefix;

	db_query("
		INSERT INTO {$db_prefix}news_categories
		(name, image, sub)
		VALUES ('$_POST[name]','$_POST[image]','-1')", __FILE__, __LINE__);
	
	redirectexit('op=NewsManagement');
}

function delncat()
{
	global $db_prefix;

	db_query("
		DELETE FROM {$db_prefix}news_categories
		WHERE ID_CATEGORY = '$_REQUEST[id]'", __FILE__, __LINE__);
	
	redirectexit('op=NewsManagement');
}

function encat2()
{
	global $db_prefix;

	$id = (int) $_POST['id'];

	db_query("
		UPDATE {$db_prefix}news_categories
		SET name='$_POST[name]',image='$_POST[image]'
		WHERE ID_CATEGORY = '$id'", __FILE__, __LINE__);

	redirectexit('op=NewsManagement');
}

?>
Return current item: Enigma