Location: PHPKode > projects > EverQuest Roster/Gallery > html/includes/install.php
<?php

error_reporting  (E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);

//+---------------------------------------
// ENTER YOUR PATH TO THE DIRECTORY THIS SCRIPT
// IS IN.
//
// Tips:
//
// If you are using Windows and Apache, do not
// use backslashes, use normal forward slashes.
// You may need to remove the drive letter also
// Example: C:\apache\htdocs\ibforums\ will need
// to be: /apache/htdocs/ibforums/
//
// If you are using Windows and IIS, then you will
// need to enter double backslashes.
//
// In all cases, please enter a trailing slash (or
// trailing backslashes...)
//+---------------------------------------

$root = "./";



//+---------------------------------------

$template = new template;
$std      = new installer;

$VARS = $std->parse_incoming();

//+---------------------------------------
// What are we doing then? Eh? I'm talking to you!
//+---------------------------------------

if ( file_exists($root.'install.lock') )
{
        install_error("This installer is locked!<br>Please (via FTP) remove the 'install.lock' file in this directory");
        exit();
}


switch($VARS['a'])
{
        case '1':
                do_select();
                break;

        case '2':
                do_upgrade();
                break;

        case '3':
                do_upgrade15b1();
                break;

        case '4':
                do_db15b1();
                break;

        case '5':
                do_upgrade15();
                break;

        case '6':
                do_db15();
                break;

        case '7':
                do_upgrade16();
                break;

        case '8':
                do_db16();
                break;

        case '9':
                do_upgrade17b1();
                break;

        case '10':
                do_db17b1();
                break;

        case '11':
                do_setup_form();
                break;

        case '12':
                do_install();
                break;

        case '13':
                do_finish();
                break;

        default:
                do_intro();
                break;
}

function do_select()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        $template->print_top('Selection!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Selecting a Method</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>You need to select a method of installing</b>
                                                                                   <br><br>
                                                                                   Select New Install if you are installing for the first time<br>Select Upgrade if you are upgrading from a previous version.
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

                $template->contents .= "<tr><td align='center' style='font-size:18px'><br><b><a href='install.php?a=11'>New Install</a></b>&nbsp;<b><a href='install.php?a=2'>Upgrade</a></b></td></tr>";

        $template->output();

}

function do_upgrade()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        $template->print_top('Upgrade!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Selecting an Upgrade</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>You need to select the current version you have installed.</b>
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=3'>Version 1.5b1</a></center><p>
                                                                                   <center><b><a href='install.php?a=5'>Version 1.5</a></center><p>
                                                                                   <center><b><a href='install.php?a=7'>Version 1.6</a></center><p>
                                                                                   <center><b><a href='install.php?a=9'>Version 1.7b1</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}

function do_upgrade15b1()
{
        global $std, $template, $root, $HTTP_SERVER_VARS;

        $template->print_top('Set Up form');

        //--------------------------------------------------

        $this_url = str_replace( "/install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);

        if ( ! $this_url )
        {
                $this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);

            if ($this_url == '')
            {
                    $this_url == '/';
            }
            $this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
    }


        //--------------------------------------------------

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Your Server Environment</td>
                                                        <tr>
                                                        <td>
                                                          <form action='install.php' method='POST'>
                                                          <input type='hidden' name='a' value='4'>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the paths and URL's for the board. If in doubt, please
                                                                                   check with your webhost before asking for support.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The character images path</b><br>This is the direct path to the directory the character images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosurl' value='/home/user/htdocs/roster/images/chars/'></td>
                                                                 </tr>
                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The gallery images path</b><br>This is the direct path to the directory the gallery images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galurl' value='/home/user/htdocs/gallery/images/'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your Script Options</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the numerical options for the script remember only numbers are allowed!, The default configuration is already entered.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max character images size</b><br>This is the largest a single characters image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosmimgs' value='100'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max # of listings for gallery main page</b><br>This is the number of images to show per page in the gallery list</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimg' value='50'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max gallery image size</b><br>This is the largest a single gallery image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimgs' value='200'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your SQL Environment</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter your SQL information. If in doubt, please
                                                                                   check with your webhost before asking for support. You may choose to enter an existing database name,
                                                                                   if not - you must create a new database before continuing.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Host</b><br>(localhost is usually sufficient)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_host' value='localhost'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Database Name</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_database' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_user' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_pass' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                         <td colspan='2' id='tdrow1' align='center'><input type='submit' value='Process'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>
                                                 </form>
                                                 </td>
                                                 </tr>

                                                 ";

        $template->output();

}

function do_db15b1()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        // Ok, lets check for blankies...

        $NEW_INFO = array();

        $need = array('rosurl','galurl','rosmimgs','galmimg','galmimgs','guildpass','sql_host','sql_database','sql_user');


        //-----------------------------------
        // IMPORT $INFO!
        //-----------------------------------

        if ($root == './')
        {
                $root = str_replace( '\\', '/', getcwd() ) . '/';
        }

        $require = $root."config.php";

        if ( ! file_exists($require) )
        {
                install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
        }

        include($require);

        //-----------------------------------
        // Attempt a DB connection..
        //-----------------------------------

        if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
        {
                install_error("Could not create a mySQL connection, please check the SQL values entered");
        }


        if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
        {
                install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
        }

        //-----------------------------------
        // Attempt to write the config file.
        //-----------------------------------

        $new  = array( 'HOSTNAME'        => $VARS['sql_host'],
                       'DATABASE'        => $VARS['sql_database'],
                       'LOGIN'           => $HTTP_POST_VARS['sql_user'],
                       'PASSWORD'        => $HTTP_POST_VARS['sql_pass'],
                       #'PREFIX'          => $VARS['sql_tbl_prefix'],
                       'GUILD_PASSWORD'  => $VARS['guildpass'],
                       'IMAGE_DIR'       => $VARS['rosurl'],
                       'MAX_IMAGE_SIZE'  => $VARS['rosmimgs'],
                       'GIMAGE_DIR'      => $VARS['galurl'],
                       'GMAX_IMAGES'     => $VARS['galmimg'],
                       'GMAX_IMAGE_SIZE' => $VARS['galmimgs']

                     );

         foreach( $new as $k => $v )
         {
                 // Update the old...

                 $v = preg_replace( "/'/", "\\'" , $v );
                 $v = preg_replace( "/\r/", ""   , $v );

                 define("$k", "$v");
         }

         $file_string = "<?php\n\n";

         $file_string .= "        /**********************************************************************************
        *                                                                                 *
        *                                 config.php                                      *
        *                             -------------------                                 *
        *                                                                                 *
        * Program           : EverQuest Roster/Gallery v1.7b1                             *
        * Copyright         : (C) 2001 - 2002 BladeTek Internet Services &                *
        *                                                     The EQRG Developement Team  *
        * Website           : http://eqrg.roleplayersinteraction.com                      *
        * Project Website   : http://www.sourceforge.net/projects/eqrostergallery         *
        * Email             : hide@address.com                                        *
        *                                                                                 *
        * For license information, please read the COPYING file which                     *
        * came with this edition                                                          *
        *                                                                                 *
        **********************************************************************************/\n\n        session_start();\n\n";

         foreach( $new as $k => $v )
         {

                 $file_string .= '        define('."'".$k."'".', '."'".$v."');\n";
         }

         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p

         if ( $fh = fopen( $require, 'w' ) )
         {
                 fputs($fh, $file_string, strlen($file_string) );
                 fclose($fh);
         }
         else
         {
                 install_error("Could not write to 'config.php'");
         }

         //-----------------------------------
         // Lets populate the database!
         //-----------------------------------

         $SQL = get_sqlu15b1();

         foreach( $SQL as $q )
         {

        if ( ! mysql_query($q, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());
        }
        }

        // ARE WE DONE? REALLY? COOL!!

        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Success!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Your database has now been installed!</b>
                                                                                   <br><br>
                                                                                   The installation process is almost complete..
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=13'>CLICK HERE TO COMPLETE THE INSTALL</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}

function do_upgrade15()
{
        global $std, $template, $root, $HTTP_SERVER_VARS;

        $template->print_top('Set Up form');

        //--------------------------------------------------

        $this_url = str_replace( "/install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);

        if ( ! $this_url )
        {
                $this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);

            if ($this_url == '')
            {
                    $this_url == '/';
            }
            $this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
    }


        //--------------------------------------------------

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Your Server Environment</td>
                                                        <tr>
                                                        <td>
                                                          <form action='install.php' method='POST'>
                                                          <input type='hidden' name='a' value='6'>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the paths and URL's for the board. If in doubt, please
                                                                                   check with your webhost before asking for support.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The character images path</b><br>This is the direct path to the directory the character images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosurl' value='/home/user/htdocs/roster/images/chars/'></td>
                                                                 </tr>
                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The gallery images path</b><br>This is the direct path to the directory the gallery images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galurl' value='/home/user/htdocs/gallery/images/'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your Script Options</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the numerical options for the script remember only numbers are allowed!, The default configuration is already entered.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max character images size</b><br>This is the largest a single characters image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosmimgs' value='100'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max # of listings for gallery main page</b><br>This is the number of images to show per page in the gallery list</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimg' value='50'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max gallery image size</b><br>This is the largest a single gallery image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimgs' value='200'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your SQL Environment</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter your SQL information. If in doubt, please
                                                                                   check with your webhost before asking for support. You may choose to enter an existing database name,
                                                                                   if not - you must create a new database before continuing.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Host</b><br>(localhost is usually sufficient)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_host' value='localhost'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Database Name</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_database' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_user' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_pass' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                         <td colspan='2' id='tdrow1' align='center'><input type='submit' value='Process'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>
                                                 </form>
                                                 </td>
                                                 </tr>

                                                 ";

        $template->output();

}

