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
|
<?php
/** * rating plugin updater - Updates the rating in the database * @author Stephen Billard (sbillard) * @package plugins */ if (isset($_POST['id']) && isset($_POST['table'])) { define('OFFSET_PATH', 4); require_once(dirname(dirname(dirname(__FILE__))) . '/template-functions.php');
$id = sanitize_numeric($_POST['id']); $table = sanitize($_POST['table'], 3); $dbtable = prefix($table); $ip = jquery_rating::id(); $unique = '_' . $table . '_' . $id; if (isset($_POST['star_rating-value' . $unique])) { $rating = ceil(sanitize_numeric($_POST['star_rating-value' . $unique]) / max(1, getOption('rating_split_stars')));
// Make sure the incoming rating isn't higher than what is allowed if ($rating > getOption('rating_stars_count')) { $rating = getOption('rating_stars_count'); }
$IPlist = query_single_row("SELECT * FROM $dbtable WHERE id= $id"); if (is_array($IPlist)) { $oldrating = jquery_rating::getRatingByIP($ip, $IPlist['used_ips'], $IPlist['rating']); } else { $oldrating = false; } if (!$oldrating || getOption('rating_recast')) { if ($rating) { $_rating_current_IPlist[$ip] = (float) $rating; } else { if (isset($_rating_current_IPlist[$ip])) { unset($_rating_current_IPlist[$ip]); // retract vote } } $insertip = serialize($_rating_current_IPlist); if ($oldrating) { if ($rating) { $voting = ''; } else { $voting = ' total_votes=total_votes-1,'; // retract vote } $valuechange = $rating - $oldrating; if ($valuechange >= 0) { $valuechange = '+' . $valuechange; } $valuechange = ' total_value=total_value' . $valuechange . ','; } else { $voting = ' total_votes=total_votes+1,'; $valuechange = ' total_value=total_value+' . $rating . ','; } $sql = "UPDATE " . $dbtable . ' SET' . $voting . $valuechange . " rating=total_value/total_votes, used_ips=" . db_quote($insertip) . " WHERE id='" . $id . "'"; $rslt = query($sql, false); } } } ?>
|