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: settings_save.php 1681 2012-05-02 23:01:05Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings_save.php $
15
 * @lastmodified    $Date: 2012-05-03 01:01:05 +0200 (Thu, 03 May 2012) $
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']) || preg_match('/[^0-9a-f]/i',$_POST['page_id']))
29
{
30
	header("Location: index.php");
31
	exit(0);
32
} else {
33
//	$page_id = $admin->checkIDKEY('page_id');
34
//	$page_id = (int)$_POST['page_id'];
35
	if((!($page_id = $admin->checkIDKEY('page_id')))) {
36
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/index.php');
37
	}
38
}
39

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

    
49
if (!$admin->checkFTAN())
50
{
51
	$admin->print_header();
52
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$target_url);
53
}
54
// After check print the header
55
$admin->print_header();
56

    
57
// Include the WB functions file
58
require_once(WB_PATH.'/framework/functions.php');
59

    
60
// Get values
61
$page_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('page_title')));
62
$menu_title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('menu_title')));
63
$page_code = intval($admin->get_post('page_code')) ;
64
$description = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('description'))));
65
$keywords = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->add_slashes($admin->get_post('keywords'))));
66
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-3
67
$visibility = $admin->get_post_escaped('visibility');
68
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-93-3
69
$template = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('template')); // fix secunia 2010-93-3
70
$template = (($template == DEFAULT_TEMPLATE ) ? '' : $template);
71
$target = preg_replace("/\W/", "", $admin->get_post('target'));
72
$aAdminGroups   = (isset($_POST['admin_groups']) ? $_POST['admin_groups'] : array(1));
73
$aAdminUsers    = (isset($_POST['admin_users']) ? $_POST['admin_users'] : array());
74
$aViewingGroups = (isset($_POST['viewing_groups']) ? $_POST['viewing_groups'] : array(1));
75
$aViewingUsers  = (isset($_POST['viewing_users']) ? $_POST['viewing_users'] : array());
76
$searching = intval($admin->get_post('searching'));
77
$language = strtoupper($admin->get_post('language'));
78
$language = (preg_match('/^[A-Z]{2}$/', $language) ? $language : DEFAULT_LANGUAGE);
79
$menu = intval($admin->get_post('menu')); // fix secunia 2010-91-3
80
$page_code = (isset($_POST['page_code']) ? intval($_POST['page_code']) : 0);
81
$sPageIcon = (isset($_POST['page_icon']) ? $_POST['page_icon'] : 0);
82
$sMenuIcon0 = (isset($_POST['menu_icon_0']) ? $_POST['menu_icon_0'] : 0);
83
$sMenuIcon1 = (isset($_POST['menu_icon_1']) ? $_POST['menu_icon_1'] : 0);
84

    
85

    
86
// Validate data
87
if($page_title == '' || substr($page_title,0,1)=='.')
88
{
89
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
90
}
91
if($menu_title == '' || substr($menu_title,0,1)=='.')
92
{
93
	$admin->print_error($MESSAGE['PAGES']['BLANK_MENU_TITLE']);
94
}
95

    
96
// Get existing perms
97
$sql = 'SELECT `parent`,`link`,`position`,`admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.$page_id;
98
$results = $database->query($sql);
99

    
100
$results_array = $results->fetchRow();
101
$old_parent = $results_array['parent'];
102
$old_link = $results_array['link'];
103
$old_position = $results_array['position'];
104

    
105
if(!$admin->ami_group_member($results_array['admin_groups']) &&
106
   !$admin->is_group_match($admin->get_user_id(), $results_array['admin_users']))
