<?php
/*=================================================
	Project: phpGedView
	File: index.php
	Author: John Finlay
	Comments:
		MyGedView page allows a logged in user the abilty
		to keep bookmarks, see a list of upcoming events, etc.

	Change Log:
		11/6/03 - File Created

	phpGedView: Genealogy Viewer
    Copyright (C) 2002 to 2003  John Finlay and Others

    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

===================================================*/
# $Id: index.php,v 1.149 2004/12/08 19:04:30 yalnifj Exp $

require("config.php");

if (!isset($CONFIGURED)) {
	print "Unable to include the config.php file.  Make sure that . is in your PHP include path in the php.ini file.";
	exit;
}
require("functions_blocks.php");
require($PGV_BASE_DIRECTORY.$factsfile["english"]);
if (file_exists($PGV_BASE_DIRECTORY.$factsfile[$LANGUAGE])) require($PGV_BASE_DIRECTORY.$factsfile[$LANGUAGE]);

if (isset($_SESSION["timediff"])) $time = time()-$_SESSION["timediff"];
else $time = time();
$day = date("j", $time);
$month = date("M", $time);
$year = date("Y", $time);

if (!isset($action)) $action="";

//-- make sure that they have user status before they can use this page
//-- otherwise have them login again
$uname = getUserName();
if (empty($uname)) {
	if (!empty($command)) {
		if ($command=="user") {
			header("Location: login.php?help_message=mygedview_login_help&url=".urlencode("index.php?command=user"));
			exit;
		}
	}
	$command="gedcom";
}
else $user = getUser($uname);

if (empty($command)) $command="user";

if (!empty($uname)) {
	//-- add favorites action
	if (($action=="addfav")&&(!empty($gid))) {
		$gid = strtoupper($gid);
		$indirec = find_person_record($gid);
		if ($indirec) {
			$favorite = array();
			if ($command=="user") $favorite["username"] = $uname;
			else $favorite["username"] = $GEDCOM;
			$favorite["gid"] = $gid;
			$favorite["type"] = "INDI";
			$favorite["file"] = $GEDCOM;
			addFavorite($favorite);
		}
	}
	if (($action=="deletefav")&&(isset($fv_id))) {
		deleteFavorite($fv_id);
	}
	else if ($action=="deletemessage") {
		if (isset($message_id)) {
			if (!is_array($message_id)) deleteMessage($message_id);
			else {
				foreach($message_id as $mid) {
					if (isset($mid)) deleteMessage($mid);
				}
			}
		}
	}
	else if (($action=="deletenews")&&(isset($news_id))) {
		deleteNews($news_id);
	}
}

//-- get the blocks list
if ($command=="user") {
	$ublocks = getBlocks($uname);
	if (count($ublocks["main"])==0) {
		$ublocks["main"][] = "print_todays_events";
		$ublocks["main"][] = "print_user_messages";
		$ublocks["main"][] = "print_user_favorites";
	}
	if (count($ublocks["right"])==0) {
		$ublocks["right"][] = "print_welcome_block";
		$ublocks["right"][] = "print_random_media";
		$ublocks["right"][] = "print_upcoming_events";
		$ublocks["right"][] = "print_logged_in_users";
	}
}
else {
	$ublocks = getBlocks($GEDCOM);
	if (count($ublocks["main"])==0) {
		$ublocks["main"][] = "print_gedcom_stats";
		$ublocks["main"][] = "print_gedcom_news";
		$ublocks["main"][] = "print_gedcom_favorites";
	}
	if (count($ublocks["right"])==0) {
		$ublocks["right"][] = "print_gedcom_block";
		$ublocks["right"][] = "print_random_media";
		$ublocks["right"][] = "print_todays_events";
		$ublocks["right"][] = "print_logged_in_users";
	}
}
/* - sample blocks array
$ublocks = array();
$ublocks["main"] = array();
$ublocks["right"] = array();
$ublocks["main"][] = "print_todays_events";
$ublocks["main"][] = "print_user_messages";
$ublocks["main"][] = "print_user_favorites";
$ublocks["right"][] = "print_welcome_block";
$ublocks["right"][] = "print_random_media";
$ublocks["right"][] = "print_upcoming_events";
$ublocks["right"][] = "print_logged_in_users";
*/

if ($command=="user") {
	$helpindex = "index_myged_help";
	print_header($pgv_lang["mygedview"]);
	//print_help_link("index_myged_help", "page_help");
}
else {
	print_header($GEDCOMS[$GEDCOM]["title"]);
	//print_help_link("index_help", "page_help");
}
?>
<script language="JavaScript" type="text/javascript">
<!--
	function refreshpage() {
		window.location = 'index.php?command=<?php print $command; ?>';
	}
	function addnews(uname) {
		window.open('editnews.php?uname='+uname, '', 'top=50,left=50,width=500,height=400,resizable=1,scrollbars=1');
	}
	function editnews(news_id) {
		window.open('editnews.php?news_id='+news_id, '', 'top=50,left=50,width=500,height=400,resizable=1,scrollbars=1');
	}
//-->
</script>
<?php
//-- start of main content section
print "\t<div id=\"index_main_blocks\">\n";
print "<div id=\"index_title\">\n";
if ($command=="user") {
	print "<h1>".$pgv_lang["mygedview"]."</h1>";
	print $pgv_lang["mygedview_desc"];
}
print "</div>\n";

foreach($ublocks["main"] as $block) {
	eval($block."(false);");
}
print "</div>\n";
//-- end of main content section

//-- start of blocks section
print "\t<div id=\"index_small_blocks\">\n";
for($i=0; $i<count($ublocks["right"]); $i++) {
	$block = $ublocks["right"][$i];
	eval($block."();");
}
if ($command=="user") {
	if ((!in_array("print_welcome_block", $ublocks["right"]))&&(!in_array("print_welcome_block", $ublocks["main"]))) {
		print "<a href=\"#\" onclick=\"window.open('index_edit.php?name=".getUserName()."&amp;command=user', '', 'top=50,left=50,width=600,height=550,scrollbars=1,resizable=1');\">".$pgv_lang["customize_page"]."</a>\n";
		print_help_link("mygedview_customize_help", "qm");
	}
}
if ($command=="gedcom") {
	if ((!in_array("print_gedcom_block", $ublocks["right"]))&&(!in_array("print_gedcom_block", $ublocks["main"]))) {
		if (userIsAdmin(getUserName())) {
			print "<a href=\"#\" onclick=\"window.open('index_edit.php?name=$GEDCOM&amp;command=gedcom', '', 'top=50,left=50,width=600,height=550,scrollbars=1,resizable=1');\">".$pgv_lang["customize_gedcom_page"]."</a>\n";
		}
	}
}
print "\t</div>\n";
//-- end of blocks section

print_footer();
?>
