Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 542)
+++ trunk/CHANGELOG	(revision 543)
@@ -11,6 +11,11 @@
 ! = Update/Change
 
 ------------------------------------- 2.7.0 -------------------------------------
+16-Jan-2008 Thomas Hornik
+! changed module menu_link: added table mod_menu_link, fixed page-deleting-bug,
+	fixed odd behavior in case of menu_link as default-page.
+16-Jan-2008 Thomas Hornik
+# changing PHP-error-level within website baker does not work - fixed (fixed ticket 532)
 14-Jan-2008 Matthias Gallas
 #	Replaced hardcoded .php with the variable PAGE_EXTENSION for the use in pagenames.
 	(!!Attention!! To get extenions other than .php working additional fixes are necessary!)
Index: trunk/wb/admin/pages/settings2.php
===================================================================
--- trunk/wb/admin/pages/settings2.php	(revision 542)
+++ trunk/wb/admin/pages/settings2.php	(revision 543)
@@ -143,12 +143,6 @@
 // Get page trail
 $page_trail = get_page_trail($page_id);
 
-// Make sure link is not overwritten if page uses the menu link module
-$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
-if($query_sections->numRows() > 0) {
-	$link = $old_link;
-} 
-
 // Update page settings in the pages table
 $query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', page_title = '$page_title', menu_title = '$menu_title', menu = '$menu', level = '$level', page_trail = '$page_trail', root_parent = '$root_parent', link = '$link', template = '$template', target = '$target', description = '$description', keywords = '$keywords', position = '$position', visibility = '$visibility', searching = '$searching', language = '$language', admin_groups = '$admin_groups', viewing_groups = '$viewing_groups' WHERE page_id = '$page_id'";
 $database->query($query);
@@ -237,4 +231,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/modules/menu_link/modify.html
===================================================================
--- trunk/wb/modules/menu_link/modify.html	(revision 542)
+++ trunk/wb/modules/menu_link/modify.html	(nonexistent)
@@ -1,47 +0,0 @@
-<!-- BEGIN main_block -->
-
-<form action="{WB_URL}/modules/menu_link/save.php" method="post">
-
-<input type="hidden" name="page_id" value="{PAGE_ID}" />
-<input type="hidden" name="section_id" value="{SECTION_ID}" />
-
-<table cellpadding="0" cellspacing="0" border="0" width="100%">
-<tr>
-	<td>
-		{TEXT_LINK}:
-	</td>
-	<td>
-		<input type="text" id="link" name="link" style="width: 100%;" value="{LINK}" />
-	</td>
-</tr>
-<tr>
-	<td>
-		{TEXT_TARGET}:
-	</td>
-	<td>
-		<select name="target" style="WIDTH: 100%;" value="{TARGET}" />
-			<option value="_blank"{BLANK_SELECTED}>{TEXT_NEW_WINDOW}</option>
-			<option value="_self"{SELF_SELECTED}>{TEXT_SAME_WINDOW}</option>
-			<option value="_top"{TOP_SELECTED}>{TEXT_TOP_FRAME}</option>
-		</select>
-	</td>
-</tr>
-</table>
-
-<br />
-
-<table cellpadding="0" cellspacing="0" border="0" width="100%">
-<tr>
-	<td align="left">
-		<input type="submit" value="{TEXT_SAVE}" style="width: 100px; margin-top: 5px;" />
-	</td>
-	<td align="right">
-		</form>
-		<input type="button" value="{TEXT_CANCEL}" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
-	</td>
-</tr>
-</table>
-
-</form>
-
-<!-- END main_block -->
\ No newline at end of file

Property changes on: trunk/wb/modules/menu_link/modify.html
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Id
\ No newline at end of property
Index: trunk/wb/modules/menu_link/uninstall.php
===================================================================
--- trunk/wb/modules/menu_link/uninstall.php	(nonexistent)
+++ trunk/wb/modules/menu_link/uninstall.php	(revision 543)
@@ -0,0 +1,34 @@
+<?php
+
+// $Id$
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2008, 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
+
+*/
+
+// prevent this file from being accesses directly
+if(defined('WB_PATH') == false) {
+	exit("Cannot access this file directly"); 
+}
+
+$table = TABLE_PREFIX ."mod_menu_link";
+$database->query("DROP TABLE `$table`");
+
+?>
\ No newline at end of file
Index: trunk/wb/modules/menu_link/view.php
===================================================================
--- trunk/wb/modules/menu_link/view.php	(revision 542)
+++ trunk/wb/modules/menu_link/view.php	(revision 543)
@@ -31,4 +31,4 @@
 ?>
 <a href="<?php echo WB_URL; ?>">
 Click HERE to go to the main page
