Project

General

Profile

1 1301 Luisehahne
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, 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 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
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 = $admin->get_post('type');
31
$parent = $admin->get_post('parent');
32
$visibility = $admin->get_post('visibility');
33
$admin_groups = $admin->get_post('admin_groups');
34
$viewing_groups = $admin->get_post('viewing_groups');
35
36
// Work-out if we should check for existing page_code
37
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
38
$field_sql = $database->query($sql);
39
$field_set = $field_sql->numRows();
40
41
// add Admin to admin and viewing-groups
42
$admin_groups[] = 1;
43
$viewing_groups[] = 1;
44
45
if ($parent!=0) {
46
	if (!$admin->get_page_permission($parent,'admin'))
47
    {
48
        $admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
49
    }
50
51
} elseif (!$admin->get_permission('pages_add_l0','system'))
52
{
53
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
54
}
55
56
// Validate data
57
if($title == '' || substr($title,0,1)=='.')
58
{
59
	$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
60
}
61
62
// Check to see if page created has needed permissions
63
if(!in_array(1, $admin->get_groups_id()))
64
{
65
	$admin_perm_ok = false;
66
	foreach ($admin_groups as $adm_group)
67
    {
68
		if (in_array($adm_group, $admin->get_groups_id()))
69
        {
70
			$admin_perm_ok = true;
71
		}
72
	}
73
	if ($admin_perm_ok == false)
74
    {
75
		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
76
	}
77
	$admin_perm_ok = false;
78
	foreach ($viewing_groups as $view_group)
79
    {
80
		if (in_array($view_group, $admin->get_groups_id()))
81
        {
82
			$admin_perm_ok = true;
83
		}
84
	}
85
	if ($admin_perm_ok == false)
86
    {
87
		$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
88
	}
89
}
90
91
$admin_groups = implode(',', $admin_groups);
92
$viewing_groups = implode(',', $viewing_groups);
93
94
// Work-out what the link and page filename should be
95
if($parent == '0')
96
{
97
	$link = '/'.page_filename($title);
98
	// rename menu titles: index && intro to prevent clashes with intro page feature and WB core file /pages/index.php
99
	if($link == '/index' || $link == '/intro')
100
    {
101
		$link .= '_0';
102
		$filename = WB_PATH .PAGES_DIRECTORY .'/' .page_filename($title) .'_0' .PAGE_EXTENSION;
103
	} else {
104
		$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION;
105
	}
106
} else {
107
	$parent_section = '';
108
	$parent_titles = array_reverse(get_parent_titles($parent));
109
	foreach($parent_titles AS $parent_title)
110
    {
111
		$parent_section .= page_filename($parent_title).'/';
112
	}
113
	if($parent_section == '/') { $parent_section = ''; }
114
	$link = '/'.$parent_section.page_filename($title);
115
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
116
	make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
117
}
118
119
// Check if a page with same page filename exists
120
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
121
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/'))
122
{
123
	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
124
}
125
126
// Include the ordering class
127
require(WB_PATH.'/framework/class.order.php');
128
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
129
// First clean order
130
$order->clean($parent);
131
// Get new order
132
$position = $order->get_new($parent);
133
134
// Work-out if the page parent (if selected) has a seperate template or language to the default
135
$query_parent = $database->query("SELECT template, language FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
136
if($query_parent->numRows() > 0)
137
{
138
	$fetch_parent = $query_parent->fetchRow();
139
	$template = $fetch_parent['template'];
140
	$language = $fetch_parent['language'];
141
} else {
142
	$template = '';
143
	$language = DEFAULT_LANGUAGE;
144
}
145
146
// Insert page into pages table
147
$sql  = 'INSERT INTO `'.TABLE_PREFIX.'pages` SET ';
148
$sql .= '`parent` = '.$parent.', ';
149
$sql .= '`target` = "_top", ';
150
$sql .= '`page_title` = "'.$title.'", ';
151
$sql .= '`menu_title` = "'.$title.'", ';
152
$sql .= '`template` = "'.$template.'", ';
153
$sql .= '`visibility` = "'.$visibility.'", ';
154
$sql .= '`position` = '.$position.', ';
155
$sql .= '`menu` = 1, ';
156
$sql .= '`language` = "'.$language.'", ';
157
$sql .= '`searching` = 1, ';
158
$sql .= '`modified_when` = '.time().', ';
159
$sql .= '`modified_by` = '.$admin->get_user_id().', ';
160
$sql .= '`admin_groups` = "'.$admin_groups.'", ';
161
$sql .= '`viewing_groups` = "'.$viewing_groups.'"';
162
163
$database->query($sql);
164
/*
165
$query = "INSERT INTO ".TABLE_PREFIX."pages
166
(page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES
167
('$title','$title','$parent','$template','_top','$position','$visibility','1','1','$language','$admin_groups','$viewing_groups','".time()."','".$admin->get_user_id()."')";
168
$database->query($query);
169
*/
170
if($database->is_error())
171
{
172
	$admin->print_error($database->get_error());
173
}
174
175
// Get the page id
176
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
177
178
// Work out level
179
$level = level_count($page_id);
180
// Work out root parent
181
$root_parent = root_parent($page_id);
182
// Work out page trail
183
$page_trail = get_page_trail($page_id);
184
185
// Update page with new level and link
186
$sql  = 'UPDATE `'.TABLE_PREFIX.'pages` SET ';
187
$sql .= '`root_parent` = '.$root_parent.', ';
188
$sql .= '`level` = '.$level.', ';
189
$sql .= '`link` = "'.$link.'", ';
190
$sql .= '`page_trail` = "'.$page_trail.'"';
191
$sql .= (defined('PAGE_LANGUAGES') && PAGE_LANGUAGES)
192
         && $field_set
193
         && ($language == DEFAULT_LANGUAGE)
194
         && (file_exists(WB_PATH.'/modules/mod_multilingual/update_keys.php')
195
         )
196
         ? ', `page_code` = '.(int)$page_id.' ' : ' ';
197
$sql .= 'WHERE `page_id` = '.$page_id;
198
$database->query($sql);
199
/*
200
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
201
*/
202
if($database->is_error())
203
{
204
	$admin->print_error($database->get_error());
205
}
206
// Create a new file in the /pages dir
207
create_access_file($filename, $page_id, $level);
208
209
// add position 1 to new page
210
$position = 1;
211
212
// Add new record into the sections table
213
$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
214
215
// Get the section id
216
$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
217
218
// Include the selected modules add file if it exists
219
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
220
	require(WB_PATH.'/modules/'.$module.'/add.php');
221
}
222
223
// Check if there is a db error, otherwise say successful
224
if($database->is_error()) {
225
	$admin->print_error($database->get_error());
226
} else {
227
	$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
228
}
229
230
// Print admin footer
231
$admin->print_footer();
232
233 239 stefan
?>