Completed
Push — master ( 38bf19...25ce06 )
by Michael
02:36
created

rate-item.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
include_once __DIR__ . '/header.php';
24
include_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
25
$myts = MyTextSanitizer::getInstance(); // MyTextSanitizer object
26
include_once XOOPS_ROOT_PATH . '/modules/adslight/include/functions.php';
27
if (!empty($HTTP_POST_VARS['submit'])) {
28
    $eh         = new ErrorHandler; //ErrorHandler object
29
    $ratinguser = ($xoopsUser instanceof XoopsUser) ? $xoopsUser->getVar('uid') : 0;
30
31
    $anonwaitdays = 1; // Make sure only 1 anonymous rating from an IP in a single day.
32
    $ip           = getenv('REMOTE_ADDR');
33
    $lid          = XoopsRequest::getInt('lid', 0, 'POST');
34
    $rating       = XoopsRequest::getInt('rating', 0, 'POST');
35
36
    // Check if Rating is Null
37
    if ($rating == '--') {
38
        redirect_header('rate-item.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_NORATING'));
39
    }
40
41
    // Check if Link POSTER is voting (UNLESS Anonymous users allowed to post)
42
    if ($ratinguser != 0) {
43
        $result = $xoopsDB->query('SELECT submitter FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
44
        while (list($ratinguserDB) = $xoopsDB->fetchRow($result)) {
45
            if ($ratinguserDB == $ratinguser) {
46
                redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_CANTVOTEOWN'));
47
            }
48
        }
49
50
        // Check if REG user is trying to vote twice.
51
        $result = $xoopsDB->query('SELECT ratinguser FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
52 View Code Duplication
        while (list($ratinguserDB) = $xoopsDB->fetchRow($result)) {
53
            if ($ratinguserDB == $ratinguser) {
54
                redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_VOTEONCE2'));
55
            }
56
        }
57 View Code Duplication
    } else {
58
59
        // Check if ANONYMOUS user is trying to vote more than once per day.
60
        $yesterday = (time() - (86400 * $anonwaitdays));
61
        $result    = $xoopsDB->query('SELECT count(*) FROM '
62
                                     . $xoopsDB->prefix('adslight_item_votedata')
63
                                     . ' WHERE lid='
64
                                     . $xoopsDB->escape($lid)
65
                                     . " AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday");
66
        list($anonvotecount) = $xoopsDB->fetchRow($result);
67
        if ($anonvotecount > 0) {
68
            redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_VOTEONCE2'));
69
        }
70
    }
71
    $rating = ($rating > 10) ? 10 : (int)$rating;
72
73
    //All is well.  Add to Line Item Rate to DB.
74
    $newid    = $xoopsDB->genId($xoopsDB->prefix('adslight_item_votedata') . '_ratingid_seq');
75
    $datetime = time();
76
    $sql      = sprintf("INSERT INTO %s (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (%u, %u, %u, %u, '%s', %u)", $xoopsDB->prefix('adslight_item_votedata'), $newid,
77
                        $lid, $ratinguser, $rating, $ip, $datetime);
78
    $xoopsDB->query($sql) || $eh->show('0013');
79
80
    //All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB.
81
    updateIrating($lid);
82
    $ratemessage = constant('_ADSLIGHT_VOTEAPPRE') . '<br>' . sprintf(constant('_ADSLIGHT_THANKURATEITEM'), $xoopsConfig['sitename']);
83
    redirect_header('viewads.php?lid=' . $lid . '', 3, $ratemessage);
84 View Code Duplication
} else {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_rate_item.tpl';
86
    include XOOPS_ROOT_PATH . '/header.php';
87
    $lid    = XoopsRequest::getInt('lid', 0, 'GET');
88
    $result = $xoopsDB->query('SELECT lid, title FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid) . '');
89
    list($lid, $title) = $xoopsDB->fetchRow($result);
90
    $xoopsTpl->assign('link', array('lid' => $lid, 'title' => $myts->htmlSpecialChars($title)));
91
    $xoopsTpl->assign('lang_voteonce', constant('_ADSLIGHT_VOTEONCE'));
92
    $xoopsTpl->assign('lang_ratingscale', constant('_ADSLIGHT_RATINGSCALE'));
93
    $xoopsTpl->assign('lang_beobjective', constant('_ADSLIGHT_BEOBJECTIVE'));
94
    $xoopsTpl->assign('lang_donotvote', constant('_ADSLIGHT_DONOTVOTE'));
95
    $xoopsTpl->assign('lang_rateit', constant('_ADSLIGHT_RATEIT'));
96
    $xoopsTpl->assign('lang_cancel', _CANCEL);
97
    $xoopsTpl->assign('mydirname', $moduleDirName);
98
    include XOOPS_ROOT_PATH . '/footer.php';
99
}
100