xref: /webtrees/index.php (revision 360b89275a04a221062f5224ea2baec62a72740c)
1<?php
2/**
3 * My Page page allows a logged in user the abilty
4 * to keep bookmarks, see a list of upcoming events, etc.
5 *
6 * webtrees: Web based Family History software
7 * Copyright (C) 2010 webtrees development team.
8 *
9 * Derived from PhpGedView
10 * Copyright (C) 2002 to 2009  PGV Development Team.  All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 *
26 * @package webtrees
27 * @subpackage Display
28 * @version $Id$
29 */
30
31define('WT_SCRIPT_NAME', 'index.php');
32require './includes/session.php';
33
34// The only option for action is "ajax"
35$action=safe_REQUEST($_REQUEST, 'action', 'ajax');
36
37// The default view depends on whether we are logged in
38$ctype=safe_REQUEST($_REQUEST, 'ctype', array('gedcom', 'user'), WT_USER_ID ? 'user' : 'gedcom');
39
40// A request to see a user page, but not logged in?
41if (!WT_USER_ID && $ctype=='user') {
42	header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH.'login.php?url='.rawurlencode('index.php?ctype=user'));
43	exit;
44}
45
46//-- get the blocks list
47if ($ctype=='user') {
48	$blocks=get_user_blocks(WT_USER_ID);
49} else {
50	$blocks=get_gedcom_blocks(WT_GED_ID);
51}
52
53$all_blocks=WT_Module::getActiveBlocks();
54
55// We generate individual blocks using AJAX
56if ($action=='ajax') {
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
81// We have finished writing session data, so release the lock
82Zend_Session::writeClose();
83
84if ($ctype=='user') {
85	$helpindex = 'mypage_portal';
86	print_header(i18n::translate('My Page'));
87} else {
88	$helpindex = 'index_portal';
89	print_header(get_gedcom_setting(WT_GED_ID, 'title'));
90}
91
92if (WT_USE_LIGHTBOX) {
93	require WT_ROOT.'modules/lightbox/lb_defaultconfig.php';
94	require WT_ROOT.'modules/lightbox/functions/lb_call_js.php';
95}
96
97// TODO: these should be moved to their respective module/block
98echo WT_JS_START;
99?>
100	function refreshpage() {
101		window.location = 'index.php?ctype=<?php echo $ctype; ?>';
102	}
103	function addnews(uname) {
104		window.open('editnews.php?username='+uname, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
105	}
106	function editnews(news_id) {
107		window.open('editnews.php?news_id='+news_id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
108	}
109	var pastefield;
110	function paste_id(value) {
111		pastefield.value=value;
112	}
113<?php
114echo WT_JS_END;
115//-- start of main content section
116if ($ctype=='user') {
117	echo '<div align="center">';
118	echo '<h1>', i18n::translate('My Page'), '</h1>';
119	echo i18n::translate('My Page allows you to keep bookmarks of your favorite people, track upcoming events, and collaborate with other webtrees users.');
120	echo '<br /><br /></div>';
121}
122echo '<script src="js/jquery/jquery.min.js" type="text/javascript"></script>';
123echo '<script type="text/javascript">jQuery.noConflict();</script>';
124if ($blocks['main']) {
125	if ($blocks['side']) {
126		echo '<div id="index_main_blocks">';
127	} else {
128		echo '<div id="index_full_blocks">';
129	}
130	foreach ($blocks['main'] as $block_id=>$module_name) {
131		$class_name=$module_name.'_WT_Module';
132		$module=new $class_name;
133		if ($SEARCH_SPIDER || !$module->loadAjax()) {
134			// Load the block directly
135			$module->getBlock($block_id);
136		} else {
137			// Load the block asynchronously
138			echo '<div id="block_', $block_id, '"><img src="images/loading.gif" alt="', htmlspecialchars(i18n::translate('Loading...')),  '"/></div>';
139			echo WT_JS_START, "jQuery('#block_{$block_id}').load('index.php?ctype={$ctype}&action=ajax&block_id={$block_id}');", WT_JS_END;
140		}
141	}
142	echo '</div>';
143}
144
145if ($blocks['side']) {
146	if ($blocks['main']) {
147		echo '<div id="index_small_blocks">';
148	} else {
149		echo '<div id="index_full_blocks">';
150	}
151	foreach ($blocks['side'] as $block_id=>$module_name) {
152		$class_name=$module_name.'_WT_Module';
153		$module=new $class_name;
154		if ($SEARCH_SPIDER || !$module->loadAjax()) {
155			// Load the block directly
156			$module->getBlock($block_id);
157		} else {
158			// Load the block asynchronously
159			echo '<div id="block_', $block_id, '"><img src="images/loading.gif" alt="', htmlspecialchars(i18n::translate('Loading...')),  '"/></div>';
160			echo WT_JS_START, "jQuery('#block_{$block_id}').load('index.php?ctype={$ctype}&action=ajax&block_id={$block_id}');", WT_JS_END;
161		}
162	}
163	echo '</div>';
164}
165
166// Ensure there is always way to configure the blocks
167if ($ctype=='user' && !in_array('user_welcome', $blocks['main']) && !in_array('user_welcome', $blocks['side'])) {
168	echo '<div align="center">';
169	echo "<a href=\"javascript:;\" onclick=\"window.open('index_edit.php?name=".rawurlencode(WT_USER_NAME)."&amp;ctype=user', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".i18n::translate('Customize My Page').'</a>';
170	echo help_link('mypage_customize');
171	echo '</div>';
172}
173if (WT_USER_IS_ADMIN && $ctype=='gedcom' && !in_array('gedcom_block', $blocks['main']) && !in_array('gedcom_block', $blocks['side'])) {
174	echo '<div align="center">';
175	echo "<a href=\"javascript:;\" onclick=\"window.open('index_edit.php?name=".WT_GEDURL."&amp;ctype=gedcom', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".i18n::translate('Customize this GEDCOM Home Page').'</a>';
176	echo '</div>';
177}
178
179print_footer();
180