Project

General

Profile

1
<?php
2

    
3
/*
4

    
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2006, Ryan Djurovich
7

    
8
 Website Baker is free software; you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation; either version 2 of the License, or
11
 (at your option) any later version.
12

    
13
 Website Baker is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 GNU General Public License for more details.
17

    
18
 You should have received a copy of the GNU General Public License
19
 along with Website Baker; if not, write to the Free Software
20
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21

    
22
*/
23

    
24
// Include config file
25
require('../../config.php');
26

    
27
// Make sure people are allowed to access this page
28
if(MANAGE_SECTIONS != 'enabled') {
29
	header('Location: '.ADMIN_URL.'/pages/index.php');
30
	exit(0);
31
}
32

    
33
// Get page id
34
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
35
	header("Location: index.php");
36
	exit(0);
37
} else {
38
	$page_id = $_GET['page_id'];
39
}
40

    
41
// Create new admin object
42
require_once(WB_PATH.'/framework/class.admin.php');
43
$admin = new admin('Pages', 'pages_modify');
44

    
45
// Check if we are supposed to add or delete a section
46
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
47
	// Get more information about this section
48
	$section_id = $_GET['section_id'];
49
	$query_section = $database->query("SELECT module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id'");
50
	if($query_section->numRows() == 0) {
51
		$admin->print_error('Section not found');
52
	}
53
	$section = $query_section->fetchRow();
54
	// Include the modules delete file if it exists
55
	if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
56
		require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
57
	}
58
	$database->query("DELETE FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' LIMIT 1");
59
	if($database->is_error()) {
60
		$admin->print_error($database->get_error());
61
	} else {
62
		require(WB_PATH.'/framework/class.order.php');
63
		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
64
		$order->clean($page_id);
65
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
66
		$admin->print_footer();
67
		exit();
68
	}
69
} elseif(isset($_POST['module']) AND $_POST['module'] != '') {
70
	// Get section info
71
	$module = $_POST['module'];
72
	// Include the ordering class
73
	require(WB_PATH.'/framework/class.order.php');
74
	// Get new order
75
	$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
76
	$position = $order->get_new($page_id);	
77
	// Insert module into DB
78
	$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,module,position,block) VALUES ('$page_id','$module','$position','1')");
79
	// Get the section id
80
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");	
81
	// Include the selected modules add file if it exists
82
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
83
		require(WB_PATH.'/modules/'.$module.'/add.php');
84
	}	
85
}
86

    
87
// Get perms
88
$database = new database();
89
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
90
$results_array = $results->fetchRow();
91
$old_admin_groups = explode(',', $results_array['admin_groups']);
92
$old_admin_users = explode(',', $results_array['admin_users']);
93
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
94
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
95
}
96

    
97
// Get page details
98
$database = new database();
99
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
100
$results = $database->query($query);
101
if($database->is_error()) {
102
	$admin->print_header();
103
	$admin->print_error($database->get_error());
104
}
105
if($results->numRows() == 0) {
106
	$admin->print_header();
107
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
108
}
109
$results_array = $results->fetchRow();
110

    
111
// Set module permissions
112
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
113

    
114
// Unset block var
115
unset($block);
116
// Include template info file (if it exists)
117
if($results_array['template'] != '') {
118
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
119
} else {
120
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
121
}
122
if(file_exists($template_location)) {
123
	require($template_location);
124
}
125
// Check if $menu is set
126
if(!isset($block[1]) OR $block[1] == '') {
127
	// Make our own menu list
128
	$block[1] = $TEXT['MAIN'];
129
}
130

    
131
?>
132
<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%" height="50" style="margin-bottom: 10px;">
133
<tr style="background-color: #F0F0F0;">
134
	<td valign="middle" align="left">
135
		<h2><?php echo $HEADING['MANAGE_SECTIONS']; ?></h2>
136
	</td>
137
	<td align="right">
138
		<?php echo $TEXT['CURRENT_PAGE']; ?>: 
139
		<b><?php echo ($results_array['page_title']); ?></b>
140
		-
141
		<a href="<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>"><?php echo $HEADING['MODIFY_PAGE']; ?></a>
142
		-
143
		<a href="<?php echo ADMIN_URL; ?>/pages/settings.php?page_id=<?php echo $page_id; ?>"><?php echo $TEXT['CHANGE_SETTINGS']; ?></a>
144
	</td>