function do_db15()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        // Ok, lets check for blankies...

        $NEW_INFO = array();

        $need = array('rosurl','galurl','rosmimgs','galmimg','galmimgs','guildpass','sql_host','sql_database','sql_user');


        //-----------------------------------
        // IMPORT $INFO!
        //-----------------------------------

        if ($root == './')
        {
                $root = str_replace( '\\', '/', getcwd() ) . '/';
        }

        $require = $root."config.php";

        if ( ! file_exists($require) )
        {
                install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
        }

        include($require);

        //-----------------------------------
        // Attempt a DB connection..
        //-----------------------------------

        if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
        {
                install_error("Could not create a mySQL connection, please check the SQL values entered");
        }


        if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
        {
                install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
        }

        //-----------------------------------
        // Attempt to write the config file.
        //-----------------------------------

        $new  = array( 'HOSTNAME'        => $VARS['sql_host'],
                       'DATABASE'        => $VARS['sql_database'],
                       'LOGIN'           => $HTTP_POST_VARS['sql_user'],
                       'PASSWORD'        => $HTTP_POST_VARS['sql_pass'],
                       #'PREFIX'          => $VARS['sql_tbl_prefix'],
                       'GUILD_PASSWORD'  => $VARS['guildpass'],
                       'IMAGE_DIR'       => $VARS['rosurl'],
                       'MAX_IMAGE_SIZE'  => $VARS['rosmimgs'],
                       'GIMAGE_DIR'      => $VARS['galurl'],
                       'GMAX_IMAGES'     => $VARS['galmimg'],
                       'GMAX_IMAGE_SIZE' => $VARS['galmimgs']

                     );

         foreach( $new as $k => $v )
         {
                 // Update the old...

                 $v = preg_replace( "/'/", "\\'" , $v );
                 $v = preg_replace( "/\r/", ""   , $v );

                 define("$k", "$v");
         }

         $file_string = "<?php\n\n";

         $file_string .= "        /**********************************************************************************
        *                                                                                 *
        *                                 config.php                                      *
        *                             -------------------                                 *
        *                                                                                 *
        * Program           : EverQuest Roster/Gallery v1.7b1                             *
        * Copyright         : (C) 2001 - 2002 BladeTek Internet Services &                *
        *                                                     The EQRG Developement Team  *
        * Website           : http://eqrg.roleplayersinteraction.com                      *
        * Project Website   : http://www.sourceforge.net/projects/eqrostergallery         *
        * Email             : hide@address.com                                        *
        *                                                                                 *
        * For license information, please read the COPYING file which                     *
        * came with this edition                                                          *
        *                                                                                 *
        **********************************************************************************/\n\n        session_start();\n\n";

         foreach( $new as $k => $v )
         {

                 $file_string .= '        define('."'".$k."'".', '."'".$v."');\n";
         }

         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p

         if ( $fh = fopen( $require, 'w' ) )
         {
                 fputs($fh, $file_string, strlen($file_string) );
                 fclose($fh);
         }
         else
         {
                 install_error("Could not write to 'config.php'");
         }

         //-----------------------------------
         // Lets populate the database!
         //-----------------------------------

         $SQL = get_sqlu15();

         foreach( $SQL as $q )
         {

        if ( ! mysql_query($q, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());
        }
        }

        // ARE WE DONE? REALLY? COOL!!

        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Success!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Your database has now been installed!</b>
                                                                                   <br><br>
                                                                                   The installation process is almost complete..
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=13'>CLICK HERE TO COMPLETE THE INSTALL</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}

function do_upgrade16()
{
        global $std, $template, $root, $HTTP_SERVER_VARS;

        $template->print_top('Set Up form');

        //--------------------------------------------------

        $this_url = str_replace( "/install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);

        if ( ! $this_url )
        {
                $this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);

            if ($this_url == '')
            {
                    $this_url == '/';
            }
            $this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
    }


        //--------------------------------------------------

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Your Server Environment</td>
                                                        <tr>
                                                        <td>
                                                          <form action='install.php' method='POST'>
                                                          <input type='hidden' name='a' value='8'>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the paths and URL's for the board. If in doubt, please
                                                                                   check with your webhost before asking for support.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The character images path</b><br>This is the direct path to the directory the character images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosurl' value='/home/user/htdocs/roster/images/chars/'></td>
                                                                 </tr>
                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The gallery images path</b><br>This is the direct path to the directory the gallery images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galurl' value='/home/user/htdocs/gallery/images/'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your Script Options</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the numerical options for the script remember only numbers are allowed!, The default configuration is already entered.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max character images size</b><br>This is the largest a single characters image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosmimgs' value='100'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max # of listings for gallery main page</b><br>This is the number of images to show per page in the gallery list</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimg' value='50'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max gallery image size</b><br>This is the largest a single gallery image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimgs' value='200'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your SQL Environment</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter your SQL information. If in doubt, please
                                                                                   check with your webhost before asking for support. You may choose to enter an existing database name,
                                                                                   if not - you must create a new database before continuing.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Host</b><br>(localhost is usually sufficient)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_host' value='localhost'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Database Name</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_database' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_user' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_pass' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                         <td colspan='2' id='tdrow1' align='center'><input type='submit' value='Process'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>
                                                 </form>
                                                 </td>
                                                 </tr>

                                                 ";

        $template->output();

}

function do_db16()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        // Ok, lets check for blankies...

        $NEW_INFO = array();

        $need = array('rosurl','galurl','rosmimgs','galmimg','galmimgs','guildpass','sql_host','sql_database','sql_user');


        //-----------------------------------
        // IMPORT $INFO!
        //-----------------------------------

        if ($root == './')
        {
                $root = str_replace( '\\', '/', getcwd() ) . '/';
        }

        $require = $root."config.php";

        if ( ! file_exists($require) )
        {
                install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
        }

        include($require);

        //-----------------------------------
        // Attempt a DB connection..
        //-----------------------------------

        if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
        {
                install_error("Could not create a mySQL connection, please check the SQL values entered");
        }


        if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
        {
                install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
        }

        //-----------------------------------
        // Attempt to write the config file.
        //-----------------------------------

        $new  = array( 'HOSTNAME'        => $VARS['sql_host'],
                       'DATABASE'        => $VARS['sql_database'],
                       'LOGIN'           => $HTTP_POST_VARS['sql_user'],
                       'PASSWORD'        => $HTTP_POST_VARS['sql_pass'],
                       #'PREFIX'          => $VARS['sql_tbl_prefix'],
                       'GUILD_PASSWORD'  => $VARS['guildpass'],
                       'IMAGE_DIR'       => $VARS['rosurl'],
                       'MAX_IMAGE_SIZE'  => $VARS['rosmimgs'],
                       'GIMAGE_DIR'      => $VARS['galurl'],
                       'GMAX_IMAGES'     => $VARS['galmimg'],
                       'GMAX_IMAGE_SIZE' => $VARS['galmimgs']

                     );

         foreach( $new as $k => $v )
         {
                 // Update the old...

                 $v = preg_replace( "/'/", "\\'" , $v );
                 $v = preg_replace( "/\r/", ""   , $v );

                 define("$k", "$v");
         }

         $file_string = "<?php\n\n";

         $file_string .= "        /**********************************************************************************
        *                                                                                 *
        *                                 config.php                                      *
        *                             -------------------                                 *
        *                                                                                 *
        * Program           : EverQuest Roster/Gallery v1.7b1                             *
        * Copyright         : (C) 2001 - 2002 BladeTek Internet Services &                *
        *                                                     The EQRG Developement Team  *
        * Website           : http://eqrg.roleplayersinteraction.com                      *
        * Project Website   : http://www.sourceforge.net/projects/eqrostergallery         *
        * Email             : hide@address.com                                        *
        *                                                                                 *
        * For license information, please read the COPYING file which                     *
        * came with this edition                                                          *
        *                                                                                 *
        **********************************************************************************/\n\n        session_start();\n\n";

         foreach( $new as $k => $v )
         {

                 $file_string .= '        define('."'".$k."'".', '."'".$v."');\n";
         }

         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p

         if ( $fh = fopen( $require, 'w' ) )
         {
                 fputs($fh, $file_string, strlen($file_string) );
                 fclose($fh);
         }
         else
         {
                 install_error("Could not write to 'config.php'");
         }

         //-----------------------------------
         // Lets populate the database!
         //-----------------------------------

         $SQL = get_sqlu16();

         foreach( $SQL as $q )
         {

        if ( ! mysql_query($q, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());
        }
        }

        // ARE WE DONE? REALLY? COOL!!

        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Success!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Your database has now been installed!</b>
                                                                                   <br><br>
                                                                                   The installation process is almost complete..
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=13'>CLICK HERE TO COMPLETE THE INSTALL</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}

