Location: PHPKode > projects > HuMo-gen > admin/include/statistics.php
<?php
// *** Safety line ***
if (!defined('ADMIN_PAGE')){ exit; }

@set_time_limit(3000);

require_once('statistieken/maxChart.class.php'); // REQUIRE FOR STATISTICS
include ("../include/person_cls.php");
include ('../include/database_name.php');

if(function_exists('date_default_timezone_set')){
	date_default_timezone_set('Europe/Amsterdam');
}

echo '<h1 align=center>'.$language["stats_name"].'</h1>';

// *** Use a class to process person data ***
$persoon_cls = New persoon_cls;

// *** Show 1 statistics line ***
function stat_regel($gezinDb){
	global $db, $language, $persoon_cls, $Taalkeuze;

	echo '<tr>';
	if (isset($gezinDb->aantal)){ echo '<td>'.$gezinDb->aantal.'</td>'; }

	$treetext_name=database_name($gezinDb->tree_prefix, $Taalkeuze);		
	echo '<td>'.$treetext_name.'</td>';

	if (!isset($gezinDb->aantal)){ echo '<td>'.$gezinDb->stat_date_stat.'</td>'; }

	// *** Check if family is still in the genealogy! ***
	$controle_sql=mysql_query("SELECT * FROM ".$gezinDb->tree_prefix."family
		WHERE fam_gedcomnumber='$gezinDb->stat_gedcom_fam'",$db);
	$controleDb=mysql_fetch_object($controle_sql);
	$controle=false;
	if ($controleDb AND $controleDb->fam_man==$gezinDb->stat_gedcom_man AND $controleDb->fam_woman==$gezinDb->stat_gedcom_woman){
		$controle=true;
	}

	if ($controle==true){
		print '<td><a href="../gezin.php?id='.$gezinDb->stat_gedcom_fam.'&amp;database='.$gezinDb->tree_prefix.
		'">'.$language["stats_fam"].' </a>';

		//*** Man ***
		$persoon=mysql_query("SELECT * FROM ".$gezinDb->tree_prefix."person
			WHERE pers_gedcomnumber='$gezinDb->stat_gedcom_man'",$db);
		$personDb=mysql_fetch_object($persoon);
		if (!$gezinDb->stat_gedcom_man){
			echo 'N.N.';
		}
		else{
			$_SESSION['tree_prefix']=$gezinDb->tree_prefix;
			echo $persoon_cls->naam($personDb);
		}

		echo " &amp; ";
		//*** Woman ***
		$persoon=mysql_query("SELECT * FROM ".$gezinDb->tree_prefix."person
			WHERE pers_gedcomnumber='$gezinDb->stat_gedcom_woman'",$db);
		$personDb=mysql_fetch_object($persoon);
		if (!$gezinDb->stat_gedcom_woman){
			echo 'N.N.';
		}
		else{
			$_SESSION['tree_prefix']=$gezinDb->tree_prefix;
			echo $persoon_cls->naam($personDb);
		}
	}
	else{
		echo '<td><b>'.$language["stats_old_family"].'</b></td>';
	}
}

// *** Show 1 month, statistics calender ***
function kalender($maand, $jaar, $thismonth){
	global $db, $language, $stat_keuze;
	echo '<table class="humo" width="100%" border="1" cellspacing="0">';
	if ($maand=='1'){ $kalenderkop=$language["jan_lang"]; }
	if ($maand=='2'){ $kalenderkop=$language["feb_lang"]; }
	if ($maand=='3'){ $kalenderkop=$language["mrt_lang"]; }
	if ($maand=='4'){ $kalenderkop=$language["apr_lang"]; }
	if ($maand=='5'){ $kalenderkop=$language["mei_lang"]; }
	if ($maand=='6'){ $kalenderkop=$language["jun_lang"]; }
	if ($maand=='7'){ $kalenderkop=$language["jul_lang"]; }
	if ($maand=='8'){ $kalenderkop=$language["aug_lang"]; }
	if ($maand=='9'){ $kalenderkop=$language["sep_lang"]; }
	if ($maand=='10'){ $kalenderkop=$language["okt_lang"]; }
	if ($maand=='11'){ $kalenderkop=$language["nov_lang"]; }
	if ($maand=='12'){ $kalenderkop=$language["dec_lang"]; }
	echo '<tr class="tabel_kop"><th colspan="8">'.$kalenderkop.' '.$jaar.'</th></TR>';
	echo '<tr><th>Nr.</th><th>'.$language["stats_maandag"].'</th><th>'.$language["stats_dinsdag"].'</th><th>'.$language["stats_woensdag"].'</th><th>'.$language["stats_donderdag"].'</th><th>'.$language["stats_vrijdag"].'</th><th>'.$language["stats_zaterdag"].'</th><th>'.$language["stats_zondag"].'</th></tr>';
	$week=mktime (0,0,0,$maand,1,$jaar);
	$weeknummer = date ("W", $week);
	echo "<tr><th>$weeknummer</th>";

	// If neccesary skip days at start fo month
	$First_Day_Of_Month = date("w", mktime(0, 0, 0, $maand, 1, $jaar));
	if ($First_Day_Of_Month > "1") {
		echo '<td colspan="' . ($First_Day_Of_Month-1) . '"><br></td>';
	}
	// Sunday:
	if ($First_Day_Of_Month == "0") { echo '<td colspan="6"><br></td>'; }

	// Show days
	$Days_In_Month = cal_days_in_month(CAL_GREGORIAN, $maand, $jaar);
	$dag=1; $rij=1; $veld=$First_Day_Of_Month;
	if ($veld=='0'){ $veld=7; }  // First day is sunday.

	$i = 1;
	for ($i; $i <= $Days_In_Month ;$i++) {
		$datum_vandaag=date("Y-n-d");
		if ($dag<10){ $dag='0'.$dag; }
		$datum=$jaar.'-'.$maand.'-'.$dag;
		$gisteren=strtotime ($datum);
		$vandaag=$gisteren+86400;


		if ($stat_keuze=='visitors'){
			// *** Show visitors ***
			$datasql = mysql_query("SELECT stat_ip_address FROM humo_stat_date
				WHERE stat_date_linux > ".$gisteren." AND stat_date_linux < ".$vandaag.' GROUP BY stat_ip_address',$db);
		}
		else{
			// *** Show families ***
			$datasql = mysql_query("SELECT * FROM humo_stat_date
				WHERE stat_date_linux > ".$gisteren." AND stat_date_linux < ".$vandaag,$db);
		}

		if ($datasql){ $statistiek=mysql_num_rows($datasql); }

		// *** Use another colour for present day ***
		$kleur=''; if ($datum==$datum_vandaag){ $kleur=' bgcolor="#00FFFF"'; }

		echo "<td$kleur>$dag <b>$statistiek</b></td>";
		$dag++;
		if ($dag<=$Days_In_Month){
			$veld++;
			if ($veld == 8) {
				$week=mktime (0,0,0,$maand,$dag,$jaar);
				$weeknummer = date ("W", $week);
				echo "</tr>\n";
				echo "<tr><th>$weeknummer</th>";
				$rij++;
				$veld = 1;
			}
		}

		// *** Array for grafical statistics ***
		$data[$dag-1]=$statistiek;
	}

	// Add end month spacers
	if ((8 - $veld) >= "1") { echo '<td colspan="'.(8 - $veld).'"><br></td></tr>'; }

	// *** Always make 6 rows ***
	//if ($rij==5){ echo "</tr><tr><td colspan=8>&nbsp;<p>&nbsp;</td></tr>"; }
	if ($rij==5){ echo "</tr><tr><td colspan=8><br></td></tr>"; }

	echo "</table><br>\n";

	// *** Show grafical month statistics ***
	$dezemaand=$thismonth;
	$mc = new maxChart($data);
	$mc->displayChart($kalenderkop."&nbsp;".$jaar,1,700,200,false,$dezemaand);
}

// *** Function to show year statistics ***
function jaar_grafiek($maand, $jaar)  {
	 global $db, $language, $stat_keuze;
	 $beginmaand=$maand + 1;
	 $beginjaar=$jaar - 1;
	 if($maand==12) {
			$beginjaar=$jaar;
			$beginmaand=1;
	 }
	 for ($i=1; $i<13; $i++) {
		if($beginmaand==13) { $beginmaand=1; $beginjaar++; }

		$datum=$beginjaar.'-'.$beginmaand.'-'."1";   
		$eerstedag=strtotime ($datum);
		$Days_In_Month = cal_days_in_month(CAL_GREGORIAN, $beginmaand, $beginjaar);  
		$laatstedag=$eerstedag+(86400*$Days_In_Month);

		if ($stat_keuze=='visitors'){
			// *** Show visitors ***
			$datasql = mysql_query("SELECT stat_ip_address FROM humo_stat_date
				WHERE stat_date_linux > ".$eerstedag." AND stat_date_linux < ".$laatstedag."
				GROUP BY stat_ip_address",$db);
		}
		else{
		 // *** Show visited families ***
		 $datasql = mysql_query("SELECT * FROM humo_stat_date
			 WHERE stat_date_linux > ".$eerstedag." AND stat_date_linux < ".$laatstedag,$db);
		}

		if ($datasql){ $statistiek=mysql_num_rows($datasql); }

		if ($beginmaand=='1'){ $maandnaam=$language["date_jan"]; }
		if ($beginmaand=='2'){ $maandnaam=$language["date_feb"]; }
		if ($beginmaand=='3'){ $maandnaam=$language["date_mar"]; }
		if ($beginmaand=='4'){ $maandnaam=$language["date_apr"]; }
		if ($beginmaand=='5'){ $maandnaam=$language["date_may"]; }
		if ($beginmaand=='6'){ $maandnaam=$language["date_jun"]; }
		if ($beginmaand=='7'){ $maandnaam=$language["date_jul"]; }
		if ($beginmaand=='8'){ $maandnaam=$language["date_aug"]; }
		if ($beginmaand=='9'){ $maandnaam=$language["date_sep"]; }
		if ($beginmaand=='10'){ $maandnaam=$language["date_oct"]; }
		if ($beginmaand=='11'){ $maandnaam=$language["date_nov"]; }
		if ($beginmaand=='12'){ $maandnaam=$language["date_dec"]; }
		$kortjaar=substr($beginjaar,2);
		$twaalfmaanden[$maandnaam."&nbsp;".$kortjaar]=$statistiek;
		$beginmaand++;
	}
	$mc = new maxChart($twaalfmaanden);
	$dezemaand = date("n");

	if ($stat_keuze=='visitors'){
		$mc->displayChart($language["stats_visitors"],1,700,200,false,$dezemaand);
	}
	else{
		$mc->displayChart($language["stats_vorige_maanden"],1,700,200,false,$dezemaand);
	}

}
// End statistics

//*************BEGIN COUNTRY STATISTICS FUNCTIONS ******************
function iptocountry($ip, $pad) {
		$numbers = preg_split( "/\./", $ip);
		include($pad.$numbers[0].".php");

		$code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);

		foreach($ranges as $key => $value){
				if($key<=$code){
				    if($ranges[$key][0]>=$code){$country=$ranges[$key][1];break;}
				    }
		}
		if ($country==""){$country="unkown";}
		return $country;
}

function country(){
	global $db, $language;

	// *** For test purposes ***
	$pad='ip_files/';
	if (file_exists("../../humo-gen ip_files")){ $pad='../../humo-gen ip_files/'; }

	$stat=mysql_query("SELECT stat_ip_address FROM humo_stat_date GROUP BY stat_ip_address",$db);
	// Print out result
	while($row = mysql_fetch_array($stat)){
		$land=iptocountry($row['stat_ip_address'], $pad);
		//if ($landen[$land]) {
		if (isset($landen[$land])) {
			$landen[$land]++;
		}
		else {
			$landen[$land]=1;
		}
	}
	
	echo '<table class="humo" border="1" cellspacing="0" width="100%">';
	echo '<tr class="tabel_kop"><th>'.$language["stats_country_origin2"].'</th> <th>'.$language["stats_aantal"].'</th> </tr>';
	if (isset($landen)){
		arsort($landen);
		foreach ($landen as $key => $value) {
			include($pad."countries.php");
			echo '<tr><td>';
			//flag
			//$file_to_check="ip_files/flags/".$key.".gif";
			$file_to_check=$pad."flags/".$key.".gif";
			if (file_exists($file_to_check)){
				print '<img src="'.$file_to_check.'" width="30" height="15">';
			}
			else{
				print "<img src=flags/noflag.gif width=30 height=15>";
			}
			echo "&nbsp;";

			echo $countries[$key][1].'&nbsp;('.$key.')</td>';
			echo '<td>'.$value.'</td></tr>';
		}
	}

	echo '<tr><td>'.$language["stats_uniek"].'</td>';
	$totaal=mysql_num_rows($stat);
	echo '<td>'.$totaal.'</td></tr>';
	echo '</table>';

	//echo "<br>";
}
// ************ END COUNTRY STATISTICS FUNCTIONS  ***************

$stat_keuze='algemeen';
if (isset($_POST['stat_keuze']) AND $_POST['stat_keuze']=='datum'){ $stat_keuze='datum'; }
if (isset($_POST['stat_keuze']) AND $_POST['stat_keuze']=='visitors'){ $stat_keuze='visitors'; }
if (isset($_POST['stat_keuze']) AND $_POST['stat_keuze']=='oud'){ $stat_keuze='oud'; }
if (isset($_POST['stat_keuze']) AND $_POST['stat_keuze']=='remove'){ $stat_keuze='remove'; }
if (isset($_GET['tree_prefix'])){ $stat_keuze='oud'; }

// *** Keuze knoppen weergeven ***
echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo '<input type="hidden" name="stat_keuze" value="algemeen">';
	$stijl=''; if ($stat_keuze=='algemeen'){ $stijl=' class="geselecteerd"'; }
	echo '<input type="Submit" name="submit" value="'.$language["stats_algemeen"].'"'.$stijl.'>';
echo '</form>';

echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo ' <input type="hidden" name="stat_keuze" value="datum">';
	$stijl=''; if ($stat_keuze=='datum'){ $stijl=' class="geselecteerd"'; }
	echo '<input type="Submit" name="submit" value="'.$language["stats_datum"].'"'.$stijl.'>';
echo '</form>';

echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo ' <input type="hidden" name="stat_keuze" value="visitors">';
	$stijl=''; if ($stat_keuze=='visitors'){ $stijl=' class="geselecteerd"'; }
	echo '<input type="Submit" name="submit" value="'.$language["stats_visitors"].'"'.$stijl.'>';
echo '</form>';

echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo ' <input type="hidden" name="stat_keuze" value="oud">';
	$stijl=''; if ($stat_keuze=='oud'){ $stijl=' class="geselecteerd"'; }
	echo '<input type="Submit" name="submit" value="'.$language["stats_oud"].'"'.$stijl.'>';
echo '</form>';

echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo ' <input type="hidden" name="stat_keuze" value="remove">';
	$stijl=''; if ($stat_keuze=='remove'){ $stijl=' class="geselecteerd"'; }
	echo '<input type="Submit" name="submit" value="'.$language["stats_remove"].'"'.$stijl.'>';
echo '</form>';

// *** Remove old statistics ***
if (isset($_POST['remove2'])){
	$timestamp=mktime(0, 0, 0, $_POST['stat_month'], $_POST['stat_day'], $_POST['stat_year']);

	$sql='DELETE FROM humo_stat_date WHERE stat_date_linux < "'.$timestamp.'"';
	$result = mysql_query($sql);

	echo '<div class="confirm">';
	echo $language["stats_remove_before"].' '.date("d-m-Y", $timestamp).' '.$language["stats_remove_erased"];
	echo '</div>';
}

if ($stat_keuze=='remove'){
	echo '<h2>'.$language["stats_remove"].'</h2>';	

	echo $language["stats_remove_text"].'<br>';

	echo '<form method="POST" action="">';
	echo '<input type="hidden" name="page" value="'.$page.'">';
	echo $language["stats_remove_date"];
	echo ' <input type="text" name="stat_day" value="1" size="1">';
	$month=date("m"); $year=date("Y");
	$month--; if ($month==0){ $month=12; $year--; }
	echo ' <input type="text" name="stat_month" value="'.$month.'" size="1">	';

	echo ' <input type="text" name="stat_year" value="'.$year.'" size="2"> '.$language["stats_remove_dateformat"].'<br>';

	echo '<input type ="Submit" name="remove2" value="'.$language["stats_remove_button"].'">';
	echo '</form>';
}

if ($stat_keuze=='algemeen'){
	echo '<br><b>'.$language["stats_status"].'</b><br>';
	$gezin=mysql_query("SELECT *, count(humo_stat_date.stat_easy_id) as aantal
		FROM humo_stat_date LEFT JOIN humo_trees
		ON humo_trees.tree_id=humo_stat_date.stat_tree_id
		GROUP BY humo_stat_date.stat_tree_id
		ORDER BY tree_order desc",$db);
	echo '<table class="humo" border="1" cellspacing="0" width="100%">';
	echo '<tr class="tabel_kop"><th>'.$language["stats_stamboom"].'</th><th>Records</th><th>'.$language["stats_aantal"].'</th></tr>';
	while ($gezinDb=mysql_fetch_object($gezin)){
		//stat_regel($gezinDb);
		if ($gezinDb->tree_prefix){
			// *** Show family tree name ***
			$treetext_name=database_name($gezinDb->tree_prefix, $Taalkeuze);		
			echo '<tr><td>'.$treetext_name.'</td>';
		}
		else{
			echo '<tr><td><b>'.$language["stats_erased"].'</b></td>';
		}
		echo '<td>'.$gezinDb->aantal.'</td>';

		// *** Totaal aantal unieke bezoekers ***
		$bezoekers=0;
		if ($gezinDb->tree_id){
			$stat=mysql_query("SELECT *
				FROM humo_stat_date LEFT JOIN humo_trees
				ON humo_trees.tree_id=humo_stat_date.stat_tree_id
				WHERE humo_trees.tree_id=".$gezinDb->tree_id."
				GROUP BY stat_ip_address
				",$db);
			$bezoekers=mysql_num_rows($stat);
		}
		echo '<td>'.$bezoekers.'</td>';

	echo '</tr>';
	}
	echo '</table>';

	echo '<br><b>'.$language["stats_diverse"].'</b><br>';
	echo '<table class="humo" border="1" cellspacing="0" width="100%">';
	echo '<tr class="tabel_kop"><th>'.$language["stats_item"].'</th><th>'.$language["stats_teller"].'</th></tr>';
		// *** Totaal aantal unieke bezoekers ***
		$stat=mysql_query("SELECT * FROM humo_stat_date GROUP BY stat_ip_address",$db);
		$bezoekers=mysql_num_rows($stat);
		echo '<tr><td>'.$language["stats_uniek"].'</td><td>'.$bezoekers.'</td>';

		// *** Totaal aantal bezochte gezinnen ***
		$datasql = mysql_query("SELECT * FROM humo_stat_date",$db);
		if ($datasql){ $totaal=mysql_num_rows($datasql); }
		echo '<tr><td>'.$language["stats_gezinnen"].'</td><td>'.$totaal.'</td>';

		// Bezoekers per dag/ maand/ jaar mogelijk...
		//  //1 dag = 86400
		//if (strtotime ("now") - strtotime($advertentieDb->Datum) > 86400 ){ $verlopen='verlopen1'; }
		$tijdbestek=strtotime ("now")-3600; // 1 uur
		$datasql = mysql_query("SELECT * FROM humo_stat_date WHERE stat_date_linux > ".$tijdbestek,$db);
		if ($datasql){ $totaal=mysql_num_rows($datasql); }
		echo '<tr><td>'.$language["stats_gezinnen_uur"].'</td><td>'.$totaal.'</td>';
	echo '</table>';

	//******** START COUNTRY STATISTICS (second file check for test) *************
	if (file_exists("ip_files") OR file_exists("../../humo-gen ip_files")) {
		echo '<br><b>'.$language["stats_country_origin"].'</b><br>';
		country();
	}
	//******** END COUNTRY STATISTICS ********

	$aantal_regels=15; // *** Aantal weer te geven regels in onderstaande statistieken ***

	echo '<br><b>'.$aantal_regels.' '.$language["stats_mostvisitedfams"].'</b><br>';
	$gezin=mysql_query("SELECT *, count(humo_stat_date.stat_easy_id) as aantal
		FROM humo_stat_date, humo_trees
		WHERE humo_trees.tree_id=humo_stat_date.stat_tree_id
		GROUP BY humo_stat_date.stat_easy_id desc
		ORDER BY aantal desc
		LIMIT 0,".$aantal_regels,$db);
	echo '<table class="humo" border="1" cellspacing="0" width="100%">';
	echo '<tr class="tabel_kop"><th>#</th><th>'.$language["stats_stamboom"].'</th><th>'.$language["stats_gezin"].'</th></tr>';
	while ($gezinDb=mysql_fetch_object($gezin)){ stat_regel($gezinDb); }
	echo '</table>';

	echo '<br><b>'.$aantal_regels.' '.$language["stats_lastvisitedfams"].'</b><br>';
	$gezin=mysql_query("SELECT * FROM humo_stat_date, humo_trees
		WHERE humo_trees.tree_id=humo_stat_date.stat_tree_id
		ORDER BY humo_stat_date.stat_date_stat DESC LIMIT 0,".$aantal_regels,$db);

	echo '<table class="humo" border="1" cellspacing="0" width="100%">';
	echo '<tr class="tabel_kop"><th>'.$language["stats_stamboom"].'</th><th>'.$language["stats_datumtijd"].'</th><th>'.$language["stats_gezin"].'</th></tr>';
	while ($gezinDb=mysql_fetch_object($gezin)){ stat_regel($gezinDb); }
	echo '</table>';
}


if ($stat_keuze=='datum'){
	// *** Selectie van maand ***
	$maand_huidig = date("n");
	$maand = $maand_huidig;
	if (isset($_POST['maand'])){ $maand=$_POST['maand']; }

	echo '<br><form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		echo ' <input type="hidden" name="stat_keuze" value="datum">';
		print "<select size='1' name='maand'>";
			$select=''; if ($maand=='1'){ $select=' SELECTED'; }
			print '<option value="1"'.$select.'>'.$language["jan_lang"].'</option>';
			$select=''; if ($maand=='2'){ $select=' SELECTED'; }
			print '<option value="2"'.$select.'>'.$language["feb_lang"].'</option>';
			$select=''; if ($maand=='3'){ $select=' SELECTED'; }
			print '<option value="3"'.$select.'>'.$language["mrt_lang"].'</option>';
			$select=''; if ($maand=='4'){ $select=' SELECTED'; }
			print '<option value="4"'.$select.'>'.$language["apr_lang"].'</option>';
			$select=''; if ($maand=='5'){ $select=' SELECTED'; }
			print '<option value="5"'.$select.'>'.$language["mei_lang"].'</option>';
			$select=''; if ($maand=='6'){ $select=' SELECTED'; }
			print '<option value="6"'.$select.'>'.$language["jun_lang"].'</option>';
			$select=''; if ($maand=='7'){ $select=' SELECTED'; }
			print '<option value="7"'.$select.'>'.$language["jul_lang"].'</option>';
			$select=''; if ($maand=='8'){ $select=' SELECTED'; }
			print '<option value="8"'.$select.'>'.$language["aug_lang"].'</option>';
			$select=''; if ($maand=='9'){ $select=' SELECTED'; }
			print '<option value="9"'.$select.'>'.$language["sep_lang"].'</option>';
			$select=''; if ($maand=='10'){ $select=' SELECTED'; }
			print '<option value="10"'.$select.'>'.$language["okt_lang"].'</option>';
			$select=''; if ($maand=='11'){ $select=' SELECTED'; }
			print '<option value="11"'.$select.'>'.$language["nov_lang"].'</option>';
			$select=''; if ($maand=='12'){ $select=' SELECTED'; }
			print '<option value="12"'.$select.'>'.$language["dec_lang"].'</option>';
		print "</select>";

		// *** Selectie van jaar ***

		// *** In de database het oudste record zoeken ***
		$datasql = mysql_query("SELECT * FROM humo_stat_date ORDER BY stat_date_linux LIMIT 0,1",$db);
		$dataDb=mysql_fetch_object($datasql);
		$eerste_jaar = date("Y",$dataDb->stat_date_linux);

		$jaar_huidig = date("Y");
		$jaar=$jaar_huidig;
		if (isset($_POST['jaar'])){ $jaar=$_POST['jaar']; }

		print " <select size='1' name='jaar'>";
		for ($jaar_select=$eerste_jaar; $jaar_select<=$jaar_huidig; $jaar_select++) {
			$select='';
			if ($jaar==$jaar_select){ $select=' SELECTED'; }
			print '<option value="'.$jaar_select.'"'.$select.'>'.$jaar_select.'</option>';
		}
		print "</select>";

		echo ' <input type="Submit" name="submit" value="Select">';

	echo '</form>';

	// *** Bezochte gezinnen in de huidige maand ***
	//echo '<p><b>Totaal aantal bezochte gezinnen in de geselecteerde maand:</b><br>';
	echo '<br><b>'.$language["stats_gezinnen"].'</b><br>';

	// HUIDIGE MAAND GRAFIEK
	//echo '<p>';
	if ($maand==$maand_huidig AND $jaar==$jaar_huidig){
		kalender($maand, $jaar, true);
	}
	else{
		kalender($maand, $jaar, false);
	}

	// JAAR GRAFIEK
	echo "<br>";
	jaar_grafiek($maand, $jaar);
}

if ($stat_keuze=='visitors'){

	// *** Selectie van maand ***
	$maand_huidig = date("n");
	$maand = $maand_huidig;
	if (isset($_POST['maand'])){ $maand=$_POST['maand']; }

	echo '<br><form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		echo ' <input type="hidden" name="stat_keuze" value="visitors">';
		print "<select size='1' name='maand'>";
			$select=''; if ($maand=='1'){ $select=' SELECTED'; }
			print '<option value="1"'.$select.'>'.$language["jan_lang"].'</option>';
			$select=''; if ($maand=='2'){ $select=' SELECTED'; }
			print '<option value="2"'.$select.'>'.$language["feb_lang"].'</option>';
			$select=''; if ($maand=='3'){ $select=' SELECTED'; }
			print '<option value="3"'.$select.'>'.$language["mrt_lang"].'</option>';
			$select=''; if ($maand=='4'){ $select=' SELECTED'; }
			print '<option value="4"'.$select.'>'.$language["apr_lang"].'</option>';
			$select=''; if ($maand=='5'){ $select=' SELECTED'; }
			print '<option value="5"'.$select.'>'.$language["mei_lang"].'</option>';
			$select=''; if ($maand=='6'){ $select=' SELECTED'; }
			print '<option value="6"'.$select.'>'.$language["jun_lang"].'</option>';
			$select=''; if ($maand=='7'){ $select=' SELECTED'; }
			print '<option value="7"'.$select.'>'.$language["jul_lang"].'</option>';
			$select=''; if ($maand=='8'){ $select=' SELECTED'; }
			print '<option value="8"'.$select.'>'.$language["aug_lang"].'</option>';
			$select=''; if ($maand=='9'){ $select=' SELECTED'; }
			print '<option value="9"'.$select.'>'.$language["sep_lang"].'</option>';
			$select=''; if ($maand=='10'){ $select=' SELECTED'; }
			print '<option value="10"'.$select.'>'.$language["okt_lang"].'</option>';
			$select=''; if ($maand=='11'){ $select=' SELECTED'; }
			print '<option value="11"'.$select.'>'.$language["nov_lang"].'</option>';
			$select=''; if ($maand=='12'){ $select=' SELECTED'; }
			print '<option value="12"'.$select.'>'.$language["dec_lang"].'</option>';
		print "</select>";

		// *** Selectie van jaar ***

		// *** In de database het oudste record zoeken ***
		$datasql = mysql_query("SELECT * FROM humo_stat_date ORDER BY stat_date_linux LIMIT 0,1",$db);
		$dataDb=mysql_fetch_object($datasql);
		$eerste_jaar = date("Y",$dataDb->stat_date_linux);

		$jaar_huidig = date("Y");
		$jaar=$jaar_huidig;
		if (isset($_POST['jaar'])){ $jaar=$_POST['jaar']; }

		print " <select size='1' name='jaar'>";
		for ($jaar_select=$eerste_jaar; $jaar_select<=$jaar_huidig; $jaar_select++) {
			$select='';
			if ($jaar==$jaar_select){ $select=' SELECTED'; }
			print '<option value="'.$jaar_select.'"'.$select.'>'.$jaar_select.'</option>';
		}
		print "</select>";

		echo ' <input type="Submit" name="submit" value="Select">';

	echo '</form>';

	// *** Visitors in present month ***
	echo '<br><b>'.$language["stats_visitors"].'</b><br>';

	// HUIDIGE MAAND GRAFIEK
	//echo '<p>';
	if ($maand==$maand_huidig AND $jaar==$jaar_huidig){
		kalender($maand, $jaar, true);
	}
	else{
		kalender($maand, $jaar, false);
	}

	// JAAR GRAFIEK
	echo "<br>";
	jaar_grafiek($maand, $jaar);

	// *** User agent ***
	echo '<br><b>'.$language["stats_user_agent"].'</b><br>';
	// *** Weergeven user agent informatie (50 meest gebruikte user agents) ***
	$datasql=mysql_query("SELECT *, count(humo_stat_date.stat_user_agent) as aantal
		FROM humo_stat_date
		WHERE stat_user_agent LIKE '_%'
		GROUP BY humo_stat_date.stat_user_agent desc
		ORDER BY aantal desc
		LIMIT 0,50",$db);
		//LIMIT 0,".$aantal_regels,$db);
	
	while ($dataDb=mysql_fetch_object($datasql)){
		$stat_user_agent=$dataDb->stat_user_agent;
		if (count_chars($stat_user_agent)>100){
			$stat_user_agent=substr($stat_user_agent,0,100).'...';			
		}
		echo '<b>'.$dataDb->aantal.'</b> '.$stat_user_agent.'<br>';		
	}

}



if ($stat_keuze=='oud'){

	// *************************
	// *** OUDE Statistieken ***
	// *************************

	//Voorvoegsel wijzigen
	if (isset($_GET['tree_prefix'])){
		$_SESSION['tree_prefix']=$_GET['tree_prefix'];
	}
	if (!isset($_SESSION["tree_prefix"])){
		$datasql = mysql_query("SELECT * FROM humo_trees ORDER BY tree_order",$db);
		@$dataDb=mysql_fetch_object($datasql);
		$_SESSION['tree_prefix']=$dataDb->tree_prefix;
	}

	// *** Database selecteren ***
	@$datasql = mysql_query("SELECT * FROM humo_trees ORDER BY tree_order",$db);

	$num_rows = mysql_num_rows($datasql);
	if ($num_rows>1){
		print '<h2>'.$language["stats_old_text"].'</h2>';

		print '<b>'.$language["stats_select_tree"].'</b><br>';
		while (@$dataDb=mysql_fetch_object($datasql)){
			if ($dataDb->tree_prefix!='LEEG'){
			//AANTAL personen en gezinnen berekenen
			$persoon=mysql_query("SELECT * FROM ".$dataDb->tree_prefix."person",$db);
			@$personen=mysql_num_rows($persoon);

			$gezin=mysql_query("SELECT * FROM ".$dataDb->tree_prefix."family",$db);
			@$gezinnen=mysql_num_rows($gezin);

			// *** Update datum ***
			$datum=$dataDb->tree_date;
			$maand=''; //voor lege datums
				if (substr($datum,5,2)=='01'){ $maand=' jan ';}
				if (substr($datum,5,2)=='02'){ $maand=' feb ';}
				if (substr($datum,5,2)=='03'){ $maand=' mrt ';}
				if (substr($datum,5,2)=='04'){ $maand=' apr ';}
				if (substr($datum,5,2)=='05'){ $maand=' mei ';}
				if (substr($datum,5,2)=='06'){ $maand=' jun ';}
				if (substr($datum,5,2)=='07'){ $maand=' jul ';}
				if (substr($datum,5,2)=='08'){ $maand=' aug ';}
				if (substr($datum,5,2)=='09'){ $maand=' sep ';}
				if (substr($datum,5,2)=='10'){ $maand=' okt ';}
				if (substr($datum,5,2)=='11'){ $maand=' nov ';}
				if (substr($datum,5,2)=='12'){ $maand=' dec ';}
			$datum=substr($datum,8,2).$maand.substr($datum,0,4);

			$treetext_name=database_name($dataDb->tree_prefix, $Taalkeuze);		
			if (isset($_SESSION['tree_prefix']) AND $_SESSION['tree_prefix']==$dataDb->tree_prefix){
				echo "<b>".$treetext_name."</b>";
			}
			else{
				echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$page.'&amp;tree_prefix='.$dataDb->tree_prefix.'">'.$treetext_name.'</a>';
			}
			print ' <font size=-1>('.$datum.': '.$personen.' '.$language["main_nr_persons"].", ".$gezinnen.' '.$language["main_nr_fams"].")</font>\n<br>";
			}
		}
	}

	//*** Statistieken ***
	echo '<br><b>'.$language["stats_mostvisitedfams"].'</b><br>';

		//MAXIMAAL 50 REGELS!!!
		$gezin=mysql_query("SELECT * FROM ".$_SESSION['tree_prefix']."family
			WHERE fam_counter ORDER BY fam_counter desc LIMIT 0,50",$db);
		while ($gezinDb=mysql_fetch_object($gezin)){
			echo $gezinDb->fam_counter." ";

			print '<a href="../gezin.php?id='.$gezinDb->fam_gedcomnumber.'">'.$language["stats_fam"].' </a>';

			//*** Man ***
			$persoon=mysql_query("SELECT * FROM ".$_SESSION['tree_prefix']."person
				WHERE pers_gedcomnumber='$gezinDb->fam_man'",$db);
			$personDb=mysql_fetch_object($persoon);
			if (!$gezinDb->fam_man){
				echo 'N.N.';
			}
			else{
				echo $persoon_cls->naam($personDb);
			}

			echo " &amp; ";

			//*** Vrouw ***
			$persoon=mysql_query("SELECT * FROM ".$_SESSION['tree_prefix']."person WHERE pers_gedcomnumber='$gezinDb->fam_woman'",$db);
			$personDb=mysql_fetch_object($persoon);
			if (!$gezinDb->fam_woman){
				echo 'N.N.';
			}
			else{
				echo $persoon_cls->naam($personDb);
			}
			echo "<br>";
		}
	// *** Einde oude statistieken ***
}
?>
Return current item: HuMo-gen