Project

General

Profile

« Previous | Next » 

Revision 565

Added by thorn almost 17 years ago

Module menu_link: added dropdown-listbox to select anchor

View differences:

trunk/wb/index.php
59 59
if($query_this_module->numRows() == 1) { // This is a menu_link. Get link of target-page and redirect
60 60
	// get target_page_id
61 61
	$table = TABLE_PREFIX.'mod_menu_link';
62
	$query_tpid = $database->query("SELECT target_page_id FROM $table WHERE page_id = '$this_page_id'");
62
	$query_tpid = $database->query("SELECT target_page_id, anchor FROM $table WHERE page_id = '$this_page_id'");
63 63
	if($query_tpid->numRows() == 1) {
64 64
		$res=$query_tpid->fetchRow();
65 65
		$target_page_id = $res['target_page_id'];
66
		$anchor = $res['anchor'];
67
		if($anchor != '0') $anchor = ''.$anchor;
68
		else $anchor = FALSE;
66 69
		// get link of target-page
67 70
		$table = TABLE_PREFIX.'pages';
68 71
		$query_link = $database->query("SELECT link FROM $table WHERE page_id = '$target_page_id'");
......
70 73
			$res=$query_link->fetchRow();
71 74
			$target_page_link = $res['link'];
72 75
			// redirect
73
			header('Location: '.WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION);
76
			header('Location: '.WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION.($anchor?'#'.$anchor:''));
74 77
			exit;
75 78
		}
76 79
	}
trunk/wb/languages/EN.php
223 223
$TEXT['FULL_NAME'] = 'Full Name';
224 224
$TEXT['ACCOUNT_SIGNUP'] = 'Account Sign-Up';
225 225
$TEXT['LINK'] = 'Link';
226
$TEXT['ANCHOR'] = 'Anchor';
226 227
$TEXT['TARGET'] = 'Target';
227 228
$TEXT['NEW_WINDOW'] = 'New Window';
228 229
$TEXT['SAME_WINDOW'] = 'Same Window';
trunk/wb/modules/menu_link/save.php
29 29
$update_when_modified = true; // Tells script to update when this page was last updated
30 30
require(WB_PATH.'/modules/admin.php');
31 31

  
32
// Update id and target
33
if(!isset($_POST['link']))
34
	$foreign_page_id = 0;
35
else
36
	$foreign_page_id = $_POST['link']; // foreign-page_id
32
// Update id, anchor and target
33
if(isset($_POST['page_link'])) {
34
	$foreign_page_id = $_POST['page_link'];
35
	$page_target = $_POST['page_target'];
36
	$url_target = $_POST['target'];
37 37

  
38
$url_target = $_POST['target'];
39
$table_pages = TABLE_PREFIX.'pages';
40
$table_mod = TABLE_PREFIX.'mod_menu_link';
41
$database->query("UPDATE $table_pages SET target = '$url_target' WHERE page_id = '$page_id'");
42
$database->query("UPDATE $table_mod SET target_page_id = '$foreign_page_id' WHERE page_id = '$page_id'");
38
	$table_pages = TABLE_PREFIX.'pages';
39
	$table_mod = TABLE_PREFIX.'mod_menu_link';
40
	$database->query("UPDATE $table_pages SET target = '$url_target' WHERE page_id = '$page_id'");
41
	$database->query("UPDATE $table_mod SET target_page_id = '$foreign_page_id', anchor = '$page_target' WHERE page_id = '$page_id'");
42
}
43 43

  
44 44
// Check if there is a database error, otherwise say successful
45 45
if($database->is_error()) {
trunk/wb/modules/menu_link/install.php
36 36
		`section_id` INT(11) NOT NULL DEFAULT '0',
37 37
		`page_id` INT(11) NOT NULL DEFAULT '0',
38 38
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
39
		`anchor` VARCHAR(255) NOT NULL DEFAULT '' ,
39 40
		PRIMARY KEY (`section_id`)
40 41
	)
