Location: PHPKode > projects > Bloggie Lite > install/install.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('IN_BLOGGIE', true);

$version = "0.0.2 Beta";

$bloggie_root_path = "../";
include_once($bloggie_root_path.'config.php');
//include_once($bloggie_root_path.'init.php');
include_once($bloggie_root_path.'includes/db.php');
//include_once($bloggie_root_path.'includes/functions.php');
//include_once($bloggie_root_path.'language/'.$language);

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

$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>BloggieLite <? 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;
    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>BloggieLite</span></a></div>

<?
if (!file_exists('../config.php'))
{
  $header = "Error : config.php is not found !<hr />";
  $message= "\"config.php\" needed for the installation was available. Unable to proceed further. <br /><br />
  <b>What do I need to do ?</b><br /><br />
  1. Create config.php manually before running the install.php.<br />
     &nbsp;&nbsp;&nbsp;- Please open config_bak.php ( BloggieLite root directory ) & fill-up relevant info<br />
     &nbsp;&nbsp;&nbsp;- Save it as config.php.<br />
     &nbsp;&nbsp;&nbsp;- Run install.php again <br />
     <br />
     OR
     <br /><br />
  2. Run the wizard.php to guide you<br />

";
  die_msg($header, $message);
}
else
{
if ($install_step =="0") {

$part = explode("/",$_SERVER['SCRIPT_NAME']) ;
$n = count($part);
$path ="";
for ($i=1; $i<$n-2; $i++ ) {
$path .="/".$part[$i] ;
 }
$installed_url= "http://" . $_SERVER['HTTP_HOST'] . $path ;

?>
<p>Admin Configuration<br /><br />
<p>Please enter administator's information</p><br /><br />

<form method="post"  action="install.php?install_step=1">
  <table>
    <tr>
      <td align="right">Administrator's User Name : </td>
      <td ><input type="text" name="admin_name"  value="" style="width:250px" /></td>
    </tr>
    <tr>
      <td align="right">Administrator's Password : </td>
      <td ><input type="password" name="admin_pass1" value='' style="width:250px" /></td>
    </tr>
    <tr>
      <td align="right">Reenter Password : </td>
      <td ><input type="password" name="admin_pass2" value='' style="width:250px" /></td>
    </tr>
    <tr>
      <td align="right">Time Zone ( GMT ) : </td>
      <td ><input type="text" name="gmt" value='' style="width:250px" /></td>
    </tr>
    <tr>
      <td align="right">Bloggie Lite's Installed URL :<br / ><span style="font-size:9px">( eg: <? echo $installed_url ?> )</span></td>
      <td ><input type="text" name="blog_url" value="<? echo $installed_url ?>"  style="width:250px" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center">
      <input name="submit" type="submit" value="Submit" /></td>
    </tr>
  </table>

<?
}
if(isset($_GET['install_step'])) $install_step = intval($_GET['install_step']);
else $install_step = 0;
switch($install_step) {
  case 1:

$admin_name = ( isset($_POST['admin_name']) ) ? htmlspecialchars($_POST['admin_name']) : "admin";
$admin_pass1 = ( isset($_POST['admin_pass1']) ) ? $_POST['admin_pass1'] : "pass";
$admin_pass2 = ( isset($_POST['admin_pass2']) ) ? $_POST['admin_pass2'] : "pass";
$gmt = ( isset($_POST['gmt']) ) ? $_POST['gmt'] : "0";
$blog_url = ( isset($_POST['blog_url']) ) ? $_POST['blog_url'] : "0";

if  ($admin_pass1 != $admin_pass2) {
  $header = "Error : Password not match !<hr />";
  $message= "Password entered do not match, Please press back button or click on this link <a href=\"install.php\">Link</a> <br /><br />";
  die_msg($header, $message);
}

$sql = "SELECT * from " . POST_TBL . ";" ;

  if( mysql_query($sql) )
   {
    $header = "Error : Tables Already Exist !<hr />";
    $message= "BloggieLite's tables detected, Looks like you have already installed BloggieLite... <br /><br />
    If you would like to reinstall please remove your old tables from mySQL database<br /><br />";
  die_msg($header, $message);
  } else {

    $sql = "CREATE TABLE ".COMMENT_TBL." (
  comment_id int(5) NOT NULL auto_increment,
  post_id int(5) NOT NULL default '0',
  comment_subject text NOT NULL,
  com_tstamp varchar(10) NOT NULL default '',
  user_id int(5) NOT NULL default '0',
  poster varchar(64) NOT NULL default '',
  email varchar(128) NOT NULL default '',
  home varchar(128) NOT NULL default '',
  comments text NOT NULL,
  comment_type enum('comment','linkback','trackback','pingback') NOT NULL default 'comment',
  approved enum('0','1') NOT NULL default '0',
  ip varchar(16) NOT NULL default '',
  PRIMARY KEY  (comment_id)
) TYPE=MyISAM;";

  if( !($result = $db->sql_query($sql)) )
   {
     $sql_error = $db->sql_error();
    echo $sql_error['message']."1";
   }
//   $result = $db->sql_query($sql) ;

   $sql = "CREATE TABLE ".POST_TBL." (
  post_id smallint(5) unsigned NOT NULL auto_increment,
  user_id varchar(4) NOT NULL default '',
  subject tinytext,
  perm_subj varchar(255) NOT NULL default '',
  message longtext,
  timestamp int(11) NOT NULL default '0',
  cat_id tinyint(2) NOT NULL default '0',
  allow_tb char(1) NOT NULL default '',
  allow_ping char(1) NOT NULL default '',
  allow_comments char(1) NOT NULL default '',
  comments_count int(3) NOT NULL default '0',
  post_status char(1) NOT NULL default '',
  PRIMARY KEY  (post_id)
) TYPE=MyISAM;" ;

  if( !($result = $db->sql_query($sql)) )
   {
     $sql_error = $db->sql_error();
    echo $sql_error['message']."2";
   }
//   $result = $db->sql_query($sql) ;

   $sql =
   "CREATE TABLE ".USER_TBL." (
  user varchar(64) NOT NULL default '',
  id tinyint(4) NOT NULL auto_increment,
  password varchar(32) NOT NULL default '',
  level tinyint(1) NOT NULL default '0',
  gravatar varchar(128) NOT NULL default '',
  session_time int(11) NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY id (id)
) TYPE=MyISAM;
  " ;

 if( !($result = $db->sql_query($sql)) )
 {
 $sql_error = $db->sql_error();
 echo $sql_error['message']."4";
 }

   $sql =
   "CREATE TABLE ".CAT_TBL." (
  cat_id tinyint(2) NOT NULL auto_increment,
  cat_desc varchar(64) NOT NULL default '',
  cat_perma varchar(64) NOT NULL default '',
  PRIMARY KEY  (cat_id)
) TYPE=MyISAM;";

 if( !($result = $db->sql_query($sql)) )
 {
 $sql_error = $db->sql_error();
 echo $sql_error['message']."5";
 }

   $sql =
   "CREATE TABLE ".SCODE_TBL." (
  cookie varchar(32) NOT NULL default '',
  scode varchar(5) NOT NULL default '',
  timestamp int(11) NOT NULL default '0'
) TYPE=MyISAM;";

 if( !($result = $db->sql_query($sql)) )
 {
 $sql_error = $db->sql_error();
 echo $sql_error['message']."6";
 }

   $sql =
   "CREATE TABLE ".PREF_TBL." (
  option_name varchar(255) NOT NULL default '',
  setting varchar(255) NOT NULL default ''
) TYPE=MyISAM;";

 if( !($result = $db->sql_query($sql)) )
 {
 $sql_error = $db->sql_error();
 echo $sql_error['message']."7";
 }
