Project

General

Profile

1
<?php
2

    
3
// $Id: sections_save.php 546 2008-01-17 18:10:50Z doc $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, 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
// Get perms
48
$database = new database();
49
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
50
$results_array = $results->fetchRow();
51
$old_admin_groups = explode(',', $results_array['admin_groups']);
52
$old_admin_users = explode(',', $results_array['admin_users']);
53
$in_old_group = FALSE;
54
foreach($admin->get_groups_id() as $cur_gid){
55
    if (in_array($cur_gid, $old_admin_groups)) {
56
        $in_old_group = TRUE;
57
    }
58
}
59
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
60
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
61
}
62

    
63
// Get page details
64
$database = new database();
65
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
66
$results = $database->query($query);
67
if($database->is_error()) {
68
	$admin->print_header();
69
	$admin->print_error($database->get_error());
70
}
71
if($results->numRows() == 0) {
72
	$admin->print_header();
73
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
74
}
75
$results_array = $results->fetchRow();
76

    
77
// Set module permissions
78
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
79

    
80
// Loop through sections
81
$query_sections = $database->query("SELECT section_id,module,position FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
82
if($query_sections->numRows() > 0) {
83
	$num_sections = $query_sections->numRows();
84
	while($section = $query_sections->fetchRow()) {
85
		if(!is_numeric(array_search($section['module'], $module_permissions))) {
86
			// Update the section record with properties
87
			$section_id = $section['section_id'];
88
			$sql = '';
89
			if(isset($_POST['block'.$section_id]) AND $_POST['block'.$section_id] != '') {
90
				$sql = "block = '".$admin->add_slashes($_POST['block'.$section_id])."'";
91
				$query = "UPDATE ".TABLE_PREFIX."sections SET $sql WHERE section_id = '$section_id' LIMIT 1";
92
				if($sql != '') {
93
					$database->query($query);
94
				}
95
			}
96
		}
97
	}
98
}
99
// Check for error or print success message
100
if($database->is_error()) {
101
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
102
} else {
103
	$admin->print_success($MESSAGE['PAGES']['SECTIONS_PROPERTIES_SAVED'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
104
}
105

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

    
109
?>
(14-14/19)