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 1686 2012-05-07 12:31:03Z 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
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
239
	$install_tables = true;
240
} else {
241
	$install_tables = false;
242
}
243
// End database details code
244

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

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

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

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

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

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

    
343
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
344
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
345
	require_once($sSecMod);
346
	require_once(WB_PATH.'/framework/class.admin.php');
347

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

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

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

    
421
	require(ADMIN_PATH.'/interface/version.php');
422

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

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

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

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

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

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

    
547
	// Insert default data
548

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

    
557
	// Search header
558
	$search_header = addslashes('
559
<h1>[TEXT_SEARCH]</h1>
560

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

    
584
</form>
585

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

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

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

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

    
682
	// Check if there was a database error
683
	if($database->is_error()) {
684
		set_error($database->get_error());
685
	}
686

    
687
// end of if install_tables
688

    
689
$ThemeUrl = WB_URL.$admin->correct_theme_source('warning.html');
690
// Setup template object, parse vars to it, then parse it
691
$ThemePath = realpath(WB_PATH.$admin->correct_theme_source('login.htt'));
692

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