Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         install
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version      	$Id: save.php 1687 2012-05-07 15:00:23Z darkviper $
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date: $
16
 *
17
 */
18

    
19
$debug = true;
20

    
21
if (true === $debug) {
22
	ini_set('display_errors', 1);
23
	error_reporting(E_ALL);
24
}
25
// Start a session
26
if(!defined('SESSION_STARTED')) {
27
	session_name('wb_session_id');
28
	session_start();
29
	define('SESSION_STARTED', true);
30
}
31
// get random-part for session_name()
32
list($usec,$sec) = explode(' ',microtime());
33
srand((float)$sec+((float)$usec*100000));
34
$session_rand = rand(1000,9999);
35
if(!class_exists('WbAutoloader', false)) {
36
	include(dirname(dirname(__FILE__)).'/framework/WbAutoloader.php');
37
}
38
WbAutoloader::doRegister(array('admin'=>'a', 'modules'=>'m'));
39

    
40
// Function to set error
41
function set_error($message, $field_name = '') {
42
	global $_POST;
43
	if(isset($message) AND $message != '') {
44
		// Copy values entered into session so user doesn't have to re-enter everything
45
		if(isset($_POST['website_title'])) {
46
			$_SESSION['wb_url'] = $_POST['wb_url'];
47
			$_SESSION['default_timezone'] = $_POST['default_timezone'];
48
			$_SESSION['default_language'] = $_POST['default_language'];
49
			if(!isset($_POST['operating_system'])) {
50
				$_SESSION['operating_system'] = 'linux';
51
			} else {
52
				$_SESSION['operating_system'] = $_POST['operating_system'];
53
			}
54
			if(!isset($_POST['world_writeable'])) {
55
				$_SESSION['world_writeable'] = false;
56
			} else {
57
				$_SESSION['world_writeable'] = true;
58
			}
59
			$_SESSION['database_host'] = $_POST['database_host'];
60
			$_SESSION['database_username'] = $_POST['database_username'];
61
			$_SESSION['database_password'] = $_POST['database_password'];
62
			$_SESSION['database_name'] = $_POST['database_name'];
63
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
64
			if(!isset($_POST['install_tables'])) {
65
				$_SESSION['install_tables'] = false;
66
			} else {
67
				$_SESSION['install_tables'] = true;
68
			}
69
			$_SESSION['website_title'] = $_POST['website_title'];
70
			$_SESSION['admin_username'] = $_POST['admin_username'];
71
			$_SESSION['admin_email'] = $_POST['admin_email'];
72
			$_SESSION['admin_password'] = $_POST['admin_password'];
73
			$_SESSION['admin_repassword'] = $_POST['admin_repassword'];
74
		}
75
		// Set the message
76
		$_SESSION['message'] = $message;
77
		// Set the element(s) to highlight
78
		if($field_name != '') {
79
			$_SESSION['ERROR_FIELD'] = $field_name;
80
		}
81
		// Specify that session support is enabled
82
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
83
		// Redirect to first page again and exit
84
		header('Location: index.php?sessions_checked=true');
85
		exit();
86
	}
87
}
88
/* */
89

    
90
// Function to workout what the default permissions are for files created by the webserver
91
function default_file_mode($temp_dir) {
92
	$v = explode(".",PHP_VERSION);
93
	$v = $v[0].$v[1];
94
	if($v > 41 AND is_writable($temp_dir)) {
95
		$filename = $temp_dir.'/test_permissions.txt';
96
		$handle = fopen($filename, 'w');
97
		fwrite($handle, 'This file is to get the default file permissions');
98
		fclose($handle);
99
		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
100
		unlink($filename);
101
	} else {
102
		$default_file_mode = '0777';
103
	}
104
	return $default_file_mode;
105
}
106

    
107
// Function to workout what the default permissions are for directories created by the webserver
108
function default_dir_mode($temp_dir) {
109
	$v = explode(".",PHP_VERSION);
110
	$v = $v[0].$v[1];
111
	if($v > 41 AND is_writable($temp_dir)) {
112
		$dirname = $temp_dir.'/test_permissions/';
113
		mkdir($dirname);
114
		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
115
		rmdir($dirname);
116
	} else {
117
		$default_dir_mode = '0777';
118
	}
119
	return $default_dir_mode;
120
}
121

    
122
function add_slashes($input) {
123
	if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
124
		return $input;
125
	}
