Project

General

Profile

1
<?php
2

    
3
// $Id: sections_save.php 10 2005-09-04 08:59:31Z ryan $
4
/*
5

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

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

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

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

    
23
*/
24

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

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

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

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

    
44
// Get perms
45
$database = new database();
46
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
47
$results_array = $results->fetchRow();
48
$old_admin_groups = explode(',', $results_array['admin_groups']);
49
$old_admin_users = explode(',', $results_array['admin_users']);
50
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
51
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
52
}
53

    
54
// Get page details
55
$database = new database();
56
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
57
$results = $database->query($query);
58
if($database->is_error()) {
59
	$admin->print_header();
60
	$admin->print_error($database->get_error());
61
}
62
if($results->numRows() == 0) {
63
	$admin->print_header();
64
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
65
}
66
$results_array = $results->fetchRow();
67

    
68
// Set module permissions
69
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
70

    
71
// Loop through sections
72
$query_sections = $database->query("SELECT section_id,module,position FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
73
if($query_sections->numRows() > 0) {
74
	$num_sections = $query_sections->numRows();
75
	while($section = $query_sections->fetchRow()) {
76
		// Get the modules real name
77
		$module_path = WB_PATH.'/modules/'.$section['module'].'/info.php';
78
		if(file_exists($module_path)) {
79
			require($module_path);
80
			if(!isset($module_type)) { $module_type = 'unknown'; }
81
			if(!is_numeric(array_search($section['module'], $module_permissions)) AND $module_type == 'page') {
82
				// Update the section record with properties
83
				$section_id = $section['section_id'];
84
				$sql = '';
85
				if(isset($_POST['block'.$section_id]) AND $_POST['block'.$section_id] != '') {
86
					$sql = "block = '".addslashes($_POST['block'.$section_id])."'";
87
					$query = "UPDATE ".TABLE_PREFIX."sections SET $sql WHERE section_id = '$section_id' LIMIT 1";
88
					if($sql != '') {
89
						$database->query($query);
90
					}
91
				}
92
			}
93
			if(isset($module_type)) { unset($module_type); } // Unset module type
94
		}
95
	}
96
}
97

    
98
// Check for error or print success message
99
if($database->is_error()) {
100
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
101
} else {
102
	$admin->print_success($MESSAGE['PAGES']['SECTIONS_PROPERTIES_SAVED'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
103
}
104

    
105
// Print admin footer
106
$admin->print_footer();
107

    
108
?>
(15-15/20)