forked from tbagriyanik/eOgr
/
rating.php
213 lines (179 loc) · 6.31 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
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
<?php
/*
eOgr - elearning project
Developer Site: http://yunus.sourceforge.net
Demo Site: http://yunus.sourceforge.net/eogr
Source Track: http://eogr.googlecode.com
Support: http://www.ohloh.net/p/eogr
This project is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or any later version. See the GNU
Lesser General Public License for more details.
*/
@session_start();
@header("Content-Type: text/html; charset=iso-8859-9");
$taraDili=(isset($_COOKIE["lng"]))?$_COOKIE["lng"]:"";
if(!($taraDili=="TR" || $taraDili=="EN")) $taraDili="EN";
if ($taraDili=="TR")
require("lib/tr.php");
elseif ($taraDili=="EN")
require("lib/en.php");
else
require("lib/en.php");
require 'database.php';
/*
baglan2:
veritabaný baðlantýsý
*/
function baglan2()
{
global $_host;
global $_username;
global $_password;
return @mysql_connect($_host, $_username, $_password);
}
if(!baglan2())
die("<font id='hata'> Lüften, 'veritabanı' <a href=install.php>kurulumunu (installation)</a> yapınız!</font>");
$yol1 = baglan2();
if (!@mysql_select_db($_db, $yol1))
{
die("<font id='hata'>
Veritabanı <a href=install.php>ayarlarınızı</a> yapmadınız!<br/>
You need to go to <a href=install.php>installing page</a>!<br/>
</font>");
}
/*
temizle2:
xss temizliði
*/
function temizle2($metin)
{
$metin = str_replace("&", "", $metin);
$metin = str_replace("#", "", $metin);
$metin = str_replace("%", "", $metin);
$metin = str_replace("\n", "", $metin);
$metin = str_replace("\r", "", $metin);
$metin = str_replace("'", "`", $metin);
//$metin = str_replace('"', '¨', $metin);
$metin = str_replace("\\", "|", $metin);
$metin = str_replace("<", "‹", $metin);
$metin = str_replace(">", "›", $metin);
$metin = trim(htmlentities($metin));
return $metin;
}
/*
getUserIDrate:
kullanýcý kimlik bilgisi
*/
function getUserIDrate($usernam, $passwor)
{
global $yol1;
$usernam = substr(temizle2($usernam),0,15);
$sql1 = "SELECT id, userName, userPassword FROM eo_users where userName='".temizle2($usernam)."' AND userPassword='".temizle2($passwor)."' limit 0,1";
$result1 = mysql_query($sql1, $yol1);
if ($result1 && mysql_numrows($result1) == 1)
{
return (mysql_result($result1, 0, "id"));
}else {
return ("");
}
}
/*
oyGonder:
konuya oy verme
*/
function oyGonder($userID, $konuID, $rate){
global $yol1;
$sql1 = "SELECT id, userID, konuID FROM eo_rating where userID='".temizle2($userID)."' AND konuID='".temizle2($konuID)."' limit 0,1";
$result1 = mysql_query($sql1, $yol1);
if ($result1 && mysql_numrows($result1) == 1)
{
$kayno = mysql_result($result1, 0, "id");
$datem = date("Y-n-j H:i:s");
$sql2 = "update eo_rating SET value='$rate', rateDate='$datem' where id = '" .$kayno. "' LIMIT 1";
$result2 = mysql_query($sql2, $yol1);
}else {
$datem = date("Y-n-j H:i:s");
$sql2 = "insert into eo_rating VALUES (NULL , '$userID', '$konuID' , '$rate', '$datem')";
$result2 = mysql_query($sql2, $yol1);
return ("");
}
return "";
}
/*
oyGetir:
konunun kullanýcý oy bilgisi
*/
function oyGetir($userID, $konuID){
global $yol1;
$sql1 = "SELECT value FROM eo_rating where userID='".temizle2($userID)."' AND konuID='".temizle2($konuID)."' limit 0,1";
$result1 = mysql_query($sql1, $yol1);
if ($result1 && mysql_numrows($result1) == 1)
{
return mysql_result($result1, 0, "value");
}
return 0;
}
/*
oyToplam:
konunun oy toplamý
*/
function oyToplam($konuID){
global $yol1;
$sql1 = "SELECT count(*) as Toplam FROM eo_rating where konuID='".temizle2($konuID)."'";
$result1 = mysql_query($sql1, $yol1);
if ($result1 && mysql_numrows($result1) == 1)
{
return mysql_result($result1, 0, "Toplam");
}
return 0;
}
/*
oyOrtalama:
konunun oy ortalamasý
*/
function oyOrtalama($konuID){
global $yol1;
$sql1 = "SELECT avg(value) as Ort FROM eo_rating where konuID='".temizle2($konuID)."'";
$result1 = mysql_query($sql1, $yol1);
if ($result1 && mysql_numrows($result1) == 1)
{
return mysql_result($result1, 0, "Ort");
}
return 0;
}
if(isset($_SESSION["usern"]) && getUserIDrate($_SESSION["usern"],$_SESSION["userp"])=="") die ("");
$id = $_SESSION["aktifDers"];
if (!empty($id)) {
//eðer ders sayfasýndan gelen bir DEÐER var ise
//yoksa adresten gelindi ise olmaz
if (isset($_GET['konu2']) && $_GET['konu2'] == $id && !empty($_GET['konu2'])) {
if (isset($_SESSION["usern"]) && isset($_GET['rating']) && is_numeric($_GET['rating']) && $_GET['rating']>0 && $_GET['rating']<6 ) {
oyGonder(getUserIDrate($_SESSION["usern"],$_SESSION["userp"]), temizle2($id ),temizle2($_GET['rating']));
echo $metin[275];
} else
die("Oy hatalý");
}
if (isset($_SESSION["usern"]) && oyGetir(getUserIDrate($_SESSION["usern"],$_SESSION["userp"]), temizle2($id ))>0) {
echo "
<p>".$metin[249]." :</p>
<ul class=\"rate".oyGetir(getUserIDrate($_SESSION["usern"],$_SESSION["userp"]), temizle2($id ))."\">";
} else {
echo "
<p>".$metin[248]." :</p>
<ul>";
}
echo '
<li style="list-style-type:none;"><label class="rate1" title="'.$metin[250].'" href="?konu2='.$id.'&rating=1">1</label></li>
<li style="list-style-type:none;"><label class="rate2" title="'.$metin[251].'" href="?konu2='.$id.'&rating=2">2</label></li>
<li style="list-style-type:none;"><label class="rate3" title="'.$metin[252].'" href="?konu2='.$id.'&rating=3">3</label></li>
<li style="list-style-type:none;"><label class="rate4" title="'.$metin[253].'" href="?konu2='.$id.'&rating=4">4</label></li>
<li style="list-style-type:none;"><label class="rate5" title="'.$metin[254].'" href="?konu2='.$id.'&rating=5">5</label></li>
</ul>';
if(oyToplam($id)>0)
echo "$metin[273] : ".oyToplam($id).", $metin[274] : ".round(oyOrtalama($id),1);
else
echo "$metin[278]";
}
?>