1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees; 17 18use Fisharebest\Webtrees\Controller\PageController; 19use Fisharebest\Webtrees\Functions\FunctionsEdit; 20use Fisharebest\Webtrees\Module\ModuleConfigInterface; 21 22define('WT_SCRIPT_NAME', 'admin_module_sidebar.php'); 23require 'includes/session.php'; 24 25$controller = new PageController; 26$controller 27 ->restrictAccess(Auth::isAdmin()) 28 ->setPageTitle(I18N::translate('Sidebars')); 29 30$action = Filter::post('action'); 31$modules = Module::getAllModulesByComponent('sidebar'); 32 33if ($action === 'update_mods' && Filter::checkCsrf()) { 34 foreach ($modules as $module) { 35 foreach (Tree::getAll() as $tree) { 36 $access_level = Filter::post('access-' . $module->getName() . '-' . $tree->getTreeId(), WT_REGEX_INTEGER, $module->defaultAccessLevel()); 37 Database::prepare( 38 "REPLACE INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)" 39 )->execute(array($module->getName(), $tree->getTreeId(), $access_level)); 40 } 41 $order = Filter::post('order-' . $module->getName()); 42 Database::prepare( 43 "UPDATE `##module` SET sidebar_order = ? WHERE module_name = ?" 44 )->execute(array($order, $module->getName())); 45 } 46 47 header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME); 48 49 return; 50} 51 52$controller 53 ->addInlineJavascript(' 54 jQuery("#module_table").sortable({ 55 items: ".sortme", 56 forceHelperSize: true, 57 forcePlaceholderSize: true, 58 opacity: 0.7, 59 cursor: "move", 60 axis: "y", 61 update: function(event, ui) { 62 jQuery("input", jQuery(this)).each( 63 function (index, element) { 64 element.value = index + 1; 65 } 66 ); 67 } 68 }); 69 ') 70 ->pageHeader(); 71 72?> 73<ol class="breadcrumb small"> 74 <li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li> 75 <li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li> 76 <li class="active"><?php echo $controller->getPageTitle(); ?></li> 77</ol> 78 79<h1><?php echo $controller->getPageTitle(); ?></h1> 80 81<form method="post"> 82 <input type="hidden" name="action" value="update_mods"> 83 <?php echo Filter::getCsrf(); ?> 84 <table id="module_table" class="table table-bordered"> 85 <thead> 86 <tr> 87 <th class="col-xs-1"><?php echo I18N::translate('Sidebar'); ?></th> 88 <th class="col-xs-5"><?php echo I18N::translate('Description'); ?></th> 89 <th class="col-xs-1"><?php echo I18N::translate('Order'); ?></th> 90 <th class="col-xs-5"><?php echo I18N::translate('Access level'); ?></th> 91 </tr> 92 </thead> 93 <tbody> 94 <?php $order = 0; ?> 95 <?php foreach ($modules as $module): ?> 96 <?php $order++; ?> 97 <tr class="sortme"> 98 <td class="col-xs-1"> 99 <?php if ($module instanceof ModuleConfigInterface): ?> 100 <a href="<?php echo $module->getConfigLink(); ?>"><?php echo $module->getTitle(); ?> <i class="fa fa-cogs"></i></a> 101 <?php else: ?> 102 <?php echo $module->getTitle(); ?> 103 <?php endif; ?> 104 </td> 105 <td class="col-xs-5"><?php echo $module->getDescription(); ?></td> 106 <td class="col-xs-1"><input type="text" size="3" value="<?php echo $order; ?>" name="order-<?php echo $module->getName(); ?>"></td> 107 <td class="col-xs-5"> 108 <table class="table"> 109 <tbody> 110 <?php foreach (Tree::getAll() as $tree): ?> 111 <tr> 112 <td> 113 <?php echo $tree->getTitleHtml(); ?> 114 </td> 115 <td> 116 <?php echo FunctionsEdit::editFieldAccessLevel('access-' . $module->getName() . '-' . $tree->getTreeId(), $module->getAccessLevel($tree, 'sidebar')); ?> 117 </td> 118 </tr> 119 <?php endforeach; ?> 120 </tbody> 121 </table> 122 </td> 123 </tr> 124 <?php endforeach; ?> 125 </tbody> 126 </table> 127 <button class="btn btn-primary" type="submit"> 128 <i class="fa fa-check"></i> 129 <?php echo I18N::translate('save'); ?> 130 </button> 131</form> 132