-
Notifications
You must be signed in to change notification settings - Fork 0
/
rating.php
130 lines (123 loc) · 4.6 KB
/
rating.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
<?php
/*
##########################################################################
# #
# Version 4 / / / #
# -----------__---/__---__------__----__---/---/- #
# | /| / /___) / ) (_ ` / ) /___) / / #
# _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___ #
# Free Content / Management System #
# / #
# #
# #
# Copyright 2005-2015 by webspell.org #
# #
# visit webSPELL.org, webspell.info to get webSPELL for free #
# - Script runs under the GNU GENERAL PUBLIC LICENSE #
# - It's NOT allowed to remove this copyright-tag #
# -- http://www.fsf.org/licensing/licenses/gpl.html #
# #
# Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at), #
# Far Development by Development Team - webspell.org #
# #
# visit webspell.org #
# #
##########################################################################
*/
include("_mysql.php");
include("_settings.php");
include("_functions.php");
$_language->readModule('rating');
if (!$userID) {
die($_language->module[ 'no_access' ]);
}
$rating = $_POST[ 'rating' ];
settype($rating, "integer");
if ($rating > 10 || $rating < 0) {
die($_language->module[ 'just_rate_between_0_10' ]);
}
$type = $_POST[ 'type' ];
$id = $_POST[ 'id' ];
if ($type == "ar") {
$table = "articles";
$key = "articlesID";
} else if ($type == "de") {
$table = "demos";
$key = "demoID";
} else if ($type == "fi") {
$table = "files";
$key = "fileID";
} else if ($type == "ga") {
$table = "gallery_pictures";
$key = "picID";
}
if (isset($table) && isset($key)) {
$getarticles = safe_query(
"SELECT
" . $table . "
FROM
" . PREFIX . "user
WHERE
userID='" . (int)$userID."'"
);
if (mysqli_num_rows($getarticles)) {
$ga = mysqli_fetch_array($getarticles);
$go = false;
if ($ga[ $table ] == "") {
$array = array();
$go = true;
} else {
$string = $ga[ $table ];
$array = explode(":", $string);
if (!in_array($id, $array)) {
$go = true;
}
}
// Only vote, if isn't voted
if ($go === true) {
safe_query(
"UPDATE
" . PREFIX . $table . "
SET
votes=votes+1,
points=points+" . $rating . "
WHERE
" . $key . " = '" . (int)$id."'"
);
$ergebnis = safe_query(
"SELECT votes, points FROM " . PREFIX . $table . " WHERE " . $key . " = '" . (int)$id."'"
);
$ds = mysqli_fetch_array($ergebnis);
$rate = round($ds[ 'points' ] / $ds[ 'votes' ]);
safe_query(
"UPDATE " . PREFIX . $table . " SET rating='" . $rate . "' WHERE " . $key . "='" . (int)$id."'"
);
$array[ ] = $id;
$string_new = implode(":", $array);
safe_query(
"UPDATE " . PREFIX . "user SET " . $table . "='" . $string_new . "' WHERE userID='" . (int)$userID."'"
);
}
}
$default_table = "index.php?site=";
switch ($table) {
case "gallery_pictures":
$table = $default_table . "gallery&picID=" . $id;
break;
case "articles":
$table = $default_table . "articles&action=show&articlesID=" . $id;
break;
case "demos":
$table = $default_table . "demos&action=showdemo&demoID=" . $id;
break;
case "files":
$table = $default_table . "files&file=" . $id;
break;
default:
$table = "index.php";
break;
}
header("Location: " . $table);
} else {
header("Location: index.php");
}