$timestamp = time();
$admin_pass = md5($admin_pass1);

$sql = "INSERT INTO ".POST_TBL." SET user_id='1', subject='Testing Message for BloggieLite',
        message='This is a test Message. You can delete this message after you logged in',
        perm_subj='testing-message-for-bloggielite', timestamp='$timestamp', cat_id='1'";
if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."8";
}

$sql = "INSERT INTO ".CAT_TBL." VALUES (1, 'General', 'general')";
if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."9";
}
$sql = "INSERT INTO ".USER_TBL." SET user='$admin_name', password='$admin_pass', level='1'";
if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."10";
}

$sql = "INSERT INTO ".USER_TBL." SET user='guest', level='0'";
if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."10a";
}

$sql = "UPDATE ".USER_TBL." SET id = '0' WHERE user='guest'" ;
if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."10c";
}

$sql ="INSERT INTO ".PREF_TBL."  (option_name, setting) VALUES
('blog_limit', '5'),
('recent_limit', '10'),
('archive_limit', '10'),
('default_style', 'mylite'),
('language', 'lang_eng.php'),
('bloggie_path', '$blog_url'),
('flood_interval', '120'),
('gmt', '$gmt'),
('email_notification', '1'),
('moderate_comment', '1'),
('email', ''),
('encoding', 'iso-8859-1'),
('reply_to', ''),
('email_name', 'Bloggie Lite'),
('enable_comment', '1'),
('comment_html_safe', '1'),
('version', '$version'),
('cookie_name', ''),
('blog_name', 'Bloggie Lite'),
('guest_gravatar', ''),
('post_html_safe', '1'),
('font_family', 'Verdana'),
('sef_method', 'yes'),
('plugins', 'a:2:{i:0;s:7:\"css.php\";i:1;s:8:\"link.php\";}'),
('link_format', 'index.php/{READ}/{YYYY}/{MM}/{DD}/{TITLE}');";

if( !($result = $db->sql_query($sql)) )
{
   $sql_error = $db->sql_error();
   echo $sql_error['message']."11";
}

?>
 <div class="status"><b>Create BloggieLite's Tables</b><hr /><br /><br />
  BloggieLite's Tables successfully created<br />
  BloggieLite's Data successfully inserted<br />
  Installation completed...Easy right?<br /><br />
  Please delete the install folder before start blogging for security reason<br /><br />
 <br />
 <br />
 </div>
 <center><div class="border"><a href="../index.php" class="link">Now Lets Blog</a></div></center>
 <br />
<?
 echo $footer;
 break;
// End create table


  }

  } //end switch
}

?>
Return current item: Bloggie Lite