Project

General

Profile

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: settings2.php 1494 2011-08-11 14:59:01Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings2.php $
15
 * @lastmodified    $Date: 2011-08-11 16:59:01 +0200 (Thu, 11 Aug 2011) $
16
 *
17
 */
18
/* */
19

    
20
// Create new admin object and print admin header
21
require('../../config.php');
22
require_once(WB_PATH.'/framework/class.admin.php');
23

    
24
// suppress to print the header, so no new FTAN will be set
25
$admin = new admin('Pages', 'pages_settings',false);
26

    
27
// Get page id
28
if(!isset($_POST['page_id']) || !is_numeric($_POST['page_id']))
29
{
30
	header("Location: index.php");
31
	exit(0);
32
} else {
33
	$page_id = (int)$_POST['page_id'];
34
}
35

    
36
/*
37
if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
38
{
39
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
40
}
41
*/
42
$pagetree_url = ADMIN_URL.'/pages/index.php';
43
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
44

    
45
if (!$admin->checkFTAN())
46
{
47
	$admin->print_header();
48
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$target_url);
49
}
50
// After check print the header
51
$admin->print_header();
52

    
53
// Include the WB functions file
54
require_once(WB_PATH.'/framework/functions.php');
55

    
56
// Get values
57
$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
58
$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
59
$page_code = intval($admin->get_post('page_code')) ;
60
$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
61
$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
62
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-3
63
$visibility = $admin->get_post_escaped('visibility');
64
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
65
$template = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('template')); // fix secunia 2010-93-3
66
$template = (($template == DEFAULT_TEMPLATE ) ? '' : $template);
67
$target = preg_replace("/\W/", "", $admin->get_post('target'));
68
$admin_groups = $admin->get_post_escaped('admin_groups');
69
$viewing_groups = $admin->get_post_escaped('viewing_groups');
70
$searching = intval($admin->get_post('searching'));
71
$language = strtoupper($admin->get_post('language'));
72
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
73
$menu = intval($admin->get_post('menu')); // fix secunia 2010-91-3
74

    
75
// Validate data
76
if($page_title == '' || substr($page_title,0,1)=='.')
77
{
78
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
79
}
80
if($menu_title == '' || substr($menu_title,0,1)=='.')
81
{
82
	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
83
}
84

    
85
// Get existing perms
86
// $database = new database();
87

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

    
91
$results_array = $results->fetchRow();
92
$old_parent = $results_array['parent'];
93
$old_link = $results_array['link'];
94
$old_position = $results_array['position'];
95
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
96
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
97

    
98
// Work-out if we should check for existing page_code
99
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
100

    
101
$in_old_group = FALSE;
102
foreach($admin->get_groups_id() as $cur_gid)
103
{
104
    if (in_array($cur_gid, $old_admin_groups))
105
    {
106
	$in_old_group = TRUE;
107
    }
108
}
109
if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
110
{
111
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
112
}
113

    
114
// Setup admin groups
115
$admin_groups[] = 1;
116
//if(!in_array(1, $admin->get_groups_id())) {
117
//	$admin_groups[] = implode(",",$admin->get_groups_id());
118
//}
119
$admin_groups = preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
120
// Setup viewing groups
121
$viewing_groups[] = 1;
122
//if(!in_array(1, $admin->get_groups_id())) {
123
//	$viewing_groups[] = implode(",",$admin->get_groups_id());
124
//}
125
$viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
126

    
127
// If needed, get new order
128
if($parent != $old_parent)
129
{
130
	// Include ordering class
131
	require(WB_PATH.'/framework/class.order.php');
132
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
133
	// Get new order
134
	$position = $order->get_new($parent);
135
	// Clean new order
136
	$order->clean($parent);
137
} else {
138
	$position = $old_position;
139
}
140

    
141
// Work out level and root parent
142
if ($parent!='0')
143
{
144
	$level = level_count($parent)+1;
145
	$root_parent = root_parent($parent);
146
}
147
else {
148
	$level = '0';
149
	$root_parent = '0';
150
}
151

    
152
// Work-out what the link should be
153
if($parent == '0')
154
{
155
	$link = '/'.page_filename($menu_title);
156
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
157
	if($link == '/index' || $link == '/intro')
158
    {
159
		$link .= '_' .$page_id;
160
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
161
	} else {
162
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
163
	}
164
} else {
165
	$parent_section = '';
166
	$parent_titles = array_reverse(get_parent_titles($parent));
167
	foreach($parent_titles AS $parent_title)
168
    {
169
		$parent_section .= page_filename($parent_title).'/';
170
	}
171
	if($parent_section == '/')
172
    {
173
      $parent_section = '';
174
    }
175
	$link = '/'.$parent_section.page_filename($menu_title);
176
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
177
}
178

    
179
// Check if a page with same page filename exists
180
// $database = new database();
181
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
182
$get_same_page = $database->query($sql);
183

    
184
if($get_same_page->numRows() > 0)
185
{
186
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
187
}
188

    
189
// Update page with new order
190
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
191
// $database = new database();
192
$database->query($sql);
193

    
194
// Get page trail
195
$page_trail = get_page_trail($page_id);
196

    
197
// Update page settings in the pages table
198
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
199
$sql .= '`parent` = '.$parent.', ';
200
$sql .= '`page_title` = "'.$page_title.'", ';
201
$sql .= '`menu_title` = "'.$menu_title.'", ';
202
$sql .= '`menu` = '.$menu.', ';
203
$sql .= '`level` = '.$level.', ';
204
$sql .= '`page_trail` = "'.$page_trail.'", ';
205
$sql .= '`root_parent` = '.$root_parent.', ';
206
$sql .= '`link` = "'.$link.'", ';
207
$sql .= '`template` = "'.$template.'", ';
208
$sql .= '`target` = "'.$target.'", ';
209
$sql .= '`description` = "'.$description.'", ';
210
$sql .= '`keywords` = "'.$keywords.'", ';
211
$sql .= '`position` = '.$position.', ';
212
$sql .= '`visibility` = "'.$visibility.'", ';
213
$sql .= '`searching` = '.$searching.', ';
214
$sql .= '`language` = "'.$language.'", ';
215
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
216
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
217
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES) && $field_set && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')) ? ', `page_code` = '.(int)$page_code.' ' : ' ';
218
$sql .= 'WHERE `page_id` = '.$page_id;
219
$database->query($sql);
220

    
221
$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
222
if($database->is_error())
223
{
224
	$admin->print_error($database->get_error(), $target_url );
225
}
226
// Clean old order if needed
227
if($parent != $old_parent)
228
{
229
	$order->clean($old_parent);
230
}
231

    
232
/* BEGIN page "access file" code */
233

    
234
// Create a new file in the /pages dir if title changed
235
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
236
{
237
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
238
} else {
239
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
240
	// First check if we need to create a new file
241
	if(($old_link != $link) || (!file_exists($old_filename)))
242
    {
243
		// Delete old file
244
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
245
		if(file_exists($old_filename))
246
        {
247
			unlink($old_filename);
248
		}
249
		// Create access file
250
		create_access_file($filename,$page_id,$level);
251
		// Move a directory for this page
252
		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
253
        {
254
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
255
		}
256
		// Update any pages that had the old link with the new one
257
		$old_link_len = strlen($old_link);
258
        $sql = '';
259
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
260

    
261
		if($query_subs->numRows() > 0)
262
        {
263
			while($sub = $query_subs->fetchRow())
264
            {
265
				// Double-check to see if it contains old link
266
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
267
                {
268
					// Get new link
269
					$replace_this = $old_link;
270
					$old_sub_link_len =strlen($sub['link']);
271
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
272
					// Work out level
273
					$new_sub_level = level_count($sub['page_id']);
274
					// Update level and link
275
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
276
					// Re-write the access file for this page
277
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
278
					if(file_exists($old_subpage_file))
279
                    {
280
						unlink($old_subpage_file);
281
					}
282
					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
283
				}
284
			}
285
		}
286
	}
287
}
288

    
289
// Function to fix page trail of subs
290
function fix_page_trail($parent,$root_parent)
291
{
292
	// Get objects and vars from outside this function
293
	global $admin, $template, $database, $TEXT, $MESSAGE;
294
	// Get page list from database
295
	// $database = new database();
296
	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
297
	$get_pages = $database->query($query);
298
	// Insert values into main page list
299
	if($get_pages->numRows() > 0)
300
    {
301
		while($page = $get_pages->fetchRow())
302
        {
303
			// Fix page trail
304

    
305
			$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']."'");
306
			// Run this query on subs
307
			fix_page_trail($page['page_id'],$root_parent);
308
		}
309
	}
310
}
311

    
312
// Fix sub-pages page trail
313
fix_page_trail($page_id,$root_parent);
314

    
315
/* END page "access file" code */
316

    
317
//$pagetree_url = ADMIN_URL.'/pages/index.php';
318
//$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
319
// Check if there is a db error, otherwise say successful
320
if($database->is_error())
321
{
322
	$admin->print_error($database->get_error(), $target_url );
323
} else {
324
	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
325
}
326

    
327
// Print admin footer
328
$admin->print_footer();
(21-21/22)