107
{
108
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
109
}
110

    
111
// Setup admin groups
112
$aAdminGroups = (is_array($aAdminGroups) ? $aAdminGroups : array(1));
113
array_unshift($aAdminGroups, 1);
114
$sAdminGroups = implode(',', array_unique($aAdminGroups, SORT_REGULAR));
115
$sAdminGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminGroups) ? '1' : $sAdminGroups);
116

    
117
$aAdminUsers = (is_array($aAdminUsers) ? $aAdminUsers : array());
118
$sAdminUsers = implode(',', array_diff($aAdminUsers, array(0)));
119
$sAdminUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sAdminUsers) ? array() : $sAdminUsers);
120

    
121
$aViewingGroups = (is_array($aViewingGroups) ? $aViewingGroups : array(1));
122
array_unshift($aViewingGroups, 1);
123
$sViewingGroups = implode(',', array_unique($aViewingGroups, SORT_REGULAR));
124
$sViewingGroups = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingGroups) ? '1' : $sViewingGroups);
125

    
126
$aViewingUsers = (is_array($aViewingUsers) ? $aViewingUsers : array());
127
$sViewingUsers = implode(',', array_diff($aViewingUsers, array(0)));
128
$sViewingUsers = (preg_match('/^,|[^0-9,]|,,|,$/', $sViewingUsers) ? array() : $sViewingUsers);
129

    
130
$sPageIcon = (($sPageIcon == '0') ? '' : $sPageIcon);
131
if(!is_readable(WB_PATH.$sPageIcon)) { $sPageIcon = ''; }
132
$sMenuIcon0 = (($sMenuIcon0 == '0') ? '' : $sMenuIcon0);
133
if(!is_readable(WB_PATH.$sMenuIcon0)) { $sMenuIcon0 = ''; }
134
$sMenuIcon1 = (($sMenuIcon1 == '0') ? '' : $sMenuIcon1);
135
if(!is_readable(WB_PATH.$sMenuIcon1)) { $sMenuIcon1 = ''; }
136

    
137
// If needed, get new order
138
if($parent != $old_parent)
139
{
140
	// Include ordering class
141
	require(WB_PATH.'/framework/class.order.php');
142
	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
143
	// Get new order
144
	$position = $order->get_new($parent);
145
	// Clean new order
146
	$order->clean($parent);
147
} else {
148
	$position = $old_position;
149
}
150

    
151
// Work out level and root parent
152
if ($parent!='0')
153
{
154
	$level = level_count($parent)+1;
155
	$root_parent = root_parent($parent);
156
}
157
else {
158
	$level = '0';
159
	$root_parent = '0';
160
}
161

    
162
// Work-out what the link should be
163
if($parent == '0')
164
{
165
	$link = '/'.page_filename($menu_title);
166
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
167
	if($link == '/index' || $link == '/intro')
168
    {
169
		$link .= '_' .$page_id;
170
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).'_'.$page_id .PAGE_EXTENSION;
171
	} else {
172
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($menu_title).PAGE_EXTENSION;
173
	}
174
} else {
175
	$parent_section = '';
176
	$parent_titles = array_reverse(get_parent_titles($parent));
177
	foreach($parent_titles AS $parent_title)
178
    {
179
		$parent_section .= page_filename($parent_title).'/';
180
	}
181
	if($parent_section == '/')
182
    {
183
      $parent_section = '';
184
    }
185
	$link = '/'.$parent_section.page_filename($menu_title);
186
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($menu_title).PAGE_EXTENSION;
187
}
188

    
189
// Check if a page with same page filename exists
190
// $database = new database();
191
$sql = 'SELECT `page_id`,`page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `link` = "'.$link.'" AND `page_id` != '.$page_id;
192
$get_same_page = $database->query($sql);
193

    
194
if($get_same_page->numRows() > 0)
195
{
196
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
197
}
198

    
199
// Update page with new order
200
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET `parent`='.$parent.', `position`='.$position.' WHERE `page_id`='.$page_id.'';
201
// $database = new database();
202
$database->query($sql);
203

    
204
// Get page trail
205
$page_trail = get_page_trail($page_id);
206

    
207
// Update page settings in the pages table
208
$sql = 'UPDATE `'.TABLE_PREFIX.'pages` '
209
     . 'SET `parent`='.$parent.', '
210
     .     '`page_title`=\''.$page_title.'\', '
211
     .     '`tooltip`=\''.$page_title.'\', '
212
     .     '`page_icon` =\''.mysql_real_escape_string($sPageIcon).'\', '
213
     .     '`menu_title`=\''.$menu_title.'\', '
214
     .     '`menu_icon_0` =\''.mysql_real_escape_string($sMenuIcon0).'\', '
215
     .     '`menu_icon_1` =\''.mysql_real_escape_string($sMenuIcon1).'\', '
216
     .     '`menu`='.$menu.', '
217
     .     '`level`='.$level.', '
218
     .     '`page_trail`=\''.$page_trail.'\', '
219
     .     '`root_parent`='.$root_parent.', '
220
     .     '`link`=\''.$link.'\', '
221
     .     '`template`=\''.$template.'\', '
