Project

General

Profile

« Previous | Next » 

Revision 1358

Added by Dietmar over 13 years ago

validation fixes in pages backend theme

View differences:

settings2.php
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Get page id
20
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id']))
21
{
22
	header("Location: index.php");
23
	exit(0);
24
} else {
25
	$page_id = $_POST['page_id'];
26
}
27

  
28
// Create new admin object and print admin header
29
require('../../config.php');
30
require_once(WB_PATH.'/framework/class.admin.php');
31
$admin = new admin('Pages', 'pages_settings');
32

  
33
if (!$admin->checkFTAN())
34
{
35
	$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'index.php');
36
	exit();
37
}
38

  
39
// Include the WB functions file
40
require_once(WB_PATH.'/framework/functions.php');
41

  
42
// Get values
43
$page_title = htmlspecialchars($admin->get_post_escaped('page_title') );
44
$menu_title = htmlspecialchars($admin->get_post_escaped('menu_title') );
45
$page_code = (int) $admin->get_post_escaped('page_code');
46
$description = htmlspecialchars($admin->add_slashes($admin->get_post('description')) );
47
$keywords = htmlspecialchars($admin->add_slashes($admin->get_post('keywords')) );
48
$parent = (int) $admin->get_post_escaped('parent'); // fix secunia 2010-91-3
49
$visibility = $admin->get_post_escaped('visibility');
50
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) $visibility = 'public'; // fix
51
$template = preg_replace("/\W/", "", $admin->get_post_escaped('template')); // fix secunia 2010-93-3
52
$target = preg_replace("/\W/", "", $admin->get_post_escaped('target'));
53
$admin_groups = $admin->get_post_escaped('admin_groups');
54
$viewing_groups = $admin->get_post_escaped('viewing_groups');
55
$searching = $admin->get_post_escaped('searching');
56
$language = strtoupper($admin->get_post('language'));
57
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
58
$menu = (int) $admin->get_post_escaped('menu'); // fix secunia 2010-91-3
59

  
60
// Validate data
61
if($page_title == '' || substr($page_title,0,1)=='.')
62
{
63
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
64
}
65
if($menu_title == '' || substr($menu_title,0,1)=='.')
66
{
67
	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
68
}
69

  
70
// Get existing perms
71
// $database = new database();
72

  
73
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
74
$results = $database->query($sql);
75

  
76
$results_array = $results->fetchRow();
77
$old_parent = $results_array['parent'];
78
$old_link = $results_array['link'];
79
$old_position = $results_array['position'];
80
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
81
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
82

  
83
// Work-out if we should check for existing page_code
84
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
85
$field_sql = $database->query($sql);
86
$field_set = $field_sql->numRows();
87

  
88
$in_old_group = FALSE;
89
foreach($admin->get_groups_id() as $cur_gid)
90
{
91
    if (in_array($cur_gid, $old_admin_groups))
92
    {
93
	$in_old_group = TRUE;
94
    }
95
}
96
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
97
{
98
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
99
}
100

  
101
// Setup admin groups
102
$admin_groups[] = 1;
103
//if(!in_array(1, $admin->get_groups_id())) {
104
//	$admin_groups[] = implode(",",$admin->get_groups_id());
105
//}
106
$admin_groups = preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
107
// Setup viewing groups
108
$viewing_groups[] = 1;
109
//if(!in_array(1, $admin->get_groups_id())) {
110
//	$viewing_groups[] = implode(",",$admin->get_groups_id());
111
//}
112
$viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
113

  
114
// If needed, get new order
115
if($parent != $old_parent)
116
{
117
	// Include ordering class
118
	require(WB_PATH.'/framework/class.order.php');
119
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
120
	// Get new order
121
	$position = $order->get_new($parent);
122
	// Clean new order
123
	$order->clean($parent);
124
} else {
125
	$position = $old_position;
126
}
127

  
128
// Work out level and root parent
129
if ($parent!='0')
130
{
131
	$level = level_count($parent)+1;
132
	$root_parent = root_parent($parent);
133
}
134
else {
135
	$level = '0';
136
	$root_parent = '0';
137
}
138

  
139
// Work-out what the link should be
140
if($parent == '0')
141
{
142
	$link = '/'.page_filename($menu_title);
143
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
144
	if($link == '/index' || $link == '/intro')
145
    {
146
		$link .= '_' .$page_id;
147
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
148
	} else {
149
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
150
	}
151
} else {
152
	$parent_section = '';
153
	$parent_titles = array_reverse(get_parent_titles($parent));
154
	foreach($parent_titles AS $parent_title)
155
    {
156
		$parent_section .= page_filename($parent_title).'/';
157
	}
158
	if($parent_section == '/')
159
    {
160
      $parent_section = '';
161
    }
162
	$link = '/'.$parent_section.page_filename($menu_title);
163
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
164
}
165

  
166
// Check if a page with same page filename exists
167
// $database = new database();
168
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
169
$get_same_page = $database->query($sql);
170

  
171
if($get_same_page->numRows() > 0)
172
{
173
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
174
}
175

  
176
// Update page with new order
177
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
178
// $database = new database();
179
$database->query($sql);
180

  
181
// Get page trail
182
$page_trail = get_page_trail($page_id);
183

  
184
// Update page settings in the pages table
185
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
186
$sql .= '`parent` = '.$parent.', ';
187
$sql .= '`page_title` = "'.$page_title.'", ';
188
$sql .= '`menu_title` = "'.$menu_title.'", ';
189
$sql .= '`menu` = '.$menu.', ';
190
$sql .= '`level` = '.$level.', ';
191
$sql .= '`page_trail` = "'.$page_trail.'", ';
192
$sql .= '`root_parent` = '.$root_parent.', ';
193
$sql .= '`link` = "'.$link.'", ';
194
$sql .= '`template` = "'.$template.'", ';
195
$sql .= '`target` = "'.$target.'", ';
196
$sql .= '`description` = "'.$description.'", ';
197
$sql .= '`keywords` = "'.$keywords.'", ';
198
$sql .= '`position` = '.$position.', ';
199
$sql .= '`visibility` = "'.$visibility.'", ';
200
$sql .= '`searching` = '.$searching.', ';
201
$sql .= '`language` = "'.$language.'", ';
202
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
203
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
204
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.$page_code.' ' : ' ';
205
$sql .= 'WHERE `page_id` = '.$page_id;
206
$database->query($sql);
207

  
208
$ftan2 = $admin->getFTAN(2);
209
$target_url = ADMIN_URL."/pages/settings.php?page_id=$page_id&amp;$ftan2";
210
if($database->is_error())
211
{
212
	$admin->print_error($database->get_error(), $target_url );
213
}
214
// Clean old order if needed
215
if($parent != $old_parent)
216
{
217
	$order->clean($old_parent);
218
}
219

  
220
/* BEGIN page "access file" code */
221

  
222
// Create a new file in the /pages dir if title changed
223
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
224
{
225
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
226
} else {
227
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
228
	// First check if we need to create a new file
229
	if(($old_link != $link) || (!file_exists($old_filename)))
230
    {
231
		// Delete old file
232
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
233
		if(file_exists($old_filename))
234
        {
235
			unlink($old_filename);
236
		}
237
		// Create access file
238
		create_access_file($filename,$page_id,$level);
239
		// Move a directory for this page
240
		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
241
        {
242
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
243
		}
244
		// Update any pages that had the old link with the new one
245
		$old_link_len = strlen($old_link);
246
        $sql = '';
247
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
248

  
249
		if($query_subs->numRows() > 0)
250
        {
251
			while($sub = $query_subs->fetchRow())
252
            {
253
				// Double-check to see if it contains old link
254
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
255
                {
256
					// Get new link
257
					$replace_this = $old_link;
258
					$old_sub_link_len =strlen($sub['link']);
259
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
260
					// Work out level
261
					$new_sub_level = level_count($sub['page_id']);
262
					// Update level and link
263
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
264
					// Re-write the access file for this page
265
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
266
					if(file_exists($old_subpage_file))
267
                    {
268
						unlink($old_subpage_file);
269
					}
270
					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
271
				}
272
			}
273
		}
274
	}
275
}
276

  
277
// Function to fix page trail of subs
278
function fix_page_trail($parent,$root_parent)
279
{
280
	// Get objects and vars from outside this function
281
	global $admin, $template, $database, $TEXT, $MESSAGE;
282
	// Get page list from database
283
	// $database = new database();
284
	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
285
	$get_pages = $database->query($query);
286
	// Insert values into main page list
287
	if($get_pages->numRows() > 0)
288
    {
289
		while($page = $get_pages->fetchRow())
290
        {
291
			// Fix page trail
292

  
293
			$database->query("UPDATE ".TABLE_PREFIX."pages SET ".($root_parent != 0 ?"root_parent = '$root_parent', ":"")." page_trail = '".get_page_trail($page['page_id'])."' WHERE page_id = '".$page['page_id']."'");
294
			// Run this query on subs
295
			fix_page_trail($page['page_id'],$root_parent);
296
		}
297
	}
298
}
299

  
300
// Fix sub-pages page trail
301
fix_page_trail($page_id,$root_parent);
302

  
303
/* END page "access file" code */
304

  
305
$pagetree_url = ADMIN_URL.'/pages/index.php';
306
$ftan2 = $admin->getFTAN(2);
307
$target_url = ADMIN_URL."/pages/settings.php?page_id=$page_id&amp;$ftan2";
308
// Check if there is a db error, otherwise say successful
309
if($database->is_error())
310
{
311
	$admin->print_error($database->get_error(), $target_url );
312
} else {
313
	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
314
}
315

  
316
// Print admin footer
317
$admin->print_footer();
318

  
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
16
 *
