Project

General

Profile

1 552 thorn
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26 582 thorn
// Start a session
27 552 thorn
if(!defined('SESSION_STARTED')) {
28 582 thorn
	session_name('wb_session_id');
29 552 thorn
	session_start();
30 582 thorn
	define('SESSION_STARTED', true);
31
}
32
// get random-part for session_name()
33
list($usec,$sec) = explode(' ',microtime());
34
srand((float)$sec+((float)$usec*100000));
35
$session_rand = rand(1000,9999);
36 552 thorn
37
// Function to set error
38
function set_error($message) {
39
	global $_POST;
40
	if(isset($message) AND $message != '') {
41
		// Copy values entered into session so user doesn't have to re-enter everything
42
		if(isset($_POST['website_title'])) {
43
			$_SESSION['wb_url'] = $_POST['wb_url'];
44
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
45 632 doc
			$_SESSION['default_language'] = $_POST['default_language'];
46 552 thorn
			if(!isset($_POST['operating_system'])) {
47
				$_SESSION['operating_system'] = 'linux';
48
			} else {
49
				$_SESSION['operating_system'] = $_POST['operating_system'];
50
			}
51
			if(!isset($_POST['world_writeable'])) {
52
				$_SESSION['world_writeable'] = false;
53
			} else {
54
				$_SESSION['world_writeable'] = true;
55
			}
56
			$_SESSION['database_host'] = $_POST['database_host'];
57
			$_SESSION['database_username'] = $_POST['database_username'];
58
			$_SESSION['database_password'] = $_POST['database_password'];
59
			$_SESSION['database_name'] = $_POST['database_name'];
60
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
61
			if(!isset($_POST['install_tables'])) {
62
				$_SESSION['install_tables'] = false;
63
			} else {
64
				$_SESSION['install_tables'] = true;
65
			}
66
			$_SESSION['website_title'] = $_POST['website_title'];
67
			$_SESSION['admin_username'] = $_POST['admin_username'];
68
			$_SESSION['admin_email'] = $_POST['admin_email'];
69
			$_SESSION['admin_password'] = $_POST['admin_password'];
70
		}
71
		// Set the message
72
		$_SESSION['message'] = $message;
73
		// Specify that session support is enabled
74
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
75
		// Redirect to first page again and exit
76
		header('Location: index.php?sessions_checked=true');
77
		exit();
78
	}
79
}
80
81
// Dummy class to allow modules' install scripts to call $admin->print_error
82
class admin_dummy
83
{
84
	var $error='';
85
	function print_error($message)
86
	{
87
		$this->error=$message;
88
	}
89
}
90
91
// Function to workout what the default permissions are for files created by the webserver
92
function default_file_mode($temp_dir) {
93
	$v = explode(".",PHP_VERSION);
94
	$v = $v[0].$v[1];
95
	if($v > 41 AND is_writable($temp_dir)) {
96
		$filename = $temp_dir.'/test_permissions.txt';
97
		$handle = fopen($filename, 'w');
98
		fwrite($handle, 'This file is to get the default file permissions');
99
		fclose($handle);
100
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
101
		unlink($filename);
102
	} else {
103
		$default_file_mode = '0777';
104
	}
105
	return $default_file_mode;
106
}
107
108
// Function to workout what the default permissions are for directories created by the webserver
109
function default_dir_mode($temp_dir) {
110
	$v = explode(".",PHP_VERSION);
111
	$v = $v[0].$v[1];
112
	if($v > 41 AND is_writable($temp_dir)) {
113
		$dirname = $temp_dir.'/test_permissions/';
114
		mkdir($dirname);
115
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
116
		rmdir($dirname);
117
	} else {
118
		$default_dir_mode = '0777';
119
	}
120
	return $default_dir_mode;
121
}
122
123
function add_slashes($input) {
124
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
125
			return $input;
126
		}
127
		$output = addslashes($input);
128
		return $output;
129
	}
130
131
// Begin check to see if form was even submitted
132
// Set error if no post vars found
133
if(!isset($_POST['website_title'])) {
134
	set_error('Please fill-in the form below');
135
}
136
// End check to see if form was even submitted
137
138
// Begin path and timezone details code
139
140
// Check if user has entered the installation url
141
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
142
	set_error('Please enter an absolute URL');
143
} else {
144
	$wb_url = $_POST['wb_url'];
145
}
146
// Remove any slashes at the end of the URL
147
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
148
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
149
}
150
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
151
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
152
}
153
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
154
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
155
}
156
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
157
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
158
}
159
// Get the default time zone
160
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
161
	set_error('Please select a valid default timezone');
