Project

General

Profile

1 993 Ruebenwurz
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
// Must include code to stop this file being accessed directly
27
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
28
29
// check if module language file exists for the language set by the user (e.g. DE, EN)
30
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
31
	// no module language file exists for the language set by the user, include default module language file EN.php
32
	require_once(WB_PATH .'/modules/menu_link/languages/EN.php');
33
} else {
34
	// a module language file exists for the language defined by the user, load it
35
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
36
}
37
38
// get target page_id
39
$table = TABLE_PREFIX.'mod_menu_link';
40
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
41
$sql_row = $sql_result->fetchRow();
42
$target_page_id = $sql_row['target_page_id'];
43
$r_type = $sql_row['redirect_type'];
44
$extern = $sql_row['extern'];
45
$anchor = $sql_row['anchor'];
46
$sel = ' selected';
47
48 1003 ruud
// Get list of all visible pages and build a page-tree
49 993 Ruebenwurz
50
// this function will fetch the page_tree, recursive
51
if(!function_exists('menulink_make_tree')) {
52
function menulink_make_tree($parent, $link_pid, $tree) {
53
	global $database, $admin, $menulink_titles;
54
	$table_p = TABLE_PREFIX."pages";
55
	// get list of page-trails, recursive
56
	if($query_page = $database->query("SELECT * FROM `$table_p` WHERE `parent`=$parent ORDER BY `position`")) {
57
		while($page = $query_page->fetchRow()) {
58 1003 ruud
			if($admin->page_is_visible($page) ) {
59 993 Ruebenwurz
				$pids = explode(',', $page['page_trail']);
60
				$entry = '';
61 1004 ruud
				foreach($pids as $pid)
62 993 Ruebenwurz
					$entry .= $menulink_titles[$pid].' / ';
63 1004 ruud
				$tree[$page['page_id']] = rtrim($entry, '/ ');
64
				$tree = menulink_make_tree($page['page_id'], $link_pid, $tree);
65 993 Ruebenwurz
			}
66
		}
67
	}
68
	return($tree);
69
}
70
}
71 1003 ruud
72 993 Ruebenwurz
// get list of all page_ids and page_titles
73
global $menulink_titles;
74
$menulink_titles = array();
75
$table_p = TABLE_PREFIX."pages";
76
if($query_page = $database->query("SELECT `page_id`,`page_title` FROM `$table_p`")) {
77
	while($page = $query_page->fetchRow())
78
		$menulink_titles[$page['page_id']] = $page['page_title'];
79
}
80
// now get the tree
81
$links = array();
82
$links = menulink_make_tree(0, $page_id, $links);
83
84
// Get list of targets (id=... or <a name ...>) from pages in $links
85
$targets = array();
86
$table_mw = TABLE_PREFIX."mod_wysiwyg";
87
$table_s = TABLE_PREFIX."sections";
88
foreach($links as $pid=>$l) {
89
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
90
		while($section = $query_section->fetchRow()) {
91
			// get section-anchor
92
			if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
93
				$targets[$pid][] = SEC_ANCHOR.$section['section_id'];
94
			} else {
95
				$targets[$pid] = array();
96
			}
97
			if($section['module'] == 'wysiwyg') {
98
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
99
					$page = $query_page->fetchRow();
100
					if(preg_match_all('/<(?:a[^>]+name|[^>]+id)\s*=\s*"([^"]+)"/i',$page['content'], $match)) {
101
						foreach($match[1] AS $t) {
102
							$targets[$pid][$t] = $t;
103
						}
104
					}
105
				}
106
			}
107
		}
108
	}
109
}
110
// get target-window for actual page
111
$table = TABLE_PREFIX."pages";
112
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
113
$page = $query_page->fetchRow();
114
$target = $page['target'];
115
116
117
// script for target-select-box
118
?>
119
<script type="text/javascript">
120
	function populate() {
121
		o=document.getElementById('page_link');
122
		d=document.getElementById('page_target');
123
		e=document.getElementById('extern');
124
		if(!d){return;}
125
		var mitems=new Array();
126
		mitems['0']=[' ','0'];
127
		mitems['-1']=[' ','0'];
128
		<?php
129
		foreach($links AS $pid=>$link) {
130
			$str="mitems['$pid']=[";
131
			$str.="' ',";
132
			$str.="'0',";
133
			if(is_array($targets) && is_array($targets[$pid])) {
134
				foreach($targets[$pid] AS $value) {
135
					$str.="'#$value',";
136
					$str.="'$value',";
137
				}
138
				$str=rtrim($str, ',');
139
				$str.="];\n";
140
			}
141
			echo $str;
142
		}
143
		?>
144
		d.options.length=0;
145
		cur=mitems[o.options[o.selectedIndex].value];
146
		if(!cur){return;}
147
		d.options.length=cur.length/2;
148
		j=0;
149
		for(var i=0;i<cur.length;i=i+2)
150
		{
151
			d.options[j].text=cur[i];
152
			d.options[j++].value=cur[i+1];
153
		}
154
155
		if(o.value=='-1') {
156
			e.disabled = false;
157
		} else {
158
			e.disabled = true;
159
		}
160
	}
161
</script>
162
163
<form name="menulink" action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
164
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
165
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
166
<table cellpadding="0" cellspacing="0" border="0" width="100%">
167
<tr>
168
	<td>
169
		<?php echo $TEXT['LINK'].':' ?>
170
	</td>
171
	<td>
172
		<select name="page_link" id="page_link" onchange="populate()" style="width:250px;" />
173
			<option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
174
			<option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>
175
			<?php foreach($links AS $pid=>$link) {
176 1003 ruud
				if ($pid == $page_id)  // Display current page with selection disabled
177
					echo "<option value=\"$pid\" disabled=\"disabled\">$link *</option>";
178
				else
179
					echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>";
180 993 Ruebenwurz
			} ?>
181
		</select>
182
		&nbsp;
183
		<input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
184
	</td>
185
</tr>
186
<tr>
187
	<td>
188
		<?php echo $TEXT['ANCHOR'].':' ?>
189
	</td>
190
	<td>
191
		<select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" />
192
			<option value="<?php echo $anchor ?>" selected><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
193
		</select>
194
	</td>
195
</tr>
196
<tr>
197
	<td>
198
		<?php echo $TEXT['TARGET'].':' ?>
199
	</td>
200
	<td>
201
		<select name="target" style="width:250px;" />
202
			<option value="_blank"<?php if($target=='_blank') echo ' selected="selected"'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
203
			<option value="_self"<?php if($target=='_self') echo ' selected="selected"'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
204
			<option value="_top"<?php if($target=='_top') echo ' selected="selected"'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
205
		</select>
206
	</td>
207
</tr>
208
<tr>
209
	<td>
210
		<?php echo $MOD_MENU_LINK['R_TYPE'].':' ?>
211
	</td>
212
	<td>
213
		<select name="r_type" style="width:250px;" />
214
			<option value="301"<?php if($r_type=='301') echo ' selected="selected"'; ?>>301</option>
215
			<option value="302"<?php if($r_type=='302') echo ' selected="selected"'; ?>>302</option>
216
		</select>
217
	</td>
218
</tr>
219
</table>
220
221
<br />
222
223
<table cellpadding="0" cellspacing="0" border="0" width="100%">
224
<tr>
225
	<td align="left">
226
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
227
	</td>
228
	<td align="right">
229
		</form>
230
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
231
	</td>
232
</tr>
233
</table>
234
235
</form>