function do_upgrade17b1()
{
        global $std, $template, $root, $HTTP_SERVER_VARS;

        $template->print_top('Set Up form');

        //--------------------------------------------------

        $this_url = str_replace( "/install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);

        if ( ! $this_url )
        {
                $this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);

            if ($this_url == '')
            {
                    $this_url == '/';
            }
            $this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
    }


        //--------------------------------------------------

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Your Server Environment</td>
                                                        <tr>
                                                        <td>
                                                          <form action='install.php' method='POST'>
                                                          <input type='hidden' name='a' value='10'>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the paths and URL's for the board. If in doubt, please
                                                                                   check with your webhost before asking for support.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The character images path</b><br>This is the direct path to the directory the character images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosurl' value='/home/user/htdocs/roster/images/chars/'></td>
                                                                 </tr>
                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The gallery images path</b><br>This is the direct path to the directory the gallery images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galurl' value='/home/user/htdocs/gallery/images/'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your Script Options</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the numerical options for the script remember only numbers are allowed!, The default configuration is already entered.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max character images size</b><br>This is the largest a single characters image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosmimgs' value='100'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max # of listings for gallery main page</b><br>This is the number of images to show per page in the gallery list</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimg' value='50'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max gallery image size</b><br>This is the largest a single gallery image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimgs' value='200'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your SQL Environment</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter your SQL information. If in doubt, please
                                                                                   check with your webhost before asking for support. You may choose to enter an existing database name,
                                                                                   if not - you must create a new database before continuing.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Host</b><br>(localhost is usually sufficient)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_host' value='localhost'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Database Name</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_database' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_user' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_pass' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                         <td colspan='2' id='tdrow1' align='center'><input type='submit' value='Process'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>
                                                 </form>
                                                 </td>
                                                 </tr>

                                                 ";

        $template->output();

}

function do_db17b1()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        // Ok, lets check for blankies...

        $NEW_INFO = array();

        $need = array('rosurl','galurl','rosmimgs','galmimg','galmimgs','guildpass','sql_host','sql_database','sql_user');


        //-----------------------------------
        // IMPORT $INFO!
        //-----------------------------------

        if ($root == './')
        {
                $root = str_replace( '\\', '/', getcwd() ) . '/';
        }

        $require = $root."config.php";

        if ( ! file_exists($require) )
        {
                install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
        }

        include($require);

        //-----------------------------------
        // Attempt a DB connection..
        //-----------------------------------

        if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
        {
                install_error("Could not create a mySQL connection, please check the SQL values entered");
        }


        if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
        {
                install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
        }

        //-----------------------------------
        // Attempt to write the config file.
        //-----------------------------------

        $new  = array( 'HOSTNAME'        => $VARS['sql_host'],
                       'DATABASE'        => $VARS['sql_database'],
                       'LOGIN'           => $HTTP_POST_VARS['sql_user'],
                       'PASSWORD'        => $HTTP_POST_VARS['sql_pass'],
                       #'PREFIX'          => $VARS['sql_tbl_prefix'],
                       'GUILD_PASSWORD'  => $VARS['guildpass'],
                       'IMAGE_DIR'       => $VARS['rosurl'],
                       'MAX_IMAGE_SIZE'  => $VARS['rosmimgs'],
                       'GIMAGE_DIR'      => $VARS['galurl'],
                       'GMAX_IMAGES'     => $VARS['galmimg'],
                       'GMAX_IMAGE_SIZE' => $VARS['galmimgs']

                     );

         foreach( $new as $k => $v )
         {
                 // Update the old...

                 $v = preg_replace( "/'/", "\\'" , $v );
                 $v = preg_replace( "/\r/", ""   , $v );

                 define("$k", "$v");
         }

         $file_string = "<?php\n\n";

         $file_string .= "        /**********************************************************************************
        *                                                                                 *
        *                                 config.php                                      *
        *                             -------------------                                 *
        *                                                                                 *
        * Program           : EverQuest Roster/Gallery v1.7b1                             *
        * Copyright         : (C) 2001 - 2002 BladeTek Internet Services &                *
        *                                                     The EQRG Developement Team  *
        * Website           : http://eqrg.roleplayersinteraction.com                      *
        * Project Website   : http://www.sourceforge.net/projects/eqrostergallery         *
        * Email             : hide@address.com                                        *
        *                                                                                 *
        * For license information, please read the COPYING file which                     *
        * came with this edition                                                          *
        *                                                                                 *
        **********************************************************************************/\n\n        session_start();\n\n";

         foreach( $new as $k => $v )
         {

                 $file_string .= '        define('."'".$k."'".', '."'".$v."');\n";
         }

         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p

         if ( $fh = fopen( $require, 'w' ) )
         {
                 fputs($fh, $file_string, strlen($file_string) );
                 fclose($fh);
         }
         else
         {
                 install_error("Could not write to 'config.php'");
         }

         //-----------------------------------
         // Lets populate the database!
         //-----------------------------------

         $SQL = get_sqlu17b1();

         foreach( $SQL as $q )
         {

        if ( ! mysql_query($q, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());
        }
        }

        // ARE WE DONE? REALLY? COOL!!

        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Success!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Your database has now been installed!</b>
                                                                                   <br><br>
                                                                                   The installation process is almost complete..
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=13'>CLICK HERE TO COMPLETE THE INSTALL</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}

function do_finish()
{
        global $std, $template, $root, $VARS, $SQL;

        // Attempt to lock the install..

        if ($FH = fopen( $root.'install.lock', 'w' ) )
        {
                fwrite( $FH, 'locked', 6 );
                fclose($FH);

                @chmod( $root.'install.lock', 0666 );

                $template->print_top('Success!');

                $template->contents .= "<tr>
                                                                  <td id='subtitle'>Success!</td>
                                                                <tr>
                                                                <td>
                                                                  <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                                  <tr>
                                                                        <td>
                                                                  <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                                   <tr>
                                                                        <td>
                                                                         <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                         <tr>
                                                                           <td>
                                                                                        <b>The installation is now complete!</b>
                                                                                        <br><br>
                                                                                        Although the installer is now locked (to re-install, remove the file 'install.lock'), for added
                                                                                        security, please remove the install.php program before continuing.
                                                                                        <br><br>
                                                                                        <center><b><a href='../login.php'>CLICK HERE TO LOG IN!</a></center>
                                                                                </td>
                                                                         </tr>
                                                                        </table>
                                                                  </td>
                                                                 </tr>
                                                                </table>
                                                           </td>
                                                          </tr>
                                                         </table>";
        }
        else
        {
        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='warning'>WARNING!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                <b>The installation is now complete!</b>
                                                                                <br><br>
                                                                                PLEASE REMOVE THE INSTALLER ('install.php') BEFORE CONTINUING!
                                                                                <br>
                                                                                Failure to do so will enable ANYONE to delete your database at any time!
                                                                                <br><br>
                                                                                <center><b><a href='../login.php'>CLICK HERE TO LOG IN!</a></center>
                                                                        </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";
        }

        $template->output();



}

//+---------------------------------------


function do_install()
{
        global $std, $template, $root, $VARS, $HTTP_POST_VARS;

        // Ok, lets check for blankies...

        $NEW_INFO = array();

        $need = array('rosurl','galurl','rosmimgs','galmimg','galmimgs','guildpass','sql_host','sql_database','sql_user','adminname','ap1','ap2','email');

        //-----------------------------------

        foreach($need as $greed)
        {
                if ($VARS[ $greed ] == "")
                {
                        install_error("You must complete all of the form with the sole exception of 'SQL Table prefix'");
                }
        }

        //-----------------------------------

        $VARS['board_url'] = preg_replace( "#/$#", "", $VARS['board_url'] );

        /*if ($VARS['sql_tbl_prefix'] == "")
        {
                $VARS['sql_tbl_prefix'] = 'eqrg_';
        }*/

        //-----------------------------------
        // Did the admin passy and passy2 match?
        //-----------------------------------

        if ($VARS['ap1'] != $VARS['ap2'])
        {
                install_error("Your passwords did not match");
        }

        /*if ( ! preg_match( "!^http://!", $VARS['board_url'] ) )
        {
                install_error("The board URL must start with 'http://'");
        }*/

        //-----------------------------------
        // IMPORT $INFO!
        //-----------------------------------

        if ($root == './')
        {
                $root = str_replace( '\\', '/', getcwd() ) . '/';
        }

        $require = $root."config.php";

        if ( ! file_exists($require) )
        {
                install_error("Could not locate '$require'. You may need to enter a value for the root path in this installer script, to do this, simply open up this script in a text editor and enter a value in \$root - remember to add a trailing slash. NT users will need to use double backslashes");
        }

        //@chmod( "conf_global.php", 0666 );

        include($require);

        //echo("here");
        //exit();

        #if ( count($INFO) < 1 )
        #{
        #        install_error("Possible corruption in 'config.php' ({$VARS['base_dir']}config.php), please re-upload in ASCII format");
        #}

        //-----------------------------------
        // Attempt a DB connection..
        //-----------------------------------

        if ( ! $connect_id = mysql_connect( $VARS['sql_host'],$HTTP_POST_VARS['sql_user'],$HTTP_POST_VARS['sql_pass'] ) )
        {
                install_error("Could not create a mySQL connection, please check the SQL values entered");
        }


        if ( ! mysql_select_db($VARS['sql_database'], $connect_id) )
        {
                install_error("mySQL could not locate a database called '{$VARS['sql_database']}' please check the value entered for this");
        }

        //-----------------------------------
        // Attempt to write the config file.
        //-----------------------------------

        $new  = array( 'HOSTNAME'        => $VARS['sql_host'],
                       'DATABASE'        => $VARS['sql_database'],
                       'LOGIN'           => $HTTP_POST_VARS['sql_user'],
                       'PASSWORD'        => $HTTP_POST_VARS['sql_pass'],
                       #'PREFIX'          => $VARS['sql_tbl_prefix'],
                       'GUILD_PASSWORD'  => $VARS['guildpass'],
                       'IMAGE_DIR'       => $VARS['rosurl'],
                       'MAX_IMAGE_SIZE'  => $VARS['rosmimgs'],
                       'GIMAGE_DIR'      => $VARS['galurl'],
                       'GMAX_IMAGES'     => $VARS['galmimg'],
                       'GMAX_IMAGE_SIZE' => $VARS['galmimgs']

                     );

         foreach( $new as $k => $v )
         {
                 // Update the old...

                 $v = preg_replace( "/'/", "\\'" , $v );
                 $v = preg_replace( "/\r/", ""   , $v );

                 define("$k", "$v");
         }

         $file_string = "<?php\n\n";

         $file_string .= "        /**********************************************************************************
        *                                                                                 *
        *                                 config.php                                      *
        *                             -------------------                                 *
        *                                                                                 *
        * Program           : EverQuest Roster/Gallery v1.7b1                             *
        * Copyright         : (C) 2001 - 2002 BladeTek Internet Services &                *
        *                                                     The EQRG Developement Team  *
        * Website           : http://eqrg.roleplayersinteraction.com                      *
        * Project Website   : http://www.sourceforge.net/projects/eqrostergallery         *
        * Email             : hide@address.com                                        *
        *                                                                                 *
        * For license information, please read the COPYING file which                     *
        * came with this edition                                                          *
        *                                                                                 *
        **********************************************************************************/\n        session_start();\n";

         foreach( $new as $k => $v )
         {

                 $file_string .= '        define('."'".$k."'".', '."'".$v."');\n";
         }

         $file_string .= "\n".'?'.'>';   // Question mark + greater than together break syntax hi-lighting in BBEdit 6 :p

         if ( $fh = fopen( $require, 'w' ) )
         {
                 fputs($fh, $file_string, strlen($file_string) );
                 fclose($fh);
         }
         else
         {
                 install_error("Could not write to 'config.php'");
         }

         //-----------------------------------
         // Lets populate the database!
         //-----------------------------------

         $SQL = get_sql();

         foreach( $SQL as $q )
         {
       /*          if ($VARS['sql_tbl_prefix'] != "eqrg_")
        {
           $q = preg_replace("/eqrg_(\S+?)([\s\.,]|$)/", $VARS['sql_tbl_prefix']."\\1\\2", $q);
        }*/

        if ( preg_match("/CREATE TABLE (\S+) \(/", $q, $match) )
        {
                if ($match[1])
                {
                        $the_query = "DROP TABLE if exists ".$match[1];
                        if (! mysql_query($the_query, $connect_id) )
                        {
                                install_error("mySQL Error: ".mysql_error());
                        }
                }
        }

        if ( ! mysql_query($q, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());
        }
        }

        // Insert the admin...
        #".$VARS['sql_tbl_prefix']."
        #$passy = md5($VARS['ap1']);
        $time  = time();

        $query = "INSERT INTO users (id, level, timezone, update_time, login, passwd, email, sort1, sort2, sort3) ".
                     "VALUES(1, 34, 0, $time, '{$VARS['adminname']}', '{$VARS['ap1']}', '{$VARS['email']}', 'status', 'class', 'name')";

        if ( ! mysql_query($query, $connect_id) )
        {
                install_error("mySQL Error: ".mysql_error());

        }

        // ARE WE DONE? REALLY? COOL!!

        $template->print_top('Success!');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Success!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Your database has now been installed!</b>
                                                                                   <br><br>
                                                                                   The installation process is almost complete..
                                                                                   <br><br>
                                                                                   <center><b><a href='install.php?a=13'>CLICK HERE TO COMPLETE THE INSTALL</a></center>
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        $template->output();

}




