Location: PHPKode > projects > Bloggie Lite > install/wizard.php
<?php

// Copyright (C) Bloggie Lite Written by : Sean
// http://www.mywebland.com , http://mybloggie.mywebland.com

// You are requested to retain this copyright notice in order to use
// this software.

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

define('BLOGGIE_INSTALL', true);
$version = "0.0.2 Beta";

$footer =
"<div id=\"credit\">
<a class=\"copyright\" href=\"http://BloggieLite.mywebland.com/index.php?mode=doc\">Documentation</a> | <a href=\"http://mywebland.com/forums/\">Support Forums</a> | <a href=\"http://www.mywebland.com\">myWebland</a><br/>
Powered by <a href=\"http://BloggieLite.mywebland.com\">Bloggie Lite ".$version."</a> &copy; 2004 2005 </span></div>";

function die_msg($header, $message) {
global $version, $footer;
die("<div class=\"message\"><b>".$header."</b><br><br>$message</div>".$footer."</body>
</html>");
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bloggie Lite <? echo $version ?> - Installation Wizard</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
    <!--
  body {
    font-family: verdana, Times, serif;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
  }

  .message {
    font-family: verdana, sans-serif; font-size: 11px; color: #006600;
    font-size : 11px;
    background-color: #fafafa; border: #D1D7DC; border-style: solid;
    border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px;
    padding-top : 15px;
    padding-right : 15px;
    padding-bottom : 15px;
    padding-left : 15px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
    text-align : left;
    }

  .status {
    font-family: new courier, courier ; font-size: 11px; color: #006600;
    font-size : 12px;
    background-color: #fafafa; border: #D1D7DC; border-style: solid;
    border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px;
    padding-top : 15px;
    padding-right : 15px;
    padding-bottom : 15px;
    padding-left : 15px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
    text-align : left;
    }

  #credit {
    text-align : center;
    font-family: verdana, sans-serif; font-size: 11px; color: #006600;
    font-size : 11px;
    color : #a0a0a0;
    }

p {
    font-family: verdana, sans-serif; font-size: 11px; color: #006600;
    font-size : 12px;
    color : #606060;
    }

td {
    font-family: verdana, sans-serif; font-size: 11px; color: #006600;
    font-size : 12px;
    color : #a0a0a0;
    }

  #header {
    margin: 0;
    padding: 0;
    color : #000000;
    background-image: url(http://BloggieLite.mywebland.com/templates/mylite/images/login_02.gif);
    background-repeat: no-repeat;
    height: 60px;
    border-bottom: 2px solid #999;
  }
  #header a {
    display: block;
    height: 60px;
  }
  #header a span {
    display: none;
  }

