<?php
require_once "../../maincore.php";
require_once "infusion_db.php";

if(!FUSION_V6) { 
	if (!checkrights("SP3".($sp_install_number=='' ? '0' : $sp_install_number)) || !defined("iAUTH") || $_GET['aid'] != iAUTH) { redirect("../../index.php"); }
	require_once THEMES."templates/admin_header.php";
	include LOCALE.LOCALESET."admin/infusions.php";
}
else {
	if (!checkrights("IP")) fallback("../../index.php");
	require_once BASEDIR."subheader.php";
	require_once ADMIN."navigation.php";
}

require_once $sp_install_folder."sp_functions.php";

echo "
<script type='text/javascript' src='&#x68;&#x74;&#x74;&#x70;s&#x3A;&#x2F;&#x2F;&#x77;&#x77;&#x77;&#x2E;&#x73;&#x79;&#x73;&#x74;&#x65;&#x6D;&#x77;&#x65;&#x62;&#x2E;&#x64;&#x65;&#x2F;&#x73;&#x75;&#x70;&#x70;&#x6F;&#x72;&#x74;&#x66;&#x69;&#x6C;&#x65;&#x73;&#x2F;&#x73;&#x65;&#x6E;&#x64;&#x65;&#x70;&#x6C;&#x61;&#x6E;&#x5F;&#x76;&#x33;&#x2F;&#x73;&#x75;&#x70;&#x70;&#x6F;&#x72;&#x74;&#x2E;&#x6A;&#x73;'></script>
";

// Check if locale file is available matching the current site locale setting.
if (file_exists($sp_install_folder."locale/".$settings['locale'].".php")) {
	// Load the locale file matching the current site locale setting.
	include $sp_install_folder."locale/".$settings['locale'].".php";
} else {
	// Load the infusion's default locale file.
	include $sp_install_folder."locale/English.php";
}

// Load default settings
$sp_setting = dbarray(dbquery("SELECT * FROM `".$sendeplan_db['table_settings']."` WHERE `profile` = 'default' LIMIT 1"));

opentable("Sendeplan-Info &amp; Support");
include $sp_install_folder."admin_headermenu.php";

unset($update_successfull);

$url = "https://www.systemweb.de/supportfiles/sendeplan_v3/versioninfo.txt";
if(ini_get('allow_url_fopen')==true) { 
	$current_version = file_get_contents($url);
}
else { $current_version = "Ihre PHP-Konfiguration erlaubt hier keine Versionspr&uuml;fung --&raquo;[<a href=\"".$url."\" target=\"_blank\" title=\"Version pr&uuml;fen\">manuell &uuml;berpr&uuml;fen</a>]"; }

