Index: trunk/INSTALL
===================================================================
--- trunk/INSTALL	(revision 238)
+++ trunk/INSTALL	(revision 239)
@@ -1,26 +1,26 @@
-Website Baker 2 Installation Instructions
-============================================
-This will quickly explain what you will need
-to install website baker.
-
-First of all, you must have a webserver with
-PHP and MySQL installed correctly. Once you 
-have got that, place the "wb" folder 
-somewhere on your server, probably under the
-document root:
-e.g. /documentroot/wb
-
-This should be accessed by an address 
-something like this:
-e.g. http://localhost/wb/
-
-Now create a blank MySQL database
-(Commonly called "wb").
-
-Once that is all done simple run the
-install script from your browser:
-e.g. http://localhost/wb/install/index.php
-
+Website Baker 2 Installation Instructions
+============================================
+This will quickly explain what you will need
+to install website baker.
+
+First of all, you must have a webserver with
+PHP and MySQL installed correctly. Once you 
+have got that, place the "wb" folder 
+somewhere on your server, probably under the
+document root:
+e.g. /documentroot/wb
+
+This should be accessed by an address 
+something like this:
+e.g. http://localhost/wb/
+
+Now create a blank MySQL database
+(Commonly called "wb").
+
+Once that is all done simple run the
+install script from your browser:
+e.g. http://localhost/wb/install/index.php
+
 Fill-out the form and submit it, and if all
 the details are correct, you should be taken