function do_setup_form()
{
        global $std, $template, $root, $HTTP_SERVER_VARS;

        $template->print_top('Set Up form');

        //--------------------------------------------------

        $this_url = str_replace( "/install.php", "", $HTTP_SERVER_VARS['HTTP_REFERER']);

        if ( ! $this_url )
        {
                $this_url = substr($HTTP_SERVER_VARS['SCRIPT_NAME'],0, -15);

            if ($this_url == '')
            {
                    $this_url == '/';
            }
            $this_url = 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].$this_url;
    }


        //--------------------------------------------------

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Your Server Environment</td>
                                                        <tr>
                                                        <td>
                                                          <form action='install.php' method='POST'>
                                                          <input type='hidden' name='a' value='10'>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the paths and URL's for the board. If in doubt, please
                                                                                   check with your webhost before asking for support.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The character images path</b><br>This is the direct path to the directory the character images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosurl' value='/home/user/htdocs/roster/images/chars/'></td>
                                                                 </tr>
                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The gallery images path</b><br>This is the direct path to the directory the gallery images will be uploaded to (must have trailing slash \"/\")</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galurl' value='/home/user/htdocs/gallery/images/'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your Script Options</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter the numerical options for the script remember only numbers are allowed!, The default configuration is already entered.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max character images size</b><br>This is the largest a single characters image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='rosmimgs' value='100'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max # of listings for gallery main page</b><br>This is the number of images to show per page in the gallery list</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimg' value='50'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>The max gallery image size</b><br>This is the largest a single gallery image can be uploaded (in KB)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='galmimgs' value='200'></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 </td>
                                                 </tr>
                                                 <tr>
                                                          <td id='subtitle'>Your SQL Environment</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires you to enter your SQL information. If in doubt, please
                                                                                   check with your webhost before asking for support. You may choose to enter an existing database name,
                                                                                   if not - you must create a new database before continuing.
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Host</b><br>(localhost is usually sufficient)</td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_host' value='localhost'></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Database Name</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_database' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_user' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>SQL Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='sql_pass' value=''></td>
                                                                 </tr>

                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>

                                                 <tr>
                                                          <td id='subtitle'>Your Admin Account</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td colspan='2' id='tdrow1'>
                                                                                   This section requires information to create your administration account. Please
                                                                                   enter the data carefully!
                                                                           </td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>Username</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='adminname' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>Password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='password' id='textinput' name='ap1' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>Retype your password</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='password' id='textinput' name='ap2' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                   <td width='40%' id='tdrow1'><b>Email Address</b></td>
                                                                   <td width='60%' id='tdrow2'><input type='text' id='textinput' name='email' value=''></td>
                                                                 </tr>

                                                                 <tr>
                                                                         <td colspan='2' id='tdrow1' align='center'><input type='submit' value='Process'></td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>
                                                 </form>
                                                 </td>
                                                 </tr>

                                                 ";

        $template->output();

}

//+---------------------------------------

function do_intro()
{
        global $std, $template, $root;

        $template->print_top('Welcome');

        $template->contents .= "<tr>
                                                          <td id='subtitle'>Welcome!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>Welcome to the EverQuest Roster/Gallery Safe Mode Installer</b>
                                                                                   <br><br>
                                                                                   Before we go any further, please ensure that all the files have been uploaded, and that the
                                                                                   file 'config.php' has suitable permissions to allow this script to write to it ( 0666 should be sufficient ).
                                                                                   <br><br>
                                                                                   You will also need your SQL database name, your SQL username, your SQL password and SQL host (usually localhost).
                                                                                   <br><br>
                                                                                   Once you have clicked on proceed, you will be taken to a form to enter information the installer needs to set up your scripts.
                                                                           </td>
                                                                 </tr>
                                                                 <tr>
                                                                 <td align='center'>
                                                                 <b>EQRG License</b><p>

                                                                 <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"#000000\">
                                                                   <tr>
                                                                     <td>
                                                                 <iframe width=450 height=300 marginwidth=0 marginheight=0 framespacing=0 frameborder=0 scrolling=yes src=\"license.htm\"><script language=\"JavaScript\" src=\"license.htm\"></script></iframe>
                                                                     </td>
                                                                   </tr>
                                                                 </table>
                                                                 </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";

        // Check to make sure that the config file is there and it's got suitable permissions to write to:

        $file = $root."config.php";

        $warnings = array();

        if ( ! file_exists($file) )
        {
                $warnings[] = "Cannot locate the file 'config.php'. This should be uploaded into the same directory as this script!";
        }

        if ( ! is_writeable($file) )
        {
                $warnings[] = "Cannot write to 'config.php'. Please adjust the permissions to allow this script to write to the file. if in doubt, CHMOD via FTP to 0777";
        }

        $phpversion = phpversion();

        if ($phpversion < '4.1.1') {
                $warnings[] = "You cannot install EQRG. EQRG requires PHP Version 4.1.1 or better.";
        }

        if ( count($warnings) > 0 )
        {

                $err_string = "<ul><li>".implode( "<li>", $warnings )."</ul>";

                $template->contents .= "<tr>
                                                          <td id='warning'>WARNING!</td>
                                                        <tr>
                                                        <td>
                                                          <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                          <tr>
                                                                <td>
                                                          <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                           <tr>
                                                                <td>
                                                                 <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                                 <tr>
                                                                   <td>
                                                                                   <b>The following errors must be rectified before continuing!</b>
                                                                                   <br><br>
                                                                                   $err_string
                                                                           </td>
                                                                 </tr>
                                                                </table>
                                                          </td>
                                                         </tr>
                                                        </table>
                                                   </td>
                                                  </tr>
                                                 </table>";
        }
        else
        {
                $template->contents .= "<tr><td align='center' style='font-size:18px'><br><b><a href='install.php?a=1'>I Agree</a></b></td></tr>";
        }


        $template->output();
}



function install_error($msg="")
{
        global $std, $template, $root;

        $template->print_top('Warning!');



        $template->contents .= "<tr>
                                                  <td id='warning'>WARNING!</td>
                                                <tr>
                                                <td>
                                                  <table cellpadding='8' cellspacing='0' width='100%' align='center' border='0' id='tablewrap'>
                                                  <tr>
                                                        <td>
                                                  <table width='100%' cellspacing='1' cellpadding='0' align='center' border='0' id='table1'>
                                                   <tr>
                                                        <td>
                                                         <table width='100%' cellspacing='2' cellpadding='3' align='center' border='0'>
                                                         <tr>
                                                           <td>
                                                                        <b>The following errors must be rectified before continuing!</b><br>Please go back and try again!
                                                                        <br><br>
                                                                        $msg
                                                                </td>
                                                         </tr>
                                                        </table>
                                                  </td>
                                                 </tr>
                                                </table>
                                           </td>
                                          </tr>
                                         </table>";



        $template->output();
}

