. */ namespace Fisharebest\Webtrees; /** * Defined in session.php * * @global Tree $WT_TREE */ global $WT_TREE; use Fisharebest\Webtrees\Controller\PageController; use Fisharebest\Webtrees\Functions\FunctionsDb; define('WT_SCRIPT_NAME', 'index_edit.php'); require './includes/session.php'; $controller = new PageController; // Only one of $user_id and $gedcom_id should be set $user_id = Filter::get('user_id', WT_REGEX_INTEGER, Filter::post('user_id', WT_REGEX_INTEGER)); $gedcom_id = Filter::get('gedcom_id', WT_REGEX_INTEGER, Filter::post('gedcom_id', WT_REGEX_INTEGER)); if ($user_id) { $gedcom_id = null; if ($user_id < 0) { $controller->setPageTitle(I18N::translate('Set the default blocks for new users')); $can_reset = false; } else { $controller->setPageTitle(I18N::translate('Change the “My page” blocks')); $can_reset = true; } } else { if ($gedcom_id < 0) { $controller->setPageTitle(I18N::translate('Set the default blocks for new family trees')); $can_reset = false; } else { $controller->setPageTitle(I18N::translate('Change the “Home page” blocks')); $can_reset = true; } } // Only an admin can edit the "default" page // Only managers can edit the "home page" // Only a user or an admin can edit a user’s "my page" if ( $gedcom_id < 0 && !Auth::isAdmin() || $gedcom_id > 0 && !Auth::isManager(Tree::findById($gedcom_id)) || $user_id && Auth::id() != $user_id && !Auth::isAdmin() ) { header('Location: ' . WT_BASE_URL); return; } $action = Filter::get('action'); if ($can_reset && Filter::post('default') === '1') { if ($user_id) { $defaults = FunctionsDb::getUserBlocks(-1); } else { $defaults = FunctionsDb::getTreeBlocks(-1); } $main = $defaults['main']; $right = $defaults['side']; } else { if (isset($_REQUEST['main'])) { $main = $_REQUEST['main']; } else { $main = array(); } if (isset($_REQUEST['right'])) { $right = $_REQUEST['right']; } else { $right = array(); } } // Define all the icons we're going to use $IconUarrow = 'icon-uarrow'; $IconDarrow = 'icon-darrow'; if (I18N::direction() === 'ltr') { $IconRarrow = 'icon-rarrow'; $IconLarrow = 'icon-larrow'; $IconRDarrow = 'icon-rdarrow'; $IconLDarrow = 'icon-ldarrow'; } else { $IconRarrow = 'icon-larrow'; $IconLarrow = 'icon-rarrow'; $IconRDarrow = 'icon-ldarrow'; $IconLDarrow = 'icon-rdarrow'; } $all_blocks = array(); foreach (Module::getActiveBlocks($WT_TREE) as $name => $block) { if ($user_id && $block->isUserBlock() || $gedcom_id && $block->isGedcomBlock()) { $all_blocks[$name] = $block; } } if ($user_id) { $blocks = FunctionsDb::getUserBlocks($user_id); } else { $blocks = FunctionsDb::getTreeBlocks($gedcom_id); } if ($action === 'update') { foreach (array('main', 'side') as $location) { if ($location === 'main') { $new_blocks = $main; } else { $new_blocks = $right; } foreach ($new_blocks as $order => $block_name) { if (is_numeric($block_name)) { // existing block Database::prepare("UPDATE `##block` SET block_order=? WHERE block_id=?")->execute(array($order, $block_name)); // existing block moved location Database::prepare("UPDATE `##block` SET location=? WHERE block_id=?")->execute(array($location, $block_name)); } else { // new block if ($user_id) { Database::prepare("INSERT INTO `##block` (user_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($user_id, $location, $order, $block_name)); } else { Database::prepare("INSERT INTO `##block` (gedcom_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($gedcom_id, $location, $order, $block_name)); } } } // deleted blocks foreach ($blocks[$location] as $block_id => $block_name) { if (!in_array($block_id, $main) && !in_array($block_id, $right)) { Database::prepare("DELETE FROM `##block_setting` WHERE block_id=?")->execute(array($block_id)); Database::prepare("DELETE FROM `##block` WHERE block_id=?")->execute(array($block_id)); } } } if ($user_id) { header('Location: ' . WT_BASE_URL . 'index.php?ctype=user&ged=' . $WT_TREE->getNameUrl()); } else { header('Location: ' . WT_BASE_URL . 'index.php?ctype=gedcom&ged=' . $WT_TREE->getNameUrl()); } return; } $controller ->pageHeader() ->addInlineJavascript(' /** * Move Up Block Javascript function * * This function moves the selected option up in the given select list * * @param String section_name the name of the select to move the options */ function move_up_block(section_name) { section_select = document.getElementById(section_name); if (section_select) { if (section_select.selectedIndex <= 0) return false; index = section_select.selectedIndex; temp = new Option(section_select.options[index-1].text, section_select.options[index-1].value); section_select.options[index-1] = new Option(section_select.options[index].text, section_select.options[index].value); section_select.options[index] = temp; section_select.selectedIndex = index-1; } } /** * Move Down Block Javascript function * * This function moves the selected option down in the given select list * * @param String section_name the name of the select to move the options */ function move_down_block(section_name) { section_select = document.getElementById(section_name); if (section_select) { if (section_select.selectedIndex < 0) return false; if (section_select.selectedIndex >= section_select.length-1) return false; index = section_select.selectedIndex; temp = new Option(section_select.options[index+1].text, section_select.options[index+1].value); section_select.options[index+1] = new Option(section_select.options[index].text, section_select.options[index].value); section_select.options[index] = temp; section_select.selectedIndex = index+1; } } /** * Move Block from one column to the other Javascript function * * This function moves the selected option down in the given select list * * @param String from_column the name of the select to move the option from * @param String to_column the name of the select to remove the option to */ function move_left_right_block(from_column, to_column) { to_select = document.getElementById(to_column); from_select = document.getElementById(from_column); instruct = document.getElementById("instructions"); if ((to_select) && (from_select)) { add_option = from_select.options[from_select.selectedIndex]; if (to_column != "available_select") { to_select.options[to_select.length] = new Option(add_option.text, add_option.value); } if (from_column != "available_select") { from_select.options[from_select.selectedIndex] = null; //remove from list } } } /** * Select Options Javascript function * * This function selects all the options in the multiple select lists */ function select_options() { section_select = document.getElementById("main_select"); if (section_select) { for (i=0; i $block) { $controller->addInlineJavascript( 'block_descr["' . $block_name . '"] = "' . Filter::escapeJs($block->getDescription()) . '";' ); } $controller->addInlineJavascript( 'block_descr["advice1"] = "' . I18N::translate('Select a block and use the arrows to move it.') . '";' ); ?>

