package Upgrade;
use strict;
#################################################################################
# Ikonboard v3 by Jarvis Entertainment Group, Inc.
#
# No parts of this script can be used outside Ikonboard without prior consent.
#
# More information available from <ib-license@jarvisgroup.net>
# (c)2001 Jarvis Entertainment Group, Inc.
# 
# http://www.ikonboard.com
#
# Please Read the license for more information
#
# Script Author: Phil Gengler (LrdChaos) <lrdchaos@codeallday.com>
#+-----------------------------------------------------------------+
#
# Upgrade: Perform some basic upgrade things.
#
#################################################################################

BEGIN {
    require 'Lib/FUNC.pm';
    require 'Lib/ADMIN.pm';
}

my $std      = FUNC::STD->new();
my $mem      = FUNC::Member->new();
my $output   = FUNC::Output->new();
my $ADMIN    = FUNC::ADMIN->new();

sub new {
    my $pkg = shift;
    my $obj = { };
    bless $obj, $pkg;
    return $obj;
}

sub Upgrade {
	my ($obj, $db) = @_;
	
	my $html;
	
	$html = qq!<form action="$iB::INFO->{'BOARD_URL'}/ikonboard.$iB::INFO->{'CGI_EXT'}">
			<input type="hidden" name="s" value="$iB::SESSION">
			<input type="hidden" name="act" value="Upgrade">
			<input type="hidden" name="CODE" value="doupgrade">
			<center><input type="submit" value="Upgrade"></center></form>!;
	
    $output->print_ikonboard( DB         => $db,
                              STD        => $std,
                              OUTPUT     => $html,
                              JAVASCRIPT => 1,
                              TITLE      => "iB::Upgrading",
                              NAV        => [ "Upgrading" ],
                            );


}

sub do_upgrade {
	my ($obj, $db) = @_;
	
	$db->insert( TABLE  => 'email_templates',
		     VALUES => {  ID       => 'MASS_MAIL',
		     		  TYPE	   => 't',
		     		  TEMPLATE => '<#MESSAGE#>\n\n-------------------------------------------------\n\nPlease note, Ikonboard cannot be held responsible for the content of this email.The option to remove yourself from these mailings is in your profile. Log into your Control Panel at <#BOARD_ADDRESS#>, and choose Email Settings, and uncheck "Send me any updates sent by the board administrator".',
		     	       },
		   );
	if (-e $iB::INFO{'DB_DIR'} . "Email-log") {
		unlink $iB::INFO->{'DB_DIR'} . "Email-log";
	}
	require $iB::INFO->{'SKIN_DIR'} . 'Default/Styles.pm' or die $!;
    	require $iB::INFO->{'SKIN_DIR'} . 'Default/gfx_data.cfg' or die $!;

    	my $GFX = gfx_data->new();
    	my $SKN = Styles->new();
    	
    	$GFX->{'B_POLL_LOCKED'} = [ "Locked poll topic Marker", "f_poll_locked.gif", "1", "0", "", "", "", "",];
    	my $path = '$iB::INFO->{\'IMAGES_URL\'}';
	$SKN->{'B_POLL_LOCKED'} = "<img src=\"$path/Skin/Default/images/f_poll_locked.gif\" border=\"\"  alt=\"\">";
	
	foreach (keys %{$SKN}) {
	    my $real_location = '$iB::INFO->{\'IMAGES_URL\'}/Skin/Default/images';
            $SKN->{$_} =~ s!$iB::INFO->{'IMAGES_URL'}/Skin/Default/images!$real_location!i;
        }
	
	$ADMIN->make_module( FILE        => 'Styles.pm',
                             PKG_NAME    => 'Styles',
                             VALUES      => $SKN,
                             PATH        => $iB::INFO->{'IKON_DIR'}.'Skin/Default/',
			     INTERPOLATE => 'yes'
                           );

    	$ADMIN->make_module( FILE     => 'gfx_data.cfg',
                             PKG_NAME => 'gfx_data',
                             VALUES   => $GFX,
                             PATH     => $iB::INFO->{'IKON_DIR'}.'Skin/Default/'
                           );

	$output->print_ikonboard( DB         => $db,
                                  STD        => $std,
                                  OUTPUT     => "Success!",
                                  JAVASCRIPT => 1,
                                  TITLE      => "iB::Upgrading",
                                  NAV        => [ "Upgrading" ],
                                );
}
		

sub Process {
    my ($obj, $db) = @_;
    my $CodeNo = $iB::IN{'CODE'};
        
    if ($iB::MEMBER->{'MEMBER_GROUP'} ne $iB::INFO->{'SUPAD_GROUP'}) {
    	$std->Error( DB => $db, LEVEL => 1, MESSAGE => "no_older");
    }
    my %Mode = ( ''           => \&Upgrade,
                 'doupgrade'  => \&do_upgrade,
               );
    $Mode{$CodeNo} ? $Mode{$CodeNo}->($obj,$db) : FatalError();
} 

sub FatalError { }

1;