<?php
	/*
	MGB 0.7.x - OpenSource PHP and MySql Guestbook
	Copyright (C) 2004 - 2013 Juergen Grueneisl - http://www.m-gb.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, or
	(at your option) any later version.

	This program 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 this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	*/

	// =============== //
	// version.inc.php //
	// =============== //
	//
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	// make sure nobody has direct acces to this script
	if(!defined('ADMINISTRATION')) {
		include ("error.html");
		die();
	} else {
		if(check_rights($_GET['action'], $_SESSION['ID'])) {
			// load config, settings, template and language files
			require ("../includes/config.inc.php");
			require ("../includes/functions.inc.php");
			require ("../includes/load_settings.inc.php");
			require("../language/".$settings['language_path']."/lang_admin.php");
			// load template
			$content_version = mgb_load_template("admin", "default", "version", $settings['debug_mode']);

			if(function_exists('fopen') AND ini_get(allow_url_fopen) == 1) {
				// latest stable version
				$file = fopen("http://www.m-gb.org/latest.txt", "r");
				$latest_version = "<a href=\"http://www.m-gb.org/files/latest/mgb-latest.zip\" title=\"ZIP Version\">".fread($file, 50)."</a>";
				fclose($file);

				// latest unstable version
				$file = fopen("http://www.m-gb.org/latest_dev.txt", "r");
				$latest_devversion = "<a href=\"http://www.m-gb.org/files/latest/mgb-latest_dev.zip\" title=\"ZIP Version\">".fread($file, 50)."</a>";
				fclose($file);

				// info about latest stable version
				$file = fopen("http://www.m-gb.org/latest_info.txt", "r");
				$latest_version_info = fread($file, 1000);
				fclose($file);

				switch(version_compare($settings['version'], $latest_version)) {
					case -1: $version_info = "<span class='old_version'>".$lang['old_version']."</span>";
						break;
					case 0: $version_info = "<span class='same_version'>".$lang['same_version']."</span>";
						break;
					case 1: $version_info = "<span class='newer_version'>".$lang['newer_version']."</span>";
						break;
				}
			} elseif(!function_exists('fopen') OR ini_get(allow_url_fopen) == 0) {
				if(extension_loaded('curl')) {
					// latest stable version
					$latest_version = "<a href=\"http://www.m-gb.org/files/latest/mgb-latest.zip\" title=\"ZIP Version\">".get_mgb_version_info('http://www.m-gb.org/latest.txt')."</a>";
					// latest unstable version
					$latest_devversion = "<a href=\"http://www.m-gb.org/files/latest/mgb-latest_dev.zip\" title=\"ZIP Version\">".get_mgb_version_info('http://www.m-gb.org/latest_dev.txt')."</a>";
					// info about latest version
					$latest_version_info = get_mgb_version_info('http://www.m-gb.org/latest_info.txt');

					switch(version_compare($settings['version'], $latest_version)) {
						case -1: $version_info = "<span class='old_version'>".$lang['old_version']."</span>";
							break;
						case 0: $version_info = "<span class='same_version'>".$lang['same_version']."</span>";
							break;
						case 1: $version_info = "<span class='newer_version'>".$lang['newer_version']."</span>";
							break;
					}
				}
			} else {
				$latest_version = "?";
				$latest_devversion = "?";
				$latest_version_info = "?";
				$version_info = "<span class='old_version'>".$lang['errormessage15']."</span>";
			}
		}
	}

	$page_include = $content_version;

	$page_include = template("LANG_CURRENT_VERSION", $lang['current_version'], $page_include);
	$page_include = template("LANG_STABLE_VERSION", $lang['stable_version'], $page_include);
	$page_include = template("LANG_UNSTABLE_VERSION", $lang['unstable_version'], $page_include);

	$page_include = template("LATEST_VERSION", $latest_version, $page_include);
	$page_include = template("LATEST_DEVVERSION", $latest_devversion, $page_include);
	$page_include = template("LATEST_VERSION_INFO", $latest_version_info, $page_include);
	$page_include = template("VERSION_INFO", $version_info, $page_include);

	$content_scrolling_function = "<br>";
?>