//+--------------------------------------------------------------------------
// CLASSES
//+--------------------------------------------------------------------------



class template
{
        var $contents = "";

        function output()
        {
                echo $this->contents;
                echo "</table>";
                echo "<p><center>\n";
                echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"425\">\n";
                echo "<tr>\n";
                echo "<td valign=\"middle\" align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"http://www.mysql.com\" target=\"_blank\"><img src=\"../images/mysql.gif\" width=\"90\" height=\"33\" alt=\"Powered By: MySQL\" border=\"0\"></td>\n";
                echo "<td valign=\"middle\" align=\"center\" bgcolor=\"#FFFFFF\"><font face=\"Arial\" size=\"1\" color=\"#000000\">EverQuest Tools Installer v1.0<br>Copyright &copy; 2002 EQRG Dev. Team.<br>All Rights Reserved.</font></td>\n";
                echo "<td valign=\"middle\" align=\"center\" bgcolor=\"#FFFFFF\"><a href=\"http://www.php.net\" target=\"_blank\"><img src=\"../images/php.gif\" width=\"90\" height=\"33\" alt=\"Powered By: PHP\" border=\"0\"></td>\n";
                echo "</tr>\n";
                echo "</table>\n";
                echo "</center>\n";
                exit();
        }

        //--------------------------------------

        function print_top($title="")
        {

                $this->contents = "<html>
                          <head><title>EverQuest Roster/Gallery Setup :: $title </title>
                          <style type='text/css'>
                                  TABLE, TR, TD     { font-family:Verdana, Arial;font-size: 11px; color:#333333 }
                                        BODY      { font: 11px Verdana; color:#333333 }
                                        a:link, a:visited, a:active  { color:#000055 }
                                        a:hover                      { color:#333377;text-decoration:underline }

                                        #title  { font-size:10px; font-weight:bold; line-height:150%; color:#FFFFFF; height: 24px; background-image: url(images/top_cell.gif); }
                                        #title  a:link, #title  a:visited, #title  a:active { text-decoration: underline; color : #FFFFFF; font-size:11px }

                                        #detail { font-family: Arial; font-size:11px; color: #333333 }

                                         #large { font-family: verdana, arial; font-size:20px; color:#4C77B6; font-weight:bold; letter-spacing:-1px }

                                        #subtitle { font-family: Verdana; font-size:22px; color:#4C77B6; font-weight:bold }

                                        #warning { font-family: Verdana; font-size:22px; color:#FF0000; font-weight:bold }

                                        #table1 {  background-color:#F1F1F1; width:100%; align:center; border:1px solid black }

                                        #tdrow1 { background-color:#F3F3EE }

                                        #tdrow2 { background-color:#EBEBE4 }

                                        #catrow  { font-size:10px; font-weight:bold; line-height:150%; color:#4C77B6; background-color:#C2CFDF; }

                                        #tablewrap {  border:1px dashed #777777; background-color:#EFEFEF }

                                        #copy { color:#555555; font-size:9px }

                                        #tdtop  { font-weight:bold; height:20px; line-height:150%; color:#FFFFFF; background-image: url(images/top_cell.gif); }

                                        #green    { background-color: #caf2d9 }
                                        #red      { background-color: #f5cdcd }

                                        #button   { background-color: #4C77B6; color: #FFFFFF; font-family:Verdana, Arial; font-size:11px }

                                        #textinput { background-color: #EEEEEE; color:Ê#000000; font-family:Verdana, Arial; font-size:10px; width:100% }

                                        #dropdown { background-color: #EEEEEE; color:Ê#000000; font-family:Verdana, Arial; font-size:10px }

                                        #multitext { background-color: #EEEEEE; color:Ê#000000; font-family:Courier, Verdana, Arial; font-size:10px }

                                  </style>
                                  </head>
                                 <body marginheight='0' marginwidth='0' leftmargin='0' topmargin='0' bgcolor='#FFFFFF'>

                                 <table width='100%' height='70' cellpadding='0' cellspacing='0' border='0'>
                                        <tr bgcolor='#4C77B6'>
                                                <td width='370' align='left' bgcolor='#4C77B6'><img src='../images/setup.gif' width='370' height='70'></td>
                                        </tr>
                                </table>
                                <br>
                                <table width='90%' cellpadding='0' cellspacing='0' border='0' align='center'>
                                 ";

        }


}


class installer
{

        function parse_incoming()
    {
            global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR;
            $return = array();

                if( is_array($HTTP_GET_VARS) )
                {
                        while( list($k, $v) = each($HTTP_GET_VARS) )
                        {
                                //$k = $this->clean_key($k);
                                if( is_array($HTTP_GET_VARS[$k]) )
                                {
                                        while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
                                        {
                                                $return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
                                        }
                                }
                                else
                                {
                                        $return[$k] = $this->clean_value($v);
                                }
                        }
                }

                // Overwrite GET data with post data

                if( is_array($HTTP_POST_VARS) )
                {
                        while( list($k, $v) = each($HTTP_POST_VARS) )
                        {
                                //$k = $this->clean_key($k);
                                if ( is_array($HTTP_POST_VARS[$k]) )
                                {
                                        while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
                                        {
                                                $return[$k][ $this->clean_key($k2) ] = $this->clean_value($v2);
                                        }
                                }
                                else
                                {
                                        $return[$k] = $this->clean_value($v);
                                }
                        }
                }

                return $return;
        }

    function clean_key($key) {

            if ($key == "")
            {
                    return "";
            }

            $key = preg_replace( "/\.\./"           , ""  , $key );
            $key = preg_replace( "/\_\_(.+?)\_\_/"  , ""  , $key );
            $key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key );
            return $key;
    }

    function clean_value($val) {

            if ($val == "")
            {
                    return "";
            }

            $val = preg_replace( "/&/"         , "&amp;"         , $val );
            $val = preg_replace( "/<!--/"      , "&#60;&#33;--"  , $val );
            $val = preg_replace( "/-->/"       , "--&#62;"       , $val );
            $val = preg_replace( "/<script/i"  , "&#60;script"   , $val );
            $val = preg_replace( "/>/"         , "&gt;"          , $val );
            $val = preg_replace( "/</"         , "&lt;"          , $val );
            $val = preg_replace( "/\"/"        , "&quot;"        , $val );
            $val = preg_replace( "/\|/"        , "&#124;"        , $val );
            $val = preg_replace( "/\n/"        , "<br>"          , $val ); // Convert literal newlines
            $val = preg_replace( "/\\\$/"      , "&#036;"        , $val );
            $val = preg_replace( "/\r/"        , ""              , $val ); // Remove literal carriage returns
            $val = preg_replace( "/!/"         , "&#33;"         , $val );
            $val = preg_replace( "/'/"         , "&#39;"         , $val ); // IMPORTANT: It helps to increase sql query safety.
            $val = stripslashes($val);                                     // Swop PHP added backslashes
            $val = preg_replace( "/\\\/"       , "&#092;"        , $val ); // Swop user inputted backslashes
            return $val;
    }

}



function get_sql()
{

$SQL = array();

$SQL[] = "CREATE TABLE bank (
  id int(11) NOT NULL default '0',
  plat bigint(8) NOT NULL default '0',
  gold bigint(8) NOT NULL default '0',
  silv bigint(8) NOT NULL default '0',
  copp bigint(8) NOT NULL default '0',
  weap text NOT NULL,
  armo text NOT NULL,
  spel text NOT NULL,
  misc text NOT NULL,
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";
$SQL[] = "INSERT INTO bank VALUES (1, 0, 0, 0, 0, '', '', '', '')";

$SQL[] = "CREATE TABLE char_stats (
  id int(11) NOT NULL default '0',
  hit_points smallint(6) NOT NULL default '1',
  armor_class smallint(6) NOT NULL default '1',
  attack smallint(6) NOT NULL default '1',
  strength smallint(6) NOT NULL default '0',
  stamina smallint(6) NOT NULL default '0',
  agility smallint(6) NOT NULL default '0',
  dexterity smallint(6) NOT NULL default '0',
  wisdom smallint(6) NOT NULL default '0',
  intelligence smallint(6) NOT NULL default '0',
  charisma smallint(6) NOT NULL default '0',
  poison smallint(6) NOT NULL default '0',
  magic smallint(6) NOT NULL default '0',
  disease smallint(6) NOT NULL default '0',
  fire smallint(6) NOT NULL default '0',
  cold smallint(6) NOT NULL default '0',
  alchemy smallint(6) NOT NULL default '0',
  baking smallint(6) NOT NULL default '0',
  brewing smallint(6) NOT NULL default '0',
  fishing smallint(6) NOT NULL default '0',
  fletching smallint(6) NOT NULL default '0',
  jewelcraft smallint(6) NOT NULL default '0',
  make_poison smallint(6) NOT NULL default '0',
  pottery smallint(6) NOT NULL default '0',
  smithing smallint(6) NOT NULL default '0',
  tailoring smallint(6) NOT NULL default '0',
  tinkering smallint(6) NOT NULL default '0',
  research smallint(6) NOT NULL default '0',
  PRIMARY KEY  (id),
  KEY id (id)
)";

$SQL[] = "CREATE TABLE chars (
  id int(11) NOT NULL auto_increment,
  owner int(11) NOT NULL default '0',
  born_on int(11) NOT NULL default '0',
  level smallint(6) NOT NULL default '0',
  status smallint(6) NOT NULL default '0',
  class smallint(6) NOT NULL default '0',
  race smallint(6) NOT NULL default '0',
  religion smallint(6) NOT NULL default '0',
  has_epic tinyint(4) NOT NULL default '0',
  valid tinyint(4) NOT NULL default '0',
  primary_char tinyint(4) NOT NULL default '0',
  name varchar(20) NOT NULL default '',
  surname varchar(40) NOT NULL default '',
  notes text NOT NULL,
  gender tinyint(4) NOT NULL default '0',
  piclink text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY status (status)
)";

$SQL[] = "CREATE TABLE equipment (
  id int(11) NOT NULL default '0',
  ear1 varchar(128) NOT NULL default '',
  neck varchar(128) NOT NULL default '',
  face varchar(128) NOT NULL default '',
  head varchar(128) NOT NULL default '',
  ear2 varchar(128) NOT NULL default '',
  finger1 varchar(128) NOT NULL default '',
  wrist1 varchar(128) NOT NULL default '',
  arms varchar(128) NOT NULL default '',
  hands varchar(128) NOT NULL default '',
  wrist2 varchar(128) NOT NULL default '',
  finger2 varchar(128) NOT NULL default '',
  shoulders varchar(128) NOT NULL default '',
  chest varchar(128) NOT NULL default '',
  back varchar(128) NOT NULL default '',
  waist varchar(128) NOT NULL default '',
  legs varchar(128) NOT NULL default '',
  feet varchar(128) NOT NULL default '',
  melee1 varchar(128) NOT NULL default '',
  melee2 varchar(128) NOT NULL default '',
  range varchar(128) NOT NULL default '',
  ammo varchar(128) NOT NULL default '',
  other text NOT NULL,
  zonekeys text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id)
)";

