summaryrefslogtreecommitdiff
path: root/sidebar.php
blob: 4402250937dbdcf97895d9aeb5dc52230f9df43b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/**
* Animated Sidebar for the Individual Page
*
* webtrees: Web based Family History software
 * Copyright (C) 2010 webtrees development team.
 *
 * Derived from PhpGedView
* Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package webtrees
* @subpackage Sidebar
* @version $Id$
*/

if (!defined('WT_SCRIPT_NAME')) define('WT_SCRIPT_NAME', 'sidebar.php');
require_once('includes/session.php');
require_once(WT_ROOT.'includes/classes/class_module.php');

$sidebarmods = WT_Module::getActiveSidebars();
if (!$sidebarmods) {
	return;
}

$sb_action = safe_GET('sb_action', WT_REGEX_ALPHANUM, 'none');
//-- handle ajax calls
if ($sb_action!='none') {
	header('Content-type: text/html; charset=UTF-8');
	class tempController {
		var $pid;
		var $famid;
	}

	$controller = new tempController();

	$pid = safe_GET_xref('pid', '');
	if (empty($pid)) $pid = safe_POST_xref('pid', '');
	if (!empty($pid)) {
		$controller->pid = $pid;
	}
	$pid = safe_GET_xref('rootid',  '');
	if (empty($pid)) $pid = safe_POST_xref('rootid', '');
	if (!empty($pid)) {
		$controller->pid = $pid;
	}
	$famid = safe_GET('famid', WT_REGEX_XREF, '');
	if (empty($famid)) $famid = safe_POST('famid', WT_REGEX_XREF, '');
	if (!empty($famid)) {
		$controller->famid = $famid;
	}
	$sid = safe_GET('sid', WT_REGEX_XREF, '');
	if (empty($sid)) $sid = safe_POST('sid', WT_REGEX_XREF, '');
	if (!empty($sid)) {
		$controller->sid = $sid;
	}

	if ($sb_action=='loadMods') {
		$counter = 0;
		foreach($sidebarmods as $mod) {
			if (isset($controller)) $mod->setController($controller);
			if ($mod->hasSidebarContent()) {
				?>
				<h3 title="<?php echo $mod->getName()?>"><a href="#"><?php echo $mod->getTitle()?></a></h3>
				<div id="sb_content_<?php echo $mod->getName()?>">
				<?php if ($counter==0) echo $mod->getSidebarContent();
				else {?><img src="<?php echo WT_THEME_DIR ?>images/loading.gif" /><?php }?>
				</div>
				<?php
				$counter++;
			}
		}
		exit;
	}
	if ($sb_action=='loadmod') {
		$modName = safe_GET('mod', WT_REGEX_URL, '');
		if (isset($sidebarmods[$modName])) {
			$mod = $sidebarmods[$modName];
			if (isset($controller)) $mod->setController($controller);
			echo $mod->getSidebarContent();
		}
		exit;
	}
	if (isset($sidebarmods[$sb_action])) {
		$mod = $sidebarmods[$sb_action];
		echo $mod->getSidebarAjaxContent();
	}
	exit;
}

global $controller;
$pid='';
$famid='';
if (isset($controller)) {
	if (isset($controller->pid)) $pid = $controller->pid;
	if (isset($controller->rootid)) $pid = $controller->rootid;
	if (isset($controller->famid)) $famid = $controller->famid;
	if (isset($controller->sid)) $pid = $controller->sid;
} else {
	$pid = safe_GET_xref('pid', '');
	if (empty($pid)) $pid = safe_POST_xref('pid', '');
	if (empty($pid)) $pid = safe_GET_xref('rootid',  '');
	if (empty($pid)) $pid = safe_POST_xref('rootid', '');
	if (empty($pid)) $pid = safe_POST_xref('sid', '');
	if (empty($pid)) $pid = safe_GET_xref('sid', '');
	$famid = safe_GET('famid', WT_REGEX_XREF, '');
	if (empty($famid)) $famid = safe_POST('famid', WT_REGEX_XREF, '');
}
?>

