Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/modules/Mod_ArticlesManagement.php
<?php
/*
*****************************************************************

 Mod_ArticlesManagement.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.');
else
	AdminArticlesHub();

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

	isAllowedTo('manage_articles');

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

	loadMLanguage('ArticleManagement');
	loadMTemplate('ArticlesManagement');
	
	$context['page_title'] = $txt['art00'];

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


	$subActions = array(
		'asection',
		'asection2',
		'delsection',
		'esection',
		'esection2',
		);

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

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


	$context['page_title'] = $txt['art00'];

	//get, the current article sections, and stick 'em into an array for the template.
	$request = db_query("
		SELECT *
		FROM {$db_prefix}art_sections
		ORDER BY position", __FILE__, __LINE__);

	while ($result = mysql_fetch_assoc($request))
	{
		$context['artsec'][] = array(
				'title'				=> 	$result['title'],
				'image'			=> 	!empty($result['banner']) ? $result['banner'] : 'blank.gif',
				'position'			=>		$result['position'],
				'groups'			=>		$result['memberGroups'],
				'ID_SECTION'		=>		$result['ID_SECTION'],
			);
	}
	
	mysql_free_result($request);

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

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

	natcasesort($context['ArticlesImage']);
	
	$context['sub_template'] = 'ArtMgmt_addsec';

}

function asection2()
{
	global $context, $db_prefix;
	
	//change the multi-select group permissions from an array to a string
    	$secperm = (is_array($_REQUEST['section_permit'])) ? implode(',', $_REQUEST['section_permit']) : '';

	//insert the new section into the table
	db_query("
		INSERT INTO {$db_prefix}art_sections (title,banner,position,memberGroups)
			VALUES ('$_REQUEST[title]','$_REQUEST[image]','$_REQUEST[position]','$secperm')", __FILE__, __LINE__);
	
	redirectexit('module=ArticlesManagement;sa=asection', true);
}

function delsection()
{
	global $context, $db_prefix;

	$secid = $_REQUEST['secid'];

	//delete the section from the table
	db_query("
		DELETE FROM {$db_prefix}art_sections
		WHERE (ID_SECTION='$secid')", __FILE__, __LINE__);

	/* if we delete the section then we need to delete the articles or assign a new section for them!
	   lets delete them for now
	*/
	db_query("
		DELETE FROM {$db_prefix}articles
		WHERE (ID_SECTION='$id')", __FILE__, __LINE__);
	
	redirectexit('module=ArticlesManagement', true);
}

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

	$secid = $_REQUEST['secid'];

	//get the section to be edited
	$request = db_query("
		SELECT *
		FROM {$db_prefix}art_sections
		WHERE ID_SECTION = '$secid'
		LIMIT 1 ", __FILE__, __LINE__);

	$result = mysql_fetch_assoc($request);

	$earts[] = array(
		'title'				=> 	$result['title'],
		'image'			=> 	$result['banner'],
		'position'			=>		$result['position'],
		'groups'			=>		$result['memberGroups'],
		'ID_SECTION'		=>		$result['ID_SECTION'],
		);
	
	mysql_free_result($request);

	$context['editart'] = $earts;
	
	unset($earts);
		
		
	$imgdir = $settings['theme_dir'] . '/images/Articles';

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

	natcasesort($context['ArticlesImage']);
	
	$context['sub_template'] = 'ArtMgmt_editsec';			

}

function esection2()
{
	global $context, $db_prefix;

	$secid = $_POST['secid'];

	//change the multi-select group permissions from an array to a string
    	$secperm = (is_array($_REQUEST['section_permit'])) ? implode(',', $_REQUEST['section_permit']) : '';

	//update the database
	$result = db_query("
		UPDATE {$db_prefix}art_sections
		SET title='$_POST[title]',banner='$_POST[image]',
			position='$_POST[position]',memberGroups='$secperm'
		WHERE (ID_SECTION='$secid')", __FILE__, __LINE__);

	redirectexit('module=ArticlesManagement', true);

}

?>
Return current item: Enigma