162
} else {
163
	$default_timezone = $_POST['default_timezone']*60*60;
164
}
165
// End path and timezone details code
166
167 629 doc
// Get the default language
168
$allowed_languages = array('CA', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'PT','SE', 'TR');
169
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
170
	set_error('Please select a valid default backend language');
171
} else {
172
	$default_language = $_POST['default_language'];
173
	// make sure the selected language file exists in the language folder
174
	if(!file_exists('../languages/' .$default_language .'.php')) {
175
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language');
176
	}
177
}
178
// End default language details code
179
180 552 thorn
// Begin operating system specific code
181
// Get operating system
182
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
183
	set_error('Please select a valid operating system');
184
} else {
185
	$operating_system = $_POST['operating_system'];
186
}
187
// Work-out file permissions
188
if($operating_system == 'windows') {
189
	$file_mode = '0777';
190
	$dir_mode = '0777';
191
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
192
	$file_mode = '0777';
193
	$dir_mode = '0777';
194
} else {
195
	$file_mode = default_file_mode('../temp');
196
	$dir_mode = default_dir_mode('../temp');
197
}
198
// End operating system specific code
199
200
// Begin database details code
201
// Check if user has entered a database host
202
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
203
	set_error('Please enter a database host name');
204
} else {
205
	$database_host = $_POST['database_host'];
206
}
207
// Check if user has entered a database username
208
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
209
	set_error('Please enter a database username');
210
} else {
211
	$database_username = $_POST['database_username'];
212
}
213
// Check if user has entered a database password
214
if(!isset($_POST['database_password'])) {
215
	set_error('Please enter a database password');
216
} else {
217
	$database_password = $_POST['database_password'];
218
}
219
// Check if user has entered a database name
220
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
221
	set_error('Please enter a database name');
222
} else {
223
	$database_name = $_POST['database_name'];
224
}
225
// Get table prefix
226
$table_prefix = $_POST['table_prefix'];
227
// Find out if the user wants to install tables and data
228
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
229
	$install_tables = true;
230
} else {
231
	$install_tables = false;
232
}
233
// End database details code
234
235
// Begin website title code
236
// Get website title
237
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
238
	set_error('Please enter a website title');
239
} else {
240
	$website_title = add_slashes($_POST['website_title']);
241
}
242
// End website title code
243
244
// Begin admin user details code
245
// Get admin username
246
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
247
	set_error('Please enter a username for the Administrator account');
248
} else {
249
	$admin_username = $_POST['admin_username'];
250
}
251
// Get admin email and validate it
252
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
253
	set_error('Please enter an email for the Administrator account');
254
} else {
255
	if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['admin_email'])) {
256
		$admin_email = $_POST['admin_email'];
257
	} else {
258
		set_error('Please enter a valid email address for the Administrator account');
259
	}
260
}
261
// Get the two admin passwords entered, and check that they match
262
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
263
	set_error('Please enter a password for the Administrator account');
264
} else {
265
	$admin_password = $_POST['admin_password'];
266
}
267
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
268
	set_error('Please make sure you re-enter the password for the Administrator account');
269
} else {
270
	$admin_repassword = $_POST['admin_repassword'];
271
}
272
if($admin_password != $admin_repassword) {
273
	set_error('Sorry, the two Administrator account passwords you entered do not match');
274
}
275
// End admin user details code
276
277
// Try and write settings to config file
278
$config_content = "" .
279
"<?php\n".
280
"\n".
281
"define('DB_TYPE', 'mysql');\n".
282
"define('DB_HOST', '$database_host');\n".
283
"define('DB_USERNAME', '$database_username');\n".
284
"define('DB_PASSWORD', '$database_password');\n".
285
"define('DB_NAME', '$database_name');\n".
286
"define('TABLE_PREFIX', '$table_prefix');\n".
287
"\n".
288
"define('WB_PATH', dirname(__FILE__));\n".
289
"define('WB_URL', '$wb_url');\n".
290
"define('ADMIN_PATH', WB_PATH.'/admin');\n".
291
"define('ADMIN_URL', '$wb_url/admin');\n".
292
"\n".
293
"require_once(WB_PATH.'/framework/initialize.php');\n".
294
"\n".
295
"?>";
296
297
$config_filename = '../config.php';
298
299
// Check if the file exists and is writable first.
300
if(file_exists($config_filename) AND is_writable($config_filename)) {
301
	if(!$handle = fopen($config_filename, 'w')) {
302
		set_error("Cannot open the configuration file ($config_filename)");
303
	} else {
304
		if (fwrite($handle, $config_content) === FALSE) {
305
			set_error("Cannot write to the configuration file ($config_filename)");
306
		}
307
		// Close file
308
		fclose($handle);
309
	}
310
} else {
311
	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
312
}
313
314
// Define configuration vars
315
define('DB_TYPE', 'mysql');
316
define('DB_HOST', $database_host);
317
define('DB_USERNAME', $database_username);
318
define('DB_PASSWORD', $database_password);
319
define('DB_NAME', $database_name);
320
define('TABLE_PREFIX', $table_prefix);
321
define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
322
define('WB_URL', $wb_url);
323
define('ADMIN_PATH', WB_PATH.'/admin');
324
define('ADMIN_URL', $wb_url.'/admin');
325
326
// Check if the user has entered a correct path
327
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
328
	set_error('It appears the Absolute path that you entered is incorrect');