$SQL[] = "CREATE TABLE eventguest (
  egid int(11) NOT NULL auto_increment,
  eid int(11) NOT NULL default '0',
  unreg_password varchar(30) NOT NULL default '',
  name varchar(20) NOT NULL default '',
  surname varchar(40) NOT NULL default '',
  race smallint(6) NOT NULL default '0',
  class smallint(6) NOT NULL default '0',
  level smallint(6) NOT NULL default '0',
  PRIMARY KEY  (egid),
  KEY egid (egid)
)";

$SQL[] = "CREATE TABLE eventreg (
  eid int(11) NOT NULL default '0',
  owner tinyint(11) NOT NULL default '0',
  ologin varchar(20) NOT NULL default '',
  userchar smallint(6) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE events (
  id int(11) NOT NULL auto_increment,
  name varchar(40) NOT NULL default '',
  level1 smallint(6) NOT NULL default '0',
  level2 smallint(6) NOT NULL default '0',
  zone smallint(6) NOT NULL default '0',
  date int(11) NOT NULL default '0',
  description text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY zone (zone)
)";

$SQL[] = "CREATE TABLE images (
  id int(11) NOT NULL auto_increment,
  poster int(11) NOT NULL default '0',
  posted int(11) NOT NULL default '0',
  name varchar(128) NOT NULL default '',
  comment text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY poster (poster),
  KEY posted (posted)
)";

$SQL[] = "CREATE TABLE options (
  id int(11) NOT NULL default '0',
  wslink tinyint(4) NOT NULL default '0',
  wsadre varchar(255) NOT NULL default '',
  leaderimg tinyint(4) NOT NULL default '0',
  officerimg tinyint(4) NOT NULL default '0',
  epicimg tinyint(4) NOT NULL default '0',
  charview tinyint(4) NOT NULL default '0',
  gzipcom tinyint(4) NOT NULL default '0',
  aic1 varchar(7) NOT NULL default '',
  aic2 varchar(7) NOT NULL default '',
  atf text NOT NULL,
  ats tinyint(1) NOT NULL default '0',
  atc1 varchar(7) NOT NULL default '',
  atc2 varchar(7) NOT NULL default '',
  scriptw varchar(4) NOT NULL default '',
  tbc varchar(7) NOT NULL default '',
  thc varchar(7) NOT NULL default '',
  thtf text NOT NULL,
  thts tinyint(1) NOT NULL default '0',
  thtc varchar(7) NOT NULL default '',
  ticl varchar(7) NOT NULL default '',
  ttfl text NOT NULL,
  ttsl tinyint(1) NOT NULL default '0',
  ttcl varchar(7) NOT NULL default '',
  ticr varchar(7) NOT NULL default '',
  ttfr text NOT NULL,
  ttsr tinyint(1) NOT NULL default '0',
  ttcr varchar(7) NOT NULL default '',
  pntf text NOT NULL,
  pnts tinyint(1) NOT NULL default '0',
  pntc varchar(7) NOT NULL default '',
  tmf text NOT NULL,
  tms tinyint(1) NOT NULL default '0',
  tmc varchar(7) NOT NULL default '',
  nowi varchar(4) NOT NULL default '0',
  nbc varchar(7) NOT NULL default '',
  nbgc1 varchar(7) NOT NULL default '',
  nbgc2 varchar(7) NOT NULL default '',
  ntf text NOT NULL,
  nts tinyint(1) NOT NULL default '0',
  ntc varchar(7) NOT NULL default '',
  ntfa text NOT NULL,
  ntsa tinyint(1) NOT NULL default '0',
  ntca varchar(7) NOT NULL default '',
  disign tinyint(4) NOT NULL default '0',
  diros tinyint(4) NOT NULL default '0',
  digal tinyint(4) NOT NULL default '0',
  dibank tinyint(4) NOT NULL default '0',
  dieven tinyint(4) NOT NULL default '0',
  diaward tinyint(4) NOT NULL default '0',
  guestreg tinyint(4) NOT NULL default '0',
  gpass varchar(30) NOT NULL default '',
  guestpass varchar(30) NOT NULL default '',
  email varchar(255) NOT NULL default '',
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";
$SQL[] = "INSERT INTO options VALUES (1, 0, 'http://www.yoursite.com', 0, 0, 0, 1, 0, '#FFFFFF', '#AFC8E7', 'Arial', 1, '#000000', '#000000', '500', '#3870B0', '#80A8D8', 'Arial', 2, '#000000', '#80A8D8', 'Arial', 1, '#000000', '#AFC8E7', 'Arial', 1, '#000000', 'Arial', 2, '#000000', 'Arial', 2, '#000000', '400', '#3870B0', '#80A8D8', '#AFC8E7', 'Arial', 2, '#000000', 'Arial', 1, '#000000', 0, 0, 0, 0, 0, 0, 0, 'guildpass', 'pass', 'hide@address.com')";

$SQL[] = "CREATE TABLE privmsg (
  mid int(11) NOT NULL auto_increment,
  userid int(11) NOT NULL default '0',
  title varchar(40) NOT NULL default '',
  message text NOT NULL,
  date int(11) NOT NULL default '0',
  sender int(11) NOT NULL default '0',
  viewed tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (mid),
  KEY mid (mid)
)";

$SQL[] = "CREATE TABLE sessions (
  loginname varchar(20) NOT NULL default '',
  userid int(11) NOT NULL default '0',
  session_id varchar(32) NOT NULL default ''
)";

$SQL[] = "CREATE TABLE stats (
  sid int(11) NOT NULL default '0',
  lastmem varchar(20) NOT NULL default '',
  mostdate int(11) NOT NULL default '0',
  mostcunt int(11) NOT NULL default '0',
  PRIMARY KEY  (sid),
  KEY id (sid)
)";
$SQL[] = "INSERT INTO stats VALUES (1, '', 0, 0)";

$SQL[] = "CREATE TABLE users (
  id int(11) NOT NULL auto_increment,
  level smallint(6) NOT NULL default '0',
  timezone smallint(6) NOT NULL default '0',
  update_time int(11) NOT NULL default '0',
  login varchar(20) NOT NULL default '',
  passwd varchar(20) NOT NULL default '',
  email varchar(255) NOT NULL default '',
  sort1 varchar(10) NOT NULL default 'status',
  sort2 varchar(10) NOT NULL default 'class',
  sort3 varchar(10) NOT NULL default 'name',
  realname varchar(150) NOT NULL default '',
  websiteurl varchar(150) NOT NULL default '',
  icquni varchar(15) NOT NULL default '',
  yahooid varchar(100) NOT NULL default '',
  msnuid varchar(100) NOT NULL default '',
  aimuid varchar(100) NOT NULL default '',
  location varchar(150) NOT NULL default '',
  occupation varchar(150) NOT NULL default '',
  skills varchar(255) NOT NULL default '',
  intrests varchar(255) NOT NULL default '',
  biography text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY login (login)
)";

$SQL[] = "CREATE TABLE zones (
  zid int(11) NOT NULL auto_increment,
  zname varchar(255) NOT NULL default '',
  descrip text NOT NULL,
  PRIMARY KEY  (zid),
  KEY id (zid),
  KEY zname (zname)
)";

return $SQL;
}

