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:

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>

Also available in: Unified diff