17
 */
18

  
19
// Get page id
20
if(!isset($_POST['page_id']) OR !is_numeric($_POST['page_id']))
21
{
22
	header("Location: index.php");
23
	exit(0);
24
} else {
25
	$page_id = $_POST['page_id'];
26
}
27

  
28
// Create new admin object and print admin header
29
require('../../config.php');
30
require_once(WB_PATH.'/framework/class.admin.php');
31
$admin = new admin('Pages', 'pages_settings');
32
if (!$admin->checkFTAN())
33
{
34
	$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'index.php');
35
	exit();
36
}
37

  
38
// Include the WB functions file
39
require_once(WB_PATH.'/framework/functions.php');
40

  
41
// Get values
42
$page_title = htmlspecialchars($admin->get_post_escaped('page_title') );
43
$menu_title = htmlspecialchars($admin->get_post_escaped('menu_title') );
44
$page_code = $admin->get_post_escaped('page_code');
45
$description = htmlspecialchars($admin->add_slashes($admin->get_post('description')) );
46
$keywords = htmlspecialchars($admin->add_slashes($admin->get_post('keywords')) );
47
$parent = $admin->get_post_escaped('parent');
48
$visibility = $admin->get_post_escaped('visibility');
49
$template = $admin->get_post_escaped('template');
50
$target = $admin->get_post_escaped('target');
51
$admin_groups = $admin->get_post_escaped('admin_groups');
52
$viewing_groups = $admin->get_post_escaped('viewing_groups');
53
$searching = $admin->get_post_escaped('searching');
54
$language = $admin->get_post_escaped('language');
55
$menu = $admin->get_post_escaped('menu');
56

  
57
// Validate data
58
if($page_title == '' || substr($page_title,0,1)=='.')
59
{
60
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
61
}
62
if($menu_title == '' || substr($menu_title,0,1)=='.')
63
{
64
	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
65
}
66

  
67
// Get existing perms
68
// $database = new database();
69

  
70
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
71
$results = $database->query($sql);
72

  
73
$results_array = $results->fetchRow();
74
$old_parent = $results_array['parent'];
75
$old_link = $results_array['link'];
76
$old_position = $results_array['position'];
77
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
78
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
79

  
80
// Work-out if we should check for existing page_code
81
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
82
$field_sql = $database->query($sql);
83
$field_set = $field_sql->numRows();
84

  
85
$in_old_group = FALSE;
86
foreach($admin->get_groups_id() as $cur_gid)
87
{
88
    if (in_array($cur_gid, $old_admin_groups))
89
    {
90
	$in_old_group = TRUE;
91
    }
92
}
93
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
94
{
95
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
96
}
97

  
98
// Setup admin groups
99
$admin_groups[] = 1;
100
//if(!in_array(1, $admin->get_groups_id())) {
101
//	$admin_groups[] = implode(",",$admin->get_groups_id());
102
//}
103
$admin_groups = implode(',', $admin_groups);
104
// Setup viewing groups
105
$viewing_groups[] = 1;
106
//if(!in_array(1, $admin->get_groups_id())) {
107
//	$viewing_groups[] = implode(",",$admin->get_groups_id());
108
//}
109
$viewing_groups = implode(',', $viewing_groups);
110

  
111
// If needed, get new order
112
if($parent != $old_parent)
113
{
114
	// Include ordering class
115
	require(WB_PATH.'/framework/class.order.php');
116
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
117
	// Get new order
118
	$position = $order->get_new($parent);
119
	// Clean new order
120
	$order->clean($parent);
121
} else {
122
	$position = $old_position;
123
}
124

  
125
// Work out level and root parent
126
if ($parent!='0')
127
{
128
	$level = level_count($parent)+1;
129
	$root_parent = root_parent($parent);
130
}
131
else {
132
	$level = '0';
133
	$root_parent = '0';
134
}
135

  
136
// Work-out what the link should be
137
if($parent == '0')
138
{
139
	$link = '/'.page_filename($menu_title);
140
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
141
	if($link == '/index' || $link == '/intro')
142
    {
143
		$link .= '_' .$page_id;
144
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
145
	} else {
146
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
147
	}
148
} else {
149
	$parent_section = '';
150
	$parent_titles = array_reverse(get_parent_titles($parent));
151
	foreach($parent_titles AS $parent_title)
152
    {
153
		$parent_section .= page_filename($parent_title).'/';
154
	}
155
	if($parent_section == '/')
156
    {
157
      $parent_section = '';
158
    }
159
	$link = '/'.$parent_section.page_filename($menu_title);
160
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
161
}
162

  
163
// Check if a page with same page filename exists
164
// $database = new database();
165
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
166
$get_same_page = $database->query($sql);
167

  
168
if($get_same_page->numRows() > 0)
169
{
170
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
171
}
172

  
173
// Update page with new order
174
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
175
// $database = new database();
176
$database->query($sql);
177

  
178
// Get page trail
179
$page_trail = get_page_trail($page_id);
180

  
181
// Update page settings in the pages table
182
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
183
$sql .= '`parent` = '.$parent.', ';
184
$sql .= '`page_title` = "'.$page_title.'", ';
185
$sql .= '`menu_title` = "'.$menu_title.'", ';
186
$sql .= '`menu` = '.$menu.', ';
187
$sql .= '`level` = '.$level.', ';
188
$sql .= '`page_trail` = "'.$page_trail.'", ';
189
$sql .= '`root_parent` = '.$root_parent.', ';
190
$sql .= '`link` = "'.$link.'", ';
191
$sql .= '`template` = "'.$template.'", ';
192
$sql .= '`target` = "'.$target.'", ';
193
$sql .= '`description` = "'.$description.'", ';
194
$sql .= '`keywords` = "'.$keywords.'", ';
195
$sql .= '`position` = '.$position.', ';
196
$sql .= '`visibility` = "'.$visibility.'", ';
197
$sql .= '`searching` = '.$searching.', ';
198
$sql .= '`language` = "'.$language.'", ';
199
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
200
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
201
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.(int)$page_code.' ' : ' ';
202
$sql .= 'WHERE `page_id` = '.$page_id;
203
$database->query($sql);
204

  
205
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
206
if($database->is_error())
207
{
208
	$admin->print_error($database->get_error(), $target_url );
209
}
210
// Clean old order if needed
211
if($parent != $old_parent)
212
{
213
	$order->clean($old_parent);
214
}
215

  
216
/* BEGIN page "access file" code */
217

  
218
// Create a new file in the /pages dir if title changed
219
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
220
{
221
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
222
} else {
223
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
224
	// First check if we need to create a new file
225
	if(($old_link != $link) || (!file_exists($old_filename)))
226
    {
227
		// Delete old file
228
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
229
		if(file_exists($old_filename))
230
        {
231
			unlink($old_filename);
232
		}
233
		// Create access file
234
		create_access_file($filename,$page_id,$level);
235
		// Move a directory for this page
236
		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') AND is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
237
        {
238
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
239
		}
240
		// Update any pages that had the old link with the new one
241
		$old_link_len = strlen($old_link);
242
        $sql = '';
243
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
244

  
245
		if($query_subs->numRows() > 0)
246
        {
247
			while($sub = $query_subs->fetchRow())
248
            {
249
				// Double-check to see if it contains old link
250
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
251
                {
252
					// Get new link
253
					$replace_this = $old_link;
254
					$old_sub_link_len =strlen($sub['link']);
255
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
256
					// Work out level
257
					$new_sub_level = level_count($sub['page_id']);
258
					// Update level and link
259
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
260
					// Re-write the access file for this page
261
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
262
					if(file_exists($old_subpage_file))
263
                    {
264
						unlink($old_subpage_file);
265
					}
266
					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
267
				}
268
			}
269
		}
270
	}
271
}
272

  
273
// Function to fix page trail of subs
274
function fix_page_trail($parent,$root_parent)
275
{
276
	// Get objects and vars from outside this function
277
	global $admin, $template, $database, $TEXT, $MESSAGE;
278
	// Get page list from database
279
	// $database = new database();
280
	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
281
	$get_pages = $database->query($query);
282
	// Insert values into main page list
283
	if($get_pages->numRows() > 0)
284
    {
285
		while($page = $get_pages->fetchRow())
286
        {
287
			// Fix page trail
288

  
289
			$database->query("UPDATE ".TABLE_PREFIX."pages SET ".($root_parent != 0 ?"root_parent = '$root_parent', ":"")." page_trail = '".get_page_trail($page['page_id'])."' WHERE page_id = '".$page['page_id']."'");
290
			// Run this query on subs
291
			fix_page_trail($page['page_id'],$root_parent);
292
		}
293
	}
294
}
295

  
296
// Fix sub-pages page trail
297
fix_page_trail($page_id,$root_parent);
298

  
299
/* END page "access file" code */
300

  
301
$pagetree_url = ADMIN_URL.'/pages/index.php';
302
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
303
// Check if there is a db error, otherwise say successful
304
if($database->is_error())
305
{
306
	$admin->print_error($database->get_error(), $target_url );
307
} else {
308
	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
309
}
310

  
311
// Print admin footer
312
$admin->print_footer();
313

  
319 314
?>

Also available in: Unified diff