summaryrefslogtreecommitdiff
path: root/block_edit.php
blob: 44495568cf4d134777c586f2fc54db636a0ef9c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
namespace Fisharebest\Webtrees;

/**
 * Defined in session.php
 *
 * @global Tree $WT_TREE
 */
global $WT_TREE;

use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Module\CkeditorModule;

define('WT_SCRIPT_NAME', 'block_edit.php');
require './includes/session.php';

$block_id = Filter::getInteger('block_id');
$block    = Database::prepare(
	"SELECT SQL_CACHE * FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOneRow();

// Check access.  (1) the block must exist and be enabled, (2) gedcom blocks require
// managers, (3) user blocks require the user or an admin
$blocks = Module::getActiveBlocks($WT_TREE);
if (
	!$block ||
	!array_key_exists($block->module_name, $blocks) ||
	$block->gedcom_id && !Auth::isManager(Tree::findById($block->gedcom_id)) ||
	$block->user_id && $block->user_id != Auth::id() && !Auth::isAdmin()
) {
	header('Location: ' . WT_BASE_URL);

	return;
}

$block = $blocks[$block->module_name];

if (Filter::post('save')) {
	$ctype = Filter::post('ctype', 'user', 'gedcom');
	header('Location: ' . WT_BASE_URL . 'index.php?ctype=' . $ctype . '&ged=' . $WT_TREE->getNameUrl());
	$block->configureBlock($block_id);

	return;
}

$ctype = FIlter::get('ctype', 'user', 'gedcom');

$controller = new PageController;
$controller
	->setPageTitle(I18N::translate('Configure') . ' — ' . $block->getTitle())
	->pageHeader();

if (Module::getModuleByName('ckeditor')) {
	CkeditorModule::enableEditor($controller);
}

?>
<h2><?php echo $controller->getPageTitle(); ?></h2>

<form name="block" method="post" action="?block_id=<?php echo $block_id; ?>">
	<input type="hidden" name="save" value="1">
	<input type="hidden" name="ged" value="<?php echo $WT_TREE->getNameHtml(); ?>">
	<input type="hidden" name="ctype" value="<?php echo $ctype; ?>">
	<?php echo Filter::getCsrf(); ?>
	<table class="facts_table">
		<thead>
			<tr>
				<td class="descriptionbox">
					<?php echo I18N::translate('Description'); ?>
				</td>
				<td class="optionbox">
					<?php echo $block->getDescription(); ?>
				</td>
			</tr>
		</thead>
		<tbody>
			<?php echo $block->configureBlock($block_id); ?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="2" class="topbottombar">
					<input type="submit" value="<?php echo I18N::translate('save'); ?>">
				</td>
			</tr>
		</tfoot>
	</table>
</form>