-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoeken.php
88 lines (73 loc) · 2.82 KB
/
zoeken.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
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
session_start();
/* Controleren of er gezocht is */
if(isset($_GET['zoek'])) {
/* Includes importeren */
include_once('Includes/connect.php');
include_once('Includes/slashes.php');
/* Classes importeren */
include_once('Classes/User.php');
include_once('Classes/Template.php');
/* Classes initialiseren */
$cUser = new User();
$cTPL = new Template('Templates/main.tpl');
/* Verbinding maken met db */
connectDB();
include('Includes/login.php');
$cTPL->setPlace('TITEL', 'Zoeken');
$cTPL->setFile('CONTENT', 'Templates/zoeken.tpl');
$cTPL->parse();
$cTPL->setPlace('ZOEKEN', htmlentities($_GET['zoek']));
/* Spellen ophalen */
$sQuery = "SELECT s.spelid, s.naam, c.naam AS console, s.rating, s.stemmen FROM spellen s, consoles c
WHERE s.consoleid=c.consoleid AND s.naam LIKE '%" . add($_GET['zoek']) . "%' ORDER BY s.naam;";
if ($cResult = mysql_query($sQuery)) {
if (mysql_num_rows($cResult) <= 0) {
// Zoekwoord opslaan
$sQuery = "INSERT INTO zoekwoorden (zoekwoord) VALUES ('" . $_GET['zoek'] . "');";
mysql_query($sQuery);
$cTPL->setBlock('RESULTATEN', 'niks');
} else {
$cTPL->setBlock('RESULTATEN', 'resultaten');
$cTPL->parse();
$sBG = '';
while ($aData = mysql_fetch_assoc($cResult)) {
if ($sBG == '') {
$sBG = 'img/patroon.gif';
} else {
$sBG = '';
}
$cTPL->setBlock('SPEL', 'spel');
$cTPL->parse();
$cTPL->setPlace('SPELID', $aData['spelid']);
$cTPL->setPlace('NAAM', preg_replace('#' . $_GET['zoek'] . '#i', '<b>' . $_GET['zoek'] . '</b>', $aData['naam']));
$cTPL->setPlace('CONSOLE', $aData['console']);
$cTPL->setPlace('BG', $sBG);
/* Sterren berekenen */
if ($aData['stemmen'] <= 0) {
$iSterren = 0;
} else {
$iSterren = round(($aData['rating'] / $aData['stemmen']) * 2) / 2;
}
/* Sterren weergeven */
for ($i = 1; $i <= 5; $i++) {
$iSterren -= 1;
if ($iSterren >= 0) {
$cTPL->setBlock('STER' . $i, 'helester');
} elseif ($iSterren == -0.5) {
$cTPL->setBlock('STER' . $i, 'halvester');
} else {
$cTPL->setBlock('STER' . $i, 'legester');
}
}
$cTPL->parse();
}
}
} else {
die(mysql_error());
}
$cTPL->show();
} else {
header('Http/1.0 404 Not Found');
}