-
Notifications
You must be signed in to change notification settings - Fork 7
/
topic.php
executable file
·282 lines (228 loc) · 14.5 KB
/
topic.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
// nur wenn man eingeloggt ist und admin Rechte hat
if(($_SESSION['profile']['loggedin']==1) &&($_SESSION['profile']['admin']==1)){
// Includieren
include ("includes/db_connect.inc");
include ("functions/reallyDel.php");
include ("functions/clearDatabase.php");
// Objekte erzeugen
$topics=new Topic();
$question= new Question();
$answer= new Answer();
// Überprüfung auf String / Wertzuweisung
$action=''; if(isset($_GET['action']))$action=strval($_GET['action']);
$error='';
if(isset($_GET['error'])) $error =strval($_GET['error']);
// Übeprüfung auf buchstaben (keine Zahlen zugelassen)
if(!ctype_alpha($error)) unset($error);
// Überbrüfung auf integer / Wertzuweisung //Initialisierung
$t_id=0; if(isset($_SESSION['values']['t_id']))$t_id=abs(intval($_SESSION['values']['t_id']));
if(isset($_GET['t_id']))$t_id=abs(intval($_GET['t_id']));
if(isset($_REQUEST['topic']))$t_id=abs(intval($_REQUEST['topic']));
$q_id=0; if(isset($_GET['q_id']))$q_id=abs(intval($_GET['q_id']));
// Wenn auf der Statistik-Seite Aktionen aufgerufen werden
if(isset($_SESSION['values']['return_site']) && ($_SESSION['values']['return_site']=='statistic')) {
$site="site=statistic&action=getStatisticQuestions&t_id=$t_id";
} else {
$site="site=topic&action=getQuestions&t_id=$t_id";
}
// Fetch encoding from session, simplifies future switch to utf-8 encoding.
$encoding = $_SESSION['_config']['encoding'];
if (!$encoding) {
$encoding = "iso-8859-1"; // Backwards compatibility
}
// Löschen der Session Variable
if (isset($_SESSION['values']['question']['new'])) unset($_SESSION['values']['question']['new']);
// Auswahl der gewählten Aktionen
switch ($action){
case 'save':{ // speichern eines neuen Topics
// Wertzuweisung
$questPerQuiz=0; if(isset($_REQUEST["questPerQuiz"]))$questPerQuiz =abs(intval($_REQUEST["questPerQuiz"]));
$rawToPass=0; if(isset($_REQUEST["rawToPass"]))$rawToPass =abs(intval($_REQUEST["rawToPass"]));
$name=""; if(isset($_REQUEST["new_topic"]))$name= $_REQUEST["new_topic"];
$topics->setTopicName($name);
$checkNum=$topics->setNumOfQu($questPerQuiz);
$checkPerc=$topics->setrawToPass($rawToPass);
$topics->setSession();
if($checkPerc!=0) echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=new_topic&error=rawToPass' />";
if($checkNum!=0)echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=new_topic&error=numOfQu' />";
else if($checkPerc==0 && $checkNum==0){
$reply=$topics->saveTopic();
if($reply=='none'){
$topics->unsetSession();
echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
} else echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=new_topic&error=$reply' />";
}
break;
}
case 'new_topic':{ // neues Topic
if($error)$topics->setError($error);
$topics->newForm();
break;
}
case 'setTopicInactive':{ //inaktiv setzen
$topics->setTopicID($t_id);
$topics->setInactiveTopic();
echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
break;
}
case 'setTopicAvtive':{ //aktivieren
$topics->setTopicID($t_id);
$topics->setActiveTopic();
echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
break;
}
case'delTopic':{ // Löschen eines Themas
$questionArray=array();
reallyDelTopic($t_id);
if($_REQUEST['submit']==Global_13){
$topics->setTopicID($t_id);
$topics->delTopic();
echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
}
else if($_REQUEST['submit']==Global_14)echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
break;
}
case 'getQuestions':{ // Fragen zum Thema anzeigen
$topics->setTopic($t_id);
echo "<br /><h2> ".Topic_03." ".stripslashes($topics->getTopicName())."<br /></h2>";
$question->setTopic($t_id);
$question->setAllQuestions();
$question->showQuestionTable();
break;
}
case 'delQuestion': { // Löschen einer Frage
reallyDelQuestion($q_id,$t_id);
if($_REQUEST['submit']==Global_13){
$answer->delAnswers($q_id);
$question->delQuestion($q_id);
echo" <meta http-equiv='refresh' content='0; url=?$site' />";
}
else if($_REQUEST['submit']==Global_14) echo" <meta http-equiv='refresh' content='0; url=?$site' />";
break;
}
case 'setQuestionInactive':{ // Deaktivieren einer Frage
$question->setID($q_id);
$question->setInactive();
echo" <meta http-equiv='refresh' content='0; url=?$site' />";
break;
}
case 'setQuestionActive':{ //Aktivieren einer Frage
$question->setID($q_id);
$question->setActive();
echo" <meta http-equiv='refresh' content='0; url=?$site'>";
break;
}
case 'showDetails':{ // Anzeigen der Fragedetails
if($q_id!=0) $_SESSION ['values']['question']['q_id']=$q_id;
if($error=='conflict') echo "<h5>".Topic_01." <br /></h5>";
$question->setID($_SESSION ['values']['question']['q_id']);
$question->loadQuestion();
$type=$question->getType();
$topics->getTopic();
$topicArray=$topics->getTopicArray();
$question->setAllTopics($topicArray);
$question->showQuestionDetails();
$answer->setQuestionID($_SESSION ['values']['question']['q_id']);
$answer->setAnswerType($_SESSION ['values']['question']['qt']);
$answer->getAnswers();
$answer->showAnswers();
break;
}
case 'updateQuestion': { // Question updaten
// Wertzuweisung
$questionText=""; if(isset($_REQUEST["question"]))$questionText= $_REQUEST["question"];
$descriptionText=""; if(isset($_REQUEST["descriptionText"]))$descriptionText= $_REQUEST["descriptionText"];
$description=0; if(isset($_REQUEST["description"]))$description=$_REQUEST["description"];
$question->setID($q_id);
$question->loadQuestion();
$reply=$question->setUpdateQuestion($questionText,$t_id);
// neue Beschreibung
if($descriptionText!="" && $description==1)$question->saveDescription($q_id,$descriptionText);
// Änderung der Beschreibung
else if($descriptionText!="" && $description==0)$question->updateDescription($q_id,$descriptionText);
// Beschreibung löschen
if($descriptionText =="" && $description==0)$question->delDescription($q_id,$descriptionText);
if($reply=='conflict') echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=showDetails&q_id=$q_id&error=conflict' />";
else echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=showDetails&q_id=$q_id' />";
break;
}
case 'updateAnswers': { // Antwort updaten
// Wertzuweisung
$type=0; if(isset($_GET['type'])) $type=abs(intval($_GET['type']));
$a_id=0; if(isset($_GET['a_id'])) $a_id=abs(intval($_GET['a_id']));
$changed_answers=array(); if(isset($_REQUEST["change"]))$changed_answers= $_REQUEST["change"];// array der geänderten Antworten
//$answerList=array();$answerList=$_SESSION['values']['answerList'];
$question->setID($q_id);
$question->loadQuestion();
$topics->getTopic();
$topicArray=$topics->getTopicArray();
$question->setAllTopics($topicArray);
$type=$question->getType();
$question->showQuestionDetails();
$answer->setQuestionID($q_id);
$answer->getAnswers();
$answer->setAnswerList();
$answer->setAnswerType($type);
if(isset($_REQUEST['submit']) && !$a_id && $_REQUEST['submit']==Button_11){
$answer->setChangedAnswers($changed_answers);
$answer->updateChangedAnswers();
}
if($a_id){
$answer->changeCorrect($a_id);
$answer->updateTruthFalse();
}
if (isset($_REQUEST["editAnsw"])){
//$answer->setAnswerList($answerList);
$answer->setType();
}
if(!isset($_REQUEST["editAnsw"]) || empty($_REQUEST["editAnsw"])){
$answer->showAnswers();
}
break;
}
case 'editTopic':{
if(!isset($_SESSION['values']['topic']) || empty($_SESSION['values']['topic'])){
$topics->setTopicID($t_id);
$topics->setTopic($t_id);
} else {
if($error)$topics->setError($error);
$topics->setTopicID($_SESSION['values']['topic']['t_id']);
}
$topics->updateForm();
break;
}
case 'updateTopic':{ // Topic updaten
//Wertzuweisung
$name=""; if(isset($_REQUEST["new_topic"]))$name= $_REQUEST["new_topic"];
$numofQuiz=0; if(isset($_REQUEST["questPerQuiz"]))$numOfQuiz =abs(intval($_REQUEST["questPerQuiz"]));
$rawToPass=0; if(isset($_REQUEST["rawToPass"])) $rawToPass =abs(intval($_REQUEST["rawToPass"]));
$topics->setTopicID($t_id);
$topics->setTopicName($name);
$checkNum=$topics->setNumOfQu($numOfQuiz);
$checkPerc=$topics->setrawToPass($rawToPass);
$topics->setSession();
if($checkPerc!=0) echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=editTopic&error=rawToPass' />";
else if($checkNum!=0)echo" <meta http-equiv='refresh' content='0; url=?site=topic&action=editTopic&error=numOfQu' />";
else if($checkPerc==0 && $checkNum==0){
$topics->updateTopic();
$topics->unsetSession();
echo" <meta http-equiv='refresh' content='0; url=?site=topic' />";
}
break;
}
default: { // Übersicht der Themen
echo"<h2><br />".Topic_02." </h2>";
clearDatabase();
$topics->unsetSession();
$question->unsetSession();
$topics->getTopic();
$topicarray=$topics->getTopicArray();
$number=$question->getNumberOfQuestions($topicarray);
$topics->showTopicTable($number);
unset($_SESSION['values']['return_site']);
}
}
}
else echo '<h5 class="centered">'.Global_01.'</h5>';
?>