Project

General

Profile

1
<?php
2

    
3
// $Id: save.php 581 2008-01-21 01:33:55Z thorn $
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
	// get random-part for session_name()
29
	list($usec,$sec) = explode(' ',microtime());
30
	srand((float)$sec+((float)$usec*100000));
31
	$session_rand = rand(1000,9999);
32
	session_name("wb_{$session_rand}_session_id");
33
	session_start();
34
	$_SESSION['SESSION_RAND'] = $session_rand;
35
	define('SESSION_STARTED', true);
36
} else {
37
	$session_rand = $_SESSION['SESSION_RAND'];
38
}
39

    
40
// Function to set error
41
function set_error($message) {
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
			if(!isset($_POST['operating_system'])) {
49
				$_SESSION['operating_system'] = 'linux';
50
			} else {
51
				$_SESSION['operating_system'] = $_POST['operating_system'];
52
			}
53
			if(!isset($_POST['world_writeable'])) {
54
				$_SESSION['world_writeable'] = false;
55
			} else {
56
				$_SESSION['world_writeable'] = true;
57
			}
58
			$_SESSION['database_host'] = $_POST['database_host'];
59
			$_SESSION['database_username'] = $_POST['database_username'];
60
			$_SESSION['database_password'] = $_POST['database_password'];
61
			$_SESSION['database_name'] = $_POST['database_name'];
62
			$_SESSION['table_prefix'] = $_POST['table_prefix'];
63
			if(!isset($_POST['install_tables'])) {
64
				$_SESSION['install_tables'] = false;
65
			} else {
66
				$_SESSION['install_tables'] = true;
67
			}
68
			$_SESSION['website_title'] = $_POST['website_title'];
69
			$_SESSION['admin_username'] = $_POST['admin_username'];
70
			$_SESSION['admin_email'] = $_POST['admin_email'];
71
			$_SESSION['admin_password'] = $_POST['admin_password'];
72
		}
73
		// Set the message
74
		$_SESSION['message'] = $message;
75
		// Specify that session support is enabled
76
		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
77
		// Redirect to first page again and exit
78
		header('Location: index.php?sessions_checked=true');
79
		exit();
80
	}
81
}
82

    
83
// Dummy class to allow modules' install scripts to call $admin->print_error
84
class admin_dummy
85
{
86
	var $error='';
87
	function print_error($message)
88
	{
89
		$this->error=$message;
90
	}
91
}
92

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

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

    
125
function add_slashes($input) {
126
		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
127
			return $input;
128
		}
129
		$output = addslashes($input);
130
		return $output;
131
	}
132

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

    
140
// Begin path and timezone details code
141

    
142
// Check if user has entered the installation url
143
if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
144
	set_error('Please enter an absolute URL');
145
} else {
146
	$wb_url = $_POST['wb_url'];
147
}
148
// Remove any slashes at the end of the URL
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
if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
159
	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
160
}
161
// Get the default time zone
162
if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
163
	set_error('Please select a valid default timezone');
164
} else {
165
	$default_timezone = $_POST['default_timezone']*60*60;
166
}
167
// End path and timezone details code
168

    
169
// Begin operating system specific code
170
// Get operating system
171
if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
172
	set_error('Please select a valid operating system');
173
} else {
174
	$operating_system = $_POST['operating_system'];
175
}
176
// Work-out file permissions
177
if($operating_system == 'windows') {
178
	$file_mode = '0777';
179
	$dir_mode = '0777';
180
} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
181
	$file_mode = '0777';
182
	$dir_mode = '0777';
183
} else {
184
	$file_mode = default_file_mode('../temp');
185
	$dir_mode = default_dir_mode('../temp');
186
}
187
// End operating system specific code
188

    
189
// Begin database details code
190
// Check if user has entered a database host
191
if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
192
	set_error('Please enter a database host name');
193
} else {
194
	$database_host = $_POST['database_host'];
195
}
196
// Check if user has entered a database username
197
if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
198
	set_error('Please enter a database username');
199
} else {
200
	$database_username = $_POST['database_username'];
201
}
202
// Check if user has entered a database password
203
if(!isset($_POST['database_password'])) {
204
	set_error('Please enter a database password');
205
} else {
206
	$database_password = $_POST['database_password'];
207
}
208
// Check if user has entered a database name
209
if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
210
	set_error('Please enter a database name');
211
} else {
212
	$database_name = $_POST['database_name'];
213
}
214
// Get table prefix
215
$table_prefix = $_POST['table_prefix'];
216
// Find out if the user wants to install tables and data
217
if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
218
	$install_tables = true;
