Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: add.php 1868 2013-02-19 21:07:19Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
14
 * @lastmodified    $Date: 2013-02-19 22:07:19 +0100 (Tue, 19 Feb 2013) $
15
 *
16
 */
17

    
18
// Create new admin object and print admin header
19
//require('../../config.php');
20
//require_once(WB_PATH.'/framework/class.admin.php');
21
// Create new admin object and print admin header
22
if(!defined('WB_URL'))
23
{
24
    $config_file = realpath('../../config.php');
25
    if(file_exists($config_file) && !defined('WB_URL'))
26
    {
27
    	require($config_file);
28
    }
29
}
30
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
31
// suppress to print the header, so no new FTAN will be set
32
$admin = new admin('Pages', 'pages_add', false);
33
if (!$admin->checkFTAN())
34
{
35
	$admin->print_header();
36
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
37
}
38

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

    
42
// Get values
43
//$title = $admin->get_post_escaped('title');
44
//$title = htmlspecialchars($title);
45
$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title')));
46
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
47
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
48
$visibility = $admin->get_post('visibility');
49
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
50
$admin_groups = $admin->get_post('admin_groups');
51
$viewing_groups = $admin->get_post('viewing_groups');
52

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

    
56
// add Admin to admin and viewing-groups
57
$admin_groups[] = 1;
58
$viewing_groups[] = 1;
59

    
60
// After check print the header
61
$admin->print_header();
62
// check parent page permissions:
63
if ($parent!=0) {
64
	if (!$admin->get_page_permission($parent,'admin'))
65
    {
66
        $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
67
    }
68

    
69
} elseif (!$admin->get_permission('pages_add_l0','system'))
70
{
71
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
72
}
73

    
74
// check module permissions:
75
if (!$admin->get_permission($module, 'module'))
76
{
77
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
78
}
79

    
80
// Validate data
81
if($title == '' || substr($title,0,1)=='.')
82
{
83
	$admin->print_error($title.'::'.$MESSAGE['PAGES_BLANK_PAGE_TITLE']);
84
}
85

    
86
// Check to see if page created has needed permissions
87
if(!in_array(1, $admin->get_groups_id()))
88
{
89
	$admin_perm_ok = false;
90
	foreach ($admin_groups as $adm_group)
91
    {
92
		if (in_array($adm_group, $admin->get_groups_id()))
93
        {
94
			$admin_perm_ok = true;
95
		}
96
	}
97
	if ($admin_perm_ok == false)
98
    {
99
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
100
	}
101
	$admin_perm_ok = false;
102
	foreach ($viewing_groups as $view_group)
103
    {
104
		if (in_array($view_group, $admin->get_groups_id()))
105
        {
106
			$admin_perm_ok = true;
107
		}
108
	}
109
	if ($admin_perm_ok == false)
110
    {
111
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
112
	}
113
}
114

    
115
$admin_groups = implode(',', $admin_groups);
116
$viewing_groups = implode(',', $viewing_groups);
117

    
118
// Work-out what the link and page filename should be
119
if($parent == '0')
120
{
121
	$link = '/'.page_filename($title);
122
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
123
	if($link == '/index' || $link == '/intro')
124
    {
125
		$sTmpFile = WB_PATH .PAGES_DIRECTORY .$link.PAGE_EXTENSION;
126
		$link .= (file_exists($sTmpFile)) ? '_0' : '';
127
		$filename = WB_PATH .PAGES_DIRECTORY .$link .PAGE_EXTENSION;
128
	} else {
129
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
130
	}
131

    
132
} else {
133
	$parent_section = '';
134
	$parent_titles = array_reverse(get_parent_titles($parent));
135
	foreach($parent_titles AS $parent_title)
136
    {
137
		$parent_section .= page_filename($parent_title).'/';
138
	}
139
	if($parent_section == '/') { $parent_section = ''; }
140
	$link = '/'.$parent_section.page_filename($title);
141
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
142
	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
143
}
144

    
145
// Check if a page with same page filename exists
146
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
147
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
148
{
149
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
150
}
151

    
152
// Include the ordering class
153
require(WB_PATH.'/framework/class.order.php');
154
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
155
// First clean order
156
$order->clean($parent);
157
// Get new order
158
$position = $order->get_new($parent);
159

    
160
// Work-out if the page parent (if selected) has a seperate template or language to the default
161
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
162
if($query_parent->numRows() > 0)
163
{
164
	$fetch_parent = $query_parent->fetchRow();
165
	$template = $fetch_parent['template'];
166
	$language = $fetch_parent['language'];
167
} else {
168
	$template = '';
169
	$language = DEFAULT_LANGUAGE;
170
}
171

    
172
// Insert page into pages table
173
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET ';
174
$sql .= '`parent` = '.$parent.', ';
175
$sql .= '`target` = "_top", ';
176
$sql .= '`page_title` = "'.$title.'", ';
177
$sql .= '`menu_title` = "'.$title.'", ';
178
$sql .= '`tooltip` = "'.$title.'", ';
179
$sql .= '`template` = "'.$template.'", ';
180
$sql .= '`visibility` = "'.$visibility.'", ';
181
$sql .= '`position` = '.$position.', ';
182
$sql .= '`menu` = 1, ';
183
$sql .= '`language` = "'.$language.'", ';
184
$sql .= '`searching` = 1, ';
185
$sql .= '`modified_when` = '.time().', ';
186
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
187
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
188
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
189

    
190
$database->query($sql);
191

    
192
if($database->is_error())
193
{
194
	$admin->print_error($database->get_error());
195
}
196

    
197
// Get the page id
198
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
199

    
200
// Work out level
201
$level = level_count($page_id);
202
// Work out root parent
203
$root_parent = root_parent($page_id);
204
// Work out page trail
205
$page_trail = get_page_trail($page_id);
206

    
207
// Update page with new level and link
208
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
209
$sql .= '`root_parent` = '.$root_parent.', ';
210
$sql .= '`level` = '.$level.', ';
211
$sql .= '`link` = "'.$link.'", ';
212
$sql .= '`page_trail` = "'.$page_trail.'"';
213
$sql .= ((defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
214
         && $field_set
215
         && ($language == DEFAULT_LANGUAGE)
216
         && class_exists('m_MultiLingual_Lib')
217
         ? ', `page_code` = '.(int)$page_id.' ' : ' ');
218
$sql .= 'WHERE `page_id` = '.$page_id;
219
$database->query($sql);
220
/*
221
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
222
*/
223
if($database->is_error())
224
{
225
	$admin->print_error($database->get_error());
226
}
227

    
228
// add position 1 to new page section
229
$position = 1;
230

    
231
// Add new record into the sections table
232
// Insert module into DB
233
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
234
$sql .= '`page_id` = '.(int)$page_id.', ';
235
$sql .= '`module` = \''.$module.'\', ';
236
$sql .= '`position` = '.(int)$position.', ';
237
$sql .= '`block` = \'1\', ';
238
$sql .= '`publ_start` = \'0\',';
239
$sql .= '`publ_end` = \'0\' ';
240
if($database->query($sql)) {
241
	// Get the section id
242
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
243
	// Include the selected modules add file if it exists
244
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
245
    {
246
		require(WB_PATH.'/modules/'.$module.'/add.php');
247
	}
248
}
249

    
250
// Create a new file in the /pages dir
251
create_access_file($filename, $page_id, $level);
252

    
253
if(!file_exists($filename)) {
254
	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
255
}
256

    
257
// Check if there is a db error, otherwise say successful
258
if($database->is_error()) {
259
	$admin->print_error($database->get_error().' (sections)');
260
} else {
261
	$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
262
}
263

    
264
// Print admin footer
265
$admin->print_footer();
(2-2/23)