getPageTitle(); ?>

'; echo '', I18N::translate('Main section blocks'), ''; echo ''; echo ''; echo ''; echo ''; echo ''; // NOTE: Row 2 column 1: Up/Down buttons for left (main) block list echo ''; // NOTE: Row 2 column 2: Left (Main) block list echo ''; // NOTE: Row 2 column 3: Left/Right buttons for left (main) block list echo ''; // Row 2 column 4: Middle (Available) block list echo ''; // NOTE: Row 2 column 5: Left/Right buttons for right block list echo ''; // NOTE: Row 2 column 6: Right block list echo ''; // NOTE: Row 2 column 7: Up/Down buttons for right block list echo ''; echo ''; // NOTE: Row 3 columns 1-7: Summary description of currently selected block echo ''; if ($can_reset) { echo ''; echo '
'; echo '', I18N::translate('Available blocks'), ''; echo ''; echo '', I18N::translate('Right section blocks'), ''; echo '
'; echo ''; echo '
'; echo ''; echo '

'; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo ''; echo '
'; echo ''; echo '

'; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo ''; echo '
'; echo ''; echo '

'; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo ''; echo '

'; echo '
'; echo I18N::translate('Select a block and use the arrows to move it.'); echo '
'; echo '', I18N::translate('Restore the default block layout'), ''; } else { echo ''; } echo ''; echo '
'; echo '
';