-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.php
54 lines (48 loc) · 1.41 KB
/
math.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
<?php
$generatorPath = 'generators';
$directoryHandle = @opendir($generatorPath) or die("Unable to find question generators at path: $generatorPath.");
while( $file = readdir($directoryHandle) ) {
if( preg_match( '/\.php$/', $file ) ) {
require_once("$generatorPath/$file");
}
}
closedir($directoryHandle);
$numberOfQuestions = isset($_GET['questions']) ? $_GET['questions'] : 90;
?>
<html>
<head>
<title>Math Questions</title>
<style type="text/css" media="all">
@import url("math.css");
</style>
</head>
<body>
<?php
$generators = array();
foreach( $_GET as $parameterName => $value ) {
if( $value == 'on' ) {
$generators[$parameterName] = array();
}
}
foreach( $_GET as $parameterName => $value ) {
if( preg_match('/_param_/', $parameterName) ) {
$vals = explode("_param_", $parameterName);
if( isset($generators[$vals[0]]) ) {
$generators[$vals[0]][$vals[1]] = $value;
}
}
}
$generator = new CompoundGenerator();
foreach( $generators as $generatorName => $params ) {
$generator->add(new $generatorName($params));
}
for( $i = 0; $i < $numberOfQuestions; $i++ ) {
$html = array();
$html[] = "<div class='outer'>";
$html[] = $generator->newQuestion();
$html[] = "</div>";
echo implode("\n", $html);
}
?>
</body>
</html>