-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.php
47 lines (37 loc) · 1.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo "POST request expected";
return;
}
error_reporting(E_ALL && E_WARNING && E_NOTICE);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
require_once 'includes/common.inc.php';
$requestParameters = RequestParametersParser::getRequestParameters($_POST, !empty($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : null);
_log($requestParameters);
try
{
$quizResults = new QuizResults();
$quizResults->InitFromRequest($requestParameters);
$generator = QuizReportFactory::CreateGenerator($quizResults, $requestParameters);
$report = $generator->createReport();
$dateTime = date('Y-m-d_H-i-s');
$resultFilename = dirname(__FILE__) . "/result/quiz_result_{$dateTime}.txt";
@file_put_contents($resultFilename, $report);
echo "OK";
}
catch (Exception $e)
{
error_log($e);
echo "Error: " . $e->getMessage();
}
function _log($requestParameters)
{
$logFilename = dirname(__FILE__) . '/log/quiz_results.log';
$event = array('ts' => date('Y-m-d H:i:s'), 'request_parameters' => $requestParameters, 'ts_' => time());
$logMessage = json_encode($event);
$logMessage .= ',' . PHP_EOL;
@file_put_contents($logFilename, $logMessage, FILE_APPEND);
}