-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuche.php
308 lines (281 loc) · 10.9 KB
/
suche.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
include("dbconnect.php");
?>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="css/bootstrap.min.css" TYPE="text/css"/>
<link rel="stylesheet" href="css/profit.css.php" TYPE="text/css"/>
<link rel="shortcut icon" href="sym.ico">
<title>ProFit Wiki</title>
</head>
<body id="bootstrap-overrides">
<?php
session_start();
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
//Zeit ueberpruefen
session_unset();
session_destroy();
}
$_SESSION['LAST_ACTIVITY'] = time();
?>
<?php
include("header.php");
mysqli_query($db, "SET NAMES 'utf8'");
$programmArray = getProgrammArray($db);
$bereichArray = getBereichArray($db);
$themaArray = getThemaArray($db);
?>
<div class="container">
<center><u><h2>Ergebnisse:</h2></u></center>
<?php
$suchtags = isset($_POST['suchtags']) ? $_POST['suchtags'] : '';
if(!isset($_POST['orderranking'])){
$ranking = "";
echo "<script>console.log(\"Ranking nicht aktiv!\")</script>";
}else{
$ranking = " ORDER BY Ranking DESC";
echo "<script>console.log(\"Ranking aktiv!\")</script>";
}
$pr = isset($_POST['programme']) ? $_POST['programme'] : 'Alle';
$prbe = isset($_POST['bereiche']) ? $_POST['bereiche'] : 'Alle';
$thema = isset($_POST['thema']) ? $_POST['thema'] : '-1';
if($prbe === "Bitte Programm auswählen"){
$prbe = "Alle";
echo "<script>console.log('Vorbereitung:Bereich auf Alle gesetzt.')</script>";
}
//Problematische Sonderzeichen entfernen
mysqli_real_escape_string($db, $ranking);
mysqli_real_escape_string($db, $pr);
mysqli_real_escape_string($db, $prbe);
mysqli_real_escape_string($db, $thema);
//Leerzeichen am Anfang und Ende entfernen
$suchtags = trim($suchtags);
//String in W�rter zerlegen
$suchtags = explode(" ",$suchtags);
if($suchtags!=null){
if(count($suchtags)>1){
for($i=0; $i<count($suchtags); $i++){
$suchtags[$i] = "+" . $suchtags[$i];
}
}
$suchtags = implode(" ", $suchtags);
// utf8_encode($suchtags);
}
//�berpr�fen, ob es keinen Suchbegriff gibt. Suchstring entsprechend f�r die Query anlegen.
if($suchtags == "+" || $suchtags == "+*" || $suchtags == null){
$suchstring = "";
}else{
//Boolean Mode
$suchstring = "AND MATCH(Frage, Antwort) AGAINST('".$suchtags."' IN BOOLEAN MODE)";
//TODO:LIKE
}
//�berpr�fen, ob es kein Thema gibt.
if($thema === "-1"){
$themastring = "";
}else{
$themastring = " AND ThemaID = '$thema'";
}
//Query erstellen
if($pr === "0"){
$such_query = "SELECT ID, Frage, Antwort, ProgrammID, BereichID, Ranking, ThemaID FROM faq WHERE Geloescht = '0'".$themastring."".$suchstring."".$ranking."";
echo "<script>console.log('Query-Erstellung:1')</script>";
}else{
if($prbe === "0"){
$such_query = "SELECT ID, Frage, Antwort, ProgrammID, BereichID, Ranking, ThemaID FROM faq WHERE Geloescht = '0' AND ProgrammID = '".$pr."'".$themastring."".$suchstring."".$ranking."";
echo "<script>console.log('Query-Erstellung:2')</script>";
}else{
$such_query = "SELECT ID, Frage, Antwort, ProgrammID, BereichID, Ranking, ThemaID FROM faq WHERE Geloescht = '0' AND ProgrammID = '".$pr."' AND BereichID = '".$prbe."'".$themastring."".$suchstring."".$ranking."";
echo "<script>console.log('Query-Erstellung:3')</script>";
}
}
//Einzelne Erzeugung der Fragen/Antworten
$such_result=mysqli_query($db, $such_query);
if($such_result!=null){
while($row = $such_result->fetch_row()){
?>
<div class="row" class="question">
<div class="borderclass" id="row-<?php echo $row[0];?>">
<?php
printf ("<div class=\"col-lg-8\">
<b>Frage:</b> <textarea class=\"form-control\" rows='10' name='frage' id=\"frage-%s\">%s</textarea>
</div>
<div class=\"col-lg-4\">
<b>ID:</b> %s <br>
<b>Programmname:</b> %s<br>
<b>Bereich:</b> %s<br>
<b>Thema:</b> <select name=\"thema\" class=\"form-control\" id=\"thema-%s\"> %s</select><br>
<b>Ranking:</b> <span id=\"ranknr-%s\">%s</span>
</div>",
$row[0], $row[1], $row[0], $programmArray[$row[3]], $bereichArray[$row[4]], $row[0], getThemaBox($row[6], $themaArray), $row[0], $row[5]
);
?>
<div class="col-lg-12" style="padding:1em;">
<?php printf ("<b>Antwort:</b> <textarea class=\"form-control\" rows='15' name='antwort' id=\"antwort-%s\">%s</textarea>", $row[0], $row[2]); ?>
</div>
<div class="col-lg-4">
<button class="btn btn-profit" type="button" onclick="update(<?php echo $row[0];?>)">Bearbeiten</button>
<button class="btn btn-profit" type="button" onclick="deleteID(<?php echo $row[0];?>)">Löschvorschlag</button>
<button class="btn btn-profit" type="button" onclick="getHistorie(<?php echo $row[0];?>)">Historie</button>
<?php printf("<button type=\"button\" class=\"btn btn-profit-thumb\" onclick=\"rate(".$row[0].", this)\"><span class=\"glyphicon glyphicon-thumbs-up\" id=\"glyph-".$row[0]."\"></span></button>");?>
</div>
<div class="col-lg-8">
<div id="status-<?php echo $row[0];?>"></div>
</div>
<div class="col-lg-12">
<div class="panel panel-default" id="<?php echo "Historie-".$row[0]; ?>" style="display: none;">
<!-- Wird von getHistorie(id) gefuellt -->
</div>
</div>
</div>
</div>
<?php
}
$such_result->close();
}else{
echo "<br>Keine Ergebnisse gefunden!";
}
echo "<br/><a href=\"faq_intern.php\">Zurück zur Startseite</a>";
?>
</div>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<?php
include("footer.php");
?>
<script>
function rate(id, btn) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
};
var abc = "#glyph-"+id;
console.log($(abc).css("color"));
if($(abc).css("color")!="rgb(50, 205, 50)"){
$(abc).css("color","limegreen");
xmlhttp.open("GET", "rate.php?id="+id+"&up=y", true);
var rank="#ranknr-"+id;
var idn=$(rank).text();
idn = parseInt(idn);
idn++;
$(rank).text(idn);
}else{
$(abc).css("color","white");
xmlhttp.open("GET", "rate.php?id="+id+"&up=n", true);
var rank="#ranknr-"+id;
var idn=$(rank).text();
console.log("ID:"+idn+"down");
idn = parseInt(idn);
idn--;
$(rank).text(idn);
}
console.log("Rated!");
xmlhttp.send();
}
function getHistorie(id){
var xmlhttp = new XMLHttpRequest();
var hist = "Historie-"+id;
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(hist).innerHTML = this.responseText;
$("#"+hist).slideToggle("slow");
}
};
xmlhttp.open("GET", "getHistorie.php?id=" + id, true);
xmlhttp.send();
}
function toggleQuestion(id){
var question = "Frage-"+id;
$("#"+question).slideToggle("slow");
}
function update(id){
var xmlhttp = new XMLHttpRequest();
var stat = "status-"+id;
console.log("Update von: " +id);
var fr = "frage-"+id;
var an = "antwort-"+id;
var th = "thema-"+id;
var frage = document.getElementById(fr).value.replace(/\n/g,'<br/>');
var antwort = document.getElementById(an).value.replace(/\n/g,'<br/>');
var thema = document.getElementById(th).value;
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(stat).innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "update.php?update=" + id + "&frage=" + frage + "&antwort=" + antwort + "&thema=" + thema, true);
xmlhttp.send();
}
function deleteID(id){
var xmlhttp = new XMLHttpRequest();
var stat = "status-"+id;
console.log("Loeschen von: " +id);
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById(stat).innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "update.php?delete=" + id, true);
xmlhttp.send();
}
</script>
<?php
function getProgrammArray($db){
if(!$db)
{
exit("Verbindungsfehler: ".mysqli_connect_error());
}
$result=mysqli_query($db, "SELECT ID, Name FROM programme");
$programmArray[0]="Keines";
while($row = $result->fetch_row()){
$programmArray[$row[0]]=$row[1];
}
echo "<script>console.log('getProgrammArray() end')</script>";
$result->close();
return $programmArray;
}
function getBereichArray($db){
if(!$db)
{
exit("Verbindungsfehler: ".mysqli_connect_error());
}
$result=mysqli_query($db, "SELECT ID, Name FROM bereiche");
$bereichArray[0]="Keiner";
while($row = $result->fetch_row()){
$bereichArray[$row[0]]=$row[1];
}
echo "<script>console.log('getBereichArray() end')</script>";
$result->close();
return $bereichArray;
}
function getThemaArray($db){
if(!$db)
{
exit("Verbindungsfehler: ".mysqli_connect_error());
}
$result=mysqli_query($db, "SELECT ID, Name FROM thema");
$themaArray[0]="Kein Thema";
while($row = $result->fetch_row()){
$themaArray[$row[0]]=$row[1];
}
echo "<script>console.log('getThemaArray() end')</script>";
$result->close();
return $themaArray;
}
function getThemaBox($selected, $themaArray){
$ret_string = "";
if($selected == 0){
$ret_string = "<option value=\"0\">Kein Thema</option>";
}else{
$ret_string = "<option value=\"$selected\">".$themaArray[$selected]."</option>";
}
foreach($themaArray as $index => $item){
if($item === $themaArray[$selected]){
}else{
$ret_string .= "<option value=\"".$index."\">".$item."</option>";
}
}
return $ret_string;
}
?>
</body>
</html>