<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | MPN 189 Admin Entry Conversion For 188_8                             |
// |                                                                      |
// | -> Entry Point To MPN Administration                                 |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of MPN Admin Entry For MPN 188_8.                  |
// |                                                                      |
// | MPN Admin Entry For MPN 188_8 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, or (at your option) any             |
// | later version.                                                       |
// |                                                                      |
// | MPN Admin Entry For MPN 188_8 is distributed in the hope that it     |
// | will be useful, but WITHOUT ANY WARRANTY; without even the implied   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with MPN Admin Entry For MPN 188_8; if not, write to the       |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the MPN Admin Entry For MPN 188_8.              |
// | The Initial Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Administration
 * @subpackage interface
 * @version $Id: admin.php,v 1.13.2.17 2004/08/22 14:33:48 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Copyright (C) 2003 Eric Haddix
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 * @todo finish CSS & XHTML conversion
 * @todo reformat old style formatted code to new coding style
 * @todo finish and check function comments
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****

define( '_MPN_PAGE_ID' , 27 );
define( '_DP_ADMIN_', __ROOT__ . 'admin' . DIRECTORY_SEPARATOR );
define( '_DP_ADMIN_SUBMENUS_', _DP_ADMIN_ . 'menu' . DIRECTORY_SEPARATOR . 'subs' . DIRECTORY_SEPARATOR );

$forumpage = 2;

if ( isset( $_REQUEST['op'] ) && $_REQUEST['op'] == 'logout' )
{
    $cktype = 'admin';
    @( include_once __ROOT__ . 'logout.php' )
      OR goBack( translate( 'Include Error' ) );
    exit;
}

if ( isset( $_REQUEST['op'] ) && $_REQUEST['op'] == 'login' )
{
    loginAdmin();
    exit;
}

if ( ! _MPN_ADMIN ) // LOGIN ADMIN
{
    if ( sizeof( $_GET ) != 0 ) { $_SERVER['F_LIB'] -> redirectRequest( 'admin.php' ); }

    @( include_once __ROOT__ . 'header.php' )
      OR goBack( translate( 'Include Error' ) );

    echo adminLoginForm();

    @( include_once __ROOT__ . 'footer.php' )
      OR goBack( translate( 'Include Error' ) );
    exit;
}

// ADMIN VERIFIED

$aid = $GLOBALS['ainf']['uname'];

// PROCESS SYSINFO REQUEST

if ( _ADMIN_TRUSTED && ( isset( $_REQUEST['op'] ) && $_REQUEST['op'] == 'sysinfo' ) )
{
    @phpinfo();
    exit;
}

// REDIRECT PAGE REQUESTS

if ( isset( $_REQUEST['alk'] ) )
{
    $_SERVER['F_LIB'] -> redirectRequest( 'admin.php?' . base64_decode( urldecode( $_REQUEST['alk'] ) ) );
}

// START OUTPUT

@( include_once __ROOT__ . 'header.php' )
  OR goBack( translate( 'Include Error' ) );

// LOAD THE MENU SYSTEM IF NOT LOGGING OUT

( include_once _DP_ADMIN_ . 'menu' . DIRECTORY_SEPARATOR . 'adminMenu.php' )
  OR goBack( translate( 'Include Error' ) );

// INCLUDE REQUIRED FILES

if ( isset( $_REQUEST['fct'] ) && is_file( _DP_ADMIN_ . $_REQUEST['fct'] . '/main.php' ) )
{
    if ( empty( $_REQUEST['op'] ) ) { $_REQUEST['op'] = ''; }

    ( include_once _DP_ADMIN_ . $_REQUEST['fct'] . '/main.php' )
      OR goBack( translate( 'Include Error' ) );
}
else if ( isset( $_REQUEST['op'] ) && ! isset( $_REQUEST['fct'] ) )
{
    @( include_once _DP_ADMIN_ . 'original/nuke_switch.php' )
      OR goBack( translate( 'Include Error' ) );
}
else if ( empty( $_REQUEST['op'] ) && empty( $_REQUEST['fct'] ) )
{
    @( include_once _DP_ADMIN_ . 'original/main.php' )
      OR goBack( translate( 'Include Error' ) );
}

@( include_once __ROOT__ . 'footer.php' )
  OR goBack( translate( 'Include Error' ) );


// ########## FUNCTIONS ############


/**
 * Process Admin Login Request
 *
 *
 */

function loginAdmin()
{
    global $mpnTables;

    $admin = $aid = $pwd = NULL;

    $aid = $_POST['aid'];
    $pwd = md5( $_POST['pwd'] );

    $sql = 'SELECT ( aid = "' . $aid . '" ) FROM ' . $mpnTables['authors'] . ' WHERE pwd = "' . $pwd . '"';

    if ( ! @( $result = mysql_query( $sql ) ) || ! @mysql_data_seek( $result, 0 ) )
    {
        goBack( translate( 'Unable To Verify Your Identity' ) );
        exit;
    }
    else
    {
        $admin = base64_encode( $aid . ':' . $pwd );

        bakeCookie( 'admin', $admin, '2592000' );

        $_SERVER['F_LIB'] -> redirectRequest( NULL, TRUE );
        exit;
   }

    exit( 'You Should Not Be Here' );

} // End Function

/**
 * Check Admin Script Access And Load Appropriate Sub-Menu
 *
 *
 */

function checkAccess( $section, $chkadmin = array(), $chksuper = FALSE, $silent = TRUE, $exit = TRUE )
{
    if ( ! _MPN_ADMIN ) { adminLoginForm(); }
    if ( $chksuper && ! _ADMIN_TRUSTED ) { goBack( translate( 'Insufficient Rights' ) ); }
    $access = (bool)FALSE;

    if ( ! empty( $section ) )
    {
        @( include_once _DP_ADMIN_SUBMENUS_ . $section . '.submenu.php' )
          OR goBack( translate( 'Include Error' ) );
    }

    if ( ! _ADMIN_TRUSTED )
    {
        if ( empty( $chkadmin ) || ! is_array( $chkadmin ) )
        {
            goBack( translate( 'Insufficient Rights' ) . '**' . __FILE__ . '***' .  __LINE__   );
        }

        foreach( $chkadmin AS $v )
        {
            if ( $GLOBALS['ainf'][ $v ] )
            {
                $access = (bool)TRUE;
                break;
            }
        }

        if ( ! $access )
        {
            if ( $silent )
            {
                if ( $exit )
                {
                    @( include_once __ROOT__ . 'footer.php' )
                      OR goBack( translate( 'Include Error' ) );
                    exit;
                }
                else
                {
                    return (bool)FALSE;
                }
            }
            else
            {
                goBack( translate( 'Insufficient Rights' ) . '**' . __FILE__ . '***' .  __LINE__  );
                exit;
            }
        }
    }

    return (bool)TRUE;

} // End Function

// RELIC DEAD ENDS ( JUST IN CASE )

function admin_menu( $hlpfile = '' ) { return; }

function GraphicAdmin( $hlpfile = '' ) { return; }

function have_right( $module = NULL )
{
    if ( empty( $module ) && ! _ADMIN_TRUSTED ) { return (bool)FALSE; }

    return $GLOBALS['ainf'][ substr( $module, 6 ) ];
}

?>