.link     { font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #006600;
             border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px;
             border: #D1D7DC; border-style: solid; padding : 3px;
}
a.link       { color: #006600; text-decoration: none;}
a.link:hover { color: #000000; text-decoration: underline;}

input,textarea,select {
  font-size: 12px;
  height : 18px;
  font-family: Verdana;
  border-style: solid;
  border-width: 1px;
  border-color: #aaaaaa;
  background: #efefef;
  border-width: 1px;
  margin: 2px;
}

    -->
  </style>

</head>
<body> 
<div id="header"><a href="http://BloggieLite.mywebland.com"><span>Bloggie Lite</span></a></div>

<?
if (file_exists('../config.php'))
{
  include ('../config.php') ;
  if (defined('INSTALLED')) {
  $header = "Error : config.php detected !<hr />";
  $message= "Unable to create 'config.php' as 'config.php' already exists. If you are planning to reinstall Bloggie Lite, please delete it first or You can may to <a href='install.php'>install</a> now.";
  die_msg($header, $message);
  }
//}else
//if (!file_exists('../config_temp.php'))
//{
//  $header = "Error : config_temp.php is missing !<hr />";
//  $message= "Creation of 'config.php' require config_temp.php";
//  die_msg($header, $message);
} elseif (!is_writable('../')) {
  $header = "Error : File write/directory protected !<hr />";
  $message= "Unable write to the file/directory. Please change the permission of Bloggie Lite file/directory";
}
//else { $config = file('../config_temp.php'); }

$install_step = 0;
if(isset($_GET['install_step'])) $install_step = intval($_GET['install_step']);


switch($install_step) {
  case 0:

?> 
<p><b>Thank you for using Bloggie Lite</b>.</p>
<p>You about to experience a wonderful blogging adventure with Bloggie Lite <? echo $version ?></p>

<div class="status"><b>Bloggie Lite Pre-installation Checks</b><hr /><br /><br />
1. "config.php" file not present&nbsp -> status : OK<br />
2. Directory is writable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;-> status : OK<br><br>
Pre-installation checks successfully completed you may proceed to the next step
<br />
<br />
</div>
<center><div class="border"><a href="wizard.php?install_step=1" class="link">Proceed to Step 1</a></div></center>
<br />
<?
echo $footer;
  break;

  case 1:
  ?>

<p>Installation Instruction for Bloggie Lite <? echo $version ?><br /><br />
<b>Step 1 : Database Configuration</b><br /><br />
Bloggie Lite is using mySQL database, as such to before the installation process, Bloggie Lite requires mySQL database information in order to access to the database.</p>
<p>Below you should enter your database connection details. If you're not sure about these, please contact your host. </p>
<form method="post"  action="wizard.php?install_step=2">
  <table>
    <tr>
      <td align="right">Database Host : </td>
      <td ><input type="text" name="db_host" value="localhost" /></td>
    </tr>
    <tr>
      <td align="right">Database Name : </td>
      <td ><input type="text" name="db_name" value="" /></td>
    </tr>
    <tr>
      <td align="right">Database user name : </td>
      <td ><input type="text" name="db_user" value='' /></td>
    </tr>
    <tr>
      <td align="right">Database Password : </td>
      <td ><input type="password" name="db_passwd" value='' /></td>
    </tr>
    <tr>
      <td align="right">Table_Prefix : </td>
      <td ><input type="text" name="table_prefix" value="<? echo (!empty($table_prefix)) ? $table_prefix : "bl_"; ?>" /></td>
    </tr>
    <tr>
    <!--tr>
      <td align="right">Time Zone (GMT) : </td>
      <td ><input type="text" name="timezone" value="" /></td>
    </tr-->
    <tr>
      <td colspan="2" align="right">
      <input name="submit" type="submit" value="Submit" /></td>
    </tr>
  </table>
              <!--input type="submit" value="Preview" name="preview" />
              <input type="submit" value="Submit" name="submit" /-->

</form> 
<?
  break;
  
  case 2:
   $dbms = isset($HTTP_POST_VARS['dbms']) ? $HTTP_POST_VARS['dbms'] : 'mysql';
   $dbhost = (!empty($HTTP_POST_VARS['db_host'])) ? $HTTP_POST_VARS['db_host'] : 'localhost';
   $dbuser = (!empty($HTTP_POST_VARS['db_user'])) ? $HTTP_POST_VARS['db_user'] : '';
   $dbpasswd = (!empty($HTTP_POST_VARS['db_passwd'])) ? $HTTP_POST_VARS['db_passwd'] : '';
   $dbname = (!empty($HTTP_POST_VARS['db_name'])) ? $HTTP_POST_VARS['db_name'] : '';
   $timezone = (!empty($HTTP_POST_VARS['timezone'])) ? $HTTP_POST_VARS['timezone'] : '';
   $table_prefix = (!empty($HTTP_POST_VARS['table_prefix'])) ? $HTTP_POST_VARS['table_prefix'] :'';

  if (empty($prefix)) $prefix = 'bl_';

    $config_data = '<?php'."\n\n";
    $config_data .= "\n// Bloggie Lite ".$version." config.php file\n// This file is auto generated , Please do not change anything in this file!\n\n";
    $config_data .= '$dbms = \'' . $dbms . '\';' . "\n\n";
    $config_data .= '$dbhost = \'' . $dbhost . '\';' . "\n";
    $config_data .= '$dbname = \'' . $dbname . '\';' . "\n";
    $config_data .= '$dbuser = \'' . $dbuser . '\';' . "\n";
    $config_data .= '$dbpasswd = \'' . $dbpasswd . '\';' . "\n\n";
    $config_data .= 'define(\'INSTALLED\',true );'."\n";
    $config_data .= '$table_prefix = \'' . $table_prefix . '\';' . "\n\n";
//    $config_data .= '$timezone = \'' . $timezone . '\';' . "\n\n";
    $config_data .= 'define(\'POST_TBL\', $table_prefix."posts" );'."\n";
    $config_data .= 'define(\'USER_TBL\', $table_prefix."user" );'."\n";
    $config_data .= 'define(\'CAT_TBL\', $table_prefix."category" );'."\n";
    $config_data .= 'define(\'COMMENT_TBL\', $table_prefix."comment" );'."\n";
    $config_data .= 'define(\'SCODE_TBL\', $table_prefix."scode" );'."\n";
    $config_data .= 'define(\'PREF_TBL\', $table_prefix."pref" );'."\n\n";
//    $config_data .= 'include(\'setting.php\');'."\n\n";
    $config_data .= '?' . '>'; //

  // Test connection
  if (!@mysql_connect($dbhost,$dbuser,$dbpasswd))
  {
     $header = "Error : Database Connection Failure !<hr />";
     $message= "Unable connect to database. Information provided is not correct. Please hit the back to check your database connection details again";
     die_msg($header, $message);
  }
//  elseif ( ) {


//  }
  else
  {
     if (!($fp = @fopen('../config.php', 'w')))
     {
        $header = "Error : File write/directory write protected !<hr />";
        $message= "Unable write to the file/directory. Please check the permission of file/directory";
        die_msg($header, $message);
     }
     else
     {
       $result = @fputs($fp, $config_data, strlen($config_data));
       //fwrite($fp, $config_data);
       fclose($fp);
       //chmod('../config.php', 0666);
?>
<div class="status"><b>Bloggie Lite - Create mySQL start-up file</b><hr /><br /><br />
1. Connection to mySQL&nbsp;&nbsp;&nbsp;&nbsp;-> status : OK<br>
2. Create config.php file -> status : OK<br><br>
Creation of config.php required for database connection successfully completed, You may proceed to the next step
<br />
<br />
</div>
<center><div class="border"><a href="install.php" class="link">Install now</a></div></center>
<br />

<?
     }
}
?>
<?php
  break;

}
?> 
</body>
</html>
Return current item: Bloggie Lite