222
     .     '`target`=\''.$target.'\', '
223
     .     '`description`=\''.$description.'\', '
224
     .     '`keywords`=\''.$keywords.'\', '
225
     .     '`position`='.$position.', '
226
     .     '`visibility`=\''.$visibility.'\', '
227
     .     '`searching`='.$searching.', '
228
     .     '`language`=\''.$language.'\', '
229
     .     '`admin_groups`=\''.$sAdminGroups.'\', '
230
     .     '`admin_users`=\''.$sAdminUsers.'\', '
231
     .     '`viewing_groups`=\''.$sViewingGroups.'\', '
232
     .     '`viewing_users`=\''.$sViewingUsers.'\', '
233
     .     '`page_code`='.$page_code.' '
234
     . 'WHERE `page_id`='.$page_id;
235
if(!$database->query($sql)) {
236
	$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
237
	$admin->print_error($database->get_error(), $target_url );
238
}
239
// Clean old order if needed
240
if($parent != $old_parent)
241
{
242
	$order->clean($old_parent);
243
}
244

    
245
/* BEGIN page "access file" code */
246

    
247
// Create a new file in the /pages dir if title changed
248
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/'))
249
{
250
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
251
} else {
252
    $old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
253
	// First check if we need to create a new file
254
	if(($old_link != $link) || (!file_exists($old_filename)))
255
    {
256
		// Delete old file
257
		$old_filename = WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION;
258
		if(file_exists($old_filename))
259
        {
260
			unlink($old_filename);
261
		}
262
		// Create access file
263
		create_access_file($filename,$page_id,$level);
264
		// Move a directory for this page
265
		if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.'/') && is_dir(WB_PATH.PAGES_DIRECTORY.$old_link.'/'))
266
        {
267
			rename(WB_PATH.PAGES_DIRECTORY.$old_link.'/', WB_PATH.PAGES_DIRECTORY.$link.'/');
268
		}
269
		// Update any pages that had the old link with the new one
270
		$old_link_len = strlen($old_link);
271
        $sql = '';
272
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
273

    
274
		if($query_subs->numRows() > 0)
275
        {
276
			while($sub = $query_subs->fetchRow())
277
            {
278
				// Double-check to see if it contains old link
279
				if(substr($sub['link'], 0, $old_link_len) == $old_link)
280
                {
281
					// Get new link
282
					$replace_this = $old_link;
283
					$old_sub_link_len =strlen($sub['link']);
284
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
285
					// Work out level
286
					$new_sub_level = level_count($sub['page_id']);
287
					// Update level and link
288
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
289
					// Re-write the access file for this page
290
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION;
291
					if(file_exists($old_subpage_file))
292
                    {
293
						unlink($old_subpage_file);
294
					}
295
					create_access_file(WB_PATH.PAGES_DIRECTORY.$new_sub_link.PAGE_EXTENSION, $sub['page_id'], $new_sub_level);
296
				}
297
			}
298
		}
299
	}
300
}
301

    
302
// Function to fix page trail of subs
303
function fix_page_trail($parent,$root_parent)
304
{
305
	// Get objects and vars from outside this function
306
	global $admin, $template, $database, $TEXT, $MESSAGE;
307
	// Get page list from database
308
	// $database = new database();
309
	$query = "SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'";
310
	$get_pages = $database->query($query);
311
	// Insert values into main page list
312
	if($get_pages->numRows() > 0)
313
    {
314
		while($page = $get_pages->fetchRow())
315
        {
316
			// Fix page trail
317

    
318
			$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']."'");
319
			// Run this query on subs
320
			fix_page_trail($page['page_id'],$root_parent);
321
		}
322
	}
323
}
324

    
325
// Fix sub-pages page trail
326
fix_page_trail($page_id,$root_parent);
327

    
328
/* END page "access file" code */
329

    
330
//$pagetree_url = ADMIN_URL.'/pages/index.php';
331
//$target_url = ADMIN_URL.'/pages/settings.php?page_id='.$page_id;
332
// Check if there is a db error, otherwise say successful
333
if($database->is_error())
334
{
335
	$admin->print_error($database->get_error(), $target_url );
336
} else {
337
	$admin->print_success($MESSAGE['PAGES']['SAVED_SETTINGS'], $target_url );
338
}
339

    
340
// Print admin footer
341
$admin->print_footer();
(21-21/22)