Code Duplication    Length = 46-46 lines in 3 locations

extras/newbb_4x/irmtfan/votepolls.php 1 location

@@ 75-120 (lines=46) @@
72
$mail_author = false;
73
if ('xoopspoll' === $pollmodules) {
74
    $pollObj = $xpPollHandler->get($poll_id);
75
    if ($pollObj instanceof XoopspollPoll) {
76
        if ($pollObj->getVar('multiple')) {
77
            $optionId = XoopsRequest::getInt('option_id', 0, 'POST');
78
            $optionId = (array)$optionId; // type cast to make sure it's an array
79
            $optionId = array_map('intval', $optionId); // make sure values are integers
80
        } else {
81
            $optionId = $_POST['option_id'];
82
        }
83
        if (!$pollObj->hasExpired()) {
84
            $msg = _MD_XOOPSPOLL_MUSTLOGIN;
85
            //@todo:: add $url to all redirects
86
            //            $url = $GLOBALS['xoops']->buildUrl("index.php", array('poll_id' => $poll_id));
87
            if ($pollObj->isAllowedToVote()) {
88
                $thisVoter     = (!empty($GLOBALS['xoopsUser'])
89
                                  && ($GLOBALS['xoopsUser'] instanceof XoopsUser)) ? $GLOBALS['xoopsUser']->getVar('uid') : null;
90
                $votedThisPoll = $xpLogHandler->hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $thisVoter);
91
                if (!$votedThisPoll) {
92
                    /* user that hasn't voted before in this poll or module preferences allow it */
93
                    $voteTime = time();
94
                    if ($pollObj->vote($optionId, xoops_getenv('REMOTE_ADDR'), $voteTime)) {
95
                        if (!$xpPollHandler->updateCount($pollObj)) { // update the count and save in db
96
                            echo $pollObj->getHtmlErrors();
97
                            exit();
98
                        }
99
                        $msg = _MD_XOOPSPOLL_THANKSFORVOTE;
100
                    } else {
101
                        /* there was a problem registering the vote */
102
                        redirect_header($GLOBALS['xoops']->buildUrl('index.php', array('poll_id' => $poll_id)), XoopspollConstants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSPOLL_VOTE_ERROR);
103
                    }
104
                } else {
105
                    $msg = _MD_XOOPSPOLL_ALREADYVOTED;
106
                }
107
                /* set anon user vote (and the time they voted) */
108
                if (!$GLOBALS['xoopsUser'] instanceof XoopsUser) {
109
                    xoops_load('pollUtility', 'xoopspoll');
110
                    XoopspollPollUtility::setVoteCookie($poll_id, $voteTime, 0);
111
                }
112
            } else {
113
                $msg = _MD_XOOPSPOLL_CANNOTVOTE;
114
            }
115
        } else {
116
            /* poll has expired so just show the results */
117
            $msg = _MD_XOOPSPOLL_SORRYEXPIRED;
118
        }
119
    } else {
120
        $msg = _MD_XOOPSPOLL_ERROR_INVALID_POLLID;
121
    }
