Passed
Push — master ( 222087...05cb95 )
by Michael
03:24 queued 10s
created

rate-item.php (1 issue)

Labels
Severity
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
use Xmf\Request;
24
25
require_once __DIR__ . '/header.php';
26
//require_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
27
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
28
//require_once XOOPS_ROOT_PATH . '/modules/adslight/class/Utility.php';
29
if (!empty($_POST['submit'])) {
30
    //    $erh         = new ErrorHandler; //ErrorHandler object
31
    $ratinguser = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
32
33
    $anonwaitdays = 1; // Make sure only 1 anonymous rating from an IP in a single day.
34
    $ip           = getenv('REMOTE_ADDR');
35
    $lid          = Request::getInt('lid', 0, 'POST');
36
    $rating       = Request::getInt('rating', 0, 'POST');
37
38
    // Check if Rating is Null
39
    if ('--' == $rating) {
40
        redirect_header('rate-item.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_NORATING'));
41
    }
42
43
    // Check if Link POSTER is voting (UNLESS Anonymous users allowed to post)
44
    if (0 != $ratinguser) {
45
        $result = $xoopsDB->query('SELECT submitter FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid));
46
        while (false !== (list($ratinguserDB) = $xoopsDB->fetchRow($result))) {
47
            if ($ratinguserDB == $ratinguser) {
48
                redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_CANTVOTEOWN'));
49
            }
50
        }
51
52
        // Check if REG user is trying to vote twice.
53
        $result = $xoopsDB->query('SELECT ratinguser FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($lid));
54
        while (false !== (list($ratinguserDB) = $xoopsDB->fetchRow($result))) {
55
            if ($ratinguserDB == $ratinguser) {
56
                redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_VOTEONCE2'));
57
            }
58
        }
59
    } else {
60
        // Check if ANONYMOUS user is trying to vote more than once per day.
61
        $yesterday = (time() - (86400 * $anonwaitdays));
62
        $result    = $xoopsDB->query('SELECT count(*) FROM ' . $xoopsDB->prefix('adslight_item_votedata') . ' WHERE lid=' . $xoopsDB->escape($lid) . " AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday");
63
        list($anonvotecount) = $xoopsDB->fetchRow($result);
64
        if ($anonvotecount > 0) {
65
            redirect_header('viewads.php?lid=' . $lid . '', 4, constant('_ADSLIGHT_VOTEONCE2'));
66
        }
67
    }
68
    $rating = ($rating > 10) ? 10 : $rating;
69
70
    //All is well.  Add to Line Item Rate to DB.
71
    $newid    = $xoopsDB->genId($xoopsDB->prefix('adslight_item_votedata') . '_ratingid_seq');
72
    $datetime = time();
73
    $sql      = sprintf("INSERT INTO `%s` (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (%u, %u, %u, %u, '%s', %u)", $xoopsDB->prefix('adslight_item_votedata'), $newid, $lid, $ratinguser, $rating, $ip, $datetime);
74
    // $xoopsDB->query($sql) || $eh->show('0013'); //            '0013' => 'Could not query the database.', // <br>Error: ' . $GLOBALS['xoopsDB']->error() . '',
75
    $success = $xoopsDB->query($sql);
76
    if (!$success) {
77
        $moduleHandler = $helper->getHandler('Module');
78
        $myModule      = $moduleHandler->getByDirname('adslight');
79
        $myModule->setErrors('Could not query the database.');
80
    }
81
82
    //All is well.  Calculate Score & Add to Summary (for quick retrieval & sorting) to DB.
83
    //    updateIrating($lid);
84
    Adslight\Utility::updateItemRating($lid);
0 ignored issues
show
The type Adslight\Utility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
85
    $ratemessage = constant('_ADSLIGHT_VOTEAPPRE') . '<br>' . sprintf(constant('_ADSLIGHT_THANKURATEITEM'), $xoopsConfig['sitename']);
86
    redirect_header('viewads.php?lid=' . $lid . '', 3, $ratemessage);
87
} else {
88
    $GLOBALS['xoopsOption']['template_main'] = 'adslight_rate_item.tpl';
89
    require_once XOOPS_ROOT_PATH . '/header.php';
90
    $lid    = Request::getInt('lid', 0, 'GET');
91
    $result = $xoopsDB->query('SELECT lid, title FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid));
92
    list($lid, $title) = $xoopsDB->fetchRow($result);
93
    $GLOBALS['xoopsTpl']->assign('link', [
94
        'lid'   => $lid,
95
        'title' => $myts->htmlSpecialChars($title),
96
    ]);
97
    $GLOBALS['xoopsTpl']->assign('lang_voteonce', constant('_ADSLIGHT_VOTEONCE'));
98
    $GLOBALS['xoopsTpl']->assign('lang_ratingscale', constant('_ADSLIGHT_RATINGSCALE'));
99
    $GLOBALS['xoopsTpl']->assign('lang_beobjective', constant('_ADSLIGHT_BEOBJECTIVE'));
100
    $GLOBALS['xoopsTpl']->assign('lang_donotvote', constant('_ADSLIGHT_DONOTVOTE'));
101
    $GLOBALS['xoopsTpl']->assign('lang_rateit', constant('_ADSLIGHT_RATEIT'));
102
    $GLOBALS['xoopsTpl']->assign('lang_cancel', _CANCEL);
103
    $GLOBALS['xoopsTpl']->assign('mydirname', $moduleDirName);
104
    require_once XOOPS_ROOT_PATH . '/footer.php';
105
}
106