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