126
	$output = addslashes($input);
127
	return $output;
128
}
129

    
130
// Begin check to see if form was even submitted
131
// Set error if no post vars found
132
if(!isset($_POST['website_title'])) {
133
	set_error('Please fill-in the form below');
134
}
135
// End check to see if form was even submitted
136

    
137
// Begin path and timezone details code
138

    
139
// Check if user has entered the installation url
140
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
141
	set_error('Please enter an absolute URL', 'wb_url');
142
} else {
143
	$wb_url = $_POST['wb_url'];
144
}
145
// Remove any slashes at the end of the URL
146
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
147
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
148
}
149
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
150
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
151
}
152
if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
153
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
154
}
155
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
156
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
157
}
158
// Get the default time zone
159
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
160
	set_error('Please select a valid default timezone', 'default_timezone');
161
} else {
162
	$default_timezone = $_POST['default_timezone']*60*60;
163
}
164
// End path and timezone details code
165

    
166
// Get the default language
167
$allowed_languages = array('BG','CA', 'CS', 'DA', 'DE', 'EN', 'ES', 'ET', 'FI', 'FR', 'HR', 'HU', 'IT', 'LV', 'NL', 'NO', 'PL', 'PT', 'RU','SE','SK','TR');
168
if(!isset($_POST['default_language']) OR !in_array($_POST['default_language'], $allowed_languages)) {
169
	set_error('Please select a valid default backend language','default_language');
170
} else {
171
	$default_language = $_POST['default_language'];
172
	// make sure the selected language file exists in the language folder
173
	if(!file_exists('../languages/' .$default_language .'.php')) {
174
		set_error('The language file: \'' .$default_language .'.php\' is missing. Upload file to language folder or choose another language','default_language');
175
	}
176
}
177
// End default language details code
178

    
179
// Begin operating system specific code
180
// Get operating system
181
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
182
	set_error('Please select a valid operating system');
183
} else {
184
	$operating_system = $_POST['operating_system'];
185
}
186
// Work-out file permissions
187
if($operating_system == 'windows') {
188
	$file_mode = '0777';
189
	$dir_mode = '0777';
190
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
191
	$file_mode = '0777';
192
	$dir_mode = '0777';
193
} else {
194
	$file_mode = default_file_mode('../temp');
195
	$dir_mode = default_dir_mode('../temp');
196
}
197
// End operating system specific code
198

    
199
// Begin database details code
200
// Check if user has entered a database host
201
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
202
	set_error('Please enter a database host name', 'database_host');
203
} else {
204
	$database_host = $_POST['database_host'];
205
}
206
// Check if user has entered a database username
207
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
208
	set_error('Please enter a database username','database_username');
209
} else {
210
	$database_username = $_POST['database_username'];
211
}
212
// Check if user has entered a database password
213
if(!isset($_POST['database_password'])) {
214
	set_error('Please enter a database password', 'database_password');
215
} else {
216
	$database_password = $_POST['database_password'];
217
}
218
// Check if user has entered a database name
219
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
220
	set_error('Please enter a database name', 'database_name');
221
} else {
222
	// make sure only allowed characters are specified
223
	if(preg_match('/[^a-z0-9_-]+/i', $_POST['database_name'])) {
224
		// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
225
		set_error('Only characters a-z, A-Z, 0-9, - and _ allowed in database name.', 'database_name');
226
	}
227
	$database_name = $_POST['database_name'];
228
}
229
// Get table prefix
230
if(preg_match('/[^a-z0-9_]+/i', $_POST['table_prefix'])) {
231
	// contains invalid characters (only a-z, A-Z, 0-9 and _ allowed to avoid problems with table/field names)
232
	set_error('Only characters a-z, A-Z, 0-9 and _ allowed in table_prefix.', 'table_prefix');
233
} else {
234
	$table_prefix = $_POST['table_prefix'];
235
}
236

    
237
// Find out if the user wants to install tables and data
238
$install_tables ((isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true'));
239
// End database details code
240

    
241
// Begin website title code
242
// Get website title
243
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
244
	set_error('Please enter a website title', 'website_title');
245
} else {
246
	$website_title = add_slashes($_POST['website_title']);
247
}
248
// End website title code
249

    
250
// Begin admin user details code
251
// Get admin username
252
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
253
	set_error('Please enter a username for the Administrator account','admin_username');
254
} else {
255
	$admin_username = $_POST['admin_username'];
256
}
257
// Get admin email and validate it
258
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
259
	set_error('Please enter an email for the Administrator account','admin_email');
