Location: PHPKode > projects > HuMo-gen > admin/index.php
<?php

/**
 * This is the admin web entry point for HuMo-gen.
 *
 * If you are reading this in your web browser, your server is probably
 * not configured correctly to run PHP applications!
 *
 * See the manual for basic setup instructions
 *
 * http://www.huubmons.nl/software/
 *
 * ----------
 *
 * Copyright (C) 2008-2009 Huub Mons,
 * Klaas de Winkel, Jan Maat, Jeroen Beemster, Louis Ywema, Theo Huitema,
 * René Janssen, Yossi Beck
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

// *** Check if HuMo-gen is in a CMS system ***
if (!isset($cms['cms'])){
	// *** In CMS system? ***	
	$cms['cms']=false;
}
if (!isset($cms['cms_name'])){
	// *** Name of CMS, made for CMS specific items. ***	
	$cms['cms_name']=''; 
}
if (!isset($cms['cms_path'])){
	// *** CMS path to HuMo-gen files ***
	$cms['cms_path']='../';
}
if (!isset($cms['cms_path_admin'])){
	// *** CMS path to HuMo-gen admin files ***
	$cms['cms_path_admin']='';
}

if (!$cms['cms']){
	session_start();
}

$page='index';

// *** Globals needed for Joomla ***
global $menu_admin, $stamboom_id, $language_file;

// *** Prevent Session hijacking ***
if (isset( $_SESSION['huidig_ip']) AND $_SESSION['huidig_ip'] != $_SERVER['REMOTE_ADDR']){
	// *** Remove login session if IP adres is changed ***
	echo 'BEVEILIGDE BLADZIJDE/ SECURED PAGE';
	session_unset();
	session_destroy();
	die();
}

// *** Only logoff admin ***
if (isset($_GET['uitloggen'])){
	unset($_SESSION['gebruikersnaam_admin']);
	unset($_SESSION['gebruikersid_admin']);
	unset($_SESSION['groeps_id_admin']);
}

$ADMIN=TRUE; // *** Override "no database" message for admin ***
//if (!$cms['cms']){
	include($cms['cms_path']."include/db_login.php"); // *** Database login ***
//}

// *** Use UTF-8 database connection ***
mysql_query("SET NAMES 'utf8'", $db);

//include("../include/safe.php"); //Variabelen
include($cms['cms_path']."include/safe.php"); //Variabelen

// *** Only load settings if database and table exists ***
$show_menu_left=false;

$controle_database_db=''; $controle_tabellen_db='';
// *** Check if old db_login file is used ***
if (!isset($controle_database)){
	$controle_database='ok'; // *** suppress fault message ***
	$controle_tabellen='ok'; // *** suppress fault message ***
	$controle_database_db='oud db_login bestand';
	$controle_tabellen_db='oud db_login bestand';
}

if (isset($controle_database) AND $controle_database){
	$controle_tabellen = @mysql_query("SELECT * FROM humo_settings",$db);
	if ($controle_tabellen){
		include($cms['cms_path']."include/settings_global.php");
		$show_menu_left=true;
	}
	// *** First installation: show menu if installation of tables is started ***
	if (isset($_POST['tabellen_installeren2'])){ $show_menu_left=true; }

	// *** Update to version 4.x ***
	$check_update = @mysql_query("SELECT * FROM humo_instellingen",$db);
	if ($check_update){
		$page='update';
		$show_menu_left=false;
	}
}


// *** General database selection form ***
/*
function tree_selection_form($page) {
	// *** Select family tree ***
	global $db, $language;

	if (isset($_POST["admin_tree_id"])){
		$admin_tree_id=$_POST['admin_tree_id'];
		$_SESSION['save_admin_tree_id']=$admin_tree_id;
	}
	if (isset($_SESSION['save_admin_tree_id'])){ $admin_tree_id=$_SESSION['save_admin_tree_id']; }

	$tree_sql = "SELECT * FROM humo_trees WHERE tree_prefix!='LEEG' ORDER BY tree_order";
	$tree_result = mysql_query($tree_sql,$db);
	$treetext_name3='';
	echo $language["editor_tree"].': ';
	echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	//echo '<select size="1" name="stamboom_id">';
	echo '<select size="1" name="admin_tree_id">';
		while ($treeDb=mysql_fetch_object($tree_result)){
			$treetext_name2=database_name($treeDb->tree_prefix, $Taalkeuze);
			$selected='';
			if (isset($admin_tree_id) AND $treeDb->tree_id==$admin_tree_id){
				$selected=' SELECTED';
				$treetext_name3=$treetext_name2;
			}
			echo '<option value="'.$tree_Db->tree_id.'"'.$selected.'>'.@$treetext_name2.'</option>';
		}
	echo '</select>';
	echo ' <input type="Submit" name="" value="'.$language["admin_select"].'">';
	echo '</form>';
	echo '&nbsp;<h3 style="display : inline; color: red;">'.$language["trees_selected"].' '.$treetext_name3.'</h3>';
}
*/

