Location: PHPKode > projects > Jarida > jarida_1.0/install/index.php
<?php

include("header.php");

if(($_POST['submit'] == "Proceed") OR ($_GET['sql']))
{
  require_once('../classes/class.db.cnx.mysql.php');
  $db = new dbCnxMysql($_SESSION['db_host'], $_SESSION['db_user'], $_SESSION['db_pass'], $_SESSION['db_name']);

  $init = $db->initialize();
  $template->assign('init', $init);
  if($_POST['submit'] == "Proceed")
    {
      $reader = fopen("../include/config.php", "r");
      $config_text = fread($reader, filesize("../include/config.php"));
      fclose($reader);

      $str_db_host = "\$db_host = \"" . $_SESSION['db_host'] . "\"";
      $str_db_name = "\$db_name = \"" . $_SESSION['db_name'] . "\"";
      $str_db_user = "\$db_user = \"" . $_SESSION['db_user'] . "\"";
      $str_db_pass = "\$db_pass = \"" . $_SESSION['db_pass'] . "\"";

      $config_text = str_replace('$db_host = ""', $str_db_host, $config_text);
      $config_text = str_replace('$db_name = ""', $str_db_name, $config_text);
      $config_text = str_replace('$db_user = ""', $str_db_user, $config_text);
      $config_text = str_replace('$db_pass = ""', $str_db_pass, $config_text);

      $writer = fopen("../include/config.php", "w");
      fwrite($writer, $config_text);
      fclose($writer);

    }


  if($_GET['sql'])
    {
      //Lets create the tables now
      //////////////////////////////////////////
      $query = "CREATE TABLE tblSmilie(
smilie_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
smilie_code VARCHAR(100) NOT NULL,
smilie_file VARCHAR(100) NOT NULL)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblCensor(
censor_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
censor_word VARCHAR(100) NOT NULL,
censor_replace VARCHAR(100) NOT NULL)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblPhoto(
photo_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
photo_title VARCHAR(255) NOT NULL,
photo_description TEXT,
photo_filename VARCHAR(100) NOT NULL)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblArticle(
article_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
article_title VARCHAR(255) NOT NULL,
article_date INT NOT NULL,
article_summary TEXT,
article_body TEXT,
article_views INT NOT NULL DEFAULT 0)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblPhotoComment(
comment_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
comment_photo_id INT NOT NULL,
comment_title VARCHAR(255) NOT NULL,
comment_date INT NOT NULL,
comment_body TEXT NOT NULL,
comment_name VARCHAR(100) NOT NULL,
comment_ip VARCHAR(15) NOT NULL,
comment_web VARCHAR(100))";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblArticleComment(
comment_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
comment_article_id INT NOT NULL,
comment_title VARCHAR(255) NOT NULL,
comment_date INT NOT NULL,
comment_body TEXT NOT NULL,
comment_name VARCHAR(100) NOT NULL,
comment_ip VARCHAR(15) NOT NULL,
comment_web VARCHAR(100))";


      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblConfig(
config_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
config_name VARCHAR(20) NOT NULL,
config_value VARCHAR(50) NOT NULL)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblArticlePhoto(
photo_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
photo_article_id INT NOT NULL,
photo_filename VARCHAR(100) NOT NULL)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblLink(
link_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
link_name VARCHAR(255) NOT NULL,
link_url VARCHAR(255) NOT NULL,
link_visits INT NOT NULL DEFAULT 0)";

      $result = $db->doQuery($query);

      $query = "CREATE TABLE tblBan(
ban_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
ban_ip VARCHAR(15) NOT NULL)";

      $result = $db->doQuery($query);


      //Now lets dump some defualt initial data
      ///////////////////////////////////////////////////

      $query = "INSERT INTO tblSmilie (smilie_code, smilie_file) VALUES
(':D','smilies/lol.gif'),
(':)','smilies/smile.gif'),
(';)','smilies/wink.gif'),
(':(','smilies/sad.gif'),
(':X','smilies/mad.gif'),
(':cry:','smilies/cry.gif'),
(':eek:','smilies/eek.gif'),
(':yes:','smilies/yes.gif'),
(':no:','smilies/no.gif'),
(':love:','smilies/love.gif'),
(':confused','smilies/confused.gif'),
(':giggle:','smilies/giggle.gif')";

      $result = $db->doQuery($query);

      $query = "INSERT INTO tblConfig (config_name, config_value) VALUES
('theme', 'default'),
('language','english'),
('num_articles',6),
('num_previous', 20),
('num_thumbs',8),
('pass',MD5('pass')),
('blog_name','My Blog')";

      $result = $db->doQuery($query);

    }
}

$writable = (is_writable("../include/config.php") AND is_writable("../img/upload") AND is_writable("../img/smilies"));
$template->assign('writable', $writable);

//Lets display the template
$template->display('./index.tpl');



include("footer.php");

?>
Return current item: Jarida