260
} else {
261
	if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i', $_POST['admin_email'])) {
262
		$admin_email = $_POST['admin_email'];
263
	} else {
264
		set_error('Please enter a valid email address for the Administrator account','admin_email');
265
	}
266
}
267
// Get the two admin passwords entered, and check that they match
268
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
269
	set_error('Please enter a password for the Administrator account','admin_password');
270
} else {
271
	$admin_password = $_POST['admin_password'];
272
}
273
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
274
	set_error('Please make sure you re-enter the password for the Administrator account','admin_repassword');
275
} else {
276
	$admin_repassword = $_POST['admin_repassword'];
277
}
278
if($admin_password != $admin_repassword) {
279
	set_error('Sorry, the two Administrator account passwords you entered do not match','admin_repassword');
280
}
281
// End admin user details code
282

    
283
// Try and write settings to config file
284
$config_content = "" .
285
"<?php\n".
286
"\n".
287
"define('DEBUG', false);\n".
288
"define('DB_TYPE', 'mysql');\n".
289
"define('DB_HOST', '$database_host');\n".
290
"define('DB_NAME', '$database_name');\n".
291
"define('DB_USERNAME', '$database_username');\n".
292
"define('DB_PASSWORD', '$database_password');\n".
293
"define('TABLE_PREFIX', '$table_prefix');\n".
294
"\n".
295
"define('WB_URL', '$wb_url');\n".
296
"define('ADMIN_DIRECTORY', 'admin'); // no leading/trailing slash or backslash!! A simple directory only!!\n".
297
"\n".
298
"require_once(dirname(__FILE__).'/framework/initialize.php');\n".
299
"\n";
300

    
301
$config_filename = '../config.php';
302
// Check if the file exists and is writable first.
303
if(file_exists($config_filename) AND is_writable($config_filename)) {
304
	if(!$handle = fopen($config_filename, 'w')) {
305
		set_error("Cannot open the configuration file ($config_filename)");
306
	} else {
307
		if (fwrite($handle, $config_content) === FALSE) {
308
			set_error("Cannot write to the configuration file ($config_filename)");
309
		}
310
		// Close file
311
		fclose($handle);
312
	}
313
} else {
314
	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
315
}
316

    
317
// Define configuration vars
318
define('DEBUG', false);
319
define('DB_TYPE', 'mysql');
320
define('DB_HOST', $database_host);
321
define('DB_NAME', $database_name);
322
define('DB_USERNAME', $database_username);
323
define('DB_PASSWORD', $database_password);
324
define('TABLE_PREFIX', $table_prefix);
325
define('WB_PATH', dirname(dirname(__FILE__)));
326
define('WB_URL', $wb_url);
327
define('ADMIN_DIRECTORY', 'admin');
328
define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
329
define('ADMIN_URL', $wb_url.'/'.ADMIN_DIRECTORY);
330

    
331
// Check if the user has entered a correct path
332
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
333
	set_error('It appears the Absolute path that you entered is incorrect');
334
}
335
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
336
	$database = WbDatabase::getInstance();
337
	$database->doConnect($sSqlUrl);
338

    
339
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
340
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
341
	require_once($sSecMod);
342
	require_once(WB_PATH.'/framework/class.admin.php');
343

    
344
// Dummy class to allow modules' install scripts to call $admin->print_error
345
	class admin_dummy extends admin
346
	{
347
		var $error='';
348
		function print_error($message, $link = 'index.php', $auto_footer = true)
349
		{
350
			$this->error=$message;
351
		}
352
	}
353
// Include WB functions file
354
	require_once(WB_PATH.'/framework/functions.php');
355
// Re-connect to the database, this time using in-build database class
356
	require_once(WB_PATH.'/framework/class.login.php');
357
// Check if we should install tables
358

    
359
	$sql = 'SHOW TABLES LIKE \''.str_replace('_', '\_', TABLE_PREFIX).'%\'';
360
	$aTables = array();
361
	if(($oTables = $database->query($sql))) {
362
		while($aTable = $oTables->fetchRow()) {
363
			$aTables[] = $aTable[0];
364
		}
365
	}