219
} else {
220
	$install_tables = false;
221
}
222
// End database details code
223

    
224
// Begin website title code
225
// Get website title
226
if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
227
	set_error('Please enter a website title');
228
} else {
229
	$website_title = add_slashes($_POST['website_title']);
230
}
231
// End website title code
232

    
233
// Begin admin user details code
234
// Get admin username
235
if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
236
	set_error('Please enter a username for the Administrator account');
237
} else {
238
	$admin_username = $_POST['admin_username'];
239
}
240
// Get admin email and validate it
241
if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
242
	set_error('Please enter an email for the Administrator account');
243
} else {
244
	if(eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['admin_email'])) {
245
		$admin_email = $_POST['admin_email'];
246
	} else {
247
		set_error('Please enter a valid email address for the Administrator account');
248
	}
249
}
250
// Get the two admin passwords entered, and check that they match
251
if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
252
	set_error('Please enter a password for the Administrator account');
253
} else {
254
	$admin_password = $_POST['admin_password'];
255
}
256
if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
257
	set_error('Please make sure you re-enter the password for the Administrator account');
258
} else {
259
	$admin_repassword = $_POST['admin_repassword'];
260
}
261
if($admin_password != $admin_repassword) {
262
	set_error('Sorry, the two Administrator account passwords you entered do not match');
263
}
264
// End admin user details code
265

    
266
// Try and write settings to config file
267
$config_content = "" .
268
"<?php\n".
269
"\n".
270
"define('DB_TYPE', 'mysql');\n".
271
"define('DB_HOST', '$database_host');\n".
272
"define('DB_USERNAME', '$database_username');\n".
273
"define('DB_PASSWORD', '$database_password');\n".
274
"define('DB_NAME', '$database_name');\n".
275
"define('TABLE_PREFIX', '$table_prefix');\n".
276
"\n".
277
"define('WB_PATH', dirname(__FILE__));\n".
278
"define('WB_URL', '$wb_url');\n".
279
"define('ADMIN_PATH', WB_PATH.'/admin');\n".
280
"define('ADMIN_URL', '$wb_url/admin');\n".
281
"\n".
282
"require_once(WB_PATH.'/framework/initialize.php');\n".
283
"\n".
284
"?>";
285

    
286
$config_filename = '../config.php';
287

    
288
// Check if the file exists and is writable first.
289
if(file_exists($config_filename) AND is_writable($config_filename)) {
290
	if(!$handle = fopen($config_filename, 'w')) {
291
		set_error("Cannot open the configuration file ($config_filename)");
292
	} else {
293
		if (fwrite($handle, $config_content) === FALSE) {
294
			set_error("Cannot write to the configuration file ($config_filename)");
295
		}
296
		// Close file
297
		fclose($handle);
298
	}
299
} else {
300
	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
301
}
302

    
303
// Define configuration vars
304
define('DB_TYPE', 'mysql');
305
define('DB_HOST', $database_host);
306
define('DB_USERNAME', $database_username);
307
define('DB_PASSWORD', $database_password);
308
define('DB_NAME', $database_name);
309
define('TABLE_PREFIX', $table_prefix);
310
define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
311
define('WB_URL', $wb_url);
312
define('ADMIN_PATH', WB_PATH.'/admin');
313
define('ADMIN_URL', $wb_url.'/admin');
314

    
315
// Check if the user has entered a correct path
316
if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
317
	set_error('It appears the Absolute path that you entered is incorrect');
318
}
319

    
320
// Try connecting to database	
321
if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
322
	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
