1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
40
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
519
|
Ruebenwurz
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9 |
4
|
ryan
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
// Create new admin object and print admin header
|
27 |
|
|
require('../../config.php');
|
28 |
|
|
require_once(WB_PATH.'/framework/class.admin.php');
|
29 |
|
|
$admin = new admin('Pages', 'pages_add');
|
30 |
|
|
|
31 |
|
|
// Include the WB functions file
|
32 |
|
|
require_once(WB_PATH.'/framework/functions.php');
|
33 |
|
|
|
34 |
|
|
// Get values
|
35 |
488
|
Ruebenwurz
|
$title = $admin->get_post_escaped('title');
|
36 |
657
|
thorn
|
$title = htmlspecialchars($title);
|
37 |
4
|
ryan
|
$module = $admin->get_post('type');
|
38 |
|
|
$parent = $admin->get_post('parent');
|
39 |
|
|
$visibility = $admin->get_post('visibility');
|
40 |
|
|
$admin_groups = $admin->get_post('admin_groups');
|
41 |
|
|
$viewing_groups = $admin->get_post('viewing_groups');
|
42 |
|
|
|
43 |
804
|
thorn
|
// add Admin to admin and viewing-groups
|
44 |
|
|
$admin_groups[] = 1;
|
45 |
|
|
if($visibility == 'private' || $visibility == 'registered') {
|
46 |
|
|
$viewing_groups[] = 1;
|
47 |
|
|
} else {
|
48 |
|
|
$viewing_groups = array(1);
|
49 |
733
|
thorn
|
}
|
50 |
|
|
|
51 |
319
|
stefan
|
if ($parent!=0) {
|
52 |
|
|
if (!$admin->get_page_permission($parent,'admin'))
|
53 |
|
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
54 |
|
|
} elseif (!$admin->get_permission('pages_add_l0','system')) {
|
55 |
|
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
4
|
ryan
|
// Validate data
|
59 |
428
|
Ruebenwurz
|
if($title == '' || substr($title,0,1)=='.') {
|
60 |
392
|
Ruebenwurz
|
$admin->print_error($MESSAGE['PAGES']['BLANK_PAGE_TITLE']);
|
61 |
4
|
ryan
|
}
|
62 |
|
|
|
63 |
733
|
thorn
|
// Check to see if page created has needed permissions
|
64 |
546
|
doc
|
if(!in_array(1, $admin->get_groups_id())) {
|
65 |
733
|
thorn
|
$admin_perm_ok = false;
|
66 |
|
|
foreach ($admin_groups as $adm_group) {
|
67 |
|
|
if (in_array($adm_group, $admin->get_groups_id())) {
|
68 |
|
|
$admin_perm_ok = true;
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
if ($admin_perm_ok == false) {
|
72 |
|
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
73 |
|
|
}
|
74 |
|
|
$admin_perm_ok = false;
|
75 |
|
|
foreach ($viewing_groups as $view_group) {
|
76 |
|
|
if (in_array($view_group, $admin->get_groups_id())) {
|
77 |
|
|
$admin_perm_ok = true;
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
if ($admin_perm_ok == false) {
|
81 |
|
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
82 |
|
|
}
|
83 |
4
|
ryan
|
}
|
84 |
733
|
thorn
|
|
85 |
|
|
$admin_groups = implode(',', $admin_groups);
|
86 |
4
|
ryan
|
$viewing_groups = implode(',', $viewing_groups);
|
87 |
|
|
|
88 |
|
|
// Work-out what the link and page filename should be
|
89 |
|
|
if($parent == '0') {
|
90 |
|
|
$link = '/'.page_filename($title);
|
91 |
555
|
Ruebenwurz
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).PAGE_EXTENSION;
|
92 |
4
|
ryan
|
} else {
|
93 |
|
|
$parent_section = '';
|
94 |
|
|
$parent_titles = array_reverse(get_parent_titles($parent));
|
95 |
|
|
foreach($parent_titles AS $parent_title) {
|
96 |
|
|
$parent_section .= page_filename($parent_title).'/';
|
97 |
|
|
}
|
98 |
|
|
if($parent_section == '/') { $parent_section = ''; }
|
99 |
|
|
$link = '/'.$parent_section.page_filename($title);
|
100 |
555
|
Ruebenwurz
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).PAGE_EXTENSION;
|
101 |
4
|
ryan
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
// Check if a page with same page filename exists
|
105 |
|
|
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
|
106 |
555
|
Ruebenwurz
|
if($get_same_page->numRows() > 0 OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION) OR file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')) {
|
107 |
46
|
stefan
|
$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
108 |
4
|
ryan
|
}
|
109 |
|
|
|
110 |
|
|
// Include the ordering class
|
111 |
|
|
require(WB_PATH.'/framework/class.order.php');
|
112 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
113 |
|
|
// First clean order
|
114 |
|
|
$order->clean($parent);
|
115 |
|
|
// Get new order
|
116 |
|
|
$position = $order->get_new($parent);
|
117 |
|
|
|
118 |
|
|
// Work-out if the page parent (if selected) has a seperate template to the default
|
119 |
|
|
$query_parent = $database->query("SELECT template FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
|
120 |
|
|
if($query_parent->numRows() > 0) {
|
121 |
|
|
$fetch_parent = $query_parent->fetchRow();
|
122 |
|
|
$template = $fetch_parent['template'];
|
123 |
|
|
} else {
|
124 |
|
|
$template = '';
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
// Insert page into pages table
|
128 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."pages (page_title,menu_title,parent,template,target,position,visibility,searching,menu,language,admin_groups,viewing_groups,modified_when,modified_by) VALUES ('$title','$title','$parent','$template','_top','$position','$visibility','1','1','".DEFAULT_LANGUAGE."','$admin_groups','$viewing_groups','".mktime()."','".$admin->get_user_id()."')";
|
129 |
|
|
$database->query($query);
|
130 |
|
|
if($database->is_error()) {
|
131 |
|
|
$admin->print_error($database->get_error());
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
// Get the page id
|
135 |
|
|
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
|
136 |
|
|
|
137 |
|
|
// Work out level
|
138 |
|
|
$level = level_count($page_id);
|
139 |
|
|
// Work out root parent
|
140 |
|
|
$root_parent = root_parent($page_id);
|
141 |
|
|
// Work out page trail
|
142 |
|
|
$page_trail = get_page_trail($page_id);
|
143 |
|
|
|
144 |
|
|
// Update page with new level and link
|
145 |
|
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
|
146 |
|
|
|
147 |
|
|
// Create a new file in the /pages dir
|
148 |
|
|
create_access_file($filename, $page_id, $level);
|
149 |
|
|
|
150 |
|
|
// Get new order for section
|
151 |
|
|
$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
|
152 |
|
|
$position = $order->get_new($parent);
|
153 |
|
|
|
154 |
|
|
// Add new record into the sections table
|
155 |
|
|
$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
|
156 |
|
|
|
157 |
|
|
// Get the section id
|
158 |
|
|
$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
|
159 |
|
|
|
160 |
|
|
// Include the selected modules add file if it exists
|
161 |
|
|
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
|
162 |
|
|
require(WB_PATH.'/modules/'.$module.'/add.php');
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
// Check if there is a db error, otherwise say successful
|
166 |
|
|
if($database->is_error()) {
|
167 |
|
|
$admin->print_error($database->get_error());
|
168 |
|
|
} else {
|
169 |
|
|
$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
// Print admin footer
|
173 |
|
|
$admin->print_footer();
|
174 |
|
|
|
175 |
239
|
stefan
|
?>
|