<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (stristr(htmlentities($_SERVER['SCRIPT_NAME']), 'mainfile.php')) {
	Header('Location: index.php');
	die();
}

// initialisation
// End the transaction
if(!defined('END_TRANSACTION')) {
  define('END_TRANSACTION', 2);
}

define('MAXIMUS', true);
define('NUKE_FILE', true);
$max_time = time();

if (file_exists('includes/custom_files/custom_mainfile.php')) {
	include_once('includes/custom_files/custom_mainfile.php');
}

if (!isset($main_module)) { $main_module =  'News'; }
if (!isset($pagetitle))   { $pagetitle = ''; }
// Get php version
$phpver = phpversion();

// convert superglobals if php is lower then 4.1.0
if ($phpver < '4.1.0') {
  $_GET    = $HTTP_GET_VARS;
  $_POST   = $HTTP_POST_VARS;
  $_SERVER = $HTTP_SERVER_VARS;
  $_FILES  = $HTTP_POST_FILES;
  $_ENV    = $HTTP_ENV_VARS;
  if($_SERVER['REQUEST_METHOD'] == "POST") {
    $_REQUEST = $_POST;
  } elseif($_SERVER['REQUEST_METHOD'] == "GET") {
    $_REQUEST = $_GET;
  }
  if(isset($HTTP_COOKIE_VARS)) {
    $_COOKIE = $HTTP_COOKIE_VARS;
  }
  if(isset($HTTP_SESSION_VARS)) {
    $_SESSION = $HTTP_SESSION_VARS;
  }
}

// override old superglobals if php is higher then 4.1.0
if($phpver >= '4.1.0') {
  $HTTP_GET_VARS    = $_GET;
  $HTTP_POST_VARS   = $_POST;
  $HTTP_SERVER_VARS = $_SERVER;
  $HTTP_POST_FILES  = $_FILES;
  $HTTP_ENV_VARS    = $_ENV;
  $PHP_SELF         = $_SERVER['PHP_SELF'];
  if(isset($_SESSION)) {
    $HTTP_SESSION_VARS = $_SESSION;
  }
  if(isset($_COOKIE)) {
    $HTTP_COOKIE_VARS= $_COOKIE;
  }
}

if (!function_exists('floatval')) {
    function floatval($inputval) {
        return (float)$inputval;
    }
}

if ($phpver >= '4.0.4pl1' && isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'],'compatible')) {
  if (extension_loaded('zlib')) {
    @ob_end_clean();
    @ob_start('ob_gzhandler');
  }
} elseif ($phpver > '4.0' && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
    if (extension_loaded('zlib')) {
      $do_gzip_compress = true;
      @ob_start(array('ob_gzhandler',5));
      @ob_implicit_flush(0);
      if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
      @header('Content-Encoding: gzip');
      }
    }
  }
}

if (!ini_get("register_globals")) {
	@import_request_variables('GPC', '');
}

// Ce code controle que les variables $admin, $admin2, $lang et $user sont bien des COOKIES
if( (isset($admin) && $admin != $_COOKIE['admin']) OR (isset($admin2) && $admin2 != $_COOKIE['admin2']) OR (isset($user) && $user != $_COOKIE['user']) OR (isset($lang) && $lang != $_COOKIE['lang']) ) {
	$admin = $admin2 = $user = $lang = NULL;
  	die("Illegal Operation");
}

if(isset($admin)) {
	$admin = base64_decode($admin);
	$admin = addslashes($admin);
	$admin = base64_encode($admin);
} else {
	$admin = '';
}

if(isset($user)) {
	$user = base64_decode($user);
	$user = addslashes($user);
	$user = base64_encode($user);
} else {
	$user ='';
}

$urle    = $_SERVER['REQUEST_URI'];
$max_url = $_SERVER['QUERY_STRING'];

// define the INCLUDE PATH
if(defined('FORUM_ADMIN')) {
  define('INCLUDE_PATH', '../../../');
} elseif(defined('INSIDE_MOD')) {
  define('INCLUDE_PATH', '../../');
} else {
  define('INCLUDE_PATH', './');
}

if (is_file(INCLUDE_PATH.'config.php')) {include_once(INCLUDE_PATH.'config.php');}

// Error reporting, to be set in config.php
if($display_errors) {
  @ini_set('display_errors', 1);
  @ini_set('html_errors', 1);
  @error_reporting(E_ALL^E_NOTICE);
} else {
  @ini_set('display_errors', 0);
  @ini_set('html_errors', 1);
  @error_reporting(0);
}

if (is_file(INCLUDE_PATH.'kernel/constants.php')) {include_once(INCLUDE_PATH.'kernel/constants.php');}
if (!defined('ADMIN_MAX') AND (is_file(INCLUDE_PATH."".$cache."/Configuration/".$cache_prefix."_configadvance.php"))){
include_once(INCLUDE_PATH."".$cache."/Configuration/".$cache_prefix."_configadvance.php");
}
if ( empty($dbname) ) {
Header('Location: installation/index.php');die();}
if (is_file(INCLUDE_PATH."".$cache."/Configuration/".$cache_prefix."_cMax_config.php")) {include_once(INCLUDE_PATH."".$cache."/Configuration/".$cache_prefix."_cMax_config.php");}
if (is_file(INCLUDE_PATH.'kernel/db/db.php')) {include_once(INCLUDE_PATH.'kernel/db/db.php');}
if (is_file(INCLUDE_PATH.'kernel/connect.php')) {include_once(INCLUDE_PATH.'kernel/connect.php');}
if (is_file(INCLUDE_PATH.'kernel/utility.php')) {include_once(INCLUDE_PATH.'kernel/utility.php');}
if (is_file(INCLUDE_PATH.'kernel/authors.php')) {include_once(INCLUDE_PATH.'kernel/authors.php');}
if (is_file(INCLUDE_PATH.'kernel/users.php')) {include_once(INCLUDE_PATH.'kernel/users.php');}
if (is_file(INCLUDE_PATH.'kernel/nukesentinel.php')) {include_once(INCLUDE_PATH.'kernel/nukesentinel.php');}
if (is_file(INCLUDE_PATH.'kernel/security.php')) {include_once(INCLUDE_PATH.'kernel/security.php');}
if(!defined('FORUM_ADMIN')) {
if (is_file(INCLUDE_PATH.'class.php')) {include_once(INCLUDE_PATH.'class.php');}
}
if (is_file(INCLUDE_PATH.'kernel/templates/themes.php')) {include_once(INCLUDE_PATH.'kernel/templates/themes.php');}

