Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         menu_link
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: modify.php 1907 2013-06-07 02:30:42Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/menu_link/modify.php $
14
 * @lastmodified    $Date: 2013-06-07 04:30:42 +0200 (Fri, 07 Jun 2013) $
15
 *
16
*/
17

    
18
// Must include code to stop this file being access directly
19
/* -------------------------------------------------------- */
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
24
}
25
/* -------------------------------------------------------- */
26

    
27
// check if module language file exists for the language set by the user (e.g. DE, EN)
28
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
29
	// no module language file exists for the language set by the user, include default module language file EN.php
30
	require_once(WB_PATH .'/modules/menu_link/languages/EN.php');
31
} else {
32
	// a module language file exists for the language defined by the user, load it
33
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
34
}
35

    
36
// get target page_id
37
$table = TABLE_PREFIX.'mod_menu_link';
38
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
39
$sql_row = $sql_result->fetchRow();
40
$target_page_id = $sql_row['target_page_id'];
41
$r_type = $sql_row['redirect_type'];
42
$extern = $sql_row['extern'];
43
$anchor = $sql_row['anchor'];
44
$sel = ' selected="selected"';
45

    
46
// Get list of all visible pages and build a page-tree
47

    
48
// this function will fetch the page_tree, recursive
49
if(!function_exists('menulink_make_tree')) {
50
function menulink_make_tree($parent, $link_pid, $tree) {
51
	global $database, $admin, $menulink_titles;
52
	$table_p = TABLE_PREFIX."pages";
53
	// get list of page-trails, recursive
54
	if($query_page = $database->query("SELECT * FROM `$table_p` WHERE `parent`=$parent ORDER BY `position`")) {
55
		while($page = $query_page->fetchRow()) {
56
			if($admin->page_is_visible($page) ) {
57
				$pids = explode(',', $page['page_trail']);
58
				$entry = '';
59
				foreach($pids as $pid)
60
					$entry .= $menulink_titles[$pid].' / ';
61
				$tree[$page['page_id']] = rtrim($entry, '/ ');
62
				$tree = menulink_make_tree($page['page_id'], $link_pid, $tree);
63
			}
64
		}
65
	}
66
	return($tree);
67
}
68
}
69

    
70
// get list of all page_ids and page_titles
71
global $menulink_titles;
72
$menulink_titles = array();
73
$table_p = TABLE_PREFIX."pages";
74
if($query_page = $database->query("SELECT `page_id`,`menu_title` FROM `$table_p`")) {
75
	while($page = $query_page->fetchRow())
76
		$menulink_titles[$page['page_id']] = $page['menu_title'];
77
}
78
// now get the tree
79
$links = array();
80
$links = menulink_make_tree(0, $page_id, $links);
81

    
82
// Get list of targets (id=... or <a name ...>) from pages in $links
83
$targets = array();
84
$table_mw = TABLE_PREFIX."mod_wysiwyg";
85
$table_s = TABLE_PREFIX."sections";
86
foreach($links as $pid=>$l) {
87
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
88
		while($section = $query_section->fetchRow(MYSQL_ASSOC)) {
89
			// get section-anchor
90
			if(defined('SEC_ANCHOR') && SEC_ANCHOR!='none') {
91
				$targets[$pid][] = SEC_ANCHOR.$section['section_id'];
92
			} else {
93
				$targets[$pid] = array();
94
			}
95
			if($section['module'] == 'wysiwyg') {
96
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
97
					$page = $query_page->fetchRow();
98
					if(preg_match_all('/<(?:a[^>]+name|[^>]+id)\s*=\s*"([^"]+)"/i',$page['content'], $match)) {
99
						foreach($match[1] AS $t) {
100
							$targets[$pid][$t] = $t;
101
						}
102
					}
103
				}
104
			}
105
		}
106
	}
107
}
108
// get target-window for actual page
109
$table = TABLE_PREFIX."pages";
110
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
111
$page = $query_page->fetchRow();
112
$target = $page['target'];
113

    
114

    
115
// script for target-select-box
116
?>
117
<script language="JavaScript" type="text/javascript">
118
/*<![CDATA[*/
119
	function populate() {
120
		o=document.getElementById('menu_link');
121
		d=document.getElementById('page_target');
122
		e=document.getElementById('extern');
123
		if(!d){return;}
124
		var mitems=new Array();
125
		mitems['0']=[' ','0'];
126
		mitems['-1']=[' ','0'];
127
		<?php
128
		foreach($links AS $pid=>$link) {
129
			$str="mitems['$pid']=[";
130
			$str.="' ',";
131
			$str.="'0',";
132
			if(is_array($targets) && is_array($targets[$pid])) {
133
				foreach($targets[$pid] AS $value) {
134
					$str.="'#$value',";
135
					$str.="'$value',";
136
				}
137
				$str=rtrim($str, ',');
138
				$str.="];\n";
139
			}
140
			echo $str;
141
		}
142
		?>
143
		d.options.length=0;
144
		cur=mitems[o.options[o.selectedIndex].value];
145
		if(!cur){return;}
146
		d.options.length=cur.length/2;
147
		j=0;
148
		for(var i=0;i<cur.length;i=i+2)
149
		{
150
			d.options[j].text=cur[i];
151
			d.options[j++].value=cur[i+1];
152
		}
153

    
154
		if(o.value=='-1') {
155
			e.disabled = false;
156
		} else {
157
			e.disabled = true;
158
		}
159
	}
160

    
161
/*]]>*/
162
</script>
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
<?php echo $admin->getFTAN(); ?>
167
<table cellpadding="0" cellspacing="0" border="0" width="100%">
168
<tr>
169
	<td>
170
		<?php echo $TEXT['LINK'].':' ?>
171
	</td>
172
	<td>
173
		<select name="menu_link" id="menu_link" onchange="populate()" style="width:250px;" >
174
			<option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
175
			<option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>
176
			<?php foreach($links AS $pid=>$link) {
177
				if ($pid == $page_id)  // Display current page with selection disabled
178
					echo "<option value=\"$pid\" disabled=\"disabled\">$link *</option>\n";
179
				else
180
					echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>\n";
181
			} ?>
182
		</select>
183
		&nbsp;
184
		<input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
185
	</td>
186
</tr>
187
<tr>
188
	<td>
189
		<?php echo $TEXT['ANCHOR'].':' ?>
190
	</td>
191
	<td>
192
		<select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" >
193
			<option value="<?php echo $anchor ?>" selected="selected"><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
194
		</select>
195
	</td>
196
</tr>
197
<tr>
198
	<td>
199
		<?php echo $TEXT['TARGET'].':' ?>
200
	</td>
201
	<td>
202
		<select name="target" style="width:250px;" >
203
			<option value="_blank"<?php if($target=='_blank') echo ' selected="selected"'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
204
			<option value="_self"<?php if($target=='_self') echo ' selected="selected"'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
205
			<option value="_top"<?php if($target=='_top') echo ' selected="selected"'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
206
		</select>
207
	</td>
208
</tr>
209
<tr>
210
	<td>
211
		<?php echo $MOD_MENU_LINK['R_TYPE'].':' ?>
212
	</td>
213
	<td>
214
		<select name="r_type" style="width:250px;" >
215
			<option value="301"<?php if($r_type=='301') echo ' selected="selected"'; ?>>301</option>
216
			<option value="302"<?php if($r_type=='302') echo ' selected="selected"'; ?>>302</option>
217
		</select>
218
	</td>
219
</tr>
220
</table>
221

    
222
<br />
223

    
224
<table cellpadding="0" cellspacing="0" border="0" width="100%">
225
<tr>
226
	<td align="left">
227
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
228
	</td>
229
	<td align="right">
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>
(6-6/10)