-</a>
\ No newline at end of file
+</a>
Index: trunk/wb/modules/menu_link/info.php
===================================================================
--- trunk/wb/modules/menu_link/info.php	(revision 542)
+++ trunk/wb/modules/menu_link/info.php	(revision 543)
@@ -23,13 +23,23 @@
 
 */
 
+/* History:
+
+2.6.1.0 - 16. Jan. 2008 - thorn
+- added table mod_menu_link
+- added install.php, delete.php, add.php
+- changed wb/index.php: redirect if page is menu_link
+- removed special-handling of menu_link in: admin/pages/settings2.php
+
+*/
+
 $module_directory = 'menu_link';
 $module_name = 'Menu Link';
 $module_function = 'page';
-$module_version = '2.6';
+$module_version = '2.6.1.0';
 $module_platform = '2.6.x';
-$module_author = 'Ryan Djurovich';
+$module_author = 'Ryan Djurovich, thorn';
 $module_license = 'GNU General Public License';
 $module_description = 'This module allows you to insert a link into the menu.';
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/modules/menu_link/save.php
===================================================================
--- trunk/wb/modules/menu_link/save.php	(revision 542)
+++ trunk/wb/modules/menu_link/save.php	(revision 543)
@@ -29,17 +29,17 @@
 $update_when_modified = true; // Tells script to update when this page was last updated
 require(WB_PATH.'/modules/admin.php');
 
-$database = new database();
-
 // Update the mod_menu_links table with the link
