last changes, install script refinement, other bug fixes (non-critical)
[phpns.git] / install / install.inc.php
blob44746079a5437ed779039abb79ba03fc3ed2d8b0
1 <?php
3 /* Copyright (c) 2007-08 Kyle Osborn, Alec Henriksen
4 * phpns is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public Licence (GPL) as published by the Free
6 * Software Foundation; either version 2 of the Licence, or (at your option) any
7 * later version.
8 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
9 * understanding of what this license means and how to abide by it.
12 if (INSTALLING == TRUE) {
14 $databaseinfo['host'] = $data['db_host'];
15 $databaseinfo['user'] = $data['db_user'];
16 $databaseinfo['password'] = $data['db_password'];
17 $databaseinfo['dbname'] = $data['db_name'];
20 include("../inc/errors.php"); // include error profiles
22 if ($_POST['overwrite'] != NULL) {
23 $sql = 'DROP TABLE IF EXISTS
24 `'.$data['db_tableprefix'].'articles`,
25 `'.$data['db_tableprefix'].'banlist`,
26 `'.$data['db_tableprefix'].'categories`,
27 `'.$data['db_tableprefix'].'comments`,
28 `'.$data['db_tableprefix'].'cookielog`,
29 `'.$data['db_tableprefix'].'gconfig`,
30 `'.$data['db_tableprefix'].'images`,
31 `'.$data['db_tableprefix'].'ranks`,
32 `'.$data['db_tableprefix'].'syslog`,
33 `'.$data['db_tableprefix'].'templates`,
34 `'.$data['db_tableprefix'].'themes`,
35 `'.$data['db_tableprefix'].'userlogin`,
36 `'.$data['db_tableprefix'].'users`;';
38 $res = mysql_query($sql) or die("<textarea>Failed to delete existing tables in DB. Mysql: ".mysql_error."</textarea>");
41 //connect to mysql database for all files
42 $mysql['connection'] = mysql_connect($databaseinfo['host'], $databaseinfo['user'], $databaseinfo['password'])
43 or die ($error['connection']);
45 //select mysql database
46 $mysql['db'] = mysql_select_db($databaseinfo['dbname'],$mysql['connection'])
47 or die ($error['database']);
51 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'articles` (
52 `id` int(25) NOT NULL auto_increment,
53 `article_title` varchar(150) NOT NULL,
54 `article_sef_title` varchar(150) NOT NULL,
55 `article_subtitle` varchar(150) NOT NULL,
56 `article_author` varchar(100) NOT NULL,
57 `article_cat` varchar(15) NOT NULL,
58 `article_text` varchar(20000) NOT NULL,
59 `article_exptext` varchar(20000) NOT NULL,
60 `article_imgid` varchar(100) NOT NULL,
61 `allow_comments` varchar(1) NOT NULL,
62 `start_date` varchar(15) NOT NULL,
63 `end_date` varchar(15) NOT NULL,
64 `active` varchar(1) NOT NULL,
65 `approved` varchar(1) NOT NULL,
66 `timestamp` varchar(15) NOT NULL,
67 `ip` varchar(15) NOT NULL,
68 PRIMARY KEY (`id`),
69 KEY `article_title` (`article_title`,`timestamp`)
70 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
71 $res = mysql_query($sql);
74 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'banlist` (
75 `id` int(10) NOT NULL auto_increment,
76 `ip` varchar(15) NOT NULL,
77 `banned_by` varchar(20) NOT NULL,
78 `reason` varchar(5000) NOT NULL,
79 `timestamp` varchar(12) NOT NULL,
80 PRIMARY KEY (`id`)
81 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
82 $res = mysql_query($sql);
84 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'categories` (
85 `id` int(15) NOT NULL auto_increment,
86 `cat_name` varchar(100) NOT NULL,
87 `cat_parent` varchar(10000) NOT NULL,
88 `cat_author` varchar(100) NOT NULL,
89 `cat_desc` varchar(1000) NOT NULL,
90 `timestamp` varchar(15) NOT NULL,
91 `ip` varchar(15) NOT NULL,
92 PRIMARY KEY (`id`)
93 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ;';
94 $res = mysql_query($sql);
96 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'comments` (
97 `id` int(25) NOT NULL auto_increment,
98 `article_id` varchar(25) NOT NULL,
99 `comment_text` varchar(1000) NOT NULL,
100 `website` varchar(100) NOT NULL,
101 `comment_author` varchar(20) NOT NULL,
102 `timestamp` varchar(15) NOT NULL,
103 `approved` varchar(1) NOT NULL,
104 `ip` varchar(15) NOT NULL,
105 PRIMARY KEY (`id`)
106 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
107 $res = mysql_query($sql);
109 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'cookielog` (
110 `id` int(20) NOT NULL auto_increment,
111 `user_id` varchar(15) NOT NULL,
112 `rank_id` varchar(15) NOT NULL,
113 `cookie_id` varchar(32) NOT NULL,
114 `timestamp` varchar(15) NOT NULL,
115 `ip` varchar(15) NOT NULL,
116 PRIMARY KEY (`id`),
117 KEY `user_id` (`user_id`)
118 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
120 $res = mysql_query($sql);
122 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'gconfig` (
123 `id` int(5) NOT NULL auto_increment,
124 `name` varchar(100) NOT NULL,
125 `v1` varchar(17) NOT NULL,
126 `v2` varchar(10) NOT NULL,
127 `v3` varchar(1000) NOT NULL,
128 PRIMARY KEY (`id`)
129 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
130 $res = mysql_query($sql);
132 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'images` (
133 `id` int(15) NOT NULL auto_increment,
134 `user_id` varchar(15) NOT NULL,
135 `image_filepath` varchar(500) NOT NULL,
136 `alt_description` varchar(100) NOT NULL,
137 `timestamp` varchar(15) NOT NULL,
138 `ip` varchar(15) NOT NULL,
139 PRIMARY KEY (`id`),
140 KEY `user_id` (`user_id`)
141 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
142 $res = mysql_query($sql);
144 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'ranks` (
145 `id` int(15) NOT NULL auto_increment,
146 `rank_title` varchar(100) NOT NULL,
147 `rank_desc` varchar(1000) NOT NULL,
148 `rank_author` varchar(100) NOT NULL,
149 `permissions` varchar(100) NOT NULL,
150 `category_list` varchar(200) NOT NULL,
151 `timestamp` varchar(15) NOT NULL,
152 PRIMARY KEY (`id`)
153 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
154 $res = mysql_query($sql);
156 $sql = 'CREATE TABLE `'.$data['db_tableprefix'].'syslog` (
157 `id` int(24) NOT NULL auto_increment,
158 `task` varchar(20) NOT NULL,
159 `description` varchar(200) NOT NULL,
160 `user` int(5) NOT NULL,
161 `page` varchar(120) NOT NULL,
162 `timestamp` varchar(12) NOT NULL,
163 PRIMARY KEY (`id`)
164 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;';
165 $res = mysql_query($sql);
168 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'templates` (
169 `id` int(15) NOT NULL auto_increment,
170 `template_name` varchar(100) NOT NULL,
171 `template_desc` varchar(1000) NOT NULL,
172 `template_author` varchar(100) NOT NULL,
173 `timestamp` varchar(15) NOT NULL,
174 `html_article` varchar(5000) NOT NULL,
175 `html_comment` varchar(5000) NOT NULL,
176 `html_form` varchar(5000) NOT NULL,
177 `html_pagination` varchar(5000) NOT NULL,
178 `template_selected` varchar(1) NOT NULL,
179 PRIMARY KEY (`id`)
180 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
181 $res = mysql_query($sql);
183 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'themes` (
184 `id` int(10) NOT NULL auto_increment,
185 `theme_name` varchar(100) NOT NULL,
186 `theme_author` varchar(100) NOT NULL,
187 `theme_dir` varchar(200) NOT NULL,
188 `base_dir` varchar(50) NOT NULL,
189 `timestamp` varchar(15) NOT NULL,
190 `theme_selected` varchar(1) NOT NULL,
191 `permissions` varchar(10000) NOT NULL,
192 PRIMARY KEY (`id`)
193 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
194 $res = mysql_query($sql);
196 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'userlogin` (
197 `id` int(20) NOT NULL auto_increment,
198 `username` varchar(15) NOT NULL,
199 `rank_id` varchar(15) NOT NULL,
200 `timestamp` varchar(15) NOT NULL,
201 `ip` varchar(15) NOT NULL,
202 PRIMARY KEY (`id`),
203 KEY `user_id` (`username`)
204 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=82 ;
206 $res = mysql_query($sql);
208 $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'users` (
209 `id` int(15) NOT NULL auto_increment,
210 `user_name` varchar(100) NOT NULL,
211 `full_name` varchar(150) NOT NULL,
212 `email` varchar(100) NOT NULL,
213 `password` varchar(40) NOT NULL,
214 `timestamp` varchar(15) NOT NULL,
215 `ip` varchar(15) NOT NULL,
216 `msn` varchar(100) NOT NULL,
217 `aim` varchar(100) NOT NULL,
218 `yahoo` varchar(100) NOT NULL,
219 `skype` varchar(100) NOT NULL,
220 `display_picture` varchar(150) NOT NULL,
221 `rank_id` varchar(15) NOT NULL,
222 `notifications` varchar(1) NOT NULL,
223 PRIMARY KEY (`id`)
224 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;';
225 $res = mysql_query($sql);
227 $sql = "INSERT INTO `".$data['db_tableprefix']."articles` (`id`, `article_title`, `article_subtitle`, `article_author`, `article_cat`, `article_text`, `article_exptext`, `article_imgid`, `allow_comments`, `start_date`, `end_date`, `active`, `approved`, `timestamp`, `ip`) VALUES (1, 'Welcome to phpns!','','".$data['username']."','all','&lt;p&gt;If you see are viewing this message, the phpns installation was a success! This article is filed under &amp;quot;Site Wide News&amp;quot;, which is the default category that is created during installation.&lt;/p&gt;&lt;p&gt;&lt;font color=&quot;#000000&quot;&gt;You are free to modify this message, or delete it all together&lt;/font&gt;. Why should you use phpns?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;It&#039;s free&lt;/strong&gt;. Phpns is released under the GPL license, which gives you the ability to change it, redistribute it, and use it personally or professionally.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s easy to integrate&lt;/strong&gt;. Only one line of code is necessary on your website, and you have a dynamic, fully functional news system. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s easy to install&lt;/strong&gt;. The guided installation will have you up and running in minutes, asking you just a few questions about your database setup.&lt;/li&gt;&lt;/ul&gt;Some more information is available in the &amp;quot;Full Article&amp;quot; section...','What does &amp;quot;free&amp;quot; mean? &lt;blockquote&gt;To the phpns developers, the word &amp;quot;free&amp;quot; means more than just the cost of the product. The word free means that &lt;strong&gt;you are free&lt;/strong&gt; to modify anything you want about phpns, without any license restrictions.&lt;/blockquote&gt;&lt;p&gt;Why is phpns free in both price and modification?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we believe in the open-source message. Closed source applications restrict the user from customizing the way the system works, and prevents the communitiy from contributing to the package. Plus, we love seeing our software being put to good use, and we love seeing modifications of our work!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Why don&#039;t you require a &amp;quot;Powered by phpns&amp;quot; message at the bottom of each page, like other news systems?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we hate that.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;What can I do to help the project?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you would like to be a part of the project, we always appreciate help. What you can do:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Spread the word. Recommend our system to your friends and co-workers!&lt;/li&gt;&lt;li&gt;Report bugs you&#039;ve encountered at the &lt;a href=&quot;http://launchpad.net/phpns&quot;&gt;phpns launchpad website&lt;/a&gt;. &lt;/li&gt;&lt;li&gt;Submit reviews to software review websites around the internet. As long as they are honest, this is a great way to help us.&lt;/li&gt;&lt;li&gt;Donate. This helps with hosting/domain costs, and you&#039;ll get your name on the website along with a message and URL of your blog/website.&lt;/li&gt;&lt;li&gt;Become a sponsor. If you&#039;re a hosting service, business, or organization, we&#039;re always looking for funding and bandwith.&lt;/li&gt;&lt;li&gt;Develop. Contact us on the website if you think we could use your services.&lt;/li&gt;&lt;/ul&gt;That&#039;s it. Enjoy phpns!&lt;br /&gt;&lt;/blockquote&gt;','imgid','0','','','1','1','".time()."','".$_SERVER['REMOTE_ADDR']."')";
228 $res = mysql_query($sql);
230 $sql = "INSERT INTO `".$data['db_tableprefix']."gconfig` (`id`, `name`, `v1`, `v2`, `v3`) VALUES
231 (NULL, 'siteonline', '0', '0', '0'),
232 (NULL, 'def_rsslimit', '', '', '3'),
233 (NULL, 'def_rssorder', 'desc', '', ''),
234 (NULL, 'def_items_per_page', '10', '', ''),
235 (NULL, 'def_rsstitle', '', '', 'RSS feed for ".$_SERVER['SERVER_NAME']."'),
236 (NULL, 'def_rssdesc', '', '', 'An RSS feed from ".$_SERVER['SERVER_NAME']."'),
237 (NULL, 'def_rssenabled', '1', '', ''),
238 (NULL, 'def_limit', '10', '', ''),
239 (NULL, 'def_order', 'desc', '', ''),
240 (NULL, 'def_offset', '0', '', ''),
241 (NULL, 'timestamp_format', '', '', 'l F d, Y g:i a'),
242 (NULL, 'def_comlimit', '', '', '100000'),
243 (NULL, 'def_comenabled', '1', '', ''),
244 (NULL, 'def_comorder', 'asc', '', ''),
245 (NULL, 'global_message', '', '', 'Welcome to the phpns admin panel! Click \'change message\' to modify/delete this message.'),
246 (NULL, 'siteonline', '0', '0', '0'),
247 (NULL, 'wysiwyg', 'yes', '', ''),
248 (NULL, 'sys_time_format', 'l F d, Y g:i a', '', ''),
249 (NULL, 'line', 'yes', '', '');";
250 $res = mysql_query($sql);
252 $sql = "INSERT INTO `".$data['db_tableprefix']."ranks` (`id`, `rank_title`, `rank_desc`, `rank_author`, `permissions`, `category_list`, `timestamp`) VALUES
253 (1, 'Administrators', 'Any user assigned to this rank will have full access.', '".$data['username']."', '1,1,1,1,1,1,1,1,1,1,1,1', 'all', '".time() ."');";
254 $res = mysql_query($sql);
256 $sql = "INSERT INTO `".$data['db_tableprefix']."themes` (`id`, `theme_name`, `theme_author`, `theme_dir`, `base_dir`, `timestamp`, `theme_selected`, `permissions`) VALUES
257 (1, 'default', 'phpns team', 'themes/default/', 'default', '".time() ."', '1', '');";
258 $res = mysql_query($sql);
260 $sql = "INSERT INTO `".$data['db_tableprefix']."users` (`id`, `user_name`, `full_name`, `email`, `password`, `timestamp`, `ip`, `msn`, `aim`, `yahoo`, `skype`, `display_picture`, `rank_id`, `notifications`) VALUES
261 (1, '".$data['username']."', '".$data['username']."', '".$data['email']."', '".$data['password'] ."', '".time() ."', '127.0.0.1', '', '', '', '', '', '1', '1');";
262 $res = mysql_query($sql);
264 $sql = "INSERT INTO `".$data['db_tableprefix']."categories` (`id`, `cat_name`, `cat_parent`, `cat_author`, `cat_desc`, `timestamp`, `ip`) VALUES (1, 'Site Wide News', '', '".$data['username']."', 'This is for general news on your website.', '".time()."','".$_SERVER['REMOTE_ADDR']."');";
265 $res = mysql_query($sql);
267 $sql = 'INSERT INTO `'.$data['db_tableprefix'].'templates` (`id`, `template_name`, `template_desc`, `template_author`, `timestamp`, `html_article`, `html_comment`, `html_form`, `html_pagination`, `template_selected`) VALUES
268 ("1", "Default", "This is the default phpns template.", "Phpns-team", "1194252704", "&lt;div style=&quot;margin-bottom: 30px; min-height: 130px;&quot;&gt;\r\n &lt;h2 style=&quot;margin-bottom: 0pt&quot;&gt;&lt;a href=&quot;{article_href}&quot; style=&quot;text-decoration: none;&quot;&gt;{title}&lt;/a&gt;&lt;/h2&gt;\r\n &lt;h3&gt;&lt;em&gt;{sub_title}&lt;/em&gt;&lt;/h3&gt;\r\n &lt;h4 style=&quot;margin: 0 0 0 3em; font-weight: normal;&quot;&gt;Posted by &lt;a href=&quot;#&quot;&gt;{author}&lt;/a&gt; on {date}&lt;/h4&gt;\r\n &lt;span style=&quot;float: right&quot;&gt;&lt;a href=&quot;{image_location}&quot;&gt;{image}&lt;/a&gt;&lt;/span&gt;\r\n&lt;div style=&quot;float:right; padding: 0 0 10px 10px&quot;&gt;{reddit} {digg}&lt;/div&gt;\r\n {main_article}\r\n {extended_article}\r\n &lt;div id=&quot;comments&quot; style=&quot;text-align: right; clear: both;&quot;&gt;\r\n &lt;strong&gt;&lt;a href=&quot;{article_href}#comments&quot;&gt;{comment_count} comments&lt;/a&gt;&lt;/strong&gt;\r\n &lt;/div&gt;\r\n&lt;/div&gt;\r\n", "&lt;div style=&quot;background: #eee; margin: 20px 0 0 5%; padding: 5px;&quot;&gt;\r\n &lt;div style=&quot;border: 1px solid #ccc; padding: 3px; background: #ccc; margin-bo
269 ttom: 5px;&quot;&gt; \r\n &lt;div style=&quot;text-align: right; float: right&quot;&gt; {timestamp} {admin}&lt;/div&gt; \r\n &lt;strong&gt;Posted by &lt;a href=&quot;{website}&quot;&gt;{author}&lt;/a&gt;&lt;/strong&gt; as {ip}\r\n &lt;/div&gt;\r\n {comment}\r\n&lt;/div&gt;", "&lt;form style=&quot;margin-top: 50px;&quot; action=&quot;{action}&quot; method=&quot;post&quot;&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt; &lt;label for=&quot;name&quot;&gt;Name (required)&lt;/label&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt; &lt;label for=&quot;email&quot;&gt;Email (not publishe
270 d) (required)&lt;/label&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;website&quot; id=&quot;website&quot; /&gt; &lt;label for=&quot;website&quot;&gt;Website&lt;/label&gt;&lt;br /&gt;\r\n &lt;textarea name=&quot;comment&quot; style=&quot;width:100%; height: 150px&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;captcha&quot; style=&quot;width: 100px&quot; /&gt; &lt;label for=&quot;captcha&quot;&gt;&lt;strong&gt;What is {captcha_question}?&lt;/strong&gt;&lt;/label&gt;&lt;br /&gt;\r\n {hidden_data}\r\n {captcha_answer}\r\n &lt;input type=&quot;submit&quot; value=&quot;Submit comment&quot; id=&quot;submit&quot; /&gt;\r\n&lt;/form&gt;\r\n\r\n", "
271 &lt;a style=&quot;padding: 3px; margin: 10px; border: 1px solid #888;&quot; href=&quot;{previous_page}&quot;&gt;Previous Page&lt;/a&gt; {middle_pages} &lt;a style=&quot;padding: 3px; margin: 10px; border: 1px solid #888;&quot; href=&quot;{next_page}&quot;&gt;Next Page&lt;/a&gt;", "1"
274 $res = mysql_query($sql) or die(mysql_error());
276 $sql = "INSERT INTO `".$data['db_tableprefix']."syslog` (`id`, `task`, `description`, `user`, `page`, `timestamp`) VALUES
277 (1, 'INSTALL', 'User &lt;i&gt;".$data['username']."&lt;/i&gt; has installed phpns!', '1', '/phpns/install/', ".time().")";
278 $res = mysql_query($sql) or die(mysql_error());
280 } //end main (installing) if