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$controller=new WT_Controller_Base(); 31 32// The only option for action is "ajax" 33$action=safe_REQUEST($_REQUEST, 'action', 'ajax'); 34 35// The default view depends on whether we are logged in 36$ctype=safe_REQUEST($_REQUEST, 'ctype', array('gedcom', 'user'), WT_USER_ID ? 'user' : 'gedcom'); 37 38// A request to see a user page, but not logged in? 39if (!WT_USER_ID && $ctype=='user') { 40 header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.'login.php?url='.rawurlencode('index.php?ctype=user')); 41 exit; 42} 43 44//-- get the blocks list 45if ($ctype=='user') { 46 $blocks=get_user_blocks(WT_USER_ID); 47} else { 48 $blocks=get_gedcom_blocks(WT_GED_ID); 49} 50 51$all_blocks=WT_Module::getActiveBlocks(); 52 53// We generate individual blocks using AJAX 54if ($action=='ajax') { 55 // We have finished writing session data, so release the lock 56 Zend_Session::writeClose(); 57 header('Content-Type: text/html; charset=UTF-8'); 58 // Check we're displaying an allowable block. 59 $block_id=safe_GET('block_id'); 60 if (array_key_exists($block_id, $blocks['main'])) { 61 $module_name=$blocks['main'][$block_id]; 62 } elseif (array_key_exists($block_id, $blocks['side'])) { 63 $module_name=$blocks['side'][$block_id]; 64 } else { 65 exit; 66 } 67 if (array_key_exists($module_name, $all_blocks)) { 68 $class_name=$module_name.'_WT_Module'; 69 $module=new $class_name; 70 $module->getBlock($block_id); 71 } 72 if (WT_DEBUG) { 73 echo execution_stats(); 74 } 75 if (WT_DEBUG_SQL) { 76 echo WT_DB::getQueryLog(); 77 } 78 exit; 79} 80 81if ($ctype=='user') { 82 $controller->setPageTitle(WT_I18N::translate('My page')); 83} else { 84 $controller->setPageTitle(get_gedcom_setting(WT_GED_ID, 'title')); 85} 86$controller->pageHeader(); 87 88if (WT_USE_LIGHTBOX) { 89 require WT_ROOT.WT_MODULES_DIR.'lightbox/functions/lb_call_js.php'; 90} 91 92// TODO: these should be moved to their respective module/block 93echo WT_JS_START; 94?> 95 jQuery(document).ready(function() { 96 jQuery("#index_full_blocks").sortable({placeholder: 'ui-state-highlight', forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: 'move'}); 97 jQuery("#index_small_blocks").sortable({placeholder: 'ui-state-highlight', forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: 'move', connectWith: '#index_main_blocks'}); 98 jQuery("#index_main_blocks").sortable({placeholder: 'ui-state-highlight', forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: 'move', connectWith: '#index_small_blocks'}); 99 100 jQuery( "#index_full_blocks", "#index_small_blocks", "#index_main_blocks" ).disableSelection(); 101 }); 102 103 function refreshpage() { 104 window.location = 'index.php?ctype=<?php echo $ctype; ?>'; 105 } 106 function addnews(uname) { 107 window.open('editnews.php?username='+uname, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1'); 108 } 109 function editnews(news_id) { 110 window.open('editnews.php?news_id='+news_id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1'); 111 } 112 var pastefield; 113 function paste_id(value) { 114 pastefield.value=value; 115 } 116<?php 117echo WT_JS_END; 118//-- start of main content section 119echo '<div id="home-page">'; 120if ($ctype=='user') { 121 echo '<h1 align="center">', WT_I18N::translate('My page'), '</h1>'; 122} 123if ($blocks['main']) { 124 if ($blocks['side']) { 125 echo '<div id="index_main_blocks">'; 126 } else { 127 echo '<div id="index_full_blocks">'; 128 } 129 foreach ($blocks['main'] as $block_id=>$module_name) { 130 $class_name=$module_name.'_WT_Module'; 131 $module=new $class_name; 132 if ($SEARCH_SPIDER || !$module->loadAjax()) { 133 // Load the block directly 134 $module->getBlock($block_id); 135 } else { 136 // Load the block asynchronously 137 echo '<div id="block_', $block_id, '"><img src="', WT_STATIC_URL, 'images/loading.gif" alt="', htmlspecialchars(WT_I18N::translate('Loading...')), '"/></div>'; 138 echo WT_JS_START, "jQuery('#block_{$block_id}').load('index.php?ctype={$ctype}&action=ajax&block_id={$block_id}');", WT_JS_END; 139 } 140 } 141 echo '</div>'; 142} 143if ($blocks['side']) { 144 if ($blocks['main']) { 145 echo '<div id="index_small_blocks">'; 146 } else { 147 echo '<div id="index_full_blocks">'; 148 } 149 foreach ($blocks['side'] as $block_id=>$module_name) { 150 $class_name=$module_name.'_WT_Module'; 151 $module=new $class_name; 152 if ($SEARCH_SPIDER || !$module->loadAjax()) { 153 // Load the block directly 154 $module->getBlock($block_id); 155 } else { 156 // Load the block asynchronously 157 echo '<div id="block_', $block_id, '"><img src="', WT_STATIC_URL, 'images/loading.gif" alt="', htmlspecialchars(WT_I18N::translate('Loading...')), '"/></div>'; 158 echo WT_JS_START, "jQuery('#block_{$block_id}').load('index.php?ctype={$ctype}&action=ajax&block_id={$block_id}');", WT_JS_END; 159 } 160 } 161 echo '</div>'; 162} 163 164// Ensure there is always way to configure the blocks 165if ($ctype=='user' && !in_array('user_welcome', $blocks['main']) && !in_array('user_welcome', $blocks['side'])) { 166 echo '<div align="center">'; 167 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>'; 168 echo '</div>'; 169} 170if (WT_USER_IS_ADMIN && $ctype=='gedcom' && !in_array('gedcom_block', $blocks['main']) && !in_array('gedcom_block', $blocks['side'])) { 171 echo '<div align="center">'; 172 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>'; 173 echo '</div>'; 174 echo '</div>';//close 'home-page' 175} 176