329
}
330
331
// Try connecting to database
332
if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
333
	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
334
}
335
336
// Try to create the database
337
mysql_query('CREATE DATABASE '.$database_name);
338
339
// Close the mysql connection
340
mysql_close();
341
342
// Include WB functions file
343
require_once(WB_PATH.'/framework/functions.php');
344
345
// Re-connect to the database, this time using in-build database class
346
require_once(WB_PATH.'/framework/class.login.php');
347
$database=new database();
348
349
// Check if we should install tables
350
if($install_tables == true) {
351
352
	// Remove tables if they exist
353
354
	// Pages table
355
	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
356
	$database->query($pages);
357
	// Sections table
358
	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
359
	$database->query($sections);
360
	// Settings table
361
	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
362
	$database->query($settings);
363
	// Users table
364
	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
365
	$database->query($users);
366
	// Groups table
367
	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
368
	$database->query($groups);
369
	// Search table
370
	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
371
	$database->query($search);
372
	// Addons table
373
	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
374
	$database->query($addons);
375
376
	// Try installing tables
377
378
	// Pages table
379
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
380
	       . ' `parent` INT NOT NULL DEFAULT \'0\','
381
	       . ' `root_parent` INT NOT NULL DEFAULT \'0\','
382
	       . ' `level` INT NOT NULL DEFAULT \'0\','
383
	       . ' `link` TEXT NOT NULL,'
384
	       . ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
385
	       . ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
386
	       . ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
387
	       . ' `description` TEXT NOT NULL ,'
388
	       . ' `keywords` TEXT NOT NULL ,'
389
	       . ' `page_trail` TEXT NOT NULL  ,'
390
	       . ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
391
	       . ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
392
	       . ' `position` INT NOT NULL DEFAULT \'0\','
393
	       . ' `menu` INT NOT NULL DEFAULT \'0\','
394
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
395
	       . ' `searching` INT NOT NULL DEFAULT \'0\','
396
	       . ' `admin_groups` TEXT NOT NULL ,'
397
	       . ' `admin_users` TEXT NOT NULL ,'
398
	       . ' `viewing_groups` TEXT NOT NULL ,'
399
	       . ' `viewing_users` TEXT NOT NULL ,'
400
	       . ' `modified_when` INT NOT NULL DEFAULT \'0\','
401
	       . ' `modified_by` INT NOT NULL  DEFAULT \'0\','
402
	       . ' PRIMARY KEY ( `page_id` ) '
403
	       . ' )';
404
	$database->query($pages);
405
406
	// Sections table
407
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
408
	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
409
	       . ' `position` INT NOT NULL DEFAULT \'0\','
410
	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
411
	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
412
	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
413
	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
414
	       . ' PRIMARY KEY ( `section_id` ) '
415
	       . ' )';
416
	$database->query($pages);
417
418
	require(WB_PATH.'/admin/interface/version.php');
419
420
	// Settings table
421
	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
422
		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
423
		. ' `value` TEXT NOT NULL ,'
424
		. ' PRIMARY KEY ( `setting_id` ) '
425
		. ' )';
426
	$database->query($settings);
427
428
	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
429
	." (name, value) VALUES "
430
	." ('wb_version', '".VERSION."'),"
431
	." ('website_title', '$website_title'),"
432
	." ('website_description', ''),"
433
	." ('website_keywords', ''),"
434
	." ('website_header', ''),"
435
	." ('website_footer', ''),"
436
	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
437
	." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
438
	." ('er_level', ''),"
439 629 doc
	." ('default_language', '$default_language'),"
440 581 thorn
	." ('app_name', 'wb_$session_rand'),"
441 552 thorn
	." ('default_timezone', '$default_timezone'),"
442
	." ('default_date_format', 'M d Y'),"
443
	." ('default_time_format', 'g:i A'),"
444
	." ('home_folders', 'true'),"
445
	." ('default_template', 'round'),"
446
	." ('default_charset', 'utf-8'),"
447
	." ('multiple_menus', 'false'),"
448
	." ('page_level_limit', '4'),"
449
	." ('intro_page', 'false'),"
450
	." ('page_trash', 'disabled'),"
451
	." ('homepage_redirection', 'false'),"
452
	." ('page_languages', 'false'),"
453
	." ('wysiwyg_editor', 'fckeditor'),"
454
	." ('manage_sections', 'true'),"
455
	." ('section_blocks', 'false'),"
456
	." ('smart_login', 'false'),"
457
	." ('frontend_login', 'false'),"
458
	." ('frontend_signup', 'false'),"
459
	." ('search', 'public'),"
460
	." ('page_extension', '.php'),"
461
	." ('page_spacer', '-'),"
462
	." ('pages_directory', '/pages'),"
463
	." ('media_directory', '/media'),"
464
	." ('operating_system', '$operating_system'),"
465
	." ('string_file_mode', '$file_mode'),"
466
	." ('string_dir_mode', '$dir_mode'),"
467
	." ('wbmailer_routine', 'phpmail'),"
468 568 doc
	." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
469
	." ('wbmailer_default_sendername', 'WB Mailer'),"
470 552 thorn
	." ('wbmailer_smtp_host', ''),"
471
	." ('wbmailer_smtp_auth', ''),"
472
	." ('wbmailer_smtp_username', ''),"
473
	." ('wbmailer_smtp_password', '')";
474
	$database->query($settings_rows);
475
476
	// Users table
477
	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
478
	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
479
	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
480
	       . ' `active` INT NOT NULL DEFAULT \'0\','
481
	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
482
	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
483
	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
484
	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
485
	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
486
	       . ' `email` TEXT NOT NULL ,'
487
	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
488
	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
489
	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
490 629 doc
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'' .$default_language .'\' ,'
491 552 thorn
	       . ' `home_folder` TEXT NOT NULL ,'
492
	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
493
	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
494
	       . ' PRIMARY KEY ( `user_id` ) '
495
	       . ' )';
496
	$database->query($users);
497
498
	// Groups table
499
	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
500
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
501
	        . ' `system_permissions` TEXT NOT NULL ,'
502
	        . ' `module_permissions` TEXT NOT NULL ,'
503
	        . ' `template_permissions` TEXT NOT NULL ,'
504
	        . ' PRIMARY KEY ( `group_id` ) '
505
	        . ' )';
506
	$database->query($groups);
507
508
	// Search settings table
509
	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
510
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
511
	        . ' `value` TEXT NOT NULL ,'
512
	        . ' `extra` TEXT NOT NULL ,'
513
	        . ' PRIMARY KEY ( `search_id` ) '
514
	        . ' )';
515
	$database->query($search);
516
517
	// Addons table
518
	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
519
			.'`addon_id` INT NOT NULL auto_increment ,'
520
			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
521
			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
522
			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
523
			.'`description` TEXT NOT NULL ,'
524
			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
525
			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
526
			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
527
			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
528
			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
529
			.' PRIMARY KEY ( `addon_id` ) '
530
			.' )';
531
	$database->query($addons);
532
533
	// Insert default data
534
535
	// Admin group
536
	$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
537
	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
538
	$database->query($insert_admin_group);
539
	// Admin user
540
	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,groups_id,active,username,password,email,display_name) VALUES ('1','1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
541
	$database->query($insert_admin_user);
542
543
	// Search header
544
	$search_header = addslashes('
545
<h1>[TEXT_SEARCH]</h1>
546
547
<form name="search" action="[WB_URL]/search/index.php" method="get">
548
<table cellpadding="3" cellspacing="0" border="0" width="500">
549
<tr>
550
<td>
551
<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
552
<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
553
</td>
554
<td width="150">
555
<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
556
</td>
557
</tr>
558
<tr>
559
<td colspan="2">
560
<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
561
<label for="match_all">[TEXT_ALL_WORDS]</label>
562
<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
563
<label for="match_any">[TEXT_ANY_WORDS]</label>
564
<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
565
<label for="match_exact">[TEXT_EXACT_MATCH]</label>
566
</td>
567
</tr>
568
</table>
569
570
</form>
571
572
<hr />
573
	');
574
	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
575
	$database->query($insert_search_header);
576
	// Search footer
577
	$search_footer = addslashes('');
578
	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
579
	$database->query($insert_search_footer);
580
	// Search results header
581
	$search_results_header = addslashes(''.
582
'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
583
<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
584
	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
585
	$database->query($insert_search_results_header);
586
	// Search results loop
587
	$search_results_loop = addslashes(''.
588
'<tr style="background-color: #F0F0F0;">
589
<td><a href="[LINK]">[TITLE]</a></td>
590
<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
591
</tr>
592
<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
593
<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
594
595
	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
596
	$database->query($insert_search_results_loop);
597
	// Search results footer
598
	$search_results_footer = addslashes("</table>");
599
	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
600
	$database->query($insert_search_results_footer);
601
	// Search no results
602
	$search_no_results = addslashes('<br />[TEXT_NO_RESULTS]');
603
	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
604
	$database->query($insert_search_no_results);
605
	// Search module-order
606
	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
607
	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
608
	$database->query($insert_search_module_order);
609
	// Search max lines of excerpt
610
	$search_max_excerpt = addslashes('15');
611
	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
612
	$database->query($insert_search_max_excerpt);
613
	// some config-elements
614
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
615
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
616
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
617
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
618
	// Search template
619
	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
620
621
	require_once(WB_PATH.'/framework/initialize.php');
622
623
	// Include the PclZip class file (thanks to
624
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
625
626
	// Install add-ons
627
	if(file_exists(WB_PATH.'/install/modules')) {
628
		// Unpack pre-packaged modules
629
630
	}
631
	if(file_exists(WB_PATH.'/install/templates')) {
632
		// Unpack pre-packaged templates
633
634
	}
635
	if(file_exists(WB_PATH.'/install/languages')) {
636
		// Unpack pre-packaged languages
637
638
	}
639
640
	$admin=new admin_dummy();
641
	// Load addons into DB
642
	$dirs['modules'] = WB_PATH.'/modules/';
643
	$dirs['templates'] = WB_PATH.'/templates/';
644
	$dirs['languages'] = WB_PATH.'/languages/';
645
	foreach($dirs AS $type => $dir) {
646
		if($handle = opendir($dir)) {
647
			while(false !== ($file = readdir($handle))) {
648
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
649
					// Get addon type
650
					if($type == 'modules') {
651
						load_module($dir.'/'.$file, true);
652
						// Pretty ugly hack to let modules run $admin->set_error
653
						// See dummy class definition admin_dummy above
654
						if ($admin->error!='') {
655
							set_error($admin->error);
656
						}
657
					} elseif($type == 'templates') {
658
						load_template($dir.'/'.$file);
659
					} elseif($type == 'languages') {
660
						load_language($dir.'/'.$file);
661
					}
662
				}
663
			}
664
		closedir($handle);
665
		}
666
	}
667
668
	// Check if there was a database error
669
	if($database->is_error()) {
670
		set_error($database->get_error());
671
	}
672
673
}
674
675
// Log the user in and go to Website Baker Administration
676
$thisApp = new Login(
677
							array(
678
									"MAX_ATTEMPS" => "50",
679
									"WARNING_URL" => ADMIN_URL."/login/warning.html",
680
									"USERNAME_FIELDNAME" => 'admin_username',
681
									"PASSWORD_FIELDNAME" => 'admin_password',
682
									"REMEMBER_ME_OPTION" => SMART_LOGIN,
683
									"MIN_USERNAME_LEN" => "2",
684
									"MIN_PASSWORD_LEN" => "2",
685
									"MAX_USERNAME_LEN" => "30",
686
									"MAX_PASSWORD_LEN" => "30",
687
									'LOGIN_URL' => ADMIN_URL."/login/index.php",
688
									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
689
									'TEMPLATE_DIR' => ADMIN_PATH."/login",
690
									'TEMPLATE_FILE' => "template.html",
691
									'FRONTEND' => false,
692
									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
693
									'USERS_TABLE' => TABLE_PREFIX."users",
694
									'GROUPS_TABLE' => TABLE_PREFIX."groups",
695
							)
696
					);
697
?>