##----------------------------------------------------------------------------------#
 # MusicMiner Web Server															#
 # Name:		source/app/sql/upgrade_1.2.0.4.sql									#
 # Author:		Jesse J Morrow	(jesse@jessejmorrow.com)							#
 # Created:		2009-11-23															#
 # Updated:		2009-11-23															#
 # Compat:		MySQL 5																#
 # Copyright:	Copyright 2009 Soundminer Inc.										#
 # Purpose:		Upgrade the installed MusicMiner databases.							#
 # Version:		1.2.0.3 to 1.2.0.4													#
 #----------------------------------------------------------------------------------##

# Add more HTML customization fields to `site` table
ALTER TABLE `mm_admin`.`site` ADD COLUMN `main_head` TEXT NOT NULL COMMENT 'Custom HTML to insert at end of <head></head>.' AFTER `login_body2`,
 ADD COLUMN `main_body1` TEXT NOT NULL COMMENT 'Custom HTML to insert at start of <body></body>.' AFTER `main_head`,
 ADD COLUMN `main_body2` TEXT NOT NULL COMMENT 'Custom HTML to insert at end of <body></body>.' AFTER `main_body1`,
 ADD COLUMN `admin_head` TEXT NOT NULL COMMENT 'Custom HTML to insert at end of <head></head>.' AFTER `main_body2`,
 ADD COLUMN `admin_body1` TEXT NOT NULL COMMENT 'Custom HTML to insert at start of <body></body>.' AFTER `admin_head`,
 ADD COLUMN `admin_body2` TEXT NOT NULL COMMENT 'Custom HTML to insert at end of <body></body>.' AFTER `admin_body1`;

# Convert old style customization to new style
UPDATE `mm_admin`.`site` SET `main_body1` = IF(`html_header_height` = 0, '', CONCAT('<div id="header">', `html_header`, '</div>'));
UPDATE `mm_admin`.`site` SET `main_body2` = IF(`html_footer_height` = 0, '', CONCAT('<div id="footer">', `html_footer`, '</div>'));
UPDATE `mm_admin`.`site` SET `main_head` = IF(`html_header_height` = 0 AND `html_footer_height` = 0, '', CONCAT(
'<style type="text/css">
	div#header, div#footer { position: absolute; left: 0; right: 0; overflow: hidden; }
	div#header { top: 0; height: ', `html_header_height`, 'px; }
	div#footer { bottom: 0; height: ', `html_footer_height`, 'px; }
	div#wrap { top: ', `html_header_height`, 'px; bottom: ', `html_footer_height`, 'px; }
</style>' ) );
UPDATE `mm_admin`.`site` SET `admin_head` = `main_head`, `admin_body1` = `main_body1`, `admin_body2` = `main_body2`;

# Remove old fields
ALTER TABLE `mm_admin`.`site` DROP COLUMN `html_header`,
 DROP COLUMN `html_footer`,
 DROP COLUMN `html_header_height`,
 DROP COLUMN `html_footer_height`;

#-----------------------------------------------------------------------------
# Versions
#-----------------------------------------------------------------------------

# Update version fields
UPDATE `mm_admin`.`schema` SET `db_ver` = '1.2.0.4';