Project

General

Profile

1 1358 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6 1707 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1358 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1373 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1358 Luisehahne
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
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 1457 Luisehahne
// suppress to print the header, so no new FTAN will be set
22
$admin = new admin('Pages', 'pages_add', false);
23 1358 Luisehahne
if (!$admin->checkFTAN())
24
{
25 1457 Luisehahne
	$admin->print_header();
26 1425 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
27 1358 Luisehahne
}
28
29
// Include the WB functions file
30
require_once(WB_PATH.'/framework/functions.php');
31
32
// Get values
33 1760 Luisehahne
//$title = $admin->get_post_escaped('title');
34
//$title = htmlspecialchars($title);
35
$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title')));
36 1494 Luisehahne
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
37 1475 Luisehahne
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
38 1358 Luisehahne
$visibility = $admin->get_post('visibility');
39 1384 Luisehahne
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
40 1358 Luisehahne
$admin_groups = $admin->get_post('admin_groups');
41
$viewing_groups = $admin->get_post('viewing_groups');
42
43
// Work-out if we should check for existing page_code
44 1457 Luisehahne
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
45 1358 Luisehahne
46
// add Admin to admin and viewing-groups
47
$admin_groups[] = 1;
48
$viewing_groups[] = 1;
49
50 1473 Luisehahne
// After check print the header
51
$admin->print_header();
52 1406 FrankH
// check parent page permissions:
53 1358 Luisehahne
if ($parent!=0) {
54
	if (!$admin->get_page_permission($parent,'admin'))
55
    {
56 1707 Luisehahne
        $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
57 1358 Luisehahne
    }
58
59
} elseif (!$admin->get_permission('pages_add_l0','system'))
60
{
61 1707 Luisehahne
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
62
}
63 1358 Luisehahne
64 1406 FrankH
// check module permissions:
65
if (!$admin->get_permission($module, 'module'))
66
{
67 1707 Luisehahne
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
68
}
69 1406 FrankH
70 1358 Luisehahne
// Validate data
71
if($title == '' || substr($title,0,1)=='.')
72
{
73 1760 Luisehahne
	$admin->print_error($title.'::'.$MESSAGE['PAGES_BLANK_PAGE_TITLE']);
74 1358 Luisehahne
}
75
76
// Check to see if page created has needed permissions
77
if(!in_array(1, $admin->get_groups_id()))
78
{
79
	$admin_perm_ok = false;
80
	foreach ($admin_groups as $adm_group)
81
    {
82
		if (in_array($adm_group, $admin->get_groups_id()))
83
        {
84
			$admin_perm_ok = true;
85 1707 Luisehahne
		}
86 1358 Luisehahne
	}
87
	if ($admin_perm_ok == false)
88
    {
89 1707 Luisehahne
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
90 1358 Luisehahne
	}
91
	$admin_perm_ok = false;
92
	foreach ($viewing_groups as $view_group)
93
    {
94
		if (in_array($view_group, $admin->get_groups_id()))
95
        {
96
			$admin_perm_ok = true;
97
		}
98
	}
99
	if ($admin_perm_ok == false)
100
    {
101 1707 Luisehahne
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
102 1358 Luisehahne
	}
103
}
104
105
$admin_groups = implode(',', $admin_groups);
106
$viewing_groups = implode(',', $viewing_groups);
107
108
// Work-out what the link and page filename should be
109
if($parent == '0')
110
{
111
	$link = '/'.page_filename($title);
112
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
113
	if($link == '/index' || $link == '/intro')
114
    {
115 1760 Luisehahne
		$sTmpFile = WB_PATH .PAGES_DIRECTORY .$link.PAGE_EXTENSION;
116
		$link .= (file_exists($sTmpFile)) ? '_0' : '';
117
		$filename = WB_PATH .PAGES_DIRECTORY .$link .PAGE_EXTENSION;
118 1358 Luisehahne
	} else {
119 1760 Luisehahne
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
120 1358 Luisehahne
	}
121 1760 Luisehahne
122 1358 Luisehahne
} else {
123
	$parent_section = '';
124
	$parent_titles = array_reverse(get_parent_titles($parent));
125
	foreach($parent_titles AS $parent_title)
126
    {
127
		$parent_section .= page_filename($parent_title).'/';
128
	}
129
	if($parent_section == '/') { $parent_section = ''; }
130
	$link = '/'.$parent_section.page_filename($title);
131
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
132
	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
133
}
134
135
// Check if a page with same page filename exists
136
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
137
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
138
{
139 1707 Luisehahne
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
140 1358 Luisehahne
}
141
142
// Include the ordering class
143
require(WB_PATH.'/framework/class.order.php');
144
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
145
// First clean order
146
$order->clean($parent);
147
// Get new order
148
$position = $order->get_new($parent);
149
150
// Work-out if the page parent (if selected) has a seperate template or language to the default
151
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
152
if($query_parent->numRows() > 0)
153
{
154
	$fetch_parent = $query_parent->fetchRow();
155
	$template = $fetch_parent['template'];
156
	$language = $fetch_parent['language'];
157
} else {
158
	$template = '';
159
	$language = DEFAULT_LANGUAGE;
160
}
161
162
// Insert page into pages table
163
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET ';
164
$sql .= '`parent` = '.$parent.', ';
165
$sql .= '`target` = "_top", ';
166
$sql .= '`page_title` = "'.$title.'", ';
167
$sql .= '`menu_title` = "'.$title.'", ';
168 1772 Luisehahne
$sql .= '`tooltip` = "'.$title.'", ';
169 1358 Luisehahne
$sql .= '`template` = "'.$template.'", ';
170
$sql .= '`visibility` = "'.$visibility.'", ';
171
$sql .= '`position` = '.$position.', ';
172
$sql .= '`menu` = 1, ';
173
$sql .= '`language` = "'.$language.'", ';
174
$sql .= '`searching` = 1, ';
175
$sql .= '`modified_when` = '.time().', ';
176
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
177
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
178
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
179
180
$database->query($sql);
181
/*
182
$query = "INSERT INTO ".TABLE_PREFIX."pages
183
(page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES
184
('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')";
185
$database->query($query);
186
*/
187
if($database->is_error())
188
{
189
	$admin->print_error($database->get_error());
190
}
191
192
// Get the page id
193
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
194
195
// Work out level
196
$level = level_count($page_id);
197
// Work out root parent
198
$root_parent = root_parent($page_id);
199
// Work out page trail
200
$page_trail = get_page_trail($page_id);
201
202
// Update page with new level and link
203
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
204
$sql .= '`root_parent` = '.$root_parent.', ';
205
$sql .= '`level` = '.$level.', ';
206
$sql .= '`link` = "'.$link.'", ';
207
$sql .= '`page_trail` = "'.$page_trail.'"';
208
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
209
         && $field_set
