Location: PHPKode > projects > DantoBB > DantoBB_1-0/sources/admin_modules.php
<?php

/*
	Copyright (C) 2009 DantoBB Team
	http://www.dantobb.com
*/

/**
 * ACP module management
 *
 * Gives an interface to manage ACP modules on the board.
 *
 * @author	DantoBB Team
 * @link	http://www.dantobb.com
 * @license	GPL-2
 * @version	$Revision: 1.0 $
 * @copyright	Copyright (C) 2009 DantoBB Team
 * @package	DantoBB
 * @subpackage	ACP
 */

//
// Die when called directly in browser
//
if ( !defined('INCLUDED') )
	exit();

if ( $functions->get_config('enable_acp_modules') ) {
	
	$_GET['do'] = ( !empty($_GET['do']) ) ? $_GET['do'] : 'index';
	$modules_dir = ROOT_PATH.'sources/modules/';
	
	if ( $_GET['do'] == 'index' ) {
		
		$content = '<p>'.sprintf($lang['ModulesInfo'], '<a href="http://www.dantobb.com/">www.dantobb.com</a>').'</p>';
		$content .= '<ul id="adminfunctionsmenu">';
			$content .= '<li><a href="'.$functions->make_url('admin.php', array('act' => 'modules', 'do' => 'upload')).'">'.$lang['ModulesUpload'].'</a></li> ';
		$content .= '</ul>';
		
		if ( count($admin_functions->acp_modules) ) {
			
			$content .= '<table id="adminregulartable"><tr><th>'.$lang['ModulesCategory'].' - '.$lang['ModulesLongName'].'</th><th>'.$lang['ModulesShortName'].' - '.$lang['ModulesFilename'].'</th><th class="action">'.$lang['Delete'].'</th></tr>';
			foreach ( $admin_functions->acp_modules as $module ) {
				
				$delete_link = ( is_writable($modules_dir.$module['filename']) ) ? '<a href="'.$functions->make_url('admin.php', array('act' => 'modules', 'do' => 'delete', 'name' => $module['short_name'])).'">'.$lang['Delete'].'</a>' : $lang['ModulesDeleteNotPermitted'];
				
				$content .= '<tr><td>'.$lang['Category-'.$module['acp_category']].'<br />&middot; <a href="'.$functions->make_url('admin.php', array('act' => 'mod_'.$module['short_name'])).'">'.$module['long_name'].'</a></td><td><code>'.$module['short_name'].'<br />'.$module['filename'].'</code></td><td class="action">'.$delete_link.'</td></tr>';
				
			}
			$content .= '</table>';
			
		} else {
			
			$content .= '<p>'.$lang['ModulesNoneAvailable'].'</p>';
			
		}
		
	} elseif ( $_GET['do'] == 'upload' ) {
		
		$content = '<h2>'.$lang['ModulesUpload'].'</h2>';
		
		if ( file_exists($modules_dir) && is_writable($modules_dir) ) {
			
			if ( $_SERVER['REQUEST_METHOD'] == 'POST' && array_key_exists('acp_module', $_FILES) && is_uploaded_file($_FILES['acp_module']['tmp_name']) ) {
				
				$acp_module = $_FILES['acp_module'];
				
				if ( in_array($acp_module['name'], $admin_functions->acp_modules_files) ) {
					
					$content .= '<p><strong>'.sprintf($lang['ModulesUploadDuplicateModule'], '<code>'.$acp_module['name'].'</code>').'</strong></p>';
					
				} elseif ( $admin_functions->check_module($acp_module['name'], $acp_module['tmp_name']) ) {
					
					if ( copy($acp_module['tmp_name'], join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'modules', $acp_module['name']))) )
						$functions->redirect('admin.php', array('act' => 'modules'));
					else
						$content .= '<p><strong>'.sprintf($lang['ModulesUploadFailed'], '<code>'.$acp_module['name'].'</code>').'</strong></p>';
					
				} else {
					
					$content .= '<p><strong>'.sprintf($lang['ModulesUploadNoValidModule'], '<code>'.$acp_module['name'].'</code>').'</strong></p>';
					
				}
				
			} else {
				
				$content .= '<p>'.$lang['ModulesUploadInfo'].'</p>';
				
			}
			
			$content .= '<form action="'.$functions->make_url('admin.php', array('act' => 'modules', 'do' => 'upload')).'" method="post" enctype="multipart/form-data"><p><input type="file" name="acp_module" size="25" /> <input type="submit" value="'.$lang['Upload'].'" /></p></form>';
			
		} else {
		
			$content .= '<p>'.sprintf($lang['ModulesUploadDisabled'], '<code>sources/modules/</code>').'</p>';
		
		}
		
	} elseif ( $_GET['do'] == 'delete' && !empty($_GET['name']) && array_key_exists($_GET['name'], $admin_functions->acp_modules) && is_writable($modules_dir.$admin_functions->acp_modules[$_GET['name']]['filename']) ) {
		
		$acp_module = $admin_functions->acp_modules[$_GET['name']];
		
		if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
			
			if ( !empty($_POST['delete']) )
				unlink($modules_dir.$acp_module['filename']);
			
			$functions->redirect('admin.php', array('act' => 'modules'));
			
		} else {
			
			$content = '<h2>'.$lang['ModulesConfirmModuleDelete'].'</h2>';
			$content .= '<p>'.sprintf($lang['ModulesConfirmModuleDeleteInfo'], '<em>'.$acp_module['long_name'].'</em>', '<code>'.$acp_module['short_name'].'</code>').'</p>';
			$content .= '<form action="'.$functions->make_url('admin.php', array('act' => 'modules', 'do' => 'delete', 'name' => $_GET['name'])).'" method="post">';
			$content .= '<p class="submit"><input type="submit" name="delete" value="'.$lang['Delete'].'" /> <input type="submit" value="'.$lang['Cancel'].'" /></p>';
			$content .= '</form>';
			
		}
		
	}
	
} else {
	
	$content = '<p>'.$lang['ModulesDisabled'].'</p>';
	
}

$admin_functions->create_body('modules', $content);

?>
Return current item: DantoBB