<?php
// Sidebar state control
// NOTE: Need config option for setting $sidebar_state.
$sidebar_state = "open";	// "open"	= Sidebar initially open, [default]	+ normally auto pinned
							// "closed" = Sidebar initially closed, 		+ normally auto unpinned
//
?>

<script type="text/javascript" src="js/jquery/jquery.scrollfollow.js"></script>
<script type="text/javascript">
<!--
jQuery.noConflict(); // @see http://docs.jquery.com/Using_jQuery_with_Other_Libraries/
var loadedMods = new Array();

function closeCallback() {
	jQuery('#sidebarAccordion').hide();
	jQuery('#sidebar_pin').hide();
	if (pinned == false) {
		jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=false');
		pinned = false;
	}
	if (jQuery("#tabs li:eq("+jQuery("#tabs").tabs("option", "selected")+") a").attr("title") == "googlemap") {
		loadMap();
		map.setMapType(<?php echo $GOOGLEMAP_MAP_TYPE; ?>);
		SetMarkersAndBounds();
		ResizeMap();
	}
}

function openCallback() {
	jQuery('#sidebarAccordion').accordion({
		/* fillSpace: true, */
		autoHeight: false,
		changestart: function(event, ui) {
			loadedMods[ui.oldHeader.attr('title')] = true;
			var active = ui.newHeader.attr('title');
			if (!loadedMods[active]) {
				jQuery('#sb_content_'+active).load('sidebar.php?sb_action=loadmod&mod='+active+'&pid=<?php echo $pid?>&famid=<?php echo $famid?>');
			}
		}
	});
	if (jQuery("#tabs li:eq("+jQuery("#tabs").tabs("option", "selected")+") a").attr("title") == "googlemap") {
		loadMap();
		map.setMapType(<?php echo $GOOGLEMAP_MAP_TYPE; ?>);
		SetMarkersAndBounds();
		ResizeMap();
	}
}

