Project

General

Profile

1 238 stefan
<?php
2 1384 Luisehahne
/**
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$
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 238 stefan
19 4 ryan
// Include config file
20 238 stefan
require('../../config.php');
21
22 4 ryan
// Make sure people are allowed to access this page
23 238 stefan
if(MANAGE_SECTIONS != 'enabled') {
24
	header('Location: '.ADMIN_URL.'/pages/index.php');
25 286 stefan
	exit(0);
26 238 stefan
}
27
28 643 thorn
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
29
30 4 ryan
// Get page id
31 1384 Luisehahne
if(!isset($_GET['page_id']) || !is_numeric($_GET['page_id'])) {
32 238 stefan
	header("Location: index.php");
33 286 stefan
	exit(0);
34 238 stefan
} else {
35
	$page_id = $_GET['page_id'];
36
}
37
38 4 ryan
// Create new admin object
39 238 stefan
require_once(WB_PATH.'/framework/class.admin.php');
40
$admin = new admin('Pages', 'pages_modify');
41 1384 Luisehahne
42 1357 FrankH
if (!$admin->checkFTAN())
43
{
44 1384 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],'index.php');
45 1357 FrankH
	exit();
46
}
47
48 4 ryan
// Get perms
49 1358 Luisehahne
// $database = new database();
50 238 stefan
$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 546 doc
$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 1384 Luisehahne
if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
61 238 stefan
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
62
}
63
64 4 ryan
// Get page details
65 1384 Luisehahne
// $database = new database();
66 238 stefan
$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 4 ryan
// Set module permissions
79 238 stefan
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
80
81 4 ryan
// Loop through sections
82 238 stefan
$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 347 stefan
		if(!is_numeric(array_search($section['module'], $module_permissions))) {
87
			// Update the section record with properties
88
			$section_id = $section['section_id'];
89 552 thorn
			$sql = ''; $publ_start = 0; $publ_end = 0;
90
			$dst = date("I")?" DST":""; // daylight saving time?
91 1384 Luisehahne
			if(isset($_POST['block'.$section_id]) && $_POST['block'.$section_id] != '') {
92 347 stefan
				$sql = "block = '".$admin->add_slashes($_POST['block'.$section_id])."'";
93 552 thorn
			}
94
			// update publ_start and publ_end, trying to make use of the strtotime()-features like "next week", "+1 month", ...
95 1384 Luisehahne
			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 552 thorn
					$publ_start = 0;
98
				} else {
99 643 thorn
					$publ_start = jscalendar_to_timestamp($_POST['start_date'.$section_id]);
100 238 stefan
				}
101 1384 Luisehahne
				if(trim($_POST['end_date'.$section_id]) == '0' || trim($_POST['end_date'.$section_id]) == '') {
102 552 thorn
					$publ_end = 0;
103
				} else {
104 643 thorn
					$publ_end = jscalendar_to_timestamp($_POST['end_date'.$section_id], $publ_start);
105 552 thorn
				}
106
				if($sql != '')
107
					$sql .= ",";
108 656 thorn
				$sql .= " publ_start = '".$admin->add_slashes($publ_start)."'";
109
				$sql .= ", publ_end = '".$admin->add_slashes($publ_end)."'";
110 238 stefan
			}
111 552 thorn
			$query = "UPDATE ".TABLE_PREFIX."sections SET $sql WHERE section_id = '$section_id' LIMIT 1";
112
			if($sql != '') {
113
				$database->query($query);
114
			}
115 238 stefan
		}
116
	}
117
}
118
// Check for error or print success message
119 4 ryan
if($database->is_error()) {
120
	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
121
} else {
122 1358 Luisehahne
	$admin->print_success($MESSAGE['PAGES']['SECTIONS_PROPERTIES_SAVED'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
123 4 ryan
}
124 238 stefan
125 4 ryan
// Print admin footer
126 238 stefan
$admin->print_footer();