|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Newbb module |
|
5
|
|
|
* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
14
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
15
|
|
|
* @since 4.0 |
|
16
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use Xmf\Request; |
|
20
|
|
|
use XoopsModules\Newbb; |
|
21
|
|
|
use XoopsModules\Xoopspoll; |
|
22
|
|
|
use XoopsModules\Xoopspoll\Constants; |
|
23
|
|
|
|
|
24
|
|
|
require_once __DIR__ . '/header.php'; |
|
25
|
|
|
|
|
26
|
|
|
$poll_id = Request::getInt('poll_id', 0, 'GET'); |
|
27
|
|
|
$poll_id = Request::getInt('poll_id', $poll_id, 'POST'); |
|
28
|
|
|
$topic_id = Request::getInt('topic_id', 0, 'GET'); |
|
29
|
|
|
$topic_id = Request::getInt('topic_id', $topic_id, 'POST'); |
|
30
|
|
|
$forum = Request::getInt('forum', 0, 'GET'); |
|
31
|
|
|
$forum = Request::getInt('forum', $forum, 'POST'); |
|
32
|
|
|
|
|
33
|
|
|
/** @var Newbb\TopicHandler $topicHandler */ |
|
34
|
|
|
$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
35
|
|
|
$topic_obj = $topicHandler->get($topic_id); |
|
36
|
|
|
if (!$topicHandler->getPermission($topic_obj->getVar('forum_id'), $topic_obj->getVar('topic_status'), 'vote')) { |
|
37
|
|
|
// irmtfan - issue with javascript:history.go(-1) |
|
38
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _NOPERM); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (empty($_POST['option_id'])) { |
|
42
|
|
|
// irmtfan - add error message - simple url |
|
43
|
|
|
redirect_header("viewtopic.php?topic_id={$topic_id}", 1, _MD_POLL_NOOPTION); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
47
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
48
|
|
|
$xoopspoll = $moduleHandler->getByDirname('xoopspoll'); |
|
49
|
|
|
|
|
50
|
|
|
if (($xoopspoll instanceof \XoopsModule) && $xoopspoll->isactive()) { |
|
51
|
|
|
/* xoopspoll module installed & active */ |
|
52
|
|
|
xoops_loadLanguage('main', 'xoopspoll'); |
|
53
|
|
|
$xpPollHandler = Xoopspoll\Helper::getInstance()->getHandler('Poll'); |
|
54
|
|
|
$xpLogHandler = Xoopspoll\Helper::getInstance()->getHandler('Log'); |
|
55
|
|
|
} else { |
|
56
|
|
|
//no active poll module found |
|
57
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_POLLMODULE_ERROR); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$mail_author = false; |
|
61
|
|
|
$pollObj = $xpPollHandler->get($poll_id); |
|
62
|
|
|
if ($pollObj instanceof Xoopspoll\Poll) { |
|
63
|
|
|
if ($pollObj->getVar('multiple')) { |
|
64
|
|
|
$optionId = $_POST['option_id']; |
|
65
|
|
|
$optionId = (array)$optionId; // type cast to make sure it's an array |
|
66
|
|
|
$optionId = array_map('\intval', $optionId); // make sure values are integers |
|
67
|
|
|
} else { |
|
68
|
|
|
$optionId = $_POST['option_id']; |
|
69
|
|
|
} |
|
70
|
|
|
if (!$pollObj->hasExpired()) { |
|
71
|
|
|
$msg = _MD_XOOPSPOLL_MUSTLOGIN; |
|
72
|
|
|
//@todo:: add $url to all redirects |
|
73
|
|
|
// $url = $GLOBALS['xoops']->buildUrl("index.php", array('poll_id' => $poll_id)); |
|
74
|
|
|
if ($pollObj->isAllowedToVote()) { |
|
75
|
|
|
$thisVoter = (!empty($GLOBALS['xoopsUser']) |
|
76
|
|
|
&& ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) ? $GLOBALS['xoopsUser']->getVar('uid') : null; |
|
77
|
|
|
$votedThisPoll = $xpLogHandler->hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $thisVoter); |
|
|
|
|
|
|
78
|
|
|
if (!$votedThisPoll) { |
|
79
|
|
|
/* user that hasn't voted before in this poll or module preferences allow it */ |
|
80
|
|
|
$voteTime = time(); |
|
81
|
|
|
if ($pollObj->vote($optionId, xoops_getenv('REMOTE_ADDR'), $voteTime)) { |
|
82
|
|
|
if (!$xpPollHandler->updateCount($pollObj)) { // update the count and save in db |
|
|
|
|
|
|
83
|
|
|
echo $pollObj->getHtmlErrors(); |
|
84
|
|
|
exit(); |
|
85
|
|
|
} |
|
86
|
|
|
$msg = _MD_XOOPSPOLL_THANKSFORVOTE; |
|
87
|
|
|
} else { |
|
88
|
|
|
/* there was a problem registering the vote */ |
|
89
|
|
|
redirect_header($GLOBALS['xoops']->buildUrl('index.php', ['poll_id' => $poll_id]), Constants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSPOLL_VOTE_ERROR); |
|
90
|
|
|
} |
|
91
|
|
|
} else { |
|
92
|
|
|
$msg = _MD_XOOPSPOLL_ALREADYVOTED; |
|
93
|
|
|
} |
|
94
|
|
|
/* set anon user vote (and the time they voted) */ |
|
95
|
|
|
if (!$GLOBALS['xoopsUser'] instanceof \XoopsUser) { |
|
96
|
|
|
Xoopspoll\Utility::setVoteCookie($poll_id, $voteTime, 0); |
|
97
|
|
|
} |
|
98
|
|
|
} else { |
|
99
|
|
|
$msg = _MD_XOOPSPOLL_CANNOTVOTE; |
|
100
|
|
|
} |
|
101
|
|
|
} else { |
|
102
|
|
|
/* poll has expired so just show the results */ |
|
103
|
|
|
$msg = _MD_XOOPSPOLL_SORRYEXPIRED; |
|
104
|
|
|
} |
|
105
|
|
|
} else { |
|
106
|
|
|
$msg = _MD_XOOPSPOLL_ERROR_INVALID_POLLID; |
|
107
|
|
|
} |
|
108
|
|
|
if (null !== $url) { |
|
109
|
|
|
redirect_header($url, Constants::REDIRECT_DELAY_MEDIUM, $msg); |
|
110
|
|
|
} else { |
|
111
|
|
|
redirect_header($GLOBALS['xoops']->buildUrl('viewtopic.php', ['topic_id' => $topic_id]), Constants::REDIRECT_DELAY_MEDIUM, $msg); |
|
112
|
|
|
} |
|
113
|
|
|
// irmtfan - simple url |
|
114
|
|
|
redirect_header("viewtopic.php?topic_id={$topic_id}", 1, $msg); |
|
115
|
|
|
|