// *** Language selection for admin ***
$map=opendir($cms['cms_path'].'languages/');
while (false!==($file = readdir($map))) {
	if (strlen($file)<5 AND $file!='.' AND $file!='..'){
		if (file_exists($cms['cms_path'].'languages/'.$file.'/language_admin.php')){
			$languagebestand[]=$file;
		}
		// *** Save language choice ***
		if (isset($_GET["taalkeuze"])){
			// *** Check if language file really exists, to prevent hack of website ***
			if ($_GET["taalkeuze"]==$file){ $_SESSION['Taal_admin'] = $file; }
		}
	}
}
closedir($map);

// *** Select admin language ***
$Taalkeuze="nl";
// *** Saved default language ***
if (isset($humo_option['default_language_admin'])
	AND file_exists($cms['cms_path'].'languages/'.$humo_option['default_language_admin'].'/language_admin.php')){
	$Taalkeuze=$humo_option['default_language_admin'];
}
// *** Safety: extra check if language exists ***
if (isset($_SESSION["Taal_admin"]) 
	AND file_exists($cms['cms_path'].'languages/'.$_SESSION["Taal_admin"].'/language_admin.php')){	
	$Taalkeuze=$_SESSION["Taal_admin"];
}

$language = array();
include($cms['cms_path'].'languages/'.$Taalkeuze.'/language_admin.php'); //Taal

// *** Also read standard language file, for editing screen ***
$language_standard='nl';
if (file_exists($cms['cms_path'].'languages/'.$Taalkeuze.'/language.php')){
	$language_standard=$Taalkeuze;
}
include($cms['cms_path'].'languages/'.$language_standard.'/language.php'); //Taal

// *** Login check ***
$group_administrator='';
$group_editor='';
if (isset($_SERVER["PHP_AUTH_USER"])){
	// *** Logged in using .htacess ***

	// *** Standard group permissions ***
	$group_administrator='j';
	$group_editor='j';

	// *** If username = editor then change group permissions ***
	if ($_SERVER["PHP_AUTH_USER"]=='editor'){
		$group_administrator='n';
		$group_editor='j';
	}
}
elseif($page=='update') {
	// *** No log in, update procedure (group table will be changed) ***
}
else{
	// *** Logged in using PHP-MySQL ***
	@$query = "SELECT * FROM humo_users";
	@$result = mysql_query($query,$db);
	if (@mysql_num_rows($result) > 0){

		// *** humo-users table exists, check admin log in ***
		//if (isset($_SESSION["groeps_id_admin"]) AND $_SESSION["groeps_id_admin"] == "1") {
		if (isset($_SESSION["groeps_id_admin"])) {
			// *** Logged in as admin... ***

			// *** Read group settings ***
			$groepsql = mysql_query("SELECT * FROM humo_groups WHERE group_id='".$_SESSION["groeps_id_admin"]."'",$db);
			@$groepDb=mysql_fetch_object($groepsql) or die("Geen geldige gebruikersgroep/ No valid usergroup.");

			// *** Check if user is a administrator ***
			$group_administrator=$groepDb->group_admin;
			if ($group_administrator!='j'){ $page='login'; }

			// *** Check if user is a editor ***
			if (isset($groepDb->group_editor)){
				$group_editor=$groepDb->group_editor;
				if ($group_editor=='j'){ $page=''; }
			}
		}
		else{
			// *** Show log in screen ***
			$page='login';
		}

	}
	else{
		// *** No user table: probably first installation: everything will be visible! ***
	}
}