-to Website Baker Administration.
\ No newline at end of file
+to Website Baker Administration.
Index: trunk/wb/search/search.php
===================================================================
--- trunk/wb/search/search.php	(revision 238)
+++ trunk/wb/search/search.php	(revision 239)
@@ -1,266 +1,266 @@
-<?php
-
-// $Id$
-
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
-
-if(!defined('WB_URL')) { header('Location: index.php'); }
-
-// Check if search is enabled
-if(SHOW_SEARCH != true) {
-	echo $TEXT['SEARCH'].' '.$TEXT['DISABLED'];
-} else {
-	
-	// Make pages_listed and items_listed blank arrays
-	$pages_listed = array();
-	$items_listed = array();
-
-	// Get search string
-	if(isset($_REQUEST['string'])) {
-		if ($_REQUEST['match']!='exact') {
-			$string=str_replace(',', '', $_REQUEST['string']);
-		} else {
-			$string=$_REQUEST['string'];
-		}
-		// reverse potential magic_quotes action
-		$original_string=$wb->strip_slashes($string);
-		// Double backslashes (mySQL needs doubly escaped backslashes in LIKE comparisons)
-		$string = addslashes($wb->escape_backslashes($original_string));
-		// then escape for mySQL query
-		$search_string = htmlspecialchars($original_string,ENT_QUOTES);
-	} else {
-		$string = '';
-		$search_string = '';
-	}
-	
-	// Work-out what to do (match all words, any words, or do exact match), and do relevant with query settings
-	$all_checked = '';
-	$any_checked = '';
-	$exact_checked = '';
-	if($_REQUEST['match'] != 'exact') {
-		// Split string into array with explode() function
-		$exploded_string = explode(' ', $string);
-		// Make sure there is no blank values in the array
-		$string = array();
-		foreach($exploded_string AS $each_exploded_string) {
-			if($each_exploded_string != '') {
-				$string[] = $each_exploded_string;
-			}
-		}
-		if ($_REQUEST['match'] == 'any') {
-			$any_checked = ' checked';
-			$logical_operator = ' OR';
-		} else {
-			$all_checked = ' checked';
-			$logical_operator = ' AND';
-		}
-	} else {
-		$exact_checked = ' checked';
-		$exact_string=$string;
-		$string=array();
-		$string[]=$exact_string;
-	}	
-	// Get list of usernames and display names
-	$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
-	$users = array('0' => array('display_name' => $TEXT['UNKNOWN'], 'username' => strtolower($TEXT['UNKNOWN'])));
-	if($query_users->numRows() > 0) {
-		while($user = $query_users->fetchRow()) {
-			$users[$user['user_id']] = array('display_name' => $user['display_name'], 'username' => $user['username']);
-		}
-	}
-	
-	// Get search settings
-	$query_header = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
-	$fetch_header = $query_header->fetchRow();
-	$query_footer = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'footer' LIMIT 1");
-	$fetch_footer = $query_footer->fetchRow();
-	$query_results_header = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_header' LIMIT 1");
-	$fetch_results_header = $query_results_header->fetchRow();
-	$query_results_footer = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_footer' LIMIT 1");
-	$fetch_results_footer = $query_results_footer->fetchRow();
-	$query_results_loop = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
-	$fetch_results_loop = $query_results_loop->fetchRow();
-	$query_no_results = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'no_results' LIMIT 1");
-	$fetch_no_results = $query_no_results->fetchRow();
-	
-	// Replace vars in search settings with values
-	$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_RESULTS_FOR]');
-	$values = array($search_string, WB_URL, PAGE_EXTENSION, $TEXT['RESULTS_FOR']);
-	$search_footer = str_replace($vars, $values, ($fetch_footer['value']));
-	$search_results_header = str_replace($vars, $values, ($fetch_results_header['value']));
-	$search_results_footer = str_replace($vars, $values, ($fetch_results_footer['value']));
-	// Do extra vars/values replacement
-	$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_SEARCH]', '[TEXT_ALL_WORDS]', '[TEXT_ANY_WORDS]', '[TEXT_EXACT_MATCH]', '[TEXT_MATCH]', '[TEXT_MATCHING]', '[ALL_CHECKED]', '[ANY_CHECKED]', '[EXACT_CHECKED]');
-	$values = array($search_string, WB_URL, PAGE_EXTENSION, $TEXT['SEARCH'], $TEXT['ALL_WORDS'], $TEXT['ANY_WORDS'], $TEXT['EXACT_MATCH'], $TEXT['MATCH'], $TEXT['MATCHING'], $all_checked, $any_checked, $exact_checked);
-	$search_header = str_replace($vars, $values, ($fetch_header['value']));
-	
-	// Insert js code
-	?>
-	<script language="javascript" type="text/javascript">
-	function toggle_radio(checkbox_id) {
-		if(document.getElementById(checkbox_id).checked == true) {
-			document.getElementById(checkbox_id).checked = false;
-		} else {
-			document.getElementById(checkbox_id).checked = true;
-		}
-	}
-	</script>
-	<?php
-	
-	// Show search header
-	echo $search_header;
-	
-	// Work-out if the user has already entered their details or not
-	if($string != '' AND $string != ' ' AND $string != '  ' AND $string != array()) {
-		
-		// Show search results_header
-		echo $search_results_header;
-		// Search page details only, such as description, keywords, etc.
-			$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE ";
-			$count = 0;
-			foreach($string AS $each_string) {
-				if($count != 0) { $query_pages .= $logical_operator; }
-				$query_pages .= " visibility != 'none' AND page_title LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND menu_title LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND description LIKE '%$each_string%' AND searching = '1'".
-				" OR visibility != 'none' AND visibility != 'deleted' AND keywords LIKE '%$each_string%' AND searching = '1'";
-				$count = $count+1;
-			}
-			$query_pages = $database->query($query_pages);
-		// Loop through pages
-		if($query_pages->numRows() > 0) {
-			while($page = $query_pages->fetchRow()) {
-				// Get page link
-				$link = page_link($page['link']);
-				// Set vars to be replaced by values
-				$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
-				if($page['modified_when'] > 0) {
-					$date = gmdate(DATE_FORMAT, $page['modified_when']+TIMEZONE);
-					$time = gmdate(TIME_FORMAT, $page['modified_when']+TIMEZONE);
-				} else {
-					$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
-					$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
-				}
-				$values = array($link, ($page['page_title']),($page['description']), $users[$page['modified_by']]['username'], $users[$page['modified_by']]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
-				// Show loop code with vars replaced by values
-				if($values != array()) {
-					echo str_replace($vars, $values, ($fetch_results_loop['value']));
-				}
-				// Say that we have already listed this page id
-				$pages_listed[$page['page_id']] = true;
-				// Set values to blank
-				$value = array();
-			}
-		}
-		// Get modules that have registered for custom query's to be conducted
-		$get_modules = $database->query("SELECT value,extra FROM ".TABLE_PREFIX."search WHERE name = 'module'");
-		// Loop through each module
-		if($get_modules->numRows() > 0) {
-			while($module = $get_modules->fetchRow()) {
-				// Get module name
-				$module_name = $module['value'];
-				// Get fields to use for title, link, etc.
-				$fields = unserialize($module['extra']);
-				// Get query start
-				$get_query_start = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_start' AND extra = '$module_name' LIMIT 1");
-				if($get_query_start->numRows() > 0) {
-					// Fetch query start
-					$fetch_query_start = $get_query_start->fetchRow();
-					// Prepare query start for execution by replacing {TP} with the TABLE_PREFIX
-					$query_start = str_replace('[TP]', TABLE_PREFIX, ($fetch_query_start['value']));
-					// Get query end
-					$get_query_end = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_end' AND extra = '$module_name' LIMIT 1");
-					if($get_query_end->numRows() > 0) {
-						// Fetch query start
-						$fetch_query_end = $get_query_end->fetchRow();
-						// Set query end
-						$query_end = ($fetch_query_end['value']);
-						// Get query body
-						$get_query_body = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_body' AND extra = '$module_name' LIMIT 1");
-						if($get_query_body->numRows() > 0) {
-							// Fetch query start
-							$fetch_query_body = $get_query_body->fetchRow();
-							// Prepare query body for execution by replacing {STRING} with the correct one
-							$query_body = str_replace(array('[TP]','[O]','[W]'), array(TABLE_PREFIX,'LIKE','%'), ($fetch_query_body['value']));
-							// Loop through query body for each string, then combine with start and end
-							$prepared_query = $query_start;
-							$count = 0;
-							foreach($string AS $each_string) {
-								if($count != 0) { $prepared_query .= $logical_operator; }
-								$prepared_query .= str_replace('[STRING]', $each_string, $query_body);
-								$count = $count+1;
-							}
-							$prepared_query .= $query_end;
-							// Execute query
-							$query = $database->query($prepared_query);
-							// Loop though queried items
-							if($query->numRows() > 0) {
-								while($page = $query->fetchRow()) {
-									// Only show this page if it hasn't already been list
-									if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) {
-										// Get page link
-										$link = page_link($page[$fields['link']]);
-										// Set vars to be replaced by values
-										$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
-										if($page[$fields['modified_when']] > 0) {
-											$date = gmdate(DATE_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
-											$time = gmdate(TIME_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
-										} else {
-											$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
-											$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
-										}
-										$values = array($link, ($page[$fields['title']]), ($page[$fields['description']]), $users[$page[$fields['modified_by']]]['username'], $users[$page[$fields['modified_by']]]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
-										// Show loop code with vars replaced by values
-										echo str_replace($vars, $values, ($fetch_results_loop['value']));
-										// Say that this page or item has been listed if we can
-										if(isset($fields['page_id'])) {
-											$pages_listed[$page[$fields['page_id']]] = true;
-										} elseif(isset($fields['item_id'])) {
-											$items_listed[$page[$fields['item_id']]] = true;
-										}
-									}
-								}
-							}
-						
-						}
-					}
-				}
-			}
-			
-			// Show search results_footer
-			echo $search_results_footer;
-			
-		}
-	
-	// Say no items found if we should
-	if($pages_listed == array() AND $items_listed == array()) {
-		echo $fetch_no_results['value'];
-	}
-		
-	}
-	
-	// Show search footer
-	echo $search_footer;
-	
-}
-
-?>
+<?php
+
+// $Id$
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+if(!defined('WB_URL')) { header('Location: index.php'); }
+
+// Check if search is enabled
+if(SHOW_SEARCH != true) {
+	echo $TEXT['SEARCH'].' '.$TEXT['DISABLED'];
+} else {
+	
+	// Make pages_listed and items_listed blank arrays
+	$pages_listed = array();
+	$items_listed = array();
+
+	// Get search string
+	if(isset($_REQUEST['string'])) {
+		if ($_REQUEST['match']!='exact') {
+			$string=str_replace(',', '', $_REQUEST['string']);
+		} else {
+			$string=$_REQUEST['string'];
+		}
+		// reverse potential magic_quotes action
+		$original_string=$wb->strip_slashes($string);
+		// Double backslashes (mySQL needs doubly escaped backslashes in LIKE comparisons)
+		$string = addslashes($wb->escape_backslashes($original_string));
+		// then escape for mySQL query
+		$search_string = htmlspecialchars($original_string,ENT_QUOTES);
+	} else {
+		$string = '';
+		$search_string = '';
+	}
+	
+	// Work-out what to do (match all words, any words, or do exact match), and do relevant with query settings
+	$all_checked = '';
+	$any_checked = '';
+	$exact_checked = '';
+	if($_REQUEST['match'] != 'exact') {
+		// Split string into array with explode() function
+		$exploded_string = explode(' ', $string);
+		// Make sure there is no blank values in the array
+		$string = array();
+		foreach($exploded_string AS $each_exploded_string) {
+			if($each_exploded_string != '') {
+				$string[] = $each_exploded_string;
+			}
+		}
+		if ($_REQUEST['match'] == 'any') {
+			$any_checked = ' checked';
+			$logical_operator = ' OR';
+		} else {
+			$all_checked = ' checked';
+			$logical_operator = ' AND';
+		}
+	} else {
+		$exact_checked = ' checked';
+		$exact_string=$string;
+		$string=array();
+		$string[]=$exact_string;
+	}	
+	// Get list of usernames and display names
+	$query_users = $database->query("SELECT user_id,username,display_name FROM ".TABLE_PREFIX."users");
+	$users = array('0' => array('display_name' => $TEXT['UNKNOWN'], 'username' => strtolower($TEXT['UNKNOWN'])));
+	if($query_users->numRows() > 0) {
+		while($user = $query_users->fetchRow()) {
+			$users[$user['user_id']] = array('display_name' => $user['display_name'], 'username' => $user['username']);
+		}
+	}
+	
+	// Get search settings
+	$query_header = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
+	$fetch_header = $query_header->fetchRow();
+	$query_footer = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'footer' LIMIT 1");
+	$fetch_footer = $query_footer->fetchRow();
+	$query_results_header = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_header' LIMIT 1");
+	$fetch_results_header = $query_results_header->fetchRow();
+	$query_results_footer = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_footer' LIMIT 1");
+	$fetch_results_footer = $query_results_footer->fetchRow();
+	$query_results_loop = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
+	$fetch_results_loop = $query_results_loop->fetchRow();
+	$query_no_results = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'no_results' LIMIT 1");
+	$fetch_no_results = $query_no_results->fetchRow();
+	
+	// Replace vars in search settings with values
+	$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_RESULTS_FOR]');
+	$values = array($search_string, WB_URL, PAGE_EXTENSION, $TEXT['RESULTS_FOR']);
+	$search_footer = str_replace($vars, $values, ($fetch_footer['value']));
+	$search_results_header = str_replace($vars, $values, ($fetch_results_header['value']));
+	$search_results_footer = str_replace($vars, $values, ($fetch_results_footer['value']));
+	// Do extra vars/values replacement
+	$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_SEARCH]', '[TEXT_ALL_WORDS]', '[TEXT_ANY_WORDS]', '[TEXT_EXACT_MATCH]', '[TEXT_MATCH]', '[TEXT_MATCHING]', '[ALL_CHECKED]', '[ANY_CHECKED]', '[EXACT_CHECKED]');
+	$values = array($search_string, WB_URL, PAGE_EXTENSION, $TEXT['SEARCH'], $TEXT['ALL_WORDS'], $TEXT['ANY_WORDS'], $TEXT['EXACT_MATCH'], $TEXT['MATCH'], $TEXT['MATCHING'], $all_checked, $any_checked, $exact_checked);
+	$search_header = str_replace($vars, $values, ($fetch_header['value']));
+	
+	// Insert js code
+	?>
+	<script language="javascript" type="text/javascript">
+	function toggle_radio(checkbox_id) {
+		if(document.getElementById(checkbox_id).checked == true) {
+			document.getElementById(checkbox_id).checked = false;
+		} else {
+			document.getElementById(checkbox_id).checked = true;
+		}
+	}
+	</script>
+	<?php
+	
+	// Show search header
+	echo $search_header;
+	
+	// Work-out if the user has already entered their details or not
+	if($string != '' AND $string != ' ' AND $string != '  ' AND $string != array()) {
+		
+		// Show search results_header
+		echo $search_results_header;
+		// Search page details only, such as description, keywords, etc.
+			$query_pages = "SELECT page_id, page_title, menu_title, link, description, modified_when, modified_by FROM ".TABLE_PREFIX."pages WHERE ";
+			$count = 0;
+			foreach($string AS $each_string) {
+				if($count != 0) { $query_pages .= $logical_operator; }
+				$query_pages .= " visibility != 'none' AND page_title LIKE '%$each_string%' AND searching = '1'".
+				" OR visibility != 'none' AND visibility != 'deleted' AND menu_title LIKE '%$each_string%' AND searching = '1'".
+				" OR visibility != 'none' AND visibility != 'deleted' AND description LIKE '%$each_string%' AND searching = '1'".
+				" OR visibility != 'none' AND visibility != 'deleted' AND keywords LIKE '%$each_string%' AND searching = '1'";
+				$count = $count+1;
+			}
+			$query_pages = $database->query($query_pages);
+		// Loop through pages
+		if($query_pages->numRows() > 0) {
+			while($page = $query_pages->fetchRow()) {
+				// Get page link
+				$link = page_link($page['link']);
+				// Set vars to be replaced by values
+				$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
+				if($page['modified_when'] > 0) {
+					$date = gmdate(DATE_FORMAT, $page['modified_when']+TIMEZONE);
+					$time = gmdate(TIME_FORMAT, $page['modified_when']+TIMEZONE);
+				} else {
+					$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
+					$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
+				}
+				$values = array($link, ($page['page_title']),($page['description']), $users[$page['modified_by']]['username'], $users[$page['modified_by']]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
+				// Show loop code with vars replaced by values
+				if($values != array()) {
+					echo str_replace($vars, $values, ($fetch_results_loop['value']));
+				}
+				// Say that we have already listed this page id
+				$pages_listed[$page['page_id']] = true;
+				// Set values to blank
+				$value = array();
+			}
+		}
+		// Get modules that have registered for custom query's to be conducted
+		$get_modules = $database->query("SELECT value,extra FROM ".TABLE_PREFIX."search WHERE name = 'module'");
+		// Loop through each module
+		if($get_modules->numRows() > 0) {
+			while($module = $get_modules->fetchRow()) {
+				// Get module name
+				$module_name = $module['value'];
+				// Get fields to use for title, link, etc.
+				$fields = unserialize($module['extra']);
+				// Get query start
+				$get_query_start = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_start' AND extra = '$module_name' LIMIT 1");
+				if($get_query_start->numRows() > 0) {
+					// Fetch query start
+					$fetch_query_start = $get_query_start->fetchRow();
+					// Prepare query start for execution by replacing {TP} with the TABLE_PREFIX
+					$query_start = str_replace('[TP]', TABLE_PREFIX, ($fetch_query_start['value']));
+					// Get query end
+					$get_query_end = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_end' AND extra = '$module_name' LIMIT 1");
+					if($get_query_end->numRows() > 0) {
+						// Fetch query start
+						$fetch_query_end = $get_query_end->fetchRow();
+						// Set query end
+						$query_end = ($fetch_query_end['value']);
+						// Get query body
+						$get_query_body = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'query_body' AND extra = '$module_name' LIMIT 1");
+						if($get_query_body->numRows() > 0) {
+							// Fetch query start
+							$fetch_query_body = $get_query_body->fetchRow();
+							// Prepare query body for execution by replacing {STRING} with the correct one
+							$query_body = str_replace(array('[TP]','[O]','[W]'), array(TABLE_PREFIX,'LIKE','%'), ($fetch_query_body['value']));
+							// Loop through query body for each string, then combine with start and end
+							$prepared_query = $query_start;
+							$count = 0;
+							foreach($string AS $each_string) {
+								if($count != 0) { $prepared_query .= $logical_operator; }
+								$prepared_query .= str_replace('[STRING]', $each_string, $query_body);
+								$count = $count+1;
+							}
+							$prepared_query .= $query_end;
+							// Execute query
+							$query = $database->query($prepared_query);
+							// Loop though queried items
+							if($query->numRows() > 0) {
+								while($page = $query->fetchRow()) {
+									// Only show this page if it hasn't already been list
+									if(!isset($fields['page_id']) OR !isset($pages_listed[$page[$fields['page_id']]])) {
+										// Get page link
+										$link = page_link($page[$fields['link']]);
+										// Set vars to be replaced by values
+										$vars = array('[LINK]', '[TITLE]', '[DESCRIPTION]', '[USERNAME]','[DISPLAY_NAME]','[DATE]','[TIME]','[TEXT_LAST_UPDATED_BY]','[TEXT_ON]');
+										if($page[$fields['modified_when']] > 0) {
+											$date = gmdate(DATE_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
+											$time = gmdate(TIME_FORMAT, $page[$fields['modified_when']]+TIMEZONE);
+										} else {
+											$date = $TEXT['UNKNOWN'].' '.$TEXT['DATE'];
+											$time = $TEXT['UNKNOWN'].' '.$TEXT['TIME'];
+										}
+										$values = array($link, ($page[$fields['title']]), ($page[$fields['description']]), $users[$page[$fields['modified_by']]]['username'], $users[$page[$fields['modified_by']]]['display_name'], $date, $time, $TEXT['LAST_UPDATED_BY'], strtolower($TEXT['ON']));
+										// Show loop code with vars replaced by values
+										echo str_replace($vars, $values, ($fetch_results_loop['value']));
+										// Say that this page or item has been listed if we can
+										if(isset($fields['page_id'])) {
+											$pages_listed[$page[$fields['page_id']]] = true;
+										} elseif(isset($fields['item_id'])) {
+											$items_listed[$page[$fields['item_id']]] = true;
+										}
+									}
+								}
+							}
+						
+						}
+					}
+				}
+			}
+			
+			// Show search results_footer
+			echo $search_results_footer;
+			
+		}
+	
+	// Say no items found if we should
+	if($pages_listed == array() AND $items_listed == array()) {
+		echo $fetch_no_results['value'];
+	}
+		
+	}
+	
+	// Show search footer
+	echo $search_footer;
+	
+}
+
+?>
\ No newline at end of file
Index: trunk/wb/install/save.php
===================================================================
--- trunk/wb/install/save.php	(revision 238)
+++ trunk/wb/install/save.php	(revision 239)
@@ -1,636 +1,636 @@
-<?php
-
-// $Id$
-
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
-
-// Start a session
-if(!defined('SESSION_STARTED')) {
-	session_name('wb_session_id');
-	session_start();
-	define('SESSION_STARTED', true);
-}
-
-// Function to set error
-function set_error($message) {
-	global $_POST;
-	if(isset($message) AND $message != '') {
-		// Copy values entered into session so user doesn't have to re-enter everything
-		if(isset($_POST['website_title'])) {
-			$_SESSION['wb_url'] = $_POST['wb_url'];
-			$_SESSION['wb_path'] = $_POST['wb_path'];
-			$_SESSION['default_timezone'] = $_POST['default_timezone'];
-			if(!isset($_POST['operating_system'])) {
-				$_SESSION['operating_system'] = 'linux';
-			} else {
-				$_SESSION['operating_system'] = $_POST['operating_system'];
-			}
-			if(!isset($_POST['world_writeable'])) {
-				$_SESSION['world_writeable'] = false;
-			} else {
-				$_SESSION['world_writeable'] = true;
-			}
-			$_SESSION['database_host'] = $_POST['database_host'];
-			$_SESSION['database_username'] = $_POST['database_username'];
-			$_SESSION['database_password'] = $_POST['database_password'];
-			$_SESSION['database_name'] = $_POST['database_name'];
-			$_SESSION['table_prefix'] = $_POST['table_prefix'];
-			if(!isset($_POST['install_tables'])) {
-				$_SESSION['install_tables'] = false;
-			} else {
-				$_SESSION['install_tables'] = true;
-			}
-			$_SESSION['website_title'] = $_POST['website_title'];
-			$_SESSION['admin_username'] = $_POST['admin_username'];
-			$_SESSION['admin_email'] = $_POST['admin_email'];
-			$_SESSION['admin_password'] = $_POST['admin_password'];
-		}
-		// Set the message
-		$_SESSION['message'] = $message;
-		// Specify that session support is enabled
-		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
-		// Redirect to first page again and exit
-		header('Location: index.php?sessions_checked=true');
-		exit();
-	}
-}
-
-// Function to workout what the default permissions are for files created by the webserver
-function default_file_mode($temp_dir) {
-	$v = explode(".",PHP_VERSION);
-	$v = $v[0].$v[1];
-	if($v > 41 AND is_writable($temp_dir)) {
-		$filename = $temp_dir.'/test_permissions.txt';
-		$handle = fopen($filename, 'w');
-		fwrite($handle, 'This file is to get the default file permissions');
-		fclose($handle);
-		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
-		unlink($filename);
-	} else {
-		$default_file_mode = '0777';
-	}
-	return $default_file_mode;
-}
-
-// Function to workout what the default permissions are for directories created by the webserver
-function default_dir_mode($temp_dir) {
-	$v = explode(".",PHP_VERSION);
-	$v = $v[0].$v[1];
-	if($v > 41 AND is_writable($temp_dir)) {
-		$dirname = $temp_dir.'/test_permissions/';
-		mkdir($dirname);
-		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
-		rmdir($dirname);
-	} else {
-		$default_dir_mode = '0777';
-	}
-	return $default_dir_mode;
-}
-
-function add_slashes($input) {
-		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
-			return $input;
-		}
-		$output = addslashes($input);
-		return $output;
-	}
-
-// Begin check to see if form was even submitted
-// Set error if no post vars found
-if(!isset($_POST['website_title'])) {
-	set_error('Please fill-in the form below');
-}
-// End check to see if form was even submitted
-
-// Begin path and timezone details code
-
-// Check if user has entered the installation url
-if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
-	set_error('Please enter an absolute URL');
-} else {
-	$wb_url = $_POST['wb_url'];
-}
-// Remove any slashes at the end of the URL
-if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
-	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
-}
-// Get the default time zone
-if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
-	set_error('Please select a valid default timezone');
-} else {
-	$default_timezone = $_POST['default_timezone']*60*60;
-}
-// End path and timezone details code
-
-// Begin operating system specific code
-// Get operating system
-if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
-	set_error('Please select a valid operating system');
-} else {
-	$operating_system = $_POST['operating_system'];
-}
-// Work-out file permissions
-if($operating_system == 'windows') {
-	$file_mode = '0777';
-	$dir_mode = '0777';
-} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
-	$file_mode = '0777';
-	$dir_mode = '0777';
-} else {
-	$file_mode = default_file_mode('../temp');
-	$dir_mode = default_dir_mode('../temp');
-}
-// End operating system specific code
-
-// Begin database details code
-// Check if user has entered a database host
-if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
-	set_error('Please enter a database host name');
-} else {
-	$database_host = $_POST['database_host'];
-}
-// Check if user has entered a database username
-if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
-	set_error('Please enter a database username');
-} else {
-	$database_username = $_POST['database_username'];
-}
-// Check if user has entered a database password
-if(!isset($_POST['database_password'])) {
-	set_error('Please enter a database password');
-} else {
-	$database_password = $_POST['database_password'];
-}
-// Check if user has entered a database name
-if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
-	set_error('Please enter a database name');
-} else {
-	$database_name = $_POST['database_name'];
-}
-// Get table prefix
-$table_prefix = $_POST['table_prefix'];
-// Find out if the user wants to install tables and data
-if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
-	$install_tables = true;
-} else {
-	$install_tables = false;
-}
-// End database details code
-
-// Begin website title code
-// Get website title
-if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
-	set_error('Please enter a website title');
-} else {
-	$website_title = add_slashes($_POST['website_title']);
-}
-// End website title code
-
-// Begin admin user details code
-// Get admin username
-if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
-	set_error('Please enter a username for the Administrator account');
-} else {
-	$admin_username = $_POST['admin_username'];
-}
-// Get admin email and validate it
-if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
-	set_error('Please enter an email for the Administrator account');
-} else {
-	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['admin_email'])) {
-		$admin_email = $_POST['admin_email'];
-	} else {
-		set_error('Please enter a valid email address for the Administrator account');
-	}
-}
-// Get the two admin passwords entered, and check that they match
-if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
-	set_error('Please enter a password for the Administrator account');
-} else {
-	$admin_password = $_POST['admin_password'];
-}
-if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
-	set_error('Please make sure you re-enter the password for the Administrator account');
-} else {
-	$admin_repassword = $_POST['admin_repassword'];
-}
-if($admin_password != $admin_repassword) {
-	set_error('Sorry, the two Administrator account passwords you entered do not match');
-}
-// End admin user details code
-
-// Try and write settings to config file
-$config_content = "" .
-"<?php\n".
-"\n".
-"define('DB_TYPE', 'mysql');\n".
-"define('DB_HOST', '$database_host');\n".
-"define('DB_USERNAME', '$database_username');\n".
-"define('DB_PASSWORD', '$database_password');\n".
-"define('DB_NAME', '$database_name');\n".
-"define('TABLE_PREFIX', '$table_prefix');\n".
-"\n".
-"define('WB_PATH', dirname(__FILE__));\n".
-"define('WB_URL', '$wb_url');\n".
-"define('ADMIN_PATH', WB_PATH.'/admin');\n".
-"define('ADMIN_URL', '$wb_url/admin');\n".
-"\n".
-"require_once(WB_PATH.'/framework/initialize.php');\n".
-"\n".
-"?>";
-
-$config_filename = '../config.php';
-
-// Check if the file exists and is writable first.
-if(file_exists($config_filename) AND is_writable($config_filename)) {
-	if(!$handle = fopen($config_filename, 'w')) {
-		set_error("Cannot open the configuration file ($config_filename)");
-	} else {
-		if (fwrite($handle, $config_content) === FALSE) {
-			set_error("Cannot write to the configuration file ($config_filename)");
-		}
-		// Close file
-		fclose($handle);
-	}
-} else {
-	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
-}
-
-// Define configuration vars
-define('DB_TYPE', 'mysql');
-define('DB_HOST', $database_host);
-define('DB_USERNAME', $database_username);
-define('DB_PASSWORD', $database_password);
-define('DB_NAME', $database_name);
-define('TABLE_PREFIX', $table_prefix);
-define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
-define('WB_URL', $wb_url);
-define('ADMIN_PATH', WB_PATH.'/admin');
-define('ADMIN_URL', $wb_url.'/admin');
-
-// Check if the user has entered a correct path
-if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
-	set_error('It appears the Absolute path that you entered is incorrect');
-}
-
-// Try connecting to database	
-if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
-	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
-}
-
-// Try to create the database
-mysql_query('CREATE DATABASE '.$database_name);
-
-// Close the mysql connection
-mysql_close();
-
-// Include WB functions file
-require_once(WB_PATH.'/framework/functions.php');
-
-// Re-connect to the database, this time using in-build database class
-require_once(WB_PATH.'/framework/class.login.php');
-$database=new database();
-
-// Check if we should install tables
-if($install_tables == true) {
-	
-	// Remove tables if they exist
-
-	// Pages table
-	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
-	$database->query($pages);
-	// Sections table
-	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
-	$database->query($sections);
-	// Settings table
-	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
-	$database->query($settings);
-	// Users table
-	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
-	$database->query($users);
-	// Groups table
-	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
-	$database->query($groups);
-	// Search table
-	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
-	$database->query($search);
-	// Addons table
-	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
-	$database->query($addons);
-				
-	// Try installing tables
-	
-	// Pages table
-	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
-	       . ' `parent` INT NOT NULL ,'
-	       . ' `root_parent` INT NOT NULL ,'
-	       . ' `level` INT NOT NULL ,'
-	       . ' `link` TEXT NOT NULL ,'
-	       . ' `target` VARCHAR( 7 ) NOT NULL ,'
-	       . ' `page_title` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `menu_title` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `description` TEXT NOT NULL ,'
-	       . ' `keywords` TEXT NOT NULL ,'
-	       . ' `page_trail` TEXT NOT NULL ,'
-	       . ' `template` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `visibility` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `position` INT NOT NULL ,'
-	       . ' `menu` INT NOT NULL ,'
-	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
-	       . ' `searching` INT NOT NULL ,'
-	       . ' `admin_groups` TEXT NOT NULL ,'
-	       . ' `admin_users` TEXT NOT NULL ,'
-	       . ' `viewing_groups` TEXT NOT NULL ,'
-	       . ' `viewing_users` TEXT NOT NULL ,'
-	       . ' `modified_when` INT NOT NULL ,'
-	       . ' `modified_by` INT NOT NULL ,'
-	       . ' PRIMARY KEY ( `page_id` ) )'
-	       . ' ';
-	$database->query($pages);
-	
-	// Sections table
-	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
-	       . ' `page_id` INT NOT NULL ,'
-	       . ' `position` INT NOT NULL ,'
-	       . ' `module` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `block` VARCHAR( 255 ) NOT NULL ,'
-	       . ' PRIMARY KEY ( `section_id` ) )'
-	       . ' ';
-	$database->query($pages);
-	
-	require(WB_PATH.'/admin/interface/version.php');
-	
-	// Settings table
-	$settings="CREATE TABLE `".TABLE_PREFIX."settings` ( `setting_id` INT NOT NULL auto_increment,
-		`name` VARCHAR( 255 ) NOT NULL ,
-		`value` TEXT NOT NULL ,
-		PRIMARY KEY ( `setting_id` ) )";
-	$database->query($settings);
-	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` VALUES "
-	." ('', 'wb_version', '".VERSION."'),"
-	." ('', 'website_title', '$website_title'),"
-	." ('', 'website_description', ''),"
-	." ('', 'website_keywords', ''),"
-	." ('', 'website_header', ''),"
-	." ('', 'website_footer', ''),"
-	." ('', 'wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
-	." ('', 'rename_files_on_upload', 'php,asp,phpx,aspx'),"
-	." ('', 'er_level', ''),"
-	." ('', 'default_language', 'EN'),"
-	." ('', 'app_name', 'wb'),"
-	." ('', 'default_timezone', '$default_timezone'),"
-	." ('', 'default_date_format', 'M d Y'),"
-	." ('', 'default_time_format', 'g:i A'),"
-	." ('', 'home_folders', 'true'),"
-	." ('', 'default_template', 'round'),"
-	." ('', 'multiple_menus', 'false'),"
-	." ('', 'page_level_limit', '4'),"
-	." ('', 'intro_page', 'false'),"
-	." ('', 'page_trash', 'disabled'),"
-	." ('', 'homepage_redirection', 'false'),"
-	." ('', 'page_languages', 'false'),"
-	." ('', 'wysiwyg_editor', 'htmlarea'),"
-	." ('', 'manage_sections', 'true'),"
-	." ('', 'section_blocks', 'false'),"
-	." ('', 'smart_login', 'false'),"
-	." ('', 'frontend_login', 'false'),"
-	." ('', 'frontend_signup', 'false'),"
-	." ('', 'server_email', '$admin_email'),"
-	." ('', 'search', 'public'),"
-	." ('', 'page_extension', '.php'),"
-	." ('', 'page_spacer', '-'),"
-	." ('', 'pages_directory', '/pages'),"
-	." ('', 'media_directory', '/media'),"
-	." ('', 'operating_system', '$operating_system'),"
-	." ('', 'string_file_mode', '$file_mode'),"
-	." ('', 'string_dir_mode', '$dir_mode');";
-	$database->query($settings_rows);
-	
-	
-	// Users table
-	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
-	       . ' `group_id` INT NOT NULL ,'
-	       . ' `active` INT NOT NULL ,'
-	       . ' `username` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `password` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `remember_key` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `last_reset` INT NOT NULL ,'
-	       . ' `display_name` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `email` TEXT NOT NULL ,'
-	       . ' `timezone` INT NOT NULL ,'
-	       . ' `date_format` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `time_format` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
-	       . ' `home_folder` TEXT NOT NULL ,'
-	       . ' `login_when` INT NOT NULL ,'
-	       . ' `login_ip` VARCHAR( 15 ) NOT NULL ,'
-	       . ' PRIMARY KEY ( `user_id` ) )'
-	       . ' ';
-	$database->query($users);
-	
-	// Groups table
-	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
-	        . ' `name` VARCHAR( 255 ) NOT NULL ,'
-	        . ' `system_permissions` TEXT NOT NULL ,'
-	        . ' `module_permissions` TEXT NOT NULL ,'
-	        . ' `template_permissions` TEXT NOT NULL ,'
-	        . ' PRIMARY KEY ( `group_id` ) )'
-	        . ' ';
-	$database->query($groups);
-	
-	// Search settings table
-	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
-	        . ' `name` VARCHAR( 255 ) NOT NULL ,'
-	        . ' `value` TEXT NOT NULL ,'
-	        . ' `extra` TEXT NOT NULL ,'
-	        . ' PRIMARY KEY ( `search_id` ) )'
-	        . ' ';
-	$database->query($search);
-	
-	// Addons table
-	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
-			.'`addon_id` INT NOT NULL auto_increment ,'
-			.'`type` VARCHAR( 255 ) NOT NULL ,'
-			.'`directory` VARCHAR( 255 ) NOT NULL ,'
-			.'`name` VARCHAR( 255 ) NOT NULL ,'
-			.'`description` TEXT NOT NULL ,'
-			.'`function` VARCHAR( 255 ) NOT NULL ,'
-			.'`version` VARCHAR( 255 ) NOT NULL ,'
-			.'`platform` VARCHAR( 255 ) NOT NULL ,'
-			.'`author` VARCHAR( 255 ) NOT NULL ,'
-			.'`license` VARCHAR( 255 ) NOT NULL ,'
-			.' PRIMARY KEY ( `addon_id` ) ); ';
-	$database->query($addons);
-
-	// Insert default data
-	
-	// Admin group
-	$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';
-	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
-	$database->query($insert_admin_group);
-	// Admin user
-	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,active,username,password,email,display_name) VALUES ('1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
-	$database->query($insert_admin_user);
-	
-	// Search header
-	$search_header = addslashes('
-<h1>Search</h1>
-
-<form name="search" action="[WB_URL]/search/index[PAGE_EXTENSION]" method="post">
-<table cellpadding="3" cellspacing="0" border="0" width="500">
-<tr>
-<td>
-<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
-</td>
-<td width="150">
-<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
-</td>
-</tr>
-<tr>
-<td colspan="2">
-<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
-<a href="javascript: toggle_radio(\'match_all\');">[TEXT_ALL_WORDS]</a>
-<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
-<a href="javascript: toggle_radio(\'match_any\');">[TEXT_ANY_WORDS]</a>
-<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
-<a href="javascript: toggle_radio(\'match_exact\');">[TEXT_EXACT_MATCH]</a>
-</td>
-</tr>
-</table>
-
-</form>
-
-<hr />
-	');
-	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
-	$database->query($insert_search_header);
-	// Search footer
-	$search_footer = addslashes('');
-	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
-	$database->query($insert_search_footer);
-	// Search results header
-	$search_results_header = addslashes(''.
-'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
-<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
-	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
-	$database->query($insert_search_results_header);
-	// Search results loop
-	$search_results_loop = addslashes(''.
-'<tr style="background-color: #F0F0F0;">
-<td><a href="[LINK]">[TITLE]</a></td>
-<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
-</tr>
-<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[DESCRIPTION]</td></tr>');
-
-	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
-	$database->query($insert_search_results_loop);
-	// Search results footer
-	$search_results_footer = addslashes("</table>");
-	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
-	$database->query($insert_search_results_footer);
-	// Search no results
-	$search_no_results = addslashes('<br />No results found');
-	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
-	$database->query($insert_search_no_results);
-	// Search template
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
-		
-	require_once(WB_PATH.'/framework/initialize.php');
-	$admin = new admin('dummy');
-	
-	// Include the PclZip class file (thanks to 
-	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
-			
-	// Install add-ons
-	if(file_exists(WB_PATH.'/install/modules')) {
-		// Unpack pre-packaged modules
-			
-	}
-	if(file_exists(WB_PATH.'/install/templates')) {
-		// Unpack pre-packaged templates
-		
-	}
-	if(file_exists(WB_PATH.'/install/languages')) {
-		// Unpack pre-packaged languages
-		
-	}
-	// Load addons into DB
-	$dirs['modules'] = WB_PATH.'/modules/';
-	$dirs['templates'] = WB_PATH.'/templates/';
-	$dirs['languages'] = WB_PATH.'/languages/';
-	foreach($dirs AS $type => $dir) {
-		if($handle = opendir($dir)) {
-			while(false !== ($file = readdir($handle))) {
-				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
-					// Get addon type
-					if($type == 'modules') {
-						load_module($dir.'/'.$file, true);
-					} elseif($type == 'templates') {
-						load_template($dir.'/'.$file);
-					} elseif($type == 'languages') {
-						load_language($dir.'/'.$file);
-					}
-				}
-			}
-		closedir($handle);
-		}
-	}
-	
-	// Check if there was a database error
-	if($database->is_error()) {
-		set_error($database->get_error());
-	}
-	
-}
-
-// Log the user in and go to Website Baker Administration
-$thisApp = new Login(
-							array(
-									"MAX_ATTEMPS" => "50",
-									"WARNING_URL" => ADMIN_URL."/login/warning.html",
-									"USERNAME_FIELDNAME" => 'admin_username',
-									"PASSWORD_FIELDNAME" => 'admin_password',
-									"REMEMBER_ME_OPTION" => SMART_LOGIN,
-									"MIN_USERNAME_LEN" => "2",
-									"MIN_PASSWORD_LEN" => "2",
-									"MAX_USERNAME_LEN" => "30",
-									"MAX_PASSWORD_LEN" => "30",
-									'LOGIN_URL' => ADMIN_URL."/login/index.php",
-									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
-									'TEMPLATE_DIR' => ADMIN_PATH."/login",
-									'TEMPLATE_FILE' => "template.html",
-									'FRONTEND' => false,
-									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
-									'USERS_TABLE' => TABLE_PREFIX."users",
-									'GROUPS_TABLE' => TABLE_PREFIX."groups",
-							)
-					);
-?>
+<?php
+
+// $Id$
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+// Start a session
+if(!defined('SESSION_STARTED')) {
+	session_name('wb_session_id');
+	session_start();
+	define('SESSION_STARTED', true);
+}
+
+// Function to set error
+function set_error($message) {
+	global $_POST;
+	if(isset($message) AND $message != '') {
+		// Copy values entered into session so user doesn't have to re-enter everything
+		if(isset($_POST['website_title'])) {
+			$_SESSION['wb_url'] = $_POST['wb_url'];
+			$_SESSION['wb_path'] = $_POST['wb_path'];
+			$_SESSION['default_timezone'] = $_POST['default_timezone'];
+			if(!isset($_POST['operating_system'])) {
+				$_SESSION['operating_system'] = 'linux';
+			} else {
+				$_SESSION['operating_system'] = $_POST['operating_system'];
+			}
+			if(!isset($_POST['world_writeable'])) {
+				$_SESSION['world_writeable'] = false;
+			} else {
+				$_SESSION['world_writeable'] = true;
+			}
+			$_SESSION['database_host'] = $_POST['database_host'];
+			$_SESSION['database_username'] = $_POST['database_username'];
+			$_SESSION['database_password'] = $_POST['database_password'];
+			$_SESSION['database_name'] = $_POST['database_name'];
+			$_SESSION['table_prefix'] = $_POST['table_prefix'];
+			if(!isset($_POST['install_tables'])) {
+				$_SESSION['install_tables'] = false;
+			} else {
+				$_SESSION['install_tables'] = true;
+			}
+			$_SESSION['website_title'] = $_POST['website_title'];
+			$_SESSION['admin_username'] = $_POST['admin_username'];
+			$_SESSION['admin_email'] = $_POST['admin_email'];
+			$_SESSION['admin_password'] = $_POST['admin_password'];
+		}
+		// Set the message
+		$_SESSION['message'] = $message;
+		// Specify that session support is enabled
+		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
+		// Redirect to first page again and exit
+		header('Location: index.php?sessions_checked=true');
+		exit();
+	}
+}
+
+// Function to workout what the default permissions are for files created by the webserver
+function default_file_mode($temp_dir) {
+	$v = explode(".",PHP_VERSION);
+	$v = $v[0].$v[1];
+	if($v > 41 AND is_writable($temp_dir)) {
+		$filename = $temp_dir.'/test_permissions.txt';
+		$handle = fopen($filename, 'w');
+		fwrite($handle, 'This file is to get the default file permissions');
+		fclose($handle);
+		$default_file_mode = '0'.substr(sprintf('%o', fileperms($filename)), -3);
+		unlink($filename);
+	} else {
+		$default_file_mode = '0777';
+	}
+	return $default_file_mode;
+}
+
+// Function to workout what the default permissions are for directories created by the webserver
+function default_dir_mode($temp_dir) {
+	$v = explode(".",PHP_VERSION);
+	$v = $v[0].$v[1];
+	if($v > 41 AND is_writable($temp_dir)) {
+		$dirname = $temp_dir.'/test_permissions/';
+		mkdir($dirname);
+		$default_dir_mode = '0'.substr(sprintf('%o', fileperms($dirname)), -3);
+		rmdir($dirname);
+	} else {
+		$default_dir_mode = '0777';
+	}
+	return $default_dir_mode;
+}
+
+function add_slashes($input) {
+		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
+			return $input;
+		}
+		$output = addslashes($input);
+		return $output;
+	}
+
+// Begin check to see if form was even submitted
+// Set error if no post vars found
+if(!isset($_POST['website_title'])) {
+	set_error('Please fill-in the form below');
+}
+// End check to see if form was even submitted
+
+// Begin path and timezone details code
+
+// Check if user has entered the installation url
+if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
+	set_error('Please enter an absolute URL');
+} else {
+	$wb_url = $_POST['wb_url'];
+}
+// Remove any slashes at the end of the URL
+if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
+	$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
+}
+// Get the default time zone
+if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
+	set_error('Please select a valid default timezone');
+} else {
+	$default_timezone = $_POST['default_timezone']*60*60;
+}
+// End path and timezone details code
+
+// Begin operating system specific code
+// Get operating system
+if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
+	set_error('Please select a valid operating system');
+} else {
+	$operating_system = $_POST['operating_system'];
+}
+// Work-out file permissions
+if($operating_system == 'windows') {
+	$file_mode = '0777';
+	$dir_mode = '0777';
+} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
+	$file_mode = '0777';
+	$dir_mode = '0777';
+} else {
+	$file_mode = default_file_mode('../temp');
+	$dir_mode = default_dir_mode('../temp');
+}
+// End operating system specific code
+
+// Begin database details code
+// Check if user has entered a database host
+if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
+	set_error('Please enter a database host name');
+} else {
+	$database_host = $_POST['database_host'];
+}
+// Check if user has entered a database username
+if(!isset($_POST['database_username']) OR $_POST['database_username'] == '') {
+	set_error('Please enter a database username');
+} else {
+	$database_username = $_POST['database_username'];
+}
+// Check if user has entered a database password
+if(!isset($_POST['database_password'])) {
+	set_error('Please enter a database password');
+} else {
+	$database_password = $_POST['database_password'];
+}
+// Check if user has entered a database name
+if(!isset($_POST['database_name']) OR $_POST['database_name'] == '') {
+	set_error('Please enter a database name');
+} else {
+	$database_name = $_POST['database_name'];
+}
+// Get table prefix
+$table_prefix = $_POST['table_prefix'];
+// Find out if the user wants to install tables and data
+if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
+	$install_tables = true;
+} else {
+	$install_tables = false;
+}
+// End database details code
+
+// Begin website title code
+// Get website title
+if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
+	set_error('Please enter a website title');
+} else {
+	$website_title = add_slashes($_POST['website_title']);
+}
+// End website title code
+
+// Begin admin user details code
+// Get admin username
+if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
+	set_error('Please enter a username for the Administrator account');
+} else {
+	$admin_username = $_POST['admin_username'];
+}
+// Get admin email and validate it
+if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
+	set_error('Please enter an email for the Administrator account');
+} else {
+	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['admin_email'])) {
+		$admin_email = $_POST['admin_email'];
+	} else {
+		set_error('Please enter a valid email address for the Administrator account');
+	}
+}
+// Get the two admin passwords entered, and check that they match
+if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
+	set_error('Please enter a password for the Administrator account');
+} else {
+	$admin_password = $_POST['admin_password'];
+}
+if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
+	set_error('Please make sure you re-enter the password for the Administrator account');
+} else {
+	$admin_repassword = $_POST['admin_repassword'];
+}
+if($admin_password != $admin_repassword) {
+	set_error('Sorry, the two Administrator account passwords you entered do not match');
+}
+// End admin user details code
+
+// Try and write settings to config file
+$config_content = "" .
+"<?php\n".
+"\n".
+"define('DB_TYPE', 'mysql');\n".
+"define('DB_HOST', '$database_host');\n".
+"define('DB_USERNAME', '$database_username');\n".
+"define('DB_PASSWORD', '$database_password');\n".
+"define('DB_NAME', '$database_name');\n".
+"define('TABLE_PREFIX', '$table_prefix');\n".
+"\n".
+"define('WB_PATH', dirname(__FILE__));\n".
+"define('WB_URL', '$wb_url');\n".
+"define('ADMIN_PATH', WB_PATH.'/admin');\n".
+"define('ADMIN_URL', '$wb_url/admin');\n".
+"\n".
+"require_once(WB_PATH.'/framework/initialize.php');\n".
+"\n".
+"?>";
+
+$config_filename = '../config.php';
+
+// Check if the file exists and is writable first.
+if(file_exists($config_filename) AND is_writable($config_filename)) {
+	if(!$handle = fopen($config_filename, 'w')) {
+		set_error("Cannot open the configuration file ($config_filename)");
+	} else {
+		if (fwrite($handle, $config_content) === FALSE) {
+			set_error("Cannot write to the configuration file ($config_filename)");
+		}
+		// Close file
+		fclose($handle);
+	}
+} else {
+	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
+}
+
+// Define configuration vars
+define('DB_TYPE', 'mysql');
+define('DB_HOST', $database_host);
+define('DB_USERNAME', $database_username);
+define('DB_PASSWORD', $database_password);
+define('DB_NAME', $database_name);
+define('TABLE_PREFIX', $table_prefix);
+define('WB_PATH', str_replace(array('/install','\install'), '',dirname(__FILE__)));
+define('WB_URL', $wb_url);
+define('ADMIN_PATH', WB_PATH.'/admin');
+define('ADMIN_URL', $wb_url.'/admin');
+
+// Check if the user has entered a correct path
+if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
+	set_error('It appears the Absolute path that you entered is incorrect');
+}
+
+// Try connecting to database	
+if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
+	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
+}
+
+// Try to create the database
+mysql_query('CREATE DATABASE '.$database_name);
+
+// Close the mysql connection
+mysql_close();
+
+// Include WB functions file
+require_once(WB_PATH.'/framework/functions.php');
+
+// Re-connect to the database, this time using in-build database class
+require_once(WB_PATH.'/framework/class.login.php');
+$database=new database();
+
+// Check if we should install tables
+if($install_tables == true) {
+	
+	// Remove tables if they exist
+
+	// Pages table
+	$pages = "DROP TABLE IF EXISTS `".TABLE_PREFIX."pages`";
+	$database->query($pages);
+	// Sections table
+	$sections = "DROP TABLE IF EXISTS `".TABLE_PREFIX."sections`";
+	$database->query($sections);
+	// Settings table
+	$settings = "DROP TABLE IF EXISTS `".TABLE_PREFIX."settings`";
+	$database->query($settings);
+	// Users table
+	$users = "DROP TABLE IF EXISTS `".TABLE_PREFIX."users`";
+	$database->query($users);
+	// Groups table
+	$groups = "DROP TABLE IF EXISTS `".TABLE_PREFIX."groups`";
+	$database->query($groups);
+	// Search table
+	$search = "DROP TABLE IF EXISTS `".TABLE_PREFIX."search`";
+	$database->query($search);
+	// Addons table
+	$addons = "DROP TABLE IF EXISTS `".TABLE_PREFIX."addons`";
+	$database->query($addons);
+				
+	// Try installing tables
+	
+	// Pages table
+	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'pages` ( `page_id` INT NOT NULL auto_increment,'
+	       . ' `parent` INT NOT NULL ,'
+	       . ' `root_parent` INT NOT NULL ,'
+	       . ' `level` INT NOT NULL ,'
+	       . ' `link` TEXT NOT NULL ,'
+	       . ' `target` VARCHAR( 7 ) NOT NULL ,'
+	       . ' `page_title` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `menu_title` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `description` TEXT NOT NULL ,'
+	       . ' `keywords` TEXT NOT NULL ,'
+	       . ' `page_trail` TEXT NOT NULL ,'
+	       . ' `template` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `visibility` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `position` INT NOT NULL ,'
+	       . ' `menu` INT NOT NULL ,'
+	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
+	       . ' `searching` INT NOT NULL ,'
+	       . ' `admin_groups` TEXT NOT NULL ,'
+	       . ' `admin_users` TEXT NOT NULL ,'
+	       . ' `viewing_groups` TEXT NOT NULL ,'
+	       . ' `viewing_users` TEXT NOT NULL ,'
+	       . ' `modified_when` INT NOT NULL ,'
+	       . ' `modified_by` INT NOT NULL ,'
+	       . ' PRIMARY KEY ( `page_id` ) )'
+	       . ' ';
+	$database->query($pages);
+	
+	// Sections table
+	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
+	       . ' `page_id` INT NOT NULL ,'
+	       . ' `position` INT NOT NULL ,'
+	       . ' `module` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `block` VARCHAR( 255 ) NOT NULL ,'
+	       . ' PRIMARY KEY ( `section_id` ) )'
+	       . ' ';
+	$database->query($pages);
+	
+	require(WB_PATH.'/admin/interface/version.php');
+	
+	// Settings table
+	$settings="CREATE TABLE `".TABLE_PREFIX."settings` ( `setting_id` INT NOT NULL auto_increment,
+		`name` VARCHAR( 255 ) NOT NULL ,
+		`value` TEXT NOT NULL ,
+		PRIMARY KEY ( `setting_id` ) )";
+	$database->query($settings);
+	$settings_rows=	"INSERT INTO `".TABLE_PREFIX."settings` VALUES "
+	." ('', 'wb_version', '".VERSION."'),"
+	." ('', 'website_title', '$website_title'),"
+	." ('', 'website_description', ''),"
+	." ('', 'website_keywords', ''),"
+	." ('', 'website_header', ''),"
+	." ('', 'website_footer', ''),"
+	." ('', 'wysiwyg_style', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;'),"
+	." ('', 'rename_files_on_upload', 'php,asp,phpx,aspx'),"
+	." ('', 'er_level', ''),"
+	." ('', 'default_language', 'EN'),"
+	." ('', 'app_name', 'wb'),"
+	." ('', 'default_timezone', '$default_timezone'),"
+	." ('', 'default_date_format', 'M d Y'),"
+	." ('', 'default_time_format', 'g:i A'),"
+	." ('', 'home_folders', 'true'),"
+	." ('', 'default_template', 'round'),"
+	." ('', 'multiple_menus', 'false'),"
+	." ('', 'page_level_limit', '4'),"
+	." ('', 'intro_page', 'false'),"
+	." ('', 'page_trash', 'disabled'),"
+	." ('', 'homepage_redirection', 'false'),"
+	." ('', 'page_languages', 'false'),"
+	." ('', 'wysiwyg_editor', 'htmlarea'),"
+	." ('', 'manage_sections', 'true'),"
+	." ('', 'section_blocks', 'false'),"
+	." ('', 'smart_login', 'false'),"
+	." ('', 'frontend_login', 'false'),"
+	." ('', 'frontend_signup', 'false'),"
+	." ('', 'server_email', '$admin_email'),"
+	." ('', 'search', 'public'),"
+	." ('', 'page_extension', '.php'),"
+	." ('', 'page_spacer', '-'),"
+	." ('', 'pages_directory', '/pages'),"
+	." ('', 'media_directory', '/media'),"
+	." ('', 'operating_system', '$operating_system'),"
+	." ('', 'string_file_mode', '$file_mode'),"
+	." ('', 'string_dir_mode', '$dir_mode');";
+	$database->query($settings_rows);
+	
+	
+	// Users table
+	$users = 'CREATE TABLE `'.TABLE_PREFIX.'users` ( `user_id` INT NOT NULL auto_increment,'
+	       . ' `group_id` INT NOT NULL ,'
+	       . ' `active` INT NOT NULL ,'
+	       . ' `username` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `password` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `remember_key` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `last_reset` INT NOT NULL ,'
+	       . ' `display_name` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `email` TEXT NOT NULL ,'
+	       . ' `timezone` INT NOT NULL ,'
+	       . ' `date_format` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `time_format` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
+	       . ' `home_folder` TEXT NOT NULL ,'
+	       . ' `login_when` INT NOT NULL ,'
+	       . ' `login_ip` VARCHAR( 15 ) NOT NULL ,'
+	       . ' PRIMARY KEY ( `user_id` ) )'
+	       . ' ';
+	$database->query($users);
+	
+	// Groups table
+	$groups = 'CREATE TABLE `'.TABLE_PREFIX.'groups` ( `group_id` INT NOT NULL auto_increment,'
+	        . ' `name` VARCHAR( 255 ) NOT NULL ,'
+	        . ' `system_permissions` TEXT NOT NULL ,'
+	        . ' `module_permissions` TEXT NOT NULL ,'
+	        . ' `template_permissions` TEXT NOT NULL ,'
+	        . ' PRIMARY KEY ( `group_id` ) )'
+	        . ' ';
+	$database->query($groups);
+	
+	// Search settings table
+	$search = 'CREATE TABLE `'.TABLE_PREFIX.'search` ( `search_id` INT NOT NULL auto_increment,'
+	        . ' `name` VARCHAR( 255 ) NOT NULL ,'
+	        . ' `value` TEXT NOT NULL ,'
+	        . ' `extra` TEXT NOT NULL ,'
+	        . ' PRIMARY KEY ( `search_id` ) )'
+	        . ' ';
+	$database->query($search);
+	
+	// Addons table
+	$addons = 'CREATE TABLE `'.TABLE_PREFIX.'addons` ( '
+			.'`addon_id` INT NOT NULL auto_increment ,'
+			.'`type` VARCHAR( 255 ) NOT NULL ,'
+			.'`directory` VARCHAR( 255 ) NOT NULL ,'
+			.'`name` VARCHAR( 255 ) NOT NULL ,'
+			.'`description` TEXT NOT NULL ,'
+			.'`function` VARCHAR( 255 ) NOT NULL ,'
+			.'`version` VARCHAR( 255 ) NOT NULL ,'
+			.'`platform` VARCHAR( 255 ) NOT NULL ,'
+			.'`author` VARCHAR( 255 ) NOT NULL ,'
+			.'`license` VARCHAR( 255 ) NOT NULL ,'
+			.' PRIMARY KEY ( `addon_id` ) ); ';
+	$database->query($addons);
+
+	// Insert default data
+	
+	// Admin group
+	$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';
+	$insert_admin_group = "INSERT INTO `".TABLE_PREFIX."groups` VALUES ('1', 'Administrators', '$full_system_permissions', '', '')";
+	$database->query($insert_admin_group);
+	// Admin user
+	$insert_admin_user = "INSERT INTO `".TABLE_PREFIX."users` (user_id,group_id,active,username,password,email,display_name) VALUES ('1','1','1','$admin_username','".md5($admin_password)."','$admin_email','Administrator')";
+	$database->query($insert_admin_user);
+	
+	// Search header
+	$search_header = addslashes('
+<h1>Search</h1>
+
+<form name="search" action="[WB_URL]/search/index[PAGE_EXTENSION]" method="post">
+<table cellpadding="3" cellspacing="0" border="0" width="500">
+<tr>
+<td>
+<input type="text" name="string" value="[SEARCH_STRING]" style="width: 100%;" />
+</td>
+<td width="150">
+<input type="submit" value="[TEXT_SEARCH]" style="width: 100%;" />
+</td>
+</tr>
+<tr>
+<td colspan="2">
+<input type="radio" name="match" id="match_all" value="all"[ALL_CHECKED] />
+<a href="javascript: toggle_radio(\'match_all\');">[TEXT_ALL_WORDS]</a>
+<input type="radio" name="match" id="match_any" value="any"[ANY_CHECKED] />
+<a href="javascript: toggle_radio(\'match_any\');">[TEXT_ANY_WORDS]</a>
+<input type="radio" name="match" id="match_exact" value="exact"[EXACT_CHECKED] />
+<a href="javascript: toggle_radio(\'match_exact\');">[TEXT_EXACT_MATCH]</a>
+</td>
+</tr>
+</table>
+
+</form>
+
+<hr />
+	');
+	$insert_search_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'header', '$search_header', '')";
+	$database->query($insert_search_header);
+	// Search footer
+	$search_footer = addslashes('');
+	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
+	$database->query($insert_search_footer);
+	// Search results header
+	$search_results_header = addslashes(''.
+'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
+<table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
+	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
+	$database->query($insert_search_results_header);
+	// Search results loop
+	$search_results_loop = addslashes(''.
+'<tr style="background-color: #F0F0F0;">
+<td><a href="[LINK]">[TITLE]</a></td>
+<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
+</tr>
+<tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[DESCRIPTION]</td></tr>');
+
+	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
+	$database->query($insert_search_results_loop);
+	// Search results footer
+	$search_results_footer = addslashes("</table>");
+	$insert_search_results_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_footer', '$search_results_footer', '')";
+	$database->query($insert_search_results_footer);
+	// Search no results
+	$search_no_results = addslashes('<br />No results found');
+	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
+	$database->query($insert_search_no_results);
+	// Search template
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
+		
+	require_once(WB_PATH.'/framework/initialize.php');
+	$admin = new admin('dummy');
+	
+	// Include the PclZip class file (thanks to 
+	require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
+			
+	// Install add-ons
+	if(file_exists(WB_PATH.'/install/modules')) {
+		// Unpack pre-packaged modules
+			
+	}
+	if(file_exists(WB_PATH.'/install/templates')) {
+		// Unpack pre-packaged templates
+		
+	}
+	if(file_exists(WB_PATH.'/install/languages')) {
+		// Unpack pre-packaged languages
+		
+	}
+	// Load addons into DB
+	$dirs['modules'] = WB_PATH.'/modules/';
+	$dirs['templates'] = WB_PATH.'/templates/';
+	$dirs['languages'] = WB_PATH.'/languages/';
+	foreach($dirs AS $type => $dir) {
+		if($handle = opendir($dir)) {
+			while(false !== ($file = readdir($handle))) {
+				if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
+					// Get addon type
+					if($type == 'modules') {
+						load_module($dir.'/'.$file, true);
+					} elseif($type == 'templates') {
+						load_template($dir.'/'.$file);
+					} elseif($type == 'languages') {
+						load_language($dir.'/'.$file);
+					}
+				}
+			}
+		closedir($handle);
+		}
+	}
+	
+	// Check if there was a database error
+	if($database->is_error()) {
+		set_error($database->get_error());
+	}
+	
+}
+
+// Log the user in and go to Website Baker Administration
+$thisApp = new Login(
+							array(
+									"MAX_ATTEMPS" => "50",
+									"WARNING_URL" => ADMIN_URL."/login/warning.html",
+									"USERNAME_FIELDNAME" => 'admin_username',
+									"PASSWORD_FIELDNAME" => 'admin_password',
+									"REMEMBER_ME_OPTION" => SMART_LOGIN,
+									"MIN_USERNAME_LEN" => "2",
+									"MIN_PASSWORD_LEN" => "2",
+									"MAX_USERNAME_LEN" => "30",
+									"MAX_PASSWORD_LEN" => "30",
+									'LOGIN_URL' => ADMIN_URL."/login/index.php",
+									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
+									'TEMPLATE_DIR' => ADMIN_PATH."/login",
+									'TEMPLATE_FILE' => "template.html",
+									'FRONTEND' => false,
+									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
+									'USERS_TABLE' => TABLE_PREFIX."users",
+									'GROUPS_TABLE' => TABLE_PREFIX."groups",
+							)
+					);
+?>
\ No newline at end of file
Index: trunk/wb/install/index.php
===================================================================
--- trunk/wb/install/index.php	(revision 238)
+++ trunk/wb/install/index.php	(revision 239)
@@ -51,13 +51,20 @@
 <head>
 <title>Website Baker Installation Wizard</title>
 <link href="stylesheet.css" rel="stylesheet" type="text/css">
