-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrate.php
More file actions
94 lines (77 loc) · 3.12 KB
/
rate.php
File metadata and controls
94 lines (77 loc) · 3.12 KB
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
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* wgTimelines module for xoops
*
* @copyright module for xoops
* @license GPL 3.0 or later
* @package wgtimelines
* @since 1.0
* @min_xoops 2.5.7
* @author TDM XOOPS - Email:<info@email.com> - Website:<http://xoops.org>
* @version $Id: 1.0 rate.php 13070 Wed 2016-12-14 22:22:38Z XOOPS Development Team $
*/
use Xmf\Request;
include __DIR__ . '/header.php';
$op = Request::getString('op', 'default');
switch ($op) {
case 'save-index':
case 'save-item':
// Security Check
if ($GLOBALS['xoopsSecurity']->check()) {
\redirect_header('index.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
}
$itemid = Request::getInt('item_id');
$rating = Request::getInt('rating');
$tl_id = Request::getInt('tl_id');
// Checking permissions
$rate_allowed = false;
if ($helper->getConfig('ratingbars')) {
$groups = (isset($GLOBALS['xoopsUser']) && \is_object($GLOBALS['xoopsUser'])) ? $GLOBALS['xoopsUser']->getGroups() : \XOOPS_GROUP_ANONYMOUS;
foreach ($groups as $group) {
if (\XOOPS_GROUP_ADMIN == $group || \in_array($group, $helper->getConfig('ratingbar_groups'))) {
$rate_allowed = true;
break;
}
}
}
if (!$rate_allowed) {
\redirect_header(\WGTIMELINES_URL . '/index.php?tl_id=' . $tl_id . '#item' . $itemid, 2, \_MA_WGTIMELINES_RATING_NOPERM);
}
$redir = $_SERVER['HTTP_REFERER'];
if ($op === 'save-index') {
$redir = $_SERVER['HTTP_REFERER'] . '#item' . $itemid;
}
if ($rating > 5 || $rating < 1) {
\redirect_header($redir, 2, \_MA_WGTIMELINES_RATING_VOTE_BAD);
exit();
}
$itemrating = $ratingsHandler->getItemRating($itemid);
if ($itemrating['voted']) {
\redirect_header($redir, 2, \_MA_WGTIMELINES_RATING_VOTE_ALREADY);
}
$ratingsObj = $ratingsHandler->create();
$ratingsObj->setVar('rate_itemid', $itemid);
$ratingsObj->setVar('rate_value', $rating);
$ratingsObj->setVar('rate_uid', $itemrating['uid']);
$ratingsObj->setVar('rate_ip', $itemrating['ip']);
$ratingsObj->setVar('rate_date', \time());
// Insert Data
if ($ratingsHandler->insert($ratingsObj)) {
\redirect_header($redir, 2, \_MA_WGTIMELINES_RATING_VOTE_THANKS);
}
echo '<br>error:' . $ratingsObj->getHtmlErrors();
break;
case 'default':
default:
echo \_MA_WGTIMELINES_RATING_VOTE_BAD . ' (invalid parameter)';
break;
}