// *** Save ip adress in session to prevent session hijacking ***
if( isset( $_SESSION['huidig_ip'] ) == FALSE ){
	$_SESSION['huidig_ip'] = $_SERVER['REMOTE_ADDR'];
}

if (!$cms['cms']){
	// *** Generate header of HTML pages ***
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	 "http://www.w3.org/TR/html4/loose.dtd">'."\n";
	echo "<html>\n";
	echo "<head>\n";
	//echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8" >';
	echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'."\n";
	echo '<title>'.$language["index_name"].'</title>'."\n";
	echo '<link href="../images/favicon.ico" rel="shortcut icon" type="image/x-icon">';
	echo '<link href="admin.css" rel="stylesheet" type="text/css">';
	echo '<link href="menu/v1.css" rel="stylesheet" type="text/css" media="screen">';
	echo '<link href="statistieken/style.css" rel="stylesheet" type="text/css">'; // STYLE SHEET VOOR GRAFIEK	
	echo '</head>';
	echo '<body class="humo">';
}
else{
	JHTML::stylesheet('admin_joomla.css', $cms['cms_path'].'admin/');
	JHTML::stylesheet('v1.css', $cms['cms_path_admin'].'menu/');
	JHTML::stylesheet('style.css', $cms['cms_path_admin'].'statistieken/');
}

// *** Show top menu ***
echo '<div id="humo_top">';
	echo '<img src="images/humo-gen-kl.gif" align="left" alt="logo">';
	if ($cms['cms_name']=='Joomla'){
		$path_tmp='index.php?option=com_humo-gen&amp;task=admin';
	}
	else{
		$path_tmp='index.php';
	}
	print '<form method="POST" action="'.$path_tmp.'" style="display : inline;">';
	print ' <input type="Submit" name="submit" value="'.$language["menu_admin"].' - '.$language["menu_main"].'">';
	print '</form>';

	if ($cms['cms_name']=='Joomla'){
		$path_tmp='index.php?option=com_humo-gen';
	}
	else{
		$path_tmp='../index.php';
	}
	print '<form method="POST" action="'.$path_tmp.'" style="display : inline;">';
	print ' <input type="Submit" name="submit" value="Website">';
	print '</form>';

	if (isset($_SESSION["gebruikersnaam_admin"])) {
		if ($cms['cms_name']=='Joomla'){
			$path_tmp='index.php?option=com_humo-gen&amp;task=admin&amp;uitloggen=1';
		}
		else{
			$path_tmp='index.php?uitloggen=1';
		}
		print '<form method="POST" action="'.$path_tmp.'" style="display : inline;">';
		print ' <input type="Submit" name="submit" value="'.$language["menu_logout"].'">';
		print '</form>';
	}

	//*** Talen keuze ***
	echo '&nbsp;&nbsp;&nbsp;';
	for ($i=0; $i<count($languagebestand); $i++){
		// *** Get language name ***
		include($cms['cms_path'].'languages/'.$languagebestand[$i].'/language_data.php');

		if ($cms['cms_name']=='Joomla'){
			$path_tmp='index.php?option=com_humo-gen&amp;task=admin&amp;taalkeuze='.$languagebestand[$i];
		}
		else{
			$path_tmp='index.php?taalkeuze='.$languagebestand[$i];
		}
		echo '<a href="'.$path_tmp.'" style="border-right:none; background:none;">';

		echo '<img src="'.$cms['cms_path'].'languages/'.$languagebestand[$i].'/flag.gif" title="'.$language["name"].'" alt="'.$language["name"].'"'; 
		if ($Taalkeuze!=$languagebestand[$i]){ echo ' style="border:none;"'; }
		echo '></a> ';
	}
	
echo '</div>';

