diff --git a/modules/statistics/bin/loganalyzer.php b/modules/statistics/bin/loganalyzer.php
index 37578856b2dc07b38383b06893d9e4f12b49f264..bf9a1641893d805a55aaacc93cc0e892ccecddd4 100755
--- a/modules/statistics/bin/loganalyzer.php
+++ b/modules/statistics/bin/loganalyzer.php
@@ -1,93 +1,89 @@
 #!/usr/bin/env php
 <?php
 
-
 // This is the base directory of the SimpleSAMLphp installation
 $baseDir = dirname(dirname(dirname(dirname(__FILE__))));
 
 // Add library autoloader.
 require_once($baseDir . '/lib/_autoload.php');
 
-/* Initialize the configuration. */
+// Initialize the configuration.
 $configdir = SimpleSAML\Utils\Config::getConfigDir();
 SimpleSAML_Configuration::setConfigDir($configdir);
-
 SimpleSAML\Utils\Time::initTimezone();
 
 $progName = array_shift($argv);
-$debug = FALSE;
-$dryrun = FALSE;
+$debug = false;
+$dryrun = false;
 
 foreach($argv as $a) {
-	if(strlen($a) === 0) continue;
-
-	if(strpos($a, '=') !== FALSE) {
-		$p = strpos($a, '=');
-		$v = substr($a, $p + 1);
-		$a = substr($a, 0, $p);
-	} else {
-		$v = NULL;
-	}
-
-	/* Map short options to long options. */
-	$shortOptMap = array(
-		'-d' => '--debug',
-	);
-	if(array_key_exists($a, $shortOptMap))  $a = $shortOptMap[$a];
-
-	switch($a) {
-		case '--help':
-			printHelp();
-			exit(0);
-		case '--debug':
-			$debug = TRUE;
-			break;
-		case '--dry-run':
-			$dryrun = TRUE;
-			break;
-		default:
-			echo('Unknown option: ' . $a . "\n");
-			echo('Please run `' . $progName . ' --help` for usage information.' . "\n");
-			exit(1);
-		}
+    if (strlen($a) === 0) {
+        continue;
+    }
+    if (strpos($a, '=') !== false) {
+        $p = strpos($a, '=');
+        $v = substr($a, $p + 1);
+        $a = substr($a, 0, $p);
+    } else {
+        $v = null;
+    }
+
+    // Map short options to long options.
+    $shortOptMap = array('-d' => '--debug');
+    if (array_key_exists($a, $shortOptMap)) {
+        $a = $shortOptMap[$a];
+    }
+    switch ($a) {
+        case '--help':
+            printHelp();
+            exit(0);
+        case '--debug':
+            $debug = true;
+            break;
+        case '--dry-run':
+            $dryrun = true;
+            break;
+        default:
+            echo('Unknown option: ' . $a . "\n");
+            echo('Please run `' . $progName . ' --help` for usage information.' . "\n");
+            exit(1);
+    }
 }
 
-$aggregator = new sspmod_statistics_Aggregator(TRUE);
+$aggregator = new sspmod_statistics_Aggregator(true);
 $aggregator->dumpConfig();
 $aggregator->debugInfo();
 $results = $aggregator->aggregate($debug);
 $aggregator->debugInfo();
 
 if (!$dryrun) {
-	$aggregator->store($results);
+    $aggregator->store($results);
 }
 
-
 foreach ($results AS $slot => $val) {
-	 foreach ($val AS $sp => $no) {
-	 	echo $sp . " " . count($no) . " - ";
-	 }
-	 echo "\n";
+    foreach ($val AS $sp => $no) {
+        echo $sp . " " . count($no) . " - ";
+    }
+    echo "\n";
 }
 
 
-
-
 /**
  * This function prints the help output.
  */
