xref: /webtrees/index.php (revision 147d091b24585e9920a1747e20279d505c834a21)
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// The latest version is shown on the administration page.  This updates it every 3 days.
46// TODO: send an email notification to the admin when new versions are available.
47fetch_latest_version();
48
49// We generate individual blocks using AJAX
50if ($action=='ajax') {
51	$controller=new WT_Controller_Ajax();
52	$controller->pageHeader();
53
54	// Check we're displaying an allowable block.
55	$block_id=safe_GET('block_id');
56	if (array_key_exists($block_id, $blocks['main'])) {
57		$module_name=$blocks['main'][$block_id];
58	} elseif (array_key_exists($block_id, $blocks['side'])) {
59		$module_name=$blocks['side'][$block_id];
60	} else {
61		exit;
62	}
63	if (array_key_exists($module_name, $all_blocks)) {
64		$class_name=$module_name.'_WT_Module';
65		$module=new $class_name;
66		$module->getBlock($block_id);
67	}
68	if (WT_DEBUG) {
69		echo execution_stats();
70	}
71	if (WT_DEBUG_SQL) {
72		echo WT_DB::getQueryLog();
73	}
74	exit;
75}
76
77$controller=new WT_Controller_Base();
78if ($ctype=='user') {
79	$controller->requireMemberLogin();
80}
81$controller
82	->setPageTitle($ctype=='user' ? WT_I18N::translate('My page') : get_gedcom_setting(WT_GED_ID, 'title'))
83	->setMetaRobots('index,follow')
84	->pageHeader()
85	// By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times.
86	->addInlineJavascript('jQuery.ajaxSetup({cache:true});');
87
88if (WT_USE_LIGHTBOX) {
89	$album = new lightbox_WT_Module();
90	$album->getPreLoadContent();
91}
92
93if ($ctype=='user') {
94	echo '<div id="my-page">';
95	echo '<h1 class="center">', WT_I18N::translate('My page'), '</h1>';
96} else {
97	echo '<div id="home-page">';
98}
99if ($blocks['main']) {
100	if ($blocks['side']) {
101		echo '<div id="index_main_blocks">';
102	} else {
103		echo '<div id="index_full_blocks">';
104	}
105	foreach ($blocks['main'] as $block_id=>$module_name) {
106		$class_name=$module_name.'_WT_Module';
107		$module=new $class_name;
108		if ($SEARCH_SPIDER || !$module->loadAjax()) {
109			// Load the block directly
110			$module->getBlock($block_id);
111		} else {
112			// Load the block asynchronously
113			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
114			$controller->addInlineJavascript(
115				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
116			);
117		}
118	}
119	echo '</div>';
120}
121if ($blocks['side']) {
122	if ($blocks['main']) {
123		echo '<div id="index_small_blocks">';
124	} else {
125		echo '<div id="index_full_blocks">';
126	}
127	foreach ($blocks['side'] as $block_id=>$module_name) {
128		$class_name=$module_name.'_WT_Module';
129		$module=new $class_name;
130		if ($SEARCH_SPIDER || !$module->loadAjax()) {
131			// Load the block directly
132			$module->getBlock($block_id);
133		} else {
134			// Load the block asynchronously
135			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
136			$controller->addInlineJavascript(
137				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
138			);
139		}
140	}
141	echo '</div>';
142}
143
144// link for changing blocks
145echo '<div id="link_change_blocks">';
146	if ($ctype=='user') echo '<a href="index_edit.php?user_id='.WT_USER_ID.'" onclick="return modalDialog(\'index_edit.php?user_id='.WT_USER_ID.'\', \'', WT_I18N::translate('Change the blocks on this page'), '\');">', WT_I18N::translate('Change the blocks on this page'), '</a>';
147	if (WT_USER_GEDCOM_ADMIN && $ctype=='gedcom') echo '<a href="index_edit.php?gedcom_id='.WT_GED_ID.'" onclick="return modalDialog(\'index_edit.php?gedcom_id='.WT_GED_ID.'\', \'', WT_I18N::translate('Change the blocks on this page'), '\');">', WT_I18N::translate('Change the blocks on this page'), '</a>';
148	if ($SHOW_COUNTER) {echo '<span>'.WT_I18N::translate('Hit Count:').' '.$hitCount.'</span>';}
149echo '</div>', // <div id="link_change_blocks">
150	 '</div>'; // <div id="home-page">
151