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-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: add.php 1358 2010-12-28 08:44:12Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/add.php $
15
 * @lastmodified    $Date: 2010-12-28 09:44:12 +0100 (Tue, 28 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
if (!$admin->checkFTAN())
25
{
26
	$admin->print_error($MESSAGE['PAGES_NOT_SAVED'],'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 = $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
// Work-out if we should check for existing page_code
43
$sql = 'DESCRIBE `'.TABLE_PREFIX.'pages` `page_code`';
44
$field_sql = $database->query($sql);
45
$field_set = $field_sql->numRows();
46

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

    
51
if ($parent!=0) {
52
	if (!$admin->get_page_permission($parent,'admin'))
53
    {
54
        $admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
55
    }
56

    
57
} elseif (!$admin->get_permission('pages_add_l0','system'))
58
{
59
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
60
}	
61

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
239
?>
(1-1/21)