-<script language="javascript" type="text/javascript">
-function toggle_checkbox(checkbox_id) {
-	if(document.getElementById(checkbox_id).checked == true) {
-		document.getElementById(checkbox_id).checked = false;
-	} else {
-		document.getElementById(checkbox_id).checked = true;
-	}
+<script language="javascript" type="text/javascript">
+
+function toggle_checkbox(checkbox_id) {
+
+	if(document.getElementById(checkbox_id).checked == true) {
+
+		document.getElementById(checkbox_id).checked = false;
+
+	} else {
+
+		document.getElementById(checkbox_id).checked = true;
+
+	}
+
 }
 function confirm_link(message, url) {
 	if(confirm(message)) location.href = url;
@@ -72,7 +79,8 @@
 		document.getElementById('operating_system_windows').checked = true;
 		document.getElementById('file_perms_box').style.display = 'none';
 	}
-}
+}
+
 </script>
 </head>
 <body>
@@ -372,4 +380,4 @@
 </table>
 
 </body>
-</html>
+</html>
\ No newline at end of file
Index: trunk/wb/admin/groups/get_permissions.php
===================================================================
--- trunk/wb/admin/groups/get_permissions.php	(revision 238)
+++ trunk/wb/admin/groups/get_permissions.php	(revision 239)
@@ -243,4 +243,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/groups/groups.php
===================================================================
--- trunk/wb/admin/groups/groups.php	(revision 238)
+++ trunk/wb/admin/groups/groups.php	(revision 239)
@@ -182,4 +182,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/groups/index.php
===================================================================
--- trunk/wb/admin/groups/index.php	(revision 238)
+++ trunk/wb/admin/groups/index.php	(revision 239)
@@ -1,192 +1,192 @@
-<?php
-
-// $Id$
-
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
-
-// Print admin header
-require('../../config.php');
-require_once(WB_PATH.'/framework/class.admin.php');
-$admin = new admin('Access', 'groups');
-
-// Create new template object for the modify/remove menu
-$template = new Template(ADMIN_PATH.'/groups');
-$template->set_file('page', 'template.html');
-$template->set_block('page', 'main_block', 'main');
-$template->set_var('ADMIN_URL', ADMIN_URL);
-
-// Get existing value from database
-$database = new database();
-$query = "SELECT group_id,name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'";
-$results = $database->query($query);
-if($database->is_error()) {
-	$admin->print_error($database->get_error(), 'index.php');
-}
-
-// Insert values into the modify/remove menu
-$template->set_block('main_block', 'list_block', 'list');
-if($results->numRows() > 0) {
-	// Insert first value to say please select
-	$template->set_var('VALUE', '');
-	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
-	$template->parse('list', 'list_block', true);
-	// Loop through groups
-	while($group = $results->fetchRow()) {
-		$template->set_var('VALUE', $group['group_id']);
-		$template->set_var('NAME', $group['name']);
-		$template->parse('list', 'list_block', true);
-	}
-} else {
-	// Insert single value to say no groups were found
-	$template->set_var('NAME', $TEXT['NONE_FOUND']);
-	$template->parse('list', 'list_block', true);
-}
-
-// Insert permissions values
-if($admin->get_permission('groups_add') != true) {
-	$template->set_var('DISPLAY_ADD', 'hide');
-}
-if($admin->get_permission('groups_modify') != true) {
-	$template->set_var('DISPLAY_MODIFY', 'hide');
-}
-if($admin->get_permission('groups_delete') != true) {
-	$template->set_var('DISPLAY_DELETE', 'hide');
-}
-
-// Insert language headings
-$template->set_var(array(
-								'HEADING_MODIFY_DELETE_GROUP' => $HEADING['MODIFY_DELETE_GROUP'],
-								'HEADING_ADD_GROUP' => $HEADING['ADD_GROUP']
-								)
-						);
-// Insert language text and messages
-$template->set_var(array(
-								'TEXT_MODIFY' => $TEXT['MODIFY'],
-								'TEXT_DELETE' => $TEXT['DELETE'],
-								'TEXT_MANAGE_USERS' => $TEXT['MANAGE_USERS'],
-								'CONFIRM_DELETE' => $MESSAGE['GROUPS']['CONFIRM_DELETE']
-								)
-						);
-
-// Parse template object
-$template->parse('main', 'main_block', false);
-$template->pparse('output', 'page');
-
-// Setup template for add group form
-$template = new Template(ADMIN_PATH.'/groups');
-$template->set_file('page', 'group_form.html');
-$template->set_block('page', 'main_block', 'main');
-$template->set_var('DISPLAY_EXTRA', 'none');
-$template->set_var('ACTION_URL', ADMIN_URL.'/groups/add.php');
-$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
-$template->set_var('ADVANCED_ACTION', 'index.php');
-
-// Tell the browser whether or not to show advanced options
-if(isset($_POST['advanced']) AND $_POST['advanced'] == $TEXT['SHOW_ADVANCED'].' >>') {
-	$template->set_var('DISPLAY_ADVANCED', '');
-	$template->set_var('DISPLAY_BASIC', 'none');
-	$template->set_var('ADVANCED', 'yes');
-	$template->set_var('ADVANCED_BUTTON', '<< '.$TEXT['HIDE_ADVANCED']);
-} else {
-	$template->set_var('DISPLAY_ADVANCED', 'none');
-	$template->set_var('DISPLAY_BASIC', '');
-	$template->set_var('ADVANCED', 'no');
-	$template->set_var('ADVANCED_BUTTON', $TEXT['SHOW_ADVANCED'].' >>');
-}
-
-// Insert permissions values
-if($admin->get_permission('groups_add') != true) {
-	$template->set_var('DISPLAY_ADD', 'hide');
-}
-
-// Insert values into module list
-$template->set_block('main_block', 'module_list_block', 'module_list');
-$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'page'");
-if($result->numRows() > 0) {
-	while($addon = $result->fetchRow()) {
-		$template->set_var('VALUE', $addon['directory']);
-		$template->set_var('NAME', $addon['name']);
-		$template->parse('module_list', 'module_list_block', true);
-	}
-}
-
-// Insert values into template list
-$template->set_block('main_block', 'template_list_block', 'template_list');
-$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
-if($result->numRows() > 0) {
-	while($addon = $result->fetchRow()) {
-		$template->set_var('VALUE', $addon['directory']);
-		$template->set_var('NAME', $addon['name']);
-		$template->parse('template_list', 'template_list_block', true);
-	}
-}
-
-// Insert language text and messages
-$template->set_var(array(
-								'TEXT_RESET' => $TEXT['RESET'],
-								'TEXT_ACTIVE' => $TEXT['ACTIVE'],
-								'TEXT_DISABLED' => $TEXT['DISABLED'],
-								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
-								'TEXT_USERNAME' => $TEXT['USERNAME'],
-								'TEXT_PASSWORD' => $TEXT['PASSWORD'],
-								'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
-								'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
-								'TEXT_EMAIL' => $TEXT['EMAIL'],
-								'TEXT_GROUP' => $TEXT['GROUP'],
-								'TEXT_SYSTEM_PERMISSIONS' => $TEXT['SYSTEM_PERMISSIONS'],
-								'TEXT_MODULE_PERMISSIONS' => $TEXT['MODULE_PERMISSIONS'],
-								'TEXT_TEMPLATE_PERMISSIONS' => $TEXT['TEMPLATE_PERMISSIONS'],
-								'TEXT_NAME' => $TEXT['NAME'],
-								'SECTION_PAGES' => $MENU['PAGES'],
-								'SECTION_MEDIA' => $MENU['MEDIA'],
-								'SECTION_MODULES' => $MENU['MODULES'],
-								'SECTION_TEMPLATES' => $MENU['TEMPLATES'],
-								'SECTION_SETTINGS' => $MENU['SETTINGS'],
-								'SECTION_LANGUAGES' => $MENU['LANGUAGES'],
-								'SECTION_USERS' => $MENU['USERS'],
-								'SECTION_GROUPS' => $MENU['GROUPS'],
-								'TEXT_VIEW' => $TEXT['VIEW'],
-								'TEXT_ADD' => $TEXT['ADD'],
-								'TEXT_LEVEL' => $TEXT['LEVEL'],
-								'TEXT_MODIFY' => $TEXT['MODIFY'],
-								'TEXT_DELETE' => $TEXT['DELETE'],
-								'TEXT_MODIFY_CONTENT' => $TEXT['MODIFY_CONTENT'],
-								'TEXT_MODIFY_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
-								'HEADING_MODIFY_INTRO_PAGE' => $HEADING['MODIFY_INTRO_PAGE'],
-								'TEXT_CREATE_FOLDER' => $TEXT['CREATE_FOLDER'],
-								'TEXT_RENAME' => $TEXT['RENAME'],
-								'TEXT_UPLOAD_FILES' => $TEXT['UPLOAD_FILES'],
-								'TEXT_BASIC' => $TEXT['BASIC'],
-								'TEXT_ADVANCED' => $TEXT['ADVANCED'],
-								'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
-								'CHECKED' => 'checked'
-								)
-						);
-
-// Parse template for add group form
-$template->parse('main', 'main_block', false);
-$template->pparse('output', 'page');
-
-// Print the admin footer
-$admin->print_footer();
-
-?>
+<?php
+
+// $Id$
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+// Print admin header
+require('../../config.php');
+require_once(WB_PATH.'/framework/class.admin.php');
+$admin = new admin('Access', 'groups');
+
+// Create new template object for the modify/remove menu
+$template = new Template(ADMIN_PATH.'/groups');
+$template->set_file('page', 'template.html');
+$template->set_block('page', 'main_block', 'main');
+$template->set_var('ADMIN_URL', ADMIN_URL);
+
+// Get existing value from database
+$database = new database();
+$query = "SELECT group_id,name FROM ".TABLE_PREFIX."groups WHERE group_id != '1'";
+$results = $database->query($query);
+if($database->is_error()) {
+	$admin->print_error($database->get_error(), 'index.php');
+}
+
+// Insert values into the modify/remove menu
+$template->set_block('main_block', 'list_block', 'list');
+if($results->numRows() > 0) {
+	// Insert first value to say please select
+	$template->set_var('VALUE', '');
+	$template->set_var('NAME', $TEXT['PLEASE_SELECT'].'...');
+	$template->parse('list', 'list_block', true);
+	// Loop through groups
+	while($group = $results->fetchRow()) {
+		$template->set_var('VALUE', $group['group_id']);
+		$template->set_var('NAME', $group['name']);
+		$template->parse('list', 'list_block', true);
+	}
+} else {
+	// Insert single value to say no groups were found
+	$template->set_var('NAME', $TEXT['NONE_FOUND']);
+	$template->parse('list', 'list_block', true);
+}
+
+// Insert permissions values
+if($admin->get_permission('groups_add') != true) {
+	$template->set_var('DISPLAY_ADD', 'hide');
+}
+if($admin->get_permission('groups_modify') != true) {
+	$template->set_var('DISPLAY_MODIFY', 'hide');
+}
+if($admin->get_permission('groups_delete') != true) {
+	$template->set_var('DISPLAY_DELETE', 'hide');
+}
+
+// Insert language headings
+$template->set_var(array(
+								'HEADING_MODIFY_DELETE_GROUP' => $HEADING['MODIFY_DELETE_GROUP'],
+								'HEADING_ADD_GROUP' => $HEADING['ADD_GROUP']
+								)
+						);
+// Insert language text and messages
+$template->set_var(array(
+								'TEXT_MODIFY' => $TEXT['MODIFY'],
+								'TEXT_DELETE' => $TEXT['DELETE'],
+								'TEXT_MANAGE_USERS' => $TEXT['MANAGE_USERS'],
+								'CONFIRM_DELETE' => $MESSAGE['GROUPS']['CONFIRM_DELETE']
+								)
+						);
+
+// Parse template object
+$template->parse('main', 'main_block', false);
+$template->pparse('output', 'page');
+
+// Setup template for add group form
+$template = new Template(ADMIN_PATH.'/groups');
+$template->set_file('page', 'group_form.html');
+$template->set_block('page', 'main_block', 'main');
+$template->set_var('DISPLAY_EXTRA', 'none');
+$template->set_var('ACTION_URL', ADMIN_URL.'/groups/add.php');
+$template->set_var('SUBMIT_TITLE', $TEXT['ADD']);
+$template->set_var('ADVANCED_ACTION', 'index.php');
+
+// Tell the browser whether or not to show advanced options
+if(isset($_POST['advanced']) AND $_POST['advanced'] == $TEXT['SHOW_ADVANCED'].' >>') {
+	$template->set_var('DISPLAY_ADVANCED', '');
+	$template->set_var('DISPLAY_BASIC', 'none');
+	$template->set_var('ADVANCED', 'yes');
+	$template->set_var('ADVANCED_BUTTON', '<< '.$TEXT['HIDE_ADVANCED']);
+} else {
+	$template->set_var('DISPLAY_ADVANCED', 'none');
+	$template->set_var('DISPLAY_BASIC', '');
+	$template->set_var('ADVANCED', 'no');
+	$template->set_var('ADVANCED_BUTTON', $TEXT['SHOW_ADVANCED'].' >>');
+}
+
+// Insert permissions values
+if($admin->get_permission('groups_add') != true) {
+	$template->set_var('DISPLAY_ADD', 'hide');
+}
+
+// Insert values into module list
+$template->set_block('main_block', 'module_list_block', 'module_list');
+$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'page'");
+if($result->numRows() > 0) {
+	while($addon = $result->fetchRow()) {
+		$template->set_var('VALUE', $addon['directory']);
+		$template->set_var('NAME', $addon['name']);
+		$template->parse('module_list', 'module_list_block', true);
+	}
+}
+
+// Insert values into template list
+$template->set_block('main_block', 'template_list_block', 'template_list');
+$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
+if($result->numRows() > 0) {
+	while($addon = $result->fetchRow()) {
+		$template->set_var('VALUE', $addon['directory']);
+		$template->set_var('NAME', $addon['name']);
+		$template->parse('template_list', 'template_list_block', true);
+	}
+}
+
+// Insert language text and messages
+$template->set_var(array(
+								'TEXT_RESET' => $TEXT['RESET'],
+								'TEXT_ACTIVE' => $TEXT['ACTIVE'],
+								'TEXT_DISABLED' => $TEXT['DISABLED'],
+								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
+								'TEXT_USERNAME' => $TEXT['USERNAME'],
+								'TEXT_PASSWORD' => $TEXT['PASSWORD'],
+								'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
+								'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
+								'TEXT_EMAIL' => $TEXT['EMAIL'],
+								'TEXT_GROUP' => $TEXT['GROUP'],
+								'TEXT_SYSTEM_PERMISSIONS' => $TEXT['SYSTEM_PERMISSIONS'],
+								'TEXT_MODULE_PERMISSIONS' => $TEXT['MODULE_PERMISSIONS'],
+								'TEXT_TEMPLATE_PERMISSIONS' => $TEXT['TEMPLATE_PERMISSIONS'],
+								'TEXT_NAME' => $TEXT['NAME'],
+								'SECTION_PAGES' => $MENU['PAGES'],
+								'SECTION_MEDIA' => $MENU['MEDIA'],
+								'SECTION_MODULES' => $MENU['MODULES'],
+								'SECTION_TEMPLATES' => $MENU['TEMPLATES'],
+								'SECTION_SETTINGS' => $MENU['SETTINGS'],
+								'SECTION_LANGUAGES' => $MENU['LANGUAGES'],
+								'SECTION_USERS' => $MENU['USERS'],
+								'SECTION_GROUPS' => $MENU['GROUPS'],
+								'TEXT_VIEW' => $TEXT['VIEW'],
+								'TEXT_ADD' => $TEXT['ADD'],
+								'TEXT_LEVEL' => $TEXT['LEVEL'],
+								'TEXT_MODIFY' => $TEXT['MODIFY'],
+								'TEXT_DELETE' => $TEXT['DELETE'],
+								'TEXT_MODIFY_CONTENT' => $TEXT['MODIFY_CONTENT'],
+								'TEXT_MODIFY_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
+								'HEADING_MODIFY_INTRO_PAGE' => $HEADING['MODIFY_INTRO_PAGE'],
+								'TEXT_CREATE_FOLDER' => $TEXT['CREATE_FOLDER'],
+								'TEXT_RENAME' => $TEXT['RENAME'],
+								'TEXT_UPLOAD_FILES' => $TEXT['UPLOAD_FILES'],
+								'TEXT_BASIC' => $TEXT['BASIC'],
+								'TEXT_ADVANCED' => $TEXT['ADVANCED'],
+								'CHANGING_PASSWORD' => $MESSAGE['USERS']['CHANGING_PASSWORD'],
+								'CHECKED' => 'checked'
+								)
+						);
+
+// Parse template for add group form
+$template->parse('main', 'main_block', false);
+$template->pparse('output', 'page');
+
+// Print the admin footer
+$admin->print_footer();
+
+?>
\ No newline at end of file
Index: trunk/wb/admin/media/rename2.php
===================================================================
--- trunk/wb/admin/media/rename2.php	(revision 238)
+++ trunk/wb/admin/media/rename2.php	(revision 239)
@@ -163,5 +163,4 @@
 } else {
 	$admin->print_error($MESSAGE['MEDIA']['CANNOT_RENAME'], "rename.php?dir=$directory&id=$file_id", false);
 }