366
	$sTableList = implode(', ', $aTables);
367
	if($sTableList != '') {
368
		$database->query('DROP TABLE '.$sTableList);
369
	}
370
	// Try installing tables
371
	// Pages table
372
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
373
				. ' `parent` INT NOT NULL DEFAULT \'0\','
374
				. ' `root_parent` INT NOT NULL DEFAULT \'0\','
375
				. ' `level` INT NOT NULL DEFAULT \'0\','
376
				. ' `link` VARCHAR( 255 ) NOT NULL,'
377
				. ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
378
				. ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
379
				. ' `page_icon` VARCHAR( 512 ) NOT NULL DEFAULT \'\' ,'
380
				. ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
381
				. ' `menu_icon_0` VARCHAR( 512 ) NOT NULL DEFAULT \'\' ,'
382
				. ' `menu_icon_1` VARCHAR( 512 ) NOT NULL DEFAULT \'\' ,'
383
				. ' `tooltip` VARCHAR( 512 ) NOT NULL DEFAULT \'\' ,'
384
				. ' `description` TEXT NOT NULL ,'
385
				. ' `keywords` TEXT NOT NULL ,'
386
				. ' `page_trail` VARCHAR( 255 ) NOT NULL  ,'
387
				. ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
388
				. ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
389
				. ' `position` INT NOT NULL DEFAULT \'0\','
390
				. ' `menu` INT NOT NULL DEFAULT \'0\','
391
				. ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
392
				. ' `page_code` INT NOT NULL DEFAULT \'0\','
393
				. ' `searching` INT NOT NULL DEFAULT \'0\','
394
				. ' `admin_groups` VARCHAR( 512 ) NOT NULL DEFAULT \'1\' ,'
395
				. ' `admin_users` VARCHAR( 512 ) NOT NULL ,'
396
				. ' `viewing_groups` VARCHAR( 512 ) NOT NULL DEFAULT \'1\' ,'
397
				. ' `viewing_users` VARCHAR( 512 ) NOT NULL ,'
398
				. ' `modified_when` INT NOT NULL DEFAULT \'0\','
399
				. ' `modified_by` INT NOT NULL  DEFAULT \'0\','
400
				. ' PRIMARY KEY ( `page_id` ) '
401
				. ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
402
	if(!$database->query($pages)) {
403
	}
404

    
405
	// Sections table
406
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
407
	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
408
	       . ' `position` INT NOT NULL DEFAULT \'0\','
409
	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
410
	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
411
	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
412
	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
413
	       . ' PRIMARY KEY ( `section_id` ) '
414
	       . ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
415
	$database->query($pages);
416

    
417
	require(ADMIN_PATH.'/interface/version.php');
418

    
419
	// Settings table
420
	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
421
		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
422
		. ' `value` TEXT NOT NULL ,'
423
		. ' PRIMARY KEY ( `setting_id` ) '
424
		. ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
425
	$database->query($settings);
426

    
427
	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
428
	." (name, value) VALUES "
429
	." ('wb_version', '".VERSION."'),"
430
	." ('wb_revision', '".REVISION."'),"
431
 	." ('wb_sp', '".SP."'),"
432
	." ('website_title', '$website_title'),"
433
	." ('website_description', ''),"
434
	." ('website_keywords', ''),"
435
	." ('website_header', ''),"
436
	." ('website_footer', ''),"
437
	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
438
	." ('er_level', ''),"
439
	." ('default_language', '$default_language'),"
440
	." ('app_name', 'wb_$session_rand'),"
441
	." ('sec_anchor', 'wb_'),"
442
	." ('default_timezone', '$default_timezone'),"
443
	." ('default_date_format', 'M d Y'),"
444
	." ('default_time_format', 'g:i A'),"
445
	." ('redirect_timer', '1500'),"
446
	." ('home_folders', 'true'),"
447
	." ('warn_page_leave', '1'),"
448
	." ('default_template', 'round'),"
449
	." ('default_theme', 'wb_theme'),"
450
	." ('default_charset', 'utf-8'),"
451
	." ('multiple_menus', 'true'),"
452
	." ('page_level_limit', '4'),"
453
	." ('intro_page', 'false'),"
454
	." ('page_trash', 'inline'),"
455
	." ('homepage_redirection', 'false'),"
456
	." ('page_languages', 'true'),"
457
	." ('wysiwyg_editor', 'fckeditor'),"