122
    if (null !== $url) {
123
        redirect_header($url, XoopspollConstants::REDIRECT_DELAY_MEDIUM, $msg);

extras/newbb_4x/trunk_4_00/votepolls.php 1 location

@@ 58-103 (lines=46) @@
55
56
$mail_author = false;
57
$pollObj     = $xpPollHandler->get($poll_id);
58
if ($pollObj instanceof XoopspollPoll) {
59
    if ($pollObj->getVar('multiple')) {
60
        $optionId = $_POST['option_id'];
61
        $optionId = (array)$optionId; // type cast to make sure it's an array
62
        $optionId = array_map('intval', $optionId); // make sure values are integers
63
    } else {
64
        $optionId = $_POST['option_id'];
65
    }
66
    if (!$pollObj->hasExpired()) {
67
        $msg = _MD_XOOPSPOLL_MUSTLOGIN;
68
        //@todo:: add $url to all redirects
69
        //        $url = $GLOBALS['xoops']->buildUrl("index.php", array('poll_id' => $poll_id));
70
        if ($pollObj->isAllowedToVote()) {
71
            $thisVoter     = (!empty($GLOBALS['xoopsUser'])
72
                              && ($GLOBALS['xoopsUser'] instanceof XoopsUser)) ? $GLOBALS['xoopsUser']->getVar('uid') : null;
73
            $votedThisPoll = $xpLogHandler->hasVoted($poll_id, xoops_getenv('REMOTE_ADDR'), $thisVoter);
74
            if (!$votedThisPoll) {
75
                /* user that hasn't voted before in this poll or module preferences allow it */
76
                $voteTime = time();
77
                if ($pollObj->vote($optionId, xoops_getenv('REMOTE_ADDR'), $voteTime)) {
78
                    if (!$xpPollHandler->updateCount($pollObj)) { // update the count and save in db
79
                        echo $pollObj->getHtmlErrors();
80
                        exit();
81
                    }
82
                    $msg = _MD_XOOPSPOLL_THANKSFORVOTE;
83
                } else {
84
                    /* there was a problem registering the vote */
85
                    redirect_header($GLOBALS['xoops']->buildUrl('index.php', array('poll_id' => $poll_id)), XoopspollConstants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSPOLL_VOTE_ERROR);
86
                }
87
            } else {
88
                $msg = _MD_XOOPSPOLL_ALREADYVOTED;
89
            }
90
            /* set anon user vote (and the time they voted) */
91
            if (!$GLOBALS['xoopsUser'] instanceof XoopsUser) {
92
                xoops_load('pollUtility', 'xoopspoll');
93
                XoopspollPollUtility::setVoteCookie($poll_id, $voteTime, 0);
94
            }
95
        } else {
96
            $msg = _MD_XOOPSPOLL_CANNOTVOTE;
97
        }
98
    } else {
99
        /* poll has expired so just show the results */
100
        $msg = _MD_XOOPSPOLL_SORRYEXPIRED;
101
    }
102
} else {
103
    $msg = _MD_XOOPSPOLL_ERROR_INVALID_POLLID;
104
}
105
if (null !== $url) {
106
    redirect_header($url, XoopspollConstants::REDIRECT_DELAY_MEDIUM, $msg);

index.php 1 location

@@ 162-207 (lines=46) @@
159
    //    $option_id   = XoopsRequest::getInt('option_id', 0, 'POST');
160
    $mail_author = false;
161
    $pollObj     = $pollHandler->get($pollId);
162
    if ($pollObj instanceof XoopspollPoll) {
163
        if ($pollObj->getVar('multiple')) {
164
            $optionId = XoopsRequest::getArray('option_id', array(), 'POST');
165
            $optionId = (array)$optionId; // type cast to make sure it's an array
166
            $optionId = array_map('intval', $optionId); // make sure values are integers
167
        } else {
168
            $optionId = XoopsRequest::getInt('option_id', 0, 'POST');
169
        }
170
        if (!$pollObj->hasExpired()) {
171
            $msg = _MD_XOOPSPOLL_MUSTLOGIN;
172
            //@todo:: add $url to all redirects
173
            //            $url = $GLOBALS['xoops']->buildUrl("index.php", array('poll_id' => $pollId));
174
            if ($pollObj->isAllowedToVote()) {
175
                $thisVoter     = (!empty($GLOBALS['xoopsUser'])
176
                                  && ($GLOBALS['xoopsUser'] instanceof XoopsUser)) ? $GLOBALS['xoopsUser']->getVar('uid') : null;
177
                $votedThisPoll = $logHandler->hasVoted($pollId, xoops_getenv('REMOTE_ADDR'), $thisVoter);
178
                if (!$votedThisPoll) {
179
                    /* user that hasn't voted before in this poll or module preferences allow it */
180
                    $voteTime = time();
181
                    if ($pollObj->vote($optionId, xoops_getenv('REMOTE_ADDR'), $voteTime)) {
182
                        if (!$pollHandler->updateCount($pollObj)) { // update the count and save in db
183
                            echo $pollObj->getHtmlErrors();
184
                            exit();
185
                        }
186
                        $msg = _MD_XOOPSPOLL_THANKSFORVOTE;
187
                    } else {
188
                        /* there was a problem registering the vote */
189
                        redirect_header($GLOBALS['xoops']->buildUrl('index.php', array('poll_id' => $pollId)), XoopspollConstants::REDIRECT_DELAY_MEDIUM, _MD_XOOPSPOLL_VOTE_ERROR);
190
                    }
191
                } else {
192
                    $msg = _MD_XOOPSPOLL_ALREADYVOTED;
193
                }
194
                /* set anon user vote (and the time they voted) */
195
                if (!$GLOBALS['xoopsUser'] instanceof XoopsUser) {
196
                    xoops_load('pollUtility', 'xoopspoll');
197
                    XoopspollPollUtility::setVoteCookie($pollId, $voteTime, 0);
198
                }
199
            } else {
200
                $msg = _MD_XOOPSPOLL_CANNOTVOTE;
201
            }
202
        } else {
203
            /* poll has expired so just show the results */
204
            $msg = _MD_XOOPSPOLL_SORRYEXPIRED;
205
        }
206
    } else {
207
        $msg = _MD_XOOPSPOLL_ERROR_INVALID_POLLID;
208
    }
209
    if ('' !== $url) {
210
        redirect_header($url, XoopspollConstants::REDIRECT_DELAY_MEDIUM, $msg);