1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
40
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
|
|
Copyright (C) 2004-2005, Ryan Djurovich
|
9 |
|
|
|
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 |
40
|
stefan
|
$title = $admin->add_slashes($admin->get_post('title'));
|
36 |
4
|
ryan
|
$module = $admin->get_post('type');
|
37 |
|
|
$parent = $admin->get_post('parent');
|
38 |
|
|
$visibility = $admin->get_post('visibility');
|
39 |
|
|
$admin_groups = $admin->get_post('admin_groups');
|
40 |
|
|
$viewing_groups = $admin->get_post('viewing_groups');
|
41 |
|
|
|
42 |
|
|
// Validate data
|
43 |
|
|
if($title == '') {
|
44 |
|
|
$admin->print_error($MESSAGE['PAGES']['BLANK_TITLE']);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// Setup admin groups
|
48 |
|
|
$admin_groups[] = 1;
|
49 |
|
|
if($admin->get_group_id() != 1) {
|
50 |
|
|
$admin_groups[] = $admin->get_group_id();
|
51 |
|
|
}
|
52 |
|
|
$admin_groups = implode(',', $admin_groups);
|
53 |
|
|
// Setup viewing groups
|
54 |
|
|
$viewing_groups[] = 1;
|
55 |
|
|
if($admin->get_group_id() != 1) {
|
56 |
|
|
$viewing_groups[] = $admin->get_group_id();
|
57 |
|
|
}
|
58 |
|
|
$viewing_groups = implode(',', $viewing_groups);
|
59 |
|
|
|
60 |
|
|
// Work-out what the link and page filename should be
|
61 |
|
|
if($parent == '0') {
|
62 |
|
|
$link = '/'.page_filename($title);
|
63 |
|
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.page_filename($title).'.php';
|
64 |
|
|
} else {
|
65 |
|
|
$parent_section = '';
|
66 |
|
|
$parent_titles = array_reverse(get_parent_titles($parent));
|
67 |
|
|
foreach($parent_titles AS $parent_title) {
|
68 |
|
|
$parent_section .= page_filename($parent_title).'/';
|
69 |
|
|
}
|
70 |
|
|
if($parent_section == '/') { $parent_section = ''; }
|
71 |
|
|
$link = '/'.$parent_section.page_filename($title);
|
72 |
|
|
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($title).'.php';
|
73 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
// Check if a page with same page filename exists
|
77 |
|
|
$database = new database();
|
78 |
|
|
$get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
|
79 |
|
|
if($get_same_page->numRows() > 0) {
|
80 |
42
|
stefan
|
$admin->print_error("database");
|
81 |
|
|
// $admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
82 |
5
|
stefan
|
} elseif(file_exists(WB_PATH.PAGES_DIRECTORY.$link.'.php')) {
|
83 |
42
|
stefan
|
$admin->print_error(WB_PATH.PAGES_DIRECTORY.$link.'.php');
|
84 |
|
|
// $admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
85 |
5
|
stefan
|
} elseif(file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')) {
|
86 |
42
|
stefan
|
$admin->print_error("dir");
|
87 |
|
|
// $admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
|
88 |
4
|
ryan
|
}
|
89 |
|
|
|
90 |
|
|
// Include the ordering class
|
91 |
|
|
require(WB_PATH.'/framework/class.order.php');
|
92 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
93 |
|
|
// First clean order
|
94 |
|
|
$order->clean($parent);
|
95 |
|
|
// Get new order
|
96 |
|
|
$position = $order->get_new($parent);
|
97 |
|
|
|
98 |
|
|
// Work-out if the page parent (if selected) has a seperate template to the default
|
99 |
|
|
$query_parent = $database->query("SELECT template FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent'");
|
100 |
|
|
if($query_parent->numRows() > 0) {
|
101 |
|
|
$fetch_parent = $query_parent->fetchRow();
|
102 |
|
|
$template = $fetch_parent['template'];
|
103 |
|
|
} else {
|
104 |
|
|
$template = '';
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
// Insert page into pages table
|
108 |
|
|
$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()."')";
|
109 |
|
|
$database = new database();
|
110 |
|
|
$database->query($query);
|
111 |
|
|
if($database->is_error()) {
|
112 |
|
|
$admin->print_error($database->get_error());
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// Get the page id
|
116 |
|
|
$page_id = $database->get_one("SELECT LAST_INSERT_ID()");
|
117 |
|
|
|
118 |
|
|
// Work out level
|
119 |
|
|
$level = level_count($page_id);
|
120 |
|
|
// Work out root parent
|
121 |
|
|
$root_parent = root_parent($page_id);
|
122 |
|
|
// Work out page trail
|
123 |
|
|
$page_trail = get_page_trail($page_id);
|
124 |
|
|
|
125 |
|
|
// Update page with new level and link
|
126 |
|
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$link', level = '$level', root_parent = '$root_parent', page_trail = '$page_trail' WHERE page_id = '$page_id'");
|
127 |
|
|
|
128 |
|
|
// Create a new file in the /pages dir
|
129 |
|
|
create_access_file($filename, $page_id, $level);
|
130 |
|
|
|
131 |
|
|
// Get new order for section
|
132 |
|
|
$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
|
133 |
|
|
$position = $order->get_new($parent);
|
134 |
|
|
|
135 |
|
|
// Add new record into the sections table
|
136 |
|
|
$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
|
137 |
|
|
|
138 |
|
|
// Get the section id
|
139 |
|
|
$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
|
140 |
|
|
|
141 |
|
|
// Include the selected modules add file if it exists
|
142 |
|
|
if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
|
143 |
|
|
require(WB_PATH.'/modules/'.$module.'/add.php');
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
// Check if there is a db error, otherwise say successful
|
147 |
|
|
if($database->is_error()) {
|
148 |
|
|
$admin->print_error($database->get_error());
|
149 |
|
|
} else {
|
150 |
|
|
$admin->print_success($MESSAGE['PAGES']['ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
// Print admin footer
|
154 |
|
|
$admin->print_footer();
|
155 |
|
|
|
156 |
5
|
stefan
|
?>
|