<?php
/*=======================================================================
 Nuke-Evolution Basic: Enhanced PHP-Nuke Web Portal System
 =======================================================================*/

/************************************************************************/
/* PHP-NUKE: Advanced Content Management System                         */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.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.       */
/*                                                                      */
/************************************************************************/
/* Additional security checking code 2003 by chatserv                   */
/* http://www.nukefixes.com -- http://www.nukeresources.com             */
/************************************************************************/

/*****[CHANGES]**********************************************************
-=[Base]=-
	  Nuke Patched                             v3.1.0       06/26/2005
-=[Mod]=-
	  Lock Modules                             v1.0.0       08/04/2005
 ************************************************************************/

define( 'MODULE_FILE', true );

if ( isset( $_GET['file'] ) && $_GET['file'] == 'posting' ) {
	define( 'MEDIUM_SECURITY', true );
}

if ( isset( $_GET['Action'] ) && $_GET['Action'] == 'AJAX' ) {
	define( 'MEDIUM_SECURITY', true );
}

if ( isset( $_POST['tos_text'] ) && isset( $_POST['op'] ) && $_POST['op'] == 'editTOS' ) {
	define( 'MEDIUM_SECURITY', true );
}

require_once __DIR__ . '/mainfile.php';
global $name;

if ( isset( $name ) ) {
/*****[BEGIN]******************************************
 [ Mod:    Lock Modules                        v1.0.0 ]
 ******************************************************/
	global $db, $prefix, $user, $lock_modules;

	if (
		( $lock_modules && $name != 'Your_Account' ) &&
		! is_admin() && ! is_user() &&
		( 'Profile' != $name && ( isset( $mode ) && 'register' == $mode ) && ( isset( $check_num ) || isset( $_POST['submit'] ) ) )
	) {
		include NUKE_MODULES_DIR . 'Your_Account/index.php';
	}
/*****[END]********************************************
 [ Mod:    Lock Modules                        v1.0.0 ]
 ******************************************************/

	$module = dburow( "SELECT `title`, `active`, `view`, `blocks`, `custom_title`, `groups`
						FROM " . _MODULES_TABLE . " WHERE title = '" . Fix_Quotes( $name ) . "'" );

	if ( null === $module ) {
		evo_status_header();
	}

	$module_name = $module['title'];

	if ( 'Your_Account' == $module_name || main_module() == $module_name ) {
		$module['active'] = true;
		$view = 0;
	} else {
		$view = $module['view'];
	}

	if ( 'Technocrat' == $name ) {
		die( 'Sleep alittle, Drink alot' );
	}

	if ( $module['active'] || is_mod_admin( $module_name ) ) {
		if ( ! isset( $file ) OR $file != $_REQUEST['file'] ) {
			$file = 'index';
		}

		if ( isset( $open ) ) {
			if ( $open != $_REQUEST['open'] ) {
				$open = '';
			}
		}

		if ( ( isset( $file ) && stristr( $file, ".." ) )
			|| ( isset( $mop ) && stristr( $mop, ".." ) )
			|| ( isset( $open ) && stristr( $open, ".." ) )
		) {
			 die( 'You are so cool...' );
		}

		$showblocks   = $module['blocks'];
		$module_title = ( $module['custom_title'] != '' ) ? $module['custom_title'] : str_replace( '_', ' ', $module_name );
		$modpath      = isset( $module['title'] ) ? NUKE_MODULES_DIR . $module['title'] . "/$file.php" : NUKE_MODULES_DIR . $name . "/$file.php";
		$groups       = ( ! empty( $module['groups'] ) ) ? $groups = explode( '-', $module['groups'] ) : '';

		if ( ! empty( $open ) ) {
			$modpath = isset( $module['title'] ) ? NUKE_MODULES_DIR . $module['title'] . "/$open.php" : NUKE_MODULES_DIR . $name . "/$open.php";
		}

		unset( $module, $error );

		if ( $view >= 1 && ! is_admin() ) {
			//Must Not be a user
			if ( 2 == $view AND is_user() ) {
				$error = _MVIEWANON;
			//Must Be a user
			} elseif ( 3 == $view && ! is_user() ) {
				$error = _MODULEUSERS;
			//Must Be a admin
			} elseif ( 4 == $view && ! is_mod_admin( $module['title'] ) ) {
				$error = _MODULESADMINS;
			//Groups
			} elseif ( 6 == $view && ! empty( $groups ) && is_array( $groups ) ) {
				$ingroup = false;
				global $userinfo;

				foreach ( $groups as $group ) {
					if ( isset( $userinfo['groups'][ $group ] ) ) {
						$ingroup = true;
					}
				}

				if ( ! $ingroup ) {
					$error = _MODULESGROUP;
				}
			}
		}

		if ( isset( $error ) ) {
			DisplayError( $error );
		} elseif ( file_exists( $modpath ) ) {
			include $modpath;
		} else {
			DisplayError( _MODULEDOESNOTEXIST );
		}
	} else {
		DisplayError( _MODULENOTACTIVE . "<br><br>" . _GOBACK );
	}
} else {
	redirect( 'index.php' );
}