41 42
");
trunk/wb/modules/menu_link/modify.php
31 31
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
32 32
$sql_row = $sql_result->fetchRow();
33 33
$target_page_id = $sql_row['target_page_id'];
34
$anchor = $sql_row['anchor'];
35
$sel = ' selected';
34 36

  
35 37
// Get list of all visible page-links, except menu_links and actual page
38
$links = array();
36 39
$table_p = TABLE_PREFIX."pages";
37 40
$table_s = TABLE_PREFIX."sections";
38
$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");
39
if($query_page->numRows() > 0) {
41
if($query_page = $database->query("SELECT DISTINCT p.* FROM $table_p AS p INNER JOIN $table_s AS s ON p.page_id=s.page_id WHERE s.module != 'menu_link' AND p.page_id != '$page_id' AND parent = '0' ORDER BY position")) {
40 42
	while($page = $query_page->fetchRow()) {
41 43
		if($admin->page_is_visible($page)) {
42 44
			$links[$page['page_id']]='/'.$page['menu_title'];
43
			$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");
44
			if($query_subpage->numRows() > 0) {
45
			if($query_subpage = $database->query("SELECT DISTINCT p.* FROM $table_p AS p INNER JOIN $table_s AS s ON p.page_id=s.page_id WHERE s.module != 'menu_link' AND p.page_id != '$page_id' AND root_parent = '{$page['page_id']}' ORDER BY level")) {
45 46
				while($sub = $query_subpage->fetchRow()) {
46 47
					if($admin->page_is_visible($sub)) {
47 48
						$parent_link = (array_key_exists($sub['parent'],$links))?$links[$sub['parent']]:"";
......
52 53
		}
53 54
	}
54 55
}
55

  
56
// get URL-target for actual page
56
// Get list of targets (id=... or <a name ...>) from pages in $links
57
$targets = array();
58
$table_mw = TABLE_PREFIX."mod_wysiwyg";
59
$table_s = TABLE_PREFIX."sections";
60
foreach($links as $pid=>$l) {
61
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
62
		while($section = $query_section->fetchRow()) {
63
			$targets[$pid][] = "wb_section_{$section['section_id']}";
64
			if($section['module'] == 'wysiwyg') {
65
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
66
					$page = $query_page->fetchRow();
67
					if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iuU',$page['content'], $match)) {
68
						foreach($match[1] AS $t) {
69
							$targets[$pid][] = $t;
70
						}
71
					}
72
				}
73
			}
74
		}
75
	}
76
}
77
// get target-window for actual page
57 78
$table = TABLE_PREFIX."pages";
58 79
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
59 80
$page = $query_page->fetchRow();
60 81
$target = $page['target'];
61 82

  
83

  
84
// script for target-select-box
62 85
?>
86
<script type="text/javascript">
87
	function populate()
88
	{
89
		o=document.getElementById('page_link');
90
		d=document.getElementById('page_target');
91
		if(!d){return;}			
92
		var mitems=new Array();
93
		mitems['0']=[' ','0'];
94
		<?php
95
		foreach($links AS $pid=>$link) {
96
			$str="mitems['$pid']=[";
97
			$str.="' ',";
98
			$str.="'0',";
99
			if(is_array($targets) && is_array($targets[$pid])) {
100
				foreach($targets[$pid] AS $value) {
101
					$str.="'#$value',";
102
					$str.="'$value',";
103
				}
104
				$str=rtrim($str, ',');
105
				$str.="];\n";
106
			}
107
			echo $str;
108
		}
109
		?>
110
		d.options.length=0;
111
		cur=mitems[o.options[o.selectedIndex].value];
112
		if(!cur){return;}
113
		d.options.length=cur.length/2;
114
		j=0;
115
		for(var i=0;i<cur.length;i=i+2)
116
		{
117
			d.options[j].text=cur[i];
118
			d.options[j++].value=cur[i+1];
119
		}
120
	}
121
</script>
122

  
63 123
<form action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
64 124
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
65 125
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
......
69 129
		<?php echo $TEXT['LINK'].':' ?>
70 130
	</td>
71 131
	<td>
72
		<select name="link" style="WIDTH: 100%;" value="<?php echo "" ?>" />
73
		<?php
74
		foreach($links as $id=>$l) { ?>
75
			<option value="<?php echo $id ?>"<?php if($id==$target_page_id) echo ' selected'; ?>><?php echo $l ?></option>
76
		<?php } ?>
132
		<select name="page_link" id="page_link" onchange="populate()" style="width: 100%;">
133
			<option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
134
			<?php foreach($links AS $pid=>$link) {
135
				echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>";
136
			} ?>
137
		</select>
77 138
	</td>
78 139
</tr>
79 140
<tr>
80 141
	<td>
142
		<?php echo $TEXT['ANCHOR'].':' ?>
143
	</td>
144
	<td>
145
		<select name="page_target" id="page_target" onfocus="populate()" style="width: 100%;">
146
			<option value="<?php echo $anchor ?>" selected><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
147
		</select>
148
	</td>
149
</tr>
150
<tr>
151
	<td>
81 152
		<?php echo $TEXT['TARGET'].':' ?>
82 153
	</td>
83 154
	<td>
84
		<select name="target" style="WIDTH: 100%;" value="<?php echo "" ?>" />
155
		<select name="target" style="width: 100%" />
85 156
			<option value="_blank"<?php if($target=='_blank') echo ' selected'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
86 157
			<option value="_self"<?php if($target=='_self') echo ' selected'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
87 158
			<option value="_top"<?php if($target=='_top') echo ' selected'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
trunk/wb/modules/menu_link/add.php
29 29
}
30 30

  
31 31
$table = TABLE_PREFIX ."mod_menu_link";
32
$database->query("INSERT INTO `$table` (`page_id`, `section_id`, target_page_id) VALUES ('$page_id', '$section_id', '0')");
32
$database->query("INSERT INTO `$table` (`page_id`, `section_id`, target_page_id, anchor) VALUES ('$page_id', '$section_id', '0', '')");
33 33

  
34 34
?>

Also available in: Unified diff