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-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: settings2.php 1358 2010-12-28 08:44:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/settings2.php $
15
 * @lastmodified    $Date: 2010-12-28 09:44:12 +0100 (Tue, 28 Dec 2010) $
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

    
314
?>
(20-20/21)