323
}
324

    
325
// Try to create the database
326
mysql_query('CREATE DATABASE '.$database_name);
327

    
328
// Close the mysql connection
329
mysql_close();
330

    
331
// Include WB functions file
332
require_once(WB_PATH.'/framework/functions.php');
333

    
334
// Re-connect to the database, this time using in-build database class
335
require_once(WB_PATH.'/framework/class.login.php');
336
$database=new database();
337

    
338
// Check if we should install tables
339
if($install_tables == true) {
340
	
341
	// Remove tables if they exist
342

    
343
	// Pages table
344
	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
345
	$database->query($pages);
346
	// Sections table
347
	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
348
	$database->query($sections);
349
	// Settings table
350
	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
351
	$database->query($settings);
352
	// Users table
353
	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
354
	$database->query($users);
355
	// Groups table
356
	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
357
	$database->query($groups);
358
	// Search table
359
	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
360
	$database->query($search);
361
	// Addons table
362
	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
363
	$database->query($addons);
364
				
365
	// Try installing tables
366
	
367
	// Pages table
368
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
369
	       . ' `parent` INT NOT NULL DEFAULT \'0\','
370
	       . ' `root_parent` INT NOT NULL DEFAULT \'0\','
371
	       . ' `level` INT NOT NULL DEFAULT \'0\','
372
	       . ' `link` TEXT NOT NULL,'
373
	       . ' `target` VARCHAR( 7 ) NOT NULL DEFAULT \'\' ,'
374
	       . ' `page_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
375
	       . ' `menu_title` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
376
	       . ' `description` TEXT NOT NULL ,'
377
	       . ' `keywords` TEXT NOT NULL ,'
378
	       . ' `page_trail` TEXT NOT NULL  ,'
379
	       . ' `template` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
380
	       . ' `visibility` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
381
	       . ' `position` INT NOT NULL DEFAULT \'0\','
382
	       . ' `menu` INT NOT NULL DEFAULT \'0\','
383
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
384
	       . ' `searching` INT NOT NULL DEFAULT \'0\','
385
	       . ' `admin_groups` TEXT NOT NULL ,'
386
	       . ' `admin_users` TEXT NOT NULL ,'
387
	       . ' `viewing_groups` TEXT NOT NULL ,'
388
	       . ' `viewing_users` TEXT NOT NULL ,'
389
	       . ' `modified_when` INT NOT NULL DEFAULT \'0\','
390
	       . ' `modified_by` INT NOT NULL  DEFAULT \'0\','
391
	       . ' PRIMARY KEY ( `page_id` ) '
392
	       . ' )';
393
	$database->query($pages);
394
	
395
	// Sections table
396
	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
397
	       . ' `page_id` INT NOT NULL DEFAULT \'0\','
398
	       . ' `position` INT NOT NULL DEFAULT \'0\','
399
	       . ' `module` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
400
	       . ' `block` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
401
	       . ' `publ_start` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,'
402
	       . ' `publ_end` VARCHAR( 255 ) NOT NULL DEFAULT \'0\' ,' 
403
	       . ' PRIMARY KEY ( `section_id` ) '
404
	       . ' )';
405
	$database->query($pages);
406

    
407
	require(WB_PATH.'/admin/interface/version.php');
408
	
409
	// Settings table
410
	$settings='CREATE TABLE `'.TABLE_PREFIX.'settings` ( `setting_id` INT NOT NULL auto_increment,'
411
		. ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
412
		. ' `value` TEXT NOT NULL ,'
413
		. ' PRIMARY KEY ( `setting_id` ) '
414
		. ' )';
415
	$database->query($settings);
416

    
417
	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` "
418
	." (name, value) VALUES "
419
	." ('wb_version', '".VERSION."'),"
420
	." ('website_title', '$website_title'),"
421
	." ('website_description', ''),"
422
	." ('website_keywords', ''),"
423
	." ('website_header', ''),"
424
	." ('website_footer', ''),"
425
	." ('wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
426
	." ('rename_files_on_upload', 'php,asp,phpx,aspx'),"
427
	." ('er_level', ''),"
428
	." ('default_language', 'EN'),"
429
	." ('app_name', 'wb_$session_rand'),"
430
	." ('default_timezone', '$default_timezone'),"
431
	." ('default_date_format', 'M d Y'),"
432
	." ('default_time_format', 'g:i A'),"
433
	." ('home_folders', 'true'),"
434
	." ('default_template', 'round'),"
435
	." ('default_charset', 'utf-8'),"
436
	." ('multiple_menus', 'false'),"
437
	." ('page_level_limit', '4'),"
438
	." ('intro_page', 'false'),"
439
	." ('page_trash', 'disabled'),"
440
	." ('homepage_redirection', 'false'),"
441
	." ('page_languages', 'false'),"
442
	." ('wysiwyg_editor', 'fckeditor'),"
443
	." ('manage_sections', 'true'),"
444
	." ('section_blocks', 'false'),"
445
	." ('smart_login', 'false'),"
446
	." ('captcha_verification', 'true'),"
447
	." ('frontend_login', 'false'),"
448
	." ('frontend_signup', 'false'),"
449
	." ('search', 'public'),"
450
	." ('page_extension', '.php'),"
451
	." ('page_spacer', '-'),"
452
	." ('pages_directory', '/pages'),"
453
	." ('media_directory', '/media'),"
454
	." ('operating_system', '$operating_system'),"
455
	." ('string_file_mode', '$file_mode'),"
456
	." ('string_dir_mode', '$dir_mode'),"
457
	." ('wbmailer_routine', 'phpmail'),"
458
	." ('server_email', 'admin@yourdomain.com'),"		// avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
459
	." ('wbmailer_default_sendername', 'WB Mailer'),"
460
	." ('wbmailer_smtp_host', ''),"
461
	." ('wbmailer_smtp_auth', ''),"
462
	." ('wbmailer_smtp_username', ''),"
463
	." ('wbmailer_smtp_password', '')";
464
	$database->query($settings_rows);
465
	
466
	// Users table
467
	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
468
	       . ' `group_id` INT NOT NULL DEFAULT \'0\','
469
	       . ' `groups_id` VARCHAR( 255 ) NOT NULL DEFAULT \'0\','
470
	       . ' `active` INT NOT NULL DEFAULT \'0\','
471
	       . ' `username` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
472
	       . ' `password` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
473
	       . ' `remember_key` VARCHAR( 255 ) NOT NULL DEFAULT \'\','
474
	       . ' `last_reset` INT NOT NULL DEFAULT \'0\','
475
	       . ' `display_name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
476
	       . ' `email` TEXT NOT NULL ,'
477
	       . ' `timezone` INT NOT NULL DEFAULT \'0\','
478
	       . ' `date_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
479
	       . ' `time_format` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
480
	       . ' `language` VARCHAR( 5 ) NOT NULL DEFAULT \'\' ,'
481
	       . ' `home_folder` TEXT NOT NULL ,'
482
	       . ' `login_when` INT NOT NULL  DEFAULT \'0\','
483
	       . ' `login_ip` VARCHAR( 15 ) NOT NULL DEFAULT \'\' ,'
484
	       . ' PRIMARY KEY ( `user_id` ) '
485
	       . ' )';
486
	$database->query($users);
487
	
488
	// Groups table
489
	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
490
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
491
	        . ' `system_permissions` TEXT NOT NULL ,'
492
	        . ' `module_permissions` TEXT NOT NULL ,'
493
	        . ' `template_permissions` TEXT NOT NULL ,'
494
	        . ' PRIMARY KEY ( `group_id` ) '
495
	        . ' )';
496
	$database->query($groups);
497
	
498
	// Search settings table
499
	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
500
	        . ' `name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
501
	        . ' `value` TEXT NOT NULL ,'
502
	        . ' `extra` TEXT NOT NULL ,'
503
	        . ' PRIMARY KEY ( `search_id` ) '
504
	        . ' )';
505
	$database->query($search);
506
	
507
	// Addons table
508
	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
509
			.'`addon_id` INT NOT NULL auto_increment ,'
510
			.'`type` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
511
			.'`directory` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
512
			.'`name` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
513
			.'`description` TEXT NOT NULL ,'
514
			.'`function` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
515
			.'`version` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
516
			.'`platform` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
517
			.'`author` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
518
			.'`license` VARCHAR( 255 ) NOT NULL DEFAULT \'\' ,'
519
			.' PRIMARY KEY ( `addon_id` ) '
520
			.' )';
521
	$database->query($addons);
522

    
523
	// Insert default data
524
	
525
	// Admin group
526
	$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';
527
	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
528
	$database->query($insert_admin_group);
529
	// Admin user
530
	$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')";
531
	$database->query($insert_admin_user);
532
	
533
	// Search header
534
	$search_header = addslashes('
535
<h1>[TEXT_SEARCH]</h1>
536

    
537
<form name="search" action="[WB_URL]/search/index.php" method="get">
538
<table cellpadding="3" cellspacing="0" border="0" width="500">
539
<tr>
540
<td>
541
<input type="hidden" name="search_path" value="[SEARCH_PATH]" />
542
<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
543
</td>
544
<td width="150">
545
<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
546
</td>
547
</tr>
548
<tr>
549
<td colspan="2">
550
<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
551
<label for="match_all">[TEXT_ALL_WORDS]</label>
552
<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
553
<label for="match_any">[TEXT_ANY_WORDS]</label>
554
<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
555
<label for="match_exact">[TEXT_EXACT_MATCH]</label>
556
</td>
557
</tr>
558
</table>
559

    
560
</form>
561

    
562
<hr />
563
	');
564
	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
565
	$database->query($insert_search_header);
566
	// Search footer
567
	$search_footer = addslashes('');
568
	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
569
	$database->query($insert_search_footer);
570
	// Search results header
571
	$search_results_header = addslashes(''.
572
'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
573
<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
574
	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
575
	$database->query($insert_search_results_header);
576
	// Search results loop
577
	$search_results_loop = addslashes(''.
578
'<tr style="background-color: #F0F0F0;">
579
<td><a href="[LINK]">[TITLE]</a></td>
580
<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
581
</tr>
582
<tr><td colspan="2" style="text-align: justify; padding-bottom: 5px;">[DESCRIPTION]</td></tr>
583
<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[EXCERPT]</td></tr>');
584

    
585
	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
586
	$database->query($insert_search_results_loop);
587
	// Search results footer
588
	$search_results_footer = addslashes("</table>");
589
	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
590
	$database->query($insert_search_results_footer);
591
	// Search no results
592
	$search_no_results = addslashes('<br />[TEXT_NO_RESULTS]');
593
	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
594
	$database->query($insert_search_no_results);
595
	// Search module-order
596
	$search_module_order = addslashes('faqbaker,manual,wysiwyg');
597
	$insert_search_module_order = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'module_order', '$search_module_order', '')";
598
	$database->query($insert_search_module_order);
599
	// Search max lines of excerpt
600
	$search_max_excerpt = addslashes('15');
601
	$insert_search_max_excerpt = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'max_excerpt', '$search_max_excerpt', '')";
602
	$database->query($insert_search_max_excerpt);
603
	// some config-elements
604
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_enable_old_search', 'true', '')");
605
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_keywords', 'true', '')");
606
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_search_description', 'true', '')");
607
	$database->query("INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'cfg_show_description', 'true', '')");
608
	// Search template
609
	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
610
		
611
	require_once(WB_PATH.'/framework/initialize.php');
612
	
613
	// Include the PclZip class file (thanks to 
614
	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
615
			
616
	// Install add-ons
617
	if(file_exists(WB_PATH.'/install/modules')) {
618
		// Unpack pre-packaged modules
619
			
620
	}
621
	if(file_exists(WB_PATH.'/install/templates')) {
622
		// Unpack pre-packaged templates
623
		
624
	}
625
	if(file_exists(WB_PATH.'/install/languages')) {
626
		// Unpack pre-packaged languages
627
		
628
	}
629
	
630
	$admin=new admin_dummy();
631
	// Load addons into DB
632
	$dirs['modules'] = WB_PATH.'/modules/';
633
	$dirs['templates'] = WB_PATH.'/templates/';
634
	$dirs['languages'] = WB_PATH.'/languages/';
635
	foreach($dirs AS $type => $dir) {
636
		if($handle = opendir($dir)) {
637
			while(false !== ($file = readdir($handle))) {
638
				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
639
					// Get addon type
640
					if($type == 'modules') {
641
						load_module($dir.'/'.$file, true);
642
						// Pretty ugly hack to let modules run $admin->set_error
643
						// See dummy class definition admin_dummy above
644
						if ($admin->error!='') {
645
							set_error($admin->error);
646
						}
647
					} elseif($type == 'templates') {
648
						load_template($dir.'/'.$file);
649
					} elseif($type == 'languages') {
650
						load_language($dir.'/'.$file);
651
					}
652
				}
653
			}
654
		closedir($handle);
655
		}
656
	}
657
	
658
	// Check if there was a database error
659
	if($database->is_error()) {
660
		set_error($database->get_error());
661
	}
662
	
663
}
664

    
665
// Log the user in and go to Website Baker Administration
666
$thisApp = new Login(
667
							array(
668
									"MAX_ATTEMPS" => "50",
669
									"WARNING_URL" => ADMIN_URL."/login/warning.html",
670
									"USERNAME_FIELDNAME" => 'admin_username',
671
									"PASSWORD_FIELDNAME" => 'admin_password',
672
									"REMEMBER_ME_OPTION" => SMART_LOGIN,
673
									"MIN_USERNAME_LEN" => "2",
674
									"MIN_PASSWORD_LEN" => "2",
675
									"MAX_USERNAME_LEN" => "30",
676
									"MAX_PASSWORD_LEN" => "30",
677
									'LOGIN_URL' => ADMIN_URL."/login/index.php",
678
									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
679
									'TEMPLATE_DIR' => ADMIN_PATH."/login",
680
									'TEMPLATE_FILE' => "template.html",
681
									'FRONTEND' => false,
682
									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
683
									'USERS_TABLE' => TABLE_PREFIX."users",
684
									'GROUPS_TABLE' => TABLE_PREFIX."groups",
685
							)
686
					);
687
?>
(2-2/3)