public static function newReport($id, $sessionId, $referenceId)
 {
     if (false === Session::isValidSession($sessionId)) {
         throw new Exception('Session ID not valid');
     }
     if (false === Reference::isValidResults($referenceId)) {
         throw new Exception('Reference ID not valid');
     }
     if (!is_numeric($id)) {
         throw new Exception('Not a valid report ID');
     }
     if (ValidationReport::isValidValidationReport($id)) {
         throw new Exception('Report already exists');
     }
     $session = new Session($sessionId);
     $sessionResults = $session->getResults();
     $reference = new Reference($referenceId);
     $referenceResults = $reference->getResults();
     // Index the sessionResults so we can look them up
     $sessionResults['tests'] = array();
     foreach ($sessionResults['results'] as $test) {
         $result = new ResultSupport($test);
         $testName = $result->getTestName();
         if (!array_key_exists($testName, $sessionResults['tests'])) {
             $sessionResults['tests'][$testName] = array();
         }
         $testId = $test['id'];
         $sessionResults['tests'][$testName][$testId] = array();
         foreach ($test['subtests'] as $subtest) {
             $subtestName = ResultSupport::getSubtestName($subtest);
             // Update the results
             $sessionResults['tests'][$testName][$testId][$subtestName] = $subtest['status'];
         }
     }
     // Test statistics
     $testsNotRun = 0;
     $subtestsNotRun = 0;
     $testsFailed = 0;
     $subtestsFailed = 0;
     $log = array();
     // Work through each test
     foreach ($referenceResults['results'] as $test) {
         $result = new ResultSupport($test);
         $testName = $result->getTestName();
         if (!array_key_exists($testName, $sessionResults['tests'])) {
             array_push($log, array('type' => 'error', 'message' => 'FAILURE - TEST NOT RUN', 'test' => $testName, 'reference_test_id' => $test['id']));
             $testsNotRun++;
             continue;
         }
         if ('testharness' == $result->getTestType()) {
             // Counter to see if any of the subtests fail
             $failCheck = $subtestsFailed;
             foreach ($test['subtests'] as $subtest) {
                 $subtestName = ResultSupport::getSubtestName($subtest);
                 // Check the passed tests
                 if ($subtest['status'] === "PASS") {
                     $testRun = false;
                     foreach ($sessionResults['tests'][$testName] as $testId => $subtestList) {
                         if (array_key_exists($subtestName, $subtestList)) {
                             $testRun = $testId;
                             break;
                         }
                     }
                     if (false === $testRun) {
                         array_push($log, array('type' => 'error', 'message' => 'FAILURE - SUBTEST NOT RUN', 'test' => $testName, 'subtest' => $subtestName, 'reference_test_id' => $test['id'], 'test_ids' => array_keys($sessionResults['tests'][$testName])));
                         $subtestsNotRun++;
                         continue;
                     }
                     if ($sessionResults['tests'][$testName][$testRun][$subtestName] === "PASS") {
                         //fprintf(STDOUT, "  PASS: %s /  %s\n", $testName, $subtestName);
                     } else {
                         array_push($log, array('type' => 'error', 'message' => 'FAILURE - SUBTEST FAILED', 'test' => $testName, 'subtest' => $subtestName, 'reference_test_id' => $test['id'], 'test_id' => $testRun));
                         $subtestsFailed++;
                     }
                 }
             }
             // Check if any of the subtests failed
             if ($failCheck != $subtestsFailed) {
                 $testsFailed++;
             }
         } else {
         }
     }
     $status = array('session' => $sessionId, 'reference' => $referenceId, 'tests_not_run' => $testsNotRun, 'subtests_not_run' => $subtestsNotRun, 'tests_failed' => $testsFailed, 'subtests_failed' => $subtestsFailed, 'log_total' => count($log));
     $dir = VALIDATION_REPORT_DIR . '/' . $id;
     mkdir($dir);
     file_put_contents($dir . '/status', json_encode($status));
     file_put_contents($dir . '/report', json_encode($log));
     return new ValidationReport($id);
 }
        $app->render(200, $report->GetReport($app->request()->params('filters'), $app->request()->params('pageIndex'), $app->request()->params('pageSize')));
    })->name('reports');
    $app->post('/:id', function ($id) use($app) {
        $report = new ValidationReport($id);
        $result = json_decode($app->request->getBody(), true);
        if (false != $result) {
            if (array_key_exists('name', $result)) {
                $index = $report->setName($result['name']);
                $app->render(200, array());
            }
        } else {
            $app->render(400, array('error' => true, 'msg' => 'Not JSON'));
        }
    });
    $app->delete('/:id', function ($id) use($app) {
        $report = new ValidationReport($id);
        $report->delete();
        Notify(ADMIN_TOPIC, array('action' => 'delete', 'report' => $id));
        $app->render(200, array());
    });
    $app->options('/:param+', function ($param) use($app) {
        $app->render(200, array());
    });
});
$app->group('/drm', function () use($app) {
    $app->get('/', function () use($app) {
        $drm = new DRM();
        $app->render(200, $drm->info());
    })->name('drm');
    $app->post('/', function () use($app) {
        $res = false;