-
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/media/browse.php
===================================================================
--- trunk/wb/admin/media/browse.php	(revision 238)
+++ trunk/wb/admin/media/browse.php	(revision 239)
@@ -176,4 +176,4 @@
 $template->parse('main', 'main_block', false);
 $template->pparse('output', 'page');
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/media/delete.php
===================================================================
--- trunk/wb/admin/media/delete.php	(revision 238)
+++ trunk/wb/admin/media/delete.php	(revision 239)
@@ -117,4 +117,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/media/rename.php
===================================================================
--- trunk/wb/admin/media/rename.php	(revision 238)
+++ trunk/wb/admin/media/rename.php	(revision 239)
@@ -136,4 +136,4 @@
 $template->parse('main', 'main_block', false);
 $template->pparse('output', 'page');
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/templates/install.php
===================================================================
--- trunk/wb/admin/templates/install.php	(revision 238)
+++ trunk/wb/admin/templates/install.php	(revision 239)
@@ -128,4 +128,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/templates/index.php
===================================================================
--- trunk/wb/admin/templates/index.php	(revision 238)
+++ trunk/wb/admin/templates/index.php	(revision 239)
@@ -77,4 +77,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/intro.php
===================================================================
--- trunk/wb/admin/pages/intro.php	(revision 238)
+++ trunk/wb/admin/pages/intro.php	(revision 239)
@@ -76,4 +76,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/settings.php
===================================================================
--- trunk/wb/admin/pages/settings.php	(revision 238)
+++ trunk/wb/admin/pages/settings.php	(revision 239)
@@ -414,4 +414,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/sections_save.php
===================================================================
--- trunk/wb/admin/pages/sections_save.php	(revision 238)
+++ trunk/wb/admin/pages/sections_save.php	(revision 239)
@@ -105,4 +105,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/index.php
===================================================================
--- trunk/wb/admin/pages/index.php	(revision 238)
+++ trunk/wb/admin/pages/index.php	(revision 239)
@@ -544,4 +544,4 @@
 // Print admin 
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/intro2.php
===================================================================
--- trunk/wb/admin/pages/intro2.php	(revision 238)
+++ trunk/wb/admin/pages/intro2.php	(revision 239)
@@ -59,4 +59,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/sections.php
===================================================================
--- trunk/wb/admin/pages/sections.php	(revision 238)
+++ trunk/wb/admin/pages/sections.php	(revision 239)
@@ -263,4 +263,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/pages/add.php
===================================================================
--- trunk/wb/admin/pages/add.php	(revision 238)
+++ trunk/wb/admin/pages/add.php	(revision 239)
@@ -146,4 +146,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/settings/save.php
===================================================================
--- trunk/wb/admin/settings/save.php	(revision 238)
+++ trunk/wb/admin/settings/save.php	(revision 239)
@@ -160,4 +160,4 @@
 $admin->print_success($MESSAGE['SETTINGS']['SAVED'], ADMIN_URL.'/settings/index.php'.$advanced);
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/settings/template.html
===================================================================
--- trunk/wb/admin/settings/template.html	(revision 238)
+++ trunk/wb/admin/settings/template.html	(revision 239)
@@ -583,4 +583,4 @@
 &nbsp; {MODE_SWITCH_WARNING}
 </font>
 
