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 1766 2012-09-22 20:25:24Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
14
 * @lastmodified    $Date: 2012-09-22 22:25:24 +0200 (Sat, 22 Sep 2012) $
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
// suppress to print the header, so no new FTAN will be set
22
$admin = new admin('Pages', 'pages_add', false);
23
if (!$admin->checkFTAN())
24
{
25
	$admin->print_header();
26
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
27
}
28

    
29
// Include the WB functions file
30
require_once(WB_PATH.'/framework/functions.php');
31

    
32
// Get values
33
//$title = $admin->get_post_escaped('title');
34
//$title = htmlspecialchars($title);
35
$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title')));
36
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
37
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
38
$visibility = $admin->get_post('visibility');
39
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
40
$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
$field_set = $database->field_exists(TABLE_PREFIX.'pages', 'page_code');
45

    
46
// add Admin to admin and viewing-groups
47
$admin_groups[] = 1;
48
$viewing_groups[] = 1;
49

    
50
// After check print the header
51
$admin->print_header();
52
// check parent page permissions:
53
if ($parent!=0) {
54
	if (!$admin->get_page_permission($parent,'admin'))
55
    {
56
        $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
57
    }
58

    
59
} elseif (!$admin->get_permission('pages_add_l0','system'))
60
{
61
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
62
}
63

    
64
// check module permissions:
65
if (!$admin->get_permission($module, 'module'))
66
{
67
	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
68
}
69

    
70
// Validate data
71
if($title == '' || substr($title,0,1)=='.')
72
{
73
	$admin->print_error($title.'::'.$MESSAGE['PAGES_BLANK_PAGE_TITLE']);
74
}
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
		}
86
	}
87
	if ($admin_perm_ok == false)
88
    {
89
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
90
	}
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
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
102
	}
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
		$sTmpFile = WB_PATH .PAGES_DIRECTORY .$link.PAGE_EXTENSION;
116
		$link .= (file_exists($sTmpFile)) ? '_0' : '';
117
		$filename = WB_PATH .PAGES_DIRECTORY .$link .PAGE_EXTENSION;
118
	} else {
119
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
120
	}
121

    
122
} 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
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
140
}
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
$sql .= '`template` = "'.$template.'", ';
169
$sql .= '`visibility` = "'.$visibility.'", ';
170
$sql .= '`position` = '.$position.', ';
171
$sql .= '`menu` = 1, ';
172
$sql .= '`language` = "'.$language.'", ';
173
$sql .= '`searching` = 1, ';
174
$sql .= '`modified_when` = '.time().', ';
175
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
176
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
177
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
178

    
179
$database->query($sql);
180
/*
181
$query = "INSERT INTO ".TABLE_PREFIX."pages
182
(page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES
183
('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')";
184
$database->query($query);
185
*/
186
if($database->is_error())
187
{
188
	$admin->print_error($database->get_error());
189
}
190

    
191
// Get the page id
192
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
193

    
194
// Work out level
195
$level = level_count($page_id);
196
// Work out root parent
197
$root_parent = root_parent($page_id);
198
// Work out page trail
199
$page_trail = get_page_trail($page_id);
200

    
201
// Update page with new level and link
202
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
203
$sql .= '`root_parent` = '.$root_parent.', ';
204
$sql .= '`level` = '.$level.', ';
205
$sql .= '`link` = "'.$link.'", ';
206
$sql .= '`page_trail` = "'.$page_trail.'"';
207
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
208
         && $field_set
209
         && ($language == DEFAULT_LANGUAGE)
210
         && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')
211
         )
212
         ? ', `page_code` = '.(int)$page_id.' ' : ' ';
213
$sql .= 'WHERE `page_id` = '.$page_id;
214
$database->query($sql);
215
/*
216
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
217
*/
218
if($database->is_error())
219
{
220
	$admin->print_error($database->get_error());
221
}
222
// Create a new file in the /pages dir
223
create_access_file($filename, $page_id, $level);
224

    
225
if(!file_exists($filename)) {
226
	$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
227
}
228

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

    
232
// Add new record into the sections table
233
//$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
234

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

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

    
260
// Print admin footer
261
$admin->print_footer();
(1-1/22)