Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: sections_save.php 1384 2011-01-16 08:39:00Z Luisehahne $
14
 * @filesource		$HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/admin/pages/sections.php $
15
 * @lastmodified    $Date: 2011-01-10 13:14:10 +0100 (Mo, 10. Jan 2011) $
16
 *
17
 */
18

    
19
// Include config file
20
require('../../config.php');
21

    
22
// Make sure people are allowed to access this page
23
if(MANAGE_SECTIONS != 'enabled') {
24
	header('Location: '.ADMIN_URL.'/pages/index.php');
25
	exit(0);
26
}
27

    
28
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
29

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

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

    
42
if (!$admin->checkFTAN())
43
{
44
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
45
	exit();
46
}
47

    
48
// Get perms
49
// $database = new database();
50
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
51
$results_array = $results->fetchRow();
52
$old_admin_groups = explode(',', $results_array['admin_groups']);
53
$old_admin_users = explode(',', $results_array['admin_users']);
54
$in_old_group = FALSE;
55
foreach($admin->get_groups_id() as $cur_gid){
56
    if (in_array($cur_gid, $old_admin_groups)) {
57
        $in_old_group = TRUE;
58
    }
59
}
60
if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
61
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
62
}
63

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

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

    
81
// Loop through sections
82
$query_sections = $database->query("SELECT section_id,module,position FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' ORDER BY position ASC");
83
if($query_sections->numRows() > 0) {
84
	$num_sections = $query_sections->numRows();
85
	while($section = $query_sections->fetchRow()) {
86
		if(!is_numeric(array_search($section['module'], $module_permissions))) {
87
			// Update the section record with properties
88
			$section_id = $section['section_id'];
89
			$sql = ''; $publ_start = 0; $publ_end = 0;
90
			$dst = date("I")?" DST":""; // daylight saving time?
91
			if(isset($_POST['block'.$section_id]) && $_POST['block'.$section_id] != '') {
92
				$sql = "block = '".$admin->add_slashes($_POST['block'.$section_id])."'";
93
			}
94
			// update publ_start and publ_end, trying to make use of the strtotime()-features like "next week", "+1 month", ...
95
			if(isset($_POST['start_date'.$section_id]) && isset($_POST['end_date'.$section_id])) {
96
				if(trim($_POST['start_date'.$section_id]) == '0' || trim($_POST['start_date'.$section_id]) == '') {
97
					$publ_start = 0;
98
				} else {
99
					$publ_start = jscalendar_to_timestamp($_POST['start_date'.$section_id]);
100
				}
101
				if(trim($_POST['end_date'.$section_id]) == '0' || trim($_POST['end_date'.$section_id]) == '') {
102
					$publ_end = 0;
103
				} else {
104
					$publ_end = jscalendar_to_timestamp($_POST['end_date'.$section_id], $publ_start);
105
				}
106
				if($sql != '')
107
					$sql .= ",";
108
				$sql .= " publ_start = '".$admin->add_slashes($publ_start)."'";
109
				$sql .= ", publ_end = '".$admin->add_slashes($publ_end)."'";
110
			}
111
			$query = "UPDATE ".TABLE_PREFIX."sections SET $sql WHERE section_id = '$section_id' LIMIT 1";
112
			if($sql != '') {
113
				$database->query($query);
114
			}
115
		}
116
	}
117
}
118
// Check for error or print success message
119
if($database->is_error()) {
120
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
121
} else {
122
	$admin->print_success($MESSAGE['PAGES']['SECTIONS_PROPERTIES_SAVED'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
123
}
124

    
125
// Print admin footer
126
$admin->print_footer();
(18-18/21)