· 9 years ago · May 28, 2017, 06:34 AM
1<?php
2#########################################################
3# Version 1.01 Alpha Dev #
4#########################################################
5require_once (dirname(__FILE__) . '/includes/load.inc.php');
6require_once (dirname(__FILE__) . '/includes/language/install.english.php');
7$install = new Load;
8//$install->loadSettings();
9//$install->loadInstall();
10global $txt;
11//Run check to make sure the values for the connection have been entered into the form below
12if (isset($_POST['db_hostname']) && isset($_POST['db_name']) && isset($_POST['db_username']) && isset($_POST['db_passwd'])) {
13//assign form values from $_POST array into vars for use with the connetion
14 $db_host = $_POST['db_hostname'];
15 $db_name = $_POST['db_name'];
16 $db_passwd = $_POST['db_passwd'];
17 $db_username = $_POST['db_username'];
18 $db_prefix = $_POST['db_prefix'];
19 $siteName = $_POST['site_name'];
20 $site_email = $_POST['site_email'];
21 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)) {
22 $settingsFile = dirname(__FILE__) . '/settings.inc.php';
23 $fileName = 'settings.inc.php';
24 //Open the file for writing the code into the file
25 $fhandle = @fopen($settingsFile, 'r+');
26 //Read the tmpl code from the file and assign it into a var
27 $defaultsettings = file_get_contents(dirname(__FILE__) . '/includes/settings_default.inc.php');
28 $defaultsettings .= "\n" . 'define' . '(' . "'SITE_NAME'," . "'$siteName'" . ')' . ';';
29 $defaultsettings .= "\n" . '$site_email =' . "'$site_email'" . ';';
30 $defaultsettings .= "\n" . '$db_host = ' . "'$db_host'" . ';';
31 $defaultsettings .= "\n" . '$db_name = ' . "'$db_name'" . ';';
32 $defaultsettings .= "\n" . '$db_passwd = ' . "'$db_passwd'" . ';';
33 $defaultsettings .= "\n" . '$db_username =' . "'$db_username'" . ';';
34 $defaultsettings .= "\n" . '$db_prefix =' . "'$db_prefix'" . ';';
35 $defaultsettings .= "\n" . '?>';
36 //Write the tmpl code into the new file
37 @fwrite($fhandle, $defaultsettings);
38 //Close the file
39 @fclose($fhandle);
40 $setfilecreated = '<b><span style="color:green;">' . $fileName . ' ' . $txt['install_settingsfile_true'] . '</span></b><br />';
41 } else {
42 $error = $txt['install_error_settingsfile_false'];
43 }
44 //Establish a connection with MySQL and select the db we want to install into
45 $conn = mysql_connect($db_host, $db_username, $db_passwd) or die($txt['install_error_no_connection']);
46 mysql_select_db($db_name, $conn) or die($txt['install_error_cant_open_db']);
47 //Setup the query to create the images table
48 $sql = "CREATE TABLE IF NOT EXISTS `images` (
49 `image_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
50 `filename` varchar(25) NOT NULL,
51 `caption` varchar(120) NOT NULL,
52 PRIMARY KEY (`image_id`)
53 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
54 //Create table
55 $result = mysql_query($sql);
56 //Setup the MySQL for the users table
57 $createUser = "CREATE TABLE IF NOT EXISTS `users` (
58 `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
59 `group_id` tinyint(1) unsigned NOT NULL,
60 `email` varchar(255) NOT NULL,
61 `username` varchar(15) NOT NULL,
62 `salt` int(10) unsigned NOT NULL,
63 `pwd` varchar(40) NOT NULL,
64 PRIMARY KEY (`user_id`)
65 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
66 //Create the users table
67 $result = mysql_query($createUser);
68 // Create default admin user
69 $adminUser = "INSERT INTO `users` (`user_id`, `group_id`, `username`, `email`, `salt`, `pwd`) VALUES
70 (1, 1, 'Administrator', '$site_email', 1270334552, '7002fa53e21192b35586675c08694e0bc7f530ae')";
71 $insertAdminUser = mysql_query($adminUser);
72 //Setup the query to create the catgories table
73 $createCats = "CREATE TABLE IF NOT EXISTS `categories` (
74 `cat_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
75 `category` varchar(20) NOT NULL,
76 PRIMARY KEY (`cat_id`)
77 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6";
78 $result = mysql_query($createCats);
79 //Insert the default values for the catgories
80 $catDefaults = "INSERT INTO `categories` (`cat_id`, `category`) VALUES
81 (1, 'Personal'),
82 (2, 'Friends'),
83 (3, 'Family'),
84 (4, 'Holidays'),
85 (5, 'Misc')";
86 //Run the insert
87 $insert = mysql_query($catDefaults);
88 //Cat image lookup table
89 $catLookup = "CREATE TABLE IF NOT EXISTS `image_cat_lookup` (
90 `image_id` int(10) unsigned NOT NULL,
91 `cat_id` int(10) unsigned NOT NULL,
92 PRIMARY KEY (`image_id`,`cat_id`)
93 ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
94 $addCatLookup = mysql_query($catLookup);
95 //Journal table
96 $journal = "CREATE TABLE IF NOT EXISTS `journal` (
97 `article_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
98 `image_id` int(10) unsigned DEFAULT NULL,
99 `title` varchar(255) NOT NULL,
100 `article` text NOT NULL,
101 `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
102 `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
103 PRIMARY KEY (`article_id`)
104 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
105 $addJournal = mysql_query($journal);
106 //Pages table
107 $PageTable = "CREATE TABLE IF NOT EXISTS `pages` (
108 `page_id` int(5) unsigned NOT NULL AUTO_INCREMENT,
109 `image_id` int(10) unsigned DEFAULT NULL,
110 `page_name` varchar(20) NOT NULL,
111 `page_content` longtext NOT NULL,
112 PRIMARY KEY (`page_id`),
113 UNIQUE KEY `page_name` (`page_name`)
114 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
115 //Add the pages table
116 $addPages = mysql_query($PageTable);
117 //Add the default pages that we need and must be there
118 // $defaultPages = "INSERT INTO `pages` (`page_name`, `page_content`)
119 // 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.',
120 // 'index', 'This is the default Home page and you can edit this content in the admin area',
121 // 'contact', 'This is the default text for the contact page and it can be edited in the admin area',
122 // 'journal', '',
123 // 'gallery' , '')";
124 // $addDefaultPages = mysql_query($defaultPages);
125 //Settings Table
126 $settingsTable = "CREATE TABLE IF NOT EXISTS `settings` (
127 `variable` varchar(255) NOT NULL default '',
128 `value` text NOT NULL,
129 PRIMARY KEY (`variable`(30))
130 ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
131 //Add settings table
132 $addSettings = mysql_query($settingsTable);
133
134 //Default settings query
135 $dsettings = "INSERT INTO `settings` (`variable`, `value`)
136 VALUES ('site_email', '$site_email')";
137 //Add settings to table
138 $AddSettings = mysql_query($dsettings);
139
140}
141function check_for_smf($callback, $dir, $types = null, $recursive = false, $baseDir = '') {
142
143 if ($dh = opendir($dir)) {
144 while (($file = readdir($dh)) !== false) {
145 if ($file === '.' || $file === '..') {
146 continue;
147 }
148 if (is_file($dir . $file)) {
149 if (is_array($types)) {
150 if (!in_array(strtolower(pathinfo($dir . $file, PATHINFO_EXTENSION)), $types, true)) {
151 continue;
152 }
153 }
154 $callback($baseDir . $file);
155 }elseif($recursive && is_dir($dir . $file)) {
156 dir_walk($callback, $dir . $file . DIRECTORY_SEPARATOR, $types, $recursive, $baseDir . $file . DIRECTORY_SEPARATOR);
157 }
158 }
159 closedir($dh);
160 }
161}
162?>
163<form
164 name="db_info"
165 action=""
166 method="POST"
167 enctype="multipart/form-data"
168 >
169 <p><label for="site_name">Site Name:</label><br />
170 <input
171 type="text"
172 name="site_name"
173 value=""
174 size="40"
175 /><br />
176
177
178 <p><label for="site_email">Site(webmaster) Email:</label><br />
179 <input
180 type="text"
181 name="site_email"
182 value=""
183 size="40"
184 /><br />
185 <label for="db_hostname">Hostname:</label><br />
186 <input
187 type="text"
188 name="db_hostname"
189 value=""
190 size="50"
191 /><br />
192 <label for="db_name">Database name: </label><br />
193 <input
194 type="text"
195 name="db_name"
196 value=""
197 size="20"
198 /><br />
199 <label for="db_username">Database Username: </label><br />
200 <input
201 type="text"
202 name="db_username"
203 value=""
204 size="20"
205 /><br />
206 <label for="db_passwd">Database Password: </label><br />
207 <input
208 type="password"
209 name="db_passwd"
210 value=""
211 size="20"
212 /><br />
213 <label for="db_prefix">Database Prefix: </label><br />
214 <input
215 type="text"
216 name="db_prefix"
217 value=""
218 size="10"
219 /><br />
220 <br />
221 <input
222 type="submit"
223 name="install"
224 value="Install"
225 /></p>
226</form>
227<br />
228<?php
229//check_for_smf();
230if (@! $conn) {
231 echo '<span style="font-wieght:bold; color:red;"><b>' . $txt['install_error_empty_form_fields'] . '</b></span>';
232 exit();
233}
234$sql = "SHOW TABLES FROM $db_name";
235$result = mysql_query($sql);
236if (! $result) {
237 echo $txt['install_error_no_list_tbl'];
238 echo $txt['install_error_mysql_error'] . mysql_error();
239 exit();
240}
241if (isset($error)) {
242 echo $error;
243} else {
244 echo $setfilecreated;
245}
246echo $txt['install_db_tbls_created'];
247$table = array();
248while ($row = mysql_fetch_row($result)) {
249 $tables[] = $row[0];
250 echo '<b>' . $txt['install_db_tbl_names'] . ' ' . $row[0] . '</b><br />';
251}
252mysql_free_result($result);
253foreach ($tables as $k => $v) {
254 $table[] = $v;
255}
256//var_dump($table);
257if (isset($table[0]) && isset($table[1]) && isset($table[2]) && isset($table[3]) && isset($table[4]) && isset($table[5])) {
258 echo '<br /><br /><span style="font-weight:bold; color:green;">' . $txt['install_db_population_true'] . '</span>';
259} else {
260 echo '<br /><br /><span style="font-wieght:bold; color:red;">' . $txt['install_error_db_population_false'] . '</span>';
261}
262?>