jQuery(document).ready(function() {

	// Sidebar Pin Function
	jQuery('#sidebar_pin').toggle(
   	function() {
   		jQuery('#sidebar_pin img').attr('src', '<?php echo $WT_IMAGES['pin-in'];?>').attr('title', '<?php echo i18n::translate('Unpin Sidebar');?>');
   		jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=true');
   		pinned = true;
   	},
   	function() {
   		jQuery('#sidebar_pin img').attr('src', '<?php echo $WT_IMAGES['pin-out'];?>').attr('title', '<?php echo i18n::translate('Pin Sidebar');?>');
   	jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=false');
   	pinned = false;
   	}
	);
	<?php if (isset($_SESSION['WT_pin']) && $_SESSION['WT_pin']) { ?>
		jQuery('#sidebar_pin').click();
	<?php } ?>
   	// ---------------------

	var modsLoaded = false;

	// Sidebar Open/Close Function
	// Sidebar Open
	jQuery('#sidebar_open').toggle(function() {
		jQuery('#sidebar_open img').attr('style', 'margin-left:255px;' ).attr('src', '<?php echo $WT_IMAGES['slide_close'];?>').attr('title', '<?php echo i18n::translate('Sidebar Close');?>');
		jQuery('#sidebar').animate({
			right: "0px",
			width: "260px"
		}, 500);
		if (!modsLoaded) {
			jQuery('#sidebarAccordion').load('sidebar.php', 'sb_action=loadMods&pid=<?php echo $pid?>&famid=<?php echo $famid?>', openCallback);
			modsLoaded=true;
		} else {
			jQuery("#sidebarAccordion").accordion("resize");
			openCallback();
		}
		jQuery('#sidebarAccordion').show();
		jQuery('#sidebar_pin').show();
		// Shift content
   	var newwidth = 310;
		newwidth = jQuery('#tabs').width() - newwidth;
		// NOTE: REM next line to avoid the "page shift" when Navigator is opened. (Purely a preference choice)
   	jQuery('#tabs > div').css('width', newwidth+'px');
		//
  		<?php if ($sidebar_state == "open" ) { ?>
			jQuery('#sidebar_pin').click();
  		<?php } ?>

		<?php if ($sidebar_state == "open") { ?>
			jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=true&sb_closed=false');
		<?php } ?>

		<?php if ($sidebar_state == "closed") { ?>
			<?php if (isset($_SESSION['WT_pin']) && $_SESSION['WT_pin']) { ?>
				jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=true&sb_closed=false');
			<?php } else { ?>
				jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=false&sb_closed=false');
			<?php } ?>
		<?php } ?>
		sb_open=true;
	// Sidebar Close
	}, function() {
		jQuery('#sidebar_open img').attr('style', 'margin-left:0px;' ).attr('src', '<?php echo $WT_IMAGES['slide_open'];?>').attr('title', '<?php echo i18n::translate('Sidebar Open');?>');
		jQuery('#sidebar').css('left', '');
		jQuery('#sidebar').animate({
			right: "4px",
			width: "0px"
		}, 500, 'linear', closeCallback);
		// Shift content back
			jQuery('#tabs div').css('width', '');
		//
		<?php if ($sidebar_state == "open" ) { ?>
  			jQuery('#sidebar_pin').click();
  		<?php } ?>

		jQuery.get('individual.php?pid=<?php echo $controller->pid;?>&action=ajax&pin=false&sb_closed=true');
		sb_open=false;
	});
	// -----------------------------

	<?php if  ( $sidebar_state == "open" ) { ?>
 		<?php if ( isset($_SESSION['WT_pin']) && $_SESSION['WT_pin'] || !isset($_SESSION['WT_sb_closed']) ) { ?>
			jQuery('#sidebar_open').click();
			jQuery('#sidebar_controls').show();
			if ( pinned == false ) {
				jQuery('#sidebar_pin').click();
			}
  		<?php } else { ?>
  			jQuery('#sidebar_controls').show();
  		<?php } ?>
  	<?php } ?>

  	<?php if ( $sidebar_state == "closed" ) { ?>
  		if ( pinned == true) {
  			jQuery('#sidebar_open').click();
  		}
  		jQuery('#sidebar_controls').show();
  	<?php } ?>

});
-->
</script>

<div id="sidebar">
	<?php
	if ( isset($_SESSION['WT_pin']) && $_SESSION['WT_pin'] && $sidebar_state == "open") {
	?>
		<div id="sidebar_controls" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top ui-state-focus">
			<a id="sidebar_open" href="#open"><img style="margin-left:0px;" src="<?php echo $WT_IMAGES['slide_close'];?>" border="0" title="<?php echo i18n::translate('Sidebar Open');?>" alt="" /></a>
			<a id="sidebar_pin" href="#pin"><img src="<?php echo $WT_IMAGES['pin-out'];?>" border="0" title="<?php echo i18n::translate('Pin Sidebar');?>" alt="" /></a>
		</div>
	<?php
	} else {
	?>
		<div id="sidebar_controls" class="ui-accordion-header ui-helper-reset ui-state-active ui-corner-top ui-state-focus">
			<a id="sidebar_open" href="#open"><img style="margin-left:0px;" src="<?php echo $WT_IMAGES['slide_open'];?>" border="0" title="<?php echo i18n::translate('Sidebar Open');?>" alt="" /></a>
			<a id="sidebar_pin" href="#pin"><img src="<?php echo $WT_IMAGES['pin-out'];?>" border="0" title="<?php echo i18n::translate('Pin Sidebar');?>" alt="" /></a>
		</div>
	<?php
	}
	?>
	<div id="sidebarAccordion"></div>
	<span class="ui-icon ui-icon-grip-dotted-horizontal" style="margin:2px auto;"></span>
</div>
<div id="debug">
</div>