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 1754 2012-09-15 16:00:56Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
14
 * @lastmodified    $Date: 2012-09-15 18:00:56 +0200 (Sat, 15 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
$module = preg_replace('/[^a-z0-9_-]/i', "", $admin->get_post('type')); // fix secunia 2010-93-4
36
$parent = intval($admin->get_post('parent')); // fix secunia 2010-91-2
37
$visibility = $admin->get_post('visibility');
38
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) {$visibility = 'public';} // fix secunia 2010-91-2
39
$admin_groups = $admin->get_post('admin_groups');
40
$viewing_groups = $admin->get_post('viewing_groups');
41

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

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

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

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

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

    
69
// Validate data
70
if($title == '' || substr($title,0,1)=='.')
71
{
72
	$admin->print_error($MESSAGE['PAGES_BLANK_PAGE_TITLE']);
73
}
74

    
75
// Check to see if page created has needed permissions
76
if(!in_array(1, $admin->get_groups_id()))
77
{
78
	$admin_perm_ok = false;
79
	foreach ($admin_groups as $adm_group)
80
    {
81
		if (in_array($adm_group, $admin->get_groups_id()))
82
        {
83
			$admin_perm_ok = true;
84
		}
85
	}
86
	if ($admin_perm_ok == false)
87
    {
88
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
89
	}
90
	$admin_perm_ok = false;
91
	foreach ($viewing_groups as $view_group)
92
    {
93
		if (in_array($view_group, $admin->get_groups_id()))
94
        {
95
			$admin_perm_ok = true;
96
		}
97
	}
98
	if ($admin_perm_ok == false)
99
    {
100
		$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
101
	}
102
}
103

    
104
$admin_groups = implode(',', $admin_groups);
105
$viewing_groups = implode(',', $viewing_groups);
106

    
107
// Work-out what the link and page filename should be
108
if($parent == '0')
109
{
110
	$link = '/'.page_filename($title);
111
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
112
	if($link == '/index' || $link == '/intro')
113
    {
114
		$link .= '_0';
115
		$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION;
116
	} else {
117
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION;
118
	}
119
} else {
120
	$parent_section = '';
121
	$parent_titles = array_reverse(get_parent_titles($parent));
122
	foreach($parent_titles AS $parent_title)
123
    {
124
		$parent_section .= page_filename($parent_title).'/';
125
	}
126
	if($parent_section == '/') { $parent_section = ''; }
127
	$link = '/'.$parent_section.page_filename($title);
128
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
129
	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
130
}
131

    
132
// Check if a page with same page filename exists
133
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
134
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
135
{
136
	$admin->print_error($MESSAGE['PAGES_PAGE_EXISTS']);
137
}
138

    
139
// Include the ordering class
140
require(WB_PATH.'/framework/class.order.php');
141
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
142
// First clean order
143
$order->clean($parent);
144
// Get new order
145
$position = $order->get_new($parent);
146

    
147
// Work-out if the page parent (if selected) has a seperate template or language to the default
148
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
149
if($query_parent->numRows() > 0)
150
{
151
	$fetch_parent = $query_parent->fetchRow();
152
	$template = $fetch_parent['template'];
153
	$language = $fetch_parent['language'];
154
} else {
155
	$template = '';
156
	$language = DEFAULT_LANGUAGE;
157
}
158

    
159
// Insert page into pages table
160
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET ';
161
$sql .= '`parent` = '.$parent.', ';
162
$sql .= '`target` = "_top", ';
163
$sql .= '`page_title` = "'.$title.'", ';
164
$sql .= '`menu_title` = "'.$title.'", ';
165
$sql .= '`template` = "'.$template.'", ';
166
$sql .= '`visibility` = "'.$visibility.'", ';
167
$sql .= '`position` = '.$position.', ';
168
$sql .= '`menu` = 1, ';
169
$sql .= '`language` = "'.$language.'", ';
170
$sql .= '`searching` = 1, ';
171
$sql .= '`modified_when` = '.time().', ';
172
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
173
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
174
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
175

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

    
188
// Get the page id
189
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
190

    
191
// Work out level
192
$level = level_count($page_id);
193
// Work out root parent
194
$root_parent = root_parent($page_id);
195
// Work out page trail
196
$page_trail = get_page_trail($page_id);
197

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

    
222
// add position 1 to new page
223
$position = 1;
224

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

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

    
246
// Check if there is a db error, otherwise say successful
247
if($database->is_error()) {
248
	$admin->print_error($database->get_error().' (sections)');
249
} else {
250
	$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
251
}
252

    
253
// Print admin footer
254
$admin->print_footer();
(1-1/22)