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 1353 2010-12-26 19:49:01Z FrankH $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
15
 * @lastmodified    $Date: 2010-12-26 20:49:01 +0100 (Sun, 26 Dec 2010) $
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
// Include the WB functions file
25
require_once(WB_PATH.'/framework/functions.php');
26

    
27
// Get values
28
$title = $admin->get_post_escaped('title');
29
$title = htmlspecialchars($title);
30
$module = preg_replace("/\W/", "", $admin->get_post('type')); // fix secunia 2010-93-4
31
$parent = (int) $admin->get_post('parent'); // fix secunia 2010-91-2
32
$visibility = $admin->get_post('visibility');
33
if (!in_array($visibility, array('public', 'private', 'registered', 'hidden', 'none'))) $visibility = 'public'; // fix secunia 2010-91-2
34
$admin_groups = $admin->get_post('admin_groups');
35
$viewing_groups = $admin->get_post('viewing_groups');
36

    
37
// Work-out if we should check for existing page_code
38
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
39
$field_sql = $database->query($sql);
40
$field_set = $field_sql->numRows();
41

    
42
// add Admin to admin and viewing-groups
43
$admin_groups[] = 1;
44
$viewing_groups[] = 1;
45

    
46
if ($parent!=0) {
47
	if (!$admin->get_page_permission($parent,'admin'))
48
    {
49
        $admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
50
    }
51

    
52
} elseif (!$admin->get_permission('pages_add_l0','system'))
53
{
54
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
55
}	
56

    
57
// Validate data
58
if($title == '' || substr($title,0,1)=='.')
59
{
60
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
61
}
62

    
63
// Check to see if page created has needed permissions
64
if(!in_array(1, $admin->get_groups_id()))
65
{
66
	$admin_perm_ok = false;
67
	foreach ($admin_groups as $adm_group)
68
    {
69
		if (in_array($adm_group, $admin->get_groups_id()))
70
        {
71
			$admin_perm_ok = true;
72
		}
73
	}
74
	if ($admin_perm_ok == false)
75
    {
76
		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
77
	}
78
	$admin_perm_ok = false;
79
	foreach ($viewing_groups as $view_group)
80
    {
81
		if (in_array($view_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
}
91

    
92
$admin_groups =   preg_replace("/[^\d,]/", "", implode(',', $admin_groups));
93
$viewing_groups = preg_replace("/[^\d,]/", "", implode(',', $viewing_groups));
94

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

    
120
// Check if a page with same page filename exists
121
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
122
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
123
{
124
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
125
}
126

    
127
// Include the ordering class
128
require(WB_PATH.'/framework/class.order.php');
129
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
130
// First clean order
131
$order->clean($parent);
132
// Get new order
133
$position = $order->get_new($parent);
134

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

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

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

    
176
// Get the page id
177
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
178

    
179
// Work out level
180
$level = level_count($page_id);
181
// Work out root parent
182
$root_parent = root_parent($page_id);
183
// Work out page trail
184
$page_trail = get_page_trail($page_id);
185

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

    
210
// add position 1 to new page
211
$position = 1;
212

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

    
216
// Get the section id
217
$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
218

    
219
// Include the selected modules add file if it exists
220
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
221
	require(WB_PATH.'/modules/'.$module.'/add.php');
222
}
223

    
224
// Check if there is a db error, otherwise say successful
225
if($database->is_error()) {
226
	$admin->print_error($database->get_error());
227
} else {
228
	$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
229
}
230

    
231
// Print admin footer
232
$admin->print_footer();
233

    
234
?>
(1-1/21)