Project

General

Profile

1
<?php
2

    
3
// $Id: sections.php 452 2007-04-30 12:40:01Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2007, 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
// Include config file
27
require('../../config.php');
28

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

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

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

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

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

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

    
113
// Set module permissions
114
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
115

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

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

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

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

    
219
</form>
220

    
221
<?php
222
}
223

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

    
262
// Print admin footer
263
$admin->print_footer();
264

    
265
?>
(13-13/19)