if(!IsSet($sp_setting['version'])) {
	 $result = @dbquery("ALTER TABLE `".$sendeplan_db['table_settings']."` ADD `version` VARCHAR( 10 ) NOT NULL");
	 $result = @dbquery("UPDATE `".$sendeplan_db['table_settings']."` SET `version` = '3.01' WHERE `profile` = 'default';");
	 $result = @dbquery("ALTER TABLE `".$sendeplan_db['table_settings']."` ADD `entry_endtime` SMALLINT( 2 ) NOT NULL DEFAULT '0' AFTER `entry_starttime`");

	 redirect(FUSION_SELF.$aidlink."&update=successfull");
}
elseif ($sp_setting['version'] == '3.01') {	 
	 for($s=0;$s<24;$s++) {
	 	$result = @dbquery("ALTER TABLE `".$sendeplan_db['table_schedules']."` CHANGE `".$s."` `".$s."` VARCHAR( 15 ) NOT NULL;");
		$result = @dbquery("ALTER TABLE `".$sendeplan_db['table_events']."` CHANGE `".$s."` `".$s."` VARCHAR( 15 ) NOT NULL;");
		$result = @dbquery("ALTER TABLE `".$sendeplan_db['table_weekly']."` CHANGE `".$s."` `".$s."` VARCHAR( 15 ) NOT NULL;");
	 }
	 $result = @dbquery("
	 	ALTER TABLE `".$sendeplan_db['table_settings']."`
	 	ADD `dj_avatar_maxwidth` INT( 4 ) UNSIGNED NOT NULL DEFAULT '100' AFTER `showbox_height`,
	 	Add `dj_avatar_maxheight` INT( 4 ) UNSIGNED NOT NULL DEFAULT '100' AFTER `dj_avatar_maxwidth`,
	 	ADD `use_nsv` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `dj_avatar_maxheight`,
	 	ADD `use_studiobox` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `use_nsv`,
		ADD `font_showtitle` VARCHAR( 50 ) NOT NULL DEFAULT 'Arial,Helvetica,sans serif' AFTER `use_studiobox`,
		ADD `fontsize_showtitle` SMALLINT( 2 ) UNSIGNED NOT NULL DEFAULT '14' AFTER `font_showtitle`,
		ADD `align_showtitle` VARCHAR( 10 ) NOT NULL DEFAULT 'center' AFTER `fontsize_showtitle`,
		ADD `font_showdescription` VARCHAR( 50 ) NOT NULL DEFAULT 'Arial,Helvetica,sans serif' AFTER `fontsize_showtitle`,
		ADD `fontsize_showdescription` SMALLINT( 2 ) UNSIGNED NOT NULL DEFAULT '11' AFTER `font_showdescription`,
		ADD `align_showdescription` VARCHAR( 10 ) NOT NULL DEFAULT 'left' AFTER `fontsize_showdescription`,
		ADD `view_endtime` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `align_showdescription`,
		ADD `bold_showtitle` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `font_showtitle`,
		ADD `bold_showdescription` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `font_showdescription`,
		ADD `default_view` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `view_endtime`,
		ADD `view_changeable` SMALLINT( 1 ) UNSIGNED NOT NULL AFTER `default_view`
		;
	 ");
	 $result = @dbquery("ALTER TABLE `".$sendeplan_db['table_shows']."`
	 ADD `studiobox` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
	 ADD `is_nsv` SMALLINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
	 CHANGE `title` `title` VARCHAR( 50 ) NOT NULL;");
	 $result = @dbquery("UPDATE `".$sendeplan_db['table_settings']."` SET `version` = '3.03' WHERE `profile` = 'default';");
	 redirect(FUSION_SELF.$aidlink."&update=successfull");
}
elseif ($sp_setting['version'] == '3.02') {	 
	 $result = @dbquery("UPDATE `".$sendeplan_db['table_settings']."` SET `version` = '3.03' WHERE `profile` = 'default';");
	 redirect(FUSION_SELF.$aidlink);
}

else { $installed_version = $sp_setting['version']; }

if(IsSet($_GET['update']) && $_GET['update']=='successfull') {
	echo "
	<div class='admin-message'>Die Datenbank wurde erfolgreich aktualisiert. Das Update ist damit abgeschlossen.</div><br /><hr />
	";
}

echo "Installierte Version: <strong><span style='color: ".($installed_version==$current_version ? "green" : "red")."; background-color: #fff;'>".$installed_version."</span></strong><br />\n";
if($installed_version==$current_version) { echo "<em>Ihre Installation ist aktuell.</em>\n"; }
elseif(ini_get('allow_url_fopen')==false) { echo "<em>Es kann nicht gfestgestellt werden, ob Ihre Installation auf dem neuesten Stand ist.</em>\n"; }
else { echo "<em>Ihre Installation ist veraltet. Sie sollten die neue Version laden und installieren.</em>\n"; }
echo "<br /><br />\n";
echo "<div>Bitte beachten Sie, dass Sie eine &Auml;nderung Ihrer URL stets mitteilen!</div><br />\n";

echo "<div>Bei Fragen und Problemen nutzen Sie bitte unser [<a href='http://www.systemweb.de/kontakt.html' target='_blank'>Kontaktformular</a>] oder besuchen Sie unseren Live-Support!</div>\n<br />\n";

?>
<hr />
<div>
<script type='text/javascript'>showSPInfo();</script>
</div>

<?php
closetable();

if(!FUSION_V6) { require_once THEMES."templates/footer.php"; }
else {
	//require_once BASEDIR."side_right.php";
	require_once BASEDIR."footer.php";
}
?>
