-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquery.php
103 lines (87 loc) · 3.02 KB
/
query.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
<?php
if(!isset($_SESSION)) {session_start(); header("Content-Type:text/json; charset=utf-8"); }
require_once("DB.class.php");
if(@$_SESSION['extreme'] === true) {
require_once("./ExtremeGame.class.php");
} elseif(@$_SESSION['sandbox'] === true) {
require_once("./SandboxGame.class.php");
} else {
require_once("./Game.class.php");
}
$show_exercise = false;
if(!isset($_GET['query'])) { die(); }
$query = $_GET['query'];
$query = str_replace('\\"', '"', $query);
$query = str_replace('\\\'', '\'', $query);
if(@$query == "restart") {
$lang = @$_SESSION['lang'];
session_destroy();
session_start();
$_SESSION['lang'] = $lang;
$show_exercise = true;
}
if(isset($_SESSION['dbID'])) {
$db = new DB($_SESSION['dbID']);
} else {
$db = new DB();
$_SESSION['dbID'] = $db->getDbID();
}
if(isset($_SESSION['currentExercise'])) {
$game = new Game($_SESSION['currentExercise']);
} else {
$game = new Game();
}
if($query == "continue") {
$show_exercise = true;
}
if($show_exercise) {
if($game->getExercise() == null) {
$result["exercise"] = Lang::txt("Das Spiel ist zu Ende.");
$result["exercise"] .= " ".Lang::txt("Hole jetzt dein Abschluss-Zertifikat ab. Wenn du den Namen auf dem Zertifikat ändern willst, tu dies mit einem UPDATE-Befehl auf der Bewohner-Tabelle.");
$result["certificate"] = true;
} else {
$game->setPlayerName($db->getPlayerName());
$db->log("-- ".$game->getExercise()->getDescription());
if(!isset($result)) { $result = array(); }
$result = build_result($result, $game->getExercise());
}
echo json_encode($result);
die();
}
$db->log($query);
$result = $db->query($query, FALSE, $game->getExercise());
if($result != null) {
if($game->getExercise() != null && !$game->getExercise()->getSolved()) {
if($result["code"]>0) {
if($game->getExercise()->answer != null) { $result["answer"] = $game->getExercise()->answer; }
$_SESSION['currentExercise'] = $game->nextExercise();
//echo ' <a href="javascript:query(\'continue\');">Weiter</a>';
if($game->getExercise() == null) {
$result["exercise"] = Lang::txt("Das Spiel ist zu Ende.");
} else {
$game->setPlayerName($db->getPlayerName());
$db->log("-- ".$game->getExercise()->getDescription());
$result = build_result($result, $game->getExercise());
}
}
} elseif($game->getExercise() != null) {
$result["solved"] = "solved";
$_SESSION['currentExercise'] = $game->nextExercise();
}
echo json_encode($result);
}
function build_result($res, $e) {
$result = $res;
$result["exercise"] = $e->getDescription();
if($e->description2 != null) { $result["description2"] = $e->description2; }
// if($e->answer != null) { $result["answer"] = $e->answer; }
if($e->speaker != null) { $result["speaker"] = $e->speaker; }
if($e->speaker2 != null) { $result["speaker2"] = $e->speaker2; }
if($e->leftimg != null) { $result["leftimg"] = $e->leftimg; }
if($e->rightimg != null) { $result["rightimg"] = $e->rightimg; }
if($e->getSolved()) {
$result["solved"] = "solved";
$result["query"] = $e->getSolution();
}
return $result;
}