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-2011, 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 5.2.2 and higher
13
 * @version         $Id: add.php 1384 2011-01-16 08:39:00Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
15
 * @lastmodified    $Date: 2011-01-16 09:39:00 +0100 (Sun, 16 Jan 2011) $
16
 *
17
 */
18

    
19
// Create new admin object and print admin header
20
require('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Pages', 'pages_add');
23

    
24
if (!$admin->checkFTAN())
25
{
26
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
27
	exit();
28
}
29

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

    
33
// Get values
34
$title = $admin->get_post_escaped('title');
35
$title = htmlspecialchars($title);
36
$module = preg_replace("/\W/", "", $admin->get_post('type')); // fix secunia 2010-93-4
37
$parent = (int) $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
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
45
$field_sql = $database->query($sql);
46
$field_set = $field_sql->numRows();
47

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

    
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
// Validate data
64
if($title == '' || substr($title,0,1)=='.')
65
{
66
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
67
}
68

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

    
98
$admin_groups = implode(',', $admin_groups);
99
$viewing_groups = implode(',', $viewing_groups);
100

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

    
126
// Check if a page with same page filename exists
127
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
128
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
129
{
130
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
131
}
132

    
133
// Include the ordering class
134
require(WB_PATH.'/framework/class.order.php');
135
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
136
// First clean order
137
$order->clean($parent);
138
// Get new order
139
$position = $order->get_new($parent);
140

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

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

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

    
182
// Get the page id
183
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
184

    
185
// Work out level
186
$level = level_count($page_id);
187
// Work out root parent
188
$root_parent = root_parent($page_id);
189
// Work out page trail
190
$page_trail = get_page_trail($page_id);
191

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

    
216
// add position 1 to new page
217
$position = 1;
218

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

    
222
// Get the section id
223
$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
224

    
225
// Include the selected modules add file if it exists
226
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
227
	require(WB_PATH.'/modules/'.$module.'/add.php');
228
}
229

    
230
// Check if there is a db error, otherwise say successful
231
if($database->is_error()) {
232
	$admin->print_error($database->get_error());
233
} else {
234
	$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
235
}
236

    
237
// Print admin footer
238
$admin->print_footer();
239

    
240
?>
(1-1/21)