function get_sqlu15b1()
{

$SQL = array();

$SQL[] = "ALTER TABLE chars ADD gender TINYINT (4) DEFAULT '0' not null";
$SQL[] = "ALTER TABLE equipment ADD zonekeys TEXT DEFAULT '' not null";
$SQL[] = "ALTER TABLE char_stats ADD research SMALLINT(6) NOT NULL";
$SQL[] = "ALTER TABLE users ADD realname varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD websiteurl varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD icquni varchar(15) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD yahooid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD msnuid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD aimuid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD location varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD occupation varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD skills varchar(255) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD intrests varchar(255) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD biography text NOT NULL";

$SQL[] = "CREATE TABLE options (
  id int(11) NOT NULL default '0',
  wslink tinyint(4) NOT NULL default '0',
  wsadre varchar(255) NOT NULL default '',
  leaderimg tinyint(4) NOT NULL default '0',
  officerimg tinyint(4) NOT NULL default '0',
  epicimg tinyint(4) NOT NULL default '0',
  charview tinyint(4) NOT NULL default '0',
  gzipcom tinyint(4) NOT NULL default '0',
  aic1 varchar(7) NOT NULL default '',
  aic2 varchar(7) NOT NULL default '',
  atf text NOT NULL,
  ats tinyint(1) NOT NULL default '0',
  atc1 varchar(7) NOT NULL default '',
  atc2 varchar(7) NOT NULL default '',
  scriptw varchar(4) NOT NULL default '',
  tbc varchar(7) NOT NULL default '',
  thc varchar(7) NOT NULL default '',
  thtf text NOT NULL,
  thts tinyint(1) NOT NULL default '0',
  thtc varchar(7) NOT NULL default '',
  ticl varchar(7) NOT NULL default '',
  ttfl text NOT NULL,
  ttsl tinyint(1) NOT NULL default '0',
  ttcl varchar(7) NOT NULL default '',
  ticr varchar(7) NOT NULL default '',
  ttfr text NOT NULL,
  ttsr tinyint(1) NOT NULL default '0',
  ttcr varchar(7) NOT NULL default '',
  pntf text NOT NULL,
  pnts tinyint(1) NOT NULL default '0',
  pntc varchar(7) NOT NULL default '',
  tmf text NOT NULL,
  tms tinyint(1) NOT NULL default '0',
  tmc varchar(7) NOT NULL default '',
  nowi varchar(4) NOT NULL default '0',
  nbc varchar(7) NOT NULL default '',
  nbgc1 varchar(7) NOT NULL default '',
  nbgc2 varchar(7) NOT NULL default '',
  ntf text NOT NULL,
  nts tinyint(1) NOT NULL default '0',
  ntc varchar(7) NOT NULL default '',
  ntfa text NOT NULL,
  ntsa tinyint(1) NOT NULL default '0',
  ntca varchar(7) NOT NULL default '',
  disign tinyint(4) NOT NULL default '0',
  diros tinyint(4) NOT NULL default '0',
  digal tinyint(4) NOT NULL default '0',
  dibank tinyint(4) NOT NULL default '0',
  dieven tinyint(4) NOT NULL default '0',
  email varchar(255) NOT NULL default '',
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";

$SQL[] = "INSERT INTO options VALUES (1, 0, 'http://www.yoursite.com', 0, 0, 0, 1, 0, '#FFFFFF', '#AFC8E7', 'Arial', 1, '#000000', '#000000', '500', '#3870B0', '#80A8D8', 'Arial', 2, '#000000', '#80A8D8', 'Arial', 1, '#000000', '#AFC8E7', 'Arial', 1, '#000000', 'Arial', 2, '#000000', 'Arial', 2, '#000000', '400', '#3870B0', '#80A8D8', '#AFC8E7', 'Arial', 2, '#000000', 'Arial', 1, '#000000', 0, 0, 0, 0, 0, 'hide@address.com')";

$SQL[] = "CREATE TABLE events (
  id int(11) NOT NULL auto_increment,
  name varchar(40) NOT NULL default '',
  level1 smallint(6) NOT NULL default '0',
  level2 smallint(6) NOT NULL default '0',
  zone smallint(6) NOT NULL default '0',
  date int(11) NOT NULL default '0',
  description text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY zone (zone)
)";

$SQL[] = "CREATE TABLE bank (
  id int(11) NOT NULL default '0',
  plat bigint(8) NOT NULL default '0',
  gold bigint(8) NOT NULL default '0',
  silv bigint(8) NOT NULL default '0',
  copp bigint(8) NOT NULL default '0',
  weap text NOT NULL,
  armo text NOT NULL,
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";

$SQL[] = "INSERT INTO bank VALUES (1, 0, 0, 0, 0, '', '')";

$SQL[] = "CREATE TABLE eventreg (
  eid int(11) NOT NULL default '0',
  owner tinyint(11) NOT NULL default '0',
  ologin varchar(20) NOT NULL default '',
  userchar smallint(6) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE sessions (
  loginname varchar(20) NOT NULL default '',
  userid int(11) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE stats (
  sid int(11) NOT NULL default '0',
  lastmem varchar(20) NOT NULL default '',
  mostdate int(11) NOT NULL default '0',
  mostcunt int(11) NOT NULL default '0',
  PRIMARY KEY  (sid),
  KEY id (sid)
)";

$SQL[] = "CREATE TABLE zones (
  zid int(11) NOT NULL auto_increment,
  zname varchar(255) NOT NULL default '',
  descrip text NOT NULL,
  PRIMARY KEY  (zid),
  KEY id (zid),
  KEY zname (zname)
)";

$SQL[] = "INSERT INTO stats VALUES (1, '', 0, 0)";

return $SQL;
}

function get_sqlu15()
{

$SQL = array();

$SQL[] = "ALTER TABLE char_stats ADD research SMALLINT(6) NOT NULL";
$SQL[] = "ALTER TABLE users ADD realname varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD websiteurl varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD icquni varchar(15) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD yahooid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD msnuid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD aimuid varchar(100) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD location varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD occupation varchar(150) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD skills varchar(255) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD intrests varchar(255) NOT NULL default ''";
$SQL[] = "ALTER TABLE users ADD biography text NOT NULL";

$SQL[] = "CREATE TABLE options (
  id int(11) NOT NULL default '0',
  wslink tinyint(4) NOT NULL default '0',
  wsadre varchar(255) NOT NULL default '',
  leaderimg tinyint(4) NOT NULL default '0',
  officerimg tinyint(4) NOT NULL default '0',
  epicimg tinyint(4) NOT NULL default '0',
  charview tinyint(4) NOT NULL default '0',
  gzipcom tinyint(4) NOT NULL default '0',
  aic1 varchar(7) NOT NULL default '',
  aic2 varchar(7) NOT NULL default '',
  atf text NOT NULL,
  ats tinyint(1) NOT NULL default '0',
  atc1 varchar(7) NOT NULL default '',
  atc2 varchar(7) NOT NULL default '',
  scriptw varchar(4) NOT NULL default '',
  tbc varchar(7) NOT NULL default '',
  thc varchar(7) NOT NULL default '',
  thtf text NOT NULL,
  thts tinyint(1) NOT NULL default '0',
  thtc varchar(7) NOT NULL default '',
  ticl varchar(7) NOT NULL default '',
  ttfl text NOT NULL,
  ttsl tinyint(1) NOT NULL default '0',
  ttcl varchar(7) NOT NULL default '',
  ticr varchar(7) NOT NULL default '',
  ttfr text NOT NULL,
  ttsr tinyint(1) NOT NULL default '0',
  ttcr varchar(7) NOT NULL default '',
  pntf text NOT NULL,
  pnts tinyint(1) NOT NULL default '0',
  pntc varchar(7) NOT NULL default '',
  tmf text NOT NULL,
  tms tinyint(1) NOT NULL default '0',
  tmc varchar(7) NOT NULL default '',
  nowi varchar(4) NOT NULL default '0',
  nbc varchar(7) NOT NULL default '',
  nbgc1 varchar(7) NOT NULL default '',
  nbgc2 varchar(7) NOT NULL default '',
  ntf text NOT NULL,
  nts tinyint(1) NOT NULL default '0',
  ntc varchar(7) NOT NULL default '',
  ntfa text NOT NULL,
  ntsa tinyint(1) NOT NULL default '0',
  ntca varchar(7) NOT NULL default '',
  disign tinyint(4) NOT NULL default '0',
  diros tinyint(4) NOT NULL default '0',
  digal tinyint(4) NOT NULL default '0',
  dibank tinyint(4) NOT NULL default '0',
  dieven tinyint(4) NOT NULL default '0',
  email varchar(255) NOT NULL default '',
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";

$SQL[] = "INSERT INTO options VALUES (1, 0, 'http://www.yoursite.com', 0, 0, 0, 1, 0, '#FFFFFF', '#AFC8E7', 'Arial', 1, '#000000', '#000000', '500', '#3870B0', '#80A8D8', 'Arial', 2, '#000000', '#80A8D8', 'Arial', 1, '#000000', '#AFC8E7', 'Arial', 1, '#000000', 'Arial', 2, '#000000', 'Arial', 2, '#000000', '400', '#3870B0', '#80A8D8', '#AFC8E7', 'Arial', 2, '#000000', 'Arial', 1, '#000000', 0, 0, 0, 0, 0, 'hide@address.com')";

$SQL[] = "CREATE TABLE events (
  id int(11) NOT NULL auto_increment,
  name varchar(40) NOT NULL default '',
  level1 smallint(6) NOT NULL default '0',
  level2 smallint(6) NOT NULL default '0',
  zone smallint(6) NOT NULL default '0',
  date int(11) NOT NULL default '0',
  description text NOT NULL,
  PRIMARY KEY  (id),
  KEY id (id),
  KEY zone (zone)
)";

$SQL[] = "CREATE TABLE bank (
  id int(11) NOT NULL default '0',
  plat bigint(8) NOT NULL default '0',
  gold bigint(8) NOT NULL default '0',
  silv bigint(8) NOT NULL default '0',
  copp bigint(8) NOT NULL default '0',
  weap text NOT NULL,
  armo text NOT NULL,
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
)";

$SQL[] = "INSERT INTO bank VALUES (1, 0, 0, 0, 0, '', '')";

