1<?php 2// My page page allows a logged in user the abilty 3// to keep bookmarks, see a list of upcoming events, etc. 4// 5// webtrees: Web based Family History software 6// Copyright (C) 2011 webtrees development team. 7// 8// Derived from PhpGedView 9// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. 10// 11// This program is free software; you can redistribute it and/or modify 12// it under the terms of the GNU General Public License as published by 13// the Free Software Foundation; either version 2 of the License, or 14// (at your option) any later version. 15// 16// This program is distributed in the hope that it will be useful, 17// but WITHOUT ANY WARRANTY; without even the implied warranty of 18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19// GNU General Public License for more details. 20// 21// You should have received a copy of the GNU General Public License 22// along with this program; if not, write to the Free Software 23// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24// 25// $Id$ 26 27define('WT_SCRIPT_NAME', 'index.php'); 28require './includes/session.php'; 29 30// The only option for action is "ajax" 31$action=safe_REQUEST($_REQUEST, 'action', 'ajax'); 32 33// The default view depends on whether we are logged in 34$ctype=safe_REQUEST($_REQUEST, 'ctype', array('gedcom', 'user'), WT_USER_ID ? 'user' : 'gedcom'); 35 36// A request to see a user page, but not logged in? 37if (!WT_USER_ID && $ctype=='user') { 38 header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.'login.php?url='.rawurlencode('index.php?ctype=user')); 39 exit; 40} 41 42//-- get the blocks list 43if ($ctype=='user') { 44 $blocks=get_user_blocks(WT_USER_ID); 45} else { 46 $blocks=get_gedcom_blocks(WT_GED_ID); 47} 48 49$all_blocks=WT_Module::getActiveBlocks(); 50 51// We generate individual blocks using AJAX 52if ($action=='ajax') { 53 $controller=new WT_Controller_Ajax(); 54 $controller 55 ->pageHeader() 56 ->addExternalJavaScript(WT_JQUERY_URL) 57 ->addExternalJavaScript(WT_JQUERYUI_URL); 58 59 // Check we're displaying an allowable block. 60 $block_id=safe_GET('block_id'); 61 if (array_key_exists($block_id, $blocks['main'])) { 62 $module_name=$blocks['main'][$block_id]; 63 } elseif (array_key_exists($block_id, $blocks['side'])) { 64 $module_name=$blocks['side'][$block_id]; 65 } else { 66 exit; 67 } 68 if (array_key_exists($module_name, $all_blocks)) { 69 $class_name=$module_name.'_WT_Module'; 70 $module=new $class_name; 71 $module->getBlock($block_id); 72 } 73 if (WT_DEBUG) { 74 echo execution_stats(); 75 } 76 if (WT_DEBUG_SQL) { 77 echo WT_DB::getQueryLog(); 78 } 79 exit; 80} 81 82$controller=new WT_Controller_Base(); 83$controller 84 ->pageHeader() 85 ->setPageTitle($ctype=='user' ? WT_I18N::translate('My page') : get_gedcom_setting(WT_GED_ID, 'title')) 86 // By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times. 87 ->addInlineJavaScript('jQuery.ajaxSetup({cache:true});'); 88 89if (WT_USE_LIGHTBOX) { 90 require WT_ROOT.WT_MODULES_DIR.'lightbox/functions/lb_call_js.php'; 91} 92 93echo '<div id="home-page">'; 94if ($ctype=='user') { 95 echo '<h1 align="center">', WT_I18N::translate('My page'), '</h1>'; 96} 97if ($blocks['main']) { 98 if ($blocks['side']) { 99 echo '<div id="index_main_blocks">'; 100 } else { 101 echo '<div id="index_full_blocks">'; 102 } 103 foreach ($blocks['main'] as $block_id=>$module_name) { 104 $class_name=$module_name.'_WT_Module'; 105 $module=new $class_name; 106 if ($SEARCH_SPIDER || !$module->loadAjax()) { 107 // Load the block directly 108 $module->getBlock($block_id); 109 } else { 110 // Load the block asynchronously 111 echo '<div id="block_', $block_id, '"><div class="loading-image"> </div></div>'; 112 $controller->addInlineJavaScript( 113 'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");' 114 ); 115 } 116 } 117 echo '</div>'; 118} 119if ($blocks['side']) { 120 if ($blocks['main']) { 121 echo '<div id="index_small_blocks">'; 122 } else { 123 echo '<div id="index_full_blocks">'; 124 } 125 foreach ($blocks['side'] as $block_id=>$module_name) { 126 $class_name=$module_name.'_WT_Module'; 127 $module=new $class_name; 128 if ($SEARCH_SPIDER || !$module->loadAjax()) { 129 // Load the block directly 130 $module->getBlock($block_id); 131 } else { 132 // Load the block asynchronously 133 echo '<div id="block_', $block_id, '"><div class="loading-image"> </div></div>'; 134 $controller->addInlineJavaScript( 135 'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");' 136 ); 137 } 138 } 139 echo '</div>'; 140} 141 142// Ensure there is always way to configure the blocks 143if ($ctype=='user' && !in_array('user_welcome', $blocks['main']) && !in_array('user_welcome', $blocks['side'])) { 144 echo '<div align="center">'; 145 echo "<a href=\"#\" onclick=\"window.open('index_edit.php?name=".rawurlencode(WT_USER_NAME)."&ctype=user', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".WT_I18N::translate('Change the blocks on this page').'</a>'; 146 echo '</div>'; 147} 148if (WT_USER_IS_ADMIN && $ctype=='gedcom' && !in_array('gedcom_block', $blocks['main']) && !in_array('gedcom_block', $blocks['side'])) { 149 echo '<div align="center">'; 150 echo "<a href=\"#\" onclick=\"window.open('index_edit.php?name=".WT_GEDURL."&ctype=gedcom', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".WT_I18N::translate('Change the blocks on this page').'</a>'; 151 echo '</div>'; 152 echo '</div>';//close 'home-page' 153} 154