210
         && ($language == DEFAULT_LANGUAGE)
211
         && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')
212
         )
213
         ? ', `page_code` = '.(int)$page_id.' ' : ' ';
214
$sql .= 'WHERE `page_id` = '.$page_id;
215
$database->query($sql);
216
/*
217
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
218
*/
219
if($database->is_error())
220
{
221
	$admin->print_error($database->get_error());
222
}
223
// Create a new file in the /pages dir
224
create_access_file($filename, $page_id, $level);
225
226 1766 Luisehahne
if(!file_exists($filename)) {
227
	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
228
}
229
230 1358 Luisehahne
// add position 1 to new page
231
$position = 1;
232
233
// Add new record into the sections table
234 1754 Luisehahne
//$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
235 1358 Luisehahne
236 1754 Luisehahne
// Insert module into DB
237
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
238
$sql .= '`page_id` = '.(int)$page_id.', ';
239
$sql .= '`module` = \''.$module.'\', ';
240
$sql .= '`position` = '.(int)$position.', ';
241
$sql .= '`block` = \'1\', ';
242
$sql .= '`publ_start` = \'0\',';
243
$sql .= '`publ_end` = \'0\' ';
244
if($database->query($sql)) {
245
	// Get the section id
246
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
247
	// Include the selected modules add file if it exists
248
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
249
    {
250
		require(WB_PATH.'/modules/'.$module.'/add.php');
251
	}
252 1358 Luisehahne
}
253
254
// Check if there is a db error, otherwise say successful
255
if($database->is_error()) {
256 1754 Luisehahne
	$admin->print_error($database->get_error().' (sections)');
257 1358 Luisehahne
} else {
258 1707 Luisehahne
	$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
259 1358 Luisehahne
}
260
261
// Print admin footer
262
$admin->print_footer();