$SQL[] = "CREATE TABLE eventreg (
  eid int(11) NOT NULL default '0',
  owner tinyint(11) NOT NULL default '0',
  ologin varchar(20) NOT NULL default '',
  userchar smallint(6) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE sessions (
  loginname varchar(20) NOT NULL default '',
  userid int(11) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE stats (
  sid int(11) NOT NULL default '0',
  lastmem varchar(20) NOT NULL default '',
  mostdate int(11) NOT NULL default '0',
  mostcunt int(11) NOT NULL default '0',
  PRIMARY KEY  (sid),
  KEY id (sid)
)";

$SQL[] = "CREATE TABLE zones (
  zid int(11) NOT NULL auto_increment,
  zname varchar(255) NOT NULL default '',
  descrip text NOT NULL,
  PRIMARY KEY  (zid),
  KEY id (zid),
  KEY zname (zname)
)";

$SQL[] = "INSERT INTO stats VALUES (1, '', 0, 0)";

return $SQL;
}

function get_sqlu16()
{

$SQL = array();

$SQL[] = "ALTER TABLE char_stats ADD research SMALLINT(6) NOT NULL";

$SQL[] = "ALTER TABLE events ADD level1 SMALLINT(6) NOT NULL";
$SQL[] = "ALTER TABLE events ADD level2 SMALLINT(6) NOT NULL";
$SQL[] = "ALTER TABLE events DROP level";
$SQL[] = "ALTER TABLE options DROP barcolor";
$SQL[] = "ALTER TABLE options DROP bartcolor";
$SQL[] = "ALTER TABLE options DROP altcolor1";
$SQL[] = "ALTER TABLE options DROP altcolor2";
$SQL[] = "ALTER TABLE options DROP tbcolor";
$SQL[] = "ALTER TABLE options DROP ticolor";
$SQL[] = "ALTER TABLE options DROP titcolor";
$SQL[] = "ALTER TABLE options DROP noteb";
$SQL[] = "ALTER TABLE options DROP notebg";
$SQL[] = "ALTER TABLE options DROP notet";
$SQL[] = "ALTER TABLE options DROP notehr";
$SQL[] = "ALTER TABLE options DROP tablewid";
$SQL[] = "ALTER TABLE options ADD wslink tinyint(4) DEFAULT '0' NOT NULL AFTER id";
$SQL[] = "ALTER TABLE options ADD wsadre varchar(255) NOT NULL AFTER wslink";
$SQL[] = "ALTER TABLE options ADD aic1 varchar(7) NOT NULL AFTER gzipcom";
$SQL[] = "ALTER TABLE options ADD aic2 varchar(7) NOT NULL AFTER aic1";
$SQL[] = "ALTER TABLE options ADD atf text NOT NULL AFTER aic2";
$SQL[] = "ALTER TABLE options ADD ats tinyint(1) DEFAULT '0' NOT NULL AFTER atf";
$SQL[] = "ALTER TABLE options ADD atc1 varchar(7) NOT NULL AFTER ats";
$SQL[] = "ALTER TABLE options ADD atc2 varchar(7) NOT NULL AFTER atc1";
$SQL[] = "ALTER TABLE options ADD scriptw varchar(4) NOT NULL AFTER atc2";
$SQL[] = "ALTER TABLE options ADD tbc varchar(7) NOT NULL AFTER scriptw";
$SQL[] = "ALTER TABLE options ADD thc varchar(7) NOT NULL AFTER tbc";
$SQL[] = "ALTER TABLE options ADD thtf text NOT NULL AFTER thc";
$SQL[] = "ALTER TABLE options ADD thts tinyint(1) DEFAULT '0' NOT NULL AFTER thtf";
$SQL[] = "ALTER TABLE options ADD thtc varchar(7) NOT NULL AFTER thts";
$SQL[] = "ALTER TABLE options ADD ticl varchar(7) NOT NULL AFTER thtc";
$SQL[] = "ALTER TABLE options ADD ttfl text NOT NULL AFTER ticl";
$SQL[] = "ALTER TABLE options ADD ttsl tinyint(1) DEFAULT '0' NOT NULL AFTER ttfl";
$SQL[] = "ALTER TABLE options ADD ttcl varchar(7) NOT NULL AFTER ttsl";
$SQL[] = "ALTER TABLE options ADD ticr varchar(7) NOT NULL AFTER ttcl";
$SQL[] = "ALTER TABLE options ADD ttfr text NOT NULL AFTER ticr";
$SQL[] = "ALTER TABLE options ADD ttsr tinyint(1) DEFAULT '0' NOT NULL AFTER ttfr";
$SQL[] = "ALTER TABLE options ADD ttcr varchar(7) NOT NULL AFTER ttsr";
$SQL[] = "ALTER TABLE options ADD pntf text NOT NULL AFTER ttcr";
$SQL[] = "ALTER TABLE options ADD pnts tinyint(1) DEFAULT '0' NOT NULL AFTER pntf";
$SQL[] = "ALTER TABLE options ADD pntc varchar(7) NOT NULL AFTER pnts";
$SQL[] = "ALTER TABLE options ADD tmf text NOT NULL AFTER pntc";
$SQL[] = "ALTER TABLE options ADD tms tinyint(1) DEFAULT '0' NOT NULL AFTER tmf";
$SQL[] = "ALTER TABLE options ADD tmc varchar(7) NOT NULL AFTER tms";
$SQL[] = "ALTER TABLE options ADD nowi varchar(4) DEFAULT '0' NOT NULL AFTER tmc";
$SQL[] = "ALTER TABLE options ADD nbc varchar(7) NOT NULL AFTER nowi";
$SQL[] = "ALTER TABLE options ADD nbgc1 varchar(7) NOT NULL AFTER nbc";
$SQL[] = "ALTER TABLE options ADD nbgc2 varchar(7) NOT NULL AFTER nbgc1";
$SQL[] = "ALTER TABLE options ADD ntf text NOT NULL AFTER nbgc2";
$SQL[] = "ALTER TABLE options ADD nts tinyint(1) DEFAULT '0' NOT NULL AFTER ntf";
$SQL[] = "ALTER TABLE options ADD ntc varchar(7) NOT NULL AFTER nts";
$SQL[] = "ALTER TABLE options ADD ntfa text NOT NULL AFTER ntc";
$SQL[] = "ALTER TABLE options ADD ntsa tinyint(1) DEFAULT '0' NOT NULL AFTER ntfa";
$SQL[] = "ALTER TABLE options ADD ntca varchar(7) NOT NULL AFTER ntsa";
$SQL[] = "DELETE FROM options";

$SQL[] = "CREATE TABLE eventreg (
  eid int(11) NOT NULL default '0',
  owner tinyint(11) NOT NULL default '0',
  ologin varchar(20) NOT NULL default '',
  userchar smallint(6) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE sessions (
  loginname varchar(20) NOT NULL default '',
  userid int(11) NOT NULL default '0'
)";

$SQL[] = "CREATE TABLE stats (
  sid int(11) NOT NULL default '0',
  lastmem varchar(20) NOT NULL default '',
  mostdate int(11) NOT NULL default '0',
  mostcunt int(11) NOT NULL default '0',
  PRIMARY KEY  (sid),
  KEY id (sid)
)";

$SQL[] = "CREATE TABLE zones (
  zid int(11) NOT NULL auto_increment,
  zname varchar(255) NOT NULL default '',
  descrip text NOT NULL,
  PRIMARY KEY  (zid),
  KEY id (zid),
  KEY zname (zname)
)";

$SQL[] = "INSERT INTO stats VALUES (1, '', 0, 0)";
$SQL[] = "INSERT INTO options VALUES (1, 0, 'http://www.yourdomain.com', 0, 0, 0, 1, 0, '#FFFFFF', '#AFC8E7', 'Arial', 1, '#000000', '#000000', '500', '#3870B0', '#80A8D8', 'Arial', 2, '#000000', '#80A8D8', 'Arial', 1, '#000000', '#AFC8E7', 'Arial', 1, '#000000', 'Arial', 2, '#000000', 'Arial', 2, '#000000', '400', '#3870B0', '#80A8D8', '#AFC8E7', 'Arial', 2, '#000000', 'Arial', 1, '#000000', 0, 0, 0, 0, 0, 'hide@address.com')";

return $SQL;
}

function get_sqlu17b1()
{

$SQL = array();

$SQL[] = "ALTER TABLE bank ADD spel TEXT NOT NULL";
$SQL[] = "ALTER TABLE bank ADD misc TEXT NOT NULL";
$SQL[] = "ALTER TABLE chars ADD piclink TEXT NOT NULL";

$SQL[] = "CREATE TABLE eventguest (
  egid int(11) NOT NULL auto_increment,
  eid int(11) NOT NULL default '0',
  unreg_password varchar(30) NOT NULL default '',
  name varchar(20) NOT NULL default '',
  surname varchar(40) NOT NULL default '',
  race smallint(6) NOT NULL default '0',
  class smallint(6) NOT NULL default '0',
  level smallint(6) NOT NULL default '0',
  PRIMARY KEY  (egid),
  KEY egid (egid)
)";

$SQL[] = "ALTER TABLE options ADD diaward TINYINT(4) NOT NULL AFTER dieven";
$SQL[] = "ALTER TABLE options ADD guestreg TINYINT(4) NOT NULL AFTER diaward";
$SQL[] = "ALTER TABLE options ADD gpass VARCHAR(30) NOT NULL AFTER guestreg";
$SQL[] = "ALTER TABLE options ADD guestpass VARCHAR(30) NOT NULL AFTER gpass";

return $SQL;
}

?>
Return current item: EverQuest Roster/Gallery