Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        modules
33
 * @package         menu_link
34
 * @author          WebsiteBaker Project
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41
 * @version         $Id: modify.php 1271 2010-01-23 02:30:24Z Luisehahne $
42
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/menu_link/modify.php $
43
 * @lastmodified    $Date: 2010-01-23 03:30:24 +0100 (Sat, 23 Jan 2010) $
44
 *
45
*/
46

    
47
// Must include code to stop this file being accessed directly
48
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
49

    
50
// check if module language file exists for the language set by the user (e.g. DE, EN)
51
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
52
	// no module language file exists for the language set by the user, include default module language file EN.php
53
	require_once(WB_PATH .'/modules/menu_link/languages/EN.php');
54
} else {
55
	// a module language file exists for the language defined by the user, load it
56
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
57
}
58

    
59
// get target page_id
60
$table = TABLE_PREFIX.'mod_menu_link';
61
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
62
$sql_row = $sql_result->fetchRow();
63
$target_page_id = $sql_row['target_page_id'];
64
$r_type = $sql_row['redirect_type'];
65
$extern = $sql_row['extern'];
66
$anchor = $sql_row['anchor'];
67
$sel = ' selected="selected"';
68

    
69
// Get list of all visible pages and build a page-tree
70

    
71
// this function will fetch the page_tree, recursive
72
if(!function_exists('menulink_make_tree')) {
73
function menulink_make_tree($parent, $link_pid, $tree) {
74
	global $database, $admin, $menulink_titles;
75
	$table_p = TABLE_PREFIX."pages";
76
	// get list of page-trails, recursive
77
	if($query_page = $database->query("SELECT * FROM `$table_p` WHERE `parent`=$parent ORDER BY `position`")) {
78
		while($page = $query_page->fetchRow()) {
79
			if($admin->page_is_visible($page) ) {
80
				$pids = explode(',', $page['page_trail']);
81
				$entry = '';
82
				foreach($pids as $pid)
83
					$entry .= $menulink_titles[$pid].' / ';
84
				$tree[$page['page_id']] = rtrim($entry, '/ ');
85
				$tree = menulink_make_tree($page['page_id'], $link_pid, $tree);
86
			}
87
		}
88
	}
89
	return($tree);
90
}
91
}
92

    
93
// get list of all page_ids and page_titles
94
global $menulink_titles;
95
$menulink_titles = array();
96
$table_p = TABLE_PREFIX."pages";
97
if($query_page = $database->query("SELECT `page_id`,`menu_title` FROM `$table_p`")) {
98
	while($page = $query_page->fetchRow())
99
		$menulink_titles[$page['page_id']] = $page['menu_title'];
100
}
101
// now get the tree
102
$links = array();
103
$links = menulink_make_tree(0, $page_id, $links);
104

    
105
// Get list of targets (id=... or <a name ...>) from pages in $links
106
$targets = array();
107
$table_mw = TABLE_PREFIX."mod_wysiwyg";
108
$table_s = TABLE_PREFIX."sections";
109
foreach($links as $pid=>$l) {
110
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
111
		while($section = $query_section->fetchRow()) {
112
			// get section-anchor
113
			if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
114
				$targets[$pid][] = SEC_ANCHOR.$section['section_id'];
115
			} else {
116
				$targets[$pid] = array();
117
			}
118
			if($section['module'] == 'wysiwyg') {
119
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
120
					$page = $query_page->fetchRow();
121
					if(preg_match_all('/<(?:a[^>]+name|[^>]+id)\s*=\s*"([^"]+)"/i',$page['content'], $match)) {
122
						foreach($match[1] AS $t) {
123
							$targets[$pid][$t] = $t;
124
						}
125
					}
126
				}
127
			}
128
		}
129
	}
130
}
131
// get target-window for actual page
132
$table = TABLE_PREFIX."pages";
133
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
134
$page = $query_page->fetchRow();
135
$target = $page['target'];
136

    
137

    
138
// script for target-select-box
139
?>
140
<script language="JavaScript" type="text/javascript">
141
/*<![CDATA[*/
142
	function populate() {
143
		o=document.getElementById('menu_link');
144
		d=document.getElementById('page_target');
145
		e=document.getElementById('extern');
146
		if(!d){return;}
147
		var mitems=new Array();
148
		mitems['0']=[' ','0'];
149
		mitems['-1']=[' ','0'];
150
		<?php
151
		foreach($links AS $pid=>$link) {
152
			$str="mitems['$pid']=[";
153
			$str.="' ',";
154
			$str.="'0',";
155
			if(is_array($targets) && is_array($targets[$pid])) {
156
				foreach($targets[$pid] AS $value) {
157
					$str.="'#$value',";
158
					$str.="'$value',";
159
				}
160
				$str=rtrim($str, ',');
161
				$str.="];\n";
162
			}
163
			echo $str;
164
		}
165
		?>
166
		d.options.length=0;
167
		cur=mitems[o.options[o.selectedIndex].value];
168
		if(!cur){return;}
169
		d.options.length=cur.length/2;
170
		j=0;
171
		for(var i=0;i<cur.length;i=i+2)
172
		{
173
			d.options[j].text=cur[i];
174
			d.options[j++].value=cur[i+1];
175
		}
176

    
177
		if(o.value=='-1') {
178
			e.disabled = false;
179
		} else {
180
			e.disabled = true;
181
		}
182
	}
183

    
184
/*]]>*/
185
</script>
186
<form name="menulink" action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
187
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
188
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
189
<table cellpadding="0" cellspacing="0" border="0" width="100%">
190
<tr>
191
	<td>
192
		<?php echo $TEXT['LINK'].':' ?>
193
	</td>
194
	<td>
195
		<select name="menu_link" id="menu_link" onchange="populate()" style="width:250px;" >
196
			<option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
197
			<option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>
198
			<?php foreach($links AS $pid=>$link) {
199
				if ($pid == $page_id)  // Display current page with selection disabled
200
					echo "<option value=\"$pid\" disabled=\"disabled\">$link *</option>\n";
201
				else
202
					echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>\n";
203
			} ?>
204
		</select>
205
		&nbsp;
206
		<input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
207
	</td>
208
</tr>
209
<tr>
210
	<td>
211
		<?php echo $TEXT['ANCHOR'].':' ?>
212
	</td>
213
	<td>
214
		<select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" >
215
			<option value="<?php echo $anchor ?>" selected="selected"><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
216
		</select>
217
	</td>
218
</tr>
219
<tr>
220
	<td>
221
		<?php echo $TEXT['TARGET'].':' ?>
222
	</td>
223
	<td>
224
		<select name="target" style="width:250px;" >
225
			<option value="_blank"<?php if($target=='_blank') echo ' selected="selected"'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
226
			<option value="_self"<?php if($target=='_self') echo ' selected="selected"'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
227
			<option value="_top"<?php if($target=='_top') echo ' selected="selected"'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
228
		</select>
229
	</td>
230
</tr>
231
<tr>
232
	<td>
233
		<?php echo $MOD_MENU_LINK['R_TYPE'].':' ?>
234
	</td>
235
	<td>
236
		<select name="r_type" style="width:250px;" >
237
			<option value="301"<?php if($r_type=='301') echo ' selected="selected"'; ?>>301</option>
238
			<option value="302"<?php if($r_type=='302') echo ' selected="selected"'; ?>>302</option>
239
		</select>
240
	</td>
241
</tr>
242
</table>
243

    
244
<br />
245

    
246
<table cellpadding="0" cellspacing="0" border="0" width="100%">
247
<tr>
248
	<td align="left">
249
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
250
	</td>
251
	<td align="right">
252
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
253
	</td>
254
</tr>
255
</table>
256

    
257
</form>
(6-6/9)