+
 function printHelp() {
-	global $progName;
+    global $progName;
 
-	/*   '======================================================================' */
-	echo('Usage: ' . $progName . ' [options]
+    echo <<<END
+Usage: $progName [options]
 
 This program parses and aggregates SimpleSAMLphp log files.
 
 Options:
-	-d, --debug			Used when configuring the log file syntax. See doc.
-	--dry-run			Aggregate but do not store the results.
+ -d, --debug			Used when configuring the log file syntax. See doc.
+ --dry-run			Aggregate but do not store the results.
+END;
 
-');
 }
 
diff --git a/modules/statistics/bin/logcleaner.php b/modules/statistics/bin/logcleaner.php
index 3ed5e21119e08844831dca1ebbf1f077907f0132..b845a139602c756e9b28cde423fcba30057639f5 100755
--- a/modules/statistics/bin/logcleaner.php
+++ b/modules/statistics/bin/logcleaner.php
@@ -1,63 +1,61 @@
 #!/usr/bin/env php
 <?php
 
-
 // This is the base directory of the SimpleSAMLphp installation
 $baseDir = dirname(dirname(dirname(dirname(__FILE__))));
 
 // Add library autoloader.
 require_once($baseDir . '/lib/_autoload.php');
 
-/* Initialize the configuration. */
+// Initialize the configuration.
 $configdir = SimpleSAML\Utils\Config::getConfigDir();
 SimpleSAML_Configuration::setConfigDir($configdir);
 
-
-
 $progName = array_shift($argv);
-$debug = FALSE;
-$dryrun = FALSE;
+$debug = false;
+$dryrun = false;
 $output = '/tmp/simplesamlphp-new.log';
-$infile = NULL;
-
-foreach($argv as $a) {
-	if(strlen($a) === 0) continue;
-
-	if(strpos($a, '=') !== FALSE) {
-		$p = strpos($a, '=');
-		$v = substr($a, $p + 1);
-		$a = substr($a, 0, $p);
-	} else {
-		$v = NULL;
-	}
-
-	/* Map short options to long options. */
-	$shortOptMap = array(
-		'-d' => '--debug',
-	);
-	if(array_key_exists($a, $shortOptMap))  $a = $shortOptMap[$a];
-
-	switch($a) {
-		case '--help':
-			printHelp();
-			exit(0);
-		case '--debug':
-			$debug = TRUE;
-			break;
-		case '--dry-run':
-			$dryrun = TRUE;
-			break;
-		case '--infile':
-			$infile = $v;
-			break;
-		case '--outfile':
-			$output = $v;
-			break;
-		default:
-			echo('Unknown option: ' . $a . "\n");
-			echo('Please run `' . $progName . ' --help` for usage information.' . "\n");
-			exit(1);
-		}
+$infile = null;
+
+foreach ($argv as $a) {
+    if (strlen($a) === 0) {
+        continue;
+    }
+    if (strpos($a, '=') !== false) {
+        $p = strpos($a, '=');
+        $v = substr($a, $p + 1);
+        $a = substr($a, 0, $p);
+    } else {
+        $v = null;
+    }
+
+    // Map short options to long options.
+    $shortOptMap = array('-d' => '--debug');
+    if (array_key_exists($a, $shortOptMap)) {
+        $a = $shortOptMap[$a];
+    }
+
+    switch ($a) {
+        case '--help':
+            printHelp();
+            exit(0);
+        case '--debug':
+            $debug = true;
+            break;
+        case '--dry-run':
+            $dryrun = true;
+            break;
+        case '--infile':
+            $infile = $v;
+            break;
+        case '--outfile':
+            $output = $v;
+            break;
+        default:
+            echo('Unknown option: ' . $a . "\n");
+            echo('Please run `' . $progName . ' --help` for usage information.' . "\n");
+            exit(1);
+    }
 }
 
 $cleaner = new sspmod_statistics_LogCleaner($infile);
@@ -67,17 +65,18 @@ $todelete = $cleaner->clean($debug);
 echo "Cleaning these trackIDs: " . join(', ', $todelete) . "\n";
 
 if (!$dryrun) {
-	$cleaner->store($todelete, $output);
+    $cleaner->store($todelete, $output);
 }
 
 /**
  * This function prints the help output.
  */
+
 function printHelp() {
-	global $progName;
+    global $progName;
 
-	/*   '======================================================================' */
-	echo('Usage: ' . $progName . ' [options]
+    echo <<<END
+Usage: $progName [options]
 
 This program cleans logs. This script is experimental. Do not run it unless you have talked to Andreas about it. 
 The script deletes log lines related to sessions that produce more than 200 lines.
@@ -88,6 +87,6 @@ Options:
 	--infile			File input.
 	--outfile			File to output the results.
 
-');
+END;
 }
 
diff --git a/modules/statistics/config-templates/module_statistics.php b/modules/statistics/config-templates/module_statistics.php
index 8a866f939f345fa5b5d2e8dbb2f49460140a309e..3bf2c749716df48ecdf44e4f84526288ba3c5ed6 100644
--- a/modules/statistics/config-templates/module_statistics.php
+++ b/modules/statistics/config-templates/module_statistics.php
@@ -5,187 +5,184 @@
 
 $config = array (
 
-	// Authentication & authorization for statistics
+    // Authentication & authorization for statistics
 
-	// Whether the statistics require authentication before use.
-	'protected' => FALSE,
+    // Whether the statistics require authentication before use.
+    'protected' => false,
 
-	/* The authentication source that should be used. */
-	'auth' => 'admin',
+    // The authentication source that should be used.
+    'auth' => 'admin',
 
-	/* Alternative 1: List of allowed users. */
-	//'useridattr' => 'eduPersonPrincipalName',
-	//'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'),
+    // Alternative 1: List of allowed users.
+    //'useridattr' => 'eduPersonPrincipalName',
+    //'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'),
 
-	/* Alternative 2: External ACL list. */
-	//'acl' => 'adminlist',
+    // Alternative 2: External ACL list.
+    //'acl' => 'adminlist',
 
+    'default' => 'sso',
 
-
-	'default' => 'sso',
-
-	'statdir' => '/tmp/stats/',
-	'inputfile' => '/var/log/simplesamlphp.stat',
-	'offset' => 60*60*2 + 60*60*24*3, // Two hours offset to match epoch and norwegian winter time.
+    'statdir' => '/tmp/stats/',
+    'inputfile' => '/var/log/simplesamlphp.stat',
+    'offset' => 60*60*2 + 60*60*24*3, // Two hours offset to match epoch and norwegian winter time.
 	
-	'datestart' => 1,
-	'datelength' => 15,
-	'offsetspan' => 21,
+    'datestart' => 1,
+    'datelength' => 15,
+    'offsetspan' => 21,
 	
-	// Dimensions on graph from Google Charts in pixels...
-	'dimension.x' => 800,
-	'dimension.y' => 350,
+    // Dimensions on graph from Google Charts in pixels...
+    'dimension.x' => 800,
+    'dimension.y' => 350,
 	
-	/*
-	 * Do you want to generate statistics using the cron module? If so, specify which cron tag to use.
-	 * Examples: daily, weekly
-	 * To not run statistics in cron, set value to 
-	 *     'cron_tag' => NULL,
-	 */
-	'cron_tag' => 'daily',
+    /*
+     * Do you want to generate statistics using the cron module? If so, specify which cron tag to use.
+     * Examples: daily, weekly
+     * To not run statistics in cron, set value to 
+     *     'cron_tag' => null,
+     */
+    'cron_tag' => 'daily',
 
-	/*
-	 * Set max running time for this script. This is also controlle by max_execution_time in php.ini
-	 * and is defalut set to 30 sec. Your web server can have other timeout configurations that may
-	 * also interrupt PHP execution. Apache has a Timeout directive and IIS has a
-	 * CGI timeout function. Both default to 300 seconds.
-	 */
-	'time_limit' => 300,
+    /*
+     * Set max running time for this script. This is also controlle by max_execution_time in php.ini
+     * and is defalut set to 30 sec. Your web server can have other timeout configurations that may
+     * also interrupt PHP execution. Apache has a Timeout directive and IIS has a
+     * CGI timeout function. Both default to 300 seconds.
+     */
+    'time_limit' => 300,
 	
-	'timeres' => array(
-		'day' => array(
-			'name' => 'Day',
-			'slot'		=> 60*15,			// Slots of 15 minutes
-			'fileslot'	=> 60*60*24,		// One day (24 hours) file slots
-			'axislabelint' => 6*4,			// Number of slots per label. 4 per hour *6 = 6 hours 
-			'dateformat-period'	=> 'j. M', 			//  4. Mars
-			'dateformat-intra'	=> 'j. M H:i', 		//  4. Mars 12:30	
-		),
-		'week' => array(
-			'name' => 'Week',
-			'slot'		=> 60*60,			// Slots of one hour
-			'fileslot'	=> 60*60*24*7,		// 7 days of data in each file
-			'axislabelint' => 24,			// Number of slots per label. 24 is one each day
-			'dateformat-period'	=> 'j. M', 			//  4. Mars
-			'dateformat-intra'	=> 'j. M H:i', 		//  4. Mars 12:30
-		),
-		'month' => array(
-			'name' => 'Month',
-			'slot'		=> 60*60*24,		// Slots of one day
-			'fileslot'	=> 60*60*24*30,		// 30 days of data in each file
-			'axislabelint' => 7,			// Number of slots per label. 7 days => 1 week
-			'dateformat-period'	=> 'j. M Y H:i', 	//  4. Mars 12:30
-			'dateformat-intra'	=> 'j. M', 			//  4. Mars
-		),
-		'monthaligned' => array(
-			'name' => 'AlignedMonth',
-			'slot'		=> 60*60*24,		// Slots of one day
-			'fileslot'	=> NULL,		// 30 days of data in each file
-			'customDateHandler' => 'month',
-			'axislabelint' => 7,			// Number of slots per label. 7 days => 1 week
-			'dateformat-period'	=> 'j. M Y H:i', 	//  4. Mars 12:30
-			'dateformat-intra'	=> 'j. M', 			//  4. Mars
-		),
-		
-		'days180' => array(
-			'name' => '180 days',
-			'slot'		=> 60*60*24,		// Slots of 1 day (24 hours)
-			'fileslot'	=> 60*60*24*180,	// 80 days of data in each file
-			'axislabelint' => 30,			// Number of slots per label. 7 days => 1 week
-			'dateformat-period'	=> 'j. M', 		//  4. Mars
-			'dateformat-intra'	=> 'j. M', 		//  4. Mars
-		),
-	),
-	'statrules' => array(
-		'sloratio' => array(
-			'name' 		=> 'SLO to SSO ratio',
-			'descr'		=> 'Comparison of the number of Single Log-Out compared to Single Sign-On. Graph shows how many logouts where initiated for each Single Sign-On.',
-			'type' => 'calculated',
-			'presenter' => 'statistics:Ratio',
-			'ref' => array('slo', 'sso'),
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'ssomulti' => array(
-			'name' 		=> 'Requests per session',
-			'descr'		=> 'Number of SSO request pairs exchanged between IdP and SP within the same IdP session. A high number indicates that the session at the SP is timing out faster than at the IdP.',
-			'type' => 'calculated',
-			'presenter' => 'statistics:Ratio',
-			'ref' => array('sso', 'ssofirst'),
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'sso' => array(
-			'name' 		=> 'SSO to service',
-			'descr'		=> 'The number of logins at a Service Provider.',
-			'action' 	=> 'saml20-idp-SSO',
-			'col'		=> 6,				// Service Provider EntityID
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'ssofirst' => array(
-			'name' 		=> 'SSO-first to service',
-			'descr'		=> 'The number of logins at a Service Provider.',
-			'action' 	=> 'saml20-idp-SSO-first',
-			'col'		=> 6,				// Service Provider EntityID
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'slo' => array(
-			'name' 		=> 'SLO initiated from service',
-			'descr'		=> 'The number of initated Sinlge Logout from each of the service providers.',
-			'action' 	=> 'saml20-idp-SLO',
-			'col'		=> 7,				// Service Provider EntityID that initiated the logout.
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'consent' => array(
-			'name' 		=> 'Consent',
-			'descr'		=> 'Consent statistics. Everytime a user logs in to a service an entry is logged for one of three states: consent was found, consent was not found or consent storage was not available.',
-			'action' 	=> 'consent',
-			'col'		=> 6,
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'consentresponse' => array(
-			'name' 		=> 'Consent response',
-			'descr'		=> 'Consent response statistics. Everytime a user accepts consent, it is logged whether the user selected to remember the consent to next time.',
-			'action' 	=> 'consentResponse',
-			'col'		=> 6,
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-		'slopages' => array(
-			'name' 		=> 'SLO iframe pages',
-			'descr'		=> 'The varioust IFrame SLO pages a user visits',
-			'action' 	=> 'slo-iframe',
-			'col'		=> 6,				// Page the user visits.
-		),
-		'slofail' => array(
-			'name' 		=> 'Failed iframe IdP-init SLOs',
-			'descr'		=> 'The number of logout failures from various SPs',
-			'action' 	=> 'slo-iframe-fail',
-			'col'		=> 6,				// Service Provider EntityID that wasn't logged out.
-			'fieldPresentation' => array(
-				'class' => 'statistics:Entity',
-				'config' => 'saml20-sp-remote',
-			),
-		),
-	),
+    'timeres' => array(
+        'day' => array(
+            'name' => 'Day',
+            'slot'              => 60*15,            // Slots of 15 minutes
+            'fileslot'	        => 60*60*24,         // One day (24 hours) file slots
+            'axislabelint'      => 6*4,              // Number of slots per label. 4 per hour *6 = 6 hours 
+            'dateformat-period'	=> 'j. M',           //  4. Mars
+            'dateformat-intra'	=> 'j. M H:i',       //  4. Mars 12:30	
+        ),
+        'week' => array(
+            'name' => 'Week',
+            'slot'		=> 60*60,            // Slots of one hour
+            'fileslot'	        => 60*60*24*7,       // 7 days of data in each file
+            'axislabelint'      => 24,               // Number of slots per label. 24 is one each day
+            'dateformat-period'	=> 'j. M',           //  4. Mars
+            'dateformat-intra'	=> 'j. M H:i',       //  4. Mars 12:30
+        ),
+        'month' => array(
+            'name' => 'Month',
+            'slot'              => 60*60*24,         // Slots of one day
+            'fileslot'          => 60*60*24*30,      // 30 days of data in each file
+            'axislabelint'      => 7,                // Number of slots per label. 7 days => 1 week
+            'dateformat-period'	=> 'j. M Y H:i',     //  4. Mars 12:30
+            'dateformat-intra'	=> 'j. M',           //  4. Mars
+        ),
+        'monthaligned' => array(
+            'name'              => 'AlignedMonth',
+            'slot'              => 60*60*24,         // Slots of one day
+            'fileslot'          => null,             // 30 days of data in each file
+            'customDateHandler' => 'month',
+            'axislabelint'      => 7,                // Number of slots per label. 7 days => 1 week
+            'dateformat-period'	=> 'j. M Y H:i',     //  4. Mars 12:30
+            'dateformat-intra'	=> 'j. M',           //  4. Mars
+        ),
+        'days180' => array(
+            'name'              => '180 days',
+            'slot'              => 60*60*24,         // Slots of 1 day (24 hours)
+            'fileslot'          => 60*60*24*180,     // 80 days of data in each file
+            'axislabelint'      => 30,               // Number of slots per label. 7 days => 1 week
+            'dateformat-period' => 'j. M',           //  4. Mars
+            'dateformat-intra'  => 'j. M',           //  4. Mars
+        ),
+    ),
 
-);
+    'statrules' => array(
+        'sloratio' => array(
+            'name'         => 'SLO to SSO ratio',
+            'descr'        => 'Comparison of the number of Single Log-Out compared to Single Sign-On. Graph shows how many logouts where initiated for each Single Sign-On.',
+            'type'         => 'calculated',
+            'presenter'    => 'statistics:Ratio',
+            'ref'          => array('slo', 'sso'),
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'ssomulti' => array(
+            'name'         => 'Requests per session',
+            'descr'        => 'Number of SSO request pairs exchanged between IdP and SP within the same IdP session. A high number indicates that the session at the SP is timing out faster than at the IdP.',
+            'type'         => 'calculated',
+            'presenter'    => 'statistics:Ratio',
+            'ref'          => array('sso', 'ssofirst'),
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'sso' => array(
+            'name'         => 'SSO to service',
+            'descr'        => 'The number of logins at a Service Provider.',
+            'action'       => 'saml20-idp-SSO',
+            'col'          => 6,                     // Service Provider EntityID
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'ssofirst' => array(
+            'name'         => 'SSO-first to service',
+            'descr'        => 'The number of logins at a Service Provider.',
+            'action'       => 'saml20-idp-SSO-first',
+            'col'          => 6,                     // Service Provider EntityID
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'slo' => array(
+            'name'         => 'SLO initiated from service',
+            'descr'        => 'The number of initated Sinlge Logout from each of the service providers.',
+            'action'       => 'saml20-idp-SLO',
+            'col'          => 7,                     // Service Provider EntityID that initiated the logout.
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'consent' => array(
+            'name'         => 'Consent',
+            'descr'        => 'Consent statistics. Everytime a user logs in to a service an entry is logged for one of three states: consent was found, consent was not found or consent storage was not available.',
+            'action'       => 'consent',
+            'col'          => 6,
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'consentresponse' => array(
+            'name'         => 'Consent response',
+            'descr'        => 'Consent response statistics. Everytime a user accepts consent, it is logged whether the user selected to remember the consent to next time.',
+            'action'       => 'consentResponse',
+            'col'          => 6,
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+        'slopages' => array(
+            'name'         => 'SLO iframe pages',
+            'descr'        => 'The varioust IFrame SLO pages a user visits',
+            'action'       => 'slo-iframe',
+            'col'          => 6,                     // Page the user visits.
+        ),
+        slofail' => array(
+            'name'         => 'Failed iframe IdP-init SLOs',
+            'descr'        => 'The number of logout failures from various SPs',
+            'action'       => 'slo-iframe-fail',
+            'col'          => 6,                     // Service Provider EntityID that wasn't logged out.
+            'fieldPresentation' => array(
+                'class'    => 'statistics:Entity',
+                'config'   => 'saml20-sp-remote',
+            ),
+        ),
+    ),
 
+);
diff --git a/modules/statistics/hooks/hook_cron.php b/modules/statistics/hooks/hook_cron.php
index cff0093c522f418c681eabb70f0997999fe29e72..15bea92960c27b184eb0b2cece12d87317ce67ec 100644
--- a/modules/statistics/hooks/hook_cron.php
+++ b/modules/statistics/hooks/hook_cron.php
@@ -4,32 +4,37 @@
  *
  * @param array &$croninfo  Output
  */
-function statistics_hook_cron(&$croninfo) {
-	assert('is_array($croninfo)');
-	assert('array_key_exists("summary", $croninfo)');
-	assert('array_key_exists("tag", $croninfo)');
+function statistics_hook_cron(&$croninfo)
+{
+    assert('is_array($croninfo)');
+    assert('array_key_exists("summary", $croninfo)');
+    assert('array_key_exists("tag", $croninfo)');
 
-	$statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
+    $statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
 	
-	if (is_null($statconfig->getValue('cron_tag', NULL))) return;
-	if ($statconfig->getValue('cron_tag', NULL) !== $croninfo['tag']) return;
+    if (is_null($statconfig->getValue('cron_tag', nul))) {
+        return;
+    }
+    if ($statconfig->getValue('cron_tag', null) !== $croninfo['tag']) {
+        return;
+    }
 	
-	$maxtime = $statconfig->getInteger('time_limit', NULL);
-	if($maxtime){
-		set_time_limit($maxtime);
-	}
+    $maxtime = $statconfig->getInteger('time_limit', null);
+    if ($maxtime) {
+        set_time_limit($maxtime);
+    }
 	
-	try {
-		$aggregator = new sspmod_statistics_Aggregator();
-		$results = $aggregator->aggregate();
-		if (empty($results)) {
-			SimpleSAML\Logger::notice('Output from statistics aggregator was empty.');
-		} else {
-			$aggregator->store($results);
-		}
-	} catch (Exception $e) {
-		$message = 'Loganalyzer threw exception: ' . $e->getMessage();
-		SimpleSAML\Logger::warning($message);
-		$croninfo['summary'][] = $message;
-	}
+    try {
+        $aggregator = new sspmod_statistics_Aggregator();
+        $results = $aggregator->aggregate();
+        if (empty($results)) {
+            SimpleSAML\Logger::notice('Output from statistics aggregator was empty.');
+        } else {
+            $aggregator->store($results);
+        }
+    } catch (Exception $e) {
+        $message = 'Loganalyzer threw exception: ' . $e->getMessage();
+        SimpleSAML\Logger::warning($message);
+        $croninfo['summary'][] = $message;
+    }
 }
diff --git a/modules/statistics/hooks/hook_frontpage.php b/modules/statistics/hooks/hook_frontpage.php
index b8fbc724c1603c8287414d749104c9f9cb5a91c8..69a054b35fe36a6d0c532a3af15cd7052cee560c 100644
--- a/modules/statistics/hooks/hook_frontpage.php
+++ b/modules/statistics/hooks/hook_frontpage.php
@@ -4,18 +4,19 @@
  *
  * @param array &$links  The links on the frontpage, split into sections.
  */
-function statistics_hook_frontpage(&$links) {
-	assert('is_array($links)');
-	assert('array_key_exists("links", $links)');
+function statistics_hook_frontpage(&$links)
+{
+    assert('is_array($links)');
+    assert('array_key_exists("links", $links)');
 
-	$links['config']['statistics'] = array(
-		'href' => SimpleSAML\Module::getModuleURL('statistics/showstats.php'),
-		'text' => array('en' => 'Show statistics', 'no' => 'Vis statistikk'),
-		'shorttext' => array('en' => 'Statistics', 'no' => 'Statistikk'),
-	);
-	$links['config']['statisticsmeta'] = array(
-		'href' => SimpleSAML\Module::getModuleURL('statistics/statmeta.php'),
-		'text' => array('en' => 'Show statistics metadata', 'no' => 'Vis statistikk metadata'),
-		'shorttext' => array('en' => 'Statistics metadata', 'no' => 'Statistikk metadata'),
-	);
+    $links['config']['statistics'] = array(
+        'href' => SimpleSAML\Module::getModuleURL('statistics/showstats.php'),
+        'text' => array('en' => 'Show statistics', 'no' => 'Vis statistikk'),
+        'shorttext' => array('en' => 'Statistics', 'no' => 'Statistikk'),
+    );
+    $links['config']['statisticsmeta'] = array(
+        'href' => SimpleSAML\Module::getModuleURL('statistics/statmeta.php'),
+        'text' => array('en' => 'Show statistics metadata', 'no' => 'Vis statistikk metadata'),
+        'shorttext' => array('en' => 'Statistics metadata', 'no' => 'Statistikk metadata'),
+    );
 }
diff --git a/modules/statistics/hooks/hook_sanitycheck.php b/modules/statistics/hooks/hook_sanitycheck.php
index 236802c48ef15003cd4acfe839f663b011e284f8..ff84c27c80ade7bbc39c83fcb4360613d77a883d 100644
--- a/modules/statistics/hooks/hook_sanitycheck.php
+++ b/modules/statistics/hooks/hook_sanitycheck.php
@@ -4,35 +4,35 @@
  *
  * @param array &$hookinfo  hookinfo
  */
-function statistics_hook_sanitycheck(&$hookinfo) {
-	assert('is_array($hookinfo)');
-	assert('array_key_exists("errors", $hookinfo)');
-	assert('array_key_exists("info", $hookinfo)');
+function statistics_hook_sanitycheck(&$hookinfo)
+{
+    assert('is_array($hookinfo)');
+    assert('array_key_exists("errors", $hookinfo)');
+    assert('array_key_exists("info", $hookinfo)');
 
-	try {
-		$statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
-	} catch(Exception $e) {
-		$hookinfo['errors'][] = '[statistics] Could not get configuration: ' . $e->getMessage(); return;
-	}
+    try {
+        $statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
+    } catch(Exception $e) {
+        $hookinfo['errors'][] = '[statistics] Could not get configuration: ' . $e->getMessage(); return;
+    }
 
-	$statdir = $statconfig->getValue('statdir');
-	$inputfile = $statconfig->getValue('inputfile');
+    $statdir = $statconfig->getValue('statdir');
+    $inputfile = $statconfig->getValue('inputfile');
 
-	if (file_exists($statdir)) {
-		$hookinfo['info'][] = '[statistics] Statistics dir [' . $statdir . '] exists';
-		if (is_writable($statdir)) {
-			$hookinfo['info'][] = '[statistics] Statistics dir [' . $statdir . '] is writable';
-		} else {
-			$hookinfo['errors'][] = '[statistics] Statistics dir [' . $statdir . '] is not writable';
-		}
-	} else {
-		$hookinfo['errors'][] = '[statistics] Statistics dir [' . $statdir . '] does not exists';
-	}
+    if (file_exists($statdir)) {
+        $hookinfo['info'][] = '[statistics] Statistics dir [' . $statdir . '] exists';
+        if (is_writable($statdir)) {
+            $hookinfo['info'][] = '[statistics] Statistics dir [' . $statdir . '] is writable';
+        } else {
+            $hookinfo['errors'][] = '[statistics] Statistics dir [' . $statdir . '] is not writable';
+        }
+    } else {
+        $hookinfo['errors'][] = '[statistics] Statistics dir [' . $statdir . '] does not exists';
+    }
 
-
-	if (file_exists($inputfile)) {
-		$hookinfo['info'][] = '[statistics] Input file [' . $inputfile . '] exists';
-	} else {
-		$hookinfo['errors'][] = '[statistics] Input file [' . $inputfile . '] does not exists';
-	}
+    if (file_exists($inputfile)) {
+        $hookinfo['info'][] = '[statistics] Input file [' . $inputfile . '] exists';
+    } else {
+        $hookinfo['errors'][] = '[statistics] Input file [' . $inputfile . '] does not exists';
+    }
 }
diff --git a/modules/statistics/lib/AccessCheck.php b/modules/statistics/lib/AccessCheck.php
index 4d505356424c99ccb95a237c250f9c9f022c3a8b..a400f3377204f9b5f3671ff466cc1bc799624818 100644
--- a/modules/statistics/lib/AccessCheck.php
+++ b/modules/statistics/lib/AccessCheck.php
@@ -5,79 +5,77 @@
  *
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_AccessCheck {
-
-
-	/**
-	 * Check that the user has access to the statistics.
-	 *
-	 * If the user doesn't have access, send the user to the login page.
-	 */
-	public static function checkAccess(SimpleSAML_Configuration $statconfig) {
-		$protected = $statconfig->getBoolean('protected', FALSE);
-		$authsource = $statconfig->getString('auth', NULL);
-		$allowedusers = $statconfig->getValue('allowedUsers', NULL);
-		$useridattr = $statconfig->getString('useridattr', 'eduPersonPrincipalName');
-
-		$acl = $statconfig->getValue('acl', NULL);
-		if ($acl !== NULL && !is_string($acl) && !is_array($acl)) {
-			throw new SimpleSAML_Error_Exception('Invalid value for \'acl\'-option. Should be an array or a string.');
-		}
-
-		if (!$protected) {
-			return;
-		}
-
-		if (SimpleSAML\Utils\Auth::isAdmin()) {
-			// User logged in as admin. OK.
-			SimpleSAML\Logger::debug('Statistics auth - logged in as admin, access granted');
-			return;
-		}
-
-		if (!isset($authsource)) {
-			// If authsource is not defined, init admin login.
+class sspmod_statistics_AccessCheck
+{
+    /**
+     * Check that the user has access to the statistics.
+     *
+     * If the user doesn't have access, send the user to the login page.
+     */
+    public static function checkAccess(SimpleSAML_Configuration $statconfig)
+    {
+        $protected = $statconfig->getBoolean('protected', false);
+        $authsource = $statconfig->getString('auth', null);
+        $allowedusers = $statconfig->getValue('allowedUsers', null);
+        $useridattr = $statconfig->getString('useridattr', 'eduPersonPrincipalName');
+
+        $acl = $statconfig->getValue('acl', null);
+        if ($acl !== null && !is_string($acl) && !is_array($acl)) {
+            throw new SimpleSAML_Error_Exception('Invalid value for \'acl\'-option. Should be an array or a string.');
+        }
+
+        if (!$protected) {
+            return;
+        }
+
+        if (SimpleSAML\Utils\Auth::isAdmin()) {
+            // User logged in as admin. OK.
+            SimpleSAML\Logger::debug('Statistics auth - logged in as admin, access granted');
+            return;
+        }
+
+        if (!isset($authsource)) {
+            // If authsource is not defined, init admin login.
             SimpleSAML\Utils\Auth::requireAdmin();
-		}
-
-		// We are using an authsource for login.
-
-		$as = new SimpleSAML_Auth_Simple($authsource);
-		$as->requireAuth();
-
-		// User logged in with auth source.
-		SimpleSAML\Logger::debug('Statistics auth - valid login with auth source [' . $authsource . ']');
-
-		// Retrieving attributes
-		$attributes = $as->getAttributes();
-
-		if (!empty($allowedusers)) {
-			// Check if userid exists
-			if (!isset($attributes[$useridattr][0]))
-				throw new Exception('User ID is missing');
-
-			// Check if userid is allowed access..
-			if (in_array($attributes[$useridattr][0], $allowedusers)) {
-				SimpleSAML\Logger::debug('Statistics auth - User granted access by user ID [' . $attributes[$useridattr][0] . ']');
-				return;
-			}
-			SimpleSAML\Logger::debug('Statistics auth - User denied access by user ID [' . $attributes[$useridattr][0] . ']');
-
-		} else {
-			SimpleSAML\Logger::debug('Statistics auth - no allowedUsers list.');
-		}
-
-		if (!is_null($acl)) {
-			$acl = new sspmod_core_ACL($acl);
-			if ($acl->allows($attributes)) {
-				SimpleSAML\Logger::debug('Statistics auth - allowed access by ACL.');
-				return;
-			}
-			SimpleSAML\Logger::debug('Statistics auth - denied access by ACL.');
-		} else {
-			SimpleSAML\Logger::debug('Statistics auth - no ACL configured.');
-		}
-
-		throw new SimpleSAML_Error_Exception('Access denied to the current user.');
-	}
-
-}
\ No newline at end of file
+        }
+
+        // We are using an authsource for login.
+
+        $as = new SimpleSAML_Auth_Simple($authsource);
+        $as->requireAuth();
+
+        // User logged in with auth source.
+        SimpleSAML\Logger::debug('Statistics auth - valid login with auth source [' . $authsource . ']');
+
+        // Retrieving attributes
+        $attributes = $as->getAttributes();
+
+        if (!empty($allowedusers)) {
+            // Check if userid exists
+            if (!isset($attributes[$useridattr][0])) {
+                throw new Exception('User ID is missing');
+            }
+
+            // Check if userid is allowed access..
+            if (in_array($attributes[$useridattr][0], $allowedusers)) {
+                SimpleSAML\Logger::debug('Statistics auth - User granted access by user ID [' . $attributes[$useridattr][0] . ']');
+                return;
+            }
+            SimpleSAML\Logger::debug('Statistics auth - User denied access by user ID [' . $attributes[$useridattr][0] . ']');
+        } else {
+            SimpleSAML\Logger::debug('Statistics auth - no allowedUsers list.');
+        }
+
+        if (!is_null($acl)) {
+            $acl = new sspmod_core_ACL($acl);
+            if ($acl->allows($attributes)) {
+                SimpleSAML\Logger::debug('Statistics auth - allowed access by ACL.');
+                return;
+            }
+            SimpleSAML\Logger::debug('Statistics auth - denied access by ACL.');
+        } else {
+            SimpleSAML\Logger::debug('Statistics auth - no ACL configured.');
+        }
+        throw new SimpleSAML_Error_Exception('Access denied to the current user.');
+    }
+}
diff --git a/modules/statistics/lib/Aggregator.php b/modules/statistics/lib/Aggregator.php
index 18829878c7d5de2309562428a2e1b2e4daab1260..3504768898bbf5e6df53cd9229dc329ef297e441 100644
--- a/modules/statistics/lib/Aggregator.php
+++ b/modules/statistics/lib/Aggregator.php
@@ -3,273 +3,309 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_Aggregator {
-
-	private $statconfig;
-	private $statdir;
-	private $inputfile;
-	private $statrules;
-	private $offset;
-	private $metadata;
-	private $fromcmdline;
-	
-	private $starttime;
-
-	/**
-	 * Constructor
-	 */
-	public function __construct($fromcmdline = FALSE) {
-	
-		$this->fromcmdline = $fromcmdline;
-		$this->statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
-		
-		$this->statdir = $this->statconfig->getValue('statdir');
-		$this->inputfile = $this->statconfig->getValue('inputfile');
-		$this->statrules = $this->statconfig->getValue('statrules');
-		$this->timeres = $this->statconfig->getValue('timeres');
-		$this->offset = $this->statconfig->getValue('offset', 0);
-		$this->metadata = NULL;
-		
-		$this->starttime = time();
-	}
-	
-	public function dumpConfig() {
-		echo 'Statistics directory   : ' . $this->statdir . "\n";
-		echo 'Input file             : ' . $this->inputfile . "\n";
-		echo 'Offset                 : ' . $this->offset . "\n";
-	}
-	
-	public function debugInfo() {
-		echo 'Memory usage           : ' . number_format(memory_get_usage() / (1024*1024), 2) . " MB\n";
-	}
-	
-	public function loadMetadata() {
-		$filename = $this->statdir . '/.stat.metadata';
-		$metadata = NULL;
-		if (file_exists($filename)) {
-			$metadata = unserialize(file_get_contents($filename));
-		}
-		$this->metadata = $metadata;
-	}
-	
-	public function getMetadata() {
-		return $this->metadata;
-	}
-	
-	public function saveMetadata() {
-		$this->metadata['time'] = time() - $this->starttime;
-		$this->metadata['memory'] = memory_get_usage();
-		$this->metadata['lastrun'] = time();
-		
-		$filename = $this->statdir . '/.stat.metadata';
-		file_put_contents($filename, serialize($this->metadata), LOCK_EX);
-	}
-	
-	public function aggregate($debug = FALSE) {
-		
-		$this->loadMetadata();
-		
-		if (!is_dir($this->statdir)) 
-			throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
-		
-		if (!file_exists($this->inputfile)) 
-			throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
-		
-		$file = fopen($this->inputfile, 'r');
-
-		if ($file === FALSE)
-			throw new Exception('Statistics module: unable to open file [' . $this->inputfile . ']');
-		
-		$logparser = new sspmod_statistics_LogParser(
-			$this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
-		);
-		$datehandler = array(
-			'default' => new sspmod_statistics_DateHandler($this->offset),
-			'month' => new  sspmod_statistics_DateHandlerMonth($this->offset),
-		);
-		
-		
-		$notBefore = 0; $lastRead = 0; $lastlinehash = '-';
-		if (isset($this->metadata)) {
-			$notBefore = $this->metadata['notBefore'];
-			$lastlinehash = $this->metadata['lastlinehash'];
-		}
-		
-		$lastlogline = 'sdfsdf'; 
-		$lastlineflip = FALSE;
-		$results = array();
-		
-		$i = 0;
-		// Parse through log file, line by line
-		while (!feof($file)) {
-			
-			$logline = fgets($file, 4096);
-			
-			// Continue if STAT is not found on line
-			if (!preg_match('/STAT/', $logline)) continue;
-			$i++; $lastlogline = $logline;
-			
-			// Parse log, and extract epoch time and rest of content.
-			$epoch = $logparser->parseEpoch($logline);
-			$content = $logparser->parseContent($logline);
-			$action = trim($content[5]);
-
-			if ($this->fromcmdline && ($i % 10000) == 0) {
-				echo("Read line " . $i . "\n");
-			}
-			
-			if ($debug) {
-				echo("----------------------------------------\n");
-				echo('Log line: ' . $logline . "\n");
-				echo('Date parse [' . substr($logline, 0, $this->statconfig->getValue('datelength', 15)) . '] to [' . date(DATE_RFC822, $epoch) . ']' . "\n");
-				echo htmlentities(print_r($content, true));
-				if ($i >= 13) exit;
-			}
-			
-			if ($epoch > $lastRead) $lastRead = $epoch;
-			if ($epoch === $notBefore) {
-				if(!$lastlineflip) {
-					if (sha1($logline) === $lastlinehash) { 
-						$lastlineflip = TRUE;
-					}
-					continue;
-				}
-			}
-			if ($epoch < $notBefore) continue;
-			
-			// Iterate all the statrules from config.
-			foreach ($this->statrules AS $rulename => $rule) {
-				
-				$type = 'aggregate';
-				if (array_key_exists('type', $rule)) $type = $rule['type'];
-				if ($type !== 'aggregate') continue;
-				
-				foreach($this->timeres AS $tres => $tresconfig ) {
-
-					$dh = 'default';
-					if (isset($tresconfig['customDateHandler'])) $dh = $tresconfig['customDateHandler'];
-			
-					$timeslot = $datehandler['default']->toSlot($epoch, $tresconfig['slot']);
-					$fileslot = $datehandler[$dh]->toSlot($epoch, $tresconfig['fileslot']);
-				
-					if (isset($rule['action']) && ($action !== $rule['action'])) continue;
-
-					$difcol = self::getDifCol($content, $rule['col']);
-		
-					if (!isset($results[$rulename][$tres][$fileslot][$timeslot]['_'])) $results[$rulename][$tres][$fileslot][$timeslot]['_'] = 0;
-					if (!isset($results[$rulename][$tres][$fileslot][$timeslot][$difcol])) $results[$rulename][$tres][$fileslot][$timeslot][$difcol] = 0;
-		
-					$results[$rulename][$tres][$fileslot][$timeslot]['_']++;
-					$results[$rulename][$tres][$fileslot][$timeslot][$difcol]++;
-				}
-			}
-		}
-		$this->metadata['notBefore'] = $lastRead;
-		$this->metadata['lastline'] = $lastlogline;
-		$this->metadata['lastlinehash'] = sha1($lastlogline);
-		return $results;
-	}
-	
-	private static function getDifCol($content, $colrule) {
-		if (is_int($colrule)) {
-			return trim($content[$colrule]);
-		} elseif(is_array($colrule)) {
-			$difcols = array();
-			foreach($colrule AS $cr) {
-				$difcols[] = trim($content[$cr]);
-			}
-			return join('|', $difcols);
-		} else {
-			return 'NA';
-		}
-	}
-	
-	private function cummulateData($previous, $newdata) {
-		$dataset = array();
-		foreach($previous AS $slot => $dataarray) {
-			if (!array_key_exists($slot, $dataset)) $dataset[$slot] = array();
-			foreach($dataarray AS $key => $data) {
-				if (!array_key_exists($key, $dataset[$slot])) $dataset[$slot][$key] = 0;
-				$dataset[$slot][$key] += $data;
-			}
-		}
-		foreach($newdata AS $slot => $dataarray) {
-			if (!array_key_exists($slot, $dataset)) $dataset[$slot] = array();
-			foreach($dataarray AS $key => $data) {
-				if (!array_key_exists($key, $dataset[$slot])) $dataset[$slot][$key] = 0;
-				$dataset[$slot][$key] += $data;
-			}
-		}
-		return $dataset;
-	}
-	
-	
-	public function store($results) {
-
-		$datehandler = array(
-			'default' => new sspmod_statistics_DateHandler($this->offset),
-			'month' => new  sspmod_statistics_DateHandlerMonth($this->offset),
-		);
-	
-		// Iterate the first level of results, which is per rule, as defined in the config.
-		foreach ($results AS $rulename => $timeresdata) {
-
-			// Iterate over time resolutions
-			foreach($timeresdata AS $tres => $resres) {
-
-				$dh = 'default';
-				if (isset($this->timeres[$tres]['customDateHandler'])) $dh = $this->timeres[$tres]['customDateHandler'];
-			
-				$filenos = array_keys($resres);
-				$lastfile = $filenos[count($filenos)-1];
-			
-				// Iterate the second level of results, which is the fileslot.
-				foreach ($resres AS $fileno => $fileres) {
-					
-					
-					// Slots that have data.
-					$slotlist = array_keys($fileres);
-				
-					// The last slot.
-					$maxslot = $slotlist[count($slotlist)-1];
-		
-					// Get start and end slot number within the file, based on the fileslot.
-					$start = (int)$datehandler['default']->toSlot(
-							$datehandler[$dh]->fromSlot($fileno, $this->timeres[$tres]['fileslot']), 
-							$this->timeres[$tres]['slot']);
-					$end = (int)$datehandler['default']->toSlot(
-							$datehandler[$dh]->fromSlot($fileno+1, $this->timeres[$tres]['fileslot']), 
-							$this->timeres[$tres]['slot']);
-
-					// Fill in missing entries and sort file results
-					$filledresult = array();
-					for ($slot = $start; $slot < $end; $slot++) {
-						if (array_key_exists($slot,  $fileres)) {
-							$filledresult[$slot] = $fileres[$slot];
-						} else {
-							if ($lastfile == $fileno && $slot > $maxslot) {
-								$filledresult[$slot] = array('_' => NULL);
-							} else {
-								$filledresult[$slot] = array('_' => 0);
-							}
-						}
-					}
-					
-					$filename = $this->statdir . '/' . $rulename . '-' . $tres . '-' . $fileno . '.stat';
-					if (file_exists($filename)) {
-						$previousData = unserialize(file_get_contents($filename));
-						$filledresult = $this->cummulateData($previousData, $filledresult);	
-					}
-				
-					// store file
-					file_put_contents($filename, serialize($filledresult), LOCK_EX);
-				}
-				
-			}
-			
-		}
-		$this->saveMetadata();
-	
-	}
+class sspmod_statistics_Aggregator
+{
+    private $statconfig;
+    private $statdir;
+    private $inputfile;
+    private $statrules;
+    private $offset;
+    private $metadata;
+    private $fromcmdline;
+    private $starttime;
 
+    /**
+     * Constructor
+     */
+    public function __construct($fromcmdline = false)
+    {
+        $this->fromcmdline = $fromcmdline;
+        $this->statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
+
+        $this->statdir = $this->statconfig->getValue('statdir');
+        $this->inputfile = $this->statconfig->getValue('inputfile');
+        $this->statrules = $this->statconfig->getValue('statrules');
+        $this->timeres = $this->statconfig->getValue('timeres');
+        $this->offset = $this->statconfig->getValue('offset', 0);
+        $this->metadata = null;
+
+        $this->starttime = time();
+    }
+
+    public function dumpConfig()
+    {
+        echo 'Statistics directory   : ' . $this->statdir . "\n";
+        echo 'Input file             : ' . $this->inputfile . "\n";
+        echo 'Offset                 : ' . $this->offset . "\n";
+    }
+
+    public function debugInfo()
+    {
+        echo 'Memory usage           : ' . number_format(memory_get_usage() / (1024*1024), 2) . " MB\n";
+    }
+
+    public function loadMetadata()
+    {
+        $filename = $this->statdir . '/.stat.metadata';
+        $metadata = null;
+        if (file_exists($filename)) {
+            $metadata = unserialize(file_get_contents($filename));
+        }
+        $this->metadata = $metadata;
+    }
+
+    public function getMetadata()
+    {
+        return $this->metadata;
+    }
+
+    public function saveMetadata()
+    {
+        $this->metadata['time'] = time() - $this->starttime;
+        $this->metadata['memory'] = memory_get_usage();
+        $this->metadata['lastrun'] = time();
+
+        $filename = $this->statdir . '/.stat.metadata';
+        file_put_contents($filename, serialize($this->metadata), LOCK_EX);
+    }
+
+    public function aggregate($debug = false) {
+        $this->loadMetadata();
+
+        if (!is_dir($this->statdir)) {
+            throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
+        }
+
+        if (!file_exists($this->inputfile)) {
+            throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
+        }
+
+        $file = fopen($this->inputfile, 'r');
+
+        if ($file === false) {
+            throw new Exception('Statistics module: unable to open file [' . $this->inputfile . ']');
+        }
+
+        $logparser = new sspmod_statistics_LogParser(
+            $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
+        );
+        $datehandler = array(
+            'default' => new sspmod_statistics_DateHandler($this->offset),
+            'month' => new  sspmod_statistics_DateHandlerMonth($this->offset),
+        );
+
+        $notBefore = 0;
+        $lastRead = 0;
+        $lastlinehash = '-';
+
+        if (isset($this->metadata)) {
+            $notBefore = $this->metadata['notBefore'];
+            $lastlinehash = $this->metadata['lastlinehash'];
+        }
+
+        $lastlogline = 'sdfsdf'; 
+        $lastlineflip = false;
+        $results = array();
+
+        $i = 0;
+        // Parse through log file, line by line
+        while (!feof($file)) {
+            $logline = fgets($file, 4096);
+
+            // Continue if STAT is not found on line
+            if (!preg_match('/STAT/', $logline)) {
+                continue;
+            }
+
+            $i++;
+            $lastlogline = $logline;
+
+            // Parse log, and extract epoch time and rest of content.
+            $epoch = $logparser->parseEpoch($logline);
+            $content = $logparser->parseContent($logline);
+            $action = trim($content[5]);
+
+            if ($this->fromcmdline && ($i % 10000) == 0) {
+                echo("Read line " . $i . "\n");
+            }
+
+            if ($debug) {
+                echo("----------------------------------------\n");
+                echo('Log line: ' . $logline . "\n");
+                echo('Date parse [' . substr($logline, 0, $this->statconfig->getValue('datelength', 15)) . '] to [' . date(DATE_RFC822, $epoch) . ']' . "\n");
+                echo htmlentities(print_r($content, true));
+                if ($i >= 13) {
+                    exit;
+                }
+            }
+
+            if ($epoch > $lastRead) {
+                $lastRead = $epoch;
+            }
+
+            if ($epoch === $notBefore) {
+                if (!$lastlineflip) {
+                    if (sha1($logline) === $lastlinehash) { 
+                        $lastlineflip = true;
+                    }
+                    continue;
+                }
+            }
+
+            if ($epoch < $notBefore) {
+                continue;
+            }
+
+            // Iterate all the statrules from config.
+            foreach ($this->statrules as $rulename => $rule) {
+                $type = 'aggregate';
+
+                if (array_key_exists('type', $rule)) {
+                    $type = $rule['type'];
+                }
+
+                if ($type !== 'aggregate') {
+                    continue;
+                }
+
+                foreach ($this->timeres AS $tres => $tresconfig ) {
+                    $dh = 'default';
+                    if (isset($tresconfig['customDateHandler'])) {
+                        $dh = $tresconfig['customDateHandler'];
+                    }
+
+                    $timeslot = $datehandler['default']->toSlot($epoch, $tresconfig['slot']);
+                    $fileslot = $datehandler[$dh]->toSlot($epoch, $tresconfig['fileslot']);
+
+                    if (isset($rule['action']) && ($action !== $rule['action'])) {
+                        continue;
+                    }
+
+                    $difcol = self::getDifCol($content, $rule['col']);
+
+                    if (!isset($results[$rulename][$tres][$fileslot][$timeslot]['_'])) {
+                        $results[$rulename][$tres][$fileslot][$timeslot]['_'] = 0;
+                    }
+                    if (!isset($results[$rulename][$tres][$fileslot][$timeslot][$difcol])) {
+                        $results[$rulename][$tres][$fileslot][$timeslot][$difcol] = 0;
+                    }
+
+                    $results[$rulename][$tres][$fileslot][$timeslot]['_']++;
+                    $results[$rulename][$tres][$fileslot][$timeslot][$difcol]++;
+                }
+            }
+        }
+        $this->metadata['notBefore'] = $lastRead;
+        $this->metadata['lastline'] = $lastlogline;
+        $this->metadata['lastlinehash'] = sha1($lastlogline);
+        return $results;
+    }
+
+    private static function getDifCol($content, $colrule)
+    {
+        if (is_int($colrule)) {
+            return trim($content[$colrule]);
+        } elseif (is_array($colrule)) {
+            $difcols = array();
+            foreach ($colrule as $cr) {
+                $difcols[] = trim($content[$cr]);
+            }
+            return join('|', $difcols);
+        } else {
+            return 'NA';
+        }
+    }
+
+    private function cummulateData($previous, $newdata)
+    {
+        $dataset = array();
+        foreach ($previous sd $slot => $dataarray) {
+            if (!array_key_exists($slot, $dataset)) {
+                $dataset[$slot] = array();
+            }
+            foreach ($dataarray as $key => $data) {
+                if (!array_key_exists($key, $dataset[$slot])) {
+                    $dataset[$slot][$key] = 0;
+                }
+                $dataset[$slot][$key] += $data;
+            }
+        }
+        foreach ($newdata as $slot => $dataarray) {
+            if (!array_key_exists($slot, $dataset)) {
+                $dataset[$slot] = array();
+            }
+            foreach ($dataarray as $key => $data) {
+                if (!array_key_exists($key, $dataset[$slot])) {
+                    $dataset[$slot][$key] = 0;
+                }
+                $dataset[$slot][$key] += $data;
+            }
+        }
+        return $dataset;
+    }
+
+    public function store($results)
+    {
+        $datehandler = array(
+            'default' => new sspmod_statistics_DateHandler($this->offset),
+            'month' => new  sspmod_statistics_DateHandlerMonth($this->offset),
+        );
+
+        // Iterate the first level of results, which is per rule, as defined in the config.
+        foreach ($results as $rulename => $timeresdata) {
+            // Iterate over time resolutions
+            foreach ($timeresdata as $tres => $resres) {
+                $dh = 'default';
+                if (isset($this->timeres[$tres]['customDateHandler'])) {
+                    $dh = $this->timeres[$tres]['customDateHandler'];
+                }
+
+                $filenos = array_keys($resres);
+                $lastfile = $filenos[count($filenos) - 1];
+
+                // Iterate the second level of results, which is the fileslot.
+                foreach ($resres as $fileno => $fileres) {
+                    // Slots that have data.
+                    $slotlist = array_keys($fileres);
+
+                    // The last slot.
+                    $maxslot = $slotlist[count($slotlist) - 1];
+
+                    // Get start and end slot number within the file, based on the fileslot.
+                    $start = (int)$datehandler['default']->toSlot(
+                        $datehandler[$dh]->fromSlot($fileno, $this->timeres[$tres]['fileslot']), 
+                        $this->timeres[$tres]['slot']
+                    );
+                    $end = (int)$datehandler['default']->toSlot(
+                        $datehandler[$dh]->fromSlot($fileno+1, $this->timeres[$tres]['fileslot']), 
+                        $this->timeres[$tres]['slot']
+                    );
+
+                    // Fill in missing entries and sort file results
+                    $filledresult = array();
+                    for ($slot = $start; $slot < $end; $slot++) {
+                        if (array_key_exists($slot,  $fileres)) {
+                            $filledresult[$slot] = $fileres[$slot];
+                        } else {
+                            if ($lastfile == $fileno && $slot > $maxslot) {
+                                $filledresult[$slot] = array('_' => null);
+                            } else {
+                                $filledresult[$slot] = array('_' => 0);
+                            }
+                        }
+                    }
+
+                    $filename = $this->statdir . '/' . $rulename . '-' . $tres . '-' . $fileno . '.stat';
+                    if (file_exists($filename)) {
+                        $previousData = unserialize(file_get_contents($filename));
+                        $filledresult = $this->cummulateData($previousData, $filledresult);	
+                    }
+
+                    // store file
+                    file_put_contents($filename, serialize($filledresult), LOCK_EX);
+                }
+            }
+        }
+        $this->saveMetadata();
+    }
 }
diff --git a/modules/statistics/lib/DateHandler.php b/modules/statistics/lib/DateHandler.php
index 34eab33591434c9ebfc8eed00896779be1eaa211..13ed07c7f5dd5b8d25d40d1fca87ad4da784100a 100644
--- a/modules/statistics/lib/DateHandler.php
+++ b/modules/statistics/lib/DateHandler.php
@@ -3,48 +3,56 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_DateHandler {
+class sspmod_statistics_DateHandler
+{
+    protected $offset;
 
-	protected $offset;
+    /**
+     * Constructor
+     *
+     * @param array $offset 	Date offset
+     */
+    public function __construct($offset)
+    {
+        $this->offset = $offset;
+    }
 
-	/**
-	 * Constructor
-	 *
-	 * @param array $offset 	Date offset
-	 */
-	public function __construct($offset) {
-		$this->offset = $offset;
-	}
-	
-	protected function getDST($timestamp) {
-		if (idate('I', $timestamp)) return 3600;
-		return 0;
-	}
+    protected function getDST($timestamp)
+    {
+        if (idate('I', $timestamp)) {
+            return 3600;
+        }
+        return 0;
+    }
 
-	public function toSlot($epoch, $slotsize) {
-		$dst = $this->getDST($epoch);
-		return floor( ($epoch + $this->offset + $dst) / $slotsize);
-	}
+    public function toSlot($epoch, $slotsize)
+    {
+        $dst = $this->getDST($epoch);
+        return floor( ($epoch + $this->offset + $dst) / $slotsize);
+    }
 
-	public function fromSlot($slot, $slotsize) {
-		$temp = $slot*$slotsize - $this->offset;
-		$dst = $this->getDST($temp);
-		return $slot*$slotsize - $this->offset - $dst;
-	}
+    public function fromSlot($slot, $slotsize)
+    {
+        $temp = $slot*$slotsize - $this->offset;
+        $dst = $this->getDST($temp);
+        return $slot*$slotsize - $this->offset - $dst;
+    }
 
-	public function prettyDateEpoch($epoch, $dateformat) {
-		return date($dateformat, $epoch);
-	}
+    public function prettyDateEpoch($epoch, $dateformat)
+    {
+        return date($dateformat, $epoch);
+    }
 
-	public function prettyDateSlot($slot, $slotsize, $dateformat) {
-		return $this->prettyDateEpoch($this->fromSlot($slot, $slotsize), $dateformat);
+    public function prettyDateSlot($slot, $slotsize, $dateformat)
+    {
+        return $this->prettyDateEpoch($this->fromSlot($slot, $slotsize), $dateformat);
+    }
 
-	}
-	
-	public function prettyHeader($from, $to, $slotsize, $dateformat) {
-		$text = $this->prettyDateSlot($from, $slotsize, $dateformat);
-		$text .= ' to ';
-		$text .= $this->prettyDateSlot($to, $slotsize, $dateformat);
-		return $text;
-	}
+    public function prettyHeader($from, $to, $slotsize, $dateformat)
+    {
+        $text = $this->prettyDateSlot($from, $slotsize, $dateformat);
+        $text .= ' to ';
+        $text .= $this->prettyDateSlot($to, $slotsize, $dateformat);
+        return $text;
+    }
 }
diff --git a/modules/statistics/lib/DateHandlerMonth.php b/modules/statistics/lib/DateHandlerMonth.php
index b0f4e2cd15c058b8c476e66dfda37bafaa828c87..33f9762d91a3c707fb9be1410f879d957125144e 100644
--- a/modules/statistics/lib/DateHandlerMonth.php
+++ b/modules/statistics/lib/DateHandlerMonth.php
@@ -3,39 +3,37 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_DateHandlerMonth extends sspmod_statistics_DateHandler {
+class sspmod_statistics_DateHandlerMonth extends sspmod_statistics_DateHandler
+{
+    /**
+     * Constructor
+     *
+     * @param array $offset 	Date offset
+     */
+    public function __construct($offset)
+    {
+        $this->offset = $offset;
+    }
 
-	/**
-	 * Constructor
-	 *
-	 * @param array $offset 	Date offset
-	 */
-	public function __construct($offset) {
-		$this->offset = $offset;
-	}
-	
+    public function toSlot($epoch, $slotsize)
+    {
+        $dsttime = $this->getDST($epoch) + $epoch;
+        $parsed = getdate($dsttime);
+        $slot = (($parsed['year'] - 2000) * 12) + $parsed['mon'] - 1;
+        return $slot;
+    }
 
-	public function toSlot($epoch, $slotsize) {
-		$dsttime = $this->getDST($epoch) + $epoch;
-		$parsed = getdate($dsttime);
-		$slot = (($parsed['year'] - 2000) * 12) + $parsed['mon'] - 1;
-		return $slot;
-	}
+    public function fromSlot($slot, $slotsize)
+    {
+        $month = ($slot % 12);
+        $year = 2000 + floor($slot / 12);
+        return mktime(0, 0, 0, $month + 1, 1, $year);
+    }
 
-	public function fromSlot($slot, $slotsize) {
-		
-		$month = ($slot % 12);
-		$year = 2000 + floor($slot / 12);
-		
-		$epoch = mktime(0, 0, 0, $month + 1, 1, $year);
-		return $epoch;
-	}
-
-	public function prettyHeader($from, $to, $slotsize, $dateformat) {
-		
-		$month = ($from % 12) + 1;
-		$year = 2000 + floor($from / 12);
-		
-		return $year . '-' . $month;
-	}
+    public function prettyHeader($from, $to, $slotsize, $dateformat)
+    {
+        $month = ($from % 12) + 1;
+        $year = 2000 + floor($from / 12);
+        return $year . '-' . $month;
+    }
 }
diff --git a/modules/statistics/lib/Graph/GoogleCharts.php b/modules/statistics/lib/Graph/GoogleCharts.php
index b062fe41987b373ecf09853536d207d44f05ce0f..d86ccc788d4384875966cf590e737c1641a807aa 100644
--- a/modules/statistics/lib/Graph/GoogleCharts.php
+++ b/modules/statistics/lib/Graph/GoogleCharts.php
@@ -6,172 +6,174 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_Graph_GoogleCharts {
-
-	private $x, $y;
-
-	/**
-	 * Constructor.
-	 *
-	 * Takes dimension of graph as parameters. X and Y.
-	 *
-	 * @param $x 	X dimension. Default 800.
-	 * @param $y 	Y dimension. Default 350.
-	 */
-	public function __construct($x = 800, $y = 350) {
-		$this->x = $x; $this->y = $y;
-	}
-
-	private function encodeaxis($axis) {
-		return join('|', $axis);
-	}
-
-	# t:10.0,58.0,95.0
-	private function encodedata($datasets) {
-		$setstr = array();
-		foreach ($datasets AS $dataset) {
-			$setstr[] = self::extEncode($dataset);
-		}
-		return 'e:' . join(',', $setstr);
-	}
-	
-	
-	public static function extEncode($values) { #}, $max = 4095, $min = 0){ 
-		$extended_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'; 
-		$chardata = ''; 
-		$delta = 4095;
-		$size = (strlen($extended_table)); 
-		
-		foreach($values as $k => $v){ 
-			if($v >= 0 && $v <= 100){ 
-				$first = substr($extended_table, intval( ($delta*$v/100) / $size),1);
-				$second = substr($extended_table, intval( ($delta*$v/100) % $size), 1);
-				$chardata .= "$first$second";
-			} else { 
-				$chardata .= '__'; // Value out of max range; 
-			} 
-		}
-		return($chardata); 
-	}
-	
-	
-	/**
-	 * Return colors between multiple graphs...
-	 */
-	private function getFillArea($datasets) {
-		if (count($datasets) < 2) return '';
-		
-		$colors = array('eeeeee', 'cccccc', 'aaaaaa', '99eecc');
-		$num = count($datasets) ;
-		$colstr = array();
-		for ($i = 0; $i < $num; $i++) {
-			$colstr[] = 'b' . ',' . $colors[$i] . ',' . ($i) . ',' . ($i+1) . ',0';
-		}
-		return '&chm=' . join('|', $colstr);
-	}
-	
-	
-	
-	/**
-	 * Generate a Google Charts URL which points to a generated image.
-	 * More documentation on Google Charts here: 
-	 *   http://code.google.com/apis/chart/
-	 *
-	 * @param $axis		Axis
-	 * @param $axpis	Axis positions
-	 * @param $datasets	Datasets values
-	 * @param $max		Max value. Will be the topmost value on the Y-axis.
-	 */
-	public function show($axis, $axispos, $datasets, $maxes) {
-	
-		$labeld = '&chxt=x,y' . '&chxr=0,0,1|1,0,' . $maxes[0];
-		if (count($datasets) > 1) {
-			if (count($datasets) !== count($maxes)) {
-				throw new Exception('Incorrect number of max calculations for graph plotting.');
-			}
-			$labeld = '&chxt=x,y,r' . 
-				'&chxr=0,0,1|1,0,' . $maxes[0] . '|2,0,' . $maxes[1];
-			
-		}
- 	
-		$url = 'http://chart.apis.google.com/chart?' .
-			
-			// Dimension of graph. Default is 800x350
-			'chs=' . $this->x . 'x' . $this->y . 
-			
-			// Dateset values
-			'&chd=' . $this->encodedata($datasets) .
-			
-			// Fill area...
-			'&chco=ff5c00,cca600' . 
-			'&chls=1,1,0|1,6,3' .
-			
-			// chart type is linechart
-			'&cht=lc' .
-			$labeld .
-			'&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' .
-			'&chxp=0,' . join(',', $axispos) .
-			'&chg=' . (2400/(count($datasets[0])-1)) . ',-1,3,3';   // lines
-		return $url;
-	}
-	
-	public function showPie($axis, $datasets) {
-		
-		$url = 'http://chart.apis.google.com/chart?' .
-
-			// Dimension of graph. Default is 800x350
-			'chs=' . $this->x . 'x' . $this->y . 
-
-			// Dateset values.
-			'&chd=' . $this->encodedata(array($datasets)) .
-
-			// chart type is linechart
-			'&cht=p' .
-
-			'&chl=' . $this->encodeaxis($axis);
-		return $url;
-	}
-	
-	/**
-	 * Takes a input value, and generates a value that suits better as a max
-	 * value on the Y-axis. In example 37.6 will not make a good max value, instead
-	 * it will return 40. It will always return an equal or larger number than it gets
-	 * as input.
-	 *
-	 * Here is some test code:
-	 * <code>
-	 * 		$foo = array(0, 2, 2.3, 2.6, 6, 10, 15, 98, 198, 256, 487, 563, 763, 801, 899, 999, 987, 198234.485, 283746);
-	 *		foreach ($foo AS $f) {
-	 *			echo '<p>' . $f . ' => ' . sspmod_statistics_Graph_GoogleCharts::roof($f);
-	 *		}
-	 * </code>
-	 * 
-	 * @param $max 	Input value.
-	 */
-	public static function roof($max) {
-		$mul = 1;
-
-		if ($max < 1) {
-			return 1;
-		}
-
-		$t = intval(ceil($max));
-		while ($t > 100) {
-			$t /= 10;
-			$mul *= 10;
-		}
-
-		$maxGridLines = 10;
-		$candidates = array(1, 2, 5, 10, 20, 25, 50, 100);
-
-		foreach ($candidates as $c) {
-			if ($t / $c < $maxGridLines) {
-				$tick_y = $c * $mul;
-				$target_top = intval(ceil($max / $tick_y) * $tick_y);
-				return $target_top;
-			}
-		}
-
-	}
+class sspmod_statistics_Graph_GoogleCharts
+{
+    private $x, $y;
 
+    /**
+     * Constructor.
+     *
+     * Takes dimension of graph as parameters. X and Y.
+     *
+     * @param $x    X dimension. Default 800.
+     * @param $y    Y dimension. Default 350.
+     */
+    public function __construct($x = 800, $y = 350)
+    {
+        $this->x = $x;
+        $this->y = $y;
+    }
+
+    private function encodeaxis($axis)
+    {
+        return join('|', $axis);
+    }
+
+    // t:10.0,58.0,95.0
+    private function encodedata($datasets)
+    {
+        $setstr = array();
+        foreach ($datasets as $dataset) {
+            $setstr[] = self::extEncode($dataset);
+        }
+        return 'e:' . join(',', $setstr);
+    }
+
+    public static function extEncode($values) // $max = 4095, $min = 0
+    {
+        $extended_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
+        $chardata = '';
+        $delta = 4095;
+        $size = (strlen($extended_table));
+
+        foreach ($values as $k => $v) {
+            if ($v >= 0 && $v <= 100) {
+                $first = substr($extended_table, intval(($delta * $v / 100) / $size), 1);
+                $second = substr($extended_table, intval(($delta * $v / 100) % $size), 1);
+                $chardata .= "$first$second";
+            } else { 
+                $chardata .= '__'; // Value out of max range; 
+            } 
+        }
+        return($chardata); 
+    }
+
+    /**
+     * Return colors between multiple graphs...
+     */
+    private function getFillArea($datasets)
+    {
+        if (count($datasets) < 2) {
+            return '';
+        }
+
+        $colors = array('eeeeee', 'cccccc', 'aaaaaa', '99eecc');
+        $num = count($datasets) ;
+        $colstr = array();
+        for ($i = 0; $i < $num; $i++) {
+            $colstr[] = 'b' . ',' . $colors[$i] . ',' . ($i) . ',' . ($i+1) . ',0';
+        }
+        return '&chm=' . join('|', $colstr);
+    }
+
+    /**
+     * Generate a Google Charts URL which points to a generated image.
+     * More documentation on Google Charts here: 
+     *   http://code.google.com/apis/chart/
+     *
+     * @param $axis        Axis
+     * @param $axpis       Axis positions
+     * @param $datasets    Datasets values
+     * @param $max         Max value. Will be the topmost value on the Y-axis.
+     */
+    public function show($axis, $axispos, $datasets, $maxes)
+    {
+        $labeld = '&chxt=x,y' . '&chxr=0,0,1|1,0,' . $maxes[0];
+        if (count($datasets) > 1) {
+            if (count($datasets) !== count($maxes)) {
+                throw new Exception('Incorrect number of max calculations for graph plotting.');
+            }
+            $labeld = '&chxt=x,y,r' . '&chxr=0,0,1|1,0,' . $maxes[0] . '|2,0,' . $maxes[1];
+        }
+
+        $url = 'http://chart.apis.google.com/chart?' .
+            // Dimension of graph. Default is 800x350
+            'chs=' . $this->x . 'x' . $this->y . 
+
+            // Dateset values
+            '&chd=' . $this->encodedata($datasets) .
+
+            // Fill area...
+            '&chco=ff5c00,cca600' . 
+            '&chls=1,1,0|1,6,3' .
+
+            // chart type is linechart
+            '&cht=lc' .
+            $labeld .
+            '&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' .
+            '&chxp=0,' . join(',', $axispos) .
+            '&chg=' . (2400/(count($datasets[0])-1)) . ',-1,3,3';   // lines
+
+        return $url;
+    }
+
+    public function showPie($axis, $datasets)
+    {
+        $url = 'http://chart.apis.google.com/chart?' .
+
+        // Dimension of graph. Default is 800x350
+        'chs=' . $this->x . 'x' . $this->y . 
+
+        // Dateset values.
+        '&chd=' . $this->encodedata(array($datasets)) .
+
+        // chart type is linechart
+        '&cht=p' .
+
+        '&chl=' . $this->encodeaxis($axis);
+
+        return $url;
+    }
+
+    /**
+     * Takes a input value, and generates a value that suits better as a max
+     * value on the Y-axis. In example 37.6 will not make a good max value, instead
+     * it will return 40. It will always return an equal or larger number than it gets
+     * as input.
+     *
+     * Here is some test code:
+     * <code>
+     * 	    $foo = array(0, 2, 2.3, 2.6, 6, 10, 15, 98, 198, 256, 487, 563, 763, 801, 899, 999, 987, 198234.485, 283746);
+     *	    foreach ($foo AS $f) {
+     *	        echo '<p>' . $f . ' => ' . sspmod_statistics_Graph_GoogleCharts::roof($f);
+     *	    }
+     * </code>
+     * 
+     * @param $max    Input value.
+     */
+    public static function roof($max)
+    {
+        $mul = 1;
+
+        if ($max < 1) {
+            return 1;
+        }
+
+        $t = intval(ceil($max));
+        while ($t > 100) {
+            $t /= 10;
+            $mul *= 10;
+        }
+
+        $maxGridLines = 10;
+        $candidates = array(1, 2, 5, 10, 20, 25, 50, 100);
+
+        foreach ($candidates as $c) {
+            if ($t / $c < $maxGridLines) {
+                $tick_y = $c * $mul;
+                $target_top = intval(ceil($max / $tick_y) * $tick_y);
+                return $target_top;
+            }
+        }
+    }
 }
diff --git a/modules/statistics/lib/LogCleaner.php b/modules/statistics/lib/LogCleaner.php
index 9b6646495129f20e6772b0518c69f05688f70874..a39d83fb6c5ca750033f0fae2afc3f05e33ecccc 100644
--- a/modules/statistics/lib/LogCleaner.php
+++ b/modules/statistics/lib/LogCleaner.php
@@ -3,165 +3,165 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_LogCleaner {
-
-	private $statconfig;
-	private $statdir;
-	private $inputfile;
-	private $statrules;
-	private $offset;
-
-	/**
-	 * Constructor
-	 */
-	public function __construct($inputfile = NULL) {
-	
-		$this->statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
-		
-		$this->statdir = $this->statconfig->getValue('statdir');
-		$this->inputfile = $this->statconfig->getValue('inputfile');
-		$this->statrules = $this->statconfig->getValue('statrules');
-		$this->offset = $this->statconfig->getValue('offset', 0);
-		
-		if (isset($inputfile)) $this->inputfile = $inputfile;
-	}
-	
-	public function dumpConfig() {
-		
-		echo 'Statistics directory   : ' . $this->statdir . "\n";
-		echo 'Input file             : ' . $this->inputfile . "\n";
-		echo 'Offset                 : ' . $this->offset . "\n";
-		
-	}
-	
-
-
-	public function clean($debug = FALSE) {
-		
-		if (!is_dir($this->statdir)) 
-			throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
-		
-		if (!file_exists($this->inputfile)) 
-			throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
-		
-		
-		$file = fopen($this->inputfile, 'r');
-
-		$logparser = new sspmod_statistics_LogParser(
-			$this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
-		);
-		$datehandler = new sspmod_statistics_DateHandler($this->offset);
-		
-		$results = array();
-		
-		$sessioncounter = array();
-		
-		$i = 0;
-		// Parse through log file, line by line
-		while (!feof($file)) {
-			
-			$logline = fgets($file, 4096);
-			
-			// Continue if STAT is not found on line
-			if (!preg_match('/STAT/', $logline)) continue;
-			$i++;
-			
-			// Parse log, and extract epoch time and rest of content.
-			$epoch = $logparser->parseEpoch($logline);
-			$content = $logparser->parseContent($logline);
-			$action = trim($content[5]);
-
-			if (($i % 10000) == 0) {
-				echo("Read line " . $i . "\n");
-			}
-			
-			$trackid = $content[4];
-			
-			if(!isset($sessioncounter[$trackid])) $sessioncounter[$trackid] = 0;
-			$sessioncounter[$trackid]++;
-
-			if ($debug) {
-			
-				echo("----------------------------------------\n");
-				echo('Log line: ' . $logline . "\n");
-				echo('Date parse [' . substr($logline, 0, $this->statconfig->getValue('datelength', 15)) . '] to [' . date(DATE_RFC822, $epoch) . ']' . "\n");
-				echo htmlentities(print_r($content, true));
-				if ($i >= 13) exit;
-			}
-
-		}
-
-		$histogram = array();
-		foreach($sessioncounter AS $trackid => $sc) {
-			if(!isset($histogram[$sc])) $histogram[$sc] = 0;
-			$histogram[$sc]++;
-		}
-		ksort($histogram);
-		
-		$todelete = array();
-		foreach($sessioncounter AS $trackid => $sc) {
-			if($sc > 200) $todelete[] = $trackid;
-		}
-
-		return $todelete;
-	}
-	
-	
-	public function store($todelete, $outputfile) {
-		
-		echo "Preparing to delete [" .count($todelete) . "] trackids\n";
-		
-		if (!is_dir($this->statdir)) 
-			throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
-		
-		if (!file_exists($this->inputfile)) 
-			throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
-		
-		$file = fopen($this->inputfile, 'r');
-
-		// Open the output file in a way that guarantees that we will not overwrite a random file.
-		if (file_exists($outputfile)) {
-			// Delete existing output file.
-			unlink($outputfile);
-		}
-		$outfile = fopen($outputfile, 'x'); /* Create the output file. */
-
-		
-		$logparser = new sspmod_statistics_LogParser(
-			$this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
-		);
-
-		$i = 0;
-		// Parse through log file, line by line
-		while (!feof($file)) {
-			
-			$logline = fgets($file, 4096);
-			
-			// Continue if STAT is not found on line.
-			if (!preg_match('/STAT/', $logline)) continue;
-			$i++;
-			
-			$content = $logparser->parseContent($logline);
-			
-			$action = trim($content[5]);
-
-			if (($i % 10000) == 0) {
-				echo("Read line " . $i . "\n");
-			}
-			
-			$trackid = $content[4];
-			
-			if (in_array($trackid, $todelete)) {
-				continue;
-			}
-			
-			fputs($outfile, $logline);
-
-		}
-		fclose($file);
-		fclose($outfile);
-		
-	}
-
-
+class sspmod_statistics_LogCleaner
+{
+    private $statconfig;
+    private $statdir;
+    private $inputfile;
+    private $statrules;
+    private $offset;
+
+    /**
+     * Constructor
+     */
+    public function __construct($inputfile = null)
+    {
+        $this->statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
+
+        $this->statdir = $this->statconfig->getValue('statdir');
+        $this->inputfile = $this->statconfig->getValue('inputfile');
+        $this->statrules = $this->statconfig->getValue('statrules');
+        $this->offset = $this->statconfig->getValue('offset', 0);
+
+        if (isset($inputfile)) {
+            $this->inputfile = $inputfile;
+        }
+    }
+
+    public function dumpConfig()
+    {
+        echo 'Statistics directory   : ' . $this->statdir . "\n";
+        echo 'Input file             : ' . $this->inputfile . "\n";
+        echo 'Offset                 : ' . $this->offset . "\n";
+    }
+
+    public function clean($debug = false) {
+        if (!is_dir($this->statdir)) {
+            throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
+        }
+
+        if (!file_exists($this->inputfile)) {
+            throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
+        }
+
+        $file = fopen($this->inputfile, 'r');
+
+        $logparser = new sspmod_statistics_LogParser(
+            $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
+        );
+        $datehandler = new sspmod_statistics_DateHandler($this->offset);
+
+        $results = array();
+        $sessioncounter = array();
+
+        $i = 0;
+        // Parse through log file, line by line
+        while (!feof($file)) {
+            $logline = fgets($file, 4096);
+
+            // Continue if STAT is not found on line
+            if (!preg_match('/STAT/', $logline)) {
+                continue;
+            }
+            $i++;
+
+            // Parse log, and extract epoch time and rest of content.
+            $epoch = $logparser->parseEpoch($logline);
+            $content = $logparser->parseContent($logline);
+            $action = trim($content[5]);
+
+            if (($i % 10000) == 0) {
+                echo("Read line " . $i . "\n");
+            }
+
+            $trackid = $content[4];
+
+            if (!isset($sessioncounter[$trackid])) {
+                $sessioncounter[$trackid] = 0;
+            }
+            $sessioncounter[$trackid]++;
+
+            if ($debug) {
+                echo("----------------------------------------\n");
+                echo('Log line: ' . $logline . "\n");
+                echo('Date parse [' . substr($logline, 0, $this->statconfig->getValue('datelength', 15)) . '] to [' . date(DATE_RFC822, $epoch) . ']' . "\n");
+                echo htmlentities(print_r($content, true));
+                if ($i >= 13) {
+                    exit;
+                }
+            }
+        }
+
+        $histogram = array();
+        foreach ($sessioncounter as $trackid => $sc) {
+            if (!isset($histogram[$sc])) {
+                $histogram[$sc] = 0;
+            }
+            $histogram[$sc]++;
+        }
+        ksort($histogram);
+
+        $todelete = array();
+        foreach ($sessioncounter as $trackid => $sc) {
+            if ($sc > 200) {
+                $todelete[] = $trackid;
+            }
+        }
+
+        return $todelete;
+    }
+
+    public function store($todelete, $outputfile)
+    {
+        echo "Preparing to delete [" .count($todelete) . "] trackids\n";
+
+        if (!is_dir($this->statdir)) {
+            throw new Exception('Statistics module: output dir do not exists [' . $this->statdir . ']');
+        }
+
+        if (!file_exists($this->inputfile)) {
+            throw new Exception('Statistics module: input file do not exists [' . $this->inputfile . ']');
+        }
+
+        $file = fopen($this->inputfile, 'r');
+
+        // Open the output file in a way that guarantees that we will not overwrite a random file.
+        if (file_exists($outputfile)) {
+            // Delete existing output file.
+            unlink($outputfile);
+        }
+        $outfile = fopen($outputfile, 'x'); /* Create the output file. */
+
+        $logparser = new sspmod_statistics_LogParser(
+            $this->statconfig->getValue('datestart', 0), $this->statconfig->getValue('datelength', 15), $this->statconfig->getValue('offsetspan', 44)
+        );
+
+        $i = 0;
+        // Parse through log file, line by line
+        while (!feof($file)) {
+            $logline = fgets($file, 4096);
+
+            // Continue if STAT is not found on line.
+            if (!preg_match('/STAT/', $logline)) {
+                continue;
+            }
+            $i++;
+
+            $content = $logparser->parseContent($logline);
+            $action = trim($content[5]);
+
+            if (($i % 10000) == 0) {
+                echo("Read line " . $i . "\n");
+            }
+
+            $trackid = $content[4];
+            if (in_array($trackid, $todelete)) {
+                continue;
+            }
+
+            fputs($outfile, $logline);
+        }
+        fclose($file);
+        fclose($outfile);
+    }
 }
diff --git a/modules/statistics/lib/LogParser.php b/modules/statistics/lib/LogParser.php
index d1d5d203ce1c32ba9eab598e45aaf76e0c82897a..6ca677a38c5b2d624141c9105fa7746bf8aaa825 100644
--- a/modules/statistics/lib/LogParser.php
+++ b/modules/statistics/lib/LogParser.php
@@ -3,65 +3,64 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_LogParser {
+class sspmod_statistics_LogParser
+{
+    private $datestart;
+    private $datelength;
+    private $offset;
 
-	private $datestart;
-	private $datelength;
-	private $offset;
+    /**
+     * Constructor
+     *
+     * @param $datestart   At which char is the date starting
+     * @param $datelength  How many characters is the date (on the b
+     * @param $offset      At which char is the rest of the entries starting
+     */
+    public function __construct($datestart, $datelength, $offset)
+    {
+        $this->datestart = $datestart;
+        $this->datelength = $datelength;
+        $this->offset = $offset;
+    }
 
-	/**
-	 * Constructor
-	 *
-	 * @param $datestart   At which char is the date starting
-	 * @param $datelength  How many characters is the date (on the b
-	 * @param $offset      At which char is the rest of the entries starting
-	 */
-	public function __construct($datestart, $datelength, $offset) {
-		$this->datestart = $datestart;
-		$this->datelength = $datelength;
-		$this->offset = $offset;
-	}
+    public function parseEpoch($line)
+    {
+        $epoch = strtotime(substr($line, 0, $this->datelength));
+        if ($epoch > time() + 2678400) {  // 60 * 60 *24 * 31 = 2678400
+            /*
+             * More than a month in the future - probably caused by
+             * the log files missing the year.
+             * We will therefore subtrackt one year.
+             */
+            $hour = gmdate('H', $epoch);
+            $minute = gmdate('i', $epoch);
+            $second = gmdate('s', $epoch);
+            $month = gmdate('n', $epoch);
+            $day = gmdate('j', $epoch);
+            $year = gmdate('Y', $epoch) - 1;
+            $epoch = gmmktime($hour, $minute, $second, $month, $day, $year);
+        }
+        return $epoch;
+    }
 
-	public function parseEpoch($line) {
-		$epoch = strtotime(substr($line, 0, $this->datelength));
-		if ($epoch > time() + 60*60*24*31) {
-			/*
-			 * More than a month in the future - probably caused by
-			 * the log files missing the year.
-			 * We will therefore subtrackt one year.
-			 */
-			$hour = gmdate('H', $epoch);
-			$minute = gmdate('i', $epoch);
-			$second = gmdate('s', $epoch);
-			$month = gmdate('n', $epoch);
-			$day = gmdate('j', $epoch);
-			$year = gmdate('Y', $epoch) - 1;
-			$epoch = gmmktime($hour, $minute, $second, $month, $day, $year);
-		}
-		return $epoch;
-	}
+    public function parseContent($line) {
+        $contentstr = substr($line, $this->offset);
+        $content = explode(' ', $contentstr);
+        return $content;
+    }
 
-	public function parseContent($line) {
-		$contentstr = substr($line, $this->offset);
-		$content = explode(' ', $contentstr);
-		return $content;
-	}
-	
-	
-	# Aug 27 12:54:25 ssp 5 STAT [5416262207] saml20-sp-SSO urn:mace:feide.no:services:no.uninett.wiki-feide sam.feide.no NA
-	# 
-	#Oct 30 11:07:14 www1 simplesamlphp-foodle[12677]: 5 STAT [200b4679af] saml20-sp-SLO spinit urn:mace:feide.no:services:no.feide.foodle sam.feide.no
-	
-	function parse15($str) {
-		$di = date_parse($str);
-		$datestamp = mktime($di['hour'], $di['minute'], $di['second'], $di['month'], $di['day']);	
-		return $datestamp;
-	}
-	
-	function parse23($str) {
-		$timestamp = strtotime($str);
-		return $timestamp;
-	}
+    // Aug 27 12:54:25 ssp 5 STAT [5416262207] saml20-sp-SSO urn:mace:feide.no:services:no.uninett.wiki-feide sam.feide.no NA
+    // 
+    // Oct 30 11:07:14 www1 simplesamlphp-foodle[12677]: 5 STAT [200b4679af] saml20-sp-SLO spinit urn:mace:feide.no:services:no.feide.foodle sam.feide.no
 
+    function parse15($str) {
+        $di = date_parse($str);
+        $datestamp = mktime($di['hour'], $di['minute'], $di['second'], $di['month'], $di['day']);	
+        return $datestamp;
+    }
 
+    function parse23($str) {
+        $timestamp = strtotime($str);
+        return $timestamp;
+    }
 }
diff --git a/modules/statistics/lib/RatioDataset.php b/modules/statistics/lib/RatioDataset.php
index 7cb82c8749ab262102dcdec3510701be9bcf2d00..a88573c65697df752766edc1fa8bf1c42e8dd570 100644
--- a/modules/statistics/lib/RatioDataset.php
+++ b/modules/statistics/lib/RatioDataset.php
@@ -3,69 +3,76 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_RatioDataset extends sspmod_statistics_StatDataset {
+class sspmod_statistics_RatioDataset extends sspmod_statistics_StatDataset
+{
+    public function aggregateSummary()
+    {
+        /**
+         * Aggregate summary table from dataset. To be used in the table view.
+         */
+        $this->summary = array(); 
+        $noofvalues = array();
+        foreach ($this->results as $slot => $res) {
+            foreach ($res AS $key => $value) {
+                if (array_key_exists($key, $this->summary)) {
+                    $this->summary[$key] += $value;
+                    if ($value > 0) {
+                        $noofvalues[$key]++;
+                    }
+                } else {
+                    $this->summary[$key] = $value;
+                    if ($value > 0) {
+                        $noofvalues[$key] = 1;
+                    } else {
+                        $noofvalues[$key] = 0;
+                    }
+                }
+            }
+        }
 
-	
-	public function aggregateSummary() {
-		/**
-		 * Aggregate summary table from dataset. To be used in the table view.
-		 */
-		$this->summary = array(); 
-		$noofvalues = array();
-		foreach($this->results AS $slot => $res) {
-			foreach ($res AS $key => $value) {
-				if (array_key_exists($key, $this->summary)) {
-					$this->summary[$key] += $value;
-					if ($value > 0) 
-						$noofvalues[$key]++;
-				} else {
-					$this->summary[$key] = $value;
-					if ($value > 0) 
-						$noofvalues[$key] = 1;
-					else 
-						$noofvalues[$key] = 0;
-				}
-			}
-		}
-		
-		foreach($this->summary AS $key => $val) {
-			$this->summary[$key] = $this->divide($this->summary[$key], $noofvalues[$key]);
-		}
-		
-		asort($this->summary);
-		$this->summary = array_reverse($this->summary, TRUE);
-	}
-	
-	private function ag($k, $a) {
-		if (array_key_exists($k, $a)) return $a[$k];
-		return 0;
-	}
-	
-	private function divide($v1, $v2) {
-		if ($v2 == 0) return 0;
-		return ($v1 / $v2);
-	}
-	
-	public function combine($result1, $result2) {
+        foreach ($this->summary as $key => $val) {
+            $this->summary[$key] = $this->divide($this->summary[$key], $noofvalues[$key]);
+        }
 
-		$combined = array();
-		
-		foreach($result2 AS $tick => $val) {
-			$combined[$tick] = array();
-			foreach($val AS $index => $num) {
-				$combined[$tick][$index] = $this->divide( 
-					$this->ag($index, $result1[$tick]),
-					$this->ag($index, $result2[$tick])
-				);
-			}
-			
-		}
-		return $combined;
-	}
-	
-	public function getPieData() {
-		return NULL;
-	}
+        asort($this->summary);
+        $this->summary = array_reverse($this->summary, true);
+    }
 
+    private function ag($k, $a)
+    {
+        if (array_key_exists($k, $a)) {
+            return $a[$k];
+        }
+        return 0;
+    }
+
+    private function divide($v1, $v2)
+    {
+        if ($v2 == 0) {
+            return 0;
+        }
+        return ($v1 / $v2);
+    }
+
+    public function combine($result1, $result2)
+    {
+        $combined = array();
+
+        foreach ($result2 as $tick => $val) {
+            $combined[$tick] = array();
+            foreach ($val as $index => $num) {
+                $combined[$tick][$index] = $this->divide( 
+                    $this->ag($index, $result1[$tick]),
+                    $this->ag($index, $result2[$tick])
+                );
+            }
+        }
+        return $combined;
+    }
+
+    public function getPieData()
+    {
+        return null;
+    }
 }
 
diff --git a/modules/statistics/lib/Ruleset.php b/modules/statistics/lib/Ruleset.php
index 1d3231064d6cd40ff068ae950e74fd026e5ec939..643a118e50cf50c58a1097a9602999690ce4ecae 100644
--- a/modules/statistics/lib/Ruleset.php
+++ b/modules/statistics/lib/Ruleset.php
@@ -3,88 +3,93 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_Ruleset {
+class sspmod_statistics_Ruleset
+{
+    private $statconfig;
+    private $availrulenames;
+    private $availrules;
+    private $available;
 
-	private $statconfig;
-	private $availrulenames;
-	private $availrules;
-	private $available;
+    /**
+     * Constructor
+     */
+    public function __construct($statconfig)
+    {
+        $this->statconfig = $statconfig;
+        $this->init();
+    }
 
-	/**
-	 * Constructor
-	 */
-	public function __construct($statconfig) {
-		$this->statconfig = $statconfig;
-		$this->init();
-	}
+    private function init()
+    {
+        $statdir = $this->statconfig->getValue('statdir');
+        $inputfile = $this->statconfig->getValue('inputfile');
+        $statrules = $this->statconfig->getValue('statrules');
+        $timeres = $this->statconfig->getValue('timeres');
 
-	private function init() {
-		
-		$statdir = $this->statconfig->getValue('statdir');
-		$inputfile = $this->statconfig->getValue('inputfile');
-		$statrules = $this->statconfig->getValue('statrules');
-		$timeres = $this->statconfig->getValue('timeres');
+        /*
+         * Walk through file lists, and get available [rule][fileslot]...
+         */
+        if (!is_dir($statdir)) {
+            throw new Exception('Statisics output directory [' . $statdir . '] does not exists.');
+        }
+        $filelist = scandir($statdir);
+        $this->available = array();
+        foreach ($filelist as $file) {
+        if (preg_match('/([a-z0-9_]+)-([a-z0-9_]+)-([0-9]+)\.stat/', $file, $matches)) {
+            if (array_key_exists($matches[1], $statrules)) {
+                if (array_key_exists($matches[2], $timeres)) 
+                    $this->available[$matches[1]][$matches[2]][] = $matches[3];
+                }
+            }
+        }
+        if (empty($this->available)) {
+            throw new Exception('No aggregated statistics files found in [' . $statdir . ']');
+        }
 
-		/*
-		 * Walk through file lists, and get available [rule][fileslot]...
-		 */
-		if (!is_dir($statdir))
-			throw new Exception('Statisics output directory [' . $statdir . '] does not exists.');
-		$filelist = scandir($statdir);
-		$this->available = array();
-		foreach ($filelist AS $file) {
-			if (preg_match('/([a-z0-9_]+)-([a-z0-9_]+)-([0-9]+)\.stat/', $file, $matches)) {
-				if (array_key_exists($matches[1], $statrules)) {
-					if (array_key_exists($matches[2], $timeres)) 
-						$this->available[$matches[1]][$matches[2]][] = $matches[3];
-				}
-			}
-		}
-		if (empty($this->available)) 
-			throw new Exception('No aggregated statistics files found in [' . $statdir . ']');
+        /*
+         * Create array with information about available rules..
+         */
+        $this->availrules = array_keys($statrules);
+        $available_rules = array();
+        foreach ($this->availrules as $key) {
+            $available_rules[$key] = array('name' => $statrules[$key]['name'], 'descr' => $statrules[$key]['descr']);
+        }
+        $this->availrulenames = $available_rules;
+    }
 
-		/*
-		 * Create array with information about available rules..
-		 */
-		$this->availrules = array_keys($statrules);
-		$available_rules = array();
-		foreach ($this->availrules AS $key) {
-			$available_rules[$key] = array('name' => $statrules[$key]['name'], 'descr' => $statrules[$key]['descr']);
-		}
-		$this->availrulenames = $available_rules;
-		
-	}
-	
-	public function availableRules() {
-		return $this->availrules;
-	}
-	
-	public function availableRulesNames() {
-		return $this->availrulenames;
-	}
-	
-	/**
-	 * Resolve which rule is selected. Taking user preference and checks if it exists.
-	 */
-	private function resolveSelectedRule($preferRule = NULL) {
-		$rule = $this->statconfig->getString('default', $this->availrules[0]);
-		if(!empty($preferRule)) {
-			if (in_array($preferRule, $this->availrules)) {
-				$rule = $preferRule;
-			}
-		}
-		return $rule;
-	}
-	
-	public function getRule($preferRule) {
-		$rule = $this->resolveSelectedRule($preferRule);
-		$statrulesConfig = $this->statconfig->getConfigItem('statrules');
-		$statruleConfig = $statrulesConfig->getConfigItem($rule);
-		
-		$presenterClass = SimpleSAML\Module::resolveClass($statruleConfig->getValue('presenter', 'statistics:BaseRule'), 'Statistics_Rulesets');
-		$statrule = new $presenterClass($this->statconfig, $statruleConfig, $rule, $this->available);
-		return $statrule;
-	}
+    public function availableRules()
+    {
+        return $this->availrules;
+    }
 
+    public function availableRulesNames()
+    {
+        return $this->availrulenames;
+    }
+
+    /**
+     * Resolve which rule is selected. Taking user preference and checks if it exists.
+     */
+    private function resolveSelectedRule($preferRule = null)
+    {
+        $rule = $this->statconfig->getString('default', $this->availrules[0]);
+        if (!empty($preferRule)) {
+            if (in_array($preferRule, $this->availrules)) {
+                $rule = $preferRule;
+            }
+        }
+        return $rule;
+    }
+
+    public function getRule($preferRule)
+    {
+        $rule = $this->resolveSelectedRule($preferRule);
+        $statrulesConfig = $this->statconfig->getConfigItem('statrules');
+        $statruleConfig = $statrulesConfig->getConfigItem($rule);
+
+        $presenterClass = SimpleSAML\Module::resolveClass($statruleConfig->getValue('presenter', 'statistics:BaseRule'), 'Statistics_Rulesets');
+        $statrule = new $presenterClass($this->statconfig, $statruleConfig, $rule, $this->available);
+        return $statrule;
+    }
 }
 
diff --git a/modules/statistics/lib/StatDataset.php b/modules/statistics/lib/StatDataset.php
index 1c4067196d9d13fc6f3dfd7a56f5587b5db618b8..79eceeecafe5ae5ab24b03e154a3e25c093846d1 100644
--- a/modules/statistics/lib/StatDataset.php
+++ b/modules/statistics/lib/StatDataset.php
@@ -7,7 +7,6 @@
  */
 class sspmod_statistics_StatDataset
 {
-
     protected $statconfig;
     protected $ruleconfig;
     protected $timeresconfig;
@@ -55,19 +54,16 @@ class sspmod_statistics_StatDataset
         $this->loadData();
     }
 
-
     public function getFileSlot()
     {
         return $this->fileslot;
     }
 
-
     public function getTimeRes()
     {
         return $this->timeres;
     }
 
-
     public function setDelimiter($delimiter = '_')
     {
         if (empty($delimiter)) {
@@ -76,7 +72,6 @@ class sspmod_statistics_StatDataset
         $this->delimiter = $delimiter;
     }
 
-
     public function getDelimiter()
     {
         if ($this->delimiter === '_') {
@@ -85,7 +80,6 @@ class sspmod_statistics_StatDataset
         return $this->delimiter;
     }
 
-
     public function calculateMax()
     {
         $maxvalue = 0;
@@ -98,7 +92,6 @@ class sspmod_statistics_StatDataset
         $this->max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue);
     }
 
-
     public function getDebugData()
     {
         $debugdata = array();
@@ -115,7 +108,6 @@ class sspmod_statistics_StatDataset
         return $debugdata;
     }
 
-
     public function aggregateSummary()
     {
         // aggregate summary table from dataset. To be used in the table view
@@ -133,7 +125,6 @@ class sspmod_statistics_StatDataset
         $this->summary = array_reverse($this->summary, true);
     }
 
-
     public function getTopDelimiters()
     {
         // create a list of delimiter keys that has the highest total summary in this period
@@ -151,7 +142,6 @@ class sspmod_statistics_StatDataset
         return $topdelimiters;
     }
 
-
     public function availDelimiters()
     {
         $availDelimiters = array();
@@ -161,7 +151,6 @@ class sspmod_statistics_StatDataset
         return array_keys($availDelimiters);
     }
 
-
     public function getPieData()
     {
         $piedata = array();
@@ -176,25 +165,21 @@ class sspmod_statistics_StatDataset
         return $piedata;
     }
 
-
     public function getMax()
     {
         return $this->max;
     }
 
-
     public function getSummary()
     {
         return $this->summary;
     }
 
-
     public function getResults()
     {
         return $this->results;
     }
 
-
     public function getAxis()
     {
         $slotsize = $this->timeresconfig->getValue('slot');
@@ -223,7 +208,6 @@ class sspmod_statistics_StatDataset
         return array('axis' => $axis, 'axispos' => $axispos);
     }
 
-
     /*
      * Walk through dataset to get percent values from max into dataset[].
      */
@@ -247,7 +231,6 @@ class sspmod_statistics_StatDataset
         return $dataset;
     }
 
-
     public function getDelimiterPresentation()
     {
         $config = SimpleSAML_Configuration::getInstance();
@@ -273,7 +256,6 @@ class sspmod_statistics_StatDataset
         return array();
     }
 
-
     public function getDelimiterPresentationPie()
     {
         $topdelimiters = $this->getTopDelimiters();
@@ -291,7 +273,6 @@ class sspmod_statistics_StatDataset
         return $pieaxis;
     }
 
-
     public function loadData()
     {
         $statdir = $this->statconfig->getValue('statdir');
diff --git a/modules/statistics/lib/Statistics/FieldPresentation/Base.php b/modules/statistics/lib/Statistics/FieldPresentation/Base.php
index 18eb0bdecc17238b4fe1518388bd1aa29d5f8abd..e02300094bccf70260f34f27eafac8b0382c443a 100644
--- a/modules/statistics/lib/Statistics/FieldPresentation/Base.php
+++ b/modules/statistics/lib/Statistics/FieldPresentation/Base.php
@@ -1,20 +1,20 @@
 <?php
 
-class sspmod_statistics_Statistics_FieldPresentation_Base {
-	
-	protected $fields;
-	protected $template;
-	protected $config;
-	
-	function __construct($fields, $config, $template) {
-		$this->fields = $fields;
-		$this->template = $template;
-		$this->config = $config;
-	}
-	
-	public function getPresentation() {
-		return array('_' => 'Total');
-	}
-	
-	
-}
\ No newline at end of file
+class sspmod_statistics_Statistics_FieldPresentation_Base
+{
+    protected $fields;
+    protected $template;
+    protected $config;
+
+    function __construct($fields, $config, $template)
+    {
+        $this->fields = $fields;
+        $this->template = $template;
+        $this->config = $config;
+    }
+
+    public function getPresentation()
+    {
+        return array('_' => 'Total');
+    }
+}
diff --git a/modules/statistics/lib/Statistics/FieldPresentation/Entity.php b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
index 6d1bf9d6878038ce3866adc7048532be1bcedf0e..5556d08f819e68ac0d05354adda58c26b506924c 100644
--- a/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
+++ b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php
@@ -1,23 +1,20 @@
 <?php
 
-class sspmod_statistics_Statistics_FieldPresentation_Entity extends sspmod_statistics_Statistics_FieldPresentation_Base {
-	
-	
-	public function getPresentation() {
-		$mh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
-		$metadata = $mh->getList($this->config);
-		
-		$translation = array('_' => 'All services');
-		foreach($this->fields AS $field) {
-			if (array_key_exists($field, $metadata)) {
-				if (array_key_exists('name', $metadata[$field])) {
-					$translation[$field] = $this->template->t($metadata[$field]['name'], array(), FALSE);
-				}
-			}
-		}
-		return $translation;
-	}
+class sspmod_statistics_Statistics_FieldPresentation_Entity extends sspmod_statistics_Statistics_FieldPresentation_Base
+{
+    public function getPresentation()
+    {
+        $mh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
+        $metadata = $mh->getList($this->config);
 
-	
-	
-}
\ No newline at end of file
+        $translation = array('_' => 'All services');
+        foreach ($this->fields as $field) {
+            if (array_key_exists($field, $metadata)) {
+                if (array_key_exists('name', $metadata[$field])) {
+                    $translation[$field] = $this->template->t($metadata[$field]['name'], array(), false);
+                }
+            }
+        }
+        return $translation;
+    }
+}
diff --git a/modules/statistics/lib/Statistics/Rulesets/BaseRule.php b/modules/statistics/lib/Statistics/Rulesets/BaseRule.php
index 66b8da5f3236fa9f6e3641d1e4db9f269651249b..865cd2782c6af5d3e8977a73c19ad7579d483163 100644
--- a/modules/statistics/lib/Statistics/Rulesets/BaseRule.php
+++ b/modules/statistics/lib/Statistics/Rulesets/BaseRule.php
@@ -3,114 +3,117 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_Statistics_Rulesets_BaseRule {
-
-	protected $statconfig;
-	protected $ruleconfig;
-	protected $ruleid;
-	protected $available;
-
-	/**
-	 * Constructor
-	 */
-	public function __construct($statconfig, $ruleconfig, $ruleid, $available) {
-		assert('$statconfig instanceof SimpleSAML_Configuration');
-		assert('$ruleconfig instanceof SimpleSAML_Configuration');
-		$this->statconfig = $statconfig;
-		$this->ruleconfig = $ruleconfig;
-		$this->ruleid = $ruleid;
-		
-		$this->available = NULL;
-		if (array_key_exists($ruleid, $available)) $this->available = $available[$ruleid];	
-	}
-	
-	public function getRuleID() {
-		return $this->ruleid;
-	}
-	
-	public function init() {
-
-	}
-	
-	public function availableTimeRes() {
-		$timeresConfigs = $this->statconfig->getValue('timeres');
-		$available_times = array(); 
-		foreach ($timeresConfigs AS $tres => $tresconfig) {
-			if (array_key_exists($tres, $this->available))
-				$available_times[$tres] = $tresconfig['name'];
-		}
-		return $available_times;
-	}
-
-	
-	public function availableFileSlots($timeres) {
-		$timeresConfigs = $this->statconfig->getValue('timeres');
-		$timeresConfig = $timeresConfigs[$timeres];
-		
-		if (isset($timeresConfig['customDateHandler']) && $timeresConfig['customDateHandler'] == 'month') {
-			$datehandler = new sspmod_statistics_DateHandlerMonth(0);
-		} else {
-			$datehandler = new sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
-		}
-		
-		
-		/*
-		 * Get list of avaiable times in current file (rule)
-		 */
-		$available_times = array(); 
-		foreach ($this->available[$timeres] AS $slot) {
-			$available_times[$slot] = $datehandler->prettyHeader($slot, $slot+1, $timeresConfig['fileslot'], $timeresConfig['dateformat-period']);
-		}
-		return $available_times;
-	}
-
-	protected function resolveTimeRes($preferTimeRes) {
-		$timeresavailable = array_keys($this->available);
-		$timeres = $timeresavailable[0];
-
-		// Then check if the user have provided one that is valid
-		if (in_array($preferTimeRes, $timeresavailable)) {
-			$timeres = $preferTimeRes;
-		}
-		return $timeres;
-	}
-	
-	protected function resolveFileSlot($timeres, $preferTime) {
-
-		// Get which time (fileslot) to use.. First get a default, which is the most recent one.
-		$fileslot = $this->available[$timeres][count($this->available[$timeres])-1];
-		// Then check if the user have provided one.
-		if (in_array($preferTime, $this->available[$timeres])) {
-			$fileslot = $preferTime;
-		}
-		return $fileslot;
-	}
-	
-	
-	public function getTimeNavigation($timeres, $preferTime) {
-		$fileslot = $this->resolveFileSlot($timeres, $preferTime);
-		
-		// Extract previous and next time slots...
-		$available_times_prev = NULL; $available_times_next = NULL;
-
-		$timeslots = array_values($this->available[$timeres]);
-		sort($timeslots, SORT_NUMERIC);
-		$timeslotindex = array_flip($timeslots);
-
-		if ($timeslotindex[$fileslot] > 0) 
-			$available_times_prev = $timeslots[$timeslotindex[$fileslot]-1];
-		if ($timeslotindex[$fileslot] < (count($timeslotindex)-1) ) 
-			$available_times_next = $timeslots[$timeslotindex[$fileslot]+1];
-		return array('prev' => $available_times_prev, 'next' => $available_times_next);
-	}
-	
-	public function getDataSet($preferTimeRes, $preferTime) {
-		$timeres = $this->resolveTimeRes($preferTimeRes);
-		$fileslot = $this->resolveFileSlot($timeres, $preferTime);
-		$dataset = new sspmod_statistics_StatDataset($this->statconfig, $this->ruleconfig, $this->ruleid, $timeres, $fileslot);
-		return $dataset;
-	}
-	
+class sspmod_statistics_Statistics_Rulesets_BaseRule
+{
+    protected $statconfig;
+    protected $ruleconfig;
+    protected $ruleid;
+    protected $available;
 
+    /**
+     * Constructor
+     */
+    public function __construct($statconfig, $ruleconfig, $ruleid, $available)
+    {
+        assert('$statconfig instanceof SimpleSAML_Configuration');
+        assert('$ruleconfig instanceof SimpleSAML_Configuration');
+        $this->statconfig = $statconfig;
+        $this->ruleconfig = $ruleconfig;
+        $this->ruleid = $ruleid;
+
+        $this->available = null;
+        if (array_key_exists($ruleid, $available)) {
+            $this->available = $available[$ruleid];	
+        }
+    }
+
+    public function getRuleID()
+    {
+        return $this->ruleid;
+    }
+
+    public function availableTimeRes() {
+        $timeresConfigs = $this->statconfig->getValue('timeres');
+        $available_times = array(); 
+        foreach ($timeresConfigs as $tres => $tresconfig) {
+            if (array_key_exists($tres, $this->available)) {
+                $available_times[$tres] = $tresconfig['name'];
+            }
+        }
+        return $available_times;
+    }
+
+    public function availableFileSlots($timeres)
+    {
+        $timeresConfigs = $this->statconfig->getValue('timeres');
+        $timeresConfig = $timeresConfigs[$timeres];
+
+        if (isset($timeresConfig['customDateHandler']) && $timeresConfig['customDateHandler'] == 'month') {
+            $datehandler = new sspmod_statistics_DateHandlerMonth(0);
+        } else {
+            $datehandler = new sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
+        }
+
+        /*
+         * Get list of avaiable times in current file (rule)
+         */
+        $available_times = array(); 
+        foreach ($this->available[$timeres] as $slot) {
+            $available_times[$slot] = $datehandler->prettyHeader($slot, $slot + 1, $timeresConfig['fileslot'], $timeresConfig['dateformat-period']);
+        }
+        return $available_times;
+    }
+
+    protected function resolveTimeRes($preferTimeRes)
+    {
+        $timeresavailable = array_keys($this->available);
+        $timeres = $timeresavailable[0];
+
+        // Then check if the user have provided one that is valid
+        if (in_array($preferTimeRes, $timeresavailable)) {
+            $timeres = $preferTimeRes;
+        }
+        return $timeres;
+    }
+
+    protected function resolveFileSlot($timeres, $preferTime)
+    {
+        // Get which time (fileslot) to use.. First get a default, which is the most recent one.
+        $fileslot = $this->available[$timeres][count($this->available[$timeres]) - 1];
+        // Then check if the user have provided one.
+        if (in_array($preferTime, $this->available[$timeres])) {
+            $fileslot = $preferTime;
+        }
+        return $fileslot;
+    }
+
+    public function getTimeNavigation($timeres, $preferTime)
+    {
+        $fileslot = $this->resolveFileSlot($timeres, $preferTime);
+
+        // Extract previous and next time slots...
+        $available_times_prev = null;
+        $available_times_next = null;
+
+        $timeslots = array_values($this->available[$timeres]);
+        sort($timeslots, SORT_NUMERIC);
+        $timeslotindex = array_flip($timeslots);
+
+        if ($timeslotindex[$fileslot] > 0) {
+            $available_times_prev = $timeslots[$timeslotindex[$fileslot] - 1];
+        }
+        if ($timeslotindex[$fileslot] < (count($timeslotindex) - 1)) {
+            $available_times_next = $timeslots[$timeslotindex[$fileslot] + 1];
+        }
+        return array('prev' => $available_times_prev, 'next' => $available_times_next);
+    }
+
+    public function getDataSet($preferTimeRes, $preferTime)
+    {
+        $timeres = $this->resolveTimeRes($preferTimeRes);
+        $fileslot = $this->resolveFileSlot($timeres, $preferTime);
+        $dataset = new sspmod_statistics_StatDataset($this->statconfig, $this->ruleconfig, $this->ruleid, $timeres, $fileslot);
+        return $dataset;
+    }
 }
 
diff --git a/modules/statistics/lib/Statistics/Rulesets/Ratio.php b/modules/statistics/lib/Statistics/Rulesets/Ratio.php
index 8b7ab10bfe0f711ac1bb774ad7205add5c991082..39512d3c5bba6eb78ef0734980016caf8effafb0 100644
--- a/modules/statistics/lib/Statistics/Rulesets/Ratio.php
+++ b/modules/statistics/lib/Statistics/Rulesets/Ratio.php
@@ -3,62 +3,66 @@
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package SimpleSAMLphp
  */
-class sspmod_statistics_Statistics_Rulesets_Ratio extends sspmod_statistics_Statistics_Rulesets_BaseRule {
+class sspmod_statistics_Statistics_Rulesets_Ratio extends sspmod_statistics_Statistics_Rulesets_BaseRule
+{
+    protected $refrule1;
+    protected $refrule2;
 
-	protected $refrule1;
-	protected $refrule2;
-	
-	/**
-	 * Constructor
-	 */
-	public function __construct($statconfig, $ruleconfig, $ruleid, $available) {
-		assert('$statconfig instanceof SimpleSAML_Configuration');
-		assert('$ruleconfig instanceof SimpleSAML_Configuration');
-		
-		parent::__construct($statconfig, $ruleconfig, $ruleid, $available);
-		
-		$refNames = $this->ruleconfig->getArray('ref');
-		
-		$statrulesConfig = $this->statconfig->getConfigItem('statrules');
-		
-		$statruleConfig1 = $statrulesConfig->getConfigItem($refNames[0]);
-		$statruleConfig2 = $statrulesConfig->getConfigItem($refNames[1]);
-		
-		$this->refrule1 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig1, $refNames[0], $available);
-		$this->refrule2 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig2, $refNames[1], $available);
-	}
-	
-	public function availableTimeRes() {
-		return $this->refrule1->availableTimeRes();
-	}
-	
-	public function availableFileSlots($timeres) {
-		return $this->refrule1->availableFileSlots($timeres);
-	}
+    /**
+     * Constructor
+     */
+    public function __construct($statconfig, $ruleconfig, $ruleid, $available)
+    {
+        assert('$statconfig instanceof SimpleSAML_Configuration');
+        assert('$ruleconfig instanceof SimpleSAML_Configuration');
 
-	protected function resolveTimeRes($preferTimeRes) {
-		return $this->refrule1->resolveTimeRes($preferTimeRes);
-	}
-	
-	protected function resolveFileSlot($timeres, $preferTime) {
-		return $this->refrule1->resolveFileSlot($timeres, $preferTime);
-	}
-	
-	
-	public function getTimeNavigation($timeres, $preferTime) {
-		return $this->refrule1->getTimeNavigation($timeres, $preferTime);
-	}
-	
-	public function getDataSet($preferTimeRes, $preferTime) {
-		$timeres = $this->resolveTimeRes($preferTimeRes);
-		$fileslot = $this->resolveFileSlot($timeres, $preferTime);
-		
-		$refNames = $this->ruleconfig->getArray('ref');
-		
-		$dataset = new sspmod_statistics_RatioDataset($this->statconfig, $this->ruleconfig, $refNames, $timeres, $fileslot);
-		return $dataset;
-	}
-	
+        parent::__construct($statconfig, $ruleconfig, $ruleid, $available);
 
+        $refNames = $this->ruleconfig->getArray('ref');
+
+        $statrulesConfig = $this->statconfig->getConfigItem('statrules');
+
+        $statruleConfig1 = $statrulesConfig->getConfigItem($refNames[0]);
+        $statruleConfig2 = $statrulesConfig->getConfigItem($refNames[1]);
+
+        $this->refrule1 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig1, $refNames[0], $available);
+        $this->refrule2 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig2, $refNames[1], $available);
+    }
+
+    public function availableTimeRes()
+    {
+        return $this->refrule1->availableTimeRes();
+    }
+
+    public function availableFileSlots($timeres)
+    {
+        return $this->refrule1->availableFileSlots($timeres);
+    }
+
+    protected function resolveTimeRes($preferTimeRes)
+    {
+        return $this->refrule1->resolveTimeRes($preferTimeRes);
+    }
+
+    protected function resolveFileSlot($timeres, $preferTime)
+    {
+        return $this->refrule1->resolveFileSlot($timeres, $preferTime);
+    }
+
+    public function getTimeNavigation($timeres, $preferTime)
+    {
+        return $this->refrule1->getTimeNavigation($timeres, $preferTime);
+    }
+
+    public function getDataSet($preferTimeRes, $preferTime)
+    {
+        $timeres = $this->resolveTimeRes($preferTimeRes);
+        $fileslot = $this->resolveFileSlot($timeres, $preferTime);
+
+        $refNames = $this->ruleconfig->getArray('ref');
+
+        $dataset = new sspmod_statistics_RatioDataset($this->statconfig, $this->ruleconfig, $refNames, $timeres, $fileslot);
+        return $dataset;
+    }
 }
 
diff --git a/modules/statistics/templates/statistics.tpl.php b/modules/statistics/templates/statistics.tpl.php
index 1efa682d37d32f28aa21153bb2579fa58e07b93d..fdc5e5be2f00eb8efeba4bcc821ae76c54dc3d13 100644
--- a/modules/statistics/templates/statistics.tpl.php
+++ b/modules/statistics/templates/statistics.tpl.php
@@ -1,132 +1,136 @@
 <?php
 $this->data['header'] = 'SimpleSAMLphp Statistics';
 
-$this->data['jquery'] = array('core' => TRUE, 'ui' => TRUE, 'css' => TRUE);
+$this->data['jquery'] = array('core' => true, 'ui' => true, 'css' => true);
 
-$this->data['head'] ='';
+$this->data['head'] = '';
 $this->data['head'] .= '<script type="text/javascript">
 $(document).ready(function() {
-	$("#tabdiv").tabs();
+    $("#tabdiv").tabs();
 });
 </script>';
 
 $this->includeAtTemplateBase('includes/header.php');
 
+function getBaseURL($t, $type = 'get', $key = null, $value = null)
+{
+    $vars = array(
+        'rule' => $t->data['selected.rule'],
+        'time' => $t->data['selected.time'],
+        'res' => $t->data['selected.timeres'],
+    );
+    if (isset($t->data['selected.delimiter'])) {
+        $vars['d'] = $t->data['selected.delimiter'];
+    }
+    if (!empty($t->data['selected.rule2']) && $t->data['selected.rule2'] !== '_') {
+        $vars['rule2'] = $t->data['selected.rule2'];
+    }
 
-function getBaseURL($t, $type = 'get', $key = NULL, $value = NULL) {
-	$vars = array(
-		'rule' => $t->data['selected.rule'],
-		'time' => $t->data['selected.time'],
-		'res' => $t->data['selected.timeres'],
-	);
-	if (isset($t->data['selected.delimiter'])) $vars['d'] = $t->data['selected.delimiter'];
-	if (!empty($t->data['selected.rule2']) && $t->data['selected.rule2'] !== '_') $vars['rule2'] = $t->data['selected.rule2'];
-	
-	if (isset($key)) {
-		if (isset($vars[$key])) unset($vars[$key]);
-		if (isset($value)) $vars[$key] = $value;
-	}
-
-	if ($type === 'get') {
-		return 'showstats.php?' . http_build_query($vars, '', '&amp;');
-	} else {
-		$text = '';
-		foreach($vars AS $k => $v) {
-			$text .= '<input type="hidden" name="' . $k . '" value="'. htmlspecialchars($v) . '" />' . "\n";
-		}
-		return $text;
-	}
-	
-}
-
-
+    if (isset($key)) {
+        if (isset($vars[$key])) {
+            unset($vars[$key]);
+        }
+        if (isset($value)) {
+            $vars[$key] = $value;
+        }
+    }
 
+    if ($type === 'get') {
+        return 'showstats.php?' . http_build_query($vars, '', '&amp;');
+    } else {
+        $text = '';
+        foreach($vars as $k => $v) {
+            $text .= '<input type="hidden" name="' . $k . '" value="'. htmlspecialchars($v) . '" />' . "\n";
+        }
+        return $text;
+    }
+}
 ?>
 
-	<style type="text/css" media="all">
+        <style type="text/css" media="all">
 .ui-tabs-panel { padding: .5em }
 div#content {
-	margin: .4em ! important;
+        margin: .4em ! important;
 }
 .tableview {
-	border-collapse: collapse;
-	border: 1px solid #ccc;
-	margin: 1em;
-	width: 80%;
+        border-collapse: collapse;
+        border: 1px solid #ccc;
+        margin: 1em;
+        width: 80%;
 }
 .tableview th, .tableview td{
-	border: 1px solid: #ccc;
-	padding: 0px 5px;
+        border: 1px solid: #ccc;
+        padding: 0px 5px;
 }
 .tableview th {
-	background: #e5e5e5;
+        background: #e5e5e5;
 }
 .tableview tr.total td {
-	color: #500; font-weight: bold;
+        color: #500; font-weight: bold;
 }
 .tableview tr.even td {
-	background: #f5f5f5;
-	border-top: 1px solid #e0e0e0;
-	border-bottom: 1px solid #e0e0e0;
+        background: #f5f5f5;
+        border-top: 1px solid #e0e0e0;
+        border-bottom: 1px solid #e0e0e0;
 }
 .tableview th.value, .tableview td.value {
-	text-align: right;
+        text-align: right;
 }
 div.corner_t {
     max-width: none ! important;
 }
 table.timeseries tr.odd td {
-	background-color: #f4f4f4;
+        background-color: #f4f4f4;
 }
 table.timeseries td {
-	padding-right: 2em; border: 1px solid #ccc
+        padding-right: 2em; border: 1px solid #ccc
 }
 td.datacontent {
-	text-align: right;
+        text-align: right;
 }
-	</style>
+        </style>
 
 <?php
-echo('<h1>'. $this->data['available.rules'][$this->data['selected.rule']]['name'] . '</h1>');
-echo('<p>' . $this->data['available.rules'][$this->data['selected.rule']]['descr'] . '</p>');
+echo '<h1>'. $this->data['available.rules'][$this->data['selected.rule']]['name'] . '</h1>';
+echo '<p>' . $this->data['available.rules'][$this->data['selected.rule']]['descr'] . '</p>';
 
 // Report settings
 echo '<table class="selecttime" style="width: 100%; border: 1px solid #ccc; background: #eee; margin: 1px 0px; padding: 0px">';
-echo('<tr><td style="width: 50px; padding: 0px"><img style="margin: 0px" src="../../resources/icons/crystal_project/kchart.32x32.png" alt="Report settings" /></td>');
+echo '<tr><td style="width: 50px; padding: 0px"><img style="margin: 0px" src="../../resources/icons/crystal_project/kchart.32x32.png" alt="Report settings" /></td>';
 
 // Select report
 echo '<td>';
 echo '<form style="display: inline">';
 echo getBaseURL($this, 'post', 'rule');
 echo '<select onChange="submit();" name="rule">';
-foreach ($this->data['available.rules'] AS $key => $rule) {
-	if ($key === $this->data['selected.rule']) {
-		echo '<option selected="selected" value="' . $key . '">' . $rule['name'] . '</option>';
-	} else {
-		echo '<option value="' . $key . '">' . $rule['name'] . '</option>';
-	}
+foreach ($this->data['available.rules'] as $key => $rule) {
+    if ($key === $this->data['selected.rule']) {
+        echo '<option selected="selected" value="' . $key . '">' . $rule['name'] . '</option>';
+    } else {
+        echo '<option value="' . $key . '">' . $rule['name'] . '</option>';
+    }
 }
 echo '</select></form>';
 echo '</td>';
 
-
 // Select delimiter
 echo '<td style="text-align: right">';
 echo '<form style="display: inline">';
 echo getBaseURL($this, 'post', 'd');
 echo '<select onChange="submit();" name="d">';
-foreach ($this->data['availdelimiters'] AS $key => $delim) {
-
-	$delimName = $delim;
-	if(array_key_exists($delim, $this->data['delimiterPresentation'])) $delimName = $this->data['delimiterPresentation'][$delim];
-
-	if ($key == '_') {
-		echo '<option value="_">Total</option>';
-	} elseif (isset($_REQUEST['d']) && $delim == $_REQUEST['d']) {
-		echo '<option selected="selected" value="' . htmlspecialchars($delim) . '">' . htmlspecialchars($delimName) . '</option>';
-	} else {
-		echo '<option  value="' . htmlspecialchars($delim) . '">' . htmlspecialchars($delimName) . '</option>';
-	}
+foreach ($this->data['availdelimiters'] as $key => $delim) {
+    $delimName = $delim;
+    if (array_key_exists($delim, $this->data['delimiterPresentation'])) {
+        $delimName = $this->data['delimiterPresentation'][$delim];
+    }
+
+    if ($key == '_') {
+        echo '<option value="_">Total</option>';
+    } elseif (isset($_REQUEST['d']) && $delim == $_REQUEST['d']) {
+        echo '<option selected="selected" value="' . htmlspecialchars($delim) . '">' . htmlspecialchars($delimName) . '</option>';
+    } else {
+        echo '<option  value="' . htmlspecialchars($delim) . '">' . htmlspecialchars($delimName) . '</option>';
+    }
 }
 echo '</select></form>';
 echo '</td>';
@@ -136,71 +140,53 @@ echo '</table>';
 // End report settings
 
 
-
-
 // Select time and date
 echo '<table class="selecttime" style="width: 100%; border: 1px solid #ccc; background: #eee; margin: 1px 0px; padding: 0px">';
-echo('<tr><td style="width: 50px; padding: 0px"><img style="margin: 0px" src="../../resources/icons/crystal_project/date.32x32.png" alt="Select date and time" /></td>');
-
-
-
-
-
+echo '<tr><td style="width: 50px; padding: 0px"><img style="margin: 0px" src="../../resources/icons/crystal_project/date.32x32.png" alt="Select date and time" /></td>';
 
 if (isset($this->data['available.times.prev'])) {
-
-	echo('<td style=""><a href="' . getBaseURL($this, 'get', 'time', $this->data['available.times.prev']) . '">« Previous</a></td>');
+    echo '<td style=""><a href="' . getBaseURL($this, 'get', 'time', $this->data['available.times.prev']) . '">« Previous</a></td>';
 } else {
-	echo('<td style="color: #ccc">« Previous</td>');
+    echo '<td style="color: #ccc">« Previous</td>';
 }
 
-
 echo '<td style="text-align: right">';
 echo '<form style="display: inline">';
 echo getBaseURL($this, 'post', 'res');
 echo '<select onChange="submit();" name="res">';
-foreach ($this->data['available.timeres'] AS $key => $timeresname) {
-	if ($key == $this->data['selected.timeres']) {
-		echo '<option selected="selected" value="' . $key . '">' . $timeresname . '</option>';
-	} else {
-		echo '<option  value="' . $key . '">' . $timeresname . '</option>';
-	}
+foreach ($this->data['available.timeres'] as $key => $timeresname) {
+    if ($key == $this->data['selected.timeres']) {
+        echo '<option selected="selected" value="' . $key . '">' . $timeresname . '</option>';
+    } else {
+        echo '<option  value="' . $key . '">' . $timeresname . '</option>';
+    }
 }
 echo '</select></form>';
 echo '</td>';
 
-
 echo '<td style="text-align: left">';
 echo '<form style="display: inline">';
 echo getBaseURL($this, 'post', 'time');
 echo '<select onChange="submit();" name="time">';
-foreach ($this->data['available.times'] AS $key => $timedescr) {
-	if ($key == $this->data['selected.time']) {
-		echo '<option selected="selected" value="' . $key . '">' . $timedescr . '</option>';
-	} else {
-		echo '<option  value="' . $key . '">' . $timedescr . '</option>';
-	}
+foreach ($this->data['available.times'] as $key => $timedescr) {
+    if ($key == $this->data['selected.time']) {
+        echo '<option selected="selected" value="' . $key . '">' . $timedescr . '</option>';
+    } else {
+        echo '<option  value="' . $key . '">' . $timedescr . '</option>';
+    }
 }
 echo '</select></form>';
 echo '</td>';
 
 if (isset($this->data['available.times.next'])) {
-	echo('<td style="text-align: right; padding-right: 4px"><a href="' . getBaseURL($this, 'get', 'time', $this->data['available.times.next']) . '">Next »</a></td>');
+    echo '<td style="text-align: right; padding-right: 4px"><a href="' . getBaseURL($this, 'get', 'time', $this->data['available.times.next']) . '">Next »</a></td>';
 } else {
-	echo('<td style="color: #ccc; text-align: right; padding-right: 4px">Next »</td>');
+    echo '<td style="color: #ccc; text-align: right; padding-right: 4px">Next »</td>';
 }
 
-
-
-
 echo '</tr></table>';
 
 
-
-
-
-
-
 echo '<div id="tabdiv"><ul class="tabset_tabs">
    <li><a href="#graph">Graph</a></li>
    <li><a href="#table">Summary table</a></li>
@@ -210,27 +196,23 @@ echo '
 
 <div id="graph" class="tabset_content">';
 
-
 echo '<img src="' . htmlspecialchars($this->data['imgurl']) . '" />';
 
-
 echo '<form style="display: inline">';
-echo('<p style="text-align: right">Compare with total from this dataset ');
+echo '<p style="text-align: right">Compare with total from this dataset ';
 echo getBaseURL($this, 'post', 'rule2');
 echo '<select onChange="submit();" name="rule2">';
 echo '	<option value="_">None</option>';
-foreach ($this->data['available.rules'] AS $key => $rule) {
-	if ($key === $this->data['selected.rule2']) {
-		echo '<option selected="selected" value="' . $key . '">' . $rule['name'] . '</option>';
-	} else {
-		echo '<option value="' . $key . '">' . $rule['name'] . '</option>';
-	}
+foreach ($this->data['available.rules'] as $key => $rule) {
+    if ($key === $this->data['selected.rule2']) {
+        echo '<option selected="selected" value="' . $key . '">' . $rule['name'] . '</option>';
+    } else {
+        echo '<option value="' . $key . '">' . $rule['name'] . '</option>';
+    }
 }
 echo '</select></form>';
 
-
-echo '</div>'; # end graph content.
-
+echo '</div>'; // end graph content.
 
 
 /**
@@ -240,20 +222,22 @@ $classint = array('odd', 'even'); $i = 0;
 echo '<div id="table" class="tabset_content">';
 
 if (isset($this->data['pieimgurl'])) {
-	echo('<img src="' . $this->data['pieimgurl'] . '" />');
+    echo '<img src="' . $this->data['pieimgurl'] . '" />';
 }
 echo '<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>';
 
-foreach ( $this->data['summaryDataset'] as $key => $value ) {
-	$clint = $classint[$i++ % 2];
-	
-	$keyName = $key;
-	if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key];
+foreach ($this->data['summaryDataset'] as $key => $value) {
+    $clint = $classint[$i++ % 2];
+
+    $keyName = $key;
+    if (array_key_exists($key, $this->data['delimiterPresentation'])) {
+        $keyName = $this->data['delimiterPresentation'][$key];
+    }
 
-	if ($key === '_') {
-	    echo '<tr class="total '  . $clint . '"><td  class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
+    if ($key === '_') {
+        echo '<tr class="total '  . $clint . '"><td  class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
     } else {
-	    echo '<tr class="' . $clint . '"><td  class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
+        echo '<tr class="' . $clint . '"><td  class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
     }
 }
 
@@ -262,35 +246,33 @@ echo '</table></div>';
 
 echo '<div id="debug" >';
 echo '<table class="timeseries" style="">';
-echo('<tr><th>Time</th><th>Total</th>');
-foreach($this->data['topdelimiters'] AS $key) {
-	$keyName = $key;
-	if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key];
- 	echo('<th>' . $keyName . '</th>');
+echo '<tr><th>Time</th><th>Total</th>';
+foreach ($this->data['topdelimiters'] as $key) {
+    $keyName = $key;
+    if (array_key_exists($key, $this->data['delimiterPresentation'])) {
+        $keyName = $this->data['delimiterPresentation'][$key];
+    }
+    echo'<th>' . $keyName . '</th>';
 }
-echo('</tr>');
+echo '</tr>';
 
 
 $i = 0;
-foreach ($this->data['debugdata'] AS $slot => $dd) {
-	echo('<tr class="' . ((++$i % 2) == 0 ? 'odd' : 'even') . '">');
-	echo('<td style="">' . $dd[0] . '</td>');	
-	echo('<td class="datacontent">' . $dd[1] . '</td>');
-
-	foreach($this->data['topdelimiters'] AS $key) {
-		echo('<td class="datacontent">' . 
-			(array_key_exists($key, $this->data['results'][$slot]) ? $this->data['results'][$slot][$key] : '&nbsp;') . 
-			'</td>');
-	}
-	echo('</tr>');
+foreach ($this->data['debugdata'] as $slot => $dd) {
+    echo '<tr class="' . ((++$i % 2) == 0 ? 'odd' : 'even') . '">';
+    echo '<td style="">' . $dd[0] . '</td>';
+    echo '<td class="datacontent">' . $dd[1] . '</td>';
+
+    foreach ($this->data['topdelimiters'] as $key) {
+        echo '<td class="datacontent">' . (array_key_exists($key, $this->data['results'][$slot]) ?
+            $this->data['results'][$slot][$key] : '&nbsp;') . '</td>';
+    }
+    echo '</tr>';
 }
 echo '</table>';
 
 
-echo '</div>'; # End debug tab content
-echo('</div>'); # End tab div
-
-
+echo '</div>'; // End debug tab content
+echo '</div>'; // End tab div
 
 $this->includeAtTemplateBase('includes/footer.php');
-
diff --git a/modules/statistics/templates/statmeta.tpl.php b/modules/statistics/templates/statmeta.tpl.php
index 1ad37d3c559b27a9410f0add0571ac9298060bc9..f85895519e6fb77adaa9070942713d06438c8c82 100644
--- a/modules/statistics/templates/statmeta.tpl.php
+++ b/modules/statistics/templates/statmeta.tpl.php
@@ -2,55 +2,43 @@
 $this->data['header'] = 'SimpleSAMLphp Statistics Metadata';
 $this->includeAtTemplateBase('includes/header.php');
 
-?>
-
-
-<?php
-
-echo('<table style="width: 100%">');
+echo '<table style="width: 100%">' ;
 
 if (isset($this->data['metadata'])) {
-
-	if (isset($this->data['metadata']['lastrun'] )) {
-		echo('<tr><td>Aggregator last run at</td><td>' . 
-			date('l jS \of F Y H:i:s', $this->data['metadata']['lastrun']) . 
-			'</td></tr>');
-	}
-
-	if (isset($this->data['metadata']['notBefore'] )) {
-		echo('<tr><td>Aggregated data until</td><td>' . 
-			date('l jS \of F Y H:i:s', $this->data['metadata']['notBefore']) . 
-			'</td></tr>');
-	}
-	
-	if (isset($this->data['metadata']['memory'] )) {
-		echo('<tr><td>Memory usage</td><td>' . 
-			number_format($this->data['metadata']['memory'] / (1024*1024), 2) . ' MB' . 
-			'</td></tr>');
-	}
-	if (isset($this->data['metadata']['time'] )) {
-		echo('<tr><td>Execution time</td><td>' . 
-			$this->data['metadata']['time'] . ' seconds' .
-			'</td></tr>');
-	}
-	if (isset($this->data['metadata']['lastlinehash'] )) {
-		echo('<tr><td>SHA1 of last processed logline</td><td>' . 
-			$this->data['metadata']['lastlinehash'] .
-			'</td></tr>');
-	}
-	if (isset($this->data['metadata']['lastline'] )) {
-		echo('<tr><td>Last processed logline</td><td>' . 
-			$this->data['metadata']['lastline'] .
-			'</td></tr>');
-	}
-	
-	
+    if (isset($this->data['metadata']['lastrun'] )) {
+        echo '<tr><td>Aggregator last run at</td><td>' . 
+            date('l jS \of F Y H:i:s', $this->data['metadata']['lastrun']) . '</td></tr>';
+    }
+
+    if (isset($this->data['metadata']['notBefore'] )) {
+        echo '<tr><td>Aggregated data until</td><td>' . 
+            date('l jS \of F Y H:i:s', $this->data['metadata']['notBefore']) . '</td></tr>';
+    }
+
+    if (isset($this->data['metadata']['memory'] )) {
+        echo '<tr><td>Memory usage</td><td>' . 
+            number_format($this->data['metadata']['memory'] / (1024*1024), 2) . ' MB' . '</td></tr>';
+    }
+
+    if (isset($this->data['metadata']['time'] )) {
+        echo '<tr><td>Execution time</td><td>' . 
+            $this->data['metadata']['time'] . ' seconds' . '</td></tr>';
+    }
+
+    if (isset($this->data['metadata']['lastlinehash'] )) {
+        echo '<tr><td>SHA1 of last processed logline</td><td>' . 
+            $this->data['metadata']['lastlinehash'] . '</td></tr>';
+    }
+
+    if (isset($this->data['metadata']['lastline'] )) {
+        echo '<tr><td>Last processed logline</td><td>' . 
+            $this->data['metadata']['lastline'] . '</td></tr>';
+    }
 } else {
-	echo('<tr><td>No metadata found</td></tr>');
+    echo '<tr><td>No metadata found</td></tr>';
 }
 
-echo('</table>');
-
-echo('<p>[ <a href="showstats.php">Show statistics</a> ] </p>');
+echo '</table>';
+echo '<p>[ <a href="showstats.php">Show statistics</a> ] </p>';
 
 $this->includeAtTemplateBase('includes/footer.php');
diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php
index d15edc7cd5743f5bb9ab291a89dc293777f2299a..b8063c79dc0f539fa8cdc1d836ad74300df9c4df 100644
--- a/modules/statistics/www/showstats.php
+++ b/modules/statistics/www/showstats.php
@@ -4,25 +4,36 @@ $config = SimpleSAML_Configuration::getInstance();
 $statconfig = SimpleSAML_Configuration::getConfig('module_statistics.php');
 $session = SimpleSAML_Session::getSessionFromRequest();
 
-
 sspmod_statistics_AccessCheck::checkAccess($statconfig);
 
-
 /*
  * Check input parameters
  */
-$preferRule = NULL;
-$preferRule2 = NULL;
-$preferTime = NULL;
-$preferTimeRes = NULL;
-$delimiter = NULL;
-if(array_key_exists('rule', $_REQUEST)) $preferRule = $_REQUEST['rule'];
-if(array_key_exists('rule2', $_REQUEST)) $preferRule2 = $_REQUEST['rule2'];
-if(array_key_exists('time', $_REQUEST)) $preferTime = $_REQUEST['time'];
-if(array_key_exists('res', $_REQUEST)) $preferTimeRes = $_REQUEST['res'];
-if(array_key_exists('d', $_REQUEST)) $delimiter = $_REQUEST['d'];
-
-if ($preferRule2 === '_') $preferRule2 = NULL;
+$preferRule = null;
+$preferRule2 = null;
+$preferTime = null;
+$preferTimeRes = null;
+$delimiter = null;
+
+if (array_key_exists('rule', $_REQUEST)) {
+    $preferRule = $_REQUEST['rule'];
+}
+if (array_key_exists('rule2', $_REQUEST)) {
+    $preferRule2 = $_REQUEST['rule2'];
+}
+if (array_key_exists('time', $_REQUEST)) {
+    $preferTime = $_REQUEST['time'];
+}
+if (array_key_exists('res', $_REQUEST)) {
+    $preferTimeRes = $_REQUEST['res'];
+}
+if (array_key_exists('d', $_REQUEST)) {
+    $delimiter = $_REQUEST['d'];
+}
+
+if ($preferRule2 === '_') {
+    $preferRule2 = null;
+}
 
 /*
  * Create statistics data.
@@ -45,9 +56,6 @@ $timeNavigation = $statrule->getTimeNavigation($timeres, $preferTime);
 $dataset->aggregateSummary();
 $dataset->calculateMax();
 
-
-
-
 $piedata = $dataset->getPieData();
 
 $datasets = array();
@@ -59,49 +67,38 @@ $maxes = array();
 
 $maxes[] = $dataset->getMax();
 
-
 if (isset($preferRule2)) {
-	$statrule = $ruleset->getRule($preferRule2);
-	$dataset2 = $statrule->getDataset($preferTimeRes, $preferTime);
-	$dataset2->aggregateSummary();
-	$dataset2->calculateMax();
-	
-	$datasets[] = $dataset2->getPercentValues();
-	$maxes[] = $dataset2->getMax();
-}
-
-
-
-
-
-
+    $statrule = $ruleset->getRule($preferRule2);
+    $dataset2 = $statrule->getDataset($preferTimeRes, $preferTime);
+    $dataset2->aggregateSummary();
+    $dataset2->calculateMax();
 
+    $datasets[] = $dataset2->getPercentValues();
+    $maxes[] = $dataset2->getMax();
+}
 
 $dimx = $statconfig->getValue('dimension.x', 800);
 $dimy = $statconfig->getValue('dimension.y', 350);
 $grapher = new sspmod_statistics_Graph_GoogleCharts($dimx, $dimy);
 
 if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] === 'csv') {
-
-	header('Content-type: text/csv');
-	header('Content-Disposition: attachment; filename="simplesamlphp-data.csv"');
-	$data = $dataset->getDebugData();
-	foreach($data AS $de) {
-		if (isset($de[1])) {
-			echo('"' . $de[0] . '",' . $de[1] . "\n");
-		}
-	}
-	exit;
+    header('Content-type: text/csv');
+    header('Content-Disposition: attachment; filename="simplesamlphp-data.csv"');
+    $data = $dataset->getDebugData();
+    foreach ($data as $de) {
+        if (isset($de[1])) {
+            echo '"' . $de[0] . '",' . $de[1] . "\n";
+        }
+    }
+    exit;
 }
 
-
-
 $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics.tpl.php');
 $t->data['pageid'] = 'statistics';
 $t->data['header'] = 'stat';
 $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $maxes);
 if (isset($piedata)) {
-	$t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata);
+    $t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata);
 }
 $t->data['available.rules'] = $ruleset->availableRulesNames();
 $t->data['available.times'] = $statrule->availableFileSlots($timeres);
@@ -123,4 +120,3 @@ $t->data['availdelimiters'] = $dataset->availDelimiters();
 
 $t->data['delimiterPresentation'] =  $dataset->getDelimiterPresentation();
 $t->show();
-