145
</tr>
146
</table>
147

    
148
<?php
149
$query_sections = $database->query("SELECT section_id,module,position,block FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
150
if($query_sections->numRows() > 0) {
151
?>
152
<form name="section_properties" action="<?php echo ADMIN_URL; ?>/pages/sections_save.php?page_id=<?php echo $page_id; ?>" method="post">
153

    
154
<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%">
155
<tr>
156
	<td><?php echo $TEXT['TYPE']; ?>:</td>
157
	<?php if(SECTION_BLOCKS) { ?>
158
	<td style="display: {DISPLAY_BLOCK}"><?php echo $TEXT['BLOCK']; ?>:</td>
159
	<?php } ?>
160
	<td colspan="3" width="60"><?php echo $TEXT['ACTIONS']; ?>:</td>
161
</tr>
162
<?php
163
	$num_sections = $query_sections->numRows();
164
	while($section = $query_sections->fetchRow()) {
165
		// Get the modules real name
166
		$module_name=$database->get_one("SELECT name FROM ".TABLE_PREFIX."addons WHERE directory='".$section['module']."'");
167
		if(!is_numeric(array_search($section['module'], $module_permissions))) {
168
			?>
169
			<tr>
170
				<td style="width: 250px;"><a href="<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>#<?php echo $section['section_id']; ?>"><?php echo $module_name; ?></a></td>
171
				<?php if(SECTION_BLOCKS) { ?>
172
				<td>
173
					<select name="block<?php echo $section['section_id']; ?>" style="width: 150px;">
174
						<?php
175
						foreach($block AS $number => $name) {
176
							?>
177
							<option value="<?php echo $number; ?>"<?php if($number == $section['block']) { echo ' selected'; } ?>><?php echo $name; ?></option>
178
							<?php
179
						}
180
						?>
181
					</select>
182
				</td>
183
				<?php } ?>
184
				<td width="20">
185
					<?php if($section['position'] != 1) { ?>
186
					<a href="<?php echo ADMIN_URL; ?>/pages/move_up.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section['section_id']; ?>">
187
						<img src="<?php echo ADMIN_URL; ?>/images/up_16.png" alt="^" border="0" />
188
					</a>
189
					<?php } ?>
190
				</td>
191
				<td width="20">
192
					<?php if($section['position'] != $num_sections) { ?>
193
					<a href="<?php echo ADMIN_URL; ?>/pages/move_down.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section['section_id']; ?>">
194
						<img src="<?php echo ADMIN_URL; ?>/images/down_16.png" alt="v" border="0" />
195
					</a>
196
					<?php } ?>
197
				</td>
198
				<td width="20">
199
					<a href="javascript: confirm_link('<?php echo $TEXT['ARE_YOU_SURE']; ?>', '<?php echo ADMIN_URL; ?>/pages/sections.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section['section_id']; ?>');">
200
						<img src="<?php echo ADMIN_URL; ?>/images/delete_16.png" alt="Del" border="0" />
201
					</a>
202
				</td>
203
			</tr>
204
			<?php
205
			}
206
	}
207
	?>
208
	<tr>
209
		<td>&nbsp;</td>
210
		<?php if(SECTION_BLOCKS) { ?>
211
		<td><input type="submit" name="save" value="<?php echo $TEXT['SAVE']; ?>" style="width: 150px;" /></td>
212
		<?php } ?>
213
		<td colspan="3" width="60">&nbsp;</td>
214
	</tr>
215
	</table>
216

    
217
</form>
218

    
219
<?php
220
}
221

    
222
// Work-out if we should show the "Add Section" form
223
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
224
if($query_sections->numRows() == 0) {
225
	?>
226
	<h2><?php echo $TEXT['ADD_SECTION']; ?></h2>
227
	
228
	<form name="add" action="<?php echo ADMIN_URL; ?>/pages/sections.php?page_id=<?php echo $page_id; ?>" method="post">
229
	
230
	<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%">
231
	<tr>
232
		<td>
233
			<select name="module" style="width: 100%;">
234
			<?php
235
			// Insert module list
236
			$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'page' AND directory != 'menu_link'");
237
			if($result->numRows() > 0) {
238
				while($module = $result->fetchRow()) {
239
					// Check if user is allowed to use this module
240
					if(!is_numeric(array_search($module['directory'], $module_permissions))) {
241
						?>
242
						<option value="<?php echo $module['directory']; ?>"<?php if($module['directory'] == 'wysiwyg') { echo 'selected'; } ?>><?php echo $module['name']; ?></option>
243
						<?php
244
					}
245
				}
246
			}
247
			?>
248
			</select>
249
		</td>
250
		<td width="100">
251
			<input type="submit" name="submit" value="<?php echo $TEXT['ADD']; ?>" style="width: 100px" />
252
		</td>
253
	</tr>
254
	</table>
255
	
256
	</form>
257
	<?php
258
}
259

    
260
// Print admin footer
261
$admin->print_footer();
262

    
263
?>
(13-13/19)