xref: /webtrees/index.php (revision e08d466597222e7b2028b88a5e5353c84708fcfe)
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) 2012 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//-- get the blocks list
37if (WT_USER_ID && $ctype=='user') {
38	$blocks=get_user_blocks(WT_USER_ID);
39} else {
40	$blocks=get_gedcom_blocks(WT_GED_ID);
41}
42
43$all_blocks=WT_Module::getActiveBlocks();
44
45// We generate individual blocks using AJAX
46if ($action=='ajax') {
47	$controller=new WT_Controller_Ajax();
48	$controller
49		->pageHeader()
50		->addExternalJavaScript(WT_JQUERY_URL)
51		->addExternalJavaScript(WT_JQUERYUI_URL);
52
53	// Check we're displaying an allowable block.
54	$block_id=safe_GET('block_id');
55	if (array_key_exists($block_id, $blocks['main'])) {
56		$module_name=$blocks['main'][$block_id];
57	} elseif (array_key_exists($block_id, $blocks['side'])) {
58		$module_name=$blocks['side'][$block_id];
59	} else {
60		exit;
61	}
62	if (array_key_exists($module_name, $all_blocks)) {
63		$class_name=$module_name.'_WT_Module';
64		$module=new $class_name;
65		$module->getBlock($block_id);
66	}
67	if (WT_DEBUG) {
68		echo execution_stats();
69	}
70	if (WT_DEBUG_SQL) {
71		echo WT_DB::getQueryLog();
72	}
73	exit;
74}
75
76$controller=new WT_Controller_Base();
77if ($ctype=='user') {
78	$controller->requireMemberLogin();
79}
80$controller
81	->setPageTitle($ctype=='user' ? WT_I18N::translate('My page') : get_gedcom_setting(WT_GED_ID, 'title'))
82	->setMetaRobots('index,follow')
83	->pageHeader()
84	// By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times.
85	->addInlineJavaScript('jQuery.ajaxSetup({cache:true});');
86
87if (WT_USE_LIGHTBOX) {
88	require WT_ROOT.WT_MODULES_DIR.'lightbox/functions/lb_call_js.php';
89}
90
91echo '<div id="home-page">';
92if ($ctype=='user') {
93	echo '<h1 class="center">', WT_I18N::translate('My page'), '</h1>';
94}
95if ($blocks['main']) {
96	if ($blocks['side']) {
97		echo '<div id="index_main_blocks">';
98	} else {
99		echo '<div id="index_full_blocks">';
100	}
101	foreach ($blocks['main'] as $block_id=>$module_name) {
102		$class_name=$module_name.'_WT_Module';
103		$module=new $class_name;
104		if ($SEARCH_SPIDER || !$module->loadAjax()) {
105			// Load the block directly
106			$module->getBlock($block_id);
107		} else {
108			// Load the block asynchronously
109			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
110			$controller->addInlineJavaScript(
111				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
112			);
113		}
114	}
115	echo '</div>';
116}
117if ($blocks['side']) {
118	if ($blocks['main']) {
119		echo '<div id="index_small_blocks">';
120	} else {
121		echo '<div id="index_full_blocks">';
122	}
123	foreach ($blocks['side'] as $block_id=>$module_name) {
124		$class_name=$module_name.'_WT_Module';
125		$module=new $class_name;
126		if ($SEARCH_SPIDER || !$module->loadAjax()) {
127			// Load the block directly
128			$module->getBlock($block_id);
129		} else {
130			// Load the block asynchronously
131			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
132			$controller->addInlineJavaScript(
133				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
134			);
135		}
136	}
137	echo '</div>';
138}
139
140// Ensure there is always way to configure the blocks
141if ($ctype=='user' && !in_array('user_welcome', $blocks['main']) && !in_array('user_welcome', $blocks['side'])) {
142	echo '<div align="center">';
143	echo "<a href=\"#\" 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');\">".WT_I18N::translate('Change the blocks on this page').'</a>';
144	echo '</div>';
145}
146if (WT_USER_IS_ADMIN && $ctype=='gedcom' && !in_array('gedcom_block', $blocks['main']) && !in_array('gedcom_block', $blocks['side'])) {
147	echo '<div align="center">';
148	echo "<a href=\"#\" 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');\">".WT_I18N::translate('Change the blocks on this page').'</a>';
149	echo '</div>';
150}
151echo '</div>'; // <div id="home-page">
152