-<!-- END main_block -->
+<!-- END main_block -->
\ No newline at end of file
Index: trunk/wb/admin/preferences/index.php
===================================================================
--- trunk/wb/admin/preferences/index.php	(revision 238)
+++ trunk/wb/admin/preferences/index.php	(revision 239)
@@ -149,4 +149,4 @@
 
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/languages/index.php
===================================================================
--- trunk/wb/admin/languages/index.php	(revision 238)
+++ trunk/wb/admin/languages/index.php	(revision 239)
@@ -78,4 +78,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/admin/modules/index.php
===================================================================
--- trunk/wb/admin/modules/index.php	(revision 238)
+++ trunk/wb/admin/modules/index.php	(revision 239)
@@ -78,4 +78,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/wysiwyg/view.php
===================================================================
--- trunk/wb/modules/wysiwyg/view.php	(revision 238)
+++ trunk/wb/modules/wysiwyg/view.php	(revision 239)
@@ -32,4 +32,4 @@
 
 echo $content;
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/wysiwyg/save.php
===================================================================
--- trunk/wb/modules/wysiwyg/save.php	(revision 238)
+++ trunk/wb/modules/wysiwyg/save.php	(revision 239)
@@ -48,4 +48,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/wysiwyg/modify.php
===================================================================
--- trunk/wb/modules/wysiwyg/modify.php	(revision 238)
+++ trunk/wb/modules/wysiwyg/modify.php	(revision 239)
@@ -76,4 +76,4 @@
 
 </form>
 
-<br />
+<br />
\ No newline at end of file
Index: trunk/wb/modules/news/modify_post.php
===================================================================
--- trunk/wb/modules/news/modify_post.php	(revision 238)
+++ trunk/wb/modules/news/modify_post.php	(revision 239)
@@ -194,4 +194,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/news/comment.php
===================================================================
--- trunk/wb/modules/news/comment.php	(revision 238)
+++ trunk/wb/modules/news/comment.php	(revision 239)
@@ -68,4 +68,4 @@
 }
 
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/modules/news/view.php
===================================================================
--- trunk/wb/modules/news/view.php	(revision 238)
+++ trunk/wb/modules/news/view.php	(revision 239)
@@ -329,4 +329,4 @@
 		
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/account/login_form.php
===================================================================
--- trunk/wb/account/login_form.php	(revision 238)
+++ trunk/wb/account/login_form.php	(revision 239)
@@ -113,4 +113,4 @@
 
 <br />
 
-<a href="<?php echo WB_URL; ?>/account/forgot.php"><?php echo $TEXT['FORGOTTEN_DETAILS']; ?></a>
+<a href="<?php echo WB_URL; ?>/account/forgot.php"><?php echo $TEXT['FORGOTTEN_DETAILS']; ?></a>
\ No newline at end of file
Index: trunk/wb/account/forgot.php
===================================================================
--- trunk/wb/account/forgot.php	(revision 238)
+++ trunk/wb/account/forgot.php	(revision 239)
@@ -54,4 +54,4 @@
 // Include the index (wrapper) file
 require(WB_PATH.'/index.php');
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/account/preferences.php
===================================================================
--- trunk/wb/account/preferences.php	(revision 238)
+++ trunk/wb/account/preferences.php	(revision 239)
@@ -65,4 +65,4 @@
 // Include the index (wrapper) file
 require(WB_PATH.'/index.php');
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/account/forgot_form.php
===================================================================
--- trunk/wb/account/forgot_form.php	(revision 238)
+++ trunk/wb/account/forgot_form.php	(revision 239)
@@ -138,4 +138,4 @@
 		</tr>
 		<?php } ?>
 		</table>
-</form>
+</form>
\ No newline at end of file
Index: trunk/wb/account/preferences_form.php
===================================================================
--- trunk/wb/account/preferences_form.php	(revision 238)
+++ trunk/wb/account/preferences_form.php	(revision 239)
@@ -228,4 +228,4 @@
 </tr>
 </table>
 
-</form>
+</form>
\ No newline at end of file
Index: trunk/wb/account/details.php
===================================================================
--- trunk/wb/account/details.php	(revision 238)
+++ trunk/wb/account/details.php	(revision 239)
@@ -66,4 +66,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/account/signup2.php
===================================================================
--- trunk/wb/account/signup2.php	(revision 238)
+++ trunk/wb/account/signup2.php	(revision 239)
@@ -118,4 +118,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/account/login.php
===================================================================
--- trunk/wb/account/login.php	(revision 238)
+++ trunk/wb/account/login.php	(revision 239)
@@ -81,4 +81,4 @@
 require(WB_PATH.'/index.php');
 
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/framework/class.admin.php
===================================================================
--- trunk/wb/framework/class.admin.php	(revision 238)
+++ trunk/wb/framework/class.admin.php	(revision 239)
@@ -227,4 +227,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/framework/class.login.php
===================================================================
--- trunk/wb/framework/class.login.php	(revision 238)
+++ trunk/wb/framework/class.login.php	(revision 239)
@@ -363,4 +363,4 @@
 	
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/framework/class.frontend.php
===================================================================
--- trunk/wb/framework/class.frontend.php	(revision 238)
+++ trunk/wb/framework/class.frontend.php	(revision 239)
@@ -93,7 +93,7 @@
 				// Check if we should redirect or include page inline
 				if(HOMEPAGE_REDIRECTION) {
 					// Redirect to page
-					header("Location: ".page_link($this->default_link));
+					header("Location: ".$this->page_link($this->default_link));
 					exit();
 				} else {
 					// Include page inline
@@ -132,7 +132,7 @@
 			// Check if the page language is also the selected language. If not, send headers again.
 			if ($this->page['language']!=LANGUAGE) {
 				require_once(WB_PATH.'/framework/functions.php');
-				header('Location: '.page_link($this->page['link']).'?lang='.$this->page['language']);
+				header('Location: '.$this->page_link($this->page['link']).'?lang='.$this->page['language']);
 				exit();
 			}
 			// Begin code to set details as either variables of constants
@@ -268,7 +268,7 @@
 			// Get page link
 			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
 			$fetch_link = $get_link->fetchRow();
-			$link = page_link($fetch_link['link']);
+			$link = $this->page_link($fetch_link['link']);
 			$content = preg_replace($pattern,$link,$content);
 		}
 	}
Index: trunk/wb/framework/functions.php
===================================================================
--- trunk/wb/framework/functions.php	(revision 238)
+++ trunk/wb/framework/functions.php	(revision 239)
@@ -756,4 +756,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
Index: trunk/wb/index.php
===================================================================
--- trunk/wb/index.php	(revision 238)
+++ trunk/wb/index.php	(revision 239)
@@ -55,4 +55,4 @@
 // Display the template
 require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
 
-?>
+?>
\ No newline at end of file