// *** Show left menu ***
if ($show_menu_left==true and $page!='login'){
if ($cms['cms_name']=='Joomla'){
	$path_tmp='index.php?option=com_humo-gen&amp;task=admin&amp;';
}
else{
	$path_tmp='index.php?';
}

echo '<div id="humo_menu">';
	if ($group_administrator=='j'){
		echo '<p align=center><b>'.$language["menu_install"].'</b><br>';
		echo '<a href="'.$path_tmp.'page=install">'.$language["menu_install"].'</a><br>';
	}

	echo '<p align=center><b>'.$language["menu_trees"].'</b><br>';
	if ($group_administrator=='j'){
		echo '<a href="'.$path_tmp.'page=tree">'.$language["menu_trees"].'</a><br>';
	}

	echo '<a href="'.$path_tmp.'page=editor">'.$language["menu_editor"].'</a><br>';

	if ($group_administrator=='j'){
		echo '<a href="'.$path_tmp.'page=check">'.$language["menu_check"].'</a><br>';
	}

	if ($group_administrator=='j'){
		echo '<p align=center><b>'.$language["menu_control"].'</b><br>';
		echo '<a href="'.$path_tmp.'page=settings">'.$language["menu_settings"].'</a><br>';
		echo '<a href="'.$path_tmp.'page=thumbs">'.$language["menu_thumbs"].'</a><br>';
		echo '<a href="'.$path_tmp.'page=links">'.$language["menu_links"].'</a><br>';

		echo '<p align=center><b>'.$language["menu_users"].'</b><br>';
		echo '<a href="'.$path_tmp.'page=users">'.$language["menu_users"].'</a><br>';
		echo '<a href="'.$path_tmp.'page=groups">'.$language["menu_groups"].'</a><br>';

		echo '<p align=center><b>'.$language["menu_backup"].'</b><br>';
		echo '<a href="'.$path_tmp.'page=backup">'.$language["menu_backup"].'</a><br>';
		echo '<a href="'.$path_tmp.'page=export">'.$language["menu_export"].'</a><br>';

		echo '<p align=center><b>'.$language["menu_logs"].'</b><br>';
		echo '<a href="'.$path_tmp.'page=log">'.$language["menu_log"].'</a><br>';
		echo '<a href="'.$path_tmp.'page=statistics">'.$language["menu_stats"].'</a><br>';
	}
echo '</div>';
}

// *** Show selected page, default page = admin homepage ***
echo '<div id="tekstvak">';
	define('ADMIN_PAGE', true); // *** Safety line ***

	if ($page!='login'){
		if (isset($_GET['page'])){ $page=$_GET['page']; }
		if (isset($_POST['page'])){ $page=$_POST['page']; }
	}

	// *** Editor group is only allowed to see editor screen ***
	if ($group_administrator!='j' AND $group_editor=='j'){ $page='editor'; } 

	if ($page=='install'){ include ("include/install.php"); }
	elseif ($page=='login'){ include ("include/login.php"); }
	elseif ($page=='tree'){ include ("include/trees.php"); }
	elseif ($page=='editor'){ include ("include/editor.php"); }
	elseif ($page=='check'){ include ("include/tree_check.php"); }
	elseif ($page=='gedcom'){ include ("include/gedcom.php"); }
	elseif ($page=='hzc'){ include ("include/hzc.php"); }
	elseif ($page=='hzd'){ include ("include/hzd.php"); }
	elseif ($page=='settings'){ include ("include/settings_admin.php"); }
	elseif ($page=='thumbs'){ include ("include/thumbs.php"); }
	elseif ($page=='links'){ include ("include/links.php"); }
	elseif ($page=='users'){ include ("include/users.php"); }
	elseif ($page=='groups'){ include ("include/groups.php"); }
	elseif ($page=='backup'){ include ("include/backup.php"); }
	elseif ($page=='export'){ include ("include/gedcom_export.php"); }
	elseif ($page=='log'){ include ("include/log.php"); }
	elseif ($page=='statistics'){ include ("include/statistics.php"); }
	elseif ($page=='update'){ include ("include/update.php"); }
	else{ include ("include/index_inc.php"); }
echo '</div>';

if (!$cms['cms']){
	print "</body>\n";
	print "</html>";
}

//@mysql_close(); // *** Close database connection ***
?>
Return current item: HuMo-gen