forked from zheyakush/ZY-php-testing-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
112 lines (99 loc) · 2.23 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
ini_set('display_errors', 1);
require_once "./Test.php";
session_start();
/** @var Test $test */
$test = new Test();
switch ($test->getCurrentStep()) {
case 2:
if (isAjax()) {
$html = includeOutput("view/step2/question-content.php");
echo json_encode([
"step" => $test->getCurrentStep(),
"html" => $html
]);
return;
} else {
$file = "view/step2.php";
}
break;
case 3:
if (isAjax()) {
$html = includeOutput("view/step3.php");
echo json_encode([
"step" => $test->getCurrentStep(),
"html" => $html
]);
return;
} else {
$file = "view/step3.php";
}
break;
case 1:
default:
if (isAjax() && $test->isReviewMode()) {
$html = includeOutput("view/step3.php");
echo json_encode([
"redirect" => true
]);
return;
} else {
$file = "view/step1.php";
}
}
/**
* @param $filename
* @return string
*/
function includeOutput($filename)
{
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
/**
* @return bool
*/
function isAjax()
{
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'
) {
header('Content-Type: application/json');
return true;
}
return false;
}
/**
* @param $file
*/
function ajaxResponse($file)
{
global $test;
$html = includeOutput($file);
echo json_encode([
"step" => $test->getCurrentStep(),
"html" => $html
]);
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>
<?php echo $test->getPageTitle(); ?>
</title>
<link rel="stylesheet" href="css/styles.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/main.js"></script>
<script src="js/timer.js"></script>
</head>
<body>
<?php echo includeOutput($file) ?>
</div>
</body>
</html>