<?php include('inc/header.php'); ?>
<h1>Management - Spendenübersichten</h1>
<div class="container">
<?php
	odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
	
	$intRevenuesOfAllTime = odbc_result(odbc_exec($odbc_connect, 'SELECT SUM([worth]) as "Einnahmen" FROM [LOG_DONATIONS] WHERE [state] = 1'), 'Einnahmen');
	$langNameOfMonth = array(
		1=>"Januar",
		2=>"Februar",
		3=>"M&auml;rz",
		4=>"April",
		5=>"Mai",
		6=>"Juni",
		7=>"Juli",
		8=>"August",
		9=>"September",
		10=>"Oktober",
		11=>"November",
		12=>"Dezember");
	$mixedDateArray = array(
		2012 => array(11, 12),
		2013 => array(1, 2, 3, 4)
	);

	echo '
<div class="table">
	<div class="thead">
		<div class="tr">
			<div class="p50">Gesamteinnahmen seit dem Start:</div>
			<div class="p50 center">Gesamteinnahmen: ' . $intRevenuesOfAllTime . ' &euro;</div>
		</div>
	</div>
</div>';
	
	foreach($mixedDateArray as $year => $intMonthArray) {
		foreach($intMonthArray as $month) {
			
			$intRevenuesOfMonth = odbc_result(odbc_exec($odbc_connect, 'SELECT SUM([worth]) as "Einnahmen" FROM [LOG_DONATIONS] WHERE [state] = 1 AND YEAR([dbo].[formatTimestamp]([timestamp])) = ' . $year . ' AND MONTH([dbo].[formatTimestamp]([timestamp])) = ' . $month), 'Einnahmen');
			$queryDailyRevenues = '
				SELECT	SUM([worth]) as "Einnahmen",
						DAY([dbo].[formatTimestamp]([timestamp])) as "Tag"
				FROM [LOG_DONATIONS]
				WHERE [state] = 1 AND YEAR([dbo].[formatTimestamp]([timestamp])) = ' . $year . ' AND MONTH([dbo].[formatTimestamp]([timestamp])) = ' . $month . '
				GROUP BY DAY([dbo].[formatTimestamp]([timestamp])), [state]
				ORDER BY "Tag"
			';
			$odbcExecDailyRevenues = @odbc_exec($odbc_connect, $queryDailyRevenues);
			while($odbcArrayRevenuesOfDay = @odbc_fetch_array($odbcExecDailyRevenues)) {
				$intRevenuesOfDayArray[$odbcArrayRevenuesOfDay['Tag']] = $odbcArrayRevenuesOfDay['Einnahmen'];
			}
			
			
			
			echo '
<div class="table">
	<div class="thead" onclick="switching(\'' . $year.$month . '\');" style="cursor: pointer;">
		<div class="tr">
			<div class="p50" style="font-weight: bold;">' . $year . ': ' . $langNameOfMonth[$month] . '</div>
			<div class="p50 center">Gesamteinnahmen: ' . $intRevenuesOfMonth . ' &euro;</div>
		</div>
	</div>
	<div id="' . $year.$month . '" class="tbody" style="display: none;">';
			for($i = 1; $i <= date("t", mktime(0, 0, 0, $month, 1, 1)); $i++) {
				if(!empty($intRevenuesOfDayArray[$i])) {
					$intRevenuesOfDayArray[$i] = $intRevenuesOfDayArray[$i] . ' &euro;';
				}
				else {
					$intRevenuesOfDayArray[$i] = '-';
				}
				echo '
		<div class="tr">
			<div class="p20">&nbsp;</div>
			<div class="p30">' . $i . '</div>
			<div class="p50 center">' . $intRevenuesOfDayArray[$i]  . '</div>
		</div>
				';
			}
			$intRevenuesOfDayArray = '';
		echo '
	</div>
</div>';
		}
	}
?>
</div>
<?php include('inc/footer.php'); ?>