458
	." ('manage_sections', 'true'),"
459
	." ('section_blocks', 'true'),"
460
	." ('smart_login', 'false'),"
461
	." ('frontend_login', 'false'),"
462
	." ('frontend_signup', 'false'),"
463
	." ('search', 'public'),"
464
	." ('page_extension', '.php'),"
465
	." ('page_spacer', '-'),"
466
	." ('dev_infos', 'false'),"
467
	." ('pages_directory', '/pages'),"
468
	." ('page_icon_dir', '/templates/*/title_images'),"
469
	." ('rename_files_on_upload', 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx'),"
470
	." ('media_directory', '/media'),"
471
	." ('operating_system', '$operating_system'),"
472
	." ('string_file_mode', '$file_mode'),"
473
	." ('string_dir_mode', '$dir_mode'),"
474
	." ('wbmailer_routine', 'phpmail'),"
475
	." ('server_email', '$admin_email'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
476
	." ('wbmailer_default_sendername', 'WB Mailer'),"
477
	." ('wbmailer_smtp_host', ''),"
478
	." ('wbmailer_smtp_auth', ''),"
479
	." ('wbmailer_smtp_username', ''),"
480
	." ('wbmailer_smtp_password', ''),"
481
	." ('fingerprint_with_ip_octets', '2'),"
482
	." ('secure_form_module', ''),"
483
	." ('mediasettings', '')";
484
	$database->query($settings_rows);
485

    
486
	// Users table
487
	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
488
	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
489
	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
490
	       . ' `active` INT NOT NULL DEFAULT \'0\','
491
	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
492
	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
493
	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
494
	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
495
	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
496
	       . ' `email` TEXT NOT NULL ,'
497
	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
498
	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
499
	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
500
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'' .$default_language .'\' ,'
501
	       . ' `home_folder` TEXT NOT NULL ,'
502
	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
503
	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
504
	       . ' PRIMARY KEY ( `user_id` ) '
505
	       . ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
506
	$database->query($users);
507

    
508
	// Groups table
509
	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
510
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
511
	        . ' `system_permissions` TEXT NOT NULL ,'
512
	        . ' `module_permissions` TEXT NOT NULL ,'
513
	        . ' `template_permissions` TEXT NOT NULL ,'
514
	        . ' PRIMARY KEY ( `group_id` ) '
515
	        . ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
516
	$database->query($groups);
517

    
518
	// Search settings table
519
	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
520
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
521
	        . ' `value` TEXT NOT NULL ,'
522
	        . ' `extra` TEXT NOT NULL ,'
523
	        . ' PRIMARY KEY ( `search_id` ) '
524
	        . ' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
525
	$database->query($search);
526

    
527
	// Addons table
528
	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
529
			.'`addon_id` INT NOT NULL auto_increment ,'
530
			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
531
			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
532
			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
533
			.'`description` TEXT NOT NULL ,'
534
			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
535
			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
536
			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
537
			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
538
			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
539
			.' PRIMARY KEY ( `addon_id` ) '
540
			.' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
541
	$database->query($addons);
542

    
543
	// Insert default data
544

    
545
	// Admin group
546
	$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';
547
	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
548
	$database->query($insert_admin_group);
549
	// Admin user
550
	$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')";
551
	$database->query($insert_admin_user);
552

    
553
	// Search header
