Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #########################################################
- # Version 1.01 Alpha Dev #
- #########################################################
- require_once (dirname(__FILE__) . '/includes/load.inc.php');
- require_once (dirname(__FILE__) . '/includes/language/install.english.php');
- $install = new Load;
- //$install->loadSettings();
- //$install->loadInstall();
- global $txt;
- //Run check to make sure the values for the connection have been entered into the form below
- if (isset($_POST['db_hostname']) && isset($_POST['db_name']) && isset($_POST['db_username']) && isset($_POST['db_passwd'])) {
- //assign form values from $_POST array into vars for use with the connetion
- $db_host = $_POST['db_hostname'];
- $db_name = $_POST['db_name'];
- $db_passwd = $_POST['db_passwd'];
- $db_username = $_POST['db_username'];
- $db_prefix = $_POST['db_prefix'];
- $siteName = $_POST['site_name'];
- $site_email = $_POST['site_email'];
- if (file_exists(dirname(__FILE__) . '/settings.inc.php') && isset($db_host) && isset($db_name) && isset($db_passwd) && isset($db_username) && isset($siteName) && isset($site_email)) {
- $settingsFile = dirname(__FILE__) . '/settings.inc.php';
- $fileName = 'settings.inc.php';
- //Open the file for writing the code into the file
- $fhandle = @fopen($settingsFile, 'r+');
- //Read the tmpl code from the file and assign it into a var
- $defaultsettings = file_get_contents(dirname(__FILE__) . '/includes/settings_default.inc.php');
- $defaultsettings .= "\n" . 'define' . '(' . "'SITE_NAME'," . "'$siteName'" . ')' . ';';
- $defaultsettings .= "\n" . '$site_email =' . "'$site_email'" . ';';
- $defaultsettings .= "\n" . '$db_host = ' . "'$db_host'" . ';';
- $defaultsettings .= "\n" . '$db_name = ' . "'$db_name'" . ';';
- $defaultsettings .= "\n" . '$db_passwd = ' . "'$db_passwd'" . ';';
- $defaultsettings .= "\n" . '$db_username =' . "'$db_username'" . ';';
- $defaultsettings .= "\n" . '$db_prefix =' . "'$db_prefix'" . ';';
- $defaultsettings .= "\n" . '?>';
- //Write the tmpl code into the new file
- @fwrite($fhandle, $defaultsettings);
- //Close the file
- @fclose($fhandle);
- $setfilecreated = '<b><span style="color:green;">' . $fileName . ' ' . $txt['install_settingsfile_true'] . '</span></b><br />';
- } else {
- $error = $txt['install_error_settingsfile_false'];
- }
- //Establish a connection with MySQL and select the db we want to install into
- $conn = mysql_connect($db_host, $db_username, $db_passwd) or die($txt['install_error_no_connection']);
- mysql_select_db($db_name, $conn) or die($txt['install_error_cant_open_db']);
- //Setup the query to create the images table
- $sql = "CREATE TABLE IF NOT EXISTS `images` (
- `image_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `filename` varchar(25) NOT NULL,
- `caption` varchar(120) NOT NULL,
- PRIMARY KEY (`image_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
- //Create table
- $result = mysql_query($sql);
- //Setup the MySQL for the users table
- $createUser = "CREATE TABLE IF NOT EXISTS `users` (
- `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `group_id` tinyint(1) unsigned NOT NULL,
- `email` varchar(255) NOT NULL,
- `username` varchar(15) NOT NULL,
- `salt` int(10) unsigned NOT NULL,
- `pwd` varchar(40) NOT NULL,
- PRIMARY KEY (`user_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
- //Create the users table
- $result = mysql_query($createUser);
- // Create default admin user
- $adminUser = "INSERT INTO `users` (`user_id`, `group_id`, `username`, `email`, `salt`, `pwd`) VALUES
- (1, 1, 'Administrator', '$site_email', 1270334552, '7002fa53e21192b35586675c08694e0bc7f530ae')";
- $insertAdminUser = mysql_query($adminUser);
- //Setup the query to create the catgories table
- $createCats = "CREATE TABLE IF NOT EXISTS `categories` (
- `cat_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `category` varchar(20) NOT NULL,
- PRIMARY KEY (`cat_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6";
- $result = mysql_query($createCats);
- //Insert the default values for the catgories
- $catDefaults = "INSERT INTO `categories` (`cat_id`, `category`) VALUES
- (1, 'Personal'),
- (2, 'Friends'),
- (3, 'Family'),
- (4, 'Holidays'),
- (5, 'Misc')";
- //Run the insert
- $insert = mysql_query($catDefaults);
- //Cat image lookup table
- $catLookup = "CREATE TABLE IF NOT EXISTS `image_cat_lookup` (
- `image_id` int(10) unsigned NOT NULL,
- `cat_id` int(10) unsigned NOT NULL,
- PRIMARY KEY (`image_id`,`cat_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
- $addCatLookup = mysql_query($catLookup);
- //Journal table
- $journal = "CREATE TABLE IF NOT EXISTS `journal` (
- `article_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `image_id` int(10) unsigned DEFAULT NULL,
- `title` varchar(255) NOT NULL,
- `article` text NOT NULL,
- `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
- PRIMARY KEY (`article_id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
- $addJournal = mysql_query($journal);
- //Pages table
- $PageTable = "CREATE TABLE IF NOT EXISTS `pages` (
- `page_id` int(5) unsigned NOT NULL AUTO_INCREMENT,
- `image_id` int(10) unsigned DEFAULT NULL,
- `page_name` varchar(20) NOT NULL,
- `page_content` longtext NOT NULL,
- PRIMARY KEY (`page_id`),
- UNIQUE KEY `page_name` (`page_name`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
- //Add the pages table
- $addPages = mysql_query($PageTable);
- //Add the default pages that we need and must be there
- // $defaultPages = "INSERT INTO `pages` (`page_name`, `page_content`)
- // VALUES ('amanda', 'This page is dedicated by name to the woman that inspires me to much greater things than I could ever achieve alone. Amanda, I love you today and always.',
- // 'index', 'This is the default Home page and you can edit this content in the admin area',
- // 'contact', 'This is the default text for the contact page and it can be edited in the admin area',
- // 'journal', '',
- // 'gallery' , '')";
- // $addDefaultPages = mysql_query($defaultPages);
- //Settings Table
- $settingsTable = "CREATE TABLE IF NOT EXISTS `settings` (
- `variable` varchar(255) NOT NULL default '',
- `value` text NOT NULL,
- PRIMARY KEY (`variable`(30))
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
- //Add settings table
- $addSettings = mysql_query($settingsTable);
- //Default settings query
- $dsettings = "INSERT INTO `settings` (`variable`, `value`)
- VALUES ('site_email', '$site_email')";
- //Add settings to table
- $AddSettings = mysql_query($dsettings);
- }
- function check_for_smf($callback, $dir, $types = null, $recursive = false, $baseDir = '') {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- if ($file === '.' || $file === '..') {
- continue;
- }
- if (is_file($dir . $file)) {
- if (is_array($types)) {
- if (!in_array(strtolower(pathinfo($dir . $file, PATHINFO_EXTENSION)), $types, true)) {
- continue;
- }
- }
- $callback($baseDir . $file);
- }elseif($recursive && is_dir($dir . $file)) {
- dir_walk($callback, $dir . $file . DIRECTORY_SEPARATOR, $types, $recursive, $baseDir . $file . DIRECTORY_SEPARATOR);
- }
- }
- closedir($dh);
- }
- }
- ?>
- <form
- name="db_info"
- action=""
- method="POST"
- enctype="multipart/form-data"
- >
- <p><label for="site_name">Site Name:</label><br />
- <input
- type="text"
- name="site_name"
- value=""
- size="40"
- /><br />
- <p><label for="site_email">Site(webmaster) Email:</label><br />
- <input
- type="text"
- name="site_email"
- value=""
- size="40"
- /><br />
- <label for="db_hostname">Hostname:</label><br />
- <input
- type="text"
- name="db_hostname"
- value=""
- size="50"
- /><br />
- <label for="db_name">Database name: </label><br />
- <input
- type="text"
- name="db_name"
- value=""
- size="20"
- /><br />
- <label for="db_username">Database Username: </label><br />
- <input
- type="text"
- name="db_username"
- value=""
- size="20"
- /><br />
- <label for="db_passwd">Database Password: </label><br />
- <input
- type="password"
- name="db_passwd"
- value=""
- size="20"
- /><br />
- <label for="db_prefix">Database Prefix: </label><br />
- <input
- type="text"
- name="db_prefix"
- value=""
- size="10"
- /><br />
- <br />
- <input
- type="submit"
- name="install"
- value="Install"
- /></p>
- </form>
- <br />
- <?php
- //check_for_smf();
- if (@! $conn) {
- echo '<span style="font-wieght:bold; color:red;"><b>' . $txt['install_error_empty_form_fields'] . '</b></span>';
- exit();
- }
- $sql = "SHOW TABLES FROM $db_name";
- $result = mysql_query($sql);
- if (! $result) {
- echo $txt['install_error_no_list_tbl'];
- echo $txt['install_error_mysql_error'] . mysql_error();
- exit();
- }
- if (isset($error)) {
- echo $error;
- } else {
- echo $setfilecreated;
- }
- echo $txt['install_db_tbls_created'];
- $table = array();
- while ($row = mysql_fetch_row($result)) {
- $tables[] = $row[0];
- echo '<b>' . $txt['install_db_tbl_names'] . ' ' . $row[0] . '</b><br />';
- }
- mysql_free_result($result);
- foreach ($tables as $k => $v) {
- $table[] = $v;
- }
- //var_dump($table);
- if (isset($table[0]) && isset($table[1]) && isset($table[2]) && isset($table[3]) && isset($table[4]) && isset($table[5])) {
- echo '<br /><br /><span style="font-weight:bold; color:green;">' . $txt['install_db_population_true'] . '</span>';
- } else {
- echo '<br /><br /><span style="font-wieght:bold; color:red;">' . $txt['install_error_db_population_false'] . '</span>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement