Project

General

Profile

1
<?php
2
/***************************************************************************
3
* SVN Version information:
4
*
5
* $Id: modify.php 1222 2009-12-28 03:27:15Z Luisehahne $
6
*
7
*****************************************************************************
8
*                          WebsiteBaker
9
*
10
* WebsiteBaker Project <http://www.websitebaker2.org/>
11
* Copyright (C) 2009, Website Baker Org. e.V.
12
*         http://start.websitebaker2.org/impressum-datenschutz.php
13
* Copyright (C) 2004-2009, Ryan Djurovich
14
*
15
*                        About WebsiteBaker
16
*
17
* Website Baker is a PHP-based Content Management System (CMS)
18
* designed with one goal in mind: to enable its users to produce websites
19
* with ease.
20
*
21
*****************************************************************************
22
*
23
*****************************************************************************
24
*                        LICENSE INFORMATION
25
*
26
* WebsiteBaker is free software; you can redistribute it and/or
27
* modify it under the terms of the GNU General Public License
28
* as published by the Free Software Foundation; either version 2
29
* of the License, or (at your option) any later version.
30
*
31
* WebsiteBaker is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34
* See the GNU General Public License for more details.
35
*
36
* You should have received a copy of the GNU General Public License
37
* along with this program; if not, write to the Free Software
38
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
39
****************************************************************************
40
*
41
*****************************************************************************
42
*                   WebsiteBaker Extra Information
43
*
44
*
45
*
46
*
47
*****************************************************************************/
48

    
49
/**
50
 *
51
 * @category     modules
52
 * @package      menu_link
53
 * @author       Ryan Djurovich
54
 * @copyright    2004-2009, Ryan Djurovich
55
 * @copyright    2009, Website Baker Org. e.V.
56
 * @version      $Id: modify.php 1222 2009-12-28 03:27:15Z Luisehahne $
57
 * @platform     WebsiteBaker 2.8.x
58
 * @requirements >= PHP 4.3.4
59
 * @license      http://www.gnu.org/licenses/gpl.html
60
 *
61
 *
62
 */
63

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

    
67
// check if module language file exists for the language set by the user (e.g. DE, EN)
68
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
69
	// no module language file exists for the language set by the user, include default module language file EN.php
70
	require_once(WB_PATH .'/modules/menu_link/languages/EN.php');
71
} else {
72
	// a module language file exists for the language defined by the user, load it
73
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
74
}
75

    
76
// get target page_id
77
$table = TABLE_PREFIX.'mod_menu_link';
78
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
79
$sql_row = $sql_result->fetchRow();
80
$target_page_id = $sql_row['target_page_id'];
81
$r_type = $sql_row['redirect_type'];
82
$extern = $sql_row['extern'];
83
$anchor = $sql_row['anchor'];
84
$sel = ' selected="selected"';
85

    
86
// Get list of all visible pages and build a page-tree
87

    
88
// this function will fetch the page_tree, recursive
89
if(!function_exists('menulink_make_tree')) {
90
function menulink_make_tree($parent, $link_pid, $tree) {
91
	global $database, $admin, $menulink_titles;
92
	$table_p = TABLE_PREFIX."pages";
93
	// get list of page-trails, recursive
94
	if($query_page = $database->query("SELECT * FROM `$table_p` WHERE `parent`=$parent ORDER BY `position`")) {
95
		while($page = $query_page->fetchRow()) {
96
			if($admin->page_is_visible($page) ) {
97
				$pids = explode(',', $page['page_trail']);
98
				$entry = '';
99
				foreach($pids as $pid)
100
					$entry .= $menulink_titles[$pid].' / ';
101
				$tree[$page['page_id']] = rtrim($entry, '/ ');
102
				$tree = menulink_make_tree($page['page_id'], $link_pid, $tree);
103
			}
104
		}
105
	}
106
	return($tree);
107
}
108
}
109

    
110
// get list of all page_ids and page_titles
111
global $menulink_titles;
112
$menulink_titles = array();
113
$table_p = TABLE_PREFIX."pages";
114
if($query_page = $database->query("SELECT `page_id`,`menu_title` FROM `$table_p`")) {
115
	while($page = $query_page->fetchRow())
116
		$menulink_titles[$page['page_id']] = $page['menu_title'];
117
}
118
// now get the tree
119
$links = array();
120
$links = menulink_make_tree(0, $page_id, $links);
121

    
122
// Get list of targets (id=... or <a name ...>) from pages in $links
123
$targets = array();
124
$table_mw = TABLE_PREFIX."mod_wysiwyg";
125
$table_s = TABLE_PREFIX."sections";
126
foreach($links as $pid=>$l) {
127
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
128
		while($section = $query_section->fetchRow()) {
129
			// get section-anchor
130
			if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
131
				$targets[$pid][] = SEC_ANCHOR.$section['section_id'];
132
			} else {
133
				$targets[$pid] = array();
134
			}
135
			if($section['module'] == 'wysiwyg') {
136
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
137
					$page = $query_page->fetchRow();
138
					if(preg_match_all('/<(?:a[^>]+name|[^>]+id)\s*=\s*"([^"]+)"/i',$page['content'], $match)) {
139
						foreach($match[1] AS $t) {
140
							$targets[$pid][$t] = $t;
141
						}
142
					}
143
				}
144
			}
145
		}
146
	}
147
}
148
// get target-window for actual page
149
$table = TABLE_PREFIX."pages";
150
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
151
$page = $query_page->fetchRow();
152
$target = $page['target'];
153

    
154

    
155
// script for target-select-box
156
?>
157
<script language="JavaScript" type="text/javascript">
158
/*<![CDATA[*/
159
	function populate() {
160
		o=document.getElementById('menu_link');
161
		d=document.getElementById('page_target');
162
		e=document.getElementById('extern');
163
		if(!d){return;}
164
		var mitems=new Array();
165
		mitems['0']=[' ','0'];
166
		mitems['-1']=[' ','0'];
167
		<?php
168
		foreach($links AS $pid=>$link) {
169
			$str="mitems['$pid']=[";
170
			$str.="' ',";
171
			$str.="'0',";
172
			if(is_array($targets) && is_array($targets[$pid])) {
173
				foreach($targets[$pid] AS $value) {
174
					$str.="'#$value',";
175
					$str.="'$value',";
176
				}
177
				$str=rtrim($str, ',');
178
				$str.="];\n";
179
			}
180
			echo $str;
181
		}
182
		?>
183
		d.options.length=0;
184
		cur=mitems[o.options[o.selectedIndex].value];
185
		if(!cur){return;}
186
		d.options.length=cur.length/2;
187
		j=0;
188
		for(var i=0;i<cur.length;i=i+2)
189
		{
190
			d.options[j].text=cur[i];
191
			d.options[j++].value=cur[i+1];
192
		}
193

    
194
		if(o.value=='-1') {
195
			e.disabled = false;
196
		} else {
197
			e.disabled = true;
198
		}
199
	}
200

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

    
261
<br />
262

    
263
<table cellpadding="0" cellspacing="0" border="0" width="100%">
264
<tr>
265
	<td align="left">
266
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
267
	</td>
268
	<td align="right">
269
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
270
	</td>
271
</tr>
272
</table>
273

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