Project

General

Profile

1 4 ryan
<?php
2
3
/*
4
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2005, 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
}
31
32
// Get page id
33
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
34
	header("Location: index.php");
35
} else {
36
	$page_id = $_GET['page_id'];
37
}
38
39
// Create new admin object
40
require_once(WB_PATH.'/framework/class.admin.php');
41
$admin = new admin('Pages', 'pages_modify');
42
43
// Check if we are supposed to add or delete a section
44
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id'])) {
45
	// Get more information about this section
46 8 stefan
	$section_id = $_GET['section_id'];
47
	$query_section = $database->query("SELECT module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id'");
48
	if($query_section->numRows() == 0) {
49
		$admin->print_error('Section not found');
50 4 ryan
	}
51 8 stefan
	$section = $query_section->fetchRow();
52
	// Include the modules delete file if it exists
53
	if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
54
		require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
55
	}
56 4 ryan
	$database->query("DELETE FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' LIMIT 1");
57
	if($database->is_error()) {
58
		$admin->print_error($database->get_error());
59
	} else {
60
		require(WB_PATH.'/framework/class.order.php');
61
		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
62
		$order->clean($page_id);
63
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
64
		$admin->print_footer();
65
		exit();
66
	}
67
} elseif(isset($_POST['module']) AND $_POST['module'] != '') {
68
	// Get section info
69
	$module = $_POST['module'];
70
	// Include the ordering class
71
	require(WB_PATH.'/framework/class.order.php');
72
	// Get new order
73
	$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
74
	$position = $order->get_new($page_id);
75
	// Insert module into DB
76
	$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,module,position,block) VALUES ('$page_id','$module','$position','1')");
77
	// Get the section id
78
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
79
	// Include the selected modules add file if it exists
80
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
81
		require(WB_PATH.'/modules/'.$module.'/add.php');
82
	}
83
}
84
85
// Get perms
86
$database = new database();
87
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
88
$results_array = $results->fetchRow();
89
$old_admin_groups = explode(',', $results_array['admin_groups']);
90
$old_admin_users = explode(',', $results_array['admin_users']);
91
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
92
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
93
}
94
95
// Get page details
96
$database = new database();
97
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
98
$results = $database->query($query);
99
if($database->is_error()) {
100
	$admin->print_header();
101
	$admin->print_error($database->get_error());
102
}
103
if($results->numRows() == 0) {
104
	$admin->print_header();
105
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
106
}
107
$results_array = $results->fetchRow();
108
109
// Set module permissions
110
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
111 8 stefan
112
// Unset block var
113
unset($block);
114
// Include template info file (if it exists)
115
if($results_array['template'] != '') {
116
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
117
} else {
118
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
119
}
120
if(file_exists($template_location)) {
121
	require($template_location);
122
}
123
// Check if $menu is set
124
if(!isset($block[1]) OR $block[1] == '') {
125
	// Make our own menu list
126
	$block[1] = $TEXT['MAIN'];
127
}
128
129
?>
130
<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%" height="50" style="margin-bottom: 10px;">
131
<tr style="background-color: #F0F0F0;">
132
	<td valign="middle" align="left">
133
		<h2><?php echo $HEADING['MANAGE_SECTIONS']; ?></h2>
134
	</td>
135
	<td align="right">
136
		<?php echo $TEXT['CURRENT_PAGE']; ?>:
137 116 stefan
		<b><?php echo ($results_array['page_title']); ?></b>
138 8 stefan
		-
139
		<a href="<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>"><?php echo $HEADING['MODIFY_PAGE']; ?></a>
140
		-
141
		<a href="<?php echo ADMIN_URL; ?>/pages/settings.php?page_id=<?php echo $page_id; ?>"><?php echo $TEXT['CHANGE_SETTINGS']; ?></a>
142
	</td>
143
</tr>
144
</table>
145
146
<?php
147 4 ryan
$query_sections = $database->query("SELECT section_id,module,position,block FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
148 8 stefan
if($query_sections->numRows() > 0) {
149
?>
150
<form name="section_properties" action="<?php echo ADMIN_URL; ?>/pages/sections_save.php?page_id=<?php echo $page_id; ?>" method="post">
151
152
<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%">
153
<tr>
154
	<td><?php echo $TEXT['TYPE']; ?>:</td>
155
	<?php if(SECTION_BLOCKS) { ?>
156
	<td style="display: {DISPLAY_BLOCK}"><?php echo $TEXT['BLOCK']; ?>:</td>
157
	<?php } ?>
158
	<td colspan="3" width="60"><?php echo $TEXT['ACTIONS']; ?>:</td>
159
</tr>
160 4 ryan
<?php
161
	$num_sections = $query_sections->numRows();
162
	while($section = $query_sections->fetchRow()) {
163 8 stefan
		// Get the modules real name
164 4 ryan
		$module_path = WB_PATH.'/modules/'.$section['module'].'/info.php';
165
		if(file_exists($module_path)) {
166
			require($module_path);
167 169 ryan
			if(!isset($module_function)) { $module_function = 'unknown'; }
168
			if(!is_numeric(array_search($section['module'], $module_permissions)) AND $module_function == 'page') {
169 8 stefan
			?>
170
			<tr>
171
				<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>
172
				<?php if(SECTION_BLOCKS) { ?>
173
				<td>
174
					<select name="block<?php echo $section['section_id']; ?>" style="width: 150px;">
175
						<?php
176
						foreach($block AS $number => $name) {
177
							?>
178
							<option value="<?php echo $number; ?>"<?php if($number == $section['block']) { echo ' selected'; } ?>><?php echo $name; ?></option>
179
							<?php
180
						}
181
						?>
182
					</select>
183
				</td>
184
				<?php } ?>
185
				<td width="20">
186
					<?php if($section['position'] != 1) { ?>
187
					<a href="<?php echo ADMIN_URL; ?>/pages/move_up.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section['section_id']; ?>">
188
						<img src="<?php echo ADMIN_URL; ?>/images/up_16.png" alt="^" border="0" />
189
					</a>
190
					<?php } ?>
191
				</td>
192
				<td width="20">
193
					<?php if($section['position'] != $num_sections) { ?>
194
					<a href="<?php echo ADMIN_URL; ?>/pages/move_down.php?page_id=<?php echo $page_id; ?>&section_id=<?php echo $section['section_id']; ?>">
195
						<img src="<?php echo ADMIN_URL; ?>/images/down_16.png" alt="v" border="0" />
196
					</a>
197
					<?php } ?>
198
				</td>
199
				<td width="20">
200
					<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']; ?>');">
201
						<img src="<?php echo ADMIN_URL; ?>/images/delete_16.png" alt="Del" border="0" />
202
					</a>
203
				</td>
204
			</tr>
205
			<?php
206 4 ryan
			}
207 169 ryan
			if(isset($module_function)) { unset($module_function); } // Unset module type
208 4 ryan
		}
209 8 stefan
	}
210
	?>
211
	<tr>
212
		<td>&nbsp;</td>
213
		<?php if(SECTION_BLOCKS) { ?>
214
		<td><input type="submit" name="save" value="<?php echo $TEXT['SAVE']; ?>" style="width: 150px;" /></td>
215
		<?php } ?>
216
		<td colspan="3" width="60">&nbsp;</td>
217
	</tr>
218
	</table>
219
220
</form>
221
222 4 ryan
<?php
223 8 stefan
}
224
225
// Work-out if we should show the "Add Section" form
226 4 ryan
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
227 8 stefan
if($query_sections->numRows() == 0) {
228
	?>
229
	<h2><?php echo $TEXT['ADD_SECTION']; ?></h2>
230
231
	<form name="add" action="<?php echo ADMIN_URL; ?>/pages/sections.php?page_id=<?php echo $page_id; ?>" method="post">
232
233
	<table cellpadding="5" cellspacing="0" border="0" align="center" width="100%">
234
	<tr>
235
		<td>
236
			<select name="module" style="width: 100%;">
237
			<?php
238 4 ryan
			// Insert module list
239 169 ryan
			$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND function = 'page' AND directory != 'menu_link'");
240
			if($result->numRows() > 0) {
241
				while($module = $result->fetchRow()) {
242
					// Check if user is allowed to use this module
243
					if(!is_numeric(array_search($module['directory'], $module_permissions))) {
244
						?>
245
						<option value="<?php echo $module['directory']; ?>"<?php if($module['directory'] == 'wysiwyg') { echo 'selected'; } ?>><?php echo $module['name']; ?></option>
246
						<?php
247 4 ryan
					}
248
				}
249 8 stefan
			}
250
			?>
251
			</select>
252
		</td>
253
		<td width="100">
254
			<input type="submit" name="submit" value="<?php echo $TEXT['ADD']; ?>" style="width: 100px" />
255
		</td>
256
	</tr>
257
	</table>
258
259
	</form>
260
	<?php
261
}
262 4 ryan
263
// Print admin footer
264
$admin->print_footer();
265
266 8 stefan
?>