$ThemeSel = get_theme();

if (file_exists("themes/$ThemeSel/credits.php")) {
if (is_file(INCLUDE_PATH.'kernel/blocks_maximus.php')) {include_once(INCLUDE_PATH.'kernel/blocks_maximus.php');}
define('MAXIMUS_THEME', true);
} else {
define('INDEX_FILE', true);
if (is_file(INCLUDE_PATH.'kernel/blocks_phpnuke.php')) {include_once(INCLUDE_PATH.'kernel/blocks_phpnuke.php');}
}

if (is_file(INCLUDE_PATH.'kernel/langues.php')) {include_once(INCLUDE_PATH.'kernel/langues.php');}

if ( (!empty($rewrite)) && (!defined('ADMIN_MAX')) ) {
if (is_file(INCLUDE_PATH.'kernel/GoogleTap_SG.php')) {include_once(INCLUDE_PATH.'kernel/GoogleTap_SG.php');}
}

$lang_dir = "";
if (!isset($ThemeSel)) { $ThemeSel = 'MaX_Colors'; }

if(!empty($cldbi))
{ //old layer Nuke - ancien layer Nuke
if (is_file(INCLUDE_PATH.'includes/sql_layer.php')) {include_once(INCLUDE_PATH.'includes/sql_layer.php');}
	$dbi = sql_connect($dbhost, $dbuname, $dbpass, $dbname);
}

if (is_file(INCLUDE_PATH.'kernel/version.php')) {include_once(INCLUDE_PATH.'kernel/version.php');}

if(defined('FORUM_ADMIN')) {
	function redirect_url($UrlX) {
		Header("Location: $UrlX");
		die();
	}
}

if ($_COOKIE['blo']['900'] == "1"){
	$cacheblocsl = "<a href='index.php?g&amp;bloc=900&amp;actif='><img src='images/blocks/droite.png' border='0' alt=\""._OPENPANEL."\" title=\""._OPENPANEL."\" /></a>";
} else {
	$cacheblocsl ="<a href='index.php?g&amp;bloc=900&amp;actif=1'><img src='images/blocks/gauche.png' border='0' alt=\""._CLOSEPANEL."\" title=\""._CLOSEPANEL."\" /></a>";
}
if ($_COOKIE['blo']['901'] == "1"){
	$cacheblocsr = "<a href='index.php?g&amp;bloc=901&amp;actif='><img src='images/blocks/gauche.png' border='0' alt=\""._OPENPANEL."\" title=\""._OPENPANEL."\" /></a>";
} else {
	$cacheblocsr = "<a href='index.php?g&amp;bloc=901&amp;actif=1'><img src='images/blocks/droite.png' border='0' alt=\""._CLOSEPANEL."\" title=\""._CLOSEPANEL."\" /></a>";
}

if(!defined('FORUM_ADMIN')) {
	if (isset($g)){
		if (strstr($bloc, 'http') ) { $bloc = ''; }
		if ( empty( $bloc ) ) { redirect_url("".get_referer().""); }
		$bloc = str_replace('%20', '_', $bloc);
		$bloc = str_replace(' ', '_', $bloc);
		@setcookie("blo[$bloc]", "$actif" , time()+2592000);
		redirect_url("".get_referer()."");
	}
}

if (isset($gfx)){
switch($gfx) {

	case "gfx":
	$datekey  = date("F j");
	$rcode    = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $random_num . $datekey));
	$code     = substr($rcode, 2, 6);
	$ThemeSel = get_theme();
	if (file_exists("themes/".$ThemeSel."/images/code_bg.jpg")) {
		$image = ImageCreateFromJPEG("themes/".$ThemeSel."/images/code_bg.jpg");
	} else {
		$image = ImageCreateFromJPEG("images/code_bg.jpg");
	}
	$text_color = ImageColorAllocate($image, 0, 0, 0);
	Header("Content-type: image/jpeg");
	ImageString ($image, 5, 12, 2, $code, $text_color);
	ImageJPEG($image, '', 75);
	ImageDestroy($image);
	die();
	break;

	case "gfx_little":
	$datekey  = date("F j");
	$rcode    = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $random_num . $datekey));
	$code     = substr($rcode, 2, 3);
	$ThemeSel = get_theme();
	if (file_exists("themes/".$ThemeSel."/images/code_bg_little.jpg")) {
		$image = ImageCreateFromJPEG("themes/".$ThemeSel."/images/code_bg_little.jpg");
	} else {
		$image = ImageCreateFromJPEG("images/code_bg_little.jpg");
	}
	$text_color = ImageColorAllocate($image, 80, 80, 80);
	Header("Content-type: image/jpeg");
	ImageString ($image, 5, 12, 2, $code, $text_color);
	ImageJPEG($image, '', 75);
	ImageDestroy($image);
	die();
	break;
   }
}