554
	$search_header = addslashes('
555
<h1>[TEXT_SEARCH]</h1>
556

    
557
<form name="searchpage" action="[WB_URL]/search/index.php" method="get">
558
<table cellpadding="3" cellspacing="0" border="0" width="500">
559
<tr>
560
<td>
561
<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
562
<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
563
</td>
564
<td width="150">
565
<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
566
</td>
567
</tr>
568
<tr>
569
<td colspan="2">
570
<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
571
<label for="match_all">[TEXT_ALL_WORDS]</label>
572
<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
573
<label for="match_any">[TEXT_ANY_WORDS]</label>
574
<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
575
<label for="match_exact">[TEXT_EXACT_MATCH]</label>
576
</td>
577
</tr>
578
</table>
579

    
580
</form>
581

    
582
<hr />
583
	');
584
	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
585
	$database->query($insert_search_header);
586
	// Search footer
587
	$search_footer = addslashes('');
588
	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
589
	$database->query($insert_search_footer);
590
	// Search results header
591
	$search_results_header = addslashes(''.
592
'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
593
<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
594
	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
595
	$database->query($insert_search_results_header);
596
	// Search results loop
597
	$search_results_loop = addslashes(''.
598
'<tr style="background-color: #F0F0F0;">
599
<td><a href="[LINK]">[TITLE]</a></td>
600
<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
601
</tr>
602
<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
603
<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
604

    
605
	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
606
	$database->query($insert_search_results_loop);
607
	// Search results footer
608
	$search_results_footer = addslashes("</table>");
609
	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
610
	$database->query($insert_search_results_footer);
611
	// Search no results
612
	$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
613
	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
614
	$database->query($insert_search_no_results);
615
	// Search module-order
616
	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
617
	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
618
	$database->query($insert_search_module_order);
619
	// Search max lines of excerpt
620
	$search_max_excerpt = addslashes('15');
621
	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
622
	$database->query($insert_search_max_excerpt);
623
	// max time to search per module
624
	$search_time_limit = addslashes('0');
625
	$insert_search_time_limit = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'time_limit', '$search_time_limit', '')";
626
	$database->query($insert_search_time_limit);
627
	// some config-elements
628
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
629
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
630
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
631
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
632
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_flush', 'false', '')");
633
	// Search template
634
	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
635

    
636
	require_once(WB_PATH.'/framework/initialize.php');
637
	// Include the PclZip class file (thanks to
638
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
639
	// Install add-ons
640
	if(file_exists(WB_PATH.'/install/modules')) {
641
		// Unpack pre-packaged modules
642
	}
643
	if(file_exists(WB_PATH.'/install/templates')) {
644
		// Unpack pre-packaged templates
645
	}
646
	if(file_exists(WB_PATH.'/install/languages')) {
647
		// Unpack pre-packaged languages
648
	}
649
	$admin=new admin_dummy('Start','',false,false);
650
	// Load addons into DB
651
	$dirs['modules'] = WB_PATH.'/modules/';
652
	$dirs['templates'] = WB_PATH.'/templates/';
653
	$dirs['languages'] = WB_PATH.'/languages/';
654

    
655
	foreach($dirs AS $type => $dir) {
656
		if(($handle = opendir($dir))) {
657
			while(false !== ($file = readdir($handle))) {
658
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
659
					// Get addon type
660
					if($type == 'modules') {
661
						load_module($dir.'/'.$file, true);
662
						// Pretty ugly hack to let modules run $admin->set_error
663
						// See dummy class definition admin_dummy above
664
						if ($admin->error!='') {
665
							set_error($admin->error);
666
						}
667
					} elseif($type == 'templates') {
668
						load_template($dir.'/'.$file);
669
					} elseif($type == 'languages') {
670
						load_language($dir.'/'.$file);
671
					}
672
				}
673
			}
674
			closedir($handle);
675
		}
676
	}
677

    
678
	// Check if there was a database error
679
	if($database->is_error()) {
680
		set_error($database->get_error());
681
	}
682

    
683
// end of if install_tables
684

    
685
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
686
// Setup template object, parse vars to it, then parse it
687
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('login.htt'));
688

    
689
// Log the user in and go to Website Baker Administration
690
$thisApp = new Login(
691
		array(
692
				"MAX_ATTEMPS" => "50",
693
				"WARNING_URL" => $ThemeUrl."/warning.html",
694
				"USERNAME_FIELDNAME" => 'admin_username',
695
				"PASSWORD_FIELDNAME" => 'admin_password',
696
				"REMEMBER_ME_OPTION" => SMART_LOGIN,
697
				"MIN_USERNAME_LEN" => "2",
698
				"MIN_PASSWORD_LEN" => "3",
699
				"MAX_USERNAME_LEN" => "30",
700
				"MAX_PASSWORD_LEN" => "30",
701
				'LOGIN_URL' => ADMIN_URL."/login/index.php",
702
				'DEFAULT_URL' => ADMIN_URL."/start/index.php",
703
				'TEMPLATE_DIR' => $ThemePath,
704
				'TEMPLATE_FILE' => 'login.htt',
705
				'FRONTEND' => false,
706
				'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
707
				'USERS_TABLE' => TABLE_PREFIX."users",
708
				'GROUPS_TABLE' => TABLE_PREFIX."groups",
709
		)
710
);
(4-4/5)