-if(isset($_POST['link'])) {
-	// Update link and target
-	$link = $admin->add_slashes($_POST['link']);
-	$target = $_POST['target'];
-	$query = "UPDATE ".TABLE_PREFIX."pages SET link = '$link', target = '$target' WHERE page_id = '$page_id'";
-	$database->query($query);
+if(isset($_POST['link']) && isset($_POST['target'])) {
+	// Update id and target
+	$foreign_page_id = $_POST['link']; // foreign-page_id
+	$url_target = $_POST['target'];
+	$table_pages = TABLE_PREFIX.'pages';
+	$table_mod = TABLE_PREFIX.'mod_menu_link';
+	$database->query("UPDATE $table_pages SET target = '$url_target' WHERE page_id = '$page_id'");
+	$database->query("UPDATE $table_mod SET target_page_id = '$foreign_page_id' WHERE page_id = '$page_id'");
 } else {
-	$admin->print_error('Error in wb/modules/menu_link/save.php at line 35', $js_back);
+	$admin->print_error('Error in wb/modules/menu_link/save.php at line 35', true);
 }
 
 // Check if there is a database error, otherwise say successful
@@ -52,4 +52,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/modules/menu_link/delete.php
===================================================================
--- trunk/wb/modules/menu_link/delete.php	(revision 542)
+++ trunk/wb/modules/menu_link/delete.php	(revision 543)
@@ -23,6 +23,12 @@
 
 */
 
-// Nothing special has to be deleted
+// prevent this file from being accesses directly
+if(defined('WB_PATH') == false) {
+	exit("Cannot access this file directly"); 
+}
 
+$table = TABLE_PREFIX ."mod_menu_link";
+$database->query("DELETE FROM `$table` WHERE section_id = '$section_id'");
+
 ?>
\ No newline at end of file
Index: trunk/wb/modules/menu_link/install.php
===================================================================
--- trunk/wb/modules/menu_link/install.php	(revision 542)
+++ trunk/wb/modules/menu_link/install.php	(revision 543)
@@ -23,6 +23,21 @@
 
 */
 
-// No table is needed for this module
+// prevent this file from being accesses directly
+if(defined('WB_PATH') == false) {
+	exit("Cannot access this file directly"); 
+}
 
+$table = TABLE_PREFIX ."mod_menu_link";
+$database->query("DROP TABLE IF EXISTS `$table`");
+
+$database->query("
+	CREATE TABLE `$table` (
+		`section_id` INT(11) NOT NULL DEFAULT '0',
+		`page_id` INT(11) NOT NULL DEFAULT '0',
+		`target_page_id` INT(11) NOT NULL DEFAULT '0',
+		PRIMARY KEY (`section_id`)
+	)
+");
+
 ?>
\ No newline at end of file
Index: trunk/wb/modules/menu_link/modify.php
===================================================================
--- trunk/wb/modules/menu_link/modify.php	(revision 542)
+++ trunk/wb/modules/menu_link/modify.php	(revision 543)
@@ -23,49 +23,85 @@
 
 */
 
-// Setup template object
-$template = new Template(WB_PATH.'/modules/menu_link');
-$template->set_file('page', 'modify.html');
-$template->set_block('page', 'main_block', 'main');
+// Must include code to stop this file being access directly
+if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
 
-// Get page link and target
-$query_info = "SELECT link,target FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
-$get_info = $database->query($query_info);
-$fetch_info = $get_info->fetchRow();
-$link = ($fetch_info['link']);
-$target = $fetch_info['target'];
+// get target page_id
+$table = TABLE_PREFIX.'mod_menu_link';
+$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
+$sql_row = $sql_result->fetchRow();
+$target_page_id = $sql_row['target_page_id'];
 
-// Insert vars
-$template->set_var(array(
-								'PAGE_ID' => $page_id,
-								'WB_URL' => WB_URL,
-								'LINK' => $link,
-								'TEXT_LINK' => $TEXT['LINK'],
-								'TEXT_TARGET' => $TEXT['TARGET'],
-								'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
-								'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
-								'TEXT_TOP_FRAME' => $TEXT['TOP_FRAME'],
-								'TEXT_SAVE' => $TEXT['SAVE'],
-								'TEXT_CANCEL' => $TEXT['CANCEL'],
-								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT']
-								)
-						);
-
-// Select what the page target is
-switch ($target) {
-	case '_top':
-		$template->set_var('TOP_SELECTED', ' selected');
-		break;
-	case '_self':
-		$template->set_var('SELF_SELECTED', ' selected');
-		break;
-	case '_blank':
-		$template->set_var('BLANK_SELECTED', ' selected');
-		break;
+// Get list of all visible page-links, except menu_links and actual page
+$table_p = TABLE_PREFIX."pages";
+$table_s = TABLE_PREFIX."sections";
+$query_page = $database->query("SELECT DISTINCT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module != 'menu_link' AND p.page_id != '$page_id' AND parent = '0' ORDER BY position");
+if($query_page->numRows() > 0) {
+	while($page = $query_page->fetchRow()) {
+		if($admin->page_is_visible($page)) {
+			$links[$page['page_id']]='/'.$page['menu_title'];
+			$query_subpage = $database->query("SELECT DISTINCT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module != 'menu_link' AND p.page_id != '$page_id' AND root_parent = '{$page['page_id']}' ORDER BY level");
+			if($query_subpage->numRows() > 0) {
+				while($sub = $query_subpage->fetchRow()) {
+					if($admin->page_is_visible($sub)) {
+						$links[$sub['page_id']]=$links[$sub['parent']].'/'.$sub['menu_title'];
+					}
+				}
+			}
+		}
+	}
 }
 
-// Parse template object
-$template->parse('main', 'main_block', false);
-$template->pparse('output', 'page');
+// get URL-target for actual page
+$table = TABLE_PREFIX."pages";
+$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
+$page = $query_page->fetchRow();
+$target = $page['target'];
 
-?>
\ No newline at end of file
+?>
+<form action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
+<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
+<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
+<table cellpadding="0" cellspacing="0" border="0" width="100%">
+<tr>
+	<td>
+		<?php echo $TEXT['LINK'].':' ?>
+	</td>
+	<td>
+		<select name="link" style="WIDTH: 100%;" value="<?php echo "" ?>" />
+		<?php
+		foreach($links as $id=>$l) { ?>
+			<option value="<?php echo $id ?>"<?php if($id==$target_page_id) echo ' selected'; ?>><?php echo $l ?></option>
+		<?php } ?>
+	</td>
+</tr>
+<tr>
+	<td>
+		<?php echo $TEXT['TARGET'].':' ?>
+	</td>
+	<td>
+		<select name="target" style="WIDTH: 100%;" value="<?php echo "" ?>" />
+			<option value="_blank"<?php if($target=='_blank') echo ' selected'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
+			<option value="_self"<?php if($target=='_self') echo ' selected'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
+			<option value="_top"<?php if($target=='_top') echo ' selected'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
+		</select>
+	</td>
+</tr>
+</table>
+
+<br />
+
+<table cellpadding="0" cellspacing="0" border="0" width="100%">
+<tr>
+	<td align="left">
+		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
+	</td>
+	<td align="right">
+		</form>
+		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
+	</td>
+</tr>
+</table>
+
+</form>
+
Index: trunk/wb/modules/menu_link/add.php
===================================================================
--- trunk/wb/modules/menu_link/add.php	(revision 542)
+++ trunk/wb/modules/menu_link/add.php	(revision 543)
@@ -23,6 +23,12 @@
 
 */
 
-// Nothing needs to be inserted anywhere special
+// prevent this file from being accesses directly
+if(defined('WB_PATH') == false) {
+	exit("Cannot access this file directly"); 
+}
 
+$table = TABLE_PREFIX ."mod_menu_link";
+$database->query("INSERT INTO `$table` (`page_id`, `section_id`, target_page_id) VALUES ('$page_id', '$section_id', '0')");
+
 ?>
\ No newline at end of file
Index: trunk/wb/framework/class.wb.php
===================================================================
--- trunk/wb/framework/class.wb.php	(revision 542)
+++ trunk/wb/framework/class.wb.php	(revision 543)
@@ -45,6 +45,47 @@
 	// performed when frontend or backend is loaded.
 	function wb() {
 	}
+	
+	// Check whether a page is visible or not.
+	// This will check page-visibility and user- and group-rights.
+	/* page_is_visible() returns
+		false: if page-visibility is 'none' or 'deleted', or page-vis. is 'registered' or 'private' and user isn't allowed to see the page.
+		true: if page-visibility is 'public' or 'hidden', or page-vis. is 'registered' or 'private' and user _is_ allowed to see the page.
+	*/
+	function page_is_visible($page) {
+		$show_it = false; // shall we show the page?
+		$page_id = $page['page_id'];
+		$visibility = $page['visibility'];
+		$viewing_groups = $page['viewing_groups'];
+		$viewing_users = $page['viewing_users'];
+		// First check if visibility is 'none', 'deleted'
+		if($visibility == 'none') {
+			return(false);
+		} elseif($visibility == 'deleted') {
+			return(false);
+		}
+		// Now check if visibility is 'hidden', 'private' or 'registered'
+		if($visibility == 'hidden') { // hidden: hide the menu-link, but show the page
+			$show_it = true;
+		} elseif($visibility == 'private' || $visibility == 'registered') {
+			// Check if the user is logged in
+			if($this->is_authenticated() == true) {
+				// Now check if the user has perms to view the page
+				if(in_array($this->get_group_id(), explode(',', $viewing_groups)) || in_array($this->get_user_id(), explode(',', $viewing_users))) {
+					$show_it = true;
+				} else {
+					$show_it = false;
+				}
+			} else {
+				$show_it = false;
+			}
+		} elseif($visibility == 'public') {
+			$show_it = true;
+		} else {
+			$show_it = false;
+		}
+		return($show_it);
+	}
 
 	// Check whether we should show a page or not (for front-end)
 	function show_page($page) {
@@ -276,4 +317,4 @@
 	}
 
 }
-?>
\ No newline at end of file
+?>
Index: trunk/wb/framework/functions.php
===================================================================
--- trunk/wb/framework/functions.php	(revision 542)
+++ trunk/wb/framework/functions.php	(revision 543)
@@ -1195,12 +1195,12 @@
 	$directory = WB_PATH.PAGES_DIRECTORY.$link;
 	$filename = $directory.PAGE_EXTENSION;
 	$directory .= '/';
-	if(file_exists($filename) && substr($filename,0,1<>'.')) {
+	if(file_exists($filename)) {
 		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
 			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
 		} else {
 			unlink($filename);
-			if(file_exists($directory)) {
+			if(file_exists($directory) && rtrim($directory,'/')!=WB_PATH.PAGES_DIRECTORY) {
 				rm_full_dir($directory);
 			}
 		}
@@ -1316,4 +1316,4 @@
 	}
 }
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/index.php
===================================================================
--- trunk/wb/index.php	(revision 542)
+++ trunk/wb/index.php	(revision 543)
@@ -53,6 +53,29 @@
 // also, set some aliases for backward compatibility
 require(WB_PATH.'/framework/frontend.functions.php');
 
+// redirect menu-link
+$this_page_id = PAGE_ID;
+$query_this_module = $database->query("SELECT module, block FROM ".TABLE_PREFIX."sections WHERE page_id = '$this_page_id' AND module = 'menu_link'");
+if($query_this_module->numRows() == 1) { // This is a menu_link. Get link of target-page and redirect
+	// get target_page_id
+	$table = TABLE_PREFIX.'mod_menu_link';
+	$query_tpid = $database->query("SELECT target_page_id FROM $table WHERE page_id = '$this_page_id'");
+	if($query_tpid->numRows() == 1) {
+		$res=$query_tpid->fetchRow();
+		$target_page_id = $res['target_page_id'];
+		// get link of target-page
+		$table = TABLE_PREFIX.'pages';
+		$query_link = $database->query("SELECT link FROM $table WHERE page_id = '$target_page_id'");
+		if($query_link->numRows() == 1) {
+			$res=$query_link->fetchRow();
+			$target_page_link = $res['link'];
+			// redirect
+			header('Location: '.WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION);
+			exit;
+		}
+	}
+}
+
 // Display the template
 require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
 
