Location: PHPKode > projects > iLP System > Release 2.2/upload/statistics.php
<?php
/**
 * iLP System Statistiken
 * 
 * Autor:		Florian "ApoY2k" Peschka
 * Projekt:		iLP System
 * Paket:		apoy2k.ilp.wrynn
 * Lizenz:		CreativeCommons (by-nc-sa)
 * Kontakt:		hide@address.com
 * Version:		2.1.2
 */

// Zusätzliche Header laden
$tpl['headincludes'][] = 'statistics.form';

// Benutzer suchen
$get_users = $db->prepare("SELECT ilp_users.id AS user_id, ilp_users.char FROM ilp_users WHERE ilp_users.id != 0");
$get_users->execute();
$users = $get_users->fetchAll(PDO::FETCH_ASSOC);

// Datumsbeschränkungen berücksichtigen
$date_sql = 'AND ilp_events.date BETWEEN ';

if (isset($_POST['statistics_date_start']))
{
	$date_sql .= '\''.$_POST['statistics_date_start'].'\'';
	$tpl['date_start'] = $_POST['statistics_date_start'];
}
else
{
	$date_sql .= '\''.date('Y-m-d', 0).'\'';
	$tpl['date_start'] = '';
}

if (isset($_POST['statistics_date_end']))
{
	$date_sql .= ' AND \''.$_POST['statistics_date_end'].'\'';
	$tpl['date_end'] = $_POST['statistics_date_end'];
}
else
{
	$date_sql .= ' AND \''.date('Y-m-d').'\'';
	$tpl['date_end'] = '';
}

// Gesamtzahl der Raids
$get_all_events = $db->prepare("SELECT ilp_events.id FROM ilp_events WHERE 1 ".$date_sql);
$get_all_events->execute();
$all_event_count = $get_all_events->rowCount();

// Für jeden Benutzer die Berechnung der Beteiligung beginnen
foreach ($users as $user)
{
	// Ereignisse suchen, an denen der Spieler teilgenommen hat
	$get_events = $db->prepare("SELECT ilp_event_attends.id FROM ilp_event_attends, ilp_events WHERE ilp_event_attends.event_id = ilp_events.id AND ilp_event_attends.user_id = ? ".$date_sql);
	$get_events->execute(array($user['user_id']));
	$user_event_count = $get_events->rowCount();
	
	// Beute suchen, die der Spieler erhalten hat
	$get_loot = $db->prepare("SELECT ilp_loots.id, ilp_loots.value FROM ilp_loots, ilp_events WHERE ilp_loots.event_id = ilp_events.id AND ilp_loots.looter_id = ? ".$date_sql);
	$get_loot->execute(array($user['user_id']));
	$user_loot_count = $get_loot->rowCount();
	
	// Ausgegebene Punkte für die Beute des Spielers zusammenrechnen
	$user_loot_value = 0;
	while($loot_row = $get_loot->fetch(PDO::FETCH_ASSOC))
		{$user_loot_value = $user_loot_value + $loot_row['value'];}
	
	// Tea
	if (0 != $user_loot_count)
	{
		$user['tea'] = round((1 - exp(-1 * (($user_loot_value / 30) / $user_loot_count))) * 100, 2);
	}
	else
	{
		$user['tea'] = 100;
	}
	
	// Ninja
	if (0 != $user_event_count)
	{
		$user['ninja'] = round((1 - exp(-4 * ($user_loot_count / $user_event_count))) * 100, 2);
	}
	else
	{
		if (0 != $user_loot_count)
		{
			$user['ninja'] = 100;
		}
		else
		{
			$user['ninja'] = 0;
		}
	}
	
	// Attendance
	if (0 != $all_event_count)
	{
		$user['attendance'] = round(($user_event_count / $all_event_count) * 100, 2);
	}
	else
	{
		$user['attendance'] = 0;
	}
	
	$user['char'] = unserialize($user['char']);
	